Now overlay UI can show some text pretty easily and is showing the debug stats.
This commit is contained in:
parent
d8e1fc7aa3
commit
30a7e1b2cc
5 changed files with 51 additions and 21 deletions
13
guecs.hpp
13
guecs.hpp
|
@ -158,10 +158,15 @@ namespace guecs {
|
|||
return $world.get<lel::Cell>(entity);
|
||||
}
|
||||
|
||||
template <typename Comp>
|
||||
void remove(DinkyECS::Entity ent) {
|
||||
$world.remove<Comp>(ent);
|
||||
}
|
||||
template <typename Comp>
|
||||
Comp& get(DinkyECS::Entity entity) {
|
||||
return $world.get<Comp>(entity);
|
||||
}
|
||||
|
||||
template <typename Comp>
|
||||
void remove(DinkyECS::Entity ent) {
|
||||
$world.remove<Comp>(ent);
|
||||
}
|
||||
};
|
||||
|
||||
Clickable make_action(DinkyECS::World& target, Events::GUI event);
|
||||
|
|
35
gui.cpp
35
gui.cpp
|
@ -20,14 +20,10 @@ namespace gui {
|
|||
$status_view($level),
|
||||
$overlay_view($level, $textures),
|
||||
$font{FONT_FILE_NAME},
|
||||
$text{$font},
|
||||
$rayview($textures, RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT)
|
||||
{
|
||||
$window.setVerticalSyncEnabled(VSYNC);
|
||||
$window.setFramerateLimit(FRAME_LIMIT);
|
||||
$text.setPosition({RAY_VIEW_X,RAY_VIEW_Y});
|
||||
$text.setCharacterSize(20);
|
||||
$text.setFillColor(ColorValue::LIGHT_DARK);
|
||||
$textures.load_tiles();
|
||||
$textures.load_sprites();
|
||||
}
|
||||
|
@ -258,6 +254,7 @@ namespace gui {
|
|||
break;
|
||||
case KEY::P:
|
||||
debug();
|
||||
break;
|
||||
default:
|
||||
break; // ignored
|
||||
}
|
||||
|
@ -266,21 +263,27 @@ namespace gui {
|
|||
}
|
||||
|
||||
void FSM::debug() {
|
||||
auto& debug = $level.world->get_the<Debug>();
|
||||
debug.FPS = !debug.FPS;
|
||||
debug.PATHS = !debug.PATHS;
|
||||
auto player = $level.world->get_the<Player>();
|
||||
auto& player_combat = $level.world->get<Combat>(player.entity);
|
||||
player_combat.hp = player_combat.max_hp;
|
||||
$combat_view.set_damage(float(player_combat.hp) / float(player_combat.max_hp));
|
||||
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;
|
||||
$combat_view.set_damage(float(player_combat.hp) / float(player_combat.max_hp));
|
||||
$overlay_view.init_stats();
|
||||
} else {
|
||||
// it's off now, close it
|
||||
$overlay_view.close_stats();
|
||||
}
|
||||
}
|
||||
|
||||
void FSM::draw_stats() {
|
||||
auto player = $level.world->get_the<Player>();
|
||||
auto player_combat = $level.world->get<Combat>(player.entity);
|
||||
|
||||
$text.setString(
|
||||
fmt::format("FPS\n"
|
||||
std::string stats = fmt::format("STATS\n"
|
||||
"HP: {}\n"
|
||||
"mean:{:>8.5}\n"
|
||||
"sdev: {:>8.5}\n"
|
||||
|
@ -292,9 +295,9 @@ namespace gui {
|
|||
"Debug? {}\n\n",
|
||||
player_combat.hp, $stats.mean(), $stats.stddev(), $stats.min,
|
||||
$stats.max, $stats.n, VSYNC,
|
||||
FRAME_LIMIT, DEBUG_BUILD));
|
||||
FRAME_LIMIT, DEBUG_BUILD);
|
||||
|
||||
$window.draw($text);
|
||||
$overlay_view.draw_stats(stats);
|
||||
}
|
||||
|
||||
void FSM::draw_blood() {
|
||||
|
|
1
gui.hpp
1
gui.hpp
|
@ -56,7 +56,6 @@ namespace gui {
|
|||
OverlayUI $overlay_view;
|
||||
CameraLOL $camera;
|
||||
sf::Font $font;
|
||||
sf::Text $text;
|
||||
Stats $stats;
|
||||
TexturePack $textures;
|
||||
Raycaster $rayview;
|
||||
|
|
|
@ -45,4 +45,24 @@ namespace gui {
|
|||
$gui.remove<guecs::Sprite>(middle);
|
||||
}
|
||||
}
|
||||
|
||||
void OverlayUI::init_stats() {
|
||||
auto top_left = $gui.entity("top_left");
|
||||
auto &cell = $gui.cell_for(top_left);
|
||||
Textual text{"", 20};
|
||||
text.init(cell, $gui.$font);
|
||||
text.text->setFillColor(ColorValue::LIGHT_MID);
|
||||
$gui.set<Textual>(top_left, text);
|
||||
}
|
||||
|
||||
void OverlayUI::draw_stats(std::string stats) {
|
||||
auto top_left = $gui.entity("top_left");
|
||||
auto& text = $gui.get<Textual>(top_left);
|
||||
text.text->setString(stats);
|
||||
}
|
||||
|
||||
void OverlayUI::close_stats() {
|
||||
auto top_left = $gui.entity("top_left");
|
||||
$gui.remove<Textual>(top_left);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,5 +17,8 @@ namespace gui {
|
|||
void draw(sf::RenderWindow& window);
|
||||
void click(int x, int y);
|
||||
void show_damage(bool show);
|
||||
void init_stats();
|
||||
void draw_stats(std::string stats);
|
||||
void close_stats();
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue