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

master
Zed A. Shaw 7 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
test: build
./builddir/runtests
./builddir/runtests "[inventory]"
run: build test
ifeq '$(OS)' 'Windows_NT'
@ -57,7 +57,7 @@ clean:
meson compile --clean -C builddir
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:
powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp'

@ -107,7 +107,8 @@ namespace gui {
switch(ev) {
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.");
END(CLOSE);
} break;
@ -137,12 +138,12 @@ namespace gui {
END(CLOSE);
}
break;
case AIM_CLICK:
// BUG: because I put things into fake loot containers it's actually
// hard to put things back. It's probably a System::remove from the
// loot container combined with a System::drop_item
dbc::log("Put it back?");
break;
case AIM_CLICK: {
// THIS IS PUT IT BACK ON THE FLOOR
bool worked = throw_on_floor($loot_ui.$gui, false);
dbc::check(worked, "Failed to drop it back on the floor.");
END(CLOSE);
} break;
default:
handle_mouse(ev, $loot_ui.$gui);
}
@ -174,7 +175,7 @@ namespace gui {
case TICK: // ignored
break;
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
* 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($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.");
auto& grab = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
auto& grab = gui.get<guecs::GrabSource>(*$grab_source);
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();
return result;
}

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

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

@ -127,8 +127,13 @@ namespace gui {
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) {
return $gui.mouse(x, y, hover);
}
}

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

Loading…
Cancel
Save