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.

This commit is contained in:
Zed A. Shaw 2025-06-24 11:33:37 -04:00
parent 6a72d1160f
commit f559b5a39d
6 changed files with 32 additions and 43 deletions

View file

@ -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!");
}
}