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.
This commit is contained in:
parent
570b70ab0c
commit
be7b86a913
6 changed files with 17 additions and 13 deletions
|
@ -145,7 +145,7 @@ namespace gui {
|
||||||
auto& grab = $loot_ui.get_grab_source(*$grab_source);
|
auto& grab = $loot_ui.get_grab_source(*$grab_source);
|
||||||
|
|
||||||
if(drop.commit(grab.world_entity)) {
|
if(drop.commit(grab.world_entity)) {
|
||||||
$loot_ui.commit_grab(*$grab_source);
|
grab.commit();
|
||||||
$grab_source = std::nullopt;
|
$grab_source = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ namespace gui {
|
||||||
auto& grab = $status_ui.get_grab_source(*$grab_source);
|
auto& grab = $status_ui.get_grab_source(*$grab_source);
|
||||||
|
|
||||||
if(drop.commit(grab.world_entity)) {
|
if(drop.commit(grab.world_entity)) {
|
||||||
$status_ui.commit_grab(*$grab_source);
|
grab.commit();
|
||||||
$grab_source = std::nullopt;
|
$grab_source = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,8 @@ namespace guecs {
|
||||||
Clickable make_action(DinkyECS::World& target, Events::GUI event, std::any data);
|
Clickable make_action(DinkyECS::World& target, Events::GUI event, std::any data);
|
||||||
|
|
||||||
struct GrabSource {
|
struct GrabSource {
|
||||||
DinkyECS::Entity world_entity = 0;
|
DinkyECS::Entity world_entity;
|
||||||
|
std::function<void()> commit;
|
||||||
|
|
||||||
DinkyECS::Entity grab();
|
DinkyECS::Entity grab();
|
||||||
void move(sf::Vector2i position);
|
void move(sf::Vector2i position);
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace gui {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LootUI::commit_grab(DinkyECS::Entity slot_id) {
|
void LootUI::remove_slot(DinkyECS::Entity slot_id) {
|
||||||
contents.erase(slot_id);
|
contents.erase(slot_id);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,8 @@ namespace gui {
|
||||||
"item in inventory UI doesn't exist in world. New level?");
|
"item in inventory UI doesn't exist in world. New level?");
|
||||||
auto& sprite = $level.world->get<components::Sprite>(item);
|
auto& sprite = $level.world->get<components::Sprite>(item);
|
||||||
$gui.set_init<guecs::Sprite>(id, {sprite.name});
|
$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 {
|
} else {
|
||||||
$gui.set<guecs::DropTarget>(id, {
|
$gui.set<guecs::DropTarget>(id, {
|
||||||
[&, id](DinkyECS::Entity world_entity) -> bool { return place_slot(id, world_entity); }
|
[&, 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);
|
guecs::GrabSource& get_grab_source(DinkyECS::Entity entity);
|
||||||
|
|
||||||
std::optional<DinkyECS::Entity> begin_grab(DinkyECS::Entity slot);
|
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);
|
guecs::DropTarget& get_drop_target(DinkyECS::Entity gui_id);
|
||||||
bool place_slot(DinkyECS::Entity gui_id, DinkyECS::Entity world_entity);
|
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)) {
|
if($level.world->has<components::Sprite>(world_entity)) {
|
||||||
auto& sprite = $level.world->get<components::Sprite>(world_entity);
|
auto& sprite = $level.world->get<components::Sprite>(world_entity);
|
||||||
$gui.set_init<guecs::Sprite>(gui_id, {sprite.name});
|
$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);
|
contents.insert_or_assign(gui_id, world_entity);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -107,9 +108,11 @@ namespace gui {
|
||||||
return $gui.get<guecs::GrabSource>(gui_id);
|
return $gui.get<guecs::GrabSource>(gui_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatusUI::commit_grab(DinkyECS::Entity slot_id) {
|
void StatusUI::remove_slot(DinkyECS::Entity slot_id) {
|
||||||
contents.erase(slot_id);
|
if(contents.contains(slot_id)) {
|
||||||
$gui.remove<guecs::GrabSource>(slot_id);
|
contents.erase(slot_id);
|
||||||
$gui.remove<guecs::Sprite>(slot_id);
|
$gui.remove<guecs::GrabSource>(slot_id);
|
||||||
|
$gui.remove<guecs::Sprite>(slot_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,8 @@ namespace gui {
|
||||||
void update();
|
void update();
|
||||||
bool mouse(float x, float y, bool hover);
|
bool mouse(float x, float y, bool hover);
|
||||||
|
|
||||||
|
|
||||||
guecs::GrabSource& get_grab_source(DinkyECS::Entity entity);
|
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);
|
guecs::DropTarget& get_drop_target(DinkyECS::Entity gui_id);
|
||||||
bool place_slot(DinkyECS::Entity gui_id, DinkyECS::Entity world_entity);
|
bool place_slot(DinkyECS::Entity gui_id, DinkyECS::Entity world_entity);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue