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. 33
      status_ui.cpp

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

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

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

@ -47,6 +47,10 @@ namespace guecs {
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) {
auto sprite_texture = textures.get(sprite.name);
sprite.texture = sprite_texture.texture;
@ -78,6 +82,10 @@ namespace guecs {
window.draw(*sprite.sprite);
});
$world.query<Label>([&](auto, auto& text) {
window.draw(*text.text);
});
$world.query<Textual>([&](auto, auto& text) {
window.draw(*text.text);
});

@ -12,15 +12,15 @@
namespace guecs {
using std::shared_ptr, std::make_shared;
struct Textual {
struct Label {
std::string label;
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) {
font = font_ptr;
text = make_shared<sf::Text>(*font, label);
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
@ -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 {
std::function<void(DinkyECS::Entity ent, std::string &name)> action;
};

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

@ -10,16 +10,32 @@ namespace gui {
$level(level)
{
$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) {
auto& world = $gui.world();
auto& cell = $gui.cells().at("log_view");
$log_to = $gui.entity("log_view");
world.set<lel::Cell>($log_to, cell);
world.set<Rectangle>($log_to, {});
world.set<Textual>($log_to, {"TEST"});
for(auto& [name, cell] : $gui.cells()) {
if(name == "log_view") {
$log_to = $gui.entity("log_view");
world.set<lel::Cell>($log_to, cell);
world.set<Rectangle>($log_to, {});
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);
}
@ -28,13 +44,10 @@ namespace gui {
auto &world = $gui.world();
auto &text = world.get<Textual>($log_to);
std::string log;
for(auto msg : $messages) {
log += msg + "\n";
}
text.label = log;
text.update(log);
$gui.render(window);
}

Loading…
Cancel
Save