Brought the UIStack over from the previous game to use here.
This commit is contained in:
parent
25e3935170
commit
6aa1a877c9
7 changed files with 241 additions and 0 deletions
|
|
@ -52,6 +52,7 @@ namespace guecs {
|
|||
};
|
||||
|
||||
struct Rectangle {
|
||||
// BUG: confirm that padding is being used correctly here
|
||||
int padding = THEME.PADDING;
|
||||
sf::Color color = THEME.FILL_COLOR;
|
||||
sf::Color border_color = THEME.BORDER_COLOR;
|
||||
|
|
@ -62,6 +63,9 @@ namespace guecs {
|
|||
void render(sf::RenderTarget& window, sf::Shader *shader_ptr);
|
||||
};
|
||||
|
||||
// BUG: meter needs a backing rectangle of one color for the full bar, then
|
||||
// another rectangle for the current setting.
|
||||
// BUG: the meter will be past the end, probably a floating point error
|
||||
struct Meter {
|
||||
float percent = 1.0f;
|
||||
sf::Color color = THEME.BG_COLOR_DARK;
|
||||
|
|
@ -95,6 +99,7 @@ namespace guecs {
|
|||
void stop(bool hover);
|
||||
};
|
||||
|
||||
// BUG: it should be _way_ easier to set the background and change it
|
||||
struct Background {
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
|
|
|
|||
|
|
@ -60,6 +60,9 @@ namespace guecs {
|
|||
shared_ptr<sf::Font> $font = nullptr;
|
||||
lel::Parser $parser;
|
||||
string $grid = "";
|
||||
// BUG: check for this to prevent bugs, or find a way to shape the API so you
|
||||
// simply can't get it wrong
|
||||
bool initialized = false;
|
||||
|
||||
UI();
|
||||
|
||||
|
|
|
|||
97
include/guecs/uistack.hpp
Normal file
97
include/guecs/uistack.hpp
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#include <guecs/ui.hpp>
|
||||
#include <flat_map>
|
||||
#include <cassert>
|
||||
|
||||
namespace gui {
|
||||
template<typename SCREEN_TYPE>
|
||||
struct UIStack {
|
||||
using UIStackMap = std::flat_map<std::string, std::shared_ptr<SCREEN_TYPE>>;
|
||||
|
||||
UIStackMap screens{};
|
||||
bool visible = false;
|
||||
|
||||
UIStackMap::iterator $current{screens.begin()};
|
||||
SCREEN_TYPE* $active = nullptr;
|
||||
|
||||
void add(const std::string& name, std::shared_ptr<SCREEN_TYPE> screen) {
|
||||
screens.insert_or_assign(name, screen);
|
||||
update_active(screens.begin());
|
||||
}
|
||||
|
||||
void update_active(const UIStackMap::iterator& itr) {
|
||||
$current = itr;
|
||||
$active = (*$current).second.get();
|
||||
}
|
||||
|
||||
void set_active(const std::string& name) {
|
||||
assert(screens.contains(name) && "no screen with that name");
|
||||
update_active(screens.find(name));
|
||||
}
|
||||
|
||||
void set_visible(bool new_value) {
|
||||
visible = new_value;
|
||||
}
|
||||
|
||||
bool is_visible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
void render(sf::RenderTarget& target) {
|
||||
assert($active != nullptr && "you didn't set active");
|
||||
$active->render(target);
|
||||
}
|
||||
|
||||
void update() {
|
||||
assert($active != nullptr && "you didn't set active");
|
||||
$active->update();
|
||||
}
|
||||
|
||||
bool mouse(float x, float y, guecs::Modifiers mods = guecs::NO_MODS) {
|
||||
assert($active != nullptr && "you didn't set active");
|
||||
return $active->mouse(x, y, mods);
|
||||
}
|
||||
|
||||
bool move(const UIStackMap::iterator& itr, const UIStackMap::iterator& avoid, const UIStackMap::iterator& result) {
|
||||
if(itr != avoid) {
|
||||
update_active(result);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool next() {
|
||||
return move($current + 1, screens.end(), $current + 1);
|
||||
}
|
||||
|
||||
bool prev() {
|
||||
return move($current, screens.begin(), $current - 1);
|
||||
}
|
||||
|
||||
void first() {
|
||||
update_active(screens.begin());
|
||||
}
|
||||
|
||||
void last() {
|
||||
update_active(screens.end() - 1);
|
||||
}
|
||||
|
||||
const std::string& active_name() {
|
||||
assert($active != nullptr && "you didn't set active");
|
||||
return (*$current).first;
|
||||
}
|
||||
|
||||
std::shared_ptr<SCREEN_TYPE> active_ui() {
|
||||
assert($active != nullptr && "you didn't set active");
|
||||
return (*$current).second;
|
||||
}
|
||||
|
||||
std::shared_ptr<SCREEN_TYPE> at(const std::string& name) {
|
||||
return screens.at(name);
|
||||
}
|
||||
|
||||
const UIStackMap::key_container_type& names() {
|
||||
return screens.keys();
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue