Make the transitions more solid by having an open/close set of functions to maintain cleaning up internal state.
This commit is contained in:
parent
029a0f86ae
commit
dfd3118d04
2 changed files with 25 additions and 13 deletions
|
@ -31,7 +31,7 @@ namespace gui {
|
||||||
|
|
||||||
void DNDLoot::START(Event ev) {
|
void DNDLoot::START(Event ev) {
|
||||||
dbc::check(ev == Event::STARTED, "START not given a STARTED event.");
|
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) {
|
void DNDLoot::LOOTING(Event ev, std::any data) {
|
||||||
|
@ -39,8 +39,7 @@ namespace gui {
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
case LOOT_OPEN:
|
case LOOT_OPEN:
|
||||||
$loot_ui.active = false;
|
END(Event::CLOSE);
|
||||||
state(DNDState::END);
|
|
||||||
break;
|
break;
|
||||||
case LOOT_SELECT:
|
case LOOT_SELECT:
|
||||||
$grab_source = UISystem::loot_grab($loot_ui.$gui, data);
|
$grab_source = UISystem::loot_grab($loot_ui.$gui, data);
|
||||||
|
@ -64,8 +63,7 @@ namespace gui {
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
case LOOT_OPEN:
|
case LOOT_OPEN:
|
||||||
$loot_ui.active = false;
|
END(Event::CLOSE);
|
||||||
state(DNDState::END);
|
|
||||||
break;
|
break;
|
||||||
case LOOT_SELECT:
|
case LOOT_SELECT:
|
||||||
$grab_source = UISystem::loot_grab($loot_ui.$gui, data);
|
$grab_source = UISystem::loot_grab($loot_ui.$gui, data);
|
||||||
|
@ -88,8 +86,7 @@ namespace gui {
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
case LOOT_OPEN:
|
case LOOT_OPEN:
|
||||||
$loot_ui.active = false;
|
END(Event::CLOSE);
|
||||||
state(DNDState::END);
|
|
||||||
break;
|
break;
|
||||||
case LOOT_SELECT:
|
case LOOT_SELECT:
|
||||||
if(UISystem::loot_drop($status_ui.$gui,
|
if(UISystem::loot_drop($status_ui.$gui,
|
||||||
|
@ -115,9 +112,7 @@ namespace gui {
|
||||||
if(UISystem::loot_drop($loot_ui.$gui,
|
if(UISystem::loot_drop($loot_ui.$gui,
|
||||||
$status_ui.$gui, $grab_source, data))
|
$status_ui.$gui, $grab_source, data))
|
||||||
{
|
{
|
||||||
$grab_source = std::nullopt;
|
END(Event::CLOSE);
|
||||||
$grab_sprite = nullptr;
|
|
||||||
state(DNDState::END);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case LOOT_ITEM:
|
case LOOT_ITEM:
|
||||||
|
@ -146,11 +141,14 @@ namespace gui {
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case LOOT_OPEN:
|
case LOOT_OPEN:
|
||||||
$loot_ui.active = true;
|
open();
|
||||||
$grab_source = std::nullopt;
|
|
||||||
$grab_sprite = nullptr;
|
|
||||||
state(DNDState::LOOTING);
|
state(DNDState::LOOTING);
|
||||||
break;
|
break;
|
||||||
|
case CLOSE:
|
||||||
|
// called the first time transitioning to END
|
||||||
|
close();
|
||||||
|
state(DNDState::END);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
dbc::sentinel(fmt::format("invalid event: {}", int(ev)));
|
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() {
|
void DNDLoot::render() {
|
||||||
if($grab_source && $grab_sprite) {
|
if($grab_source && $grab_sprite) {
|
||||||
$window.draw(*$grab_sprite);
|
$window.draw(*$grab_sprite);
|
||||||
|
|
|
@ -39,6 +39,8 @@ namespace gui {
|
||||||
void handle_mouse(Event ev, guecs::UI& gui);
|
void handle_mouse(Event ev, guecs::UI& gui);
|
||||||
void mouse_action(bool hover);
|
void mouse_action(bool hover);
|
||||||
void render();
|
void render();
|
||||||
|
void open();
|
||||||
|
void close();
|
||||||
sf::Vector2f mouse_position();
|
sf::Vector2f mouse_position();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue