parent
a7a60ad35c
commit
23ed1594f2
@ -1 +1,74 @@ |
|||||||
#include "main_ui.hpp" |
#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(); |
||||||
|
} |
||||||
|
} |
||||||
|
@ -1,20 +1,24 @@ |
|||||||
#pragma once |
#pragma once |
||||||
#include "levelmanager.hpp" |
#include "levelmanager.hpp" |
||||||
#include <SFML/Graphics/RenderWindow.hpp> |
#include <SFML/Graphics/RenderWindow.hpp> |
||||||
|
#include "stats.hpp" |
||||||
|
#include "overlay_ui.hpp" |
||||||
|
|
||||||
namespace gui { |
namespace gui { |
||||||
|
|
||||||
class MainUI { |
class MainUI { |
||||||
public: |
public: |
||||||
|
Stats $stats; |
||||||
|
sf::RenderWindow& $window; |
||||||
GameLevel $level; |
GameLevel $level; |
||||||
sf::RenderWindow $window; |
TexturePack& $textures; |
||||||
|
OverlayUI $overlay_ui; |
||||||
|
|
||||||
MainUI(GameLevel level) : |
MainUI(sf::RenderWindow& window, GameLevel level, TexturePack &textures); |
||||||
$level(level), |
void debug(); |
||||||
$window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing") |
void draw_stats(); |
||||||
{ |
void draw_blood(); |
||||||
$window.setVerticalSyncEnabled(VSYNC); |
void render(); |
||||||
$window.setFramerateLimit(FRAME_LIMIT); |
void draw(); |
||||||
} |
|
||||||
}; |
}; |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue