Need to not transition out of END if the slot clicked is empty. Closes #45
This commit is contained in:
parent
19682fd0bc
commit
b0204772c7
2 changed files with 22 additions and 15 deletions
|
@ -111,7 +111,6 @@ namespace gui {
|
||||||
END(CLOSE);
|
END(CLOSE);
|
||||||
} break;
|
} break;
|
||||||
case INV_SELECT:
|
case INV_SELECT:
|
||||||
// BUG: should I do a bool here and not transition?
|
|
||||||
commit_move($status_ui.$gui, $grab_source, data);
|
commit_move($status_ui.$gui, $grab_source, data);
|
||||||
END(CLOSE);
|
END(CLOSE);
|
||||||
break;
|
break;
|
||||||
|
@ -146,12 +145,14 @@ namespace gui {
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
case LOOT_ITEM:
|
case LOOT_ITEM:
|
||||||
hold_world_item();
|
if(hold_world_item()) {
|
||||||
state(DNDState::ITEM_PICKUP);
|
state(DNDState::ITEM_PICKUP);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case INV_SELECT:
|
case INV_SELECT:
|
||||||
hold_inv_item(data);
|
if(hold_inv_item(data)) {
|
||||||
state(DNDState::INV_PICKUP);
|
state(DNDState::INV_PICKUP);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case LOOT_OPEN:
|
case LOOT_OPEN:
|
||||||
open();
|
open();
|
||||||
|
@ -186,17 +187,16 @@ namespace gui {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DNDLoot::clear_grab() {
|
void DNDLoot::clear_grab() {
|
||||||
|
dbc::log("CLEARED!");
|
||||||
$grab_source = std::nullopt;
|
$grab_source = std::nullopt;
|
||||||
$grab_sprite = nullptr;
|
$grab_sprite = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DNDLoot::open() {
|
void DNDLoot::open() {
|
||||||
clear_grab();
|
|
||||||
$loot_ui.active = true;
|
$loot_ui.active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DNDLoot::close() {
|
void DNDLoot::close() {
|
||||||
clear_grab();
|
|
||||||
$loot_ui.active = false;
|
$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) {
|
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);
|
auto& grab = gui.get<guecs::GrabSource>(*source_id);
|
||||||
grab.commit();
|
grab.commit();
|
||||||
|
|
||||||
auto drop_id = std::any_cast<guecs::Entity>(data);
|
auto drop_id = std::any_cast<guecs::Entity>(data);
|
||||||
auto& drop = gui.get<guecs::DropTarget>(drop_id);
|
auto& drop = gui.get<guecs::DropTarget>(drop_id);
|
||||||
drop.commit(grab.world_entity);
|
|
||||||
|
|
||||||
clear_grab();
|
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?
|
// BUG: if the drop fails then need to put the grab back?
|
||||||
// How to confirm the drop will work before doing it?
|
// How to confirm the drop will work before doing it?
|
||||||
// Or, maybe save the commit?
|
// Or, maybe save the commit?
|
||||||
}
|
}
|
||||||
|
|
||||||
void DNDLoot::hold_world_item() {
|
bool DNDLoot::hold_world_item() {
|
||||||
// NOTE: if > 1 items, go to LOOT_OPEN instead
|
// NOTE: if > 1 items, go to LOOT_OPEN instead
|
||||||
auto gui_id = $loot_ui.$gui.entity("item_0");
|
auto gui_id = $loot_ui.$gui.entity("item_0");
|
||||||
$grab_source = start_grab($loot_ui.$gui, gui_id);
|
$grab_source = start_grab($loot_ui.$gui, gui_id);
|
||||||
|
@ -267,17 +272,19 @@ namespace gui {
|
||||||
// call this once to properly position the sprite
|
// call this once to properly position the sprite
|
||||||
handle_mouse(Event::MOUSE_MOVE, $loot_ui.$gui);
|
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);
|
$grab_source = start_grab($status_ui.$gui, data);
|
||||||
|
|
||||||
if($grab_source) {
|
if($grab_source) {
|
||||||
auto& source = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
|
auto& source = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
|
||||||
$grab_sprite = source.sprite;
|
$grab_sprite = source.sprite;
|
||||||
} else {
|
|
||||||
dbc::log("inv slot empty");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $grab_source != std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -52,8 +52,8 @@ namespace gui {
|
||||||
void commit_move(guecs::UI& gui,
|
void commit_move(guecs::UI& gui,
|
||||||
std::optional<guecs::Entity> source_id, std::any data);
|
std::optional<guecs::Entity> source_id, std::any data);
|
||||||
|
|
||||||
void hold_world_item();
|
bool hold_world_item();
|
||||||
void hold_inv_item(std::any& data);
|
bool hold_inv_item(std::any& data);
|
||||||
bool throw_on_floor();
|
bool throw_on_floor();
|
||||||
|
|
||||||
void clear_grab();
|
void clear_grab();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue