-
Notifications
You must be signed in to change notification settings - Fork 79
[ZH] Implement the system time and simulation timer within InGameUI #1170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -876,6 +876,19 @@ const FieldParse InGameUI::s_fieldParseTable[] = | |
{ "ClearMinesRadiusCursor", RadiusDecalTemplate::parseRadiusDecalTemplate, NULL, offsetof( InGameUI, m_radiusCursors[ RADIUSCURSOR_CLEARMINES] ) }, | ||
{ "AmbulanceRadiusCursor", RadiusDecalTemplate::parseRadiusDecalTemplate, NULL, offsetof( InGameUI, m_radiusCursors[ RADIUSCURSOR_AMBULANCE] ) }, | ||
|
||
// TheSuperHackers @info ui enhancement configuration | ||
{ "SystemTimeFont", INI::parseAsciiString, NULL, offsetof( InGameUI, m_systemTimeFont ) }, | ||
{ "SystemTimeBold", INI::parseBool, NULL, offsetof( InGameUI, m_systemTimeBold ) }, | ||
{ "SystemTimePosition", INI::parseCoord2D, NULL, offsetof( InGameUI, m_systemTimePosition ) }, | ||
{ "SystemTimeColor", INI::parseColorInt, NULL, offsetof( InGameUI, m_systemTimeColor ) }, | ||
{ "SystemTimeDropColor", INI::parseColorInt, NULL, offsetof( InGameUI, m_systemTimeDropColor ) }, | ||
|
||
{ "GameTimeFont", INI::parseAsciiString, NULL, offsetof( InGameUI, m_gameTimeFont ) }, | ||
{ "GameTimeBold", INI::parseBool, NULL, offsetof( InGameUI, m_gameTimeBold ) }, | ||
{ "GameTimePosition", INI::parseCoord2D, NULL, offsetof( InGameUI, m_gameTimePosition ) }, | ||
{ "GameTimeColor", INI::parseColorInt, NULL, offsetof( InGameUI, m_gameTimeColor ) }, | ||
{ "GameTimeDropColor", INI::parseColorInt, NULL, offsetof( InGameUI, m_gameTimeDropColor ) }, | ||
|
||
{ NULL, NULL, NULL, 0 } // keep this last | ||
}; | ||
|
||
|
@@ -1001,6 +1014,25 @@ InGameUI::InGameUI() | |
m_replayWindow = NULL; | ||
m_messagesOn = TRUE; | ||
|
||
m_systemTimeString = NULL; | ||
m_systemTimeFont = "Tahoma"; | ||
m_systemTimePointSize = TheGlobalData->m_systemTimeFontSize; | ||
m_systemTimeBold = TRUE; | ||
m_systemTimePosition.x = 3; // TheSuperHackers @info relative to the left of the screen | ||
m_systemTimePosition.y = -1; | ||
m_systemTimeColor = GameMakeColor( 255, 255, 255, 255 ); | ||
m_systemTimeDropColor = GameMakeColor( 0, 0, 0, 255 ); | ||
|
||
m_gameTimeString = NULL; | ||
m_gameTimeFrameString = NULL; | ||
m_gameTimeFont = "Tahoma"; | ||
m_gameTimePointSize = TheGlobalData->m_gameTimeFontSize; | ||
m_gameTimeBold = TRUE; | ||
m_gameTimePosition.x = 3; // TheSuperHackers @info relative to the right of the screen | ||
m_gameTimePosition.y = -1; | ||
m_gameTimeColor = GameMakeColor( 255, 255, 255, 255 ); | ||
m_gameTimeDropColor = GameMakeColor( 0, 0, 0, 255 ); | ||
|
||
m_superweaponPosition.x = 0.7f; | ||
m_superweaponPosition.y = 0.7f; | ||
m_superweaponFlashDuration = 1.0f; | ||
|
@@ -1082,6 +1114,9 @@ InGameUI::~InGameUI() | |
// delete the message resources | ||
freeMessageResources(); | ||
|
||
// free custom ui strings | ||
freeCustomUiResources(); | ||
|
||
// delete the array for the drawbles | ||
delete [] m_placeIcon; | ||
m_placeIcon = NULL; | ||
|
@@ -1924,6 +1959,9 @@ void InGameUI::reset( void ) | |
// free any message resources allocated | ||
freeMessageResources(); | ||
|
||
// free custom ui strings | ||
freeCustomUiResources(); | ||
|
||
Int i; | ||
for (i=0; i<MAX_PLAYER_COUNT; ++i) | ||
{ | ||
|
@@ -2009,6 +2047,16 @@ void InGameUI::freeMessageResources( void ) | |
|
||
} // end freeMessageResources | ||
|
||
void InGameUI::freeCustomUiResources( void ) | ||
{ | ||
TheDisplayStringManager->freeDisplayString(m_systemTimeString); | ||
m_systemTimeString = NULL; | ||
TheDisplayStringManager->freeDisplayString(m_gameTimeString); | ||
m_gameTimeString = NULL; | ||
TheDisplayStringManager->freeDisplayString(m_gameTimeFrameString); | ||
m_gameTimeFrameString = NULL; | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------- | ||
/** Same as the unicode message method, but this takes an ascii string which is assumed | ||
* to me a string manager label */ | ||
|
@@ -3459,6 +3507,22 @@ void InGameUI::disregardDrawable( Drawable *draw ) | |
|
||
} | ||
|
||
//------------------------------------------------------------------------------------------------- | ||
/** This is called after the WindowManager has drawn the menus. */ | ||
//------------------------------------------------------------------------------------------------- | ||
void InGameUI::postWindowDraw( void ) | ||
{ | ||
if (m_systemTimePointSize > 0) | ||
{ | ||
drawSystemTime(); | ||
} | ||
|
||
if ( (m_gameTimePointSize > 0) && !TheGameLogic->isInShellGame() && TheGameLogic->isInGame() ) | ||
{ | ||
drawGameTime(); | ||
} | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------- | ||
/** This is called after the UI has been drawn. */ | ||
//------------------------------------------------------------------------------------------------- | ||
|
@@ -5718,4 +5782,59 @@ WindowMsgHandledType IdleWorkerSystem( GameWindow *window, UnsignedInt msg, | |
|
||
} | ||
|
||
void InGameUI::drawSystemTime() | ||
{ | ||
if (!m_systemTimeString) { | ||
m_systemTimeString = TheDisplayStringManager->newDisplayString(); | ||
} | ||
|
||
// current system time | ||
SYSTEMTIME systemTime; | ||
GetLocalTime( &systemTime ); | ||
|
||
UnicodeString TimeString; | ||
TimeString.format(L"%2.2d:%2.2d:%2.2d", systemTime.wHour, systemTime.wMinute, systemTime.wSecond); | ||
Int adjustedSystemTimeFontSize = TheGlobalLanguageData->adjustFontSize(m_systemTimePointSize); | ||
GameFont* systemTimeFont = TheWindowManager->winFindFont(m_systemTimeFont, adjustedSystemTimeFontSize, m_systemTimeBold); | ||
m_systemTimeString->setFont(systemTimeFont); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This setup is done every frame. This can be optimized by moving display string creation and setup to the constructor or init function. Can create a pair to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we want people to be able to change the font size dynamically from the options menu then it will need to be setup every frame. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The settings in the Options Menu are applied when pressing ACCEPT, which calls a function. In this function we will then be able to call freeCustomUiResources();
createCustomUiResources(); or refreshCustomUiResources(); to rescale the texts. This would then also need to be done after the Display Resolution has changed. |
||
m_systemTimeString->setText(TimeString); | ||
|
||
m_systemTimeString->draw(m_systemTimePosition.x, m_systemTimePosition.y, m_systemTimeColor, m_systemTimeDropColor); | ||
} | ||
|
||
void InGameUI::drawGameTime() | ||
{ | ||
if (!m_gameTimeString) { | ||
m_gameTimeString = TheDisplayStringManager->newDisplayString(); | ||
} | ||
|
||
if (!m_gameTimeFrameString) { | ||
m_gameTimeFrameString = TheDisplayStringManager->newDisplayString(); | ||
} | ||
|
||
Int currentFrame = TheGameLogic->getFrame(); | ||
Int gameSeconds = (Int) (SECONDS_PER_LOGICFRAME_REAL * currentFrame ); | ||
Int hours = gameSeconds / 60 / 60; | ||
Int minutes = (gameSeconds / 60) % 60; | ||
Int seconds = gameSeconds % 60; | ||
Int frame = currentFrame % 30; | ||
|
||
UnicodeString gameTimeString; | ||
gameTimeString.format(L"%2.2d:%2.2d:%2.2d", hours, minutes, seconds); | ||
Int adjustedGameTimeFontSize = TheGlobalLanguageData->adjustFontSize(m_gameTimePointSize); | ||
GameFont* gameTimeFont = TheWindowManager->winFindFont(m_gameTimeFont, adjustedGameTimeFontSize, m_gameTimeBold); | ||
m_gameTimeString->setFont(gameTimeFont); | ||
m_gameTimeString->setText(gameTimeString); | ||
|
||
UnicodeString gameTimeFrameString; | ||
gameTimeFrameString.format(L".%2.2d", frame); | ||
m_gameTimeFrameString->setFont(gameTimeFont); | ||
m_gameTimeFrameString->setText(gameTimeFrameString); | ||
|
||
// TheSuperHackers @info this implicitly offsets the game timer from the right instead of left of the screen | ||
int horizontalTimerOffset = TheDisplay->getWidth() - (Int)m_gameTimePosition.x - m_gameTimeString->getWidth() - m_gameTimeFrameString->getWidth(); | ||
int horizontalFrameOffset = TheDisplay->getWidth() - (Int)m_gameTimePosition.x - m_gameTimeFrameString->getWidth(); | ||
|
||
m_gameTimeString->draw(horizontalTimerOffset, m_gameTimePosition.y, m_gameTimeColor, m_gameTimeDropColor); | ||
m_gameTimeFrameString->draw(horizontalFrameOffset, m_gameTimePosition.y, GameMakeColor(180,180,180,255), m_gameTimeDropColor); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.