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);
|
return $world.get<lel::Cell>(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Comp>
|
template <typename Comp>
|
||||||
void remove(DinkyECS::Entity ent) {
|
Comp& get(DinkyECS::Entity entity) {
|
||||||
$world.remove<Comp>(ent);
|
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);
|
Clickable make_action(DinkyECS::World& target, Events::GUI event);
|
||||||
|
|
35
gui.cpp
35
gui.cpp
|
@ -20,14 +20,10 @@ namespace gui {
|
||||||
$status_view($level),
|
$status_view($level),
|
||||||
$overlay_view($level, $textures),
|
$overlay_view($level, $textures),
|
||||||
$font{FONT_FILE_NAME},
|
$font{FONT_FILE_NAME},
|
||||||
$text{$font},
|
|
||||||
$rayview($textures, RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT)
|
$rayview($textures, RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT)
|
||||||
{
|
{
|
||||||
$window.setVerticalSyncEnabled(VSYNC);
|
$window.setVerticalSyncEnabled(VSYNC);
|
||||||
$window.setFramerateLimit(FRAME_LIMIT);
|
$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_tiles();
|
||||||
$textures.load_sprites();
|
$textures.load_sprites();
|
||||||
}
|
}
|
||||||
|
@ -258,6 +254,7 @@ namespace gui {
|
||||||
break;
|
break;
|
||||||
case KEY::P:
|
case KEY::P:
|
||||||
debug();
|
debug();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break; // ignored
|
break; // ignored
|
||||||
}
|
}
|
||||||
|
@ -266,21 +263,27 @@ namespace gui {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSM::debug() {
|
void FSM::debug() {
|
||||||
auto& debug = $level.world->get_the<Debug>();
|
auto& dbg = $level.world->get_the<Debug>();
|
||||||
debug.FPS = !debug.FPS;
|
dbg.FPS = !dbg.FPS;
|
||||||
debug.PATHS = !debug.PATHS;
|
dbg.PATHS = !dbg.PATHS;
|
||||||
auto player = $level.world->get_the<Player>();
|
|
||||||
auto& player_combat = $level.world->get<Combat>(player.entity);
|
if(dbg.FPS) {
|
||||||
player_combat.hp = player_combat.max_hp;
|
// it's on now, enable things
|
||||||
$combat_view.set_damage(float(player_combat.hp) / float(player_combat.max_hp));
|
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() {
|
void FSM::draw_stats() {
|
||||||
auto player = $level.world->get_the<Player>();
|
auto player = $level.world->get_the<Player>();
|
||||||
auto player_combat = $level.world->get<Combat>(player.entity);
|
auto player_combat = $level.world->get<Combat>(player.entity);
|
||||||
|
std::string stats = fmt::format("STATS\n"
|
||||||
$text.setString(
|
|
||||||
fmt::format("FPS\n"
|
|
||||||
"HP: {}\n"
|
"HP: {}\n"
|
||||||
"mean:{:>8.5}\n"
|
"mean:{:>8.5}\n"
|
||||||
"sdev: {:>8.5}\n"
|
"sdev: {:>8.5}\n"
|
||||||
|
@ -292,9 +295,9 @@ namespace gui {
|
||||||
"Debug? {}\n\n",
|
"Debug? {}\n\n",
|
||||||
player_combat.hp, $stats.mean(), $stats.stddev(), $stats.min,
|
player_combat.hp, $stats.mean(), $stats.stddev(), $stats.min,
|
||||||
$stats.max, $stats.n, VSYNC,
|
$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() {
|
void FSM::draw_blood() {
|
||||||
|
|
1
gui.hpp
1
gui.hpp
|
@ -56,7 +56,6 @@ namespace gui {
|
||||||
OverlayUI $overlay_view;
|
OverlayUI $overlay_view;
|
||||||
CameraLOL $camera;
|
CameraLOL $camera;
|
||||||
sf::Font $font;
|
sf::Font $font;
|
||||||
sf::Text $text;
|
|
||||||
Stats $stats;
|
Stats $stats;
|
||||||
TexturePack $textures;
|
TexturePack $textures;
|
||||||
Raycaster $rayview;
|
Raycaster $rayview;
|
||||||
|
|
|
@ -45,4 +45,24 @@ namespace gui {
|
||||||
$gui.remove<guecs::Sprite>(middle);
|
$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 draw(sf::RenderWindow& window);
|
||||||
void click(int x, int y);
|
void click(int x, int y);
|
||||||
void show_damage(bool show);
|
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