GameInfoWindow.cpp 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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: GameInfoWindow.cpp ////////////////////////////////////////////////////////////////////////
  24. // Author: Chris Huybregts, Feb 2002
  25. // Description: Game Info window callbacks
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "GameClient/WindowLayout.h"
  30. #include "GameClient/MapUtil.h"
  31. #include "GameClient/Shell.h"
  32. #include "GameClient/GameWindowManager.h"
  33. #include "GameClient/GadgetListBox.h"
  34. #include "GameClient/GadgetStaticText.h"
  35. #include "GameClient/GameText.h"
  36. #include "GameClient/GameInfoWindow.h"
  37. #include "Common/MultiplayerSettings.h"
  38. #include "Common/PlayerTemplate.h"
  39. #include "GameNetwork/GameInfo.h"
  40. #include "GameNetwork/LANAPI.h"
  41. #ifdef _INTERNAL
  42. // for occasional debugging...
  43. //#pragma optimize("", off)
  44. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  45. #endif
  46. static GameWindow *parent = NULL;
  47. static GameWindow *staticTextGameName = NULL;
  48. static GameWindow *staticTextMapName = NULL;
  49. static GameWindow *listBoxPlayers = NULL;
  50. static GameWindow *winCrates = NULL;
  51. static GameWindow *winSuperWeapons = NULL;
  52. static GameWindow *winFreeForAll = NULL;
  53. static NameKeyType parentID = NAMEKEY_INVALID;
  54. static NameKeyType staticTextGameNameID = NAMEKEY_INVALID;
  55. static NameKeyType staticTextMapNameID = NAMEKEY_INVALID;
  56. static NameKeyType listBoxPlayersID = NAMEKEY_INVALID;
  57. static NameKeyType winCratesID = NAMEKEY_INVALID;
  58. static NameKeyType winSuperWeaponsID = NAMEKEY_INVALID;
  59. static NameKeyType winFreeForAllID = NAMEKEY_INVALID;
  60. static WindowLayout *gameInfoWindowLayout = NULL;
  61. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////
  62. void CreateLANGameInfoWindow( GameWindow *sizeAndPosWin )
  63. {
  64. if( !gameInfoWindowLayout )
  65. gameInfoWindowLayout = TheWindowManager->winCreateLayout( AsciiString( "Menus/GameInfoWindow.wnd" ) );
  66. gameInfoWindowLayout->runInit();
  67. gameInfoWindowLayout->bringForward();
  68. gameInfoWindowLayout->hide( TRUE );
  69. if( !parent || !sizeAndPosWin )
  70. return;
  71. Int x, y, width, height;
  72. sizeAndPosWin->winGetScreenPosition(&x,&y);
  73. parent->winSetPosition(x,y);
  74. sizeAndPosWin->winGetSize( &width, &height );
  75. parent->winSetSize(width, height);
  76. }
  77. void DestroyGameInfoWindow(void)
  78. {
  79. if (gameInfoWindowLayout)
  80. {
  81. gameInfoWindowLayout->destroyWindows();
  82. gameInfoWindowLayout->deleteInstance();
  83. gameInfoWindowLayout = NULL;
  84. }
  85. }
  86. void RefreshGameInfoWindow(GameInfo *gameInfo, UnicodeString gameName)
  87. {
  88. static const Image *randomIcon = TheMappedImageCollection->findImageByName("GameinfoRANDOM");
  89. static const Image *observerIcon = TheMappedImageCollection->findImageByName("GameinfoOBSRVR");
  90. if(!gameInfoWindowLayout || !gameInfo )
  91. return;
  92. parent->winHide( FALSE );
  93. parent->winBringToTop();
  94. // Set the game name
  95. GadgetStaticTextSetText(staticTextGameName, ((LANGameInfo *)gameInfo)->getPlayerName(0));
  96. // set the map name
  97. UnicodeString map;
  98. AsciiString asciiMap = gameInfo->getMap();
  99. asciiMap.toLower();
  100. std::map<AsciiString, MapMetaData>::iterator it = TheMapCache->find(asciiMap);
  101. if (it != TheMapCache->end())
  102. {
  103. map = it->second.m_displayName;
  104. }
  105. else
  106. {
  107. // can happen if the map will have to be transferred... so use the leaf name (srj)
  108. const char *noPath = gameInfo->getMap().reverseFind('\\');
  109. if (noPath)
  110. {
  111. ++noPath;
  112. }
  113. else
  114. {
  115. noPath = gameInfo->getMap().str();
  116. }
  117. map.translate(noPath);
  118. }
  119. GadgetStaticTextSetText(staticTextMapName,map);
  120. // fill in the player list
  121. GadgetListBoxReset(listBoxPlayers);
  122. Int numColors = TheMultiplayerSettings->getNumColors();
  123. Color white = GameMakeColor(255,255,255,255);
  124. // Color grey = GameMakeColor(188,188,188,255);
  125. for (Int i = 0; i < MAX_SLOTS; i ++)
  126. {
  127. Color playerColor = white;
  128. Int color = -1;
  129. Int addedRow;
  130. GameSlot *slot = gameInfo->getSlot(i);
  131. if(!slot || (slot->isOccupied() == FALSE))
  132. continue;
  133. color = slot->getColor();
  134. if(color > -1 && color < numColors)
  135. {
  136. MultiplayerColorDefinition *def = TheMultiplayerSettings->getColor(color);
  137. playerColor = def->getColor();
  138. }
  139. if(slot->isAI())
  140. {
  141. switch(slot->getState())
  142. {
  143. case SLOT_EASY_AI:
  144. {
  145. addedRow = GadgetListBoxAddEntryText(listBoxPlayers,TheGameText->fetch("GUI:EasyAI"),playerColor,-1, 1);
  146. break;
  147. }
  148. case SLOT_MED_AI:
  149. {
  150. addedRow = GadgetListBoxAddEntryText(listBoxPlayers,TheGameText->fetch("GUI:MediumAI"),playerColor,-1, 1);
  151. break;
  152. }
  153. case SLOT_BRUTAL_AI:
  154. {
  155. addedRow = GadgetListBoxAddEntryText(listBoxPlayers,TheGameText->fetch("GUI:HardAI"),playerColor,-1, 1);
  156. break;
  157. }
  158. default:
  159. break;
  160. }
  161. }
  162. else if(slot->isHuman())
  163. {
  164. addedRow = GadgetListBoxAddEntryText(listBoxPlayers, slot->getName(),playerColor,-1,1);
  165. }
  166. Int playerTemplate = slot->getPlayerTemplate();
  167. if(playerTemplate == PLAYERTEMPLATE_OBSERVER)
  168. {
  169. GadgetListBoxAddEntryImage(listBoxPlayers, observerIcon,addedRow, 0, 22,25);
  170. }
  171. else if(playerTemplate < 0 || playerTemplate >= ThePlayerTemplateStore->getPlayerTemplateCount())
  172. {
  173. ///< @todo: When we get art that shows player's side, then we'll actually draw the art instead of putting in text
  174. GadgetListBoxAddEntryImage(listBoxPlayers, randomIcon,addedRow, 0, 22,25);
  175. //GadgetListBoxAddEntryText(listBoxPlayers,TheGameText->fetch("GUI:???"),playerColor,addedRow, 0);
  176. }
  177. else
  178. {
  179. const PlayerTemplate *fact = ThePlayerTemplateStore->getNthPlayerTemplate(playerTemplate);
  180. GadgetListBoxAddEntryImage(listBoxPlayers, fact->getSideIconImage(),addedRow, 0, 22,25);
  181. //GadgetListBoxAddEntryText(listBoxPlayers,fact->getDisplayName(),playerColor,addedRow, 0);
  182. }
  183. }
  184. }
  185. void HideGameInfoWindow(Bool hide)
  186. {
  187. if(!parent)
  188. return;
  189. parent->winHide(hide);
  190. }
  191. //-------------------------------------------------------------------------------------------------
  192. /** Initialize the GameInfoWindow */
  193. //-------------------------------------------------------------------------------------------------
  194. void GameInfoWindowInit( WindowLayout *layout, void *userData )
  195. {
  196. parentID = TheNameKeyGenerator->nameToKey( "GameInfoWindow.wnd:ParentGameInfo" );
  197. staticTextGameNameID = TheNameKeyGenerator->nameToKey( "GameInfoWindow.wnd:StaticTextGameName" );
  198. staticTextMapNameID = TheNameKeyGenerator->nameToKey( "GameInfoWindow.wnd:StaticTextMapName" );
  199. listBoxPlayersID = TheNameKeyGenerator->nameToKey( "GameInfoWindow.wnd:ListBoxPlayers" );
  200. winCratesID = TheNameKeyGenerator->nameToKey( "GameInfoWindow.wnd:WinCrates" );
  201. winSuperWeaponsID = TheNameKeyGenerator->nameToKey( "GameInfoWindow.wnd:WinSuperWeapons" );
  202. winFreeForAllID = TheNameKeyGenerator->nameToKey( "GameInfoWindow.wnd:WinFreeForAll" );
  203. parent = TheWindowManager->winGetWindowFromId( NULL, parentID );
  204. staticTextGameName = TheWindowManager->winGetWindowFromId( parent, staticTextGameNameID );
  205. staticTextMapName = TheWindowManager->winGetWindowFromId( parent, staticTextMapNameID );
  206. listBoxPlayers = TheWindowManager->winGetWindowFromId( parent, listBoxPlayersID );
  207. winCrates = TheWindowManager->winGetWindowFromId( parent, winCratesID );
  208. winSuperWeapons = TheWindowManager->winGetWindowFromId( parent, winSuperWeaponsID );
  209. winFreeForAll = TheWindowManager->winGetWindowFromId( parent, winFreeForAllID );
  210. GadgetStaticTextSetText(staticTextGameName,UnicodeString.TheEmptyString);
  211. GadgetStaticTextSetText(staticTextMapName,UnicodeString.TheEmptyString);
  212. GadgetListBoxReset(listBoxPlayers);
  213. } // end MapSelectMenuInit
  214. //-------------------------------------------------------------------------------------------------
  215. /** GameInfo window system callback */
  216. //-------------------------------------------------------------------------------------------------
  217. WindowMsgHandledType GameInfoWindowSystem( GameWindow *window, UnsignedInt msg,
  218. WindowMsgData mData1, WindowMsgData mData2 )
  219. {
  220. switch( msg )
  221. {
  222. // might use these later
  223. // GameWindow *control = (GameWindow *)mData1;
  224. // Int controlID = control->winGetWindowId();
  225. // --------------------------------------------------------------------------------------------
  226. case GWM_CREATE:
  227. {
  228. break;
  229. } // end create
  230. //---------------------------------------------------------------------------------------------
  231. case GWM_DESTROY:
  232. {
  233. break;
  234. } // end case
  235. // --------------------------------------------------------------------------------------------
  236. case GWM_INPUT_FOCUS:
  237. {
  238. // if we're givin the opportunity to take the keyboard focus we must say we want it
  239. if( mData1 == TRUE )
  240. *(Bool *)mData2 = TRUE;
  241. return MSG_HANDLED;
  242. } // end input
  243. //---------------------------------------------------------------------------------------------
  244. default:
  245. return MSG_IGNORED;
  246. } // end switch
  247. return MSG_HANDLED;
  248. } // end MapSelectMenuSystem