There's a UISystem now for to compliment the entities and components in GUECS. I now use that to do the drag/drop transfers instead of raw code right in the FSM.
This commit is contained in:
parent
e01e697535
commit
4a48910273
11 changed files with 62 additions and 60 deletions
47
gui/fsm.cpp
47
gui/fsm.cpp
|
@ -6,6 +6,7 @@
|
|||
#include "components.hpp"
|
||||
#include <numbers>
|
||||
#include "systems.hpp"
|
||||
#include "gui/uisystems.hpp"
|
||||
#include "events.hpp"
|
||||
#include "sound.hpp"
|
||||
#include "shaders.hpp"
|
||||
|
@ -133,23 +134,19 @@ namespace gui {
|
|||
state(State::IDLE);
|
||||
break;
|
||||
case LOOT_SELECT: {
|
||||
$grab_source = std::any_cast<DinkyECS::Entity>(data);
|
||||
auto& source = $loot_ui.get_grab_source(*$grab_source);
|
||||
source.grab();
|
||||
auto gui_id = std::any_cast<guecs::Entity>(data);
|
||||
$grab_source = UISystem::loot_grab($loot_ui.$gui, gui_id);
|
||||
} break;
|
||||
case INV_SELECT: {
|
||||
auto gui_id = std::any_cast<DinkyECS::Entity>(data);
|
||||
|
||||
if($grab_source) {
|
||||
auto& drop = $status_ui.get_drop_target(gui_id);
|
||||
auto& grab = $loot_ui.get_grab_source(*$grab_source);
|
||||
auto gui_id = std::any_cast<guecs::Entity>(data);
|
||||
bool dropped = UISystem::loot_drop(
|
||||
$loot_ui.$gui, $status_ui.$gui,
|
||||
*$grab_source, gui_id);
|
||||
|
||||
if(drop.commit(grab.world_entity)) {
|
||||
grab.commit();
|
||||
$grab_source = std::nullopt;
|
||||
if(dropped) {
|
||||
state(State::LOOTING);
|
||||
}
|
||||
|
||||
state(State::LOOTING);
|
||||
}
|
||||
} break;
|
||||
case MOUSE_CLICK:
|
||||
|
@ -158,7 +155,7 @@ namespace gui {
|
|||
case MOUSE_DRAG:
|
||||
case MOUSE_MOVE: {
|
||||
if($grab_source) {
|
||||
auto& source = $loot_ui.get_grab_source(*$grab_source);
|
||||
auto& source = $loot_ui.$gui.get<guecs::GrabSource>(*$grab_source);
|
||||
source.move($router.position);
|
||||
}
|
||||
mouse_action(true);
|
||||
|
@ -186,24 +183,20 @@ namespace gui {
|
|||
state(State::IDLE);
|
||||
break;
|
||||
case LOOT_SELECT: {
|
||||
auto gui_id = std::any_cast<DinkyECS::Entity>(data);
|
||||
|
||||
if($grab_source) {
|
||||
auto& drop = $loot_ui.get_drop_target(gui_id);
|
||||
auto& grab = $status_ui.get_grab_source(*$grab_source);
|
||||
auto gui_id = std::any_cast<guecs::Entity>(data);
|
||||
bool dropped = UISystem::loot_drop(
|
||||
$status_ui.$gui, $loot_ui.$gui,
|
||||
*$grab_source, gui_id);
|
||||
|
||||
if(drop.commit(grab.world_entity)) {
|
||||
grab.commit();
|
||||
$grab_source = std::nullopt;
|
||||
if(dropped) {
|
||||
state(State::LOOTING);
|
||||
}
|
||||
|
||||
state(State::LOOTING);
|
||||
}
|
||||
} break;
|
||||
case INV_SELECT: {
|
||||
$grab_source = std::any_cast<DinkyECS::Entity>(data);
|
||||
auto& source = $status_ui.get_grab_source(*$grab_source);
|
||||
source.grab();
|
||||
auto gui_id = std::any_cast<DinkyECS::Entity>(data);
|
||||
$grab_source = UISystem::loot_grab($status_ui.$gui, gui_id);
|
||||
} break;
|
||||
case MOUSE_CLICK:
|
||||
mouse_action(false);
|
||||
|
@ -211,7 +204,7 @@ namespace gui {
|
|||
case MOUSE_DRAG:
|
||||
case MOUSE_MOVE: {
|
||||
if($grab_source) {
|
||||
auto& source = $status_ui.get_grab_source(*$grab_source);
|
||||
auto& source = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
|
||||
source.move($router.position);
|
||||
}
|
||||
mouse_action(true);
|
||||
|
@ -236,6 +229,8 @@ namespace gui {
|
|||
state(State::IDLE);
|
||||
break;
|
||||
case LOOT_SELECT:
|
||||
// BUG: this actually should init the select, so that in LOOT_GRAB
|
||||
// I can allow people to place it back into the loot ui
|
||||
state(State::LOOT_GRAB);
|
||||
LOOT_GRAB(ev, data);
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue