More GUECS cleanup before releasing. Still need to sort out events and reduce the amount of stuff that GUECS needs.

master
Zed A. Shaw 2 days ago
parent 1780a758b3
commit abea6da2e0
  1. 20
      color.hpp
  2. 1
      combat_ui.cpp
  3. 7
      constants.hpp
  4. 24
      guecs.cpp
  5. 45
      guecs.hpp
  6. 18
      guecstra.cpp
  7. 7
      guecstra.hpp
  8. 1
      gui_fsm.cpp
  9. 1
      meson.build
  10. 1
      raycaster.cpp

@ -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}; constexpr const sf::Color BLACK{0, 0, 0};
const sf::Color DARK_DARK{10, 10, 10}; constexpr const sf::Color DARK_DARK{10, 10, 10};
const sf::Color DARK_MID{30, 30, 30}; constexpr const sf::Color DARK_MID{30, 30, 30};
const sf::Color DARK_LIGHT{60, 60, 60}; constexpr const sf::Color DARK_LIGHT{60, 60, 60};
const sf::Color MID{100, 100, 100}; constexpr const sf::Color MID{100, 100, 100};
const sf::Color LIGHT_DARK{150, 150, 150}; constexpr const sf::Color LIGHT_DARK{150, 150, 150};
const sf::Color LIGHT_MID{200, 200, 200}; constexpr const sf::Color LIGHT_MID{200, 200, 200};
const sf::Color LIGHT_LIGHT{230, 230, 230}; constexpr const sf::Color LIGHT_LIGHT{230, 230, 230};
const sf::Color WHITE{255, 255, 255}; constexpr const sf::Color WHITE{255, 255, 255};
const sf::Color TRANSPARENT = sf::Color::Transparent; constexpr const sf::Color TRANSPARENT = sf::Color::Transparent;
} }

@ -3,6 +3,7 @@
#include "color.hpp" #include "color.hpp"
#include "rituals.hpp" #include "rituals.hpp"
#include <fmt/xchar.h> #include <fmt/xchar.h>
#include "guecstra.hpp"
namespace gui { namespace gui {
using namespace guecs; using namespace guecs;

@ -24,13 +24,6 @@ constexpr const int FRAME_LIMIT=60;
constexpr const int NUM_SPRITES=1; constexpr const int NUM_SPRITES=1;
constexpr const int MAX_LOG_MESSAGES=17; constexpr const int MAX_LOG_MESSAGES=17;
constexpr const int GUECS_PADDING = 3;
constexpr const int GUECS_BORDER_PX = 1;
constexpr const int GUECS_FONT_SIZE = 30;
const sf::Color GUECS_FILL_COLOR = ColorValue::DARK_MID;
const sf::Color GUECS_TEXT_COLOR = ColorValue::LIGHT_LIGHT;
const sf::Color GUECS_BG_COLOR = ColorValue::MID;
const sf::Color GUECS_BORDER_COLOR = ColorValue::MID;
#ifdef NDEBUG #ifdef NDEBUG
constexpr const bool DEBUG_BUILD=false; constexpr const bool DEBUG_BUILD=false;

@ -1,8 +1,11 @@
#include "guecs.hpp" #include "guecs.hpp"
#include "shaders.hpp" #include "shaders.hpp"
#include "sound.hpp" #include "sound.hpp"
#include "textures.hpp"
#include <typeinfo>
namespace guecs { namespace guecs {
using std::make_shared;
void Textual::init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) { void Textual::init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) {
dbc::check(font_ptr != nullptr, "you failed to initialize this WideText"); dbc::check(font_ptr != nullptr, "you failed to initialize this WideText");
@ -314,7 +317,7 @@ namespace guecs {
tc->text->setString(content); tc->text->setString(content);
} else { } else {
auto &cell = cell_for(ent); auto &cell = cell_for(ent);
Textual to_set{content, 20}; Textual to_set{content, TEXT_SIZE};
to_set.init(cell, $font); to_set.init(cell, $font);
set<Textual>(ent, to_set); set<Textual>(ent, to_set);
} }
@ -348,25 +351,10 @@ namespace guecs {
tc->text->setString(content); tc->text->setString(content);
} else { } else {
auto &cell = cell_for(ent); auto &cell = cell_for(ent);
Label to_set{content, 20}; Label to_set{content, LABEL_SIZE};
to_set.init(cell, $font); to_set.init(cell, $font);
to_set.text->setFillColor(ColorValue::LIGHT_MID); to_set.text->setFillColor(TEXT_COLOR);
set<Label>(ent, to_set); set<Label>(ent, to_set);
} }
} }
Clickable make_action(DinkyECS::World& target, Events::GUI event) {
return {[&, event](auto ent, auto data){
// remember that ent is passed in from the UI::mouse handler
target.send<Events::GUI>(event, ent, data);
}};
}
Clickable make_action(DinkyECS::World& target, Events::GUI event, std::any data) {
return {[&, event, data](auto ent, auto){
// remember that ent is passed in from the UI::mouse handler
target.send<Events::GUI>(event, ent, data);
}};
}
} }

@ -1,20 +1,29 @@
#pragma once #pragma once
#include "dbc.hpp"
#include "color.hpp" #include "color.hpp"
#include "dinkyecs.hpp"
#include "lel.hpp" #include "lel.hpp"
#include <string> #include <string>
#include <memory> #include <memory>
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include "textures.hpp"
#include <functional> #include <functional>
#include "events.hpp" #include "events.hpp"
#include "constants.hpp"
#include "components.hpp"
#include <any> #include <any>
#include "shaders.hpp" #include <queue>
#include <typeindex>
#include <unordered_map>
namespace guecs { namespace guecs {
using std::shared_ptr, std::make_shared, std::wstring, std::string; constexpr const int PADDING = 3;
constexpr const int BORDER_PX = 1;
constexpr const int TEXT_SIZE = 30;
constexpr const int LABEL_SIZE = 20;
constexpr const sf::Color FILL_COLOR = ColorValue::DARK_MID;
constexpr const sf::Color TEXT_COLOR = ColorValue::LIGHT_LIGHT;
constexpr const sf::Color BG_COLOR = ColorValue::MID;
constexpr const sf::Color BORDER_COLOR = ColorValue::MID;
constexpr const char *FONT_FILE_NAME="assets/text.otf";
using std::shared_ptr, std::wstring, std::string;
using Entity = unsigned long; using Entity = unsigned long;
@ -28,9 +37,9 @@ namespace guecs {
struct Textual { struct Textual {
std::wstring content; std::wstring content;
unsigned int size = GUECS_FONT_SIZE; unsigned int size = TEXT_SIZE;
sf::Color color = GUECS_TEXT_COLOR; sf::Color color = TEXT_COLOR;
int padding = GUECS_PADDING; int padding = PADDING;
bool centered = false; bool centered = false;
shared_ptr<sf::Font> font = nullptr; shared_ptr<sf::Font> font = nullptr;
shared_ptr<sf::Text> text = nullptr; shared_ptr<sf::Text> text = nullptr;
@ -44,6 +53,7 @@ namespace guecs {
Label(Args... args) : Textual(args...) Label(Args... args) : Textual(args...)
{ {
centered = true; centered = true;
size = LABEL_SIZE;
} }
Label() { Label() {
@ -60,7 +70,7 @@ namespace guecs {
struct Sprite { struct Sprite {
string name; string name;
int padding = GUECS_PADDING; int padding = PADDING;
std::shared_ptr<sf::Sprite> sprite = nullptr; std::shared_ptr<sf::Sprite> sprite = nullptr;
void init(lel::Cell &cell); void init(lel::Cell &cell);
@ -68,10 +78,10 @@ namespace guecs {
}; };
struct Rectangle { struct Rectangle {
int padding = GUECS_PADDING; int padding = PADDING;
sf::Color color = GUECS_FILL_COLOR; sf::Color color = FILL_COLOR;
sf::Color border_color = GUECS_BORDER_COLOR; sf::Color border_color = BORDER_COLOR;
int border_px = GUECS_BORDER_PX; int border_px = BORDER_PX;
shared_ptr<sf::RectangleShape> shape = nullptr; shared_ptr<sf::RectangleShape> shape = nullptr;
void init(lel::Cell& cell); void init(lel::Cell& cell);
@ -121,10 +131,10 @@ namespace guecs {
float y = 0.0f; float y = 0.0f;
float w = 0.0f; float w = 0.0f;
float h = 0.0f; float h = 0.0f;
sf::Color color = GUECS_BG_COLOR; sf::Color color = BG_COLOR;
shared_ptr<sf::RectangleShape> shape = nullptr; shared_ptr<sf::RectangleShape> shape = nullptr;
Background(lel::Parser& parser, sf::Color bg_color=GUECS_BG_COLOR) : Background(lel::Parser& parser, sf::Color bg_color=BG_COLOR) :
x(parser.grid_x), x(parser.grid_x),
y(parser.grid_y), y(parser.grid_y),
w(parser.grid_w), w(parser.grid_w),
@ -353,7 +363,4 @@ namespace guecs {
void show_text(const string& region, const wstring& content); void show_text(const string& region, const wstring& content);
void show_label(const string& region, const wstring& content); void show_label(const string& region, const wstring& content);
}; };
Clickable make_action(DinkyECS::World& target, Events::GUI event);
Clickable make_action(DinkyECS::World& target, Events::GUI event, std::any data);
} }

@ -0,0 +1,18 @@
#include "guecstra.hpp"
namespace guecs {
Clickable make_action(DinkyECS::World& target, Events::GUI event) {
return {[&, event](auto ent, auto data){
// remember that ent is passed in from the UI::mouse handler
target.send<Events::GUI>(event, ent, data);
}};
}
Clickable make_action(DinkyECS::World& target, Events::GUI event, std::any data) {
return {[&, event, data](auto ent, auto){
// remember that ent is passed in from the UI::mouse handler
target.send<Events::GUI>(event, ent, data);
}};
}
}

@ -0,0 +1,7 @@
#include "components.hpp"
#include "guecs.hpp"
namespace guecs {
Clickable make_action(DinkyECS::World& target, Events::GUI event);
Clickable make_action(DinkyECS::World& target, Events::GUI event, std::any data);
}

@ -8,6 +8,7 @@
#include "systems.hpp" #include "systems.hpp"
#include "events.hpp" #include "events.hpp"
#include "sound.hpp" #include "sound.hpp"
#include "shaders.hpp"
#include <fmt/xchar.h> #include <fmt/xchar.h>
namespace gui { namespace gui {

@ -95,6 +95,7 @@ sources = [
'devices.cpp', 'devices.cpp',
'goap.cpp', 'goap.cpp',
'guecs.cpp', 'guecs.cpp',
'guecstra.cpp',
'gui_fsm.cpp', 'gui_fsm.cpp',
'inventory.cpp', 'inventory.cpp',
'lel.cpp', 'lel.cpp',

@ -10,6 +10,7 @@
#include "components.hpp" #include "components.hpp"
#include "textures.hpp" #include "textures.hpp"
#include "systems.hpp" #include "systems.hpp"
#include "shaders.hpp"
using namespace fmt; using namespace fmt;
using std::make_unique; using std::make_unique;

Loading…
Cancel
Save