SkirmishMapSelectMenu.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  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: SkirmishMapSelectMenu.cpp ////////////////////////////////////////////////////////////////////////
  24. // Author: Chris Brue, August 2002
  25. // Description: MapSelect menu window callbacks
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/GameEngine.h"
  30. #include "Common/MessageStream.h"
  31. #include "Common/UserPreferences.h"
  32. #include "GameClient/WindowLayout.h"
  33. #include "GameClient/Gadget.h"
  34. #include "GameClient/GameText.h"
  35. #include "GameClient/Mouse.h"
  36. #include "GameClient/Shell.h"
  37. #include "GameClient/GameWindowManager.h"
  38. #include "GameClient/GadgetListBox.h"
  39. #include "GameClient/GadgetRadioButton.h"
  40. #include "GameClient/GadgetStaticText.h"
  41. #include "GameNetwork/LANAPICallbacks.h"
  42. #include "GameClient/MapUtil.h"
  43. // PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
  44. static NameKeyType buttonBack = NAMEKEY_INVALID;
  45. static NameKeyType buttonOK = NAMEKEY_INVALID;
  46. static NameKeyType listboxMap = NAMEKEY_INVALID;
  47. static GameWindow *parent = NULL;
  48. static GameWindow *mapList = NULL;
  49. static NameKeyType radioButtonSystemMapsID = NAMEKEY_INVALID;
  50. static NameKeyType radioButtonUserMapsID = NAMEKEY_INVALID;
  51. static GameWindow *buttonMapStartPosition[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
  52. NULL,NULL,NULL,NULL };
  53. static NameKeyType buttonMapStartPositionID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
  54. NAMEKEY_INVALID,NAMEKEY_INVALID,
  55. NAMEKEY_INVALID,NAMEKEY_INVALID,
  56. NAMEKEY_INVALID,NAMEKEY_INVALID };
  57. static GameWindow *winMapPreview = NULL;
  58. static NameKeyType winMapPreviewID = NAMEKEY_INVALID;
  59. static void NullifyControls()
  60. {
  61. mapList = NULL;
  62. winMapPreview = NULL;
  63. parent = NULL;
  64. for (Int i=0; i<MAX_SLOTS; ++i)
  65. {
  66. buttonMapStartPosition[i] = NULL;
  67. }
  68. }
  69. extern WindowLayout *skirmishMapSelectLayout;
  70. // Tooltips -------------------------------------------------------------------------------
  71. static void mapListTooltipFunc(GameWindow *window,
  72. WinInstanceData *instData,
  73. UnsignedInt mouse)
  74. {
  75. Int x, y, row, col;
  76. x = LOLONGTOSHORT(mouse);
  77. y = HILONGTOSHORT(mouse);
  78. GadgetListBoxGetEntryBasedOnXY(window, x, y, row, col);
  79. if (row == -1 || col == -1)
  80. {
  81. TheMouse->setCursorTooltip( UnicodeString::TheEmptyString);
  82. return;
  83. }
  84. Int imageItemData = (Int)GadgetListBoxGetItemData(window, row, 1);
  85. UnicodeString tooltip;
  86. switch (imageItemData)
  87. {
  88. case 0:
  89. tooltip = TheGameText->fetch("TOOLTIP:MapNoSuccess");
  90. break;
  91. case 1:
  92. tooltip = TheGameText->fetch("TOOLTIP:MapEasySuccess");
  93. break;
  94. case 2:
  95. tooltip = TheGameText->fetch("TOOLTIP:MapMediumSuccess");
  96. break;
  97. case 3:
  98. tooltip = TheGameText->fetch("TOOLTIP:MapHardSuccess");
  99. break;
  100. case 4:
  101. tooltip = TheGameText->fetch("TOOLTIP:MapMaxBrutalSuccess");
  102. break;
  103. }
  104. TheMouse->setCursorTooltip( tooltip );
  105. }
  106. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////
  107. void positionStartSpots( AsciiString mapName, GameWindow *buttonMapStartPositions[], GameWindow *mapWindow);
  108. void skirmishPositionStartSpots( void );
  109. void skirmishUpdateSlotList( void );
  110. void showSkirmishGameOptionsUnderlyingGUIElements( Bool show )
  111. {
  112. AsciiString parentName( "SkirmishGameOptionsMenu.wnd:SkirmishGameOptionsMenuParent" );
  113. NameKeyType parentID = TheNameKeyGenerator->nameToKey( parentName );
  114. GameWindow *parent = TheWindowManager->winGetWindowFromId( NULL, parentID );
  115. if (!parent)
  116. return;
  117. // hide some GUI elements of the screen underneath
  118. GameWindow *win;
  119. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:MapWindow") );
  120. win->winHide( !show );
  121. //win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:StaticTextTitle") );
  122. //win->winHide( !show );
  123. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:StaticTextTeam") );
  124. win->winHide( !show );
  125. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:StaticTextFaction") );
  126. win->winHide( !show );
  127. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:StaticTextColor") );
  128. win->winHide( !show );
  129. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxTeam0") );
  130. win->winHide( !show );
  131. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxTeam1") );
  132. win->winHide( !show );
  133. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxTeam2") );
  134. win->winHide( !show );
  135. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxTeam3") );
  136. win->winHide( !show );
  137. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxTeam4") );
  138. win->winHide( !show );
  139. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxTeam5") );
  140. win->winHide( !show );
  141. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxTeam6") );
  142. win->winHide( !show );
  143. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxTeam7") );
  144. win->winHide( !show );
  145. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxColor0") );
  146. win->winHide( !show );
  147. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxColor1") );
  148. win->winHide( !show );
  149. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxColor2") );
  150. win->winHide( !show );
  151. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxColor3") );
  152. win->winHide( !show );
  153. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxColor4") );
  154. win->winHide( !show );
  155. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxColor5") );
  156. win->winHide( !show );
  157. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxColor6") );
  158. win->winHide( !show );
  159. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxColor7") );
  160. win->winHide( !show );
  161. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxPlayerTemplate0") );
  162. win->winHide( !show );
  163. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxPlayerTemplate1") );
  164. win->winHide( !show );
  165. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxPlayerTemplate2") );
  166. win->winHide( !show );
  167. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxPlayerTemplate3") );
  168. win->winHide( !show );
  169. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxPlayerTemplate4") );
  170. win->winHide( !show );
  171. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxPlayerTemplate5") );
  172. win->winHide( !show );
  173. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxPlayerTemplate6") );
  174. win->winHide( !show );
  175. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ComboBoxPlayerTemplate7") );
  176. win->winHide( !show );
  177. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:TextEntryMapDisplay") );
  178. win->winHide( !show );
  179. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ButtonSelectMap") );
  180. win->winHide( !show );
  181. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ButtonStart") );
  182. win->winHide( !show );
  183. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:StaticTextMapPreview") );
  184. win->winHide( !show );
  185. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ButtonReset") );
  186. win->winEnable( show );
  187. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:ButtonBack") );
  188. win->winEnable( show );
  189. }
  190. //-------------------------------------------------------------------------------------------------
  191. /** Initialize the MapSelect menu */
  192. //-------------------------------------------------------------------------------------------------
  193. void SkirmishMapSelectMenuInit( WindowLayout *layout, void *userData )
  194. {
  195. // set keyboard focus to main parent
  196. AsciiString parentName( "SkirmishMapSelectMenu.wnd:SkrimishMapSelectMenuParent" );
  197. NameKeyType parentID = TheNameKeyGenerator->nameToKey( parentName );
  198. parent = TheWindowManager->winGetWindowFromId( NULL, parentID );
  199. TheWindowManager->winSetFocus( parent );
  200. LANPreferences pref;
  201. Bool usesSystemMapDir = pref.usesSystemMapDir();
  202. const MapMetaData *mmd = TheMapCache->findMap(TheSkirmishGameInfo->getMap());
  203. if (mmd)
  204. {
  205. usesSystemMapDir = mmd->m_isOfficial;
  206. }
  207. winMapPreviewID = TheNameKeyGenerator->nameToKey( AsciiString("SkirmishMapSelectMenu.wnd:WinMapPreview") );
  208. winMapPreview = TheWindowManager->winGetWindowFromId(parent, winMapPreviewID);
  209. buttonBack = TheNameKeyGenerator->nameToKey( AsciiString("SkirmishMapSelectMenu.wnd:ButtonBack") );
  210. buttonOK = TheNameKeyGenerator->nameToKey( AsciiString("SkirmishMapSelectMenu.wnd:ButtonOK") );
  211. listboxMap = TheNameKeyGenerator->nameToKey( AsciiString("SkirmishMapSelectMenu.wnd:ListboxMap") );
  212. radioButtonSystemMapsID = TheNameKeyGenerator->nameToKey( "SkirmishMapSelectMenu.wnd:RadioButtonSystemMaps" );
  213. radioButtonUserMapsID = TheNameKeyGenerator->nameToKey( "SkirmishMapSelectMenu.wnd:RadioButtonUserMaps" );
  214. GameWindow *radioButtonSystemMaps = TheWindowManager->winGetWindowFromId( parent, radioButtonSystemMapsID );
  215. GameWindow *radioButtonUserMaps = TheWindowManager->winGetWindowFromId( parent, radioButtonUserMapsID );
  216. if (usesSystemMapDir)
  217. GadgetRadioSetSelection( radioButtonSystemMaps, FALSE );
  218. else
  219. GadgetRadioSetSelection( radioButtonUserMaps, FALSE );
  220. AsciiString tmpString;
  221. for (Int i = 0; i < MAX_SLOTS; i++)
  222. {
  223. tmpString.format("SkirmishMapSelectMenu.wnd:ButtonMapStartPosition%d", i);
  224. buttonMapStartPositionID[i] = TheNameKeyGenerator->nameToKey( tmpString );
  225. buttonMapStartPosition[i] = TheWindowManager->winGetWindowFromId( winMapPreview, buttonMapStartPositionID[i] );
  226. DEBUG_ASSERTCRASH(buttonMapStartPosition[i], ("Could not find the ButtonMapStartPosition[%d]",i ));
  227. buttonMapStartPosition[i]->winHide(TRUE);
  228. buttonMapStartPosition[i]->winEnable(FALSE);
  229. }
  230. showSkirmishGameOptionsUnderlyingGUIElements(FALSE);
  231. // get the listbox window
  232. AsciiString listString( "SkirmishMapSelectMenu.wnd:ListboxMap" );
  233. NameKeyType mapListID = TheNameKeyGenerator->nameToKey( listString );
  234. mapList = TheWindowManager->winGetWindowFromId( parent, mapListID );
  235. if( mapList )
  236. {
  237. if (TheMapCache)
  238. TheMapCache->updateCache();
  239. if (usesSystemMapDir)
  240. {
  241. populateMapListbox( mapList, TRUE, TRUE, TheSkirmishGameInfo->getMap() );
  242. }
  243. else
  244. {
  245. populateMapListbox( mapList, FALSE, FALSE, TheSkirmishGameInfo->getMap() );
  246. populateMapListboxNoReset( mapList, FALSE, TRUE, TheSkirmishGameInfo->getMap() );
  247. }
  248. mapList->winSetTooltipFunc(mapListTooltipFunc);
  249. }
  250. } // end SkirmishMapSelectMenuInit
  251. //-------------------------------------------------------------------------------------------------
  252. /** MapSelect menu shutdown method */
  253. //-------------------------------------------------------------------------------------------------
  254. void SkirmishMapSelectMenuShutdown( WindowLayout *layout, void *userData )
  255. {
  256. // hide menu
  257. layout->hide( TRUE );
  258. NullifyControls();
  259. // our shutdown is complete
  260. TheShell->shutdownComplete( layout );
  261. } // end LanMapSelectMenuShutdown
  262. //-------------------------------------------------------------------------------------------------
  263. /** MapSelect menu update method */
  264. //-------------------------------------------------------------------------------------------------
  265. void SkirmishMapSelectMenuUpdate( WindowLayout *layout, void *userData )
  266. {
  267. } // end SkirmishMapSelectMenuUpdate
  268. //-------------------------------------------------------------------------------------------------
  269. /** Map select menu input callback */
  270. //-------------------------------------------------------------------------------------------------
  271. WindowMsgHandledType SkirmishMapSelectMenuInput( GameWindow *window, UnsignedInt msg,
  272. WindowMsgData mData1, WindowMsgData mData2 )
  273. {
  274. switch( msg )
  275. {
  276. // --------------------------------------------------------------------------------------------
  277. case GWM_CHAR:
  278. {
  279. UnsignedByte key = mData1;
  280. UnsignedByte state = mData2;
  281. switch( key )
  282. {
  283. // ----------------------------------------------------------------------------------------
  284. case KEY_ESC:
  285. {
  286. //
  287. // send a simulated selected event to the parent window of the
  288. // back/exit button
  289. //
  290. if( BitTest( state, KEY_STATE_UP ) )
  291. {
  292. AsciiString buttonName( "SkirmishMapSelectMenu.wnd:ButtonBack" );
  293. NameKeyType buttonID = TheNameKeyGenerator->nameToKey( buttonName );
  294. GameWindow *button = TheWindowManager->winGetWindowFromId( window, buttonID );
  295. TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  296. (WindowMsgData)button, buttonID );
  297. } // end if
  298. // don't let key fall through anywhere else
  299. return MSG_HANDLED;
  300. } // end escape
  301. } // end switch( key )
  302. } // end char
  303. } // end switch( msg )
  304. return MSG_IGNORED;
  305. } // end SkirmishMapSelectMenuInput
  306. //-------------------------------------------------------------------------------------------------
  307. /** MapSelect menu window system callback */
  308. //-------------------------------------------------------------------------------------------------
  309. WindowMsgHandledType SkirmishMapSelectMenuSystem( GameWindow *window, UnsignedInt msg,
  310. WindowMsgData mData1, WindowMsgData mData2 )
  311. {
  312. switch( msg )
  313. {
  314. // --------------------------------------------------------------------------------------------
  315. case GWM_CREATE:
  316. {
  317. break;
  318. } // end create
  319. //---------------------------------------------------------------------------------------------
  320. case GWM_DESTROY:
  321. {
  322. NullifyControls();
  323. break;
  324. } // end case
  325. // --------------------------------------------------------------------------------------------
  326. case GWM_INPUT_FOCUS:
  327. {
  328. // if we're givin the opportunity to take the keyboard focus we must say we want it
  329. if( mData1 == TRUE )
  330. *(Bool *)mData2 = TRUE;
  331. return MSG_HANDLED;
  332. } // end input
  333. //---------------------------------------------------------------------------------------------
  334. case GLM_DOUBLE_CLICKED:
  335. {
  336. GameWindow *control = (GameWindow *)mData1;
  337. Int controlID = control->winGetWindowId();
  338. if( controlID == listboxMap )
  339. {
  340. int rowSelected = mData2;
  341. if (rowSelected >= 0)
  342. {
  343. GadgetListBoxSetSelected( control, rowSelected );
  344. GameWindow *button = TheWindowManager->winGetWindowFromId( window, buttonOK );
  345. TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  346. (WindowMsgData)button, buttonOK );
  347. }
  348. }
  349. break;
  350. }
  351. //---------------------------------------------------------------------------------------------
  352. case GLM_SELECTED:
  353. {
  354. GameWindow *mapWindow = TheWindowManager->winGetWindowFromId( parent, listboxMap );
  355. GameWindow *control = (GameWindow *)mData1;
  356. Int controlID = control->winGetWindowId();
  357. if( controlID == listboxMap )
  358. {
  359. int rowSelected = mData2;
  360. if( rowSelected < 0 )
  361. {
  362. positionStartSpots( AsciiString::TheEmptyString, buttonMapStartPosition, winMapPreview);
  363. //winMapPreview->winClearStatus(WIN_STATUS_IMAGE);
  364. break;
  365. }
  366. winMapPreview->winSetStatus(WIN_STATUS_IMAGE);
  367. UnicodeString map;
  368. // get text of the map to load
  369. map = GadgetListBoxGetText( mapWindow, rowSelected, 0 );
  370. // set the map name in the global data map name
  371. AsciiString asciiMap;
  372. const char *mapFname = (const char *)GadgetListBoxGetItemData( mapWindow, rowSelected );
  373. DEBUG_ASSERTCRASH(mapFname, ("No map item data"));
  374. if (mapFname)
  375. asciiMap = mapFname;
  376. else
  377. asciiMap.translate( map );
  378. asciiMap.toLower();
  379. Image *image = getMapPreviewImage(asciiMap);
  380. winMapPreview->winSetUserData((void *)TheMapCache->findMap(asciiMap));
  381. if(image)
  382. {
  383. winMapPreview->winSetEnabledImage(0, image);
  384. }
  385. else
  386. {
  387. winMapPreview->winClearStatus(WIN_STATUS_IMAGE);
  388. }
  389. positionStartSpots( asciiMap, buttonMapStartPosition, winMapPreview);
  390. }
  391. break;
  392. }
  393. //---------------------------------------------------------------------------------------------
  394. case GBM_SELECTED:
  395. {
  396. // this isn't fixed yet
  397. GameWindow *control = (GameWindow *)mData1;
  398. Int controlID = control->winGetWindowId();
  399. if ( controlID == radioButtonSystemMapsID )
  400. {
  401. if (TheMapCache)
  402. TheMapCache->updateCache();
  403. populateMapListbox( mapList, TRUE, TRUE, TheSkirmishGameInfo->getMap() );
  404. //LANPreferences pref;
  405. //pref["UseSystemMapDir"] = "yes";
  406. //pref.write();
  407. }
  408. else if ( controlID == radioButtonUserMapsID )
  409. {
  410. if (TheMapCache)
  411. TheMapCache->updateCache();
  412. populateMapListbox( mapList, FALSE, FALSE, TheSkirmishGameInfo->getMap() );
  413. populateMapListboxNoReset( mapList, FALSE, TRUE, TheSkirmishGameInfo->getMap() );
  414. //LANPreferences pref;
  415. //pref["UseSystemMapDir"] = "no";
  416. //pref.write();
  417. }
  418. else if ( controlID == buttonBack )
  419. {
  420. showSkirmishGameOptionsUnderlyingGUIElements(TRUE);
  421. skirmishMapSelectLayout->destroyWindows();
  422. skirmishMapSelectLayout->deleteInstance();
  423. skirmishMapSelectLayout = NULL;
  424. skirmishPositionStartSpots();
  425. //TheShell->pop();
  426. //do you need this ??
  427. //PostToLanGameOptions( MAP_BACK );
  428. } // end if
  429. else if ( controlID == buttonOK )
  430. {
  431. Int selected;
  432. UnicodeString map;
  433. GameWindow *mapWindow = TheWindowManager->winGetWindowFromId( parent, listboxMap );
  434. // get the selected index
  435. GadgetListBoxGetSelected( mapWindow, &selected );
  436. if( selected != -1 )
  437. {
  438. //buttonPushed = true;
  439. // set the map name in the global data map name
  440. AsciiString asciiMap;
  441. const char *mapFname = (const char *)GadgetListBoxGetItemData( mapWindow, selected );
  442. DEBUG_ASSERTCRASH(mapFname, ("No map item data"));
  443. if (mapFname)
  444. asciiMap = mapFname;
  445. else
  446. asciiMap.translate( map );
  447. TheSkirmishGameInfo->setMap( asciiMap );
  448. const MapMetaData *md = TheMapCache->findMap(asciiMap);
  449. if (!md)
  450. {
  451. TheSkirmishGameInfo->setMapCRC(0);
  452. TheSkirmishGameInfo->setMapSize(0);
  453. }
  454. else
  455. {
  456. TheSkirmishGameInfo->setMapCRC(md->m_CRC);
  457. TheSkirmishGameInfo->setMapSize(md->m_filesize);
  458. }
  459. // reset the start positions
  460. for(Int i = 0; i < MAX_SLOTS; ++i)
  461. TheSkirmishGameInfo->getSlot(i)->setStartPos(-1);
  462. GameWindow *win;
  463. win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:TextEntryMapDisplay") );
  464. if(win)
  465. {
  466. if (md)
  467. {
  468. GadgetStaticTextSetText(win, md->m_displayName);
  469. }
  470. }
  471. //if (mapFname)
  472. //setupGameStart(mapFname);
  473. showSkirmishGameOptionsUnderlyingGUIElements(TRUE);
  474. skirmishPositionStartSpots();
  475. skirmishUpdateSlotList();
  476. skirmishMapSelectLayout->destroyWindows();
  477. skirmishMapSelectLayout->deleteInstance();
  478. skirmishMapSelectLayout = NULL;
  479. //TheShell->pop();
  480. } // end if
  481. } // end else if
  482. break;
  483. } // end selected
  484. default:
  485. return MSG_IGNORED;
  486. } // end switch
  487. return MSG_HANDLED;
  488. } // end SkirmishMapSelectMenuSystem*/