Make the transitions more solid by having an open/close set of functions to maintain cleaning up internal state.

master
Zed A. Shaw 1 day ago
parent 029a0f86ae
commit dfd3118d04
  1. 36
      gui/dnd_loot.cpp
  2. 2
      gui/dnd_loot.hpp

@ -31,7 +31,7 @@ namespace gui {
void DNDLoot::START(Event ev) {
dbc::check(ev == Event::STARTED, "START not given a STARTED event.");
state(DNDState::END);
END(Event::CLOSE);
}
void DNDLoot::LOOTING(Event ev, std::any data) {
@ -39,8 +39,7 @@ namespace gui {
switch(ev) {
case LOOT_OPEN:
$loot_ui.active = false;
state(DNDState::END);
END(Event::CLOSE);
break;
case LOOT_SELECT:
$grab_source = UISystem::loot_grab($loot_ui.$gui, data);
@ -64,8 +63,7 @@ namespace gui {
switch(ev) {
case LOOT_OPEN:
$loot_ui.active = false;
state(DNDState::END);
END(Event::CLOSE);
break;
case LOOT_SELECT:
$grab_source = UISystem::loot_grab($loot_ui.$gui, data);
@ -88,8 +86,7 @@ namespace gui {
switch(ev) {
case LOOT_OPEN:
$loot_ui.active = false;
state(DNDState::END);
END(Event::CLOSE);
break;
case LOOT_SELECT:
if(UISystem::loot_drop($status_ui.$gui,
@ -115,9 +112,7 @@ namespace gui {
if(UISystem::loot_drop($loot_ui.$gui,
$status_ui.$gui, $grab_source, data))
{
$grab_source = std::nullopt;
$grab_sprite = nullptr;
state(DNDState::END);
END(Event::CLOSE);
}
break;
case LOOT_ITEM:
@ -146,11 +141,14 @@ namespace gui {
}
} break;
case LOOT_OPEN:
$loot_ui.active = true;
$grab_source = std::nullopt;
$grab_sprite = nullptr;
open();
state(DNDState::LOOTING);
break;
case CLOSE:
// called the first time transitioning to END
close();
state(DNDState::END);
break;
default:
dbc::sentinel(fmt::format("invalid event: {}", int(ev)));
}
@ -193,6 +191,18 @@ namespace gui {
}
}
void DNDLoot::open() {
$grab_source = std::nullopt;
$grab_sprite = nullptr;
$loot_ui.active = true;
}
void DNDLoot::close() {
$grab_source = std::nullopt;
$grab_sprite = nullptr;
$loot_ui.active = false;
}
void DNDLoot::render() {
if($grab_source && $grab_sprite) {
$window.draw(*$grab_sprite);

@ -39,6 +39,8 @@ namespace gui {
void handle_mouse(Event ev, guecs::UI& gui);
void mouse_action(bool hover);
void render();
void open();
void close();
sf::Vector2f mouse_position();
};
}

Loading…
Cancel
Save