More refactoring of the FSM to MainUI. Move the overlay out and some more.
This commit is contained in:
parent
a7a60ad35c
commit
23ed1594f2
4 changed files with 106 additions and 82 deletions
73
main_ui.cpp
73
main_ui.cpp
|
@ -1 +1,74 @@
|
|||
#include "main_ui.hpp"
|
||||
#include "components.hpp"
|
||||
|
||||
namespace gui {
|
||||
using namespace components;
|
||||
|
||||
MainUI::MainUI(sf::RenderWindow& window, GameLevel level, TexturePack& textures) :
|
||||
$window(window),
|
||||
$level(level),
|
||||
$textures(textures),
|
||||
$overlay_ui($level, $textures)
|
||||
{
|
||||
$window.setVerticalSyncEnabled(VSYNC);
|
||||
$window.setFramerateLimit(FRAME_LIMIT);
|
||||
}
|
||||
|
||||
void MainUI::debug() {
|
||||
auto& dbg = $level.world->get_the<Debug>();
|
||||
dbg.FPS = !dbg.FPS;
|
||||
dbg.PATHS = !dbg.PATHS;
|
||||
|
||||
if(dbg.FPS) {
|
||||
// it's on now, enable things
|
||||
auto player = $level.world->get_the<Player>();
|
||||
auto& player_combat = $level.world->get<Combat>(player.entity);
|
||||
player_combat.hp = player_combat.max_hp;
|
||||
$overlay_ui.show_text("top_left", "STATS");
|
||||
} else {
|
||||
// it's off now, close it
|
||||
$overlay_ui.close_text("top_left");
|
||||
}
|
||||
}
|
||||
|
||||
void MainUI::draw_stats() {
|
||||
auto player = $level.world->get_the<Player>();
|
||||
auto player_combat = $level.world->get<Combat>(player.entity);
|
||||
std::string stats = fmt::format("STATS\n"
|
||||
"HP: {}\n"
|
||||
"mean:{:>8.5}\n"
|
||||
"sdev: {:>8.5}\n"
|
||||
"min: {:>8.5}\n"
|
||||
"max: {:>8.5}\n"
|
||||
"count:{:<10}\n\n"
|
||||
"VSync? {}\n"
|
||||
"FR Limit: {}\n"
|
||||
"Debug? {}\n\n",
|
||||
player_combat.hp, $stats.mean(), $stats.stddev(), $stats.min,
|
||||
$stats.max, $stats.n, VSYNC,
|
||||
FRAME_LIMIT, DEBUG_BUILD);
|
||||
|
||||
$overlay_ui.update_text("top_left", stats);
|
||||
}
|
||||
|
||||
void MainUI::draw_blood() {
|
||||
auto player = $level.world->get_the<Player>();
|
||||
auto player_combat = $level.world->get<Combat>(player.entity);
|
||||
if(float(player_combat.hp) / float(player_combat.max_hp) < 0.5) {
|
||||
$overlay_ui.show_sprite("middle", "blood_splatter");
|
||||
} else {
|
||||
$overlay_ui.close_sprite("middle");
|
||||
}
|
||||
}
|
||||
|
||||
void MainUI::render() {
|
||||
$overlay_ui.render();
|
||||
}
|
||||
|
||||
void MainUI::draw() {
|
||||
$overlay_ui.draw($window);
|
||||
|
||||
auto debug = $level.world->get_the<Debug>();
|
||||
if(debug.FPS) draw_stats();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue