Make the AIM_CLICK handler in FSM properly deal with an item already there while looting or not. Closes #56.

master
Zed A. Shaw 15 hours ago
parent 87e69bebde
commit 584c4e9f67
  1. 4
      Makefile
  2. 32
      gui/dnd_loot.cpp
  3. 2
      gui/dnd_loot.hpp
  4. 20
      gui/fsm.cpp
  5. 7
      gui/loot_ui.cpp
  6. 1
      gui/loot_ui.hpp

@ -34,7 +34,7 @@ tracy_build:
meson compile -j 10 -C builddir meson compile -j 10 -C builddir
test: build test: build
./builddir/runtests ./builddir/runtests "[inventory]"
run: build test run: build test
ifeq '$(OS)' 'Windows_NT' ifeq '$(OS)' 'Windows_NT'
@ -57,7 +57,7 @@ clean:
meson compile --clean -C builddir meson compile --clean -C builddir
debug_test: build debug_test: build
gdb --nx -x .gdbinit --ex run --args builddir/runtests -e gdb --nx -x .gdbinit --ex run --args builddir/runtests -e "[inventory]"
win_installer: win_installer:
powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp' powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp'

@ -107,7 +107,8 @@ namespace gui {
switch(ev) { switch(ev) {
case AIM_CLICK: { case AIM_CLICK: {
bool worked = throw_on_floor(); // take from inventory, drop on floor
bool worked = throw_on_floor($status_ui.$gui, true);
dbc::check(worked, "Need to fix this, should be able to abort."); dbc::check(worked, "Need to fix this, should be able to abort.");
END(CLOSE); END(CLOSE);
} break; } break;
@ -137,12 +138,12 @@ namespace gui {
END(CLOSE); END(CLOSE);
} }
break; break;
case AIM_CLICK: case AIM_CLICK: {
// BUG: because I put things into fake loot containers it's actually // THIS IS PUT IT BACK ON THE FLOOR
// hard to put things back. It's probably a System::remove from the bool worked = throw_on_floor($loot_ui.$gui, false);
// loot container combined with a System::drop_item dbc::check(worked, "Failed to drop it back on the floor.");
dbc::log("Put it back?"); END(CLOSE);
break; } break;
default: default:
handle_mouse(ev, $loot_ui.$gui); handle_mouse(ev, $loot_ui.$gui);
} }
@ -174,7 +175,7 @@ namespace gui {
case TICK: // ignored case TICK: // ignored
break; break;
default: default:
dbc::sentinel(fmt::format("invalid event: {}", int(ev))); dbc::log(fmt::format("invalid event: {}", int(ev)));
} }
} }
@ -296,15 +297,22 @@ namespace gui {
* Dropping on the ground is only possible from the * Dropping on the ground is only possible from the
* status_ui for now. * status_ui for now.
*/ */
bool DNDLoot::throw_on_floor() { bool DNDLoot::throw_on_floor(guecs::UI& gui, bool from_status) {
dbc::check($grab_source != std::nullopt, "attempt to commit_drop but no grab_source set"); dbc::check($grab_source != std::nullopt, "attempt to commit_drop but no grab_source set");
dbc::check($status_ui.$gui.has<guecs::GrabSource>(*$grab_source), dbc::check(gui.has<guecs::GrabSource>(*$grab_source),
"StatusUI doesn't actually have that GrabSource in the gui."); "StatusUI doesn't actually have that GrabSource in the gui.");
auto& grab = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source); auto& grab = gui.get<guecs::GrabSource>(*$grab_source);
grab.commit(); grab.commit();
bool result = $status_ui.drop_item(grab.world_entity); bool result = false;
if(from_status) {
result = $status_ui.drop_item(grab.world_entity);
} else {
result = $loot_ui.drop_item(grab.world_entity);
}
clear_grab(); clear_grab();
return result; return result;
} }

@ -54,7 +54,7 @@ namespace gui {
bool hold_world_item(); bool hold_world_item();
bool hold_inv_item(std::any& data); bool hold_inv_item(std::any& data);
bool throw_on_floor(); bool throw_on_floor(guecs::UI& gui, bool from_status);
void clear_grab(); void clear_grab();

@ -463,15 +463,17 @@ namespace gui {
case eGUI::INV_SELECT: case eGUI::INV_SELECT:
event(Event::INV_SELECT, data); event(Event::INV_SELECT, data);
break; break;
case eGUI::AIM_CLICK: case eGUI::AIM_CLICK: {
if(auto aimed_at = $main_ui.camera_aim()) { auto aimed_at = $main_ui.camera_aim();
fmt::println("clicked on a thing: {}", aimed_at);
System::pickup($level, aimed_at); if(aimed_at && !in_state(State::LOOTING)) {
} else { // aimed at something and not looting so it's a pickup
fmt::println("SENDING AIM_CLICK"); System::pickup($level, aimed_at);
event(Event::AIM_CLICK); } else {
} // otherwise just repeat the event and let the FSM deal
break; event(Event::AIM_CLICK);
}
} break;
case eGUI::LOOT_ITEM: { case eGUI::LOOT_ITEM: {
dbc::check(world.has<components::InventoryItem>(entity), dbc::check(world.has<components::InventoryItem>(entity),
"INVALID LOOT_ITEM, that entity has no InventoryItem"); "INVALID LOOT_ITEM, that entity has no InventoryItem");

@ -127,8 +127,13 @@ namespace gui {
update(); update();
} }
bool LootUI::drop_item(DinkyECS::Entity item_id) {
bool dropped = System::drop_item($level, item_id);
if(dropped) update();
return dropped;
}
bool LootUI::mouse(float x, float y, bool hover) { bool LootUI::mouse(float x, float y, bool hover) {
return $gui.mouse(x, y, hover); return $gui.mouse(x, y, hover);
} }
} }

@ -33,5 +33,6 @@ namespace gui {
void remove_slot(guecs::Entity slot_id); void remove_slot(guecs::Entity slot_id);
bool place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity); bool place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity);
void add_loose_item(DinkyECS::Entity entity); void add_loose_item(DinkyECS::Entity entity);
bool drop_item(DinkyECS::Entity item_id);
}; };
} }

Loading…
Cancel
Save