First prototype of the work computer.
This commit is contained in:
parent
061889cfa9
commit
ac24f2cc36
3 changed files with 72 additions and 16 deletions
|
@ -16,6 +16,11 @@
|
|||
"frame_width": 1024,
|
||||
"frame_height": 1024
|
||||
},
|
||||
"work_computer":
|
||||
{"path": "assets/work_computer-1024.png",
|
||||
"frame_width": 1024,
|
||||
"frame_height": 1024
|
||||
},
|
||||
"clicker_treat_bone":
|
||||
{"path": "assets/clicker_treat_bone.png",
|
||||
"frame_width": 256,
|
||||
|
|
BIN
assets/work_computer-1024.png
Normal file
BIN
assets/work_computer-1024.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 409 KiB |
73
main.cpp
73
main.cpp
|
@ -5,10 +5,11 @@
|
|||
#include <deque>
|
||||
#include <iostream>
|
||||
|
||||
constexpr const int WINDOW_WIDTH=1280;
|
||||
constexpr const int WINDOW_HEIGHT=720;
|
||||
constexpr const int SCREEN_WIDTH=1280;
|
||||
constexpr const int SCREEN_HEIGHT=720;
|
||||
constexpr const int FRAME_LIMIT=60;
|
||||
constexpr const bool VSYNC=true;
|
||||
bool GO_TO_WORK = false;
|
||||
|
||||
using std::string, std::wstring;
|
||||
|
||||
|
@ -71,13 +72,13 @@ struct ClickerUI {
|
|||
guecs::Entity $clicker;
|
||||
|
||||
ClickerUI() {
|
||||
$gui.position(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
$gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
$gui.layout(
|
||||
"[_|*%(300,400)clicker|_|_|_]"
|
||||
"[_|_ |_|_|_]"
|
||||
"[_|_ |_|_|_]"
|
||||
"[_|_ |_|_|_]"
|
||||
"[a1|a2|a3|a4|a5]");
|
||||
"[FoodBowl|_|*%(300,400)clicker|_|_|_]"
|
||||
"[WaterBowl|_|_ |_|_|_]"
|
||||
"[Mood|_|_ |_|_|_]"
|
||||
"[_|_|_ |_|_|_]"
|
||||
"[Treat|Food|Water|Pet|Work]");
|
||||
}
|
||||
|
||||
void init() {
|
||||
|
@ -88,13 +89,20 @@ struct ClickerUI {
|
|||
if(name != "clicker") {
|
||||
$gui.set<guecs::Rectangle>(id, {});
|
||||
$gui.set<guecs::Effect>(id, {});
|
||||
$gui.set<guecs::Sprite>(id, { "clicker_treat_bone" });
|
||||
fmt::println("button dim: {},{}", cell.w, cell.h);
|
||||
$gui.set<guecs::Label>(id, { guecs::to_wstring(name) });
|
||||
|
||||
if(name == "Work") {
|
||||
$gui.set<guecs::Clickable>(id, { [&](auto, auto) {
|
||||
GO_TO_WORK = true;
|
||||
fmt::println("Going to Work!");
|
||||
} });
|
||||
} else {
|
||||
$gui.set<guecs::Clickable>(id, {
|
||||
[&](auto, auto) { handle_button(Event::A_BUTTON); }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$clicker = $gui.entity("clicker");
|
||||
$gui.set<guecs::Sprite>($clicker, {"clicker_the_dog"});
|
||||
|
@ -146,17 +154,51 @@ struct ClickerUI {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
struct WorkComputerUI {
|
||||
guecs::UI $gui;
|
||||
|
||||
WorkComputerUI() {
|
||||
$gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
$gui.layout("[_|*%(300)computer|_|_|_]");
|
||||
}
|
||||
|
||||
void init() {
|
||||
auto computer = $gui.entity("computer");
|
||||
$gui.set<guecs::Sprite>(computer, {"work_computer"});
|
||||
$gui.set<guecs::Label>(computer, {L"Work Computer"});
|
||||
$gui.set<guecs::Clickable>(computer, { [&](auto, auto) {
|
||||
GO_TO_WORK = false;
|
||||
fmt::println("Leaving Work!");
|
||||
} });
|
||||
|
||||
$gui.init();
|
||||
}
|
||||
|
||||
void render(sf::RenderWindow& window) {
|
||||
$gui.render(window);
|
||||
}
|
||||
|
||||
void mouse(float x, float y, bool hover) {
|
||||
$gui.mouse(x, y, hover);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main() {
|
||||
sfml::Backend backend;
|
||||
guecs::init(&backend);
|
||||
|
||||
sf::RenderWindow window(sf::VideoMode({WINDOW_WIDTH, WINDOW_HEIGHT}), "Clicker the Dog");
|
||||
sf::RenderWindow window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Clicker the Dog");
|
||||
window.setFramerateLimit(FRAME_LIMIT);
|
||||
window.setVerticalSyncEnabled(VSYNC);
|
||||
|
||||
ClickerUI clicker;
|
||||
clicker.init();
|
||||
|
||||
WorkComputerUI computer;
|
||||
computer.init();
|
||||
|
||||
while(window.isOpen()) {
|
||||
while (const auto event = window.pollEvent()) {
|
||||
if(event->is<sf::Event::Closed>()) {
|
||||
|
@ -166,12 +208,21 @@ int main() {
|
|||
if(const auto* mouse = event->getIf<sf::Event::MouseButtonPressed>()) {
|
||||
if(mouse->button == sf::Mouse::Button::Left) {
|
||||
sf::Vector2f pos = window.mapPixelToCoords(mouse->position);
|
||||
if(GO_TO_WORK) {
|
||||
computer.mouse(pos.x, pos.y, false);
|
||||
} else {
|
||||
clicker.mouse(pos.x, pos.y, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(GO_TO_WORK) {
|
||||
window.clear();
|
||||
computer.render(window);
|
||||
} else {
|
||||
clicker.render(window);
|
||||
}
|
||||
window.display();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue