Skip to content

Commit 28da78b

Browse files
committed
Fix observer font size adjustment functionality after TSH merge
Signed-off-by: tintinhamans <5984296+tintinhamans@users.noreply.github.com>
1 parent a4fa456 commit 28da78b

1 file changed

Lines changed: 111 additions & 0 deletions

File tree

Core/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "Common/StatsCollector.h"
5252
#include "Common/ThingTemplate.h"
5353
#include "Common/GameLOD.h"
54+
#include "Common/OptionPreferences.h"
5455

5556
#include "GameClient/InGameUI.h"
5657
#include "GameClient/CommandXlat.h"
@@ -180,6 +181,75 @@ Bool hasThingsInProduction(PlayerType playerType)
180181

181182
#endif // defined(RTS_DEBUG) || defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)
182183

184+
enum ObserverFontSizeChange
185+
{
186+
ObserverFontSizeChange_Increase,
187+
ObserverFontSizeChange_Decrease,
188+
};
189+
190+
static const Int ObserverFontSizeMin = 0;
191+
static const Int ObserverFontSizeMax = 15;
192+
193+
static Int applyObserverFontSizeChange(Int fontSize, ObserverFontSizeChange change)
194+
{
195+
switch (change)
196+
{
197+
case ObserverFontSizeChange_Increase:
198+
if (fontSize < ObserverFontSizeMax)
199+
++fontSize;
200+
break;
201+
202+
case ObserverFontSizeChange_Decrease:
203+
if (fontSize > ObserverFontSizeMin)
204+
--fontSize;
205+
break;
206+
}
207+
208+
return fontSize;
209+
}
210+
211+
static void writeObserverFontSizePref(const char* prefKey, Int fontSize)
212+
{
213+
OptionPreferences optPref;
214+
AsciiString prefString;
215+
prefString.format("%d", fontSize);
216+
optPref[prefKey] = prefString;
217+
optPref.write();
218+
}
219+
220+
static bool changeObserverNotificationFontSize(ObserverFontSizeChange change)
221+
{
222+
const Int fontSize = applyObserverFontSizeChange(TheWritableGlobalData->m_observerNotificationFontSize, change);
223+
224+
if (fontSize == TheWritableGlobalData->m_observerNotificationFontSize)
225+
return false;
226+
227+
TheWritableGlobalData->m_observerNotificationFontSize = fontSize;
228+
229+
if (TheInGameUI)
230+
TheInGameUI->refreshObserverNotificationResources();
231+
232+
writeObserverFontSizePref("ObserverNotificationFontSize", fontSize);
233+
234+
return true;
235+
}
236+
237+
static bool changeObserverStatsFontSize(ObserverFontSizeChange change)
238+
{
239+
const Int fontSize = applyObserverFontSizeChange(TheWritableGlobalData->m_observerStatsFontSize, change);
240+
241+
if (fontSize == TheWritableGlobalData->m_observerStatsFontSize)
242+
return false;
243+
244+
TheWritableGlobalData->m_observerStatsFontSize = fontSize;
245+
246+
if (TheInGameUI)
247+
TheInGameUI->initObserverOverlay();
248+
249+
writeObserverFontSizePref("ObserverStatsFontSize", fontSize);
250+
251+
return true;
252+
}
183253

184254
bool changeMaxRenderFps(FpsValueChange change)
185255
{
@@ -3278,6 +3348,46 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
32783348
break;
32793349
}
32803350

3351+
//-----------------------------------------------------------------------------------------
3352+
case GameMessage::MSG_META_INCREASE_OBSERVER_NOTIFICATION_FONT:
3353+
{
3354+
if (changeObserverNotificationFontSize(ObserverFontSizeChange_Increase))
3355+
{
3356+
disp = DESTROY_MESSAGE;
3357+
}
3358+
break;
3359+
}
3360+
3361+
//-----------------------------------------------------------------------------------------
3362+
case GameMessage::MSG_META_DECREASE_OBSERVER_NOTIFICATION_FONT:
3363+
{
3364+
if (changeObserverNotificationFontSize(ObserverFontSizeChange_Decrease))
3365+
{
3366+
disp = DESTROY_MESSAGE;
3367+
}
3368+
break;
3369+
}
3370+
3371+
//-----------------------------------------------------------------------------------------
3372+
case GameMessage::MSG_META_INCREASE_OBSERVER_STATS_FONT:
3373+
{
3374+
if (changeObserverStatsFontSize(ObserverFontSizeChange_Increase))
3375+
{
3376+
disp = DESTROY_MESSAGE;
3377+
}
3378+
break;
3379+
}
3380+
3381+
//-----------------------------------------------------------------------------------------
3382+
case GameMessage::MSG_META_DECREASE_OBSERVER_STATS_FONT:
3383+
{
3384+
if (changeObserverStatsFontSize(ObserverFontSizeChange_Decrease))
3385+
{
3386+
disp = DESTROY_MESSAGE;
3387+
}
3388+
break;
3389+
}
3390+
32813391
//-----------------------------------------------------------------------------------------
32823392
case GameMessage::MSG_META_INCREASE_LOGIC_TIME_SCALE:
32833393
{
@@ -3369,6 +3479,7 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
33693479
}
33703480

33713481
ToggleControlBar();
3482+
TheInGameUI->toggleObserverStats();
33723483
}
33733484
disp = DESTROY_MESSAGE;
33743485
break;

0 commit comments

Comments
 (0)