GUI for combat now works better and I can create sprites for things if I want.
This commit is contained in:
parent
46de98e6f4
commit
49a71e257e
10 changed files with 55 additions and 18 deletions
15
ecs_gui.cpp
15
ecs_gui.cpp
|
@ -20,7 +20,7 @@ DinkyECS::Entity GUECS::entity(std::string name) {
|
|||
return entity;
|
||||
}
|
||||
|
||||
void GUECS::init() {
|
||||
void GUECS::init(TexturePack& textures) {
|
||||
$world.query<lel::Cell, Rectangle>([](const auto &, auto& cell, auto& rect) {
|
||||
rect.init(cell);
|
||||
});
|
||||
|
@ -28,6 +28,15 @@ void GUECS::init() {
|
|||
$world.query<lel::Cell, Textual>([this](const auto &, auto& cell, auto& text) {
|
||||
text.init(cell, $font);
|
||||
});
|
||||
|
||||
$world.query<lel::Cell, Sprite>([&](const auto &, auto &cell, auto &sprite) {
|
||||
auto sprite_texture = textures.get(sprite.name);
|
||||
sprite.texture = sprite_texture.texture;
|
||||
sprite.sprite = make_shared<sf::Sprite>(*sprite.texture);
|
||||
sprite.sprite->setPosition({float(cell.x + 5), float(cell.y + 5)});
|
||||
auto size = sprite.texture->getSize();
|
||||
sprite.sprite->setScale({float(cell.w - 10) / size.x, float(cell.h - 10) / size.y});
|
||||
});
|
||||
}
|
||||
|
||||
void GUECS::render(sf::RenderWindow& window) {
|
||||
|
@ -44,6 +53,10 @@ void GUECS::render(sf::RenderWindow& window) {
|
|||
window.draw(*rect.shape);
|
||||
});
|
||||
|
||||
$world.query<Sprite>([&](const auto &, const auto& sprite) {
|
||||
window.draw(*sprite.sprite);
|
||||
});
|
||||
|
||||
$world.query<Textual>([&](const auto &, const auto& text) {
|
||||
window.draw(*text.text);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue