aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorLoic Blot <loic.blot@unix-experience.fr>2018-01-04 21:35:26 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2018-01-05 20:59:30 +0100
commitfe510d90c15d9bec3a8c1dafc7b1730b11a9f6bd (patch)
treeb4c2626053fa8e4dceedbb0a061724843c667161 /src/client
parentaab3b18e4b9f847ba1e521d5a73624b0bb6a467a (diff)
downloadminetest-fe510d90c15d9bec3a8c1dafc7b1730b11a9f6bd.tar.gz
minetest-fe510d90c15d9bec3a8c1dafc7b1730b11a9f6bd.tar.bz2
minetest-fe510d90c15d9bec3a8c1dafc7b1730b11a9f6bd.zip
GameUI refactor (part 4/X): Move Game::guitext_status, Game::m_statustext, GameRunData::statustext_time to GameUI class
Other enhancements: * Simplify setStatusText to showStatusText, as it shows the label too (preventing almost every setStatusText to call setStatusTextTime(0) * Add unittests
Diffstat (limited to 'src/client')
-rw-r--r--src/client/gameui.cpp46
-rw-r--r--src/client/gameui.h29
2 files changed, 67 insertions, 8 deletions
diff --git a/src/client/gameui.cpp b/src/client/gameui.cpp
index d6d52823a..7955dea59 100644
--- a/src/client/gameui.cpp
+++ b/src/client/gameui.cpp
@@ -54,10 +54,16 @@ void GameUI::init()
m_guitext_info = gui::StaticText::add(guienv, L"",
core::rect<s32>(0, 0, 400, g_fontengine->getTextHeight() * 5 + 5)
+ v2s32(100, 200), false, true, guiroot);
+
+ // Status text (displays info when showing and hiding GUI stuff, etc.)
+ m_guitext_status = gui::StaticText::add(guienv, L"<Status>",
+ core::rect<s32>(0, 0, 0, 0), false, false, guiroot);
+
+ m_guitext_status->setVisible(false);
}
void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_control,
- const CameraOrientation &cam, const PointedThing &pointed_old)
+ const CameraOrientation &cam, const PointedThing &pointed_old, float dtime)
{
v2u32 screensize = RenderingEngine::get_instance()->getWindowSize();
@@ -125,6 +131,44 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_
setStaticText(m_guitext_info, translate_string(m_infotext).c_str());
m_guitext_info->setVisible(m_flags.show_hud && g_menumgr.menuCount() == 0);
+
+ static const float statustext_time_max = 1.5f;
+
+ if (!m_statustext.empty()) {
+ m_statustext_time += dtime;
+
+ if (m_statustext_time >= statustext_time_max) {
+ clearStatusText();
+ m_statustext_time = 0.0f;
+ }
+ }
+
+ setStaticText(m_guitext_status, translate_string(m_statustext).c_str());
+ m_guitext_status->setVisible(!m_statustext.empty());
+
+ if (!m_statustext.empty()) {
+ s32 status_width = m_guitext_status->getTextWidth();
+ s32 status_height = m_guitext_status->getTextHeight();
+ s32 status_y = screensize.Y - 150;
+ s32 status_x = (screensize.X - status_width) / 2;
+
+ m_guitext_status->setRelativePosition(core::rect<s32>(status_x ,
+ status_y - status_height, status_x + status_width, status_y));
+
+ // Fade out
+ video::SColor initial_color(255, 0, 0, 0);
+
+ if (guienv->getSkin())
+ initial_color = guienv->getSkin()->getColor(gui::EGDC_BUTTON_TEXT);
+
+ video::SColor final_color = initial_color;
+ final_color.setAlpha(0);
+ video::SColor fade_color = initial_color.getInterpolated_quadratic(
+ initial_color, final_color,
+ pow(m_statustext_time / statustext_time_max, 2.0f));
+ m_guitext_status->setOverrideColor(fade_color);
+ m_guitext_status->enableOverrideColor(true);
+ }
}
void GameUI::initFlags()
diff --git a/src/client/gameui.h b/src/client/gameui.h
index 0e1085b01..fc2b8707e 100644
--- a/src/client/gameui.h
+++ b/src/client/gameui.h
@@ -33,6 +33,9 @@ class GameUI
// Temporary between coding time to move things here
friend class Game;
+ // Permit unittests to access members directly
+ friend class TestGameUI;
+
public:
GameUI() = default;
~GameUI() = default;
@@ -51,25 +54,37 @@ public:
void init();
void update(const RunStats &stats, Client *client, MapDrawControl *draw_control,
- const CameraOrientation &cam, const PointedThing &pointed_old);
+ const CameraOrientation &cam, const PointedThing &pointed_old, float dtime);
void initFlags();
const Flags &getFlags() const { return m_flags; }
void showMinimap(bool show);
- void setInfoText(const std::wstring &str) { m_infotext = str; }
- void clearInfoText() { m_infotext.clear(); }
+ inline void setInfoText(const std::wstring &str) { m_infotext = str; }
+ inline void clearInfoText() { m_infotext.clear(); }
+
+ inline void showStatusText(const std::wstring &str)
+ {
+ m_statustext = str;
+ m_statustext_time = 0.0f;
+ }
+ inline void clearStatusText() { m_statustext.clear(); }
private:
Flags m_flags;
- 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 = nullptr; // First line of debug text
+ gui::IGUIStaticText *m_guitext2 = nullptr; // Second line of debug text
+
+ gui::IGUIStaticText *m_guitext_info = nullptr; // At the middle of the screen
std::wstring m_infotext;
+
+ gui::IGUIStaticText *m_guitext_status = nullptr;
+ std::wstring m_statustext;
+ float m_statustext_time = 0.0f;
+
// @TODO future move
- // gui::IGUIStaticText *m_guitext_status;
// gui::IGUIStaticText *m_guitext_chat; // Chat text
// gui::IGUIStaticText *m_guitext_profiler; // Profiler text
};