diff --git a/gui/dnd_loot.cpp b/gui/dnd_loot.cpp index fda4cee..2b48418 100644 --- a/gui/dnd_loot.cpp +++ b/gui/dnd_loot.cpp @@ -115,6 +115,8 @@ 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); } break; @@ -134,11 +136,19 @@ namespace gui { // NOTE: if > 1 items, go to LOOT_OPEN instead auto gui_id = $loot_ui.$gui.entity("item_0"); $grab_source = UISystem::loot_grab($loot_ui.$gui, gui_id); - if($grab_source) state(DNDState::ITEM_PICKUP); + + if($grab_source) { + auto& source = $loot_ui.$gui.get(*$grab_source); + $grab_sprite = source.sprite; + // call this once to properly position the sprite + handle_mouse(Event::MOUSE_MOVE, $loot_ui.$gui); + state(DNDState::ITEM_PICKUP); + } } break; case LOOT_OPEN: $loot_ui.active = true; $grab_source = std::nullopt; + $grab_sprite = nullptr; state(DNDState::LOOTING); break; default: @@ -183,4 +193,9 @@ namespace gui { } } + 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 c2fa590..3b9a4d5 100644 --- a/gui/dnd_loot.hpp +++ b/gui/dnd_loot.hpp @@ -18,6 +18,7 @@ namespace gui { class DNDLoot : public DeadSimpleFSM { public: std::optional $grab_source = std::nullopt; + std::shared_ptr $grab_sprite = nullptr; StatusUI& $status_ui; LootUI& $loot_ui; sf::RenderWindow& $window; @@ -37,6 +38,7 @@ namespace gui { void ITEM_PICKUP(Event ev, std::any data); void handle_mouse(Event ev, guecs::UI& gui); void mouse_action(bool hover); + void render(); sf::Vector2f mouse_position(); }; } diff --git a/gui/fsm.cpp b/gui/fsm.cpp index e4be389..c9b251a 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -366,6 +366,7 @@ namespace gui { $combat_ui.render($window); if($loot_ui.active) $loot_ui.render($window); + $dnd_loot.render(); if($map_open) { $map_ui.render($window, $main_ui.$compass_dir);