From d6c5a89251e67709c7dab96e86ff5b76d6ba5f1e Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Tue, 10 Jun 2025 22:58:57 -0400 Subject: [PATCH] Fix the last few loot bugs before actually implementing the data model for inventory and loot. --- assets/items.json | 15 --------------- gui/fsm.cpp | 26 ++++++++++++++------------ gui/loot_ui.cpp | 20 +++++++++++--------- 3 files changed, 25 insertions(+), 36 deletions(-) diff --git a/assets/items.json b/assets/items.json index 109fab9..ee75cd3 100644 --- a/assets/items.json +++ b/assets/items.json @@ -28,21 +28,6 @@ ], "inventory_count": 1 }, - "TORCH_PILLAR": { - "id": "TORCH_PILLAR", - "name": "Light Hanging from Ceiling", - "description": "Light Hanging from Ceiling", - "inventory_count": 0, - "components": [ - {"_type": "Tile", "display": 1918, - "foreground": [24, 205, 210], - "background": [24, 205, 210] - }, - {"_type": "LightSource", "strength": 50, "radius": 2.8}, - {"_type": "Sprite", "name": "torch_pillar", "width": 256, "height": 256, "scale": 1.0}, - {"_type": "Sound", "attack": "pickup", "death": "blank"} - ] - }, "POTION_HEALING_SMALL": { "id": "POTION_HEALING_SMALL", "name": "Small Healing Potion", diff --git a/gui/fsm.cpp b/gui/fsm.cpp index cdaba54..02055f5 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -136,6 +136,7 @@ namespace gui { case LOOT_SELECT: { auto gui_id = std::any_cast(data); $grab_source = UISystem::loot_grab($loot_ui.$gui, gui_id); + if(!$grab_source) state(State::LOOTING); } break; case INV_SELECT: { if($grab_source) { @@ -195,8 +196,9 @@ namespace gui { } } break; case INV_SELECT: { - auto gui_id = std::any_cast(data); - $grab_source = UISystem::loot_grab($status_ui.$gui, gui_id); + auto gui_id = std::any_cast(data); + $grab_source = UISystem::loot_grab($status_ui.$gui, gui_id); + if(!$grab_source) state(State::LOOTING); } break; case MOUSE_CLICK: mouse_action(false); @@ -228,16 +230,16 @@ namespace gui { $loot_ui.active = false; state(State::IDLE); break; - case LOOT_SELECT: - // BUG: this actually should init the select, so that in LOOT_GRAB - // I can allow people to place it back into the loot ui - state(State::LOOT_GRAB); - LOOT_GRAB(ev, data); - break; - case INV_SELECT: - state(State::INV_GRAB); - INV_GRAB(ev, data); - break; + case LOOT_SELECT: { + auto gui_id = std::any_cast(data); + $grab_source = UISystem::loot_grab($loot_ui.$gui, gui_id); + if($grab_source) state(State::LOOT_GRAB); + } break; + case INV_SELECT: { + auto gui_id = std::any_cast(data); + $grab_source = UISystem::loot_grab($status_ui.$gui, gui_id); + if($grab_source) state(State::INV_GRAB); + } break; case MOUSE_DRAG_START: case MOUSE_CLICK: mouse_action(false); diff --git a/gui/loot_ui.cpp b/gui/loot_ui.cpp index 4afe2f8..a17bf18 100644 --- a/gui/loot_ui.cpp +++ b/gui/loot_ui.cpp @@ -46,21 +46,12 @@ namespace gui { update(); } - void LootUI::remove_slot(DinkyECS::Entity slot_id) { - contents.erase(slot_id); - update(); - } - void LootUI::update() { dbc::check(contents.size() < INV_SLOTS, "too many items in loot contents, must be < 16"); for(size_t i = 0; i < INV_SLOTS; i++) { auto id = $gui.entity("item_", int(i)); - if($gui.has(id)) { - $gui.remove(id); - } - if(contents.contains(id)) { auto item = contents.at(id); dbc::check($level.world->has(item), @@ -73,6 +64,12 @@ namespace gui { grabber.setSprite($gui, id); $gui.set(id, grabber); } else { + // BUG: fix remove so it's safe to call on empty + if($gui.has(id)) { + $gui.remove(id); + $gui.remove(id); + } + $gui.set(id, { [&, id](DinkyECS::Entity world_entity) -> bool { return place_slot(id, world_entity); } }); @@ -80,6 +77,11 @@ namespace gui { } } + void LootUI::remove_slot(DinkyECS::Entity slot_id) { + contents.erase(slot_id); + update(); + } + bool LootUI::place_slot(DinkyECS::Entity id, DinkyECS::Entity world_entity) { if(contents.size() < INV_SLOTS && !contents.contains(id)) { contents.try_emplace(id, world_entity);