Fixed the problem where the only way to complete a grab/drop operation was to capture the MOUSE_CLICK directly. Solution was to move the mouse processing out of DNDLoot and only handle the MOUSE_MOVE/DRAG.

master
Zed A. Shaw 2 days ago
parent 6a72d1160f
commit f559b5a39d
  1. 31
      gui/dnd_loot.cpp
  2. 1
      gui/dnd_loot.hpp
  3. 19
      gui/fsm.cpp
  4. 3
      gui/fsm_events.hpp
  5. 20
      gui/overlay_ui.cpp
  6. 1
      systems.cpp

@ -48,10 +48,6 @@ namespace gui {
$grab_source = start_grab($status_ui.$gui, data); $grab_source = start_grab($status_ui.$gui, data);
if($grab_source) state(DNDState::INV_GRAB); if($grab_source) state(DNDState::INV_GRAB);
break; break;
case MOUSE_DRAG_START:
case MOUSE_CLICK:
mouse_action(false);
break;
default: default:
state(DNDState::LOOTING); state(DNDState::LOOTING);
} }
@ -108,8 +104,8 @@ namespace gui {
(void)data; (void)data;
switch(ev) { switch(ev) {
case MOUSE_CLICK: case AIM_CLICK: {
case MOUSE_DROP: { fmt::println("IN INV_PICKUP AIM CLICK!");
auto& grab = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source); auto& grab = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
grab.commit(); grab.commit();
bool dropped = $status_ui.drop_item(grab.world_entity); bool dropped = $status_ui.drop_item(grab.world_entity);
@ -132,7 +128,6 @@ namespace gui {
} }
break; break;
case LOOT_ITEM: case LOOT_ITEM:
dbc::log("PUT IT BACK!");
break; break;
default: default:
handle_mouse(ev, $loot_ui.$gui); 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) { void DNDLoot::handle_mouse(Event ev, guecs::UI& gui) {
using enum Event; using enum Event;
switch(ev) { switch(ev) {
case MOUSE_CLICK:
mouse_action(false);
break;
case MOUSE_DRAG: case MOUSE_DRAG:
case MOUSE_MOVE: { case MOUSE_MOVE: {
if($grab_source) { if($grab_source) {
auto& source = gui.get<guecs::GrabSource>(*$grab_source); auto& source = gui.get<guecs::GrabSource>(*$grab_source);
source.move($window.mapPixelToCoords($router.position)); source.move($window.mapPixelToCoords($router.position));
} }
mouse_action(true);
} break; } break;
case MOUSE_DRAG_START:
mouse_action(false);
break;
case MOUSE_DROP:
mouse_action(false);
break;
default: default:
break; // ignored break; // ignored
} }
@ -234,8 +209,6 @@ namespace gui {
void DNDLoot::render() { void DNDLoot::render() {
if($grab_source && $grab_sprite) { if($grab_source && $grab_sprite) {
$window.draw(*$grab_sprite); $window.draw(*$grab_sprite);
} else {
dbc::log("nothing to render!");
} }
} }

@ -40,7 +40,6 @@ namespace gui {
void INV_PICKUP(Event ev, std::any data); void INV_PICKUP(Event ev, std::any data);
void handle_mouse(Event ev, guecs::UI& gui); void handle_mouse(Event ev, guecs::UI& gui);
void mouse_action(bool hover);
void render(); void render();
void open(); void open();
void close(); void close();

@ -93,7 +93,6 @@ namespace gui {
state(State::IN_COMBAT); state(State::IN_COMBAT);
} break; } break;
case STOP_COMBAT: case STOP_COMBAT:
dbc::log("Exiting ATTACKING STATE");
state(State::IDLE); state(State::IDLE);
break; break;
case ATTACK: case ATTACK:
@ -118,8 +117,18 @@ namespace gui {
} }
void FSM::LOOTING(Event ev, std::any data) { void FSM::LOOTING(Event ev, std::any data) {
if(!$dnd_loot.event(ev, data)) { using enum Event;
state(State::IDLE);
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); if($debug_ui.active) $debug_ui.mouse(pos.x, pos.y, hover);
$combat_ui.mouse(pos.x, pos.y, hover); $combat_ui.mouse(pos.x, pos.y, hover);
$status_ui.mouse(pos.x, pos.y, hover); $status_ui.mouse(pos.x, pos.y, hover);
if($loot_ui.active) { if($loot_ui.active) {
$loot_ui.mouse(pos.x, pos.y, hover); $loot_ui.mouse(pos.x, pos.y, hover);
} else { } else {
@ -459,7 +469,8 @@ namespace gui {
fmt::println("clicked on a thing: {}", aimed_at); fmt::println("clicked on a thing: {}", aimed_at);
System::pickup($level, aimed_at); System::pickup($level, aimed_at);
} else { } else {
dbc::log("there's no thing there!"); fmt::println("SENDING AIM_CLICK");
event(Event::AIM_CLICK);
} }
break; break;
case eGUI::LOOT_ITEM: { case eGUI::LOOT_ITEM: {

@ -26,6 +26,7 @@ namespace gui {
MOUSE_DRAG=21, MOUSE_DRAG=21,
MOUSE_DRAG_START=22, MOUSE_DRAG_START=22,
MOUSE_DROP=23, MOUSE_DROP=23,
KEY_PRESS=24 KEY_PRESS=24,
AIM_CLICK=25
}; };
} }

@ -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<Clickable>(area, {
[&](auto ent, auto data) {
level.world->send<Events::GUI>(Events::GUI::AIM_CLICK, ent, data);
}
});
}
void OverlayUI::init() { void OverlayUI::init() {
$gui.init(); $gui.init();
auto bottom = $gui.entity("bottom"); make_clickable_area($level, $gui, "top");
$gui.set<Clickable>(bottom, { make_clickable_area($level, $gui, "middle");
[&](auto ent, auto data) { make_clickable_area($level, $gui, "bottom");
$level.world->send<Events::GUI>(
Events::GUI::AIM_CLICK, ent, data);
}
});
} }
void OverlayUI::render(sf::RenderWindow& window) { void OverlayUI::render(sf::RenderWindow& window) {

@ -111,7 +111,6 @@ void System::init_positions(World &world, SpatialMap &collider) {
collider.insert(pos.location, ent); collider.insert(pos.location, ent);
} }
} else { } else {
fmt::println("System::init_positions for ent={}", ent);
dbc::check(!inv.has(ent), dbc::check(!inv.has(ent),
fmt::format("!!! Entity {} is in player inventory and _also_ has a position in the world.", ent)); fmt::format("!!! Entity {} is in player inventory and _also_ has a position in the world.", ent));

Loading…
Cancel
Save