Skip to content

Commit b0510a5

Browse files
committed
[ZH] Implement system time and simulation timer within InGameUI
1 parent 9527b54 commit b0510a5

File tree

8 files changed

+219
-0
lines changed

8 files changed

+219
-0
lines changed

GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ class GlobalData : public SubsystemInterface
409409
Bool m_saveCameraInReplay;
410410
Bool m_useCameraInReplay;
411411

412+
// TheSuperHackers @feature Mauller 21/06/2025 allow the system time and game time font size to be set, a size of zero disables them
413+
Int m_systemTimeFontSize;
414+
Int m_gameTimeFontSize;
415+
412416
Real m_shakeSubtleIntensity; ///< Intensity for shaking a camera with SHAKE_SUBTLE
413417
Real m_shakeNormalIntensity; ///< Intensity for shaking a camera with SHAKE_NORMAL
414418
Real m_shakeStrongIntensity; ///< Intensity for shaking a camera with SHAKE_STRONG

GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ class OptionPreferences : public UserPreferences
129129

130130
Int getCampaignDifficulty(void);
131131
void setCampaignDifficulty( Int diff );
132+
133+
Int getSystemTimeFontSize(void);
134+
Int getGameTimeFontSize(void);
132135
};
133136

134137
//-----------------------------------------------------------------------------

GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ friend class Drawable; // for selection/deselection transactions
382382
virtual void toggleMessages( void ) { m_messagesOn = 1 - m_messagesOn; } ///< toggle messages on/off
383383
virtual Bool isMessagesOn( void ) { return m_messagesOn; } ///< are the display messages on
384384
void freeMessageResources( void ); ///< free resources for the ui messages
385+
void freeCustomUiResources( void ); ///< free resources for custom ui elements
385386
Color getMessageColor(Bool altColor) { return (altColor)?m_messageColor2:m_messageColor1; }
386387

387388
// interface for military style messages
@@ -466,6 +467,7 @@ friend class Drawable; // for selection/deselection transactions
466467
virtual void preDraw( void ); ///< Logic which needs to occur before the UI renders
467468
virtual void draw( void ) = 0; ///< Render the in-game user interface
468469
virtual void postDraw( void ); ///< Logic which needs to occur after the UI renders
470+
virtual void postWindowDraw( void ); ///< Logic which needs to occur after the WindowManager has repainted the menus
469471

470472
/// Ingame video playback
471473
virtual void playMovie( const AsciiString& movieName );
@@ -559,6 +561,7 @@ friend class Drawable; // for selection/deselection transactions
559561
virtual void selectNextIdleWorker( void );
560562

561563
virtual void recreateControlBar( void );
564+
virtual void refreshCustomUiResources( void );
562565

563566
virtual void disableTooltipsUntil(UnsignedInt frameNum);
564567
virtual void clearTooltipsDisabled();
@@ -578,6 +581,9 @@ friend class Drawable; // for selection/deselection transactions
578581
virtual void updateIdleWorker( void );
579582
virtual void resetIdleWorker( void );
580583

584+
void drawSystemTime();
585+
void drawGameTime();
586+
581587
public:
582588
void registerWindowLayout(WindowLayout *layout); // register a layout for updates
583589
void unregisterWindowLayout(WindowLayout *layout); // stop updates for this layout
@@ -741,6 +747,25 @@ friend class Drawable; // for selection/deselection transactions
741747
VideoBuffer* m_cameoVideoBuffer;///< video playback buffer
742748
VideoStreamInterface* m_cameoVideoStream;///< Video stream;
743749

750+
// System Time
751+
DisplayString * m_systemTimeString;
752+
AsciiString m_systemTimeFont;
753+
Int m_systemTimePointSize;
754+
Bool m_systemTimeBold;
755+
Coord2D m_systemTimePosition;
756+
Color m_systemTimeColor;
757+
Color m_systemTimeDropColor;
758+
759+
// Game Time
760+
DisplayString * m_gameTimeString;
761+
DisplayString * m_gameTimeFrameString;
762+
AsciiString m_gameTimeFont;
763+
Int m_gameTimePointSize;
764+
Bool m_gameTimeBold;
765+
Coord2D m_gameTimePosition;
766+
Color m_gameTimeColor;
767+
Color m_gameTimeDropColor;
768+
744769
// message data
745770
UIMessage m_uiMessages[ MAX_UI_MESSAGES ];/**< messages to display to the user, the
746771
array is organized with newer messages at

GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,8 @@ GlobalData::GlobalData()
928928
m_saveCameraInReplay = FALSE;
929929
m_useCameraInReplay = FALSE;
930930

931+
m_systemTimeFontSize = 8;
932+
m_gameTimeFontSize = 8;
931933

932934
m_debugShowGraphicalFramerate = FALSE;
933935

@@ -1196,6 +1198,9 @@ void GlobalData::parseGameDataDefinition( INI* ini )
11961198

11971199
TheWritableGlobalData->m_saveCameraInReplay = optionPref.saveCameraInReplays();
11981200
TheWritableGlobalData->m_useCameraInReplay = optionPref.useCameraInReplays();
1201+
1202+
TheWritableGlobalData->m_systemTimeFontSize = optionPref.getSystemTimeFontSize();
1203+
TheWritableGlobalData->m_gameTimeFontSize = optionPref.getGameTimeFontSize();
11991204

12001205
Int val=optionPref.getGammaValue();
12011206
//generate a value between 0.6 and 2.0.

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,34 @@ Real OptionPreferences::getMusicVolume(void)
767767
return volume;
768768
}
769769

770+
Int OptionPreferences::getSystemTimeFontSize(void)
771+
{
772+
OptionPreferences::const_iterator it = find("SystemTimeFontSize");
773+
if (it == end())
774+
return 8;
775+
776+
Int fontSize = atoi(it->second.str());
777+
if (fontSize < 0)
778+
{
779+
fontSize = 0;
780+
}
781+
return fontSize;
782+
}
783+
784+
Int OptionPreferences::getGameTimeFontSize(void)
785+
{
786+
OptionPreferences::const_iterator it = find("GameTimeFontSize");
787+
if (it == end())
788+
return 8;
789+
790+
Int fontSize = atoi(it->second.str());
791+
if (fontSize < 0)
792+
{
793+
fontSize = 0;
794+
}
795+
return fontSize;
796+
}
797+
770798
static OptionPreferences *pref = NULL;
771799

772800
static void setDefaults( void )
@@ -1257,6 +1285,28 @@ static void saveOptions( void )
12571285
}
12581286
}
12591287

1288+
//-------------------------------------------------------------------------------------------------
1289+
// Set System Time Font Size
1290+
val = TheWritableGlobalData->m_systemTimeFontSize; // TheSuperHackers @todo replace with options input when applicable
1291+
if (val)
1292+
{
1293+
AsciiString prefString;
1294+
prefString.format("%d", val);
1295+
(*pref)["SystemTimeFontSize"] = prefString;
1296+
TheInGameUI->refreshCustomUiResources();
1297+
}
1298+
1299+
//-------------------------------------------------------------------------------------------------
1300+
// Set Game Time Font Size
1301+
val = TheWritableGlobalData->m_gameTimeFontSize; // TheSuperHackers @todo replace with options input when applicable
1302+
if (val)
1303+
{
1304+
AsciiString prefString;
1305+
prefString.format("%d", val);
1306+
(*pref)["GameTimeFontSize"] = prefString;
1307+
TheInGameUI->refreshCustomUiResources();
1308+
}
1309+
12601310
//-------------------------------------------------------------------------------------------------
12611311
// Resolution
12621312
//
@@ -1299,6 +1349,7 @@ static void saveOptions( void )
12991349
TheShell->recreateWindowLayouts();
13001350

13011351
TheInGameUI->recreateControlBar();
1352+
TheInGameUI->refreshCustomUiResources();
13021353
}
13031354
}
13041355
}

GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ void GameClient::reset( void )
456456

457457
// need to reset the in game UI to clear drawables before they are destroyed
458458
TheInGameUI->reset();
459+
// TheSuperHackers @info we need to refresh the custom ui resources as their dependencies are cleared in the prior reset call
460+
TheInGameUI->refreshCustomUiResources();
459461

460462
// destroy all Drawables
461463
for( draw = m_drawableList; draw; draw = nextDraw )

GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,19 @@ const FieldParse InGameUI::s_fieldParseTable[] =
871871
{ "ClearMinesRadiusCursor", RadiusDecalTemplate::parseRadiusDecalTemplate, NULL, offsetof( InGameUI, m_radiusCursors[ RADIUSCURSOR_CLEARMINES] ) },
872872
{ "AmbulanceRadiusCursor", RadiusDecalTemplate::parseRadiusDecalTemplate, NULL, offsetof( InGameUI, m_radiusCursors[ RADIUSCURSOR_AMBULANCE] ) },
873873

874+
// TheSuperHackers @info ui enhancement configuration
875+
{ "SystemTimeFont", INI::parseAsciiString, NULL, offsetof( InGameUI, m_systemTimeFont ) },
876+
{ "SystemTimeBold", INI::parseBool, NULL, offsetof( InGameUI, m_systemTimeBold ) },
877+
{ "SystemTimePosition", INI::parseCoord2D, NULL, offsetof( InGameUI, m_systemTimePosition ) },
878+
{ "SystemTimeColor", INI::parseColorInt, NULL, offsetof( InGameUI, m_systemTimeColor ) },
879+
{ "SystemTimeDropColor", INI::parseColorInt, NULL, offsetof( InGameUI, m_systemTimeDropColor ) },
880+
881+
{ "GameTimeFont", INI::parseAsciiString, NULL, offsetof( InGameUI, m_gameTimeFont ) },
882+
{ "GameTimeBold", INI::parseBool, NULL, offsetof( InGameUI, m_gameTimeBold ) },
883+
{ "GameTimePosition", INI::parseCoord2D, NULL, offsetof( InGameUI, m_gameTimePosition ) },
884+
{ "GameTimeColor", INI::parseColorInt, NULL, offsetof( InGameUI, m_gameTimeColor ) },
885+
{ "GameTimeDropColor", INI::parseColorInt, NULL, offsetof( InGameUI, m_gameTimeDropColor ) },
886+
874887
{ NULL, NULL, NULL, 0 } // keep this last
875888
};
876889

@@ -996,6 +1009,25 @@ InGameUI::InGameUI()
9961009
m_replayWindow = NULL;
9971010
m_messagesOn = TRUE;
9981011

1012+
m_systemTimeString = NULL;
1013+
m_systemTimeFont = "Tahoma";
1014+
m_systemTimePointSize = TheGlobalData->m_systemTimeFontSize;
1015+
m_systemTimeBold = TRUE;
1016+
m_systemTimePosition.x = 3; // TheSuperHackers @info relative to the left of the screen
1017+
m_systemTimePosition.y = -1;
1018+
m_systemTimeColor = GameMakeColor( 255, 255, 255, 255 );
1019+
m_systemTimeDropColor = GameMakeColor( 0, 0, 0, 255 );
1020+
1021+
m_gameTimeString = NULL;
1022+
m_gameTimeFrameString = NULL;
1023+
m_gameTimeFont = "Tahoma";
1024+
m_gameTimePointSize = TheGlobalData->m_gameTimeFontSize;
1025+
m_gameTimeBold = TRUE;
1026+
m_gameTimePosition.x = 3; // TheSuperHackers @info relative to the right of the screen
1027+
m_gameTimePosition.y = -1;
1028+
m_gameTimeColor = GameMakeColor( 255, 255, 255, 255 );
1029+
m_gameTimeDropColor = GameMakeColor( 0, 0, 0, 255 );
1030+
9991031
m_superweaponPosition.x = 0.7f;
10001032
m_superweaponPosition.y = 0.7f;
10011033
m_superweaponFlashDuration = 1.0f;
@@ -1077,6 +1109,9 @@ InGameUI::~InGameUI()
10771109
// delete the message resources
10781110
freeMessageResources();
10791111

1112+
// free custom ui strings
1113+
freeCustomUiResources();
1114+
10801115
// delete the array for the drawbles
10811116
delete [] m_placeIcon;
10821117
m_placeIcon = NULL;
@@ -1919,6 +1954,9 @@ void InGameUI::reset( void )
19191954
// free any message resources allocated
19201955
freeMessageResources();
19211956

1957+
// free custom ui strings
1958+
freeCustomUiResources();
1959+
19221960
Int i;
19231961
for (i=0; i<MAX_PLAYER_COUNT; ++i)
19241962
{
@@ -2004,6 +2042,16 @@ void InGameUI::freeMessageResources( void )
20042042

20052043
} // end freeMessageResources
20062044

2045+
void InGameUI::freeCustomUiResources( void )
2046+
{
2047+
TheDisplayStringManager->freeDisplayString(m_systemTimeString);
2048+
m_systemTimeString = NULL;
2049+
TheDisplayStringManager->freeDisplayString(m_gameTimeString);
2050+
m_gameTimeString = NULL;
2051+
TheDisplayStringManager->freeDisplayString(m_gameTimeFrameString);
2052+
m_gameTimeFrameString = NULL;
2053+
}
2054+
20072055
//-------------------------------------------------------------------------------------------------
20082056
/** Same as the unicode message method, but this takes an ascii string which is assumed
20092057
* to me a string manager label */
@@ -3454,6 +3502,22 @@ void InGameUI::disregardDrawable( Drawable *draw )
34543502

34553503
}
34563504

3505+
//-------------------------------------------------------------------------------------------------
3506+
/** This is called after the WindowManager has drawn the menus. */
3507+
//-------------------------------------------------------------------------------------------------
3508+
void InGameUI::postWindowDraw( void )
3509+
{
3510+
if (m_systemTimePointSize > 0)
3511+
{
3512+
drawSystemTime();
3513+
}
3514+
3515+
if ( (m_gameTimePointSize > 0) && !TheGameLogic->isInShellGame() && TheGameLogic->isInGame() )
3516+
{
3517+
drawGameTime();
3518+
}
3519+
}
3520+
34573521
//-------------------------------------------------------------------------------------------------
34583522
/** This is called after the UI has been drawn. */
34593523
//-------------------------------------------------------------------------------------------------
@@ -5659,6 +5723,33 @@ void InGameUI::recreateControlBar( void )
56595723

56605724
}
56615725

5726+
void InGameUI::refreshCustomUiResources(void)
5727+
{
5728+
if (!m_systemTimeString) {
5729+
m_systemTimeString = TheDisplayStringManager->newDisplayString();
5730+
}
5731+
5732+
m_systemTimePointSize = TheGlobalData->m_systemTimeFontSize;
5733+
Int adjustedSystemTimeFontSize = TheGlobalLanguageData->adjustFontSize(m_systemTimePointSize);
5734+
GameFont* systemTimeFont = TheWindowManager->winFindFont(m_systemTimeFont, adjustedSystemTimeFontSize, m_systemTimeBold);
5735+
m_systemTimeString->setFont(systemTimeFont);
5736+
5737+
5738+
if (!m_gameTimeString) {
5739+
m_gameTimeString = TheDisplayStringManager->newDisplayString();
5740+
}
5741+
5742+
if (!m_gameTimeFrameString) {
5743+
m_gameTimeFrameString = TheDisplayStringManager->newDisplayString();
5744+
}
5745+
5746+
m_gameTimePointSize = TheGlobalData->m_gameTimeFontSize;
5747+
Int adjustedGameTimeFontSize = TheGlobalLanguageData->adjustFontSize(m_gameTimePointSize);
5748+
GameFont* gameTimeFont = TheWindowManager->winFindFont(m_gameTimeFont, adjustedGameTimeFontSize, m_gameTimeBold);
5749+
m_gameTimeString->setFont(gameTimeFont);
5750+
m_gameTimeFrameString->setFont(gameTimeFont);
5751+
}
5752+
56625753
void InGameUI::disableTooltipsUntil(UnsignedInt frameNum)
56635754
{
56645755
if (frameNum > m_tooltipsDisabledUntil)
@@ -5713,4 +5804,40 @@ WindowMsgHandledType IdleWorkerSystem( GameWindow *window, UnsignedInt msg,
57135804

57145805
}
57155806

5807+
void InGameUI::drawSystemTime()
5808+
{
5809+
// current system time
5810+
SYSTEMTIME systemTime;
5811+
GetLocalTime( &systemTime );
57165812

5813+
UnicodeString TimeString;
5814+
TimeString.format(L"%2.2d:%2.2d:%2.2d", systemTime.wHour, systemTime.wMinute, systemTime.wSecond);
5815+
m_systemTimeString->setText(TimeString);
5816+
5817+
m_systemTimeString->draw(m_systemTimePosition.x, m_systemTimePosition.y, m_systemTimeColor, m_systemTimeDropColor);
5818+
}
5819+
5820+
void InGameUI::drawGameTime()
5821+
{
5822+
Int currentFrame = TheGameLogic->getFrame();
5823+
Int gameSeconds = (Int) (SECONDS_PER_LOGICFRAME_REAL * currentFrame );
5824+
Int hours = gameSeconds / 60 / 60;
5825+
Int minutes = (gameSeconds / 60) % 60;
5826+
Int seconds = gameSeconds % 60;
5827+
Int frame = currentFrame % 30;
5828+
5829+
UnicodeString gameTimeString;
5830+
gameTimeString.format(L"%2.2d:%2.2d:%2.2d", hours, minutes, seconds);
5831+
m_gameTimeString->setText(gameTimeString);
5832+
5833+
UnicodeString gameTimeFrameString;
5834+
gameTimeFrameString.format(L".%2.2d", frame);
5835+
m_gameTimeFrameString->setText(gameTimeFrameString);
5836+
5837+
// TheSuperHackers @info this implicitly offsets the game timer from the right instead of left of the screen
5838+
int horizontalTimerOffset = TheDisplay->getWidth() - (Int)m_gameTimePosition.x - m_gameTimeString->getWidth() - m_gameTimeFrameString->getWidth();
5839+
int horizontalFrameOffset = TheDisplay->getWidth() - (Int)m_gameTimePosition.x - m_gameTimeFrameString->getWidth();
5840+
5841+
m_gameTimeString->draw(horizontalTimerOffset, m_gameTimePosition.y, m_gameTimeColor, m_gameTimeDropColor);
5842+
m_gameTimeFrameString->draw(horizontalFrameOffset, m_gameTimePosition.y, GameMakeColor(180,180,180,255), m_gameTimeDropColor);
5843+
}

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,8 @@ void W3DInGameUI::draw( void )
432432
postDraw();
433433

434434
TheWindowManager->winRepaint();
435+
436+
postWindowDraw();
435437

436438
#ifdef EXTENDED_STATS
437439
}

0 commit comments

Comments
 (0)