Better meaning API on both sides for the drag-n-drop operations, but I _swear_ there's a way to do this in the GrabSource/DropTarget instead.

This commit is contained in:
Zed A. Shaw 2025-06-08 23:27:43 -04:00
parent 47c219b86e
commit 3e0adf0c22
6 changed files with 26 additions and 23 deletions

View file

@ -135,12 +135,12 @@ namespace gui {
case LOOT_SELECT: {
$grab_source = std::any_cast<DinkyECS::Entity>(data);
if(auto world_entity = $loot_ui.select_slot(*$grab_source)) {
auto& source = $loot_ui.get_grabber(*$grab_source);
if(auto world_entity = $loot_ui.start_grab(*$grab_source)) {
auto& source = $loot_ui.get_grab_source(*$grab_source);
source.grab($window);
source.move($router.position);
$status_ui.select_slot(*world_entity);
$status_ui.start_drop(*world_entity);
} else {
// BUG: need a cancel operation here
$window.setMouseCursorVisible(true);
@ -149,14 +149,11 @@ namespace gui {
} break;
case INV_SELECT: {
auto gui_id = std::any_cast<DinkyECS::Entity>(data);
dbc::log(fmt::format("INV_SELECT $grab_source null? {} gui_id {}",
$grab_source == std::nullopt, gui_id));
if($grab_source) {
auto& drop = $status_ui.$gui.get<guecs::DropTarget>(gui_id);
auto& drop = $status_ui.get_drop_target(gui_id);
if(drop.action()) {
$loot_ui.remove_slot(*$grab_source);
if(drop.commit()) {
$loot_ui.commit_drop(*$grab_source);
$grab_source = std::nullopt;
}
@ -171,7 +168,7 @@ namespace gui {
case MOUSE_DRAG:
case MOUSE_MOVE: {
if($grab_source) {
auto& source = $loot_ui.get_grabber(*$grab_source);
auto& source = $loot_ui.get_grab_source(*$grab_source);
source.move($router.position);
}
mouse_action(true);