Skip to content

Commit 9146c6a

Browse files
committedJan 5, 2018
Don't recalculate statustext initial color everytime & review fixes
1 parent f40f414 commit 9146c6a

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed
 

‎src/client/gameui.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ inline static const char *yawToDirectionString(int yaw)
4141
return direction[yaw];
4242
}
4343

44+
GameUI::GameUI()
45+
{
46+
if (guienv && guienv->getSkin())
47+
m_statustext_initial_color = guienv->getSkin()->getColor(gui::EGDC_BUTTON_TEXT);
48+
else
49+
m_statustext_initial_color = video::SColor(255, 0, 0, 0);
50+
51+
}
4452
void GameUI::init()
4553
{
4654
// First line of debug text
@@ -169,16 +177,10 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_
169177
status_y - status_height, status_x + status_width, status_y));
170178

171179
// Fade out
172-
video::SColor initial_color(255, 0, 0, 0);
173-
174-
if (guienv->getSkin())
175-
initial_color = guienv->getSkin()->getColor(gui::EGDC_BUTTON_TEXT);
176-
177-
video::SColor final_color = initial_color;
180+
video::SColor final_color = m_statustext_initial_color;
178181
final_color.setAlpha(0);
179-
video::SColor fade_color = initial_color.getInterpolated_quadratic(
180-
initial_color, final_color,
181-
pow(m_statustext_time / statustext_time_max, 2.0f));
182+
video::SColor fade_color = m_statustext_initial_color.getInterpolated_quadratic(
183+
m_statustext_initial_color, final_color, m_statustext_time / statustext_time_max);
182184
m_guitext_status->setOverrideColor(fade_color);
183185
m_guitext_status->enableOverrideColor(true);
184186
}
@@ -244,7 +246,7 @@ void GameUI::updateProfiler()
244246
if (w < 400)
245247
w = 400;
246248

247-
unsigned text_height = g_fontengine->getTextHeight();
249+
u32 text_height = g_fontengine->getTextHeight();
248250

249251
core::position2di upper_left, lower_right;
250252

‎src/client/gameui.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class GameUI
4646
friend class TestGameUI;
4747

4848
public:
49-
GameUI() = default;
49+
GameUI();
5050
~GameUI() = default;
5151

5252
// Flags that can, or may, change during main game loop
@@ -100,10 +100,11 @@ class GameUI
100100
gui::IGUIStaticText *m_guitext_status = nullptr;
101101
std::wstring m_statustext;
102102
float m_statustext_time = 0.0f;
103+
video::SColor m_statustext_initial_color;
103104

104-
gui::IGUIStaticText *m_guitext_chat; // Chat text
105+
gui::IGUIStaticText *m_guitext_chat = nullptr; // Chat text
105106

106-
gui::IGUIStaticText *m_guitext_profiler; // Profiler text
107+
gui::IGUIStaticText *m_guitext_profiler = nullptr; // Profiler text
107108
u8 m_profiler_current_page = 0;
108109
const u8 m_profiler_max_page = 3;
109110
};

‎src/game.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ class Game {
12771277
void updateChat(f32 dtime, const v2u32 &screensize);
12781278
static const ClientEventHandler clientEventHandler[CLIENTEVENT_MAX];
12791279

1280-
InputHandler *input;
1280+
InputHandler *input = nullptr;
12811281

12821282
Client *client = nullptr;
12831283
Server *server = nullptr;
@@ -2669,9 +2669,9 @@ void Game::toggleFog()
26692669
{
26702670
m_flags.force_fog_off = !m_flags.force_fog_off;
26712671
if (m_flags.force_fog_off)
2672-
m_game_ui->showTranslatedStatusText("Fog disabled");
2672+
m_game_ui->showTranslatedStatusText("Fog disabled");
26732673
else
2674-
m_game_ui->showTranslatedStatusText("Fog enabled");
2674+
m_game_ui->showTranslatedStatusText("Fog enabled");
26752675
}
26762676

26772677

@@ -2912,9 +2912,8 @@ inline void Game::step(f32 *dtime)
29122912
if (can_be_and_is_paused) { // This is for a singleplayer server
29132913
*dtime = 0; // No time passes
29142914
} else {
2915-
if (server) {
2915+
if (server)
29162916
server->step(*dtime);
2917-
}
29182917

29192918
client->step(*dtime);
29202919
}

‎src/gui/guiFormSpecMenu.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2026,7 +2026,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
20262026
assert(!m_tooltip_element);
20272027
// Note: parent != this so that the tooltip isn't clipped by the menu rectangle
20282028
m_tooltip_element = gui::StaticText::add(Environment, L"",
2029-
core::rect<s32>(0,0,110,18));
2029+
core::rect<s32>(0, 0, 110, 18));
20302030
m_tooltip_element->enableOverrideColor(true);
20312031
m_tooltip_element->setBackgroundColor(m_default_tooltip_bgcolor);
20322032
m_tooltip_element->setDrawBackground(true);

‎src/irrlicht_changes/static_text.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ namespace gui
9292
s32 id = -1,
9393
bool fillBackground = false)
9494
{
95-
return add(guienv, EnrichedString(text), rectangle, border, wordWrap, parent, id, fillBackground);
95+
return add(guienv, EnrichedString(text), rectangle, border, wordWrap, parent,
96+
id, fillBackground);
9697
}
9798

9899
//! draws the element and its children

‎util/updatepo.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ xgettext --package-name=minetest \
5757
--keyword=fgettext_ne \
5858
--keyword=strgettext \
5959
--keyword=wstrgettext \
60-
--keyword=showStatusTextSimple \
60+
--keyword=showTranslatedStatusText \
6161
--output $potfile \
6262
--from-code=utf-8 \
6363
`find src/ -name '*.cpp' -o -name '*.h'` \

0 commit comments

Comments
 (0)
Please sign in to comment.