|
|
|
@ -111,7 +111,6 @@ namespace gui { |
|
|
|
|
END(CLOSE); |
|
|
|
|
} break; |
|
|
|
|
case INV_SELECT: |
|
|
|
|
// BUG: should I do a bool here and not transition?
|
|
|
|
|
commit_move($status_ui.$gui, $grab_source, data); |
|
|
|
|
END(CLOSE); |
|
|
|
|
break; |
|
|
|
@ -146,12 +145,14 @@ namespace gui { |
|
|
|
|
|
|
|
|
|
switch(ev) { |
|
|
|
|
case LOOT_ITEM: |
|
|
|
|
hold_world_item(); |
|
|
|
|
if(hold_world_item()) { |
|
|
|
|
state(DNDState::ITEM_PICKUP); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case INV_SELECT: |
|
|
|
|
hold_inv_item(data); |
|
|
|
|
if(hold_inv_item(data)) { |
|
|
|
|
state(DNDState::INV_PICKUP); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case LOOT_OPEN: |
|
|
|
|
open(); |
|
|
|
@ -186,17 +187,16 @@ namespace gui { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void DNDLoot::clear_grab() { |
|
|
|
|
dbc::log("CLEARED!"); |
|
|
|
|
$grab_source = std::nullopt; |
|
|
|
|
$grab_sprite = nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void DNDLoot::open() { |
|
|
|
|
clear_grab(); |
|
|
|
|
$loot_ui.active = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void DNDLoot::close() { |
|
|
|
|
clear_grab(); |
|
|
|
|
$loot_ui.active = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -243,20 +243,25 @@ namespace gui { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void 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"); |
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
if(drop.commit(grab.world_entity)) { |
|
|
|
|
clear_grab(); |
|
|
|
|
} else { |
|
|
|
|
dbc::log("commit drop didn't happen"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 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?
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void DNDLoot::hold_world_item() { |
|
|
|
|
bool DNDLoot::hold_world_item() { |
|
|
|
|
// 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); |
|
|
|
@ -267,17 +272,19 @@ namespace gui { |
|
|
|
|
// call this once to properly position the sprite
|
|
|
|
|
handle_mouse(Event::MOUSE_MOVE, $loot_ui.$gui); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $grab_source != std::nullopt; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void DNDLoot::hold_inv_item(std::any& data) { |
|
|
|
|
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; |
|
|
|
|
} else { |
|
|
|
|
dbc::log("inv slot empty"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $grab_source != std::nullopt; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|