Finally upgraded the strings to const& since I'm about to pull guecs out and distribute it. Oh well, the joke's finally over.

This commit is contained in:
Zed A. Shaw 2025-05-03 14:52:56 -04:00
parent 82ce3cb6be
commit 438bd8ab8a
8 changed files with 53 additions and 74 deletions

View file

@ -26,7 +26,7 @@ namespace guecs {
shared_ptr<sf::Text> text = nullptr;
void init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr);
void update(std::wstring& new_content);
void update(const std::wstring& new_content);
};
struct Label : public Textual {
@ -49,13 +49,13 @@ namespace guecs {
};
struct Sprite {
std::string name;
string name;
int padding = GUECS_PADDING;
std::shared_ptr<sf::Sprite> sprite = nullptr;
std::shared_ptr<sf::Texture> texture = nullptr;
void init(lel::Cell &cell);
void update(const std::string& new_name);
void update(const string& new_name);
};
struct Rectangle {
@ -80,12 +80,12 @@ namespace guecs {
};
struct CellName {
std::string name;
string name;
};
struct Effect {
float duration = 0.1f;
std::string name{"ui_shader"};
string name{"ui_shader"};
float $u_time_end = 0.0;
bool $active = false;
std::shared_ptr<sf::Clock> $clock = nullptr;
@ -100,7 +100,7 @@ namespace guecs {
};
struct Sound {
std::string on_click{"ui_click"};
string on_click{"ui_click"};
void play(bool hover);
void stop(bool hover);
};
@ -129,20 +129,20 @@ namespace guecs {
class UI {
public:
DinkyECS::World $world;
std::unordered_map<std::string, DinkyECS::Entity> $name_ents;
std::unordered_map<string, DinkyECS::Entity> $name_ents;
shared_ptr<sf::Font> $font = nullptr;
lel::Parser $parser;
std::string $grid = "";
string $grid = "";
UI();
void position(int x, int y, int width, int height);
sf::Vector2f get_position();
sf::Vector2f get_size();
void layout(std::string grid);
DinkyECS::Entity init_entity(std::string name);
DinkyECS::Entity entity(std::string name);
DinkyECS::Entity entity(std::string name, int id);
void layout(const string& grid);
DinkyECS::Entity init_entity(const string& name);
DinkyECS::Entity entity(const string& name);
DinkyECS::Entity entity(const string& name, int id);
inline lel::CellMap& cells() {
return $parser.cells;
@ -155,7 +155,7 @@ namespace guecs {
void init();
void render(sf::RenderWindow& window);
bool mouse(float x, float y, bool hover);
void click_on(const std::string& name, bool required=false);
void click_on(const string& name, bool required=false);
void click_on(DinkyECS::Entity slot_id);
void debug_layout(sf::RenderWindow& window);
@ -183,7 +183,7 @@ namespace guecs {
return $world.get<lel::Cell>(ent);
}
lel::Cell& cell_for(std::string name) {
lel::Cell& cell_for(const string& name) {
DinkyECS::Entity ent = entity(name);
return $world.get<lel::Cell>(ent);
}
@ -194,7 +194,7 @@ namespace guecs {
}
template <typename Comp>
std::optional<Comp> get_if(DinkyECS::Entity entity) {
Comp* get_if(DinkyECS::Entity entity) {
return $world.get_if<Comp>(entity);
}
@ -221,11 +221,9 @@ namespace guecs {
void render_helper(sf::RenderWindow& window, DinkyECS::Entity ent, bool is_shape, T& target) {
sf::Shader *shader_ptr = nullptr;
if($world.has<Effect>(ent)) {
auto& shader = $world.get<Effect>(ent);
if(shader.$active && !is_shape) {
auto ptr = shader.checkout_ptr();
if(auto shader = $world.get_if<Effect>(ent)) {
if(shader->$active && !is_shape) {
auto ptr = shader->checkout_ptr();
ptr->setUniform("is_shape", is_shape);
// NOTE: this is needed because SFML doesn't handle shared_ptr
shader_ptr = ptr.get();
@ -235,9 +233,9 @@ namespace guecs {
window.draw(*target, shader_ptr);
}
void show_sprite(string region, string sprite_name);
void show_text(string region, wstring content);
void show_label(string region, wstring content);
void show_sprite(const string& region, const string& sprite_name);
void show_text(const string& region, const wstring& content);
void show_label(const string& region, const wstring& content);
};
Clickable make_action(DinkyECS::World& target, Events::GUI event);