More of the drag/drop is handled by the GrabSource/DropTarget components.
This commit is contained in:
parent
7a551cf83a
commit
570b70ab0c
7 changed files with 36 additions and 81 deletions
|
@ -46,7 +46,9 @@ namespace gui {
|
|||
guecs::make_action(*$level.world, Events::GUI::INV_SELECT, {button})
|
||||
});
|
||||
$gui.set<DropTarget>(button, {
|
||||
.commit=[&, button]() -> bool { return place_slot(button); }
|
||||
.commit=[&, button](DinkyECS::Entity world_target) -> bool {
|
||||
return place_slot(button, world_target);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -83,13 +85,12 @@ namespace gui {
|
|||
init();
|
||||
}
|
||||
|
||||
bool StatusUI::place_slot(DinkyECS::Entity gui_id) {
|
||||
if($level.world->has<components::Sprite>($selected_entity)) {
|
||||
auto& sprite = $level.world->get<components::Sprite>($selected_entity);
|
||||
|
||||
bool StatusUI::place_slot(DinkyECS::Entity gui_id, DinkyECS::Entity world_entity) {
|
||||
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});
|
||||
|
||||
contents.insert_or_assign(gui_id, $selected_entity);
|
||||
$gui.set<guecs::GrabSource>(gui_id, {world_entity});
|
||||
contents.insert_or_assign(gui_id, world_entity);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -100,26 +101,15 @@ namespace gui {
|
|||
return $gui.get<guecs::DropTarget>(gui_id);
|
||||
}
|
||||
|
||||
void StatusUI::begin_drop(DinkyECS::Entity world_entity) {
|
||||
$selected_entity = world_entity;
|
||||
}
|
||||
|
||||
guecs::GrabSource& StatusUI::get_grab_source(DinkyECS::Entity gui_id) {
|
||||
dbc::check($gui.has<guecs::Sprite>(gui_id), "invalid GrabSource requested, entity isn't in the GUI.");
|
||||
dbc::check($gui.has<guecs::GrabSource>(gui_id), "invalid GrabSource requested, entity isn't in the GUI.");
|
||||
|
||||
return static_cast<guecs::GrabSource&>($gui.get<guecs::Sprite>(gui_id));
|
||||
}
|
||||
|
||||
std::optional<DinkyECS::Entity> StatusUI::begin_grab(DinkyECS::Entity slot_id) {
|
||||
if(!contents.contains(slot_id)) return std::nullopt;
|
||||
|
||||
auto& source = get_grab_source(slot_id);
|
||||
source.grab();
|
||||
return contents.at(slot_id);
|
||||
return $gui.get<guecs::GrabSource>(gui_id);
|
||||
}
|
||||
|
||||
void StatusUI::commit_grab(DinkyECS::Entity slot_id) {
|
||||
contents.erase(slot_id);
|
||||
$gui.remove<guecs::GrabSource>(slot_id);
|
||||
$gui.remove<guecs::Sprite>(slot_id);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue