Skip to content

Commit 907d2e4

Browse files
committed
[ZH] Implement system time and simulation timer within InGameUI
1 parent 222a7bf commit 907d2e4

File tree

6 files changed

+175
-0
lines changed

6 files changed

+175
-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: 20 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
@@ -741,6 +742,25 @@ friend class Drawable; // for selection/deselection transactions
741742
VideoBuffer* m_cameoVideoBuffer;///< video playback buffer
742743
VideoStreamInterface* m_cameoVideoStream;///< Video stream;
743744

745+
// System Time
746+
DisplayString * m_systemTimeString;
747+
AsciiString m_systemTimeFont;
748+
Int m_systemTimePointSize;
749+
Bool m_systemTimeBold;
750+
Coord2D m_systemTimePosition;
751+
Color m_systemTimeColor;
752+
Color m_systemTimeDropColor;
753+
754+
// Simulation Timer
755+
DisplayString * m_simulationTimerString;
756+
DisplayString * m_simulationTimerFrameString;
757+
AsciiString m_simulationTimerFont;
758+
Int m_simulationTimerPointSize;
759+
Bool m_simulationTimerBold;
760+
Coord2D m_simulationTimerPosition;
761+
Color m_simulationTimerColor;
762+
Color m_simulationTimerDropColor;
763+
744764
// message data
745765
UIMessage m_uiMessages[ MAX_UI_MESSAGES ];/**< messages to display to the user, the
746766
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: 114 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,25 @@ InGameUI::InGameUI()
10011016
m_replayWindow = NULL;
10021017
m_messagesOn = TRUE;
10031018

1019+
m_systemTimeString = NULL;
1020+
m_systemTimeFont = "Tahoma";
1021+
m_systemTimePointSize = 8;
1022+
m_systemTimeBold = TRUE;
1023+
m_systemTimePosition.x = 5; // TheSuperHackers @info relative to the left of the screen
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_simulationTimerFrameString = NULL;
1030+
m_simulationTimerFont = "Tahoma";
1031+
m_simulationTimerPointSize = 8;
1032+
m_simulationTimerBold = TRUE;
1033+
m_simulationTimerPosition.x = 5; // TheSuperHackers @info relative to the right of the screen
1034+
m_simulationTimerPosition.y = 0;
1035+
m_simulationTimerColor = GameMakeColor( 255, 255, 255, 255 );
1036+
m_simulationTimerDropColor = GameMakeColor( 0, 0, 0, 255 );
1037+
10041038
m_superweaponPosition.x = 0.7f;
10051039
m_superweaponPosition.y = 0.7f;
10061040
m_superweaponFlashDuration = 1.0f;
@@ -1082,6 +1116,9 @@ InGameUI::~InGameUI()
10821116
// delete the message resources
10831117
freeMessageResources();
10841118

1119+
// free custom ui strings
1120+
freeCustomUiResources();
1121+
10851122
// delete the array for the drawbles
10861123
delete [] m_placeIcon;
10871124
m_placeIcon = NULL;
@@ -1924,6 +1961,9 @@ void InGameUI::reset( void )
19241961
// free any message resources allocated
19251962
freeMessageResources();
19261963

1964+
// free custom ui strings
1965+
freeCustomUiResources();
1966+
19271967
Int i;
19281968
for (i=0; i<MAX_PLAYER_COUNT; ++i)
19291969
{
@@ -2009,6 +2049,19 @@ void InGameUI::freeMessageResources( void )
20092049

20102050
} // end freeMessageResources
20112051

2052+
void InGameUI::freeCustomUiResources( void )
2053+
{
2054+
2055+
// release system time and simulation timer strings then set them to empty
2056+
TheDisplayStringManager->freeDisplayString(m_systemTimeString);
2057+
m_systemTimeString = NULL;
2058+
TheDisplayStringManager->freeDisplayString(m_simulationTimerString);
2059+
m_simulationTimerString = NULL;
2060+
TheDisplayStringManager->freeDisplayString(m_simulationTimerFrameString);
2061+
m_simulationTimerFrameString = NULL;
2062+
2063+
} // end freeCustomUiResources
2064+
20122065
//-------------------------------------------------------------------------------------------------
20132066
/** Same as the unicode message method, but this takes an ascii string which is assumed
20142067
* to me a string manager label */
@@ -3465,6 +3518,67 @@ void InGameUI::disregardDrawable( Drawable *draw )
34653518
void InGameUI::postDraw( void )
34663519
{
34673520

3521+
// TheSuperHackers @info render the system time and simulation timer first, this way other text will render over them if they overlap
3522+
// draw the current system time
3523+
if (TheGlobalData->m_showSystemTime && !TheGameLogic->isInShellGame())
3524+
{
3525+
if (!m_systemTimeString) {
3526+
m_systemTimeString = TheDisplayStringManager->newDisplayString();
3527+
}
3528+
3529+
// current system time
3530+
SYSTEMTIME systemTime;
3531+
GetLocalTime( &systemTime );
3532+
3533+
UnicodeString TimeString;
3534+
TimeString.format(L"%2.2d:%2.2d:%2.2d", systemTime.wHour, systemTime.wMinute, systemTime.wSecond);
3535+
m_systemTimeString->setFont(TheWindowManager->winFindFont( m_systemTimeFont,
3536+
TheGlobalLanguageData->adjustFontSize(m_systemTimePointSize), m_systemTimeBold ));
3537+
m_systemTimeString->setText(TimeString);
3538+
3539+
m_systemTimeString->draw(m_systemTimePosition.x, m_systemTimePosition.y, m_systemTimeColor, m_systemTimeDropColor);
3540+
}
3541+
3542+
// draw the simulation timer
3543+
if (TheGlobalData->m_showSimulationTimer && !TheGameLogic->isInShellGame())
3544+
{
3545+
if (!m_simulationTimerString) {
3546+
m_simulationTimerString = TheDisplayStringManager->newDisplayString();
3547+
}
3548+
3549+
if (!m_simulationTimerFrameString) {
3550+
m_simulationTimerFrameString = TheDisplayStringManager->newDisplayString();
3551+
}
3552+
3553+
Int currentFrame = TheGameLogic->getFrame();
3554+
Int currentSimulationTime = (Int) (SECONDS_PER_LOGICFRAME_REAL * currentFrame );
3555+
Int hours = currentSimulationTime / 3600;
3556+
Int minutes = (currentSimulationTime / 60) - (hours * 60);
3557+
Int seconds = currentSimulationTime - (minutes * 60) - (hours * 3600);
3558+
Int frame = currentFrame % 30;
3559+
3560+
// Handle the simulation time string
3561+
UnicodeString simulationTimeString;
3562+
simulationTimeString.format(L"%2.2d:%2.2d:%2.2d", hours, minutes, seconds);
3563+
m_simulationTimerString->setFont(TheWindowManager->winFindFont( m_simulationTimerFont,
3564+
TheGlobalLanguageData->adjustFontSize(m_simulationTimerPointSize), m_simulationTimerBold ));
3565+
m_simulationTimerString->setText(simulationTimeString);
3566+
3567+
// Handle the current frame string
3568+
UnicodeString simulationTimeFrameString;
3569+
simulationTimeFrameString.format(L".%2.2d", frame);
3570+
m_simulationTimerFrameString->setFont(TheWindowManager->winFindFont( m_simulationTimerFont,
3571+
TheGlobalLanguageData->adjustFontSize(m_simulationTimerPointSize), m_simulationTimerBold ));
3572+
m_simulationTimerFrameString->setText(simulationTimeFrameString);
3573+
3574+
// TheSuperHackers @info this implicitly offsets the simulation timer from the right instead of left of the screen
3575+
int horizontalTimerOffset = TheDisplay->getWidth() - (Int)m_simulationTimerPosition.x - m_simulationTimerString->getWidth() - m_simulationTimerFrameString->getWidth();
3576+
int horizontalFrameOffset = TheDisplay->getWidth() - (Int)m_simulationTimerPosition.x - m_simulationTimerFrameString->getWidth();
3577+
3578+
m_simulationTimerString->draw(horizontalTimerOffset, m_simulationTimerPosition.y, m_simulationTimerColor, m_simulationTimerDropColor);
3579+
m_simulationTimerFrameString->draw(horizontalFrameOffset, m_simulationTimerPosition.y, GameMakeColor(180,180,180,255), m_simulationTimerDropColor);
3580+
}
3581+
34683582
// render our display strings for the messages if on
34693583
if( m_messagesOn )
34703584
{

0 commit comments

Comments
 (0)