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. 22
      gui/fsm.cpp
  3. 20
      gui/loot_ui.cpp

@ -28,21 +28,6 @@
], ],
"inventory_count": 1 "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": { "POTION_HEALING_SMALL": {
"id": "POTION_HEALING_SMALL", "id": "POTION_HEALING_SMALL",
"name": "Small Healing Potion", "name": "Small Healing Potion",

@ -136,6 +136,7 @@ namespace gui {
case LOOT_SELECT: { case LOOT_SELECT: {
auto gui_id = std::any_cast<guecs::Entity>(data); auto gui_id = std::any_cast<guecs::Entity>(data);
$grab_source = UISystem::loot_grab($loot_ui.$gui, gui_id); $grab_source = UISystem::loot_grab($loot_ui.$gui, gui_id);
if(!$grab_source) state(State::LOOTING);
} break; } break;
case INV_SELECT: { case INV_SELECT: {
if($grab_source) { if($grab_source) {
@ -197,6 +198,7 @@ namespace gui {
case INV_SELECT: { case INV_SELECT: {
auto gui_id = std::any_cast<DinkyECS::Entity>(data); auto gui_id = std::any_cast<DinkyECS::Entity>(data);
$grab_source = UISystem::loot_grab($status_ui.$gui, gui_id); $grab_source = UISystem::loot_grab($status_ui.$gui, gui_id);
if(!$grab_source) state(State::LOOTING);
} break; } break;
case MOUSE_CLICK: case MOUSE_CLICK:
mouse_action(false); mouse_action(false);
@ -228,16 +230,16 @@ namespace gui {
$loot_ui.active = false; $loot_ui.active = false;
state(State::IDLE); state(State::IDLE);
break; break;
case LOOT_SELECT: case LOOT_SELECT: {
// BUG: this actually should init the select, so that in LOOT_GRAB auto gui_id = std::any_cast<guecs::Entity>(data);
// I can allow people to place it back into the loot ui $grab_source = UISystem::loot_grab($loot_ui.$gui, gui_id);
state(State::LOOT_GRAB); if($grab_source) state(State::LOOT_GRAB);
LOOT_GRAB(ev, data); } break;
break; case INV_SELECT: {
case INV_SELECT: auto gui_id = std::any_cast<DinkyECS::Entity>(data);
state(State::INV_GRAB); $grab_source = UISystem::loot_grab($status_ui.$gui, gui_id);
INV_GRAB(ev, data); if($grab_source) state(State::INV_GRAB);
break; } break;
case MOUSE_DRAG_START: case MOUSE_DRAG_START:
case MOUSE_CLICK: case MOUSE_CLICK:
mouse_action(false); mouse_action(false);

@ -46,21 +46,12 @@ namespace gui {
update(); update();
} }
void LootUI::remove_slot(DinkyECS::Entity slot_id) {
contents.erase(slot_id);
update();
}
void LootUI::update() { void LootUI::update() {
dbc::check(contents.size() < INV_SLOTS, "too many items in loot contents, must be < 16"); dbc::check(contents.size() < INV_SLOTS, "too many items in loot contents, must be < 16");
for(size_t i = 0; i < INV_SLOTS; i++) { for(size_t i = 0; i < INV_SLOTS; i++) {
auto id = $gui.entity("item_", int(i)); auto id = $gui.entity("item_", int(i));
if($gui.has<guecs::Sprite>(id)) {
$gui.remove<guecs::Sprite>(id);
}
if(contents.contains(id)) { if(contents.contains(id)) {
auto item = contents.at(id); auto item = contents.at(id);
dbc::check($level.world->has<components::Sprite>(item), dbc::check($level.world->has<components::Sprite>(item),
@ -73,6 +64,12 @@ namespace gui {
grabber.setSprite($gui, id); grabber.setSprite($gui, id);
$gui.set<guecs::GrabSource>(id, grabber); $gui.set<guecs::GrabSource>(id, grabber);
} else { } 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, { $gui.set<guecs::DropTarget>(id, {
[&, id](DinkyECS::Entity world_entity) -> bool { return place_slot(id, world_entity); } [&, 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) { bool LootUI::place_slot(DinkyECS::Entity id, DinkyECS::Entity world_entity) {
if(contents.size() < INV_SLOTS && !contents.contains(id)) { if(contents.size() < INV_SLOTS && !contents.contains(id)) {
contents.try_emplace(id, world_entity); contents.try_emplace(id, world_entity);

Loading…
Cancel
Save