I think that's all the edge cases handled. You can more loot around fairly arbitrarily.

master
Zed A. Shaw 2 days ago
parent 6ff1919587
commit 689bb150c6
  1. 23
      gui/dnd_loot.cpp
  2. 2
      gui/dnd_loot.hpp

@ -61,8 +61,8 @@ namespace gui {
END(Event::CLOSE);
break;
case LOOT_SELECT:
$grab_source = start_grab($loot_ui.$gui, data);
if($grab_source) state(DNDState::LOOTING);
commit_move($loot_ui.$gui, $grab_source, data);
state(DNDState::LOOTING);
break;
case INV_SELECT:
if(commit_drop($loot_ui.$gui,
@ -91,7 +91,8 @@ namespace gui {
}
break;
case INV_SELECT:
$grab_source = start_grab($status_ui.$gui, data);
// BUG: should I do a bool here and not transition?
commit_move($status_ui.$gui, $grab_source, data);
state(DNDState::LOOTING);
break;
default:
@ -195,15 +196,19 @@ namespace gui {
}
}
void DNDLoot::open() {
// BUG: should I do this in the commit_ functions or in the FSM?
void DNDLoot::clear_grab() {
$grab_source = std::nullopt;
$grab_sprite = nullptr;
}
void DNDLoot::open() {
clear_grab();
$loot_ui.active = true;
}
void DNDLoot::close() {
$grab_source = std::nullopt;
$grab_sprite = nullptr;
clear_grab();
$loot_ui.active = false;
}
@ -242,6 +247,7 @@ namespace gui {
if(drop.commit(grab.world_entity)) {
grab.commit();
clear_grab();
return true;
} else {
return false;
@ -256,6 +262,7 @@ namespace gui {
auto& drop = gui.get<guecs::DropTarget>(drop_id);
drop.commit(grab.world_entity);
clear_grab();
// 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?
@ -269,6 +276,8 @@ namespace gui {
dbc::check($grab_source != std::nullopt, "attempt to commit_drop but no grab_source set");
auto& grab = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
grab.commit();
return $status_ui.drop_item(grab.world_entity);
bool result = $status_ui.drop_item(grab.world_entity);
clear_grab();
return result;
}
}

@ -54,6 +54,8 @@ namespace gui {
bool throw_on_floor();
void clear_grab();
sf::Vector2f mouse_position();
};
}

Loading…
Cancel
Save