Skip to content

Commit 1d5d9d3

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

File tree

7 files changed

+228
-0
lines changed

7 files changed

+228
-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: 28 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,12 @@ 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+
587+
void refreshSystemTimeResources();
588+
void refreshGameTimeResources();
589+
581590
public:
582591
void registerWindowLayout(WindowLayout *layout); // register a layout for updates
583592
void unregisterWindowLayout(WindowLayout *layout); // stop updates for this layout
@@ -741,6 +750,25 @@ friend class Drawable; // for selection/deselection transactions
741750
VideoBuffer* m_cameoVideoBuffer;///< video playback buffer
742751
VideoStreamInterface* m_cameoVideoStream;///< Video stream;
743752

753+
// System Time
754+
DisplayString * m_systemTimeString;
755+
AsciiString m_systemTimeFont;
756+
Int m_systemTimePointSize;
757+
Bool m_systemTimeBold;
758+
Coord2D m_systemTimePosition;
759+
Color m_systemTimeColor;
760+
Color m_systemTimeDropColor;
761+
762+
// Game Time
763+
DisplayString * m_gameTimeString;
764+
DisplayString * m_gameTimeFrameString;
765+
AsciiString m_gameTimeFont;
766+
Int m_gameTimePointSize;
767+
Bool m_gameTimeBold;
768+
Coord2D m_gameTimePosition;
769+
Color m_gameTimeColor;
770+
Color m_gameTimeDropColor;
771+
744772
// message data
745773
UIMessage m_uiMessages[ MAX_UI_MESSAGES ];/**< messages to display to the user, the
746774
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/InGameUI.cpp

Lines changed: 135 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+
// refresh custom ui strings - this will create the strings if required and update the fonts
1958+
refreshCustomUiResources();
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,41 @@ void InGameUI::recreateControlBar( void )
56595723

56605724
}
56615725

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

57145813
}
57155814

5815+
void InGameUI::drawSystemTime()
5816+
{
5817+
// current system time
5818+
SYSTEMTIME systemTime;
5819+
GetLocalTime( &systemTime );
5820+
5821+
UnicodeString TimeString;
5822+
TimeString.format(L"%2.2d:%2.2d:%2.2d", systemTime.wHour, systemTime.wMinute, systemTime.wSecond);
5823+
m_systemTimeString->setText(TimeString);
5824+
5825+
m_systemTimeString->draw(m_systemTimePosition.x, m_systemTimePosition.y, m_systemTimeColor, m_systemTimeDropColor);
5826+
}
5827+
5828+
void InGameUI::drawGameTime()
5829+
{
5830+
Int currentFrame = TheGameLogic->getFrame();
5831+
Int gameSeconds = (Int) (SECONDS_PER_LOGICFRAME_REAL * currentFrame );
5832+
Int hours = gameSeconds / 60 / 60;
5833+
Int minutes = (gameSeconds / 60) % 60;
5834+
Int seconds = gameSeconds % 60;
5835+
Int frame = currentFrame % 30;
5836+
5837+
UnicodeString gameTimeString;
5838+
gameTimeString.format(L"%2.2d:%2.2d:%2.2d", hours, minutes, seconds);
5839+
m_gameTimeString->setText(gameTimeString);
5840+
5841+
UnicodeString gameTimeFrameString;
5842+
gameTimeFrameString.format(L".%2.2d", frame);
5843+
m_gameTimeFrameString->setText(gameTimeFrameString);
57165844

5845+
// TheSuperHackers @info this implicitly offsets the game timer from the right instead of left of the screen
5846+
int horizontalTimerOffset = TheDisplay->getWidth() - (Int)m_gameTimePosition.x - m_gameTimeString->getWidth() - m_gameTimeFrameString->getWidth();
5847+
int horizontalFrameOffset = TheDisplay->getWidth() - (Int)m_gameTimePosition.x - m_gameTimeFrameString->getWidth();
5848+
5849+
m_gameTimeString->draw(horizontalTimerOffset, m_gameTimePosition.y, m_gameTimeColor, m_gameTimeDropColor);
5850+
m_gameTimeFrameString->draw(horizontalFrameOffset, m_gameTimePosition.y, GameMakeColor(180,180,180,255), m_gameTimeDropColor);
5851+
}

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)