|
|
@ -76,8 +76,12 @@ namespace gui { |
|
|
|
void StatusUI::update() { |
|
|
|
void StatusUI::update() { |
|
|
|
auto player = $level.world->get_the<components::Player>(); |
|
|
|
auto player = $level.world->get_the<components::Player>(); |
|
|
|
auto& inventory = $level.world->get<inventory::Model>(player.entity); |
|
|
|
auto& inventory = $level.world->get<inventory::Model>(player.entity); |
|
|
|
for(auto& [slot, world_entity] : inventory.by_slot) { |
|
|
|
|
|
|
|
|
|
|
|
for(const auto& [slot, cell] : $gui.cells()) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(inventory.has(slot)) { |
|
|
|
auto gui_id = $gui.entity(slot); |
|
|
|
auto gui_id = $gui.entity(slot); |
|
|
|
|
|
|
|
auto world_entity = inventory.get(slot); |
|
|
|
|
|
|
|
|
|
|
|
auto& sprite = $level.world->get<components::Sprite>(world_entity); |
|
|
|
auto& sprite = $level.world->get<components::Sprite>(world_entity); |
|
|
|
$gui.set_init<guecs::Icon>(gui_id, {sprite.name}); |
|
|
|
$gui.set_init<guecs::Icon>(gui_id, {sprite.name}); |
|
|
@ -85,6 +89,14 @@ namespace gui { |
|
|
|
[&, gui_id]() { return remove_slot(gui_id); }}; |
|
|
|
[&, gui_id]() { return remove_slot(gui_id); }}; |
|
|
|
grabber.setSprite($gui, gui_id); |
|
|
|
grabber.setSprite($gui, gui_id); |
|
|
|
$gui.set<guecs::GrabSource>(gui_id, grabber); |
|
|
|
$gui.set<guecs::GrabSource>(gui_id, grabber); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
auto gui_id = $gui.entity(slot); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($gui.has<guecs::GrabSource>(gui_id)) { |
|
|
|
|
|
|
|
$gui.remove<guecs::GrabSource>(gui_id); |
|
|
|
|
|
|
|
$gui.remove<guecs::Icon>(gui_id); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -123,8 +135,7 @@ namespace gui { |
|
|
|
void StatusUI::remove_slot(guecs::Entity slot_id) { |
|
|
|
void StatusUI::remove_slot(guecs::Entity slot_id) { |
|
|
|
auto& slot_name = $gui.name_for(slot_id); |
|
|
|
auto& slot_name = $gui.name_for(slot_id); |
|
|
|
System::remove_from_container(*$level.world, $level.player, slot_name); |
|
|
|
System::remove_from_container(*$level.world, $level.player, slot_name); |
|
|
|
$gui.remove<guecs::GrabSource>(slot_id); |
|
|
|
update(); |
|
|
|
$gui.remove<guecs::Icon>(slot_id); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void StatusUI::swap(guecs::Entity gui_a, guecs::Entity gui_b) { |
|
|
|
void StatusUI::swap(guecs::Entity gui_a, guecs::Entity gui_b) { |
|
|
|