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
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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue