GlobalLanguage.cpp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. ** Command & Conquer Generals(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. { "MilitaryCaptionFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_militaryCaptionFont) },
  70. { "SuperweaponCountdownNormalFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_superweaponCountdownNormalFont) },
  71. { "SuperweaponCountdownReadyFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_superweaponCountdownReadyFont) },
  72. { "NamedTimerCountdownNormalFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_namedTimerCountdownNormalFont) },
  73. { "NamedTimerCountdownReadyFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_namedTimerCountdownReadyFont) },
  74. { "DrawableCaptionFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_drawableCaptionFont) },
  75. { "DefaultWindowFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_defaultWindowFont) },
  76. { "DefaultDisplayStringFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_defaultDisplayStringFont) },
  77. { "TooltipFontName", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_tooltipFontName) },
  78. { "NativeDebugDisplay", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_nativeDebugDisplay) },
  79. { "DrawGroupInfoFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_drawGroupInfoFont) },
  80. { "CreditsTitleFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_creditsTitleFont) },
  81. { "CreditsMinorTitleFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_creditsPositionFont) },
  82. { "CreditsNormalFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_creditsNormalFont) },
  83. { NULL, NULL, NULL, 0 } // keep this last
  84. };
  85. //-----------------------------------------------------------------------------
  86. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  87. //-----------------------------------------------------------------------------
  88. void INI::parseLanguageDefinition( INI *ini )
  89. {
  90. if( !TheGlobalLanguageData )
  91. {
  92. DEBUG_ASSERTCRASH(TheGlobalLanguageData, ("INI::parseLanguageDefinition - TheGlobalLanguage Data is not around, please create it before trying to parse the ini file."));
  93. return;
  94. } // end if
  95. // parse the ini weapon definition
  96. ini->initFromINI( TheGlobalLanguageData, TheGlobalLanguageDataFieldParseTable );
  97. }
  98. GlobalLanguage::GlobalLanguage()
  99. {
  100. m_unicodeFontName.clear();
  101. //Added By Sadullah Nader
  102. //Initializations missing and needed
  103. m_unicodeFontFileName.clear();
  104. m_unicodeFontName.clear();
  105. m_militaryCaptionSpeed = 0;
  106. m_useHardWrap = FALSE;
  107. m_resolutionFontSizeAdjustment = 0.7f;
  108. //End Add
  109. }
  110. GlobalLanguage::~GlobalLanguage()
  111. {
  112. StringListIt it = m_localFonts.begin();
  113. while( it != m_localFonts.end())
  114. {
  115. AsciiString font = *it;
  116. RemoveFontResource(font.str());
  117. //SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
  118. ++it;
  119. }
  120. }
  121. void GlobalLanguage::init( void )
  122. {
  123. INI ini;
  124. AsciiString fname;
  125. fname.format("Data\\%s\\Language.ini", GetRegistryLanguage().str());
  126. OSVERSIONINFO osvi;
  127. osvi.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
  128. //GS NOTE: Must call doesFileExist in either case so that NameKeyGenerator will stay in sync
  129. AsciiString tempName;
  130. tempName.format("Data\\%s\\Language9x.ini", GetRegistryLanguage().str());
  131. bool isExist = TheFileSystem->doesFileExist(tempName.str());
  132. if (GetVersionEx(&osvi) && osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && isExist)
  133. { //check if we're running Win9x variant since they may need different fonts
  134. fname = tempName;
  135. }
  136. ini.load( fname, INI_LOAD_OVERWRITE, NULL );
  137. StringListIt it = m_localFonts.begin();
  138. while( it != m_localFonts.end())
  139. {
  140. AsciiString font = *it;
  141. if(AddFontResource(font.str()) == 0)
  142. {
  143. DEBUG_ASSERTCRASH(FALSE,("GlobalLanguage::init Failed to add font %s", font.str()));
  144. }
  145. else
  146. {
  147. //SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
  148. }
  149. ++it;
  150. }
  151. }
  152. void GlobalLanguage::reset( void ) {}
  153. void GlobalLanguage::parseFontDesc(INI *ini, void *instance, void *store, const void* userData)
  154. {
  155. FontDesc *fontDesc = (FontDesc *)store;
  156. fontDesc->name = ini->getNextQuotedAsciiString();
  157. fontDesc->size = ini->scanInt(ini->getNextToken());
  158. fontDesc->bold = ini->scanBool(ini->getNextToken());
  159. }
  160. void GlobalLanguage::parseFontFileName( INI *ini, void * instance, void *store, const void* userData )
  161. {
  162. GlobalLanguage *monkey = (GlobalLanguage *)instance;
  163. AsciiString asciiString = ini->getNextAsciiString();
  164. monkey->m_localFonts.push_front(asciiString);
  165. }
  166. Int GlobalLanguage::adjustFontSize(Int theFontSize)
  167. {
  168. Real adjustFactor = TheGlobalData->m_xResolution/800.0f;
  169. adjustFactor = 1.0f + (adjustFactor-1.0f) * m_resolutionFontSizeAdjustment;
  170. if (adjustFactor<1.0f) adjustFactor = 1.0f;
  171. if (adjustFactor>2.0f) adjustFactor = 2.0f;
  172. Int pointSize = REAL_TO_INT_FLOOR(theFontSize*adjustFactor);
  173. return pointSize;
  174. }
  175. FontDesc::FontDesc(void)
  176. {
  177. name = "Arial Unicode MS"; ///<name of font
  178. size = 12; ///<point size
  179. bold = FALSE; ///<is bold?
  180. }
  181. //-----------------------------------------------------------------------------
  182. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  183. //-----------------------------------------------------------------------------