diff --git a/gui/fsm.cpp b/gui/fsm.cpp index 9573f9e..1db8924 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -154,7 +154,6 @@ namespace gui { } $window.setMouseCursorVisible(true); - dbc::log("INV_SELECT back to looting"); state(State::LOOTING); } } break; @@ -184,10 +183,6 @@ namespace gui { } void FSM::INV_GRAB(Event ev, std::any data) { - dbc::log("INV_SELECT NOT IMPlEMENTED"); - state(State::LOOTING); - return; - using enum Event; (void)data; @@ -197,21 +192,48 @@ namespace gui { state(State::IDLE); break; case LOOT_SELECT: { - state(State::IDLE); + auto gui_id = std::any_cast(data); + + if($grab_source) { + if($loot_ui.commit_drop(gui_id)) { + $status_ui.commit_grab(*$grab_source); + $grab_source = std::nullopt; + } + + //$window.setMouseCursorVisible(true); + state(State::LOOTING); + } } break; case INV_SELECT: { - state(State::IDLE); + $grab_source = std::any_cast(data); + + if(auto world_entity = $status_ui.begin_grab(*$grab_source)) { + //$window.setMouseCursorVisible(false); + $loot_ui.begin_drop(*world_entity); + } else { + // BUG: need a cancel operation here + //$window.setMouseCursorVisible(true); + $grab_source = std::nullopt; + } } break; case MOUSE_CLICK: mouse_action(false); break; case MOUSE_MOVE: { + if($grab_source) { + auto& source = $status_ui.get_grab_source(*$grab_source); + source.move($router.position); + } mouse_action(true); } break; case MOUSE_DRAG_START: { mouse_action(false); } break; case MOUSE_DRAG: { + if($grab_source) { + auto& source = $status_ui.get_grab_source(*$grab_source); + source.move($router.position); + } mouse_action(true); } break; case MOUSE_DROP: @@ -235,9 +257,8 @@ namespace gui { state(State::LOOT_GRAB); break; case INV_SELECT: - dbc::log("INV_SELECT disabled in FSM::LOOTING"); - state(State::IDLE); - // INV_GRAB(ev, data); + state(State::INV_GRAB); + INV_GRAB(ev, data); break; case MOUSE_DRAG_START: case MOUSE_CLICK: @@ -313,8 +334,7 @@ namespace gui { state(State::LOOTING); } break; case INV_SELECT: - dbc::log("INV_SELECT disabled in IDLE"); - // state(State::INV_GRAB); + state(State::INV_GRAB); break; case MOUSE_CLICK: mouse_action(false); diff --git a/gui/loot_ui.cpp b/gui/loot_ui.cpp index 45ea096..e11271a 100644 --- a/gui/loot_ui.cpp +++ b/gui/loot_ui.cpp @@ -78,10 +78,25 @@ namespace gui { auto& sprite = $level.world->get(item); guecs::GrabSource grabber{sprite.name}; $gui.set_init(id, grabber); + } else { + $gui.set(id, { + [&, id]() -> bool { return place_slot(id); } + }); } } } + bool LootUI::place_slot(DinkyECS::Entity id) { + if(contents.size() < INV_SLOTS && !contents.contains(id)) { + contents.try_emplace(id, $selected_entity); + dbc::log(fmt::format("adding entity {}", id)); + update(); + return true; + } else { + return false; + } + } + bool LootUI::has_grab_source(DinkyECS::Entity gui_id) { return $gui.has(gui_id); } @@ -109,4 +124,19 @@ namespace gui { guecs::DropTarget& LootUI::get_drop_target(DinkyECS::Entity gui_id) { return $gui.get(gui_id); } + + void LootUI::begin_drop(DinkyECS::Entity world_entity) { + dbc::log("begin the loot drop"); + $selected_entity = world_entity; + } + + bool LootUI::commit_drop(DinkyECS::Entity gui_id) { + if($gui.has(gui_id)) { + auto& drop = get_drop_target(gui_id); + return drop.commit(); + } else { + // NOTE: I think I need to cancel the drop or something? + return false; + } + } } diff --git a/gui/loot_ui.hpp b/gui/loot_ui.hpp index d45ac2e..97d0d0a 100644 --- a/gui/loot_ui.hpp +++ b/gui/loot_ui.hpp @@ -13,6 +13,7 @@ namespace gui { guecs::UI $gui; GameLevel $level; std::unordered_map contents; + DinkyECS::Entity $selected_entity; LootUI(GameLevel level); @@ -30,7 +31,8 @@ namespace gui { guecs::DropTarget& get_drop_target(DinkyECS::Entity gui_id); - void begin_drop(DinkyECS::Entity entity); - void commit_drop(DinkyECS::Entity entity); + void begin_drop(DinkyECS::Entity world_entity); + bool commit_drop(DinkyECS::Entity gui_id); + bool place_slot(DinkyECS::Entity id); }; } diff --git a/gui/status_ui.cpp b/gui/status_ui.cpp index 40baf7e..fd2d1bb 100644 --- a/gui/status_ui.cpp +++ b/gui/status_ui.cpp @@ -100,13 +100,13 @@ namespace gui { return $gui.get(gui_id); } - void StatusUI::begin_drop(DinkyECS::Entity entity) { - $selected_entity = entity; + void StatusUI::begin_drop(DinkyECS::Entity world_entity) { + $selected_entity = world_entity; } bool StatusUI::commit_drop(DinkyECS::Entity gui_id) { + // BUG: just roll this into DropTarget auto& drop = get_drop_target(gui_id); - return drop.commit(); } @@ -121,11 +121,17 @@ namespace gui { } std::optional StatusUI::begin_grab(DinkyECS::Entity slot_id) { - (void)slot_id; - return std::nullopt; + // BET CHAT: I'll have to change this to a full if-else later + + if(!$slots.contains(slot_id)) return std::nullopt; + + auto& source = get_grab_source(slot_id); + source.grab(); + return $slots.at(slot_id); } void StatusUI::commit_grab(DinkyECS::Entity slot_id) { - (void)slot_id; + $slots.erase(slot_id); + $gui.remove(slot_id); } } diff --git a/gui/status_ui.hpp b/gui/status_ui.hpp index 929a2e0..93ef6ed 100644 --- a/gui/status_ui.hpp +++ b/gui/status_ui.hpp @@ -32,7 +32,7 @@ namespace gui { void commit_grab(DinkyECS::Entity slot_id); guecs::DropTarget& get_drop_target(DinkyECS::Entity gui_id); - void begin_drop(DinkyECS::Entity entity); - bool commit_drop(DinkyECS::Entity entity); + void begin_drop(DinkyECS::Entity world_entity); + bool commit_drop(DinkyECS::Entity gui_id); }; }