|
|
|
#pragma once
|
|
|
|
#include "color.hpp"
|
|
|
|
#include "dinkyecs.hpp"
|
|
|
|
#include "lel.hpp"
|
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
|
|
|
#include <SFML/Graphics.hpp>
|
|
|
|
#include "texture.hpp"
|
|
|
|
#include <functional>
|
|
|
|
#include "events.hpp"
|
|
|
|
#include "constants.hpp"
|
|
|
|
|
|
|
|
namespace guecs {
|
|
|
|
using std::shared_ptr, std::make_shared;
|
|
|
|
|
|
|
|
struct Label {
|
|
|
|
std::string label;
|
|
|
|
unsigned int size = GUECS_FONT_SIZE;
|
|
|
|
shared_ptr<sf::Font> font = nullptr;
|
|
|
|
shared_ptr<sf::Text> text = nullptr;
|
|
|
|
|
|
|
|
void init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) {
|
|
|
|
if(font == nullptr) font = font_ptr;
|
|
|
|
if(text == nullptr) text = make_shared<sf::Text>(*font, label, size);
|
|
|
|
auto bounds = text->getLocalBounds();
|
|
|
|
auto text_cell = lel::center(bounds.size.x, bounds.size.y, cell);
|
|
|
|
// this stupid / 2 is because SFML renders from baseline rather than from the claimed bounding box
|
|
|
|
text->setPosition({float(text_cell.x), float(text_cell.y) - text_cell.h / 2});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Textual {
|
|
|
|
std::string content;
|
|
|
|
unsigned int size = GUECS_FONT_SIZE;
|
|
|
|
shared_ptr<sf::Font> font = nullptr;
|
|
|
|
shared_ptr<sf::Text> text = nullptr;
|
|
|
|
|
|
|
|
void init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) {
|
|
|
|
if(font == nullptr) font = font_ptr;
|
|
|
|
if(text == nullptr) text = make_shared<sf::Text>(*font, content, size);
|
|
|
|
text->setPosition({float(cell.x + GUECS_PADDING * 2), float(cell.y + GUECS_PADDING * 2)});
|
|
|
|
text->setCharacterSize(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void update(std::string& new_content) {
|
|
|
|
content = new_content;
|
|
|
|
text->setString(content);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Clickable {
|
|
|
|
std::function<void(DinkyECS::Entity ent, std::string &name)> action;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Sprite {
|
|
|
|
std::string name;
|
|
|
|
std::shared_ptr<sf::Sprite> sprite = nullptr;
|
|
|
|
std::shared_ptr<sf::Texture> texture = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Rectangle {
|
|
|
|
shared_ptr<sf::RectangleShape> shape = nullptr;
|
|
|
|
|
|
|
|
void init(lel::Cell& cell) {
|
|
|
|
sf::Vector2f size{float(cell.w) - GUECS_PADDING * 2, float(cell.h) - GUECS_PADDING * 2};
|
|
|
|
if(shape == nullptr) shape = make_shared<sf::RectangleShape>(size);
|
|
|
|
shape->setPosition({float(cell.x + GUECS_PADDING), float(cell.y + GUECS_PADDING)});
|
|
|
|
shape->setFillColor(GUECS_FILL_COLOR);
|
|
|
|
shape->setOutlineColor(GUECS_BORDER_COLOR);
|
|
|
|
shape->setOutlineThickness(GUECS_BORDER_PX);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Meter {
|
|
|
|
float percent = 1.0f;
|
|
|
|
Rectangle bar;
|
|
|
|
|
|
|
|
void init(lel::Cell& cell) {
|
|
|
|
bar.init(cell);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CellName {
|
|
|
|
std::string name;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Background {
|
|
|
|
float x = 0.0f;
|
|
|
|
float y = 0.0f;
|
|
|
|
float w = 0.0f;
|
|
|
|
float h = 0.0f;
|
|
|
|
|
|
|
|
shared_ptr<sf::RectangleShape> shape = nullptr;
|
|
|
|
|
|
|
|
Background(lel::Parser& parser) :
|
|
|
|
x(parser.grid_x),
|
|
|
|
y(parser.grid_y),
|
|
|
|
w(parser.grid_w),
|
|
|
|
h(parser.grid_h)
|
|
|
|
{}
|
|
|
|
|
|
|
|
Background() {}
|
|
|
|
|
|
|
|
void init() {
|
|
|
|
sf::Vector2f size{float(w), float(h)};
|
|
|
|
if(shape == nullptr) shape = make_shared<sf::RectangleShape>(size);
|
|
|
|
shape->setPosition({float(x), float(y)});
|
|
|
|
shape->setFillColor(GUECS_BG_COLOR);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class UI {
|
|
|
|
public:
|
|
|
|
DinkyECS::World $world;
|
|
|
|
shared_ptr<sf::Font> $font = nullptr;
|
|
|
|
lel::Parser $parser;
|
|
|
|
std::string $grid = "";
|
|
|
|
|
|
|
|
UI();
|
|
|
|
|
|
|
|
void position(int x, int y, int width, int height);
|
|
|
|
void layout(std::string grid);
|
|
|
|
DinkyECS::Entity entity(std::string name);
|
|
|
|
|
|
|
|
inline lel::CellMap& cells() {
|
|
|
|
return $parser.cells;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline DinkyECS::World& world() {
|
|
|
|
return $world;
|
|
|
|
}
|
|
|
|
|
|
|
|
void init(TexturePack& textures);
|
|
|
|
void render(sf::RenderWindow& window);
|
|
|
|
void mouse(float x, float y);
|
|
|
|
};
|
|
|
|
|
|
|
|
Clickable make_action(DinkyECS::World& target, Events::GUI event);
|
|
|
|
}
|