Skip to content

Commit 3c09aac

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

File tree

6 files changed

+197
-0
lines changed

6 files changed

+197
-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: 23 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
@@ -578,6 +579,9 @@ friend class Drawable; // for selection/deselection transactions
578579
virtual void updateIdleWorker( void );
579580
virtual void resetIdleWorker( void );
580581

582+
void drawSystemTime();
583+
void drawGameTime();
584+
581585
public:
582586
void registerWindowLayout(WindowLayout *layout); // register a layout for updates
583587
void unregisterWindowLayout(WindowLayout *layout); // stop updates for this layout
@@ -741,6 +745,25 @@ friend class Drawable; // for selection/deselection transactions
741745
VideoBuffer* m_cameoVideoBuffer;///< video playback buffer
742746
VideoStreamInterface* m_cameoVideoStream;///< Video stream;
743747

748+
// System Time
749+
DisplayString * m_systemTimeString;
750+
AsciiString m_systemTimeFont;
751+
Int m_systemTimePointSize;
752+
Bool m_systemTimeBold;
753+
Coord2D m_systemTimePosition;
754+
Color m_systemTimeColor;
755+
Color m_systemTimeDropColor;
756+
757+
// Simulation Timer
758+
DisplayString * m_gameTimeString;
759+
DisplayString * m_gameTimeFrameString;
760+
AsciiString m_gameTimeFont;
761+
Int m_gameTimePointSize;
762+
Bool m_gameTimeBold;
763+
Coord2D m_gameTimePosition;
764+
Color m_gameTimeColor;
765+
Color m_gameTimeDropColor;
766+
744767
// message data
745768
UIMessage m_uiMessages[ MAX_UI_MESSAGES ];/**< messages to display to the user, the
746769
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: 114 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 */
@@ -3465,6 +3513,17 @@ void InGameUI::disregardDrawable( Drawable *draw )
34653513
void InGameUI::postDraw( void )
34663514
{
34673515

3516+
// TheSuperHackers @info render the system time and game time first, this way other text will render over them if they overlap
3517+
if (m_systemTimePointSize > 0)
3518+
{
3519+
drawSystemTime();
3520+
}
3521+
3522+
if (m_gameTimePointSize > 0 && !TheGameLogic->isInShellGame())
3523+
{
3524+
drawGameTime();
3525+
}
3526+
34683527
// render our display strings for the messages if on
34693528
if( m_messagesOn )
34703529
{
@@ -5718,4 +5777,59 @@ WindowMsgHandledType IdleWorkerSystem( GameWindow *window, UnsignedInt msg,
57185777

57195778
}
57205779

5780+
void InGameUI::drawSystemTime()
5781+
{
5782+
if (!m_systemTimeString) {
5783+
m_systemTimeString = TheDisplayStringManager->newDisplayString();
5784+
}
57215785

5786+
// current system time
5787+
SYSTEMTIME systemTime;
5788+
GetLocalTime( &systemTime );
5789+
5790+
UnicodeString TimeString;
5791+
TimeString.format(L"%2.2d:%2.2d:%2.2d", systemTime.wHour, systemTime.wMinute, systemTime.wSecond);
5792+
Int adjustedSystemTimeFontSize = TheGlobalLanguageData->adjustFontSize(m_systemTimePointSize);
5793+
GameFont* systemTimeFont = TheWindowManager->winFindFont(m_systemTimeFont, adjustedSystemTimeFontSize, m_systemTimeBold);
5794+
m_systemTimeString->setFont(systemTimeFont);
5795+
m_systemTimeString->setText(TimeString);
5796+
5797+
m_systemTimeString->draw(m_systemTimePosition.x, m_systemTimePosition.y, m_systemTimeColor, m_systemTimeDropColor);
5798+
}
5799+
5800+
void InGameUI::drawGameTime()
5801+
{
5802+
if (!m_gameTimeString) {
5803+
m_gameTimeString = TheDisplayStringManager->newDisplayString();
5804+
}
5805+
5806+
if (!m_gameTimeFrameString) {
5807+
m_gameTimeFrameString = TheDisplayStringManager->newDisplayString();
5808+
}
5809+
5810+
Int currentFrame = TheGameLogic->getFrame();
5811+
Int gameSeconds = (Int) (SECONDS_PER_LOGICFRAME_REAL * currentFrame );
5812+
Int hours = gameSeconds / 60 / 60;
5813+
Int minutes = (gameSeconds / 60) % 60;
5814+
Int seconds = gameSeconds % 60;
5815+
Int frame = currentFrame % 30;
5816+
5817+
UnicodeString gameTimeString;
5818+
gameTimeString.format(L"%2.2d:%2.2d:%2.2d", hours, minutes, seconds);
5819+
Int adjustedGameTimeFontSize = TheGlobalLanguageData->adjustFontSize(m_gameTimePointSize);
5820+
GameFont* gameTimeFont = TheWindowManager->winFindFont(m_gameTimeFont, adjustedGameTimeFontSize, m_gameTimeBold);
5821+
m_gameTimeString->setFont(gameTimeFont);
5822+
m_gameTimeString->setText(gameTimeString);
5823+
5824+
UnicodeString gameTimeFrameString;
5825+
gameTimeFrameString.format(L".%2.2d", frame);
5826+
m_gameTimeFrameString->setFont(gameTimeFont);
5827+
m_gameTimeFrameString->setText(gameTimeFrameString);
5828+
5829+
// TheSuperHackers @info this implicitly offsets the game timer from the right instead of left of the screen
5830+
int horizontalTimerOffset = TheDisplay->getWidth() - (Int)m_gameTimePosition.x - m_gameTimeString->getWidth() - m_gameTimeFrameString->getWidth();
5831+
int horizontalFrameOffset = TheDisplay->getWidth() - (Int)m_gameTimePosition.x - m_gameTimeFrameString->getWidth();
5832+
5833+
m_gameTimeString->draw(horizontalTimerOffset, m_gameTimePosition.y, m_gameTimeColor, m_gameTimeDropColor);
5834+
m_gameTimeFrameString->draw(horizontalFrameOffset, m_gameTimePosition.y, GameMakeColor(180,180,180,255), m_gameTimeDropColor);
5835+
}

0 commit comments

Comments
 (0)