Status UI now has a log and some buttons.

master
Zed A. Shaw 3 weeks ago
parent 3a6ba8445a
commit bfe0d797c8
  1. 2
      combat_ui.cpp
  2. 2
      constants.hpp
  3. 2
      events.hpp
  4. 8
      guecs.cpp
  5. 27
      guecs.hpp
  6. 4
      gui.cpp
  7. 27
      status_ui.cpp

@ -27,7 +27,7 @@ namespace gui {
world.set<Sprite>(button, {"trash_button"}); world.set<Sprite>(button, {"trash_button"});
world.set<Clickable>(button, world.set<Clickable>(button,
guecs::make_action(*$level.world, Events::GUI::ATTACK)); guecs::make_action(*$level.world, Events::GUI::ATTACK));
world.set<Textual>(button, {"Attack"}); world.set<Label>(button, {"Attack"});
} else if(name.starts_with("bar_")) { } else if(name.starts_with("bar_")) {
$meter = $gui.entity(name); $meter = $gui.entity(name);
world.set<lel::Cell>($meter, cell); world.set<lel::Cell>($meter, cell);

@ -13,7 +13,7 @@ constexpr const int RAY_VIEW_Y=0;
constexpr const bool VSYNC=false; constexpr const bool VSYNC=false;
constexpr const int FRAME_LIMIT=60; constexpr const int FRAME_LIMIT=60;
constexpr const int NUM_SPRITES=1; constexpr const int NUM_SPRITES=1;
constexpr const int MAX_LOG_MESSAGES=20; constexpr const int MAX_LOG_MESSAGES=17;
#ifdef NDEBUG #ifdef NDEBUG
constexpr const bool DEBUG_BUILD=false; constexpr const bool DEBUG_BUILD=false;

@ -3,7 +3,7 @@
namespace Events { namespace Events {
enum GUI { enum GUI {
START, COMBAT, LOOT, DEATH, STAIRS_UP, STAIRS_DOWN, TRAP, START, COMBAT, LOOT, DEATH, STAIRS_UP, STAIRS_DOWN, TRAP,
COMBAT_START, NO_NEIGHBORS, ATTACK COMBAT_START, NO_NEIGHBORS, ATTACK, NOOP
}; };
struct Combat { struct Combat {

@ -47,6 +47,10 @@ namespace guecs {
text.init(cell, $font); text.init(cell, $font);
}); });
$world.query<lel::Cell, Label>([this](auto, auto& cell, auto& text) {
text.init(cell, $font);
});
$world.query<lel::Cell, Sprite>([&](auto, auto &cell, auto &sprite) { $world.query<lel::Cell, Sprite>([&](auto, auto &cell, auto &sprite) {
auto sprite_texture = textures.get(sprite.name); auto sprite_texture = textures.get(sprite.name);
sprite.texture = sprite_texture.texture; sprite.texture = sprite_texture.texture;
@ -78,6 +82,10 @@ namespace guecs {
window.draw(*sprite.sprite); window.draw(*sprite.sprite);
}); });
$world.query<Label>([&](auto, auto& text) {
window.draw(*text.text);
});
$world.query<Textual>([&](auto, auto& text) { $world.query<Textual>([&](auto, auto& text) {
window.draw(*text.text); window.draw(*text.text);
}); });

@ -12,15 +12,15 @@
namespace guecs { namespace guecs {
using std::shared_ptr, std::make_shared; using std::shared_ptr, std::make_shared;
struct Textual { struct Label {
std::string label; std::string label;
unsigned int size = 30;
shared_ptr<sf::Font> font = nullptr; shared_ptr<sf::Font> font = nullptr;
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) {
font = font_ptr; if(font == nullptr) font = font_ptr;
text = make_shared<sf::Text>(*font, label); if(text == nullptr) text = make_shared<sf::Text>(*font, label, size);
auto bounds = text->getLocalBounds(); auto bounds = text->getLocalBounds();
auto text_cell = lel::center(bounds.size.x, bounds.size.y, cell); 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 // this stupid / 2 is because SFML renders from baseline rather than from the claimed bounding box
@ -28,6 +28,25 @@ namespace guecs {
} }
}; };
struct Textual {
std::string content;
unsigned int size = 30;
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 + 6), float(cell.y + 6)});
text->setCharacterSize(size);
}
void update(std::string& new_content) {
content = new_content;
text->setString(content);
}
};
struct Clickable { struct Clickable {
std::function<void(DinkyECS::Entity ent, std::string &name)> action; std::function<void(DinkyECS::Entity ent, std::string &name)> action;
}; };

@ -353,6 +353,7 @@ namespace gui {
void FSM::mouse() { void FSM::mouse() {
// need to sort out how this will be easier with multiple UIs // need to sort out how this will be easier with multiple UIs
$combat_view.$gui.mouse($window); $combat_view.$gui.mouse($window);
$status_view.$gui.mouse($window);
} }
void FSM::generate_map() { void FSM::generate_map() {
@ -421,6 +422,9 @@ namespace gui {
$rotation = 0; $rotation = 0;
event(Event::ATTACK); event(Event::ATTACK);
break; break;
case eGUI::NOOP:
$status_view.log(fmt::format("NOOP EVENT! {},{}", evt, entity));
break;
default: default:
$status_view.log(fmt::format("INVALID EVENT! {},{}", evt, entity)); $status_view.log(fmt::format("INVALID EVENT! {},{}", evt, entity));
} }

@ -10,16 +10,32 @@ namespace gui {
$level(level) $level(level)
{ {
$gui.position(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT); $gui.position(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT);
$gui.layout("[log_view]"); $gui.layout(
"[*%(100,200)log_view]"
"[_]"
"[button1 | button2 | button3]"
"[button4 | button5 | button6]"
);
} }
void StatusUI::render(TexturePack &textures) { void StatusUI::render(TexturePack &textures) {
auto& world = $gui.world(); auto& world = $gui.world();
auto& cell = $gui.cells().at("log_view");
for(auto& [name, cell] : $gui.cells()) {
if(name == "log_view") {
$log_to = $gui.entity("log_view"); $log_to = $gui.entity("log_view");
world.set<lel::Cell>($log_to, cell); world.set<lel::Cell>($log_to, cell);
world.set<Rectangle>($log_to, {}); world.set<Rectangle>($log_to, {});
world.set<Textual>($log_to, {"TEST"}); world.set<Textual>($log_to, {"Welcome to the Game!", 20});
} else {
auto button = $gui.entity(name);
world.set<lel::Cell>(button, cell);
world.set<Rectangle>(button, {});
world.set<Label>(button, {name});
world.set<Clickable>(button,
guecs::make_action(*$level.world, Events::GUI::NOOP));
}
}
$gui.init(textures); $gui.init(textures);
} }
@ -28,13 +44,10 @@ namespace gui {
auto &world = $gui.world(); auto &world = $gui.world();
auto &text = world.get<Textual>($log_to); auto &text = world.get<Textual>($log_to);
std::string log; std::string log;
for(auto msg : $messages) { for(auto msg : $messages) {
log += msg + "\n"; log += msg + "\n";
} }
text.update(log);
text.label = log;
$gui.render(window); $gui.render(window);
} }

Loading…
Cancel
Save