Just need one function for the 'hold_item' action.
This commit is contained in:
parent
265e53e05a
commit
cd89625c96
2 changed files with 17 additions and 28 deletions
|
@ -153,16 +153,18 @@ namespace gui {
|
|||
using enum Event;
|
||||
|
||||
switch(ev) {
|
||||
case LOOT_ITEM:
|
||||
if(hold_world_item()) {
|
||||
state(DNDState::ITEM_PICKUP);
|
||||
}
|
||||
break;
|
||||
case INV_SELECT:
|
||||
if(hold_inv_item(data)) {
|
||||
state(DNDState::INV_PICKUP);
|
||||
}
|
||||
break;
|
||||
case LOOT_ITEM: {
|
||||
auto gui_id = $loot_ui.$gui.entity("item_0");
|
||||
if(hold_item($loot_ui.$gui, gui_id)) {
|
||||
state(DNDState::ITEM_PICKUP);
|
||||
}
|
||||
} break;
|
||||
case INV_SELECT: {
|
||||
auto gui_id = std::any_cast<guecs::Entity>(data);
|
||||
if(hold_item($status_ui.$gui, gui_id)) {
|
||||
state(DNDState::INV_PICKUP);
|
||||
}
|
||||
} break;
|
||||
case LOOT_OPEN:
|
||||
open();
|
||||
state(DNDState::LOOTING);
|
||||
|
@ -268,27 +270,15 @@ namespace gui {
|
|||
}
|
||||
}
|
||||
|
||||
bool DNDLoot::hold_world_item() {
|
||||
bool DNDLoot::hold_item(guecs::UI &gui, guecs::Entity gui_id) {
|
||||
// NOTE: if > 1 items, go to LOOT_OPEN instead
|
||||
auto gui_id = $loot_ui.$gui.entity("item_0");
|
||||
$grab_source = start_grab($loot_ui.$gui, gui_id);
|
||||
$grab_source = start_grab(gui, gui_id);
|
||||
|
||||
if($grab_source) {
|
||||
auto& source = $loot_ui.$gui.get<guecs::GrabSource>(*$grab_source);
|
||||
auto& source = gui.get<guecs::GrabSource>(*$grab_source);
|
||||
$grab_sprite = source.sprite;
|
||||
// call this once to properly position the sprite
|
||||
handle_mouse(Event::MOUSE_MOVE, $loot_ui.$gui);
|
||||
}
|
||||
|
||||
return $grab_source != std::nullopt;
|
||||
}
|
||||
|
||||
bool DNDLoot::hold_inv_item(std::any& data) {
|
||||
$grab_source = start_grab($status_ui.$gui, data);
|
||||
|
||||
if($grab_source) {
|
||||
auto& source = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
|
||||
$grab_sprite = source.sprite;
|
||||
handle_mouse(Event::MOUSE_MOVE, gui);
|
||||
}
|
||||
|
||||
return $grab_source != std::nullopt;
|
||||
|
|
|
@ -52,8 +52,7 @@ namespace gui {
|
|||
bool commit_move(guecs::UI& gui,
|
||||
std::optional<guecs::Entity> source_id, std::any data);
|
||||
|
||||
bool hold_world_item();
|
||||
bool hold_inv_item(std::any& data);
|
||||
bool hold_item(guecs::UI& gui, guecs::Entity gui_id);
|
||||
bool throw_on_floor(guecs::UI& gui, bool from_status);
|
||||
|
||||
void clear_grab();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue