Worked out an initial stab at a GrabSource for drag-n-drop or just simple grabbing things in the UI.
This commit is contained in:
parent
94385b195d
commit
842aac3127
5 changed files with 47 additions and 32 deletions
38
gui/fsm.cpp
38
gui/fsm.cpp
|
@ -10,6 +10,7 @@
|
|||
#include "sound.hpp"
|
||||
#include "shaders.hpp"
|
||||
#include <fmt/xchar.h>
|
||||
#include "gui/guecstra.hpp"
|
||||
|
||||
namespace gui {
|
||||
using namespace components;
|
||||
|
@ -57,7 +58,6 @@ namespace gui {
|
|||
}
|
||||
|
||||
void FSM::START(Event ) {
|
||||
|
||||
$main_ui.update_level($level);
|
||||
$main_ui.init();
|
||||
$loot_ui.init();
|
||||
|
@ -133,37 +133,34 @@ namespace gui {
|
|||
break;
|
||||
case LOOT_SELECT: {
|
||||
int slot_id = std::any_cast<int>(data);
|
||||
if(auto entity = $loot_ui.select_slot(slot_id)) {
|
||||
$status_ui.select_slot(slot_id, *entity);
|
||||
$dumb_sprite = $loot_ui.grab_sprite(slot_id);
|
||||
|
||||
$window.setMouseCursorVisible(false);
|
||||
$dumb_sprite->setOrigin({128, 128});
|
||||
$dumb_sprite->setPosition({
|
||||
float($router.position.x),
|
||||
float($router.position.y)
|
||||
});
|
||||
if(auto world_entity = $loot_ui.select_slot(slot_id)) {
|
||||
$grab_source = $loot_ui.$gui.entity("item_", slot_id);
|
||||
auto& source = $loot_ui.get_grabber(*$grab_source);
|
||||
|
||||
source.grab($window);
|
||||
source.move($router.position);
|
||||
|
||||
$status_ui.select_slot(slot_id, *world_entity);
|
||||
}
|
||||
} break;
|
||||
case INV_SELECT: {
|
||||
std::string slot_name = std::any_cast<std::string>(data);
|
||||
int slot_id = $status_ui.place_slot(slot_name);
|
||||
dbc::check(slot_id != -1, "status_ui is trying to place -1 slot_id");
|
||||
if(slot_id != -1) {
|
||||
$loot_ui.remove_slot(slot_id);
|
||||
}
|
||||
$window.setMouseCursorVisible(true);
|
||||
$dumb_sprite = nullptr;
|
||||
state(State::LOOTING);
|
||||
} break;
|
||||
case MOUSE_CLICK:
|
||||
mouse_action(false);
|
||||
break;
|
||||
case MOUSE_MOVE: {
|
||||
if($dumb_sprite) {
|
||||
$dumb_sprite->setPosition({
|
||||
float($router.position.x),
|
||||
float($router.position.y)
|
||||
});
|
||||
if($grab_source) {
|
||||
auto& source = $loot_ui.get_grabber(*$grab_source);
|
||||
source.move($router.position);
|
||||
}
|
||||
mouse_action(true);
|
||||
} break;
|
||||
|
@ -171,11 +168,9 @@ namespace gui {
|
|||
mouse_action(false);
|
||||
} break;
|
||||
case MOUSE_DRAG: {
|
||||
if($dumb_sprite) {
|
||||
$dumb_sprite->setPosition({
|
||||
float($router.position.x),
|
||||
float($router.position.y)
|
||||
});
|
||||
if($grab_source) {
|
||||
auto& source = $loot_ui.get_grabber(*$grab_source);
|
||||
source.move($router.position);
|
||||
}
|
||||
mouse_action(true);
|
||||
} break;
|
||||
|
@ -241,6 +236,7 @@ namespace gui {
|
|||
state(State::INV_GRAB);
|
||||
INV_GRAB(ev, data);
|
||||
break;
|
||||
case MOUSE_DRAG_START:
|
||||
case MOUSE_CLICK:
|
||||
mouse_action(false);
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue