UI is now working the same as last time but using GUECS.

This commit is contained in:
Zed A. Shaw 2025-04-22 11:54:35 -04:00
parent 70c2ce7d51
commit 8f3a3c10c2
5 changed files with 41 additions and 18 deletions

34
gui.cpp
View file

@ -2,6 +2,7 @@
#include <stdlib.h> // for EXIT_SUCCESS
#include <chrono> // for milliseconds
#include <fmt/core.h>
#include <fmt/xchar.h>
#include <memory> // for allocator, shared_ptr
#include <string> // for operator+, to_string
#include <vector>
@ -19,7 +20,7 @@ GUI::GUI(SFMLBackend &backend) : sfml(backend) {
$gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
$gui.layout(
"[*%(200,300)face|_|*%(100,300)stats|*%(200,500)log|_]"
"[*%(200,300)face|_|*%(100,300)status|*%(200,500)log|_]"
"[_|_|_|_|_]"
"[_|_|_|_|_]"
"[*%(300,200)clock|_|_|_|_]"
@ -36,8 +37,8 @@ GUI::GUI(SFMLBackend &backend) : sfml(backend) {
auto face = $gui.entity("face");
$gui.set<Sprite>(face, {"building"});
auto stats = $gui.entity("stats");
$gui.set<Textual>(stats, {L"STATS"});
auto status = $gui.entity("status");
$gui.set<Textual>(status, {L""});
auto log = $gui.entity("log");
$gui.set<Textual>(log, {L"LOG"});
@ -45,8 +46,8 @@ GUI::GUI(SFMLBackend &backend) : sfml(backend) {
auto clock = $gui.entity("clock");
$gui.set<Label>(clock, {L"00:00:00", 110});
auto hp_bar = $gui.entity("hp_bar");
$gui.set<Meter>(hp_bar, {});
$hp_bar = $gui.entity("hp_bar");
$gui.set<Meter>($hp_bar, {1.0f, {10, ColorValue::LIGHT_DARK}});
$gui.init();
}
@ -57,7 +58,13 @@ void GUI::output(const string msg) {
}
void GUI::main_loop() {
auto clock_time = std::chrono::system_clock::now();
std::wstring time = std::format(L"{:%H:%M:%OS}", clock_time);
$gui.show_label("clock", time);
$gui.show_text("status", $status);
$gui.render(sfml.window);
// $gui.debug_layout(sfml.window);
sfml.handle_events();
// sfml.update_entities();
@ -65,14 +72,14 @@ void GUI::main_loop() {
}
void GUI::build_success() {
sfml.change_face("build_success");
$gui.show_sprite("face", "build_success");
sound::stop("building");
sound::play("build_success");
output("BUILD FINISHED!");
}
void GUI::build_failed(bool play_sound, const string &command) {
sfml.change_face("build_failed");
$gui.show_sprite("face", "build_failed");
sound::stop("building");
if(play_sound) {
@ -82,8 +89,17 @@ void GUI::build_failed(bool play_sound, const string &command) {
output(fmt::format("!!! BUILD FAILED. Your command correct? '{}'", command));
}
void GUI::update_status(GameEngine &game) {
$status = fmt::format(L"HP {}\nRounds {}\nStreaks {}\nDeaths {}",
game.hit_points, game.rounds,
game.streak, game.deaths);
auto& meter = $gui.get<guecs::Meter>($hp_bar);
meter.percent = float(game.hit_points) / float(game.max_hp());
}
void GUI::you_died() {
sfml.change_face("you_died");
$gui.show_sprite("face", "you_died");
sound::stop("building");
sound::play("you_died");
output("!!!! YOU DIED! !!!! Learn to code luser.");
@ -91,7 +107,7 @@ void GUI::you_died() {
}
void GUI::building() {
sfml.change_face("building");
$gui.show_sprite("face", "building");
output("############# START ############");
output(">>>> Will it Build?");
sound::play("building");