GlobalLanguage.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: GlobalLanguage.cpp /////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Electronic Arts Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2002 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // created: Aug 2002
  34. //
  35. // Filename: GlobalLanguage.cpp
  36. //
  37. // author: Chris Huybregts
  38. //
  39. // purpose: Contains the member functions for the language munkee
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. //-----------------------------------------------------------------------------
  44. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  45. //-----------------------------------------------------------------------------
  46. //-----------------------------------------------------------------------------
  47. // USER INCLUDES //////////////////////////////////////////////////////////////
  48. //-----------------------------------------------------------------------------
  49. #include "PreRTS.h"
  50. #include "Common/INI.h"
  51. #include "Common/Registry.h"
  52. #include "GameClient/GlobalLanguage.h"
  53. #include "Common/Filesystem.h"
  54. //-----------------------------------------------------------------------------
  55. // DEFINES ////////////////////////////////////////////////////////////////////
  56. //-----------------------------------------------------------------------------
  57. GlobalLanguage *TheGlobalLanguageData = NULL; ///< The global language singalton
  58. static const FieldParse TheGlobalLanguageDataFieldParseTable[] =
  59. {
  60. { "UnicodeFontName", INI::parseAsciiString,NULL, offsetof( GlobalLanguage, m_unicodeFontName ) },
  61. //{ "UnicodeFontFileName", INI::parseAsciiString,NULL, offsetof( GlobalLanguage, m_unicodeFontFileName ) },
  62. { "LocalFontFile", GlobalLanguage::parseFontFileName, NULL, 0},
  63. { "MilitaryCaptionSpeed", INI::parseInt, NULL, offsetof( GlobalLanguage, m_militaryCaptionSpeed ) },
  64. { "UseHardWordWrap", INI::parseBool, NULL, offsetof( GlobalLanguage, m_useHardWrap) },
  65. { "ResolutionFontAdjustment", INI::parseReal, NULL, offsetof( GlobalLanguage, m_resolutionFontSizeAdjustment) },
  66. { "CopyrightFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_copyrightFont ) },
  67. { "MessageFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_messageFont) },
  68. { "MilitaryCaptionTitleFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_militaryCaptionTitleFont) },
  69. { "MilitaryCaptionDelayMS", INI::parseInt, NULL, offsetof( GlobalLanguage, m_militaryCaptionDelayMS ) },
  70. { "MilitaryCaptionFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_militaryCaptionFont) },
  71. { "SuperweaponCountdownNormalFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_superweaponCountdownNormalFont) },
  72. { "SuperweaponCountdownReadyFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_superweaponCountdownReadyFont) },
  73. { "NamedTimerCountdownNormalFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_namedTimerCountdownNormalFont) },
  74. { "NamedTimerCountdownReadyFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_namedTimerCountdownReadyFont) },
  75. { "DrawableCaptionFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_drawableCaptionFont) },
  76. { "DefaultWindowFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_defaultWindowFont) },
  77. { "DefaultDisplayStringFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_defaultDisplayStringFont) },
  78. { "TooltipFontName", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_tooltipFontName) },
  79. { "NativeDebugDisplay", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_nativeDebugDisplay) },
  80. { "DrawGroupInfoFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_drawGroupInfoFont) },
  81. { "CreditsTitleFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_creditsTitleFont) },
  82. { "CreditsMinorTitleFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_creditsPositionFont) },
  83. { "CreditsNormalFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_creditsNormalFont) },
  84. { NULL, NULL, NULL, 0 } // keep this last
  85. };
  86. //-----------------------------------------------------------------------------
  87. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  88. //-----------------------------------------------------------------------------
  89. void INI::parseLanguageDefinition( INI *ini )
  90. {
  91. if( !TheGlobalLanguageData )
  92. {
  93. DEBUG_ASSERTCRASH(TheGlobalLanguageData, ("INI::parseLanguageDefinition - TheGlobalLanguage Data is not around, please create it before trying to parse the ini file."));
  94. return;
  95. } // end if
  96. // parse the ini weapon definition
  97. ini->initFromINI( TheGlobalLanguageData, TheGlobalLanguageDataFieldParseTable );
  98. }
  99. GlobalLanguage::GlobalLanguage()
  100. {
  101. m_unicodeFontName.clear();
  102. //Added By Sadullah Nader
  103. //Initializations missing and needed
  104. m_unicodeFontFileName.clear();
  105. m_unicodeFontName.clear();
  106. m_militaryCaptionSpeed = 0;
  107. m_useHardWrap = FALSE;
  108. m_resolutionFontSizeAdjustment = 0.7f;
  109. m_militaryCaptionDelayMS = 750;
  110. //End Add
  111. }
  112. GlobalLanguage::~GlobalLanguage()
  113. {
  114. StringListIt it = m_localFonts.begin();
  115. while( it != m_localFonts.end())
  116. {
  117. AsciiString font = *it;
  118. RemoveFontResource(font.str());
  119. //SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
  120. ++it;
  121. }
  122. }
  123. void GlobalLanguage::init( void )
  124. {
  125. INI ini;
  126. AsciiString fname;
  127. fname.format("Data\\%s\\Language.ini", GetRegistryLanguage().str());
  128. OSVERSIONINFO osvi;
  129. osvi.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
  130. //GS NOTE: Must call doesFileExist in either case so that NameKeyGenerator will stay in sync
  131. AsciiString tempName;
  132. tempName.format("Data\\%s\\Language9x.ini", GetRegistryLanguage().str());
  133. bool isExist = TheFileSystem->doesFileExist(tempName.str());
  134. if (GetVersionEx(&osvi) && osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && isExist)
  135. { //check if we're running Win9x variant since they may need different fonts
  136. fname = tempName;
  137. }
  138. ini.load( fname, INI_LOAD_OVERWRITE, NULL );
  139. StringListIt it = m_localFonts.begin();
  140. while( it != m_localFonts.end())
  141. {
  142. AsciiString font = *it;
  143. if(AddFontResource(font.str()) == 0)
  144. {
  145. DEBUG_ASSERTCRASH(FALSE,("GlobalLanguage::init Failed to add font %s", font.str()));
  146. }
  147. else
  148. {
  149. //SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
  150. }
  151. ++it;
  152. }
  153. }
  154. void GlobalLanguage::reset( void ) {}
  155. void GlobalLanguage::parseFontDesc(INI *ini, void *instance, void *store, const void* userData)
  156. {
  157. FontDesc *fontDesc = (FontDesc *)store;
  158. fontDesc->name = ini->getNextQuotedAsciiString();
  159. fontDesc->size = ini->scanInt(ini->getNextToken());
  160. fontDesc->bold = ini->scanBool(ini->getNextToken());
  161. }
  162. void GlobalLanguage::parseFontFileName( INI *ini, void * instance, void *store, const void* userData )
  163. {
  164. GlobalLanguage *monkey = (GlobalLanguage *)instance;
  165. AsciiString asciiString = ini->getNextAsciiString();
  166. monkey->m_localFonts.push_front(asciiString);
  167. }
  168. Int GlobalLanguage::adjustFontSize(Int theFontSize)
  169. {
  170. Real adjustFactor = TheGlobalData->m_xResolution/800.0f;
  171. adjustFactor = 1.0f + (adjustFactor-1.0f) * m_resolutionFontSizeAdjustment;
  172. if (adjustFactor<1.0f) adjustFactor = 1.0f;
  173. if (adjustFactor>2.0f) adjustFactor = 2.0f;
  174. Int pointSize = REAL_TO_INT_FLOOR(theFontSize*adjustFactor);
  175. return pointSize;
  176. }
  177. FontDesc::FontDesc(void)
  178. {
  179. name = "Arial Unicode MS"; ///<name of font
  180. size = 12; ///<point size
  181. bold = FALSE; ///<is bold?
  182. }
  183. //-----------------------------------------------------------------------------
  184. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  185. //-----------------------------------------------------------------------------