Fix the last few loot bugs before actually implementing the data model for inventory and loot.

master
Zed A. Shaw 1 week ago
parent 4a48910273
commit d6c5a89251
  1. 15
      assets/items.json
  2. 26
      gui/fsm.cpp
  3. 20
      gui/loot_ui.cpp

@ -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",

@ -136,6 +136,7 @@ namespace gui {
case LOOT_SELECT: {
auto gui_id = std::any_cast<guecs::Entity>(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<DinkyECS::Entity>(data);
$grab_source = UISystem::loot_grab($status_ui.$gui, gui_id);
auto gui_id = std::any_cast<DinkyECS::Entity>(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<guecs::Entity>(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<DinkyECS::Entity>(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);

@ -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<guecs::Sprite>(id)) {
$gui.remove<guecs::Sprite>(id);
}
if(contents.contains(id)) {
auto item = contents.at(id);
dbc::check($level.world->has<components::Sprite>(item),
@ -73,6 +64,12 @@ namespace gui {
grabber.setSprite($gui, id);
$gui.set<guecs::GrabSource>(id, grabber);
} else {
// BUG: fix remove so it's safe to call on empty
if($gui.has<guecs::GrabSource>(id)) {
$gui.remove<guecs::Sprite>(id);
$gui.remove<guecs::GrabSource>(id);
}
$gui.set<guecs::DropTarget>(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);

Loading…
Cancel
Save