|
|
|
@ -46,16 +46,6 @@ namespace gui { |
|
|
|
|
update(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::optional<DinkyECS::Entity> LootUI::begin_grab(DinkyECS::Entity slot_id) { |
|
|
|
|
if(contents.contains(slot_id)) { |
|
|
|
|
auto& source = get_grab_source(slot_id); |
|
|
|
|
source.grab(); |
|
|
|
|
return contents.at(slot_id); |
|
|
|
|
} else { |
|
|
|
|
return std::nullopt; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void LootUI::commit_grab(DinkyECS::Entity slot_id) { |
|
|
|
|
contents.erase(slot_id); |
|
|
|
|
update(); |
|
|
|
@ -76,20 +66,19 @@ namespace gui { |
|
|
|
|
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); |
|
|
|
|
$gui.set_init<guecs::Sprite>(id, {sprite.name}); |
|
|
|
|
$gui.set<guecs::GrabSource>(id, {item}); |
|
|
|
|
} else { |
|
|
|
|
$gui.set<guecs::DropTarget>(id, { |
|
|
|
|
[&, id]() -> bool { return place_slot(id); } |
|
|
|
|
[&, id](DinkyECS::Entity world_entity) -> bool { return place_slot(id, world_entity); } |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool LootUI::place_slot(DinkyECS::Entity id) { |
|
|
|
|
bool LootUI::place_slot(DinkyECS::Entity id, DinkyECS::Entity world_entity) { |
|
|
|
|
if(contents.size() < INV_SLOTS && !contents.contains(id)) { |
|
|
|
|
contents.try_emplace(id, $selected_entity); |
|
|
|
|
dbc::log(fmt::format("adding entity {}", id)); |
|
|
|
|
contents.try_emplace(id, world_entity); |
|
|
|
|
update(); |
|
|
|
|
return true; |
|
|
|
|
} else { |
|
|
|
@ -100,7 +89,7 @@ namespace gui { |
|
|
|
|
guecs::GrabSource& LootUI::get_grab_source(DinkyECS::Entity gui_id) { |
|
|
|
|
dbc::check($gui.has<guecs::Sprite>(gui_id), "invalid GrabSource requested, entity isn't in the GUI."); |
|
|
|
|
|
|
|
|
|
return static_cast<guecs::GrabSource&>($gui.get<guecs::Sprite>(gui_id)); |
|
|
|
|
return $gui.get<guecs::GrabSource>(gui_id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void LootUI::render(sf::RenderWindow& window) { |
|
|
|
@ -120,9 +109,4 @@ namespace gui { |
|
|
|
|
guecs::DropTarget& LootUI::get_drop_target(DinkyECS::Entity gui_id) { |
|
|
|
|
return $gui.get<guecs::DropTarget>(gui_id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void LootUI::begin_drop(DinkyECS::Entity world_entity) { |
|
|
|
|
dbc::log("begin the loot drop"); |
|
|
|
|
$selected_entity = world_entity; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|