Skip to content

Commit e471c53

Browse files
committed
[ZH] Implement system time and simulation timer within InGameUI
1 parent 1802377 commit e471c53

File tree

6 files changed

+142
-0
lines changed

6 files changed

+142
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ class GlobalData : public SubsystemInterface
124124
// Run game without graphics, input or audio.
125125
Bool m_headless;
126126

127+
// TheSuperHAckers @feature Mauller 21/06/2025
128+
// Allow the system time and sim timer to be toggleable
129+
Bool m_showSystemTime;
130+
Bool m_showSimulationTimer;
131+
127132
Bool m_windowed;
128133
Int m_xResolution;
129134
Int m_yResolution;

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

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

130130
Int getCampaignDifficulty(void);
131131
void setCampaignDifficulty( Int diff );
132+
133+
// TheSuperHackers @feature Mauller 21/06/2025
134+
Bool getSystemTimeEnabled(void);
135+
Bool getSimulationTimerEnabled(void);
132136
};
133137

134138
//-----------------------------------------------------------------------------

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,24 @@ friend class Drawable; // for selection/deselection transactions
741741
VideoBuffer* m_cameoVideoBuffer;///< video playback buffer
742742
VideoStreamInterface* m_cameoVideoStream;///< Video stream;
743743

744+
// System Time
745+
DisplayString * m_systemTimeString;
746+
AsciiString m_systemTimeFont;
747+
Int m_systemTimePointSize;
748+
Bool m_systemTimeBold;
749+
Coord2D m_systemTimePosition;
750+
Color m_systemTimeColor;
751+
Color m_systemTimeDropColor;
752+
753+
// Simulation Timer
754+
DisplayString * m_simulationTimerString;
755+
AsciiString m_simulationTimerFont;
756+
Int m_simulationTimerPointSize;
757+
Bool m_simulationTimerBold;
758+
Coord2D m_simulationTimerPosition;
759+
Color m_simulationTimerColor;
760+
Color m_simulationTimerDropColor;
761+
744762
// message data
745763
UIMessage m_uiMessages[ MAX_UI_MESSAGES ];/**< messages to display to the user, the
746764
array is organized with newer messages at

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,8 @@ GlobalData::GlobalData()
614614
m_framesPerSecondLimit = 0;
615615
m_chipSetType = 0;
616616
m_headless = FALSE;
617+
m_showSystemTime = TRUE;
618+
m_showSimulationTimer = TRUE;
617619
m_windowed = 0;
618620
m_xResolution = 800;
619621
m_yResolution = 600;
@@ -1282,5 +1284,9 @@ void GlobalData::parseGameDataDefinition( INI* ini )
12821284

12831285
TheWritableGlobalData->m_xResolution = xres;
12841286
TheWritableGlobalData->m_yResolution = yres;
1287+
1288+
// TheSuperHacker @info parse new settings
1289+
TheWritableGlobalData->m_showSystemTime = optionPref.getSystemTimeEnabled();
1290+
TheWritableGlobalData->m_showSimulationTimer = optionPref.getSimulationTimerEnabled();
12851291
}
12861292

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,32 @@ Real OptionPreferences::getMusicVolume(void)
772772
return volume;
773773
}
774774

775+
// TheSuperHackers @info Here for ini parsing and future use when the options menu is reworked to add new options
776+
Bool OptionPreferences::getSystemTimeEnabled(void)
777+
{
778+
OptionPreferences::const_iterator it = find("SystemTimeEnabled");
779+
if (it == end())
780+
return TheGlobalData->m_showSystemTime;
781+
782+
if (stricmp(it->second.str(), "yes") == 0) {
783+
return TRUE;
784+
}
785+
return FALSE;
786+
}
787+
788+
// TheSuperHackers @info Here for ini parsing and future use when the options menu is reworked to add new options
789+
Bool OptionPreferences::getSimulationTimerEnabled(void)
790+
{
791+
OptionPreferences::const_iterator it = find("SimulationTimerEnabled");
792+
if (it == end())
793+
return TheGlobalData->m_showSimulationTimer;
794+
795+
if (stricmp(it->second.str(), "yes") == 0) {
796+
return TRUE;
797+
}
798+
return FALSE;
799+
}
800+
775801
static OptionPreferences *pref = NULL;
776802

777803
static void setDefaults( void )

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,21 @@ 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+
{ "SystemTimePointSize", INI::parseInt, NULL, offsetof( InGameUI, m_systemTimePointSize ) },
882+
{ "SystemTimeBold", INI::parseBool, NULL, offsetof( InGameUI, m_systemTimeBold ) },
883+
{ "SystemTimePosition", INI::parseCoord2D, NULL, offsetof( InGameUI, m_systemTimePosition ) },
884+
{ "SystemTimeColor", INI::parseColorInt, NULL, offsetof( InGameUI, m_systemTimeColor ) },
885+
{ "SystemTimeDropColor", INI::parseColorInt, NULL, offsetof( InGameUI, m_systemTimeDropColor ) },
886+
887+
{ "SimulationTimerFont", INI::parseAsciiString, NULL, offsetof( InGameUI, m_simulationTimerFont ) },
888+
{ "SimulationTimerPointSize", INI::parseInt, NULL, offsetof( InGameUI, m_simulationTimerPointSize ) },
889+
{ "SimulationTimerBold", INI::parseBool, NULL, offsetof( InGameUI, m_simulationTimerBold ) },
890+
{ "SimulationTimerPosition", INI::parseCoord2D, NULL, offsetof( InGameUI, m_simulationTimerPosition ) },
891+
{ "SimulationTimerColor", INI::parseColorInt, NULL, offsetof( InGameUI, m_simulationTimerColor ) },
892+
{ "SimulationTimerDropColor", INI::parseColorInt, NULL, offsetof( InGameUI, m_simulationTimerDropColor ) },
893+
879894
{ NULL, NULL, NULL, 0 } // keep this last
880895
};
881896

@@ -1001,6 +1016,24 @@ InGameUI::InGameUI()
10011016
m_replayWindow = NULL;
10021017
m_messagesOn = TRUE;
10031018

1019+
m_systemTimeString = NULL;
1020+
m_systemTimeFont = "Arial";
1021+
m_systemTimePointSize = 10;
1022+
m_systemTimeBold = FALSE;
1023+
m_systemTimePosition.x = 5;
1024+
m_systemTimePosition.y = 0;
1025+
m_systemTimeColor = GameMakeColor( 255, 255, 255, 255 );
1026+
m_systemTimeDropColor = GameMakeColor( 0, 0, 0, 255 );
1027+
1028+
m_simulationTimerString = NULL;
1029+
m_simulationTimerFont = "Arial";
1030+
m_simulationTimerPointSize = 10;
1031+
m_simulationTimerBold = FALSE;
1032+
m_simulationTimerPosition.x = 0.92f;
1033+
m_simulationTimerPosition.y = 0;
1034+
m_simulationTimerColor = GameMakeColor( 255, 255, 255, 255 );
1035+
m_simulationTimerDropColor = GameMakeColor( 0, 0, 0, 255 );
1036+
10041037
m_superweaponPosition.x = 0.7f;
10051038
m_superweaponPosition.y = 0.7f;
10061039
m_superweaponFlashDuration = 1.0f;
@@ -2007,6 +2040,12 @@ void InGameUI::freeMessageResources( void )
20072040

20082041
} // end for i
20092042

2043+
// release timer strings then set them to empty
2044+
TheDisplayStringManager->freeDisplayString(m_systemTimeString);
2045+
m_systemTimeString = NULL;
2046+
TheDisplayStringManager->freeDisplayString(m_simulationTimerString);
2047+
m_simulationTimerString = NULL;
2048+
20102049
} // end freeMessageResources
20112050

20122051
//-------------------------------------------------------------------------------------------------
@@ -3465,6 +3504,50 @@ void InGameUI::disregardDrawable( Drawable *draw )
34653504
void InGameUI::postDraw( void )
34663505
{
34673506

3507+
// TheSuperHackers @info render the system time and simulation timer first, this way other text will render over them if they overlap
3508+
// draw the current system time
3509+
if (TheGlobalData->m_showSystemTime && !TheGameLogic->isInShellGame())
3510+
{
3511+
if (!m_systemTimeString) {
3512+
m_systemTimeString = TheDisplayStringManager->newDisplayString();
3513+
}
3514+
3515+
// current system time
3516+
SYSTEMTIME systemTime;
3517+
GetLocalTime( &systemTime );
3518+
3519+
UnicodeString TimeString;
3520+
TimeString.format(L"%2.2d:%2.2d:%2.2d", systemTime.wHour, systemTime.wMinute, systemTime.wSecond);
3521+
m_systemTimeString->setFont(TheWindowManager->winFindFont( m_systemTimeFont,
3522+
TheGlobalLanguageData->adjustFontSize(m_systemTimePointSize), m_systemTimeBold ));
3523+
m_systemTimeString->setText(TimeString);
3524+
3525+
m_systemTimeString->draw(m_systemTimePosition.x, m_systemTimePosition.y, m_systemTimeColor, m_systemTimeDropColor);
3526+
}
3527+
3528+
// draw the simulation timer
3529+
if (TheGlobalData->m_showSimulationTimer && !TheGameLogic->isInShellGame())
3530+
{
3531+
if (!m_simulationTimerString) {
3532+
m_simulationTimerString = TheDisplayStringManager->newDisplayString();
3533+
}
3534+
3535+
Int currentFrame = TheGameLogic->getFrame();
3536+
Int currentSimulationTime = (Int) (SECONDS_PER_LOGICFRAME_REAL * currentFrame );
3537+
Int hours = currentSimulationTime / 3600;
3538+
Int minutes = (currentSimulationTime / 60) - (hours * 60);
3539+
Int seconds = currentSimulationTime - (minutes * 60) - (hours * 3600);
3540+
Int frame = currentFrame % 30;
3541+
3542+
UnicodeString simulationTimeString;
3543+
simulationTimeString.format(L"%2.2d:%2.2d:%2.2d.%2.2d", hours, minutes, seconds, frame);
3544+
m_simulationTimerString->setFont(TheWindowManager->winFindFont( m_simulationTimerFont,
3545+
TheGlobalLanguageData->adjustFontSize(m_simulationTimerPointSize), m_simulationTimerBold ));
3546+
m_simulationTimerString->setText(simulationTimeString);
3547+
3548+
m_simulationTimerString->draw(TheDisplay->getWidth() * m_simulationTimerPosition.x, m_simulationTimerPosition.y, m_simulationTimerColor, m_simulationTimerDropColor);
3549+
}
3550+
34683551
// render our display strings for the messages if on
34693552
if( m_messagesOn )
34703553
{

0 commit comments

Comments
 (0)