mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
GameUI refactor (part 2/X): Move Game::guitext to GameUI + enhancements on StaticText
Other enhancements: * C++ friendlyness for addStaticText() -> move to static StaticText::add()
This commit is contained in:
parent
0ebaed430a
commit
3a772e7ed6
8 changed files with 159 additions and 134 deletions
|
@ -19,7 +19,55 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
*/
|
||||
|
||||
#include "gameui.h"
|
||||
#include "settings.h"
|
||||
#include <irrlicht_changes/static_text.h>
|
||||
#include "gui/mainmenumanager.h"
|
||||
#include "client.h"
|
||||
#include "fontengine.h"
|
||||
#include "clientmap.h"
|
||||
#include "version.h"
|
||||
#include "renderingengine.h"
|
||||
|
||||
void GameUI::init()
|
||||
{
|
||||
// First line of debug text
|
||||
m_guitext = gui::StaticText::add(guienv, utf8_to_wide(PROJECT_NAME_C).c_str(),
|
||||
core::rect<s32>(0, 0, 0, 0), false, false, guiroot);
|
||||
}
|
||||
|
||||
void GameUI::update(const RunStats &stats, Client *client,
|
||||
const MapDrawControl *draw_control)
|
||||
{
|
||||
if (m_flags.show_debug) {
|
||||
static float drawtime_avg = 0;
|
||||
drawtime_avg = drawtime_avg * 0.95 + stats.drawtime * 0.05;
|
||||
u16 fps = 1.0 / stats.dtime_jitter.avg;
|
||||
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
os << std::fixed
|
||||
<< PROJECT_NAME_C " " << g_version_hash
|
||||
<< ", FPS: " << fps
|
||||
<< std::setprecision(0)
|
||||
<< ", drawtime: " << drawtime_avg << "ms"
|
||||
<< std::setprecision(1)
|
||||
<< ", dtime jitter: "
|
||||
<< (stats.dtime_jitter.max_fraction * 100.0) << "%"
|
||||
<< std::setprecision(1)
|
||||
<< ", view range: "
|
||||
<< (draw_control->range_all ? "All" : itos(draw_control->wanted_range))
|
||||
<< std::setprecision(3)
|
||||
<< ", RTT: " << client->getRTT() << "s";
|
||||
setStaticText(m_guitext, utf8_to_wide(os.str()).c_str());
|
||||
m_guitext->setVisible(true);
|
||||
} else {
|
||||
m_guitext->setVisible(false);
|
||||
}
|
||||
|
||||
if (m_guitext->isVisible()) {
|
||||
v2u32 screensize = RenderingEngine::get_instance()->getWindowSize();
|
||||
m_guitext->setRelativePosition(core::rect<s32>(5, 5, screensize.X,
|
||||
5 + g_fontengine->getTextHeight()));
|
||||
}
|
||||
}
|
||||
|
||||
void GameUI::initFlags()
|
||||
{
|
||||
|
@ -29,7 +77,7 @@ void GameUI::initFlags()
|
|||
m_flags.show_debug = g_settings->getBool("show_debug");
|
||||
}
|
||||
|
||||
void GameUI::showMinimap(const bool show)
|
||||
void GameUI::showMinimap(bool show)
|
||||
{
|
||||
m_flags.show_minimap = show;
|
||||
}
|
||||
|
|
|
@ -20,9 +20,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "IGUIEnvironment.h"
|
||||
#include <IGUIEnvironment.h>
|
||||
#include "game.h"
|
||||
|
||||
using namespace irr;
|
||||
class Client;
|
||||
struct MapDrawControl;
|
||||
|
||||
class GameUI
|
||||
{
|
||||
|
@ -30,6 +33,9 @@ class GameUI
|
|||
friend class Game;
|
||||
|
||||
public:
|
||||
GameUI() = default;
|
||||
~GameUI() = default;
|
||||
|
||||
// Flags that can, or may, change during main game loop
|
||||
struct Flags
|
||||
{
|
||||
|
@ -42,16 +48,19 @@ public:
|
|||
bool disable_camera_update;
|
||||
};
|
||||
|
||||
void init();
|
||||
void update(const RunStats &stats, Client *client, const MapDrawControl *draw_control);
|
||||
|
||||
void initFlags();
|
||||
const Flags &getFlags() const { return m_flags; }
|
||||
|
||||
void showMinimap(const bool show);
|
||||
void showMinimap(bool show);
|
||||
|
||||
private:
|
||||
Flags m_flags;
|
||||
|
||||
gui::IGUIStaticText *m_guitext; // First line of debug text
|
||||
// @TODO future move
|
||||
// gui::IGUIStaticText *m_guitext; // First line of debug text
|
||||
// gui::IGUIStaticText *m_guitext2; // Second line of debug text
|
||||
// gui::IGUIStaticText *m_guitext_info; // At the middle of the screen
|
||||
// gui::IGUIStaticText *m_guitext_status;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue