Skip to content

Commit eff725d

Browse files
committed
[ZH] Implement system time and simulation timer within InGameUI
1 parent 3bda27a commit eff725d

File tree

7 files changed

+206
-0
lines changed

7 files changed

+206
-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: 24 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 );
@@ -578,6 +580,9 @@ friend class Drawable; // for selection/deselection transactions
578580
virtual void updateIdleWorker( void );
579581
virtual void resetIdleWorker( void );
580582

583+
void drawSystemTime();
584+
void drawGameTime();
585+
581586
public:
582587
void registerWindowLayout(WindowLayout *layout); // register a layout for updates
583588
void unregisterWindowLayout(WindowLayout *layout); // stop updates for this layout
@@ -741,6 +746,25 @@ friend class Drawable; // for selection/deselection transactions
741746
VideoBuffer* m_cameoVideoBuffer;///< video playback buffer
742747
VideoStreamInterface* m_cameoVideoStream;///< Video stream;
743748

749+
// System Time
750+
DisplayString * m_systemTimeString;
751+
AsciiString m_systemTimeFont;
752+
Int m_systemTimePointSize;
753+
Bool m_systemTimeBold;
754+
Coord2D m_systemTimePosition;
755+
Color m_systemTimeColor;
756+
Color m_systemTimeDropColor;
757+
758+
// Simulation Timer
759+
DisplayString * m_gameTimeString;
760+
DisplayString * m_gameTimeFrameString;
761+
AsciiString m_gameTimeFont;
762+
Int m_gameTimePointSize;
763+
Bool m_gameTimeBold;
764+
Coord2D m_gameTimePosition;
765+
Color m_gameTimeColor;
766+
Color m_gameTimeDropColor;
767+
744768
// message data
745769
UIMessage m_uiMessages[ MAX_UI_MESSAGES ];/**< messages to display to the user, the
746770
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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,34 @@ Real OptionPreferences::getMusicVolume(void)
772772
return volume;
773773
}
774774

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

777805
static void setDefaults( void )
@@ -1262,6 +1290,26 @@ static void saveOptions( void )
12621290
}
12631291
}
12641292

1293+
//-------------------------------------------------------------------------------------------------
1294+
// Set System Time Font Size
1295+
val = TheWritableGlobalData->m_systemTimeFontSize; // TheSuperHackers @info replace with options input when applicable
1296+
if (val)
1297+
{
1298+
AsciiString prefString;
1299+
prefString.format("%d", val);
1300+
(*pref)["SystemTimeFontSize"] = prefString;
1301+
}
1302+
1303+
//-------------------------------------------------------------------------------------------------
1304+
// Set Game Time Font Size
1305+
val = TheWritableGlobalData->m_gameTimeFontSize; // TheSuperHackers @info replace with options input when applicable
1306+
if (val)
1307+
{
1308+
AsciiString prefString;
1309+
prefString.format("%d", val);
1310+
(*pref)["GameTimeFontSize"] = prefString;
1311+
}
1312+
12651313
//-------------------------------------------------------------------------------------------------
12661314
// Resolution
12671315
//

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

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,19 @@ const FieldParse InGameUI::s_fieldParseTable[] =
876876
{ "ClearMinesRadiusCursor", RadiusDecalTemplate::parseRadiusDecalTemplate, NULL, offsetof( InGameUI, m_radiusCursors[ RADIUSCURSOR_CLEARMINES] ) },
877877
{ "AmbulanceRadiusCursor", RadiusDecalTemplate::parseRadiusDecalTemplate, NULL, offsetof( InGameUI, m_radiusCursors[ RADIUSCURSOR_AMBULANCE] ) },
878878

879+
// TheSuperHackers @info ui enhancement configuration
880+
{ "SystemTimeFont", INI::parseAsciiString, NULL, offsetof( InGameUI, m_systemTimeFont ) },
881+
{ "SystemTimeBold", INI::parseBool, NULL, offsetof( InGameUI, m_systemTimeBold ) },
882+
{ "SystemTimePosition", INI::parseCoord2D, NULL, offsetof( InGameUI, m_systemTimePosition ) },
883+
{ "SystemTimeColor", INI::parseColorInt, NULL, offsetof( InGameUI, m_systemTimeColor ) },
884+
{ "SystemTimeDropColor", INI::parseColorInt, NULL, offsetof( InGameUI, m_systemTimeDropColor ) },
885+
886+
{ "GameTimeFont", INI::parseAsciiString, NULL, offsetof( InGameUI, m_gameTimeFont ) },
887+
{ "GameTimeBold", INI::parseBool, NULL, offsetof( InGameUI, m_gameTimeBold ) },
888+
{ "GameTimePosition", INI::parseCoord2D, NULL, offsetof( InGameUI, m_gameTimePosition ) },
889+
{ "GameTimeColor", INI::parseColorInt, NULL, offsetof( InGameUI, m_gameTimeColor ) },
890+
{ "GameTimeDropColor", INI::parseColorInt, NULL, offsetof( InGameUI, m_gameTimeDropColor ) },
891+
879892
{ NULL, NULL, NULL, 0 } // keep this last
880893
};
881894

@@ -1001,6 +1014,25 @@ InGameUI::InGameUI()
10011014
m_replayWindow = NULL;
10021015
m_messagesOn = TRUE;
10031016

1017+
m_systemTimeString = NULL;
1018+
m_systemTimeFont = "Tahoma";
1019+
m_systemTimePointSize = TheGlobalData->m_systemTimeFontSize;
1020+
m_systemTimeBold = TRUE;
1021+
m_systemTimePosition.x = 3; // TheSuperHackers @info relative to the left of the screen
1022+
m_systemTimePosition.y = -1;
1023+
m_systemTimeColor = GameMakeColor( 255, 255, 255, 255 );
1024+
m_systemTimeDropColor = GameMakeColor( 0, 0, 0, 255 );
1025+
1026+
m_gameTimeString = NULL;
1027+
m_gameTimeFrameString = NULL;
1028+
m_gameTimeFont = "Tahoma";
1029+
m_gameTimePointSize = TheGlobalData->m_gameTimeFontSize;
1030+
m_gameTimeBold = TRUE;
1031+
m_gameTimePosition.x = 3; // TheSuperHackers @info relative to the right of the screen
1032+
m_gameTimePosition.y = -1;
1033+
m_gameTimeColor = GameMakeColor( 255, 255, 255, 255 );
1034+
m_gameTimeDropColor = GameMakeColor( 0, 0, 0, 255 );
1035+
10041036
m_superweaponPosition.x = 0.7f;
10051037
m_superweaponPosition.y = 0.7f;
10061038
m_superweaponFlashDuration = 1.0f;
@@ -1082,6 +1114,9 @@ InGameUI::~InGameUI()
10821114
// delete the message resources
10831115
freeMessageResources();
10841116

1117+
// free custom ui strings
1118+
freeCustomUiResources();
1119+
10851120
// delete the array for the drawbles
10861121
delete [] m_placeIcon;
10871122
m_placeIcon = NULL;
@@ -1924,6 +1959,9 @@ void InGameUI::reset( void )
19241959
// free any message resources allocated
19251960
freeMessageResources();
19261961

1962+
// free custom ui strings
1963+
freeCustomUiResources();
1964+
19271965
Int i;
19281966
for (i=0; i<MAX_PLAYER_COUNT; ++i)
19291967
{
@@ -2009,6 +2047,16 @@ void InGameUI::freeMessageResources( void )
20092047

20102048
} // end freeMessageResources
20112049

2050+
void InGameUI::freeCustomUiResources( void )
2051+
{
2052+
TheDisplayStringManager->freeDisplayString(m_systemTimeString);
2053+
m_systemTimeString = NULL;
2054+
TheDisplayStringManager->freeDisplayString(m_gameTimeString);
2055+
m_gameTimeString = NULL;
2056+
TheDisplayStringManager->freeDisplayString(m_gameTimeFrameString);
2057+
m_gameTimeFrameString = NULL;
2058+
}
2059+
20122060
//-------------------------------------------------------------------------------------------------
20132061
/** Same as the unicode message method, but this takes an ascii string which is assumed
20142062
* to me a string manager label */
@@ -3459,12 +3507,29 @@ void InGameUI::disregardDrawable( Drawable *draw )
34593507

34603508
}
34613509

3510+
//-------------------------------------------------------------------------------------------------
3511+
/** This is called after the WindowManager has drawn the menus. */
3512+
//-------------------------------------------------------------------------------------------------
3513+
void InGameUI::postWindowDraw( void )
3514+
{
3515+
if (m_systemTimePointSize > 0)
3516+
{
3517+
drawSystemTime();
3518+
}
3519+
}
3520+
34623521
//-------------------------------------------------------------------------------------------------
34633522
/** This is called after the UI has been drawn. */
34643523
//-------------------------------------------------------------------------------------------------
34653524
void InGameUI::postDraw( void )
34663525
{
34673526

3527+
// TheSuperHackers @info render the game time first, this way other text will render over them if they overlap
3528+
if (m_gameTimePointSize > 0 && !TheGameLogic->isInShellGame())
3529+
{
3530+
drawGameTime();
3531+
}
3532+
34683533
// render our display strings for the messages if on
34693534
if( m_messagesOn )
34703535
{
@@ -5718,4 +5783,59 @@ WindowMsgHandledType IdleWorkerSystem( GameWindow *window, UnsignedInt msg,
57185783

57195784
}
57205785

5786+
void InGameUI::drawSystemTime()
5787+
{
5788+
if (!m_systemTimeString) {
5789+
m_systemTimeString = TheDisplayStringManager->newDisplayString();
5790+
}
5791+
5792+
// current system time
5793+
SYSTEMTIME systemTime;
5794+
GetLocalTime( &systemTime );
5795+
5796+
UnicodeString TimeString;
5797+
TimeString.format(L"%2.2d:%2.2d:%2.2d", systemTime.wHour, systemTime.wMinute, systemTime.wSecond);
5798+
Int adjustedSystemTimeFontSize = TheGlobalLanguageData->adjustFontSize(m_systemTimePointSize);
5799+
GameFont* systemTimeFont = TheWindowManager->winFindFont(m_systemTimeFont, adjustedSystemTimeFontSize, m_systemTimeBold);
5800+
m_systemTimeString->setFont(systemTimeFont);
5801+
m_systemTimeString->setText(TimeString);
5802+
5803+
m_systemTimeString->draw(m_systemTimePosition.x, m_systemTimePosition.y, m_systemTimeColor, m_systemTimeDropColor);
5804+
}
5805+
5806+
void InGameUI::drawGameTime()
5807+
{
5808+
if (!m_gameTimeString) {
5809+
m_gameTimeString = TheDisplayStringManager->newDisplayString();
5810+
}
5811+
5812+
if (!m_gameTimeFrameString) {
5813+
m_gameTimeFrameString = TheDisplayStringManager->newDisplayString();
5814+
}
5815+
5816+
Int currentFrame = TheGameLogic->getFrame();
5817+
Int gameSeconds = (Int) (SECONDS_PER_LOGICFRAME_REAL * currentFrame );
5818+
Int hours = gameSeconds / 60 / 60;
5819+
Int minutes = (gameSeconds / 60) % 60;
5820+
Int seconds = gameSeconds % 60;
5821+
Int frame = currentFrame % 30;
57215822

5823+
UnicodeString gameTimeString;
5824+
gameTimeString.format(L"%2.2d:%2.2d:%2.2d", hours, minutes, seconds);
5825+
Int adjustedGameTimeFontSize = TheGlobalLanguageData->adjustFontSize(m_gameTimePointSize);
5826+
GameFont* gameTimeFont = TheWindowManager->winFindFont(m_gameTimeFont, adjustedGameTimeFontSize, m_gameTimeBold);
5827+
m_gameTimeString->setFont(gameTimeFont);
5828+
m_gameTimeString->setText(gameTimeString);
5829+
5830+
UnicodeString gameTimeFrameString;
5831+
gameTimeFrameString.format(L".%2.2d", frame);
5832+
m_gameTimeFrameString->setFont(gameTimeFont);
5833+
m_gameTimeFrameString->setText(gameTimeFrameString);
5834+
5835+
// TheSuperHackers @info this implicitly offsets the game timer from the right instead of left of the screen
5836+
int horizontalTimerOffset = TheDisplay->getWidth() - (Int)m_gameTimePosition.x - m_gameTimeString->getWidth() - m_gameTimeFrameString->getWidth();
5837+
int horizontalFrameOffset = TheDisplay->getWidth() - (Int)m_gameTimePosition.x - m_gameTimeFrameString->getWidth();
5838+
5839+
m_gameTimeString->draw(horizontalTimerOffset, m_gameTimePosition.y, m_gameTimeColor, m_gameTimeDropColor);
5840+
m_gameTimeFrameString->draw(horizontalFrameOffset, m_gameTimePosition.y, GameMakeColor(180,180,180,255), m_gameTimeDropColor);
5841+
}

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

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

439439
TheWindowManager->winRepaint();
440+
441+
postWindowDraw();
440442

441443
#ifdef EXTENDED_STATS
442444
}

0 commit comments

Comments
 (0)