Mostly refactored out the common things for drag/drop so now just to refine how it's used and bring back moving the sprite around.

master
Zed A. Shaw 1 week ago
parent 570b70ab0c
commit be7b86a913
  1. 4
      gui/fsm.cpp
  2. 3
      gui/guecstra.hpp
  3. 5
      gui/loot_ui.cpp
  4. 2
      gui/loot_ui.hpp
  5. 7
      gui/status_ui.cpp
  6. 3
      gui/status_ui.hpp

@ -145,7 +145,7 @@ namespace gui {
auto& grab = $loot_ui.get_grab_source(*$grab_source);
if(drop.commit(grab.world_entity)) {
$loot_ui.commit_grab(*$grab_source);
grab.commit();
$grab_source = std::nullopt;
}
@ -193,7 +193,7 @@ namespace gui {
auto& grab = $status_ui.get_grab_source(*$grab_source);
if(drop.commit(grab.world_entity)) {
$status_ui.commit_grab(*$grab_source);
grab.commit();
$grab_source = std::nullopt;
}

@ -9,7 +9,8 @@ namespace guecs {
Clickable make_action(DinkyECS::World& target, Events::GUI event, std::any data);
struct GrabSource {
DinkyECS::Entity world_entity = 0;
DinkyECS::Entity world_entity;
std::function<void()> commit;
DinkyECS::Entity grab();
void move(sf::Vector2i position);

@ -46,7 +46,7 @@ namespace gui {
update();
}
void LootUI::commit_grab(DinkyECS::Entity slot_id) {
void LootUI::remove_slot(DinkyECS::Entity slot_id) {
contents.erase(slot_id);
update();
}
@ -67,7 +67,8 @@ namespace gui {
"item in inventory UI doesn't exist in world. New level?");
auto& sprite = $level.world->get<components::Sprite>(item);
$gui.set_init<guecs::Sprite>(id, {sprite.name});
$gui.set<guecs::GrabSource>(id, {item});
$gui.set<guecs::GrabSource>(id, {
item, [&, id]() { return remove_slot(id); }});
} else {
$gui.set<guecs::DropTarget>(id, {
[&, id](DinkyECS::Entity world_entity) -> bool { return place_slot(id, world_entity); }

@ -24,7 +24,7 @@ namespace gui {
guecs::GrabSource& get_grab_source(DinkyECS::Entity entity);
std::optional<DinkyECS::Entity> begin_grab(DinkyECS::Entity slot);
void commit_grab(DinkyECS::Entity slot_id);
void remove_slot(DinkyECS::Entity slot_id);
guecs::DropTarget& get_drop_target(DinkyECS::Entity gui_id);
bool place_slot(DinkyECS::Entity gui_id, DinkyECS::Entity world_entity);

@ -89,7 +89,8 @@ namespace gui {
if($level.world->has<components::Sprite>(world_entity)) {
auto& sprite = $level.world->get<components::Sprite>(world_entity);
$gui.set_init<guecs::Sprite>(gui_id, {sprite.name});
$gui.set<guecs::GrabSource>(gui_id, {world_entity});
$gui.set<guecs::GrabSource>(gui_id, {world_entity,
[&, gui_id]() { return remove_slot(gui_id); }});
contents.insert_or_assign(gui_id, world_entity);
return true;
} else {
@ -107,9 +108,11 @@ namespace gui {
return $gui.get<guecs::GrabSource>(gui_id);
}
void StatusUI::commit_grab(DinkyECS::Entity slot_id) {
void StatusUI::remove_slot(DinkyECS::Entity slot_id) {
if(contents.contains(slot_id)) {
contents.erase(slot_id);
$gui.remove<guecs::GrabSource>(slot_id);
$gui.remove<guecs::Sprite>(slot_id);
}
}
}

@ -23,9 +23,8 @@ namespace gui {
void update();
bool mouse(float x, float y, bool hover);
guecs::GrabSource& get_grab_source(DinkyECS::Entity entity);
void commit_grab(DinkyECS::Entity slot_id);
void remove_slot(DinkyECS::Entity slot_id);
guecs::DropTarget& get_drop_target(DinkyECS::Entity gui_id);
bool place_slot(DinkyECS::Entity gui_id, DinkyECS::Entity world_entity);

Loading…
Cancel
Save