|
|
@ -101,17 +101,18 @@ namespace gui { |
|
|
|
|
|
|
|
|
|
|
|
void DNDLoot::INV_PICKUP(Event ev, std::any data) { |
|
|
|
void DNDLoot::INV_PICKUP(Event ev, std::any data) { |
|
|
|
using enum Event; |
|
|
|
using enum Event; |
|
|
|
(void)data; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch(ev) { |
|
|
|
switch(ev) { |
|
|
|
case AIM_CLICK: { |
|
|
|
case AIM_CLICK: { |
|
|
|
fmt::println("IN INV_PICKUP AIM CLICK!"); |
|
|
|
bool worked = throw_on_floor(); |
|
|
|
auto& grab = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source); |
|
|
|
dbc::check(worked, "Need to fix this, should be able to abort."); |
|
|
|
grab.commit(); |
|
|
|
|
|
|
|
bool dropped = $status_ui.drop_item(grab.world_entity); |
|
|
|
|
|
|
|
dbc::check(dropped, "DROP FAILED!"); |
|
|
|
|
|
|
|
END(Event::CLOSE); |
|
|
|
END(Event::CLOSE); |
|
|
|
} break; |
|
|
|
} 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; |
|
|
|
default: |
|
|
|
default: |
|
|
|
handle_mouse(ev, $status_ui.$gui); |
|
|
|
handle_mouse(ev, $status_ui.$gui); |
|
|
|
} |
|
|
|
} |
|
|
@ -228,6 +229,13 @@ namespace gui { |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(!source_id) return false; |
|
|
|
if(!source_id) return false; |
|
|
|
auto target_id = std::any_cast<guecs::Entity>(data); |
|
|
|
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& drop = target.get<guecs::DropTarget>(target_id); |
|
|
|
auto& grab = source.get<guecs::GrabSource>(*source_id); |
|
|
|
auto& grab = source.get<guecs::GrabSource>(*source_id); |
|
|
@ -239,4 +247,28 @@ namespace gui { |
|
|
|
return false; |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|