Debug UI now has little icons for each enemy and can spawn any enemy. Also I forgot the files.
This commit is contained in:
parent
07ce8a4148
commit
6d73c87c4e
2 changed files with 147 additions and 0 deletions
117
debug_ui.cpp
Normal file
117
debug_ui.cpp
Normal file
|
@ -0,0 +1,117 @@
|
|||
#include "debug_ui.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "color.hpp"
|
||||
#include "events.hpp"
|
||||
#include <optional>
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/xchar.h>
|
||||
#include "components.hpp"
|
||||
|
||||
namespace gui {
|
||||
using namespace guecs;
|
||||
|
||||
DebugUI::DebugUI(LevelManager& level_mgr) :
|
||||
$level_mgr(level_mgr)
|
||||
{
|
||||
}
|
||||
|
||||
void DebugUI::init(lel::Cell cell) {
|
||||
$gui.position(cell.x, cell.y, cell.w, cell.h);
|
||||
$gui.layout(
|
||||
"[*%(100,400)debug_text]"
|
||||
"[_]"
|
||||
"[_]"
|
||||
"[_]"
|
||||
"[spawn1|spawn2|spawn3]"
|
||||
"[spawn4|spawn5|spawn6]");
|
||||
|
||||
add_spawn_button("AXE_RANGER", "axe_ranger", "spawn1");
|
||||
add_spawn_button("KNIGHT","armored_knight", "spawn2");
|
||||
add_spawn_button("SPIDER_GIANT_HAIRY", "hairy_spider", "spawn3");
|
||||
add_spawn_button("RAT_GIANT", "rat_with_sword", "spawn4");
|
||||
|
||||
$gui.init();
|
||||
}
|
||||
|
||||
void DebugUI::add_spawn_button(std::string enemy_key, std::string sprite_name, std::string region) {
|
||||
auto button = $gui.entity(region);
|
||||
$gui.set<guecs::Clickable>(button, { [this, enemy_key](auto, auto){ spawn(enemy_key); } });
|
||||
$gui.set<guecs::Sprite>(button, { sprite_name});
|
||||
}
|
||||
|
||||
void DebugUI::spawn(std::string enemy_key) {
|
||||
auto ent = $level_mgr.spawn_enemy(enemy_key);
|
||||
|
||||
auto& level = $level_mgr.current();
|
||||
level.world->send<Events::GUI>(Events::GUI::ENEMY_SPAWN, ent, {});
|
||||
}
|
||||
|
||||
void DebugUI::render(sf::RenderWindow& window) {
|
||||
auto& level = $level_mgr.current();
|
||||
|
||||
auto debug_settings = level.world->get_the<components::Debug>();
|
||||
if(debug_settings.FPS) {
|
||||
auto player = level.world->get_the<components::Player>();
|
||||
auto player_combat = level.world->get<components::Combat>(player.entity);
|
||||
auto map = level.map;
|
||||
|
||||
std::wstring stats = fmt::format(L"STATS\n"
|
||||
L"HP: {}\n"
|
||||
L"mean:{:>8.5}\n"
|
||||
L"sdev: {:>8.5}\n"
|
||||
L"min: {:>8.5}\n"
|
||||
L"max: {:>8.5}\n"
|
||||
L"count:{:<10}\n"
|
||||
L"level: {} size: {}x{}\n\n"
|
||||
L"VSync? {}\n"
|
||||
L"FR Limit: {}\n"
|
||||
L"Debug? {}\n\n",
|
||||
player_combat.hp, $stats.mean(), $stats.stddev(), $stats.min,
|
||||
$stats.max, $stats.n, level.index, map->width(), map->height(),
|
||||
VSYNC, FRAME_LIMIT, DEBUG_BUILD);
|
||||
|
||||
$gui.show_text("debug_text", stats);
|
||||
$gui.render(window);
|
||||
// $gui.debug_layout(window);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugUI::debug() {
|
||||
auto& level = $level_mgr.current();
|
||||
|
||||
auto& dbg = level.world->get_the<components::Debug>();
|
||||
dbg.FPS = !dbg.FPS;
|
||||
dbg.PATHS = !dbg.PATHS;
|
||||
|
||||
if(dbg.FPS) {
|
||||
// it's on now, enable things
|
||||
auto player = level.world->get_the<components::Player>();
|
||||
auto& player_combat = level.world->get<components::Combat>(player.entity);
|
||||
player_combat.hp = player_combat.max_hp;
|
||||
$gui.show_text("debug_text", L"STATS");
|
||||
} else {
|
||||
// it's off now, close it
|
||||
$gui.close<Textual>("debug_text");
|
||||
}
|
||||
}
|
||||
|
||||
bool DebugUI::mouse(float x, float y) {
|
||||
return $gui.mouse(x, y);
|
||||
}
|
||||
|
||||
void DebugUI::update_level(GameLevel &level) {
|
||||
$level = level;
|
||||
}
|
||||
|
||||
Stats::TimeBullshit DebugUI::time_start() {
|
||||
return $stats.time_start();
|
||||
}
|
||||
|
||||
void DebugUI::sample_time(Stats::TimeBullshit start) {
|
||||
$stats.sample_time(start);
|
||||
}
|
||||
|
||||
void DebugUI::reset_stats() {
|
||||
$stats.reset();
|
||||
}
|
||||
}
|
30
debug_ui.hpp
Normal file
30
debug_ui.hpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
#include "levelmanager.hpp"
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include "guecs.hpp"
|
||||
#include "stats.hpp"
|
||||
|
||||
namespace gui {
|
||||
class DebugUI {
|
||||
public:
|
||||
Stats $stats;
|
||||
guecs::UI $gui;
|
||||
GameLevel $level;
|
||||
LevelManager& $level_mgr;
|
||||
|
||||
DebugUI(LevelManager& level_mgr);
|
||||
|
||||
void init(lel::Cell cell);
|
||||
void render(sf::RenderWindow& window);
|
||||
bool mouse(float x, float y);
|
||||
void debug();
|
||||
void update_level(GameLevel &level);
|
||||
void spawn(std::string enemy_key);
|
||||
void add_spawn_button(std::string enemy_key, std::string sprite_name, std::string region);
|
||||
|
||||
Stats::TimeBullshit time_start();
|
||||
void sample_time(Stats::TimeBullshit start);
|
||||
void reset_stats();
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue