diff --git a/gui/dnd_loot.cpp b/gui/dnd_loot.cpp index 2b48418..338fc9f 100644 --- a/gui/dnd_loot.cpp +++ b/gui/dnd_loot.cpp @@ -31,7 +31,7 @@ namespace gui { void DNDLoot::START(Event ev) { dbc::check(ev == Event::STARTED, "START not given a STARTED event."); - state(DNDState::END); + END(Event::CLOSE); } void DNDLoot::LOOTING(Event ev, std::any data) { @@ -39,8 +39,7 @@ namespace gui { switch(ev) { case LOOT_OPEN: - $loot_ui.active = false; - state(DNDState::END); + END(Event::CLOSE); break; case LOOT_SELECT: $grab_source = UISystem::loot_grab($loot_ui.$gui, data); @@ -64,8 +63,7 @@ namespace gui { switch(ev) { case LOOT_OPEN: - $loot_ui.active = false; - state(DNDState::END); + END(Event::CLOSE); break; case LOOT_SELECT: $grab_source = UISystem::loot_grab($loot_ui.$gui, data); @@ -88,8 +86,7 @@ namespace gui { switch(ev) { case LOOT_OPEN: - $loot_ui.active = false; - state(DNDState::END); + END(Event::CLOSE); break; case LOOT_SELECT: if(UISystem::loot_drop($status_ui.$gui, @@ -115,9 +112,7 @@ namespace gui { if(UISystem::loot_drop($loot_ui.$gui, $status_ui.$gui, $grab_source, data)) { - $grab_source = std::nullopt; - $grab_sprite = nullptr; - state(DNDState::END); + END(Event::CLOSE); } break; case LOOT_ITEM: @@ -146,11 +141,14 @@ namespace gui { } } break; case LOOT_OPEN: - $loot_ui.active = true; - $grab_source = std::nullopt; - $grab_sprite = nullptr; + open(); state(DNDState::LOOTING); break; + case CLOSE: + // called the first time transitioning to END + close(); + state(DNDState::END); + break; default: dbc::sentinel(fmt::format("invalid event: {}", int(ev))); } @@ -193,6 +191,18 @@ namespace gui { } } + void DNDLoot::open() { + $grab_source = std::nullopt; + $grab_sprite = nullptr; + $loot_ui.active = true; + } + + void DNDLoot::close() { + $grab_source = std::nullopt; + $grab_sprite = nullptr; + $loot_ui.active = false; + } + void DNDLoot::render() { if($grab_source && $grab_sprite) { $window.draw(*$grab_sprite); diff --git a/gui/dnd_loot.hpp b/gui/dnd_loot.hpp index 3b9a4d5..836882f 100644 --- a/gui/dnd_loot.hpp +++ b/gui/dnd_loot.hpp @@ -39,6 +39,8 @@ namespace gui { void handle_mouse(Event ev, guecs::UI& gui); void mouse_action(bool hover); void render(); + void open(); + void close(); sf::Vector2f mouse_position(); }; }