Cleaned up the move operation more so that I can use it in the other places that I need it.
This commit is contained in:
parent
f559b5a39d
commit
6ff1919587
5 changed files with 52 additions and 8 deletions
|
@ -101,17 +101,18 @@ namespace gui {
|
|||
|
||||
void DNDLoot::INV_PICKUP(Event ev, std::any data) {
|
||||
using enum Event;
|
||||
(void)data;
|
||||
|
||||
switch(ev) {
|
||||
case AIM_CLICK: {
|
||||
fmt::println("IN INV_PICKUP AIM CLICK!");
|
||||
auto& grab = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
|
||||
grab.commit();
|
||||
bool dropped = $status_ui.drop_item(grab.world_entity);
|
||||
dbc::check(dropped, "DROP FAILED!");
|
||||
bool worked = throw_on_floor();
|
||||
dbc::check(worked, "Need to fix this, should be able to abort.");
|
||||
END(Event::CLOSE);
|
||||
} break;
|
||||
case INV_SELECT:
|
||||
// BUG: should I do a bool here and not transition?
|
||||
commit_move($status_ui.$gui, $grab_source, data);
|
||||
END(Event::CLOSE);
|
||||
} break;
|
||||
break;
|
||||
default:
|
||||
handle_mouse(ev, $status_ui.$gui);
|
||||
}
|
||||
|
@ -228,6 +229,13 @@ namespace gui {
|
|||
{
|
||||
if(!source_id) return false;
|
||||
auto target_id = std::any_cast<guecs::Entity>(data);
|
||||
fmt::println("!!!!!!!!!source_id = {} target_id = {}",
|
||||
*source_id, target_id);
|
||||
|
||||
dbc::check(target.has<guecs::DropTarget>(target_id),
|
||||
"gui does not have a DropTarget at that slot");
|
||||
dbc::check(source.has<guecs::GrabSource>(*source_id),
|
||||
"gui does not have a GrabSource at that slot");
|
||||
|
||||
auto& drop = target.get<guecs::DropTarget>(target_id);
|
||||
auto& grab = source.get<guecs::GrabSource>(*source_id);
|
||||
|
@ -239,4 +247,28 @@ namespace gui {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void DNDLoot::commit_move(guecs::UI& gui, std::optional<guecs::Entity> source_id, std::any data) {
|
||||
auto& grab = gui.get<guecs::GrabSource>(*source_id);
|
||||
grab.commit();
|
||||
|
||||
auto drop_id = std::any_cast<guecs::Entity>(data);
|
||||
auto& drop = gui.get<guecs::DropTarget>(drop_id);
|
||||
drop.commit(grab.world_entity);
|
||||
|
||||
// BUG: if the drop fails then need to put the grab back?
|
||||
// How to confirm the drop will work before doing it?
|
||||
// Or, maybe save the commit?
|
||||
}
|
||||
|
||||
/*
|
||||
* Dropping on the ground is only possible from the
|
||||
* status_ui for now.
|
||||
*/
|
||||
bool DNDLoot::throw_on_floor() {
|
||||
dbc::check($grab_source != std::nullopt, "attempt to commit_drop but no grab_source set");
|
||||
auto& grab = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
|
||||
grab.commit();
|
||||
return $status_ui.drop_item(grab.world_entity);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue