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