Separate out the major UIs to get ready for their development, and enable debug button.
This commit is contained in:
parent
7eec67ffc8
commit
9b3b81683a
11 changed files with 154 additions and 116 deletions
16
color.hpp
16
color.hpp
|
@ -1,14 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
namespace ColorValue {
|
||||
const sf::Color BLACK{1, 4, 2};
|
||||
const sf::Color DARK_DARK{9, 29, 16};
|
||||
const sf::Color DARK_MID{14, 50, 26};
|
||||
const sf::Color DARK_LIGHT{0, 109, 44};
|
||||
const sf::Color MID{63, 171, 92};
|
||||
const sf::Color LIGHT_DARK{161, 217, 155};
|
||||
const sf::Color LIGHT_MID{199, 233, 192};
|
||||
const sf::Color LIGHT_LIGHT{229, 245, 224};
|
||||
const sf::Color BLACK{0, 0, 0};
|
||||
const sf::Color DARK_DARK{10, 10, 10};
|
||||
const sf::Color DARK_MID{30, 30, 30};
|
||||
const sf::Color DARK_LIGHT{60, 60, 60};
|
||||
const sf::Color MID{100, 100, 100};
|
||||
const sf::Color LIGHT_DARK{150, 150, 150};
|
||||
const sf::Color LIGHT_MID{200, 200, 200};
|
||||
const sf::Color LIGHT_LIGHT{230, 230, 230};
|
||||
const sf::Color WHITE{255, 255, 255};
|
||||
const sf::Color TRANSPARENT = sf::Color::Transparent;
|
||||
}
|
||||
|
|
35
combat_ui.cpp
Normal file
35
combat_ui.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include "combat_ui.hpp"
|
||||
#include <ftxui/dom/node.hpp> // for Render
|
||||
#include <ftxui/screen/box.hpp> // for ftxui
|
||||
#include <ftxui/component/loop.hpp>
|
||||
#include <ftxui/screen/color.hpp>
|
||||
#include <ftxui/dom/table.hpp>
|
||||
#include "constants.hpp"
|
||||
#include "color.hpp"
|
||||
|
||||
namespace gui {
|
||||
using namespace ftxui;
|
||||
|
||||
CombatUI::CombatUI(GameLevel level) :
|
||||
Panel(COMBAT_UI_X, COMBAT_UI_Y, COMBAT_UI_WIDTH, COMBAT_UI_HEIGHT, false),
|
||||
$level(level)
|
||||
{
|
||||
default_bg = {0,0,0};
|
||||
}
|
||||
|
||||
void CombatUI::create_render() {
|
||||
$attack1_button = Button("ATTACK1", []{ fmt::println("ATTACK1 clicked"); });
|
||||
$attack2_button = Button("ATTACK2", []{ fmt::println("ATTACK2 clicked"); });
|
||||
|
||||
auto combat_rend = Renderer([&]{
|
||||
return hbox({
|
||||
$attack1_button->Render(),
|
||||
$attack2_button->Render()
|
||||
});
|
||||
});
|
||||
|
||||
set_renderer(combat_rend);
|
||||
add($attack1_button);
|
||||
add($attack2_button);
|
||||
}
|
||||
}
|
18
combat_ui.hpp
Normal file
18
combat_ui.hpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
#include "panel.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
#include <ftxui/component/component.hpp>
|
||||
|
||||
namespace gui {
|
||||
class CombatUI : public Panel {
|
||||
public:
|
||||
GameLevel $level;
|
||||
Component $attack1_button;
|
||||
Component $attack2_button;
|
||||
|
||||
CombatUI(GameLevel level);
|
||||
|
||||
void create_render();
|
||||
void update_level(GameLevel &level) { $level = level; }
|
||||
};
|
||||
}
|
|
@ -45,6 +45,7 @@ namespace components {
|
|||
struct Debug {
|
||||
bool PATHS=false;
|
||||
bool LIGHT=false;
|
||||
bool FPS=false;
|
||||
};
|
||||
|
||||
struct Weapon {
|
||||
|
|
|
@ -37,9 +37,15 @@ constexpr int BASE_MAP_FONT_SIZE=90;
|
|||
constexpr int GAME_MAP_PIXEL_POS = 600;
|
||||
constexpr int MAX_FONT_SIZE = 140;
|
||||
constexpr int MIN_FONT_SIZE = 20;
|
||||
constexpr int STATUS_UI_WIDTH = 40;
|
||||
constexpr int STATUS_UI_HEIGHT = 30;
|
||||
constexpr int STATUS_UI_WIDTH = 29;
|
||||
constexpr int STATUS_UI_HEIGHT = 25;
|
||||
constexpr int STATUS_UI_X = 43;
|
||||
constexpr int STATUS_UI_Y = 200;
|
||||
constexpr float PERCENT = 0.01f;
|
||||
constexpr int COMBAT_UI_WIDTH = 89;
|
||||
constexpr int COMBAT_UI_HEIGHT = 6;
|
||||
constexpr int COMBAT_UI_X = RAY_VIEW_X;
|
||||
constexpr int COMBAT_UI_Y = RAY_VIEW_HEIGHT;
|
||||
|
||||
|
||||
// for the panels/renderer
|
||||
|
|
71
gui.cpp
71
gui.cpp
|
@ -6,62 +6,10 @@
|
|||
#include "components.hpp"
|
||||
#include <numbers>
|
||||
#include "systems.hpp"
|
||||
#include "map_view.hpp"
|
||||
#include <ftxui/dom/node.hpp> // for Render
|
||||
#include <ftxui/screen/box.hpp> // for ftxui
|
||||
#include <ftxui/component/loop.hpp>
|
||||
#include <ftxui/screen/color.hpp>
|
||||
#include <ftxui/dom/table.hpp>
|
||||
|
||||
using namespace components;
|
||||
using namespace ftxui;
|
||||
|
||||
namespace gui {
|
||||
|
||||
void StatusUI::create_render() {
|
||||
auto player = $level.world->get_the<Player>();
|
||||
|
||||
auto status_rend = Renderer([&, player]{
|
||||
const auto& player_combat = $level.world->get<Combat>(player.entity);
|
||||
const auto& combat = $level.world->get<Combat>(player.entity);
|
||||
|
||||
std::vector<Element> log_list;
|
||||
log_list.push_back(text("Log messages here."));
|
||||
|
||||
auto log_box = vbox(log_list) | yflex_grow;
|
||||
|
||||
return hbox({
|
||||
hflow(
|
||||
vbox(
|
||||
text(fmt::format("HP: {: >3} DMG: {: >3}",
|
||||
player_combat.hp,
|
||||
combat.damage)),
|
||||
separator(),
|
||||
log_box
|
||||
) | flex_grow
|
||||
)
|
||||
});
|
||||
});
|
||||
|
||||
set_renderer(status_rend);
|
||||
}
|
||||
|
||||
void CombatUI::create_render() {
|
||||
$attack1_button = Button("ATTACK1", []{ fmt::println("ATTACK1 clicked"); });
|
||||
$attack2_button = Button("ATTACK2", []{ fmt::println("ATTACK2 clicked"); });
|
||||
|
||||
auto combat_rend = Renderer([&]{
|
||||
return hbox({
|
||||
$attack1_button->Render(),
|
||||
$attack2_button->Render()
|
||||
});
|
||||
});
|
||||
|
||||
set_renderer(combat_rend);
|
||||
add($attack1_button);
|
||||
add($attack2_button);
|
||||
}
|
||||
|
||||
using namespace components;
|
||||
|
||||
FSM::FSM() :
|
||||
$window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing"),
|
||||
|
@ -76,7 +24,7 @@ namespace gui {
|
|||
{
|
||||
$window.setVerticalSyncEnabled(VSYNC);
|
||||
$window.setFramerateLimit(FRAME_LIMIT);
|
||||
$text.setPosition({10,10});
|
||||
$text.setPosition({43,300});
|
||||
$text.setFillColor({255,255,255});
|
||||
$textures.load_tiles();
|
||||
$textures.load_sprites();
|
||||
|
@ -261,6 +209,11 @@ namespace gui {
|
|||
case KEY::Escape:
|
||||
event(Event::CLOSE);
|
||||
break;
|
||||
case KEY::P: {
|
||||
auto& debug = $level.world->get_the<Debug>();
|
||||
debug.FPS = !debug.FPS;
|
||||
debug.PATHS = !debug.PATHS;
|
||||
} break;
|
||||
default:
|
||||
break; // ignored
|
||||
}
|
||||
|
@ -290,13 +243,10 @@ namespace gui {
|
|||
"count:{:<10}\n\n"
|
||||
"VSync? {}\n"
|
||||
"FR Limit: {}\n"
|
||||
"Debug? {}\n\n"
|
||||
"dir: {:>2.02},{:>2.02}\n"
|
||||
"pos: {:>2.02},{:>2.02}\n\n",
|
||||
"Debug? {}\n\n",
|
||||
player_combat.hp, $stats.mean(), $stats.stddev(), $stats.min,
|
||||
$stats.max, $stats.n, VSYNC,
|
||||
FRAME_LIMIT, DEBUG_BUILD, $rayview.$dir_x,
|
||||
$rayview.$dir_y, $rayview.$pos_x, $rayview.$pos_y));
|
||||
FRAME_LIMIT, DEBUG_BUILD));
|
||||
|
||||
$window.draw($text);
|
||||
}
|
||||
|
@ -321,6 +271,9 @@ namespace gui {
|
|||
|
||||
$combat_view.render();
|
||||
$renderer.draw($combat_view);
|
||||
|
||||
auto debug = $level.world->get_the<Debug>();
|
||||
if(debug.FPS) draw_stats();
|
||||
}
|
||||
|
||||
void FSM::render() {
|
||||
|
|
36
gui.hpp
36
gui.hpp
|
@ -7,41 +7,10 @@
|
|||
#include "fsm.hpp"
|
||||
#include "render.hpp"
|
||||
#include "map_view.hpp"
|
||||
#include <ftxui/dom/elements.hpp> // for hflow, paragraph, separator, hbox, vbox, filler, operator|, border, Element
|
||||
#include "combat_ui.hpp"
|
||||
#include "status_ui.hpp"
|
||||
|
||||
namespace gui {
|
||||
class StatusUI : public Panel {
|
||||
public:
|
||||
GameLevel $level;
|
||||
|
||||
StatusUI(GameLevel level) :
|
||||
Panel(43, 200, 29, 25, false),
|
||||
$level(level)
|
||||
{
|
||||
default_bg = sf::Color{30,30,30};
|
||||
}
|
||||
|
||||
void create_render();
|
||||
void update_level(GameLevel &level) { $level = level; }
|
||||
};
|
||||
|
||||
class CombatUI : public Panel {
|
||||
public:
|
||||
GameLevel $level;
|
||||
Component $attack1_button;
|
||||
Component $attack2_button;
|
||||
|
||||
CombatUI(GameLevel level) :
|
||||
Panel(RAY_VIEW_X, RAY_VIEW_HEIGHT, 89, 6, false),
|
||||
$level(level)
|
||||
{
|
||||
default_bg = sf::Color{30,30,30};
|
||||
}
|
||||
|
||||
void create_render();
|
||||
void update_level(GameLevel &level) { $level = level; }
|
||||
};
|
||||
|
||||
enum class State {
|
||||
START,
|
||||
MOVING,
|
||||
|
@ -72,6 +41,7 @@ namespace gui {
|
|||
// ZED: these two will go away soon
|
||||
int $rotation_count = 0;
|
||||
float $rotation = -10.0f;
|
||||
bool $draw_stats = false;
|
||||
Point $player{0,0};
|
||||
LevelManager $levels;
|
||||
sf::RenderWindow $window;
|
||||
|
|
|
@ -47,6 +47,7 @@ sources = [
|
|||
'ansi_parser.cpp',
|
||||
'camera.cpp',
|
||||
'combat.cpp',
|
||||
'combat_ui.cpp',
|
||||
'components.cpp',
|
||||
'config.cpp',
|
||||
'dbc.cpp',
|
||||
|
@ -68,6 +69,7 @@ sources = [
|
|||
'shiterator.hpp',
|
||||
'spatialmap.cpp',
|
||||
'stats.cpp',
|
||||
'status_ui.cpp',
|
||||
'systems.cpp',
|
||||
'texture.cpp',
|
||||
'tilemap.cpp',
|
||||
|
|
|
@ -22,22 +22,13 @@ union ColorConv {
|
|||
uint32_t as_int;
|
||||
};
|
||||
|
||||
inline uint32_t dumb_lighting(uint32_t pixel, double distance) {
|
||||
if(distance < 1.0) return pixel;
|
||||
|
||||
ColorConv conv{.as_int=pixel};
|
||||
conv.as_color.r /= distance;
|
||||
conv.as_color.g /= distance;
|
||||
conv.as_color.b /= distance;
|
||||
|
||||
return conv.as_int;
|
||||
}
|
||||
|
||||
inline uint32_t new_lighting(uint32_t pixel, int level) {
|
||||
float factor = level * PERCENT;
|
||||
|
||||
ColorConv conv{.as_int=pixel};
|
||||
conv.as_color.r *= level * PERCENT;
|
||||
conv.as_color.g *= level * PERCENT;
|
||||
conv.as_color.b *= level * PERCENT;
|
||||
conv.as_color.r *= factor;
|
||||
conv.as_color.g *= factor;
|
||||
conv.as_color.b *= factor;
|
||||
|
||||
return conv.as_int;
|
||||
}
|
||||
|
|
48
status_ui.cpp
Normal file
48
status_ui.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include "status_ui.hpp"
|
||||
#include <ftxui/dom/node.hpp> // for Render
|
||||
#include <ftxui/screen/box.hpp> // for ftxui
|
||||
#include <ftxui/component/loop.hpp>
|
||||
#include <ftxui/screen/color.hpp>
|
||||
#include <ftxui/dom/table.hpp>
|
||||
#include "components.hpp"
|
||||
#include "color.hpp"
|
||||
|
||||
namespace gui {
|
||||
using namespace components;
|
||||
using namespace ftxui;
|
||||
|
||||
StatusUI::StatusUI(GameLevel level) :
|
||||
Panel(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT, false),
|
||||
$level(level)
|
||||
{
|
||||
default_bg = ColorValue::DARK_MID;
|
||||
}
|
||||
|
||||
void StatusUI::create_render() {
|
||||
auto player = $level.world->get_the<Player>();
|
||||
|
||||
auto status_rend = Renderer([&, player]{
|
||||
const auto& player_combat = $level.world->get<Combat>(player.entity);
|
||||
const auto& combat = $level.world->get<Combat>(player.entity);
|
||||
|
||||
std::vector<Element> log_list;
|
||||
log_list.push_back(text("Log messages here."));
|
||||
|
||||
auto log_box = vbox(log_list) | yflex_grow;
|
||||
|
||||
return hbox({
|
||||
hflow(
|
||||
vbox(
|
||||
text(fmt::format("HP: {: >3} DMG: {: >3}",
|
||||
player_combat.hp,
|
||||
combat.damage)),
|
||||
separator(),
|
||||
log_box
|
||||
) | flex_grow
|
||||
)
|
||||
});
|
||||
});
|
||||
|
||||
set_renderer(status_rend);
|
||||
}
|
||||
}
|
14
status_ui.hpp
Normal file
14
status_ui.hpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
#include "panel.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
#include "constants.hpp"
|
||||
|
||||
namespace gui {
|
||||
class StatusUI : public Panel {
|
||||
public:
|
||||
GameLevel $level;
|
||||
StatusUI(GameLevel level);
|
||||
void create_render();
|
||||
void update_level(GameLevel &level) { $level = level; }
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue