Clean things up before solving the move problem.
This commit is contained in:
parent
6576164fad
commit
8c8d6dc9e7
4 changed files with 16 additions and 18 deletions
|
@ -62,8 +62,9 @@ namespace gui {
|
||||||
END(CLOSE);
|
END(CLOSE);
|
||||||
break;
|
break;
|
||||||
case LOOT_SELECT:
|
case LOOT_SELECT:
|
||||||
commit_move($loot_ui.$gui, $grab_source, data);
|
if(commit_move($loot_ui.$gui, $grab_source, data)) {
|
||||||
state(DNDState::LOOTING);
|
state(DNDState::LOOTING);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case INV_SELECT:
|
case INV_SELECT:
|
||||||
if(commit_drop($loot_ui.$gui,
|
if(commit_drop($loot_ui.$gui,
|
||||||
|
@ -92,9 +93,9 @@ namespace gui {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case INV_SELECT:
|
case INV_SELECT:
|
||||||
// BUG: should I do a bool here and not transition?
|
if(commit_move($status_ui.$gui, $grab_source, data)) {
|
||||||
commit_move($status_ui.$gui, $grab_source, data);
|
state(DNDState::LOOTING);
|
||||||
state(DNDState::LOOTING);
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
handle_mouse(ev, $status_ui.$gui);
|
handle_mouse(ev, $status_ui.$gui);
|
||||||
|
@ -111,8 +112,9 @@ namespace gui {
|
||||||
END(CLOSE);
|
END(CLOSE);
|
||||||
} break;
|
} break;
|
||||||
case INV_SELECT:
|
case INV_SELECT:
|
||||||
commit_move($status_ui.$gui, $grab_source, data);
|
if(commit_move($status_ui.$gui, $grab_source, data)) {
|
||||||
END(CLOSE);
|
END(CLOSE);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
handle_mouse(ev, $status_ui.$gui);
|
handle_mouse(ev, $status_ui.$gui);
|
||||||
|
@ -228,8 +230,8 @@ namespace gui {
|
||||||
dbc::check(source.has<guecs::GrabSource>(*source_id),
|
dbc::check(source.has<guecs::GrabSource>(*source_id),
|
||||||
"gui does not have a GrabSource at that slot");
|
"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);
|
auto& grab = source.get<guecs::GrabSource>(*source_id);
|
||||||
|
auto& drop = target.get<guecs::DropTarget>(target_id);
|
||||||
|
|
||||||
if(drop.commit(grab.world_entity)) {
|
if(drop.commit(grab.world_entity)) {
|
||||||
grab.commit();
|
grab.commit();
|
||||||
|
@ -240,8 +242,9 @@ namespace gui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DNDLoot::commit_move(guecs::UI& gui, std::optional<guecs::Entity> source_id, std::any data) {
|
bool DNDLoot::commit_move(guecs::UI& gui, std::optional<guecs::Entity> source_id, std::any data) {
|
||||||
dbc::check(source_id != std::nullopt, "source_id must exist");
|
dbc::check(source_id != std::nullopt, "source_id must exist");
|
||||||
|
|
||||||
auto& grab = gui.get<guecs::GrabSource>(*source_id);
|
auto& grab = gui.get<guecs::GrabSource>(*source_id);
|
||||||
grab.commit();
|
grab.commit();
|
||||||
|
|
||||||
|
@ -250,13 +253,11 @@ namespace gui {
|
||||||
|
|
||||||
if(drop.commit(grab.world_entity)) {
|
if(drop.commit(grab.world_entity)) {
|
||||||
clear_grab();
|
clear_grab();
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
dbc::log("commit drop didn't happen");
|
// swap with the target instead
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DNDLoot::hold_world_item() {
|
bool DNDLoot::hold_world_item() {
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace gui {
|
||||||
bool commit_drop(guecs::UI& source, guecs::UI& target,
|
bool commit_drop(guecs::UI& source, guecs::UI& target,
|
||||||
std::optional<guecs::Entity> source_id, std::any data);
|
std::optional<guecs::Entity> source_id, std::any data);
|
||||||
|
|
||||||
void commit_move(guecs::UI& gui,
|
bool commit_move(guecs::UI& gui,
|
||||||
std::optional<guecs::Entity> source_id, std::any data);
|
std::optional<guecs::Entity> source_id, std::any data);
|
||||||
|
|
||||||
bool hold_world_item();
|
bool hold_world_item();
|
||||||
|
|
|
@ -131,5 +131,4 @@ namespace gui {
|
||||||
return $gui.mouse(x, y, hover);
|
return $gui.mouse(x, y, hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,8 +104,6 @@ namespace gui {
|
||||||
auto& slot_name = $slot_to_name.at(gui_id);
|
auto& slot_name = $slot_to_name.at(gui_id);
|
||||||
auto& inventory = $level.world->get_the<inventory::Model>();
|
auto& inventory = $level.world->get_the<inventory::Model>();
|
||||||
|
|
||||||
inventory.dump();
|
|
||||||
|
|
||||||
if(inventory.add(slot_name, world_entity)) {
|
if(inventory.add(slot_name, world_entity)) {
|
||||||
$level.world->make_constant(world_entity);
|
$level.world->make_constant(world_entity);
|
||||||
update();
|
update();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue