Taking things from the LootUI to the StatusUI works way better now and there's a DropTarget to match the GrabSource.

This commit is contained in:
Zed A. Shaw 2025-06-08 00:37:30 -04:00
parent 842aac3127
commit 461ad03d27
8 changed files with 93 additions and 70 deletions

View file

@ -38,7 +38,7 @@ namespace gui {
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})
guecs::make_action(*$level.world, Events::GUI::LOOT_SELECT, {id})
});
}
@ -46,20 +46,16 @@ namespace gui {
update();
}
std::optional<DinkyECS::Entity> LootUI::select_slot(int slot_id) {
if(slot_id >= 0 && size_t(slot_id) < contents.size()) {
std::optional<DinkyECS::Entity> LootUI::select_slot(DinkyECS::Entity slot_id) {
if(contents.contains(slot_id)) {
return contents.at(slot_id);
} else {
return std::nullopt;
}
}
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()));
contents.erase(contents.begin() + slot_id);
void LootUI::remove_slot(DinkyECS::Entity slot_id) {
contents.erase(slot_id);
update();
}
@ -73,8 +69,10 @@ namespace gui {
$gui.remove<guecs::Sprite>(id);
}
if(i < contents.size()) {
auto item = contents.at(i);
if(contents.contains(id)) {
auto item = contents.at(id);
dbc::check($level.world->has<components::Sprite>(item),
"item in inventory UI doesn't exist in world. New level?");
auto& sprite = $level.world->get<components::Sprite>(item);
guecs::GrabSource grabber{sprite.name};
$gui.set_init<guecs::Sprite>(id, grabber);
@ -82,8 +80,14 @@ namespace gui {
}
}
guecs::GrabSource& LootUI::get_grabber(DinkyECS::Entity entity) {
return static_cast<guecs::GrabSource&>($gui.get<guecs::Sprite>(entity));
bool LootUI::has_grabber(DinkyECS::Entity gui_id) {
return $gui.has<guecs::Sprite>(gui_id);
}
guecs::GrabSource& LootUI::get_grabber(DinkyECS::Entity gui_id) {
dbc::check(has_grabber(gui_id), "invalid GrabSource requested, entity isn't in the GUI.");
return static_cast<guecs::GrabSource&>($gui.get<guecs::Sprite>(gui_id));
}
void LootUI::render(sf::RenderWindow& window) {
@ -92,6 +96,7 @@ namespace gui {
void LootUI::update_level(GameLevel &level) {
$level = level;
contents.clear();
init();
}