Reworked the gui to use GUECS now so lots of code soon to die.
This commit is contained in:
parent
e78340a0cd
commit
70c2ce7d51
9 changed files with 97 additions and 38 deletions
29
assets/config.json
Normal file
29
assets/config.json
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"sounds": {
|
||||||
|
"you_died": "./assets/you_died.mp3",
|
||||||
|
"build_success": "./assets/build_success.mp3",
|
||||||
|
"build_failed": "./assets/build_failed.mp3",
|
||||||
|
"building": "./mysounds/building.mp3"
|
||||||
|
},
|
||||||
|
"sprites": {
|
||||||
|
"build_success": {
|
||||||
|
"path": "./assets/build_success.png",
|
||||||
|
"frame_width": 240,
|
||||||
|
"frame_height": 240},
|
||||||
|
"you_died": {
|
||||||
|
"path": "./assets/you_died.png",
|
||||||
|
"frame_width": 240,
|
||||||
|
"frame_height": 240},
|
||||||
|
"build_failed": {
|
||||||
|
"path": "./assets/build_failed.png",
|
||||||
|
"frame_width": 240,
|
||||||
|
"frame_height": 240},
|
||||||
|
"building": {
|
||||||
|
"path": "./assets/building.png",
|
||||||
|
"frame_width": 240,
|
||||||
|
"frame_height": 240}
|
||||||
|
},
|
||||||
|
"graphics": {
|
||||||
|
"smooth_textures": false
|
||||||
|
}
|
||||||
|
}
|
1
assets/tiles.json
Normal file
1
assets/tiles.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{}
|
16
color.hpp
16
color.hpp
|
@ -2,14 +2,14 @@
|
||||||
#include <SFML/Graphics/Color.hpp>
|
#include <SFML/Graphics/Color.hpp>
|
||||||
|
|
||||||
namespace ColorValue {
|
namespace ColorValue {
|
||||||
const sf::Color BLACK{0, 0, 0};
|
const sf::Color BLACK{1, 4, 2};
|
||||||
const sf::Color DARK_DARK{10, 10, 10};
|
const sf::Color DARK_DARK{9, 29, 16};
|
||||||
const sf::Color DARK_MID{30, 30, 30};
|
const sf::Color DARK_MID{14, 50, 26};
|
||||||
const sf::Color DARK_LIGHT{60, 60, 60};
|
const sf::Color DARK_LIGHT{0, 109, 44};
|
||||||
const sf::Color MID{100, 100, 100};
|
const sf::Color MID{63, 171, 92};
|
||||||
const sf::Color LIGHT_DARK{150, 150, 150};
|
const sf::Color LIGHT_DARK{161, 217, 155};
|
||||||
const sf::Color LIGHT_MID{200, 200, 200};
|
const sf::Color LIGHT_MID{199, 233, 192};
|
||||||
const sf::Color LIGHT_LIGHT{230, 230, 230};
|
const sf::Color LIGHT_LIGHT{229, 245, 224};
|
||||||
const sf::Color WHITE{255, 255, 255};
|
const sf::Color WHITE{255, 255, 255};
|
||||||
const sf::Color TRANSPARENT = sf::Color::Transparent;
|
const sf::Color TRANSPARENT = sf::Color::Transparent;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,20 +4,18 @@
|
||||||
#include "color.hpp"
|
#include "color.hpp"
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
constexpr const int TEXTURE_WIDTH=256;
|
constexpr const int SCREEN_WIDTH= 1920 / 2;
|
||||||
constexpr const int TEXTURE_HEIGHT=256;
|
constexpr const int SCREEN_HEIGHT= 1080 / 2;
|
||||||
constexpr const int SCREEN_WIDTH=1280;
|
|
||||||
constexpr const int SCREEN_HEIGHT=720;
|
|
||||||
|
|
||||||
constexpr const bool VSYNC=false;
|
constexpr const bool VSYNC=false;
|
||||||
constexpr const int FRAME_LIMIT=60;
|
constexpr const int FRAME_LIMIT=60;
|
||||||
|
|
||||||
constexpr const int GUECS_PADDING = 3;
|
constexpr const int GUECS_PADDING = 3;
|
||||||
constexpr const int GUECS_BORDER_PX = 1;
|
constexpr const int GUECS_BORDER_PX = 1;
|
||||||
constexpr const int GUECS_FONT_SIZE = 30;
|
constexpr const int GUECS_FONT_SIZE = 40;
|
||||||
const sf::Color GUECS_FILL_COLOR = ColorValue::DARK_MID;
|
const sf::Color GUECS_FILL_COLOR = ColorValue::DARK_DARK;
|
||||||
const sf::Color GUECS_TEXT_COLOR = ColorValue::LIGHT_LIGHT;
|
const sf::Color GUECS_TEXT_COLOR = ColorValue::LIGHT_LIGHT;
|
||||||
const sf::Color GUECS_BG_COLOR = ColorValue::MID;
|
const sf::Color GUECS_BG_COLOR = ColorValue::BLACK;
|
||||||
const sf::Color GUECS_BORDER_COLOR = ColorValue::MID;
|
const sf::Color GUECS_BORDER_COLOR = ColorValue::MID;
|
||||||
constexpr const char *FONT_FILE_NAME="assets/text.ttf";
|
constexpr const char *FONT_FILE_NAME="assets/text.ttf";
|
||||||
|
|
||||||
|
|
52
gui.cpp
52
gui.cpp
|
@ -14,7 +14,41 @@
|
||||||
|
|
||||||
using std::string, std::vector;
|
using std::string, std::vector;
|
||||||
|
|
||||||
GUI::GUI(SFMLBackend &backend) : gui(backend) {
|
GUI::GUI(SFMLBackend &backend) : sfml(backend) {
|
||||||
|
using namespace guecs;
|
||||||
|
|
||||||
|
$gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||||
|
$gui.layout(
|
||||||
|
"[*%(200,300)face|_|*%(100,300)stats|*%(200,500)log|_]"
|
||||||
|
"[_|_|_|_|_]"
|
||||||
|
"[_|_|_|_|_]"
|
||||||
|
"[*%(300,200)clock|_|_|_|_]"
|
||||||
|
"[_|_|_|_|_]"
|
||||||
|
"[hp_bar]");
|
||||||
|
|
||||||
|
$gui.world().set_the<Background>({$gui.$parser, ColorValue::DARK_MID});
|
||||||
|
|
||||||
|
for(auto& [name, cell] : $gui.cells()) {
|
||||||
|
auto ent = $gui.entity(name);
|
||||||
|
$gui.set<Rectangle>(ent, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
auto face = $gui.entity("face");
|
||||||
|
$gui.set<Sprite>(face, {"building"});
|
||||||
|
|
||||||
|
auto stats = $gui.entity("stats");
|
||||||
|
$gui.set<Textual>(stats, {L"STATS"});
|
||||||
|
|
||||||
|
auto log = $gui.entity("log");
|
||||||
|
$gui.set<Textual>(log, {L"LOG"});
|
||||||
|
|
||||||
|
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, {});
|
||||||
|
|
||||||
|
$gui.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::output(const string msg) {
|
void GUI::output(const string msg) {
|
||||||
|
@ -23,20 +57,22 @@ void GUI::output(const string msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::main_loop() {
|
void GUI::main_loop() {
|
||||||
gui.handle_events();
|
$gui.render(sfml.window);
|
||||||
gui.update_entities();
|
// $gui.debug_layout(sfml.window);
|
||||||
gui.update_log(_lines);
|
sfml.handle_events();
|
||||||
|
// sfml.update_entities();
|
||||||
|
sfml.update_log(_lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::build_success() {
|
void GUI::build_success() {
|
||||||
gui.change_face("build_success");
|
sfml.change_face("build_success");
|
||||||
sound::stop("building");
|
sound::stop("building");
|
||||||
sound::play("build_success");
|
sound::play("build_success");
|
||||||
output("BUILD FINISHED!");
|
output("BUILD FINISHED!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::build_failed(bool play_sound, const string &command) {
|
void GUI::build_failed(bool play_sound, const string &command) {
|
||||||
gui.change_face("build_failed");
|
sfml.change_face("build_failed");
|
||||||
sound::stop("building");
|
sound::stop("building");
|
||||||
|
|
||||||
if(play_sound) {
|
if(play_sound) {
|
||||||
|
@ -47,7 +83,7 @@ void GUI::build_failed(bool play_sound, const string &command) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::you_died() {
|
void GUI::you_died() {
|
||||||
gui.change_face("you_died");
|
sfml.change_face("you_died");
|
||||||
sound::stop("building");
|
sound::stop("building");
|
||||||
sound::play("you_died");
|
sound::play("you_died");
|
||||||
output("!!!! YOU DIED! !!!! Learn to code luser.");
|
output("!!!! YOU DIED! !!!! Learn to code luser.");
|
||||||
|
@ -55,7 +91,7 @@ void GUI::you_died() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::building() {
|
void GUI::building() {
|
||||||
gui.change_face("building");
|
sfml.change_face("building");
|
||||||
output("############# START ############");
|
output("############# START ############");
|
||||||
output(">>>> Will it Build?");
|
output(">>>> Will it Build?");
|
||||||
sound::play("building");
|
sound::play("building");
|
||||||
|
|
4
gui.hpp
4
gui.hpp
|
@ -3,6 +3,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "game_engine.hpp"
|
#include "game_engine.hpp"
|
||||||
#include "sfmlbackend.hpp"
|
#include "sfmlbackend.hpp"
|
||||||
|
#include "guecs.hpp"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
@ -10,7 +11,8 @@ class Builder;
|
||||||
|
|
||||||
class GUI {
|
class GUI {
|
||||||
std::vector<string> _lines;
|
std::vector<string> _lines;
|
||||||
SFMLBackend &gui;
|
SFMLBackend &sfml;
|
||||||
|
guecs::UI $gui;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
1
main.cpp
1
main.cpp
|
@ -19,6 +19,7 @@ int main()
|
||||||
while(backend.is_open()) {
|
while(backend.is_open()) {
|
||||||
builder.event(BuildEvent::GO);
|
builder.event(BuildEvent::GO);
|
||||||
gui.main_loop();
|
gui.main_loop();
|
||||||
|
backend.window.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.event(BuildEvent::QUIT);
|
builder.event(BuildEvent::QUIT);
|
||||||
|
|
|
@ -33,14 +33,11 @@ std::array<sf::Color, 10> VALUES{
|
||||||
};
|
};
|
||||||
|
|
||||||
SFMLBackend::SFMLBackend(GameEngine &g)
|
SFMLBackend::SFMLBackend(GameEngine &g)
|
||||||
: window(sf::VideoMode({X_DIM, Y_DIM}), "Turing's Tarpit"),
|
: window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Turing's Tarpit"),
|
||||||
game(g), current_face(textures::get("building"))
|
game(g), current_face(textures::get("building"))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SFMLBackend::Window_update() {
|
|
||||||
window.display();
|
|
||||||
}
|
|
||||||
|
|
||||||
sf::Color SFMLBackend::value(Value level) {
|
sf::Color SFMLBackend::value(Value level) {
|
||||||
return VALUES.at(int(level));
|
return VALUES.at(int(level));
|
||||||
|
@ -57,8 +54,8 @@ void SFMLBackend::handle_events() {
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::Vector2f translate(int x, int y) {
|
sf::Vector2f translate(int x, int y) {
|
||||||
float step_x = X_DIM / TEXT_SIZE;
|
float step_x = SCREEN_WIDTH / TEXT_SIZE;
|
||||||
float step_y = (Y_DIM - 12) / TEXT_SIZE;
|
float step_y = (SCREEN_HEIGHT - 12) / TEXT_SIZE;
|
||||||
|
|
||||||
sf::Vector2f position{step_x * x, step_y * y * 2};
|
sf::Vector2f position{step_x * x, step_y * y * 2};
|
||||||
|
|
||||||
|
@ -121,7 +118,6 @@ void SFMLBackend::update_entities() {
|
||||||
|
|
||||||
string time = fmt::format("{:%H:%M:%OS}", elapsed_time);
|
string time = fmt::format("{:%H:%M:%OS}", elapsed_time);
|
||||||
write_text(7, 14, time, 2.0f);
|
write_text(7, 14, time, 2.0f);
|
||||||
Window_update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SFMLBackend::change_face(const string& name) {
|
void SFMLBackend::change_face(const string& name) {
|
||||||
|
@ -150,8 +146,8 @@ void SFMLBackend::startup() {
|
||||||
|
|
||||||
window.setPosition({0,0});
|
window.setPosition({0,0});
|
||||||
|
|
||||||
window.setFramerateLimit(FPS);
|
window.setFramerateLimit(FRAME_LIMIT);
|
||||||
window.setVerticalSyncEnabled(true);
|
window.setVerticalSyncEnabled(VSYNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SFMLBackend::is_open() {
|
bool SFMLBackend::is_open() {
|
||||||
|
|
|
@ -18,10 +18,6 @@ enum class Value {
|
||||||
LIGHT_LIGHT, WHITE, TRANSPARENT
|
LIGHT_LIGHT, WHITE, TRANSPARENT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
constexpr int FPS=30;
|
|
||||||
constexpr int X_DIM = 1920 / 2;
|
|
||||||
constexpr int Y_DIM = 1080 / 2;
|
|
||||||
constexpr int TEXT_SIZE = 48;
|
constexpr int TEXT_SIZE = 48;
|
||||||
constexpr Value TEXT_COLOR = Value::LIGHT_LIGHT;
|
constexpr Value TEXT_COLOR = Value::LIGHT_LIGHT;
|
||||||
constexpr int Y_LINES = 23;
|
constexpr int Y_LINES = 23;
|
||||||
|
@ -35,6 +31,7 @@ enum class Button {
|
||||||
};
|
};
|
||||||
|
|
||||||
class SFMLBackend {
|
class SFMLBackend {
|
||||||
|
public:
|
||||||
sf::ContextSettings settings;
|
sf::ContextSettings settings;
|
||||||
sf::RenderWindow window;
|
sf::RenderWindow window;
|
||||||
std::chrono::time_point<std::chrono::system_clock> clock_start;
|
std::chrono::time_point<std::chrono::system_clock> clock_start;
|
||||||
|
@ -45,7 +42,6 @@ class SFMLBackend {
|
||||||
GameEngine &game;
|
GameEngine &game;
|
||||||
textures::SpriteTexture current_face;
|
textures::SpriteTexture current_face;
|
||||||
|
|
||||||
public:
|
|
||||||
SFMLBackend(GameEngine &g);
|
SFMLBackend(GameEngine &g);
|
||||||
|
|
||||||
// prevent copy
|
// prevent copy
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue