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. 15
      gui/fsm.cpp
  4. 3
      gui/fsm_events.hpp
  5. 18
      gui/overlay_ui.cpp
  6. 1
      systems.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<guecs::GrabSource>(*$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<guecs::GrabSource>(*$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!");
}
}

@ -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();

@ -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,10 +117,20 @@ namespace gui {
}
void FSM::LOOTING(Event ev, std::any data) {
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);
}
}
}
void FSM::IDLE(Event ev, std::any data) {
using enum Event;
@ -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: {

@ -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
};
}

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

@ -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));

Loading…
Cancel
Save