You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.8 KiB
77 lines
1.8 KiB
#pragma once
|
|
#include "color.hpp"
|
|
#include "dinkyecs.hpp"
|
|
#include "lel.hpp"
|
|
#include <string>
|
|
#include <memory>
|
|
#include <SFML/Graphics.hpp>
|
|
|
|
using std::shared_ptr, std::make_shared;
|
|
|
|
struct Textual {
|
|
std::string label;
|
|
shared_ptr<sf::Font> font = nullptr;
|
|
shared_ptr<sf::Text> text = nullptr;
|
|
|
|
void init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) {
|
|
font = font_ptr;
|
|
text = make_shared<sf::Text>(*font, label);
|
|
|
|
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 Clickable {
|
|
int event = 0;
|
|
};
|
|
|
|
struct Rectangle {
|
|
shared_ptr<sf::RectangleShape> shape = nullptr;
|
|
|
|
void init(lel::Cell& cell) {
|
|
sf::Vector2f size{(float)cell.w, (float)cell.h};
|
|
if(shape == nullptr) shape = make_shared<sf::RectangleShape>(size);
|
|
shape->setPosition({float(cell.x + 3), float(cell.y + 3)});
|
|
shape->setSize({float(cell.w - 6), float(cell.h - 6)});
|
|
shape->setFillColor(ColorValue::DARK_MID);
|
|
shape->setOutlineColor(ColorValue::MID);
|
|
shape->setOutlineThickness(1);
|
|
}
|
|
};
|
|
|
|
struct Meter {
|
|
float percent = 100.0;
|
|
};
|
|
|
|
struct CellName {
|
|
std::string name;
|
|
};
|
|
|
|
class GUECS {
|
|
public:
|
|
DinkyECS::World $world;
|
|
shared_ptr<sf::Font> $font = nullptr;
|
|
lel::Parser $parser;
|
|
std::string $grid = "";
|
|
|
|
GUECS();
|
|
|
|
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();
|
|
void render(sf::RenderWindow& window);
|
|
void mouse(sf::RenderWindow &window);
|
|
};
|
|
|