You can now go to work and make money.

main
Zed A. Shaw 5 days ago
parent 93e258cb1b
commit 1db307cb31
  1. 53
      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 <fmt/xchar.h>
#include <deque>
#include <iostream>
@ -81,6 +82,11 @@ std::unordered_map<std::string, long> 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<std::string, Event> 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<guecs::Background>($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<guecs::Background>($gui.MAIN, bg);
for(auto& [name, cell] : $gui.cells()) {
auto gui_id = $gui.entity(name);
if(name == "clicker") {
$gui.set<guecs::Clickable>(gui_id, {
[&](auto,auto) { GAME.at_work = false; }
});
} else if(name == "computer") {
$gui.set<guecs::Clickable>(gui_id, {
[&](auto,auto) {
auto text_id = $gui.entity("postit1");
auto& text = $gui.get<guecs::Textual>(text_id);
STATS["Money"]++;
text.update(make_stat_label("Money"));
}
});
} else {
$gui.set<guecs::Clickable>(gui_id, {
[&](auto,auto) { fmt::println("CLICK ON {}", name); }
});
}
if(name == "postit1") {
$gui.set<guecs::Textual>(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) {

Loading…
Cancel
Save