Making Icons a thing again since it's convenient.
This commit is contained in:
parent
7e64879f78
commit
4c019048d0
4 changed files with 35 additions and 1 deletions
|
@ -92,7 +92,7 @@ struct ClickerUI {
|
||||||
auto id = $gui.entity(name);
|
auto id = $gui.entity(name);
|
||||||
if(name != "clicker") {
|
if(name != "clicker") {
|
||||||
$gui.set<guecs::Effect>(id, {});
|
$gui.set<guecs::Effect>(id, {});
|
||||||
$gui.set<guecs::Sprite>(id, { "clicker_treat_bone" });
|
$gui.set<guecs::Icon>(id, { "clicker_treat_bone" });
|
||||||
$gui.set<guecs::Clickable>(id, {
|
$gui.set<guecs::Clickable>(id, {
|
||||||
[&](auto, auto) { handle_button(Event::A_BUTTON); }
|
[&](auto, auto) { handle_button(Event::A_BUTTON); }
|
||||||
});
|
});
|
||||||
|
|
|
@ -36,6 +36,20 @@ namespace guecs {
|
||||||
void render(sf::RenderWindow& window, sf::Shader *shader_ptr);
|
void render(sf::RenderWindow& window, sf::Shader *shader_ptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Icon : public Sprite {
|
||||||
|
template<typename... Args>
|
||||||
|
Icon(Args... args) : Sprite(args...)
|
||||||
|
{
|
||||||
|
stretch = false;
|
||||||
|
is_icon = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Icon() {
|
||||||
|
stretch = false;
|
||||||
|
is_icon = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
struct Rectangle {
|
struct Rectangle {
|
||||||
int padding = THEME.PADDING;
|
int padding = THEME.PADDING;
|
||||||
sf::Color color = THEME.FILL_COLOR;
|
sf::Color color = THEME.FILL_COLOR;
|
||||||
|
|
|
@ -218,6 +218,7 @@ namespace guecs {
|
||||||
sf::Shader* find_shader(Entity ent, bool is_shape);
|
sf::Shader* find_shader(Entity ent, bool is_shape);
|
||||||
|
|
||||||
void show_sprite(const string& region, const string& sprite_name);
|
void show_sprite(const string& region, const string& sprite_name);
|
||||||
|
void show_icon(const string& region, const string& sprite_name);
|
||||||
void show_text(const string& region, const wstring& content);
|
void show_text(const string& region, const wstring& content);
|
||||||
void show_label(const string& region, const wstring& content);
|
void show_label(const string& region, const wstring& content);
|
||||||
};
|
};
|
||||||
|
|
|
@ -89,6 +89,10 @@ namespace guecs {
|
||||||
query<lel::Cell, Sprite>([&](auto, auto &cell, auto &sprite) {
|
query<lel::Cell, Sprite>([&](auto, auto &cell, auto &sprite) {
|
||||||
sprite.init(cell);
|
sprite.init(cell);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
query<lel::Cell, Icon>([&](auto, auto &cell, auto &icon) {
|
||||||
|
icon.init(cell);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::debug_layout(sf::RenderWindow& window) {
|
void UI::debug_layout(sf::RenderWindow& window) {
|
||||||
|
@ -134,6 +138,11 @@ namespace guecs {
|
||||||
sprite.render(window, shader_ptr);
|
sprite.render(window, shader_ptr);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
query<Icon>([&](auto ent, auto& icon) {
|
||||||
|
auto shader_ptr = find_shader(ent, false);
|
||||||
|
icon.render(window, shader_ptr);
|
||||||
|
});
|
||||||
|
|
||||||
query<Text>([&](auto ent, auto& text) {
|
query<Text>([&](auto ent, auto& text) {
|
||||||
auto shader_ptr = find_shader(ent, false);
|
auto shader_ptr = find_shader(ent, false);
|
||||||
text.render(window, shader_ptr);
|
text.render(window, shader_ptr);
|
||||||
|
@ -188,6 +197,16 @@ namespace guecs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UI::show_icon(const string& region, const string& sprite_name) {
|
||||||
|
auto ent = entity(region);
|
||||||
|
|
||||||
|
if(auto sprite = get_if<Icon>(ent)) {
|
||||||
|
sprite->update(sprite_name);
|
||||||
|
} else {
|
||||||
|
set_init<Icon>(ent, {sprite_name});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void UI::show_text(const string& region, const wstring& content) {
|
void UI::show_text(const string& region, const wstring& content) {
|
||||||
auto ent = entity(region);
|
auto ent = entity(region);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue