Basic loot UI mostly working. Each time you open there's a torch and you can place it visually on any slot on your character.
This commit is contained in:
parent
4b34de2109
commit
5c47a0151c
13 changed files with 123 additions and 46 deletions
|
@ -33,34 +33,57 @@ namespace gui {
|
|||
$gui.set<guecs::Clickable>(close,
|
||||
guecs::make_action(*$level.world, Events::GUI::LOOT_CLOSE));
|
||||
|
||||
for(int i = 0; i < INV_SLOTS; i++) {
|
||||
auto id = $gui.entity("item_", i);
|
||||
$gui.set<guecs::Rectangle>(id, {THEME.PADDING,
|
||||
THEME.TRANSPARENT, THEME.LIGHT_MID });
|
||||
$gui.set<guecs::Effect>(id, {0.4f, "ui_shader"});
|
||||
$gui.set<guecs::Clickable>(id, {
|
||||
guecs::make_action(*$level.world, Events::GUI::LOOT_SELECT, {i})
|
||||
});
|
||||
}
|
||||
|
||||
$gui.init();
|
||||
update();
|
||||
}
|
||||
|
||||
void LootUI::update() {
|
||||
dbc::check(contents.size() < 16, "too many items in loot contents, must be < 16");
|
||||
for(int i = 0; i < 16; i++) {
|
||||
auto id = $gui.entity("item_", i);
|
||||
if($gui.has<guecs::Rectangle>(id)) {
|
||||
$gui.remove<guecs::Rectangle>(id);
|
||||
$gui.remove<guecs::Effect>(id);
|
||||
$gui.remove<guecs::Clickable>(id);
|
||||
$gui.remove<guecs::Sprite>(id);
|
||||
}
|
||||
std::optional<DinkyECS::Entity> LootUI::select_slot(int slot_id) {
|
||||
if(size_t(slot_id) < contents.size()) {
|
||||
return contents.at(slot_id);
|
||||
} else {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
for(size_t item_i = 0; item_i < contents.size(); item_i++) {
|
||||
auto id = $gui.entity("item_", int(item_i));
|
||||
$gui.set_init<guecs::Rectangle>(id, {THEME.PADDING,
|
||||
THEME.TRANSPARENT, THEME.LIGHT_MID });
|
||||
$gui.set_init<guecs::Effect>(id, {0.4f, "ui_shader"});
|
||||
$gui.set<guecs::Clickable>(id, {
|
||||
[=](auto, auto) { fmt::println("clicked button"); }
|
||||
});
|
||||
void LootUI::remove_slot(int slot_id) {
|
||||
dbc::check(size_t(slot_id) < contents.size(),
|
||||
fmt::format("invalid slot id {} give, contents.size={}",
|
||||
slot_id, contents.size()));
|
||||
|
||||
auto item = contents.at(item_i);
|
||||
auto& sprite = $level.world->get<components::Sprite>(item);
|
||||
$gui.set_init<guecs::Sprite>(id, {sprite.name});
|
||||
contents.erase(contents.begin() + 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));
|
||||
|
||||
fmt::println("checking for sprite at {}", id);
|
||||
if($gui.has<guecs::Sprite>(id)) {
|
||||
fmt::println("REMOVING SPRITE {}", id);
|
||||
$gui.remove<guecs::Sprite>(id);
|
||||
} else {
|
||||
fmt::println("nothing at {}", id);
|
||||
}
|
||||
|
||||
if(i < contents.size()) {
|
||||
auto item = contents.at(i);
|
||||
auto& sprite = $level.world->get<components::Sprite>(item);
|
||||
fmt::println("NEW SPRITE SPRITE {}", sprite.name);
|
||||
$gui.set_init<guecs::Sprite>(id, {sprite.name});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue