diff --git a/gui/dnd_loot.cpp b/gui/dnd_loot.cpp index 4ed7342..3528a45 100644 --- a/gui/dnd_loot.cpp +++ b/gui/dnd_loot.cpp @@ -48,10 +48,6 @@ namespace gui { $grab_source = start_grab($status_ui.$gui, data); if($grab_source) state(DNDState::INV_GRAB); break; - case MOUSE_DRAG_START: - case MOUSE_CLICK: - mouse_action(false); - break; default: state(DNDState::LOOTING); } @@ -108,8 +104,8 @@ namespace gui { (void)data; switch(ev) { - case MOUSE_CLICK: - case MOUSE_DROP: { + case AIM_CLICK: { + fmt::println("IN INV_PICKUP AIM CLICK!"); auto& grab = $status_ui.$gui.get(*$grab_source); grab.commit(); bool dropped = $status_ui.drop_item(grab.world_entity); @@ -132,7 +128,6 @@ namespace gui { } break; case LOOT_ITEM: - dbc::log("PUT IT BACK!"); break; default: handle_mouse(ev, $loot_ui.$gui); @@ -183,37 +178,17 @@ namespace gui { } } - sf::Vector2f DNDLoot::mouse_position() { - return $window.mapPixelToCoords($router.position); - } - - void DNDLoot::mouse_action(bool hover) { - sf::Vector2f pos = mouse_position(); - $status_ui.mouse(pos.x, pos.y, hover); - if($loot_ui.active) $loot_ui.mouse(pos.x, pos.y, hover); - } - void DNDLoot::handle_mouse(Event ev, guecs::UI& gui) { using enum Event; switch(ev) { - case MOUSE_CLICK: - mouse_action(false); - break; case MOUSE_DRAG: case MOUSE_MOVE: { if($grab_source) { auto& source = gui.get(*$grab_source); source.move($window.mapPixelToCoords($router.position)); } - mouse_action(true); } break; - case MOUSE_DRAG_START: - mouse_action(false); - break; - case MOUSE_DROP: - mouse_action(false); - break; default: break; // ignored } @@ -234,8 +209,6 @@ namespace gui { void DNDLoot::render() { if($grab_source && $grab_sprite) { $window.draw(*$grab_sprite); - } else { - dbc::log("nothing to render!"); } } diff --git a/gui/dnd_loot.hpp b/gui/dnd_loot.hpp index b205436..7c525fb 100644 --- a/gui/dnd_loot.hpp +++ b/gui/dnd_loot.hpp @@ -40,7 +40,6 @@ namespace gui { void INV_PICKUP(Event ev, std::any data); void handle_mouse(Event ev, guecs::UI& gui); - void mouse_action(bool hover); void render(); void open(); void close(); diff --git a/gui/fsm.cpp b/gui/fsm.cpp index 2469459..b455935 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -93,7 +93,6 @@ namespace gui { state(State::IN_COMBAT); } break; case STOP_COMBAT: - dbc::log("Exiting ATTACKING STATE"); state(State::IDLE); break; case ATTACK: @@ -118,8 +117,18 @@ namespace gui { } void FSM::LOOTING(Event ev, std::any data) { - if(!$dnd_loot.event(ev, data)) { - state(State::IDLE); + using enum Event; + + switch(ev) { + case MOUSE_DRAG_START: + case MOUSE_CLICK: + case MOUSE_DROP: + mouse_action(false); + break; + default: + if(!$dnd_loot.event(ev, data)) { + state(State::IDLE); + } } } @@ -278,6 +287,7 @@ namespace gui { if($debug_ui.active) $debug_ui.mouse(pos.x, pos.y, hover); $combat_ui.mouse(pos.x, pos.y, hover); $status_ui.mouse(pos.x, pos.y, hover); + if($loot_ui.active) { $loot_ui.mouse(pos.x, pos.y, hover); } else { @@ -459,7 +469,8 @@ namespace gui { fmt::println("clicked on a thing: {}", aimed_at); System::pickup($level, aimed_at); } else { - dbc::log("there's no thing there!"); + fmt::println("SENDING AIM_CLICK"); + event(Event::AIM_CLICK); } break; case eGUI::LOOT_ITEM: { diff --git a/gui/fsm_events.hpp b/gui/fsm_events.hpp index bdb6bad..f63719e 100644 --- a/gui/fsm_events.hpp +++ b/gui/fsm_events.hpp @@ -26,6 +26,7 @@ namespace gui { MOUSE_DRAG=21, MOUSE_DRAG_START=22, MOUSE_DROP=23, - KEY_PRESS=24 + KEY_PRESS=24, + AIM_CLICK=25 }; } diff --git a/gui/overlay_ui.cpp b/gui/overlay_ui.cpp index 87016b8..760d262 100644 --- a/gui/overlay_ui.cpp +++ b/gui/overlay_ui.cpp @@ -16,15 +16,21 @@ namespace gui { ); } + inline void make_clickable_area(GameLevel& level, guecs::UI &gui, const std::string &name) { + auto area = gui.entity(name); + + gui.set(area, { + [&](auto ent, auto data) { + level.world->send(Events::GUI::AIM_CLICK, ent, data); + } + }); + } + void OverlayUI::init() { $gui.init(); - auto bottom = $gui.entity("bottom"); - $gui.set(bottom, { - [&](auto ent, auto data) { - $level.world->send( - Events::GUI::AIM_CLICK, ent, data); - } - }); + make_clickable_area($level, $gui, "top"); + make_clickable_area($level, $gui, "middle"); + make_clickable_area($level, $gui, "bottom"); } void OverlayUI::render(sf::RenderWindow& window) { diff --git a/systems.cpp b/systems.cpp index ce7ff96..083b0f2 100644 --- a/systems.cpp +++ b/systems.cpp @@ -111,7 +111,6 @@ void System::init_positions(World &world, SpatialMap &collider) { collider.insert(pos.location, ent); } } else { - fmt::println("System::init_positions for ent={}", ent); dbc::check(!inv.has(ent), fmt::format("!!! Entity {} is in player inventory and _also_ has a position in the world.", ent));