Clean up more of the FSM so that it's almost nothing.Now I'll try to make a stand-alone 'dnd' state machine to handle drag and drop functionality.
This commit is contained in:
parent
06a843f169
commit
1ab708c4eb
3 changed files with 43 additions and 50 deletions
74
gui/fsm.cpp
74
gui/fsm.cpp
|
@ -133,23 +133,17 @@ namespace gui {
|
||||||
$loot_ui.active = false;
|
$loot_ui.active = false;
|
||||||
state(State::IDLE);
|
state(State::IDLE);
|
||||||
break;
|
break;
|
||||||
case LOOT_SELECT: {
|
case LOOT_SELECT:
|
||||||
auto gui_id = std::any_cast<guecs::Entity>(data);
|
$grab_source = UISystem::loot_grab($loot_ui.$gui, data);
|
||||||
$grab_source = UISystem::loot_grab($loot_ui.$gui, gui_id);
|
if($grab_source) state(State::LOOTING);
|
||||||
if(!$grab_source) state(State::LOOTING);
|
break;
|
||||||
} break;
|
case INV_SELECT:
|
||||||
case INV_SELECT: {
|
if(UISystem::loot_drop($loot_ui.$gui,
|
||||||
if($grab_source) {
|
$status_ui.$gui, $grab_source, data))
|
||||||
auto gui_id = std::any_cast<guecs::Entity>(data);
|
{
|
||||||
bool dropped = UISystem::loot_drop(
|
state(State::LOOTING);
|
||||||
$loot_ui.$gui, $status_ui.$gui,
|
}
|
||||||
*$grab_source, gui_id);
|
break;
|
||||||
|
|
||||||
if(dropped) {
|
|
||||||
state(State::LOOTING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
case MOUSE_CLICK:
|
case MOUSE_CLICK:
|
||||||
mouse_action(false);
|
mouse_action(false);
|
||||||
break;
|
break;
|
||||||
|
@ -183,23 +177,17 @@ namespace gui {
|
||||||
$loot_ui.active = false;
|
$loot_ui.active = false;
|
||||||
state(State::IDLE);
|
state(State::IDLE);
|
||||||
break;
|
break;
|
||||||
case LOOT_SELECT: {
|
case LOOT_SELECT:
|
||||||
if($grab_source) {
|
if(UISystem::loot_drop($status_ui.$gui,
|
||||||
auto gui_id = std::any_cast<guecs::Entity>(data);
|
$loot_ui.$gui, $grab_source, data))
|
||||||
bool dropped = UISystem::loot_drop(
|
{
|
||||||
$status_ui.$gui, $loot_ui.$gui,
|
state(State::LOOTING);
|
||||||
*$grab_source, gui_id);
|
}
|
||||||
|
break;
|
||||||
if(dropped) {
|
case INV_SELECT:
|
||||||
state(State::LOOTING);
|
$grab_source = UISystem::loot_grab($status_ui.$gui, data);
|
||||||
}
|
state(State::LOOTING);
|
||||||
}
|
break;
|
||||||
} break;
|
|
||||||
case INV_SELECT: {
|
|
||||||
auto gui_id = std::any_cast<DinkyECS::Entity>(data);
|
|
||||||
$grab_source = UISystem::loot_grab($status_ui.$gui, gui_id);
|
|
||||||
if(!$grab_source) state(State::LOOTING);
|
|
||||||
} break;
|
|
||||||
case MOUSE_CLICK:
|
case MOUSE_CLICK:
|
||||||
mouse_action(false);
|
mouse_action(false);
|
||||||
break;
|
break;
|
||||||
|
@ -230,16 +218,14 @@ namespace gui {
|
||||||
$loot_ui.active = false;
|
$loot_ui.active = false;
|
||||||
state(State::IDLE);
|
state(State::IDLE);
|
||||||
break;
|
break;
|
||||||
case LOOT_SELECT: {
|
case LOOT_SELECT:
|
||||||
auto gui_id = std::any_cast<guecs::Entity>(data);
|
$grab_source = UISystem::loot_grab($loot_ui.$gui, data);
|
||||||
$grab_source = UISystem::loot_grab($loot_ui.$gui, gui_id);
|
if($grab_source) state(State::LOOT_GRAB);
|
||||||
if($grab_source) state(State::LOOT_GRAB);
|
break;
|
||||||
} break;
|
case INV_SELECT:
|
||||||
case INV_SELECT: {
|
$grab_source = UISystem::loot_grab($status_ui.$gui, data);
|
||||||
auto gui_id = std::any_cast<DinkyECS::Entity>(data);
|
if($grab_source) state(State::INV_GRAB);
|
||||||
$grab_source = UISystem::loot_grab($status_ui.$gui, gui_id);
|
break;
|
||||||
if($grab_source) state(State::INV_GRAB);
|
|
||||||
} break;
|
|
||||||
case MOUSE_DRAG_START:
|
case MOUSE_DRAG_START:
|
||||||
case MOUSE_CLICK:
|
case MOUSE_CLICK:
|
||||||
mouse_action(false);
|
mouse_action(false);
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
#include "gui/guecstra.hpp"
|
#include "gui/guecstra.hpp"
|
||||||
|
|
||||||
namespace UISystem {
|
namespace UISystem {
|
||||||
std::optional<guecs::Entity> loot_grab(guecs::UI& gui, guecs::Entity gui_id) {
|
std::optional<guecs::Entity> loot_grab(guecs::UI& gui, std::any data) {
|
||||||
|
auto gui_id = std::any_cast<guecs::Entity>(data);
|
||||||
|
|
||||||
if(auto source = gui.get_if<guecs::GrabSource>(gui_id)) {
|
if(auto source = gui.get_if<guecs::GrabSource>(gui_id)) {
|
||||||
source->grab();
|
source->grab();
|
||||||
return gui_id;
|
return gui_id;
|
||||||
|
@ -11,9 +13,14 @@ namespace UISystem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool loot_drop(guecs::UI& source, guecs::UI& target, guecs::Entity source_id, guecs::Entity target_id) {
|
bool loot_drop(guecs::UI& source, guecs::UI& target,
|
||||||
|
std::optional<guecs::Entity> source_id, std::any data)
|
||||||
|
{
|
||||||
|
if(!source_id) return false;
|
||||||
|
auto target_id = std::any_cast<guecs::Entity>(data);
|
||||||
|
|
||||||
auto& drop = target.get<guecs::DropTarget>(target_id);
|
auto& drop = target.get<guecs::DropTarget>(target_id);
|
||||||
auto& grab = source.get<guecs::GrabSource>(source_id);
|
auto& grab = source.get<guecs::GrabSource>(*source_id);
|
||||||
|
|
||||||
if(drop.commit(grab.world_entity)) {
|
if(drop.commit(grab.world_entity)) {
|
||||||
grab.commit();
|
grab.commit();
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
namespace UISystem {
|
namespace UISystem {
|
||||||
std::optional<guecs::Entity> loot_grab(guecs::UI& gui, guecs::Entity gui_id);
|
std::optional<guecs::Entity> loot_grab(guecs::UI& gui, std::any data);
|
||||||
|
|
||||||
|
bool loot_drop(guecs::UI& source, guecs::UI& target,
|
||||||
bool loot_drop(guecs::UI& source, guecs::UI& target, guecs::Entity grab_source, guecs::Entity target_id);
|
std::optional<guecs::Entity> source_id, std::any data);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue