Skip to content

Commit 3f38b20

Browse files
committed
[GEN][ZH] Add localization labels to ui messages for debug commands (#1258)
1 parent 18d8a82 commit 3f38b20

File tree

10 files changed

+451
-127
lines changed

10 files changed

+451
-127
lines changed

Generals/Code/GameEngine/Include/GameClient/GameText.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,29 @@ class GameTextInterface : public SubsystemInterface
7777
virtual ~GameTextInterface() {};
7878

7979
virtual UnicodeString fetch( const Char *label, Bool *exists = NULL ) = 0; ///< Returns the associated labeled unicode text
80-
virtual UnicodeString fetch( AsciiString label, Bool *exists = NULL ) = 0; ///< Returns the associated labeled unicode text
80+
virtual UnicodeString fetch( AsciiString label, Bool *exists = NULL ) = 0; ///< Returns the associated labeled unicode text ; TheSuperHackers @todo Remove
81+
virtual UnicodeString fetchFormat( const Char *label, ... ) = 0;
8182

8283
// Do not call this directly, but use the FETCH_OR_SUBSTITUTE macro
8384
virtual UnicodeString fetchOrSubstitute( const Char *label, const WideChar *substituteText ) = 0;
85+
virtual UnicodeString fetchOrSubstituteFormat( const Char *label, const WideChar *substituteFormat, ... ) = 0;
86+
virtual UnicodeString fetchOrSubstituteFormatVA( const Char *label, const WideChar *substituteFormat, va_list args ) = 0;
8487

8588
// This function is not performance tuned.. Its really only for Worldbuilder. jkmcd
8689
virtual AsciiStringVec& getStringsWithLabelPrefix(AsciiString label) = 0;
8790

8891
virtual void initMapStringFile( const AsciiString& filename ) = 0;
92+
93+
#if __cplusplus < 201103L // TheSuperHackers @todo Remove function when abandoning VC6
94+
inline UnicodeString FETCH_OR_SUBSTITUTE_FORMAT( const Char *label, const WideChar *substituteFormat, ... )
95+
{
96+
va_list args;
97+
va_start(args, substituteFormat);
98+
UnicodeString str = fetchOrSubstituteFormatVA(label, substituteFormat, args);
99+
va_end(args);
100+
return str;
101+
}
102+
#endif
89103
};
90104

91105

@@ -98,12 +112,22 @@ extern GameTextInterface* CreateGameTextInterface( void );
98112

99113
// TheSuperHackers @info This is meant to be used like:
100114
// TheGameText->FETCH_OR_SUBSTITUTE("GUI:LabelName", L"Substitute Fallback Text")
115+
// TheGameText->FETCH_OR_SUBSTITUTE_FORMAT("GUI:LabelName", L"Substitute Fallback Text %d %d", 1, 2)
101116
// The substitute text will be compiled out if ENABLE_GAMETEXT_SUBSTITUTES is not defined.
102117
#if ENABLE_GAMETEXT_SUBSTITUTES
118+
103119
#define FETCH_OR_SUBSTITUTE(labelA, substituteTextW) fetchOrSubstitute(labelA, substituteTextW)
120+
#if __cplusplus >= 201103L // TheSuperHackers @todo Remove condition when abandoning VC6
121+
#define FETCH_OR_SUBSTITUTE_FORMAT(labelA, substituteFormatW, ...) fetchOrSubstituteFormat(labelA, substituteFormatW, __VA_ARGS__)
122+
#endif
123+
104124
#else
125+
105126
#define FETCH_OR_SUBSTITUTE(labelA, substituteTextW) fetch(labelA)
127+
#if __cplusplus >= 201103L // TheSuperHackers @todo Remove condition when abandoning VC6
128+
#define FETCH_OR_SUBSTITUTE_FORMAT(labelA, substituteTextW, ...) fetchFormat(labelA, __VA_ARGS__)
106129
#endif
107130

131+
#endif // ENABLE_GAMETEXT_SUBSTITUTES
108132

109133
#endif // __GAMECLIENT_GAMETEXT_H_

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ friend class Drawable; // for selection/deselection transactions
362362
// interface for messages to the user
363363
// srj sez: passing as const-ref screws up varargs for some reason. dunno why. just pass by value.
364364
virtual void messageColor( const RGBColor *rgbColor, UnicodeString format, ... ); ///< display a colored message to the user
365+
virtual void messageNoFormat( const UnicodeString& message ); ///< display a message to the user
366+
virtual void messageNoFormat( const RGBColor *rgbColor, const UnicodeString& message ); ///< display a colored message to the user
365367
virtual void message( UnicodeString format, ... ); ///< display a message to the user
366368
virtual void message( AsciiString stringManagerLabel, ... );///< display a message to the user
367369
virtual void toggleMessages( void ) { m_messagesOn = 1 - m_messagesOn; } ///< toggle messages on/off

Generals/Code/GameEngine/Source/GameClient/GameText.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ class GameTextManager : public GameTextInterface
148148

149149
virtual UnicodeString fetch( const Char *label, Bool *exists = NULL ); ///< Returns the associated labeled unicode text
150150
virtual UnicodeString fetch( AsciiString label, Bool *exists = NULL ); ///< Returns the associated labeled unicode text
151+
virtual UnicodeString fetchFormat( const Char *label, ... );
151152
virtual UnicodeString fetchOrSubstitute( const Char *label, const WideChar *substituteText );
153+
virtual UnicodeString fetchOrSubstituteFormat( const Char *label, const WideChar *substituteFormat, ... );
154+
virtual UnicodeString fetchOrSubstituteFormatVA( const Char *label, const WideChar *substituteFormat, va_list args );
152155

153156
virtual AsciiStringVec& getStringsWithLabelPrefix(AsciiString label);
154157

@@ -1354,6 +1357,28 @@ UnicodeString GameTextManager::fetch( AsciiString label, Bool *exists )
13541357
return fetch(label.str(), exists);
13551358
}
13561359

1360+
//============================================================================
1361+
// *GameTextManager::fetchFormat
1362+
//============================================================================
1363+
1364+
UnicodeString GameTextManager::fetchFormat( const Char *label, ... )
1365+
{
1366+
Bool exists;
1367+
UnicodeString str = fetch(label, &exists);
1368+
if (exists)
1369+
{
1370+
UnicodeString strFormat;
1371+
1372+
va_list args;
1373+
va_start(args, label);
1374+
strFormat.format_va(str.str(), args);
1375+
va_end(args);
1376+
1377+
str = strFormat;
1378+
}
1379+
return str;
1380+
}
1381+
13571382
//============================================================================
13581383
// GameTextManager::fetchOrSubstitute
13591384
//============================================================================
@@ -1367,6 +1392,42 @@ UnicodeString GameTextManager::fetchOrSubstitute( const Char *label, const WideC
13671392
return str;
13681393
}
13691394

1395+
//============================================================================
1396+
// GameTextManager::fetchOrSubstituteFormat
1397+
//============================================================================
1398+
1399+
UnicodeString GameTextManager::fetchOrSubstituteFormat( const Char *label, const WideChar *substituteFormat, ... )
1400+
{
1401+
va_list args;
1402+
va_start(args, substituteFormat);
1403+
UnicodeString str = fetchOrSubstituteFormatVA(label, substituteFormat, args);
1404+
va_end(args);
1405+
1406+
return str;
1407+
}
1408+
1409+
//============================================================================
1410+
// GameTextManager::fetchOrSubstituteFormatVA
1411+
//============================================================================
1412+
1413+
UnicodeString GameTextManager::fetchOrSubstituteFormatVA( const Char *label, const WideChar *substituteFormat, va_list args )
1414+
{
1415+
Bool exists;
1416+
UnicodeString str = fetch(label, &exists);
1417+
if (exists)
1418+
{
1419+
UnicodeString strFormat;
1420+
strFormat.format_va(strFormat.str(), args);
1421+
str = strFormat;
1422+
}
1423+
else
1424+
{
1425+
str.format_va(substituteFormat, args);
1426+
}
1427+
1428+
return str;
1429+
}
1430+
13701431
//============================================================================
13711432
// GameTextManager::getStringsWithLabelPrefix
13721433
//============================================================================

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,20 @@ void InGameUI::message( AsciiString stringManagerLabel, ... )
20292029
}
20302030
} // end
20312031

2032+
//-------------------------------------------------------------------------------------------------
2033+
//-------------------------------------------------------------------------------------------------
2034+
void InGameUI::messageNoFormat( const UnicodeString& message )
2035+
{
2036+
addMessageText( message, NULL );
2037+
}
2038+
2039+
//-------------------------------------------------------------------------------------------------
2040+
//-------------------------------------------------------------------------------------------------
2041+
void InGameUI::messageNoFormat( const RGBColor *rgbColor, const UnicodeString& message )
2042+
{
2043+
addMessageText( message, rgbColor );
2044+
}
2045+
20322046
//-------------------------------------------------------------------------------------------------
20332047
/** Interface for display text messages to the user */
20342048
//-------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)