From 1db307cb317b45f1b1517ff588d373c75574fc64 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sun, 15 Jun 2025 00:45:32 -0400 Subject: [PATCH] You can now go to work and make money. --- main.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/main.cpp b/main.cpp index 6a925e0..2c94d45 100644 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,7 @@ #include "guecs/sfml/components.hpp" #include "guecs/sfml/sound.hpp" #include "guecs/ui.hpp" +#include "guecs/theme.hpp" #include #include #include @@ -81,6 +82,11 @@ std::unordered_map STATS { {"Mood", 0L} }; +std::wstring make_stat_label(const std::string& name) { + return fmt::format(L"{}:\n{}", guecs::to_wstring(name), + STATS.at(name)); +} + std::unordered_map EVENTS { {"GiveTreat", Event::GIVE_TREAT}, {"GiveFood", Event::GIVE_FOOD}, @@ -104,11 +110,6 @@ struct ClickerUI { "[GiveTreat|GiveFood|GiveWater|GivePets|Work]"); } - std::wstring make_stat_label(const std::string& name) { - return fmt::format(L"{}:\n{}", guecs::to_wstring(name), - STATS.at(name)); - } - void init() { $gui.set($gui.MAIN, {$gui.$parser, {0, 0, 0, 255}}); @@ -217,23 +218,53 @@ struct WorkComputerUI { WorkComputerUI() { $gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); $gui.layout( - "[*%(100,200)clicker|a2 |a3|a4|a5 |*%(100,200)postit1]" - "[_ |a9 |*%(300,300)computer|_|_|_]" - "[a15 |a16|_ |_|_|*%(100,200)postit2]" - "[*%(100,200)coffee |a23|_ |_|_|_]" - "[_ |a50|a51|a52|a53|a54]"); + "[*%(100,200)clicker|_ |_|_|_ |*%(100,200)postit1]" + "[_ |_ |*%(300,300)computer|_|_|_]" + "[_ |_|_ |_|_|*%(100,200)postit2]" + "[*%(100,200)coffee |*%(100,200)floppy|_ |_|_|_]" + "[_ |_ |_|_|_|_]"); } void init() { guecs::Background bg{$gui.$parser}; bg.set_sprite("work_computer"); $gui.set($gui.MAIN, bg); + + for(auto& [name, cell] : $gui.cells()) { + auto gui_id = $gui.entity(name); + + if(name == "clicker") { + $gui.set(gui_id, { + [&](auto,auto) { GAME.at_work = false; } + }); + } else if(name == "computer") { + $gui.set(gui_id, { + [&](auto,auto) { + auto text_id = $gui.entity("postit1"); + auto& text = $gui.get(text_id); + STATS["Money"]++; + text.update(make_stat_label("Money")); + } + }); + } else { + $gui.set(gui_id, { + [&](auto,auto) { fmt::println("CLICK ON {}", name); } + }); + } + + if(name == "postit1") { + $gui.set(gui_id, { + make_stat_label("Money"), 50, guecs::THEME.BLACK, 25 + }); + } + } + $gui.init(); } void render(sf::RenderWindow& window) { $gui.render(window); - $gui.debug_layout(window); + // $gui.debug_layout(window); } void mouse(float x, float y, bool hover) {