LanGameOptionsMenu.cpp 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417
  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. ///////////////////////////////////////////////////////////////////////////////////////
  24. // FILE: LanGameOptionsMenu.cpp
  25. // Author: Chris Huybregts, October 2001
  26. // Description: Lan Game Options Menu
  27. ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/PlayerTemplate.h"
  30. #include "Common/GameEngine.h"
  31. #include "Common/UserPreferences.h"
  32. #include "Common/QuotedPrintable.h"
  33. #include "GameClient/AnimateWindowManager.h"
  34. #include "GameClient/WindowLayout.h"
  35. #include "GameClient/Gadget.h"
  36. #include "GameClient/Shell.h"
  37. #include "GameClient/KeyDefs.h"
  38. #include "GameClient/GameWindowManager.h"
  39. #include "GameClient/GadgetListBox.h"
  40. #include "GameClient/GadgetComboBox.h"
  41. #include "GameClient/GadgetTextEntry.h"
  42. #include "GameClient/GadgetStaticText.h"
  43. #include "GameClient/GadgetPushButton.h"
  44. #include "GameClient/GadgetCheckbox.h"
  45. #include "GameClient/MapUtil.h"
  46. #include "GameClient/Mouse.h"
  47. #include "GameClient/GameWindowTransitions.h"
  48. #include "GameClient/ChallengeGenerals.h"
  49. #include "GameNetwork/GameSpy/LobbyUtils.h"
  50. #include "GameNetwork/FirewallHelper.h"
  51. #include "GameNetwork/LANAPI.h"
  52. #include "GameNetwork/IPEnumeration.h"
  53. #include "GameNetwork/LANAPICallbacks.h"
  54. #include "Common/MultiplayerSettings.h"
  55. #include "GameClient/GameText.h"
  56. #include "GameNetwork/GUIUtil.h"
  57. #ifdef _INTERNAL
  58. // for occasional debugging...
  59. //#pragma optimize("", off)
  60. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  61. #endif
  62. extern char *LANnextScreen;
  63. extern Bool LANisShuttingDown;
  64. extern Bool LANbuttonPushed;
  65. extern void MapSelectorTooltip(GameWindow *window, WinInstanceData *instData, UnsignedInt mouse);
  66. extern void gameAcceptTooltip(GameWindow *window, WinInstanceData *instData, UnsignedInt mouse);
  67. Color white = GameMakeColor( 255, 255, 255, 255 );
  68. static bool s_isIniting = FALSE;
  69. // window ids ------------------------------------------------------------------------------
  70. static NameKeyType parentLanGameOptionsID = NAMEKEY_INVALID;
  71. static NameKeyType comboBoxPlayerID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
  72. NAMEKEY_INVALID,NAMEKEY_INVALID,
  73. NAMEKEY_INVALID,NAMEKEY_INVALID,
  74. NAMEKEY_INVALID,NAMEKEY_INVALID };
  75. static NameKeyType buttonAcceptID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
  76. NAMEKEY_INVALID,NAMEKEY_INVALID,
  77. NAMEKEY_INVALID,NAMEKEY_INVALID,
  78. NAMEKEY_INVALID,NAMEKEY_INVALID };
  79. static NameKeyType comboBoxColorID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
  80. NAMEKEY_INVALID,NAMEKEY_INVALID,
  81. NAMEKEY_INVALID,NAMEKEY_INVALID,
  82. NAMEKEY_INVALID,NAMEKEY_INVALID };
  83. static NameKeyType comboBoxPlayerTemplateID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
  84. NAMEKEY_INVALID,NAMEKEY_INVALID,
  85. NAMEKEY_INVALID,NAMEKEY_INVALID,
  86. NAMEKEY_INVALID,NAMEKEY_INVALID };
  87. static NameKeyType comboBoxTeamID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
  88. NAMEKEY_INVALID,NAMEKEY_INVALID,
  89. NAMEKEY_INVALID,NAMEKEY_INVALID,
  90. NAMEKEY_INVALID,NAMEKEY_INVALID };
  91. //static NameKeyType buttonStartPositionID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
  92. // NAMEKEY_INVALID,NAMEKEY_INVALID,
  93. // NAMEKEY_INVALID,NAMEKEY_INVALID,
  94. // NAMEKEY_INVALID,NAMEKEY_INVALID };
  95. static NameKeyType buttonMapStartPositionID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
  96. NAMEKEY_INVALID,NAMEKEY_INVALID,
  97. NAMEKEY_INVALID,NAMEKEY_INVALID,
  98. NAMEKEY_INVALID,NAMEKEY_INVALID };
  99. static NameKeyType textEntryChatID = NAMEKEY_INVALID;
  100. static NameKeyType textEntryMapDisplayID = NAMEKEY_INVALID;
  101. static NameKeyType buttonBackID = NAMEKEY_INVALID;
  102. static NameKeyType buttonStartID = NAMEKEY_INVALID;
  103. static NameKeyType buttonEmoteID = NAMEKEY_INVALID;
  104. static NameKeyType buttonSelectMapID = NAMEKEY_INVALID;
  105. static NameKeyType checkboxLimitSuperweaponsID = NAMEKEY_INVALID;
  106. static NameKeyType comboBoxStartingCashID = NAMEKEY_INVALID;
  107. static NameKeyType windowMapID = NAMEKEY_INVALID;
  108. // Window Pointers ------------------------------------------------------------------------
  109. static GameWindow *parentLanGameOptions = NULL;
  110. static GameWindow *buttonBack = NULL;
  111. static GameWindow *buttonStart = NULL;
  112. static GameWindow *buttonSelectMap = NULL;
  113. static GameWindow *buttonEmote = NULL;
  114. static GameWindow *textEntryChat = NULL;
  115. static GameWindow *textEntryMapDisplay = NULL;
  116. static GameWindow *checkboxLimitSuperweapons = NULL;
  117. static GameWindow *comboBoxStartingCash = NULL;
  118. static GameWindow *windowMap = NULL;
  119. static GameWindow *comboBoxPlayer[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
  120. NULL,NULL,NULL,NULL };
  121. static GameWindow *buttonAccept[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
  122. NULL,NULL,NULL,NULL };
  123. static GameWindow *comboBoxColor[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
  124. NULL,NULL,NULL,NULL };
  125. static GameWindow *comboBoxPlayerTemplate[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
  126. NULL,NULL,NULL,NULL };
  127. static GameWindow *comboBoxTeam[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
  128. NULL,NULL,NULL,NULL };
  129. //static GameWindow *buttonStartPosition[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
  130. // NULL,NULL,NULL,NULL };
  131. //
  132. static GameWindow *buttonMapStartPosition[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
  133. NULL,NULL,NULL,NULL };
  134. //external declarations of the Gadgets the callbacks can use
  135. GameWindow *listboxChatWindowLanGame = NULL;
  136. NameKeyType listboxChatWindowLanGameID = NAMEKEY_INVALID;
  137. WindowLayout *mapSelectLayout = NULL;
  138. static Int getNextSelectablePlayer(Int start)
  139. {
  140. LANGameInfo *game = TheLAN->GetMyGame();
  141. if (!game->amIHost())
  142. return -1;
  143. for (Int j=start; j<MAX_SLOTS; ++j)
  144. {
  145. LANGameSlot *slot = game->getLANSlot(j);
  146. if (slot && slot->getStartPos() == -1 &&
  147. ( (j==game->getLocalSlotNum() && game->getConstSlot(j)->getPlayerTemplate()!=PLAYERTEMPLATE_OBSERVER)
  148. || slot->isAI()))
  149. {
  150. return j;
  151. }
  152. }
  153. return -1;
  154. }
  155. static Int getFirstSelectablePlayer(const GameInfo *game)
  156. {
  157. const GameSlot *slot = game->getConstSlot(game->getLocalSlotNum());
  158. if (!game->amIHost() || slot && slot->getPlayerTemplate() != PLAYERTEMPLATE_OBSERVER)
  159. return game->getLocalSlotNum();
  160. for (Int i=0; i<MAX_SLOTS; ++i)
  161. {
  162. slot = game->getConstSlot(i);
  163. if (slot && slot->isAI())
  164. return i;
  165. }
  166. return game->getLocalSlotNum();
  167. }
  168. void updateMapStartSpots( GameInfo *myGame, GameWindow *buttonMapStartPositions[], Bool onLoadScreen = FALSE );
  169. void positionStartSpots( GameInfo *myGame, GameWindow *buttonMapStartPositions[], GameWindow *mapWindow);
  170. void LanPositionStartSpots( void )
  171. {
  172. positionStartSpots( TheLAN->GetMyGame(), buttonMapStartPosition, windowMap);
  173. }
  174. static void playerTooltip(GameWindow *window,
  175. WinInstanceData *instData,
  176. UnsignedInt mouse)
  177. {
  178. Int idx = -1;
  179. for (Int i=0; i<MAX_SLOTS; ++i)
  180. {
  181. if (window && window == GadgetComboBoxGetEditBox(comboBoxPlayer[i]))
  182. {
  183. idx = i;
  184. break;
  185. }
  186. }
  187. if (idx == -1)
  188. return;
  189. LANGameSlot *slot = TheLAN->GetMyGame()->getLANSlot(i);
  190. if (!slot)
  191. return;
  192. LANPlayer *player = slot->getUser();
  193. if (!player)
  194. {
  195. DEBUG_ASSERTCRASH(TheLAN->GetMyGame()->getIP(i) == 0, ("No player info in listbox!"));
  196. TheMouse->setCursorTooltip( UnicodeString::TheEmptyString );
  197. return;
  198. }
  199. UnicodeString tooltip;
  200. tooltip.format(TheGameText->fetch("TOOLTIP:LANPlayer"), player->getName().str(), player->getLogin().str(), player->getHost().str());
  201. TheMouse->setCursorTooltip( tooltip );
  202. }
  203. void StartPressed(void)
  204. {
  205. LANGameInfo *myGame = TheLAN->GetMyGame();
  206. Bool isReady = true;
  207. Bool allHaveMap = true;
  208. Int playerCount = 0;
  209. if (!myGame)
  210. {
  211. return;
  212. }
  213. myGame->getLANSlot(0)->setAccept(); // cause we are, of course!
  214. int i;
  215. int numUsers = 0;
  216. int numHumans = 0;
  217. for (i=0; i<MAX_SLOTS; ++i)
  218. {
  219. GameSlot *slot = myGame->getSlot(i);
  220. if (slot && slot->isOccupied() && slot->getPlayerTemplate() != PLAYERTEMPLATE_OBSERVER)
  221. {
  222. if (slot && slot->isHuman())
  223. numHumans++;
  224. numUsers++;
  225. }
  226. }
  227. // Check for too many players
  228. const MapMetaData *md = TheMapCache->findMap( myGame->getMap() );
  229. if (!md || md->m_numPlayers < numUsers)
  230. {
  231. if (TheLAN->AmIHost())
  232. {
  233. UnicodeString text;
  234. text.format(TheGameText->fetch("LAN:TooManyPlayers"), (md)?md->m_numPlayers:0);
  235. TheLAN->OnChat(UnicodeString(L"SYSTEM"), TheLAN->GetLocalIP(), text, LANAPI::LANCHAT_SYSTEM);
  236. }
  237. return;
  238. }
  239. // Check for observer + AI players
  240. if (TheGlobalData->m_netMinPlayers && !numHumans)
  241. {
  242. if (TheLAN->AmIHost())
  243. {
  244. UnicodeString text = TheGameText->fetch("GUI:NeedHumanPlayers");
  245. TheLAN->OnChat(UnicodeString(L"SYSTEM"), TheLAN->GetLocalIP(), text, LANAPI::LANCHAT_SYSTEM);
  246. }
  247. return;
  248. }
  249. // Check for too few players
  250. if (numUsers < TheGlobalData->m_netMinPlayers)
  251. {
  252. if (TheLAN->AmIHost())
  253. {
  254. UnicodeString text;
  255. text.format(TheGameText->fetch("LAN:NeedMorePlayers"),numUsers);
  256. TheLAN->OnChat(UnicodeString(L"SYSTEM"), TheLAN->GetLocalIP(), text, LANAPI::LANCHAT_SYSTEM);
  257. }
  258. return;
  259. }
  260. // Check for too few teams
  261. int numRandom = 0;
  262. std::set<Int> teams;
  263. for (i=0; i<MAX_SLOTS; ++i)
  264. {
  265. GameSlot *slot = myGame->getSlot(i);
  266. if (slot && slot->isOccupied() && slot->getPlayerTemplate() != PLAYERTEMPLATE_OBSERVER)
  267. {
  268. if (slot->getTeamNumber() >= 0)
  269. {
  270. teams.insert(slot->getTeamNumber());
  271. }
  272. else
  273. {
  274. ++numRandom;
  275. }
  276. }
  277. }
  278. if (numRandom + teams.size() < TheGlobalData->m_netMinPlayers)
  279. {
  280. if (TheLAN->AmIHost())
  281. {
  282. UnicodeString text;
  283. text.format(TheGameText->fetch("LAN:NeedMoreTeams"));
  284. TheLAN->OnChat(UnicodeString(L"SYSTEM"), TheLAN->GetLocalIP(), text, LANAPI::LANCHAT_SYSTEM);
  285. }
  286. return;
  287. }
  288. if (numRandom + teams.size() < 2)
  289. {
  290. UnicodeString text;
  291. text.format(TheGameText->fetch("GUI:SandboxMode"));
  292. TheLAN->OnChat(UnicodeString(L"SYSTEM"), TheLAN->GetLocalIP(), text, LANAPI::LANCHAT_SYSTEM);
  293. }
  294. // see if everyone's accepted and count the number of players in the game
  295. UnicodeString mapDisplayName;
  296. const MapMetaData *mapData = TheMapCache->findMap( myGame->getMap() );
  297. Bool willTransfer = TRUE;
  298. if (mapData)
  299. {
  300. mapDisplayName.format(L"%ls", mapData->m_displayName.str());
  301. willTransfer = !mapData->m_isOfficial;
  302. }
  303. else
  304. {
  305. mapDisplayName.format(L"%hs", myGame->getMap().str());
  306. willTransfer = WouldMapTransfer(myGame->getMap());
  307. }
  308. for( i = 0; i < MAX_SLOTS; i++ )
  309. {
  310. LANGameSlot *slot = myGame->getLANSlot(i);
  311. if( slot->isHuman() && !slot->isAccepted())
  312. {
  313. isReady = false;
  314. if (!willTransfer)
  315. {
  316. if (!slot->hasMap())
  317. {
  318. UnicodeString msg;
  319. msg.format(TheGameText->fetch("GUI:PlayerNoMap"), slot->getName().str(), mapDisplayName.str());
  320. GadgetListBoxAddEntryText(listboxChatWindowLanGame, msg , chatSystemColor, -1, 0);
  321. allHaveMap = false;
  322. }
  323. }
  324. }
  325. if( slot->isHuman() && slot->getPlayerTemplate() != PLAYERTEMPLATE_OBSERVER )
  326. playerCount++;
  327. }
  328. if(isReady)
  329. {
  330. for( i = 0; i < MAX_SLOTS; i++ )
  331. {
  332. LANGameSlot *slot = myGame->getLANSlot(i);
  333. if (slot && slot->isOpen())
  334. {
  335. slot->setState( SLOT_CLOSED );
  336. GadgetComboBoxSetSelectedPos(comboBoxPlayer[i], SLOT_CLOSED);
  337. }
  338. }
  339. Int seconds = TheMultiplayerSettings->getStartCountdownTimerSeconds();
  340. if (seconds)
  341. TheLAN->RequestGameStartTimer(seconds);
  342. else
  343. TheLAN->RequestGameStart();
  344. LANEnableStartButton(false);
  345. }
  346. else
  347. {
  348. // Does everyone have the map?
  349. if (allHaveMap)
  350. {
  351. GadgetListBoxAddEntryText(listboxChatWindowLanGame, TheGameText->fetch("GUI:NotifiedStartIntent") , chatSystemColor, -1, 0);
  352. TheLAN->RequestAccept();
  353. }
  354. }
  355. }//void StartPressed(void)
  356. void LANEnableStartButton(Bool enabled)
  357. {
  358. buttonStart->winEnable(enabled);
  359. buttonSelectMap->winEnable(enabled);
  360. }
  361. static void handleColorSelection(int index)
  362. {
  363. GameWindow *combo = comboBoxColor[index];
  364. Int color, selIndex;
  365. GadgetComboBoxGetSelectedPos(combo, &selIndex);
  366. color = (Int)GadgetComboBoxGetItemData(combo, selIndex);
  367. LANGameInfo *myGame = TheLAN->GetMyGame();
  368. if (myGame)
  369. {
  370. LANGameSlot * slot = myGame->getLANSlot(index);
  371. if (color == slot->getColor())
  372. return;
  373. if (color >= -1 && color < TheMultiplayerSettings->getNumColors())
  374. {
  375. Bool colorAvailable = TRUE;
  376. if(color != -1 )
  377. {
  378. for(Int i=0; i <MAX_SLOTS; i++)
  379. {
  380. LANGameSlot *checkSlot = myGame->getLANSlot(i);
  381. if(color == checkSlot->getColor() && slot != checkSlot)
  382. {
  383. colorAvailable = FALSE;
  384. break;
  385. }
  386. }
  387. }
  388. if(!colorAvailable)
  389. return;
  390. }
  391. slot->setColor(color);
  392. if (myGame->amIHost())
  393. {
  394. if (!s_isIniting)
  395. {
  396. // send around a new slotlist
  397. TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
  398. lanUpdateSlotList();
  399. }
  400. }
  401. else
  402. {
  403. // request the color from the host
  404. if (!slot->isLocalPlayer() || !AreSlotListUpdatesEnabled())
  405. return;
  406. AsciiString options;
  407. options.format("Color=%d", color);
  408. TheLAN->RequestGameOptions(options, true);
  409. }
  410. }
  411. }
  412. static void handlePlayerTemplateSelection(int index)
  413. {
  414. GameWindow *combo = comboBoxPlayerTemplate[index];
  415. Int playerTemplate, selIndex;
  416. GadgetComboBoxGetSelectedPos(combo, &selIndex);
  417. playerTemplate = (Int)GadgetComboBoxGetItemData(combo, selIndex);
  418. LANGameInfo *myGame = TheLAN->GetMyGame();
  419. if (myGame)
  420. {
  421. LANGameSlot * slot = myGame->getLANSlot(index);
  422. if (playerTemplate == slot->getPlayerTemplate())
  423. return;
  424. Int oldTemplate = slot->getPlayerTemplate();
  425. slot->setPlayerTemplate(playerTemplate);
  426. if (oldTemplate == PLAYERTEMPLATE_OBSERVER)
  427. {
  428. // was observer, so populate color & team with all, and enable
  429. GadgetComboBoxSetSelectedPos(comboBoxColor[index], 0);
  430. GadgetComboBoxSetSelectedPos(comboBoxTeam[index], 0);
  431. slot->setStartPos(-1);
  432. }
  433. else if (playerTemplate == PLAYERTEMPLATE_OBSERVER)
  434. {
  435. // is becoming observer, so populate color & team with random only, and disable
  436. GadgetComboBoxSetSelectedPos(comboBoxColor[index], 0);
  437. GadgetComboBoxSetSelectedPos(comboBoxTeam[index], 0);
  438. slot->setStartPos(-1);
  439. }
  440. myGame->resetAccepted();
  441. if (myGame->amIHost())
  442. {
  443. if (!s_isIniting)
  444. {
  445. // send around a new slotlist
  446. TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
  447. lanUpdateSlotList();
  448. }
  449. }
  450. else
  451. {
  452. // request the playerTemplate from the host
  453. if (AreSlotListUpdatesEnabled())
  454. {
  455. AsciiString options;
  456. options.format("PlayerTemplate=%d", playerTemplate);
  457. TheLAN->RequestGameOptions(options, true);
  458. }
  459. }
  460. }
  461. }
  462. static void handleStartPositionSelection(Int player, int startPos)
  463. {
  464. LANGameInfo *myGame = TheLAN->GetMyGame();
  465. if (myGame)
  466. {
  467. LANGameSlot * slot = myGame->getLANSlot(player);
  468. if (startPos == slot->getStartPos())
  469. return;
  470. Bool skip = FALSE;
  471. if (startPos < 0)
  472. {
  473. skip = TRUE;
  474. }
  475. if(!skip)
  476. {
  477. Bool isAvailable = TRUE;
  478. for(Int i = 0; i < MAX_SLOTS; ++i)
  479. {
  480. if(i != player && myGame->getSlot(i)->getStartPos() == startPos)
  481. {
  482. isAvailable = FALSE;
  483. break;
  484. }
  485. }
  486. if( !isAvailable )
  487. return;
  488. }
  489. slot->setStartPos(startPos);
  490. if (myGame->amIHost())
  491. {
  492. if (!s_isIniting)
  493. {
  494. // send around a new slotlist
  495. myGame->resetAccepted();
  496. TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
  497. lanUpdateSlotList();
  498. }
  499. }
  500. else
  501. {
  502. // request the color from the host
  503. if (AreSlotListUpdatesEnabled())
  504. {
  505. AsciiString options;
  506. options.format("StartPos=%d", slot->getStartPos());
  507. TheLAN->RequestGameOptions(options, true);
  508. }
  509. }
  510. }
  511. }
  512. static void handleTeamSelection(int index)
  513. {
  514. GameWindow *combo = comboBoxTeam[index];
  515. Int team, selIndex;
  516. GadgetComboBoxGetSelectedPos(combo, &selIndex);
  517. team = (Int)GadgetComboBoxGetItemData(combo, selIndex);
  518. LANGameInfo *myGame = TheLAN->GetMyGame();
  519. if (myGame)
  520. {
  521. LANGameSlot * slot = myGame->getLANSlot(index);
  522. if (team == slot->getTeamNumber())
  523. return;
  524. slot->setTeamNumber(team);
  525. myGame->resetAccepted();
  526. if (myGame->amIHost())
  527. {
  528. if (!s_isIniting)
  529. {
  530. // send around a new slotlist
  531. myGame->resetAccepted();
  532. TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
  533. lanUpdateSlotList();
  534. }
  535. }
  536. else
  537. {
  538. // request the team from the host
  539. if (AreSlotListUpdatesEnabled())
  540. {
  541. AsciiString options;
  542. options.format("Team=%d", team);
  543. TheLAN->RequestGameOptions(options, true);
  544. }
  545. }
  546. }
  547. }
  548. static void handleStartingCashSelection()
  549. {
  550. LANGameInfo *myGame = TheLAN->GetMyGame();
  551. if (myGame)
  552. {
  553. Int selIndex;
  554. GadgetComboBoxGetSelectedPos(comboBoxStartingCash, &selIndex);
  555. Money startingCash;
  556. startingCash.deposit( (UnsignedInt)GadgetComboBoxGetItemData( comboBoxStartingCash, selIndex ), FALSE );
  557. myGame->setStartingCash( startingCash );
  558. myGame->resetAccepted();
  559. if (myGame->amIHost())
  560. {
  561. if (!s_isIniting)
  562. {
  563. // send around the new data
  564. TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
  565. lanUpdateSlotList(); // Update the accepted button UI
  566. }
  567. }
  568. }
  569. }
  570. static void handleLimitSuperweaponsClick()
  571. {
  572. LANGameInfo *myGame = TheLAN->GetMyGame();
  573. if (myGame)
  574. {
  575. // At the moment, 1 and 0 are the only choices supported in the GUI, though the system could
  576. // support more.
  577. if ( GadgetCheckBoxIsChecked( checkboxLimitSuperweapons ) )
  578. {
  579. myGame->setSuperweaponRestriction( 1 );
  580. }
  581. else
  582. {
  583. myGame->setSuperweaponRestriction( 0 );
  584. }
  585. myGame->resetAccepted();
  586. if (myGame->amIHost())
  587. {
  588. if (!s_isIniting)
  589. {
  590. // send around a new slotlist
  591. TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
  592. lanUpdateSlotList(); // Update the accepted button UI
  593. }
  594. }
  595. }
  596. }
  597. void lanUpdateSlotList( void )
  598. {
  599. if(!AreSlotListUpdatesEnabled() || s_isIniting)
  600. return;
  601. UpdateSlotList( TheLAN->GetMyGame(), comboBoxPlayer, comboBoxColor,
  602. comboBoxPlayerTemplate, comboBoxTeam, buttonAccept, buttonStart, buttonMapStartPosition);
  603. updateMapStartSpots(TheLAN->GetMyGame(), buttonMapStartPosition);
  604. }
  605. //-------------------------------------------------------------------------------------------------
  606. /** Initialize the Gadgets Options Menu */
  607. //-------------------------------------------------------------------------------------------------
  608. void InitLanGameGadgets( void )
  609. {
  610. //Initialize the gadget IDs
  611. parentLanGameOptionsID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:LanGameOptionsMenuParent" ) );
  612. buttonBackID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:ButtonBack" ) );
  613. buttonStartID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:ButtonStart" ) );
  614. textEntryChatID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:TextEntryChat" ) );
  615. textEntryMapDisplayID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:TextEntryMapDisplay" ) );
  616. listboxChatWindowLanGameID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:ListboxChatWindowLanGame" ) );
  617. buttonEmoteID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:ButtonEmote" ) );
  618. buttonSelectMapID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:ButtonSelectMap" ) );
  619. checkboxLimitSuperweaponsID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:CheckboxLimitSuperweapons" ) );
  620. comboBoxStartingCashID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:ComboBoxStartingCash" ) );
  621. windowMapID = TheNameKeyGenerator->nameToKey( AsciiString( "LanGameOptionsMenu.wnd:MapWindow" ) );
  622. // Initialize the pointers to our gadgets
  623. parentLanGameOptions = TheWindowManager->winGetWindowFromId( NULL, parentLanGameOptionsID );
  624. DEBUG_ASSERTCRASH(parentLanGameOptions, ("Could not find the parentLanGameOptions"));
  625. buttonEmote = TheWindowManager->winGetWindowFromId( parentLanGameOptions,buttonEmoteID );
  626. DEBUG_ASSERTCRASH(buttonEmote, ("Could not find the buttonEmote"));
  627. buttonSelectMap = TheWindowManager->winGetWindowFromId( parentLanGameOptions,buttonSelectMapID );
  628. DEBUG_ASSERTCRASH(buttonSelectMap, ("Could not find the buttonSelectMap"));
  629. buttonStart = TheWindowManager->winGetWindowFromId( parentLanGameOptions,buttonStartID );
  630. DEBUG_ASSERTCRASH(buttonStart, ("Could not find the buttonStart"));
  631. buttonBack = TheWindowManager->winGetWindowFromId( parentLanGameOptions, buttonBackID);
  632. DEBUG_ASSERTCRASH(buttonBack, ("Could not find the buttonBack"));
  633. listboxChatWindowLanGame = TheWindowManager->winGetWindowFromId( parentLanGameOptions, listboxChatWindowLanGameID );
  634. DEBUG_ASSERTCRASH(listboxChatWindowLanGame, ("Could not find the listboxChatWindowLanGame"));
  635. textEntryChat = TheWindowManager->winGetWindowFromId( parentLanGameOptions, textEntryChatID );
  636. DEBUG_ASSERTCRASH(textEntryChat, ("Could not find the textEntryChat"));
  637. textEntryMapDisplay = TheWindowManager->winGetWindowFromId( parentLanGameOptions, textEntryMapDisplayID );
  638. DEBUG_ASSERTCRASH(textEntryMapDisplay, ("Could not find the textEntryMapDisplay"));
  639. checkboxLimitSuperweapons = TheWindowManager->winGetWindowFromId( parentLanGameOptions, checkboxLimitSuperweaponsID );
  640. DEBUG_ASSERTCRASH(checkboxLimitSuperweapons, ("Could not find the checkboxLimitSuperweapons"));
  641. comboBoxStartingCash = TheWindowManager->winGetWindowFromId( parentLanGameOptions, comboBoxStartingCashID );
  642. DEBUG_ASSERTCRASH(comboBoxStartingCash, ("Could not find the comboBoxStartingCash"));
  643. PopulateStartingCashComboBox(comboBoxStartingCash, TheLAN->GetMyGame());
  644. windowMap = TheWindowManager->winGetWindowFromId( parentLanGameOptions,windowMapID );
  645. DEBUG_ASSERTCRASH(windowMap, ("Could not find the LanGameOptionsMenu.wnd:MapWindow" ));
  646. Int localSlotNum = TheLAN->GetMyGame()->getLocalSlotNum();
  647. DEBUG_ASSERTCRASH(localSlotNum >= 0, ("Bad slot number!"));
  648. //Added By Sadullah Nader
  649. //Tooltip function is being set for techBuildings, and supplyDocks
  650. windowMap->winSetTooltipFunc(MapSelectorTooltip);
  651. //End Add
  652. for (Int i = 0; i < MAX_SLOTS; i++)
  653. {
  654. AsciiString tmpString;
  655. tmpString.format("LanGameOptionsMenu.wnd:ComboBoxPlayer%d", i);
  656. comboBoxPlayerID[i] = TheNameKeyGenerator->nameToKey( tmpString );
  657. comboBoxPlayer[i] = TheWindowManager->winGetWindowFromId( parentLanGameOptions, comboBoxPlayerID[i] );
  658. GadgetComboBoxReset(comboBoxPlayer[i]);
  659. GadgetComboBoxGetEditBox(comboBoxPlayer[i])->winSetTooltipFunc(playerTooltip);
  660. if(localSlotNum == i)
  661. {
  662. GadgetComboBoxAddEntry(comboBoxPlayer[i],TheLAN->GetMyName(),white);
  663. }
  664. else
  665. {
  666. GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:Open"),white);
  667. GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:Closed"),white);
  668. GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:EasyAI"),white);
  669. GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:MediumAI"),white);
  670. GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:HardAI"),white);
  671. GadgetComboBoxSetSelectedPos(comboBoxPlayer[i],0);
  672. }
  673. /*
  674. if(i != 0)
  675. {
  676. TheLAN->GetMyGame()->getLANSlot(i)->setState(SLOT_OPEN);
  677. }
  678. */
  679. tmpString.format("LanGameOptionsMenu.wnd:ComboBoxColor%d", i);
  680. comboBoxColorID[i] = TheNameKeyGenerator->nameToKey( tmpString );
  681. comboBoxColor[i] = TheWindowManager->winGetWindowFromId( parentLanGameOptions, comboBoxColorID[i] );
  682. DEBUG_ASSERTCRASH(comboBoxColor[i], ("Could not find the comboBoxColor[%d]",i ));
  683. PopulateColorComboBox(i, comboBoxColor, TheLAN->GetMyGame());
  684. GadgetComboBoxSetSelectedPos(comboBoxColor[i], 0);
  685. tmpString.format("LanGameOptionsMenu.wnd:ComboBoxPlayerTemplate%d", i);
  686. comboBoxPlayerTemplateID[i] = TheNameKeyGenerator->nameToKey( tmpString );
  687. comboBoxPlayerTemplate[i] = TheWindowManager->winGetWindowFromId( parentLanGameOptions, comboBoxPlayerTemplateID[i] );
  688. DEBUG_ASSERTCRASH(comboBoxPlayerTemplate[i], ("Could not find the comboBoxPlayerTemplate[%d]",i ));
  689. PopulatePlayerTemplateComboBox(i, comboBoxPlayerTemplate, TheLAN->GetMyGame(), TRUE);
  690. // add tooltips to the player template combobox and listbox
  691. comboBoxPlayerTemplate[i]->winSetTooltipFunc(playerTemplateComboBoxTooltip);
  692. GadgetComboBoxGetListBox(comboBoxPlayerTemplate[i])->winSetTooltipFunc(playerTemplateListBoxTooltip);
  693. tmpString.format("LanGameOptionsMenu.wnd:ComboBoxTeam%d", i);
  694. comboBoxTeamID[i] = TheNameKeyGenerator->nameToKey( tmpString );
  695. comboBoxTeam[i] = TheWindowManager->winGetWindowFromId( parentLanGameOptions, comboBoxTeamID[i] );
  696. DEBUG_ASSERTCRASH(comboBoxTeam[i], ("Could not find the comboBoxTeam[%d]",i ));
  697. PopulateTeamComboBox(i, comboBoxTeam, TheLAN->GetMyGame());
  698. tmpString.clear();
  699. tmpString.format("LanGameOptionsMenu.wnd:ButtonAccept%d", i);
  700. buttonAcceptID[i] = TheNameKeyGenerator->nameToKey( tmpString );
  701. buttonAccept[i] = TheWindowManager->winGetWindowFromId( parentLanGameOptions, buttonAcceptID[i] );
  702. DEBUG_ASSERTCRASH(buttonAccept[i], ("Could not find the buttonAccept[%d]",i ));
  703. //Added by Saad for the tooltips on the MultiPlayer icons
  704. buttonAccept[i]->winSetTooltipFunc(gameAcceptTooltip);
  705. //
  706. // tmpString.format("LanGameOptionsMenu.wnd:ButtonStartPosition%d", i);
  707. // buttonStartPositionID[i] = TheNameKeyGenerator->nameToKey( tmpString );
  708. // buttonStartPosition[i] = TheWindowManager->winGetWindowFromId( parentLanGameOptions, buttonStartPositionID[i] );
  709. // DEBUG_ASSERTCRASH(buttonStartPosition[i], ("Could not find the ButtonStartPosition[%d]",i ));
  710. tmpString.format("LanGameOptionsMenu.wnd:ButtonMapStartPosition%d", i);
  711. buttonMapStartPositionID[i] = TheNameKeyGenerator->nameToKey( tmpString );
  712. buttonMapStartPosition[i] = TheWindowManager->winGetWindowFromId( parentLanGameOptions, buttonMapStartPositionID[i] );
  713. DEBUG_ASSERTCRASH(buttonMapStartPosition[i], ("Could not find the ButtonMapStartPosition[%d]",i ));
  714. if(i !=0 && buttonAccept[i])
  715. buttonAccept[i]->winHide(TRUE);
  716. }
  717. if( buttonAccept[0] )
  718. GadgetButtonSetEnabledColor(buttonAccept[0], acceptTrueColor );
  719. }
  720. void DeinitLanGameGadgets( void )
  721. {
  722. parentLanGameOptions = NULL;
  723. buttonEmote = NULL;
  724. buttonSelectMap = NULL;
  725. buttonStart = NULL;
  726. buttonBack = NULL;
  727. listboxChatWindowLanGame = NULL;
  728. textEntryChat = NULL;
  729. textEntryMapDisplay = NULL;
  730. checkboxLimitSuperweapons = NULL;
  731. comboBoxStartingCash = NULL;
  732. windowMap = NULL;
  733. for (Int i = 0; i < MAX_SLOTS; i++)
  734. {
  735. comboBoxPlayer[i] = NULL;
  736. comboBoxColor[i] = NULL;
  737. comboBoxPlayerTemplate[i] = NULL;
  738. comboBoxTeam[i] = NULL;
  739. buttonAccept[i] = NULL;
  740. // buttonStartPosition[i] = NULL;
  741. buttonMapStartPosition[i] = NULL;
  742. }
  743. }
  744. //-------------------------------------------------------------------------------------------------
  745. /** Initialize the Lan Game Options Menu */
  746. //-------------------------------------------------------------------------------------------------
  747. void LanGameOptionsMenuInit( WindowLayout *layout, void *userData )
  748. {
  749. if (TheLAN->GetMyGame() && TheLAN->GetMyGame()->isGameInProgress())
  750. {
  751. // If we init while the game is in progress, we are really returning to the menu
  752. // after the game. So, we pop the menu and go back to the lobby. Whee!
  753. DEBUG_LOG(("Popping to lobby after a game!\n"));
  754. TheShell->popImmediate();
  755. return;
  756. }
  757. s_isIniting = TRUE;
  758. LANbuttonPushed = false;
  759. LANisShuttingDown = false;
  760. //initialize the gadgets
  761. EnableSlotListUpdates(FALSE);
  762. InitLanGameGadgets();
  763. EnableSlotListUpdates(TRUE);
  764. Int start = 0;
  765. // Make sure the text fields are clear
  766. GadgetListBoxReset( listboxChatWindowLanGame );
  767. GadgetTextEntrySetText(textEntryChat, UnicodeString::TheEmptyString);
  768. //The dialog needs to react differently depending on whether it's the host or not.
  769. TheMapCache->updateCache();
  770. if (TheLAN->AmIHost())
  771. {
  772. // read in some prefs
  773. LANGameInfo *game = TheLAN->GetMyGame();
  774. LANGameSlot *slot = game->getLANSlot(0);
  775. LANPreferences pref;
  776. slot->setColor( pref.getPreferredColor() );
  777. slot->setPlayerTemplate( pref.getPreferredFaction() );
  778. slot->setNATBehavior(FirewallHelperClass::FIREWALL_TYPE_SIMPLE);
  779. game->setMap( pref.getPreferredMap() );
  780. game->setStartingCash( pref.getStartingCash() );
  781. game->setSuperweaponRestriction( pref.getSuperweaponRestricted() ? 1 : 0 );
  782. AsciiString lowerMap = pref.getPreferredMap();
  783. lowerMap.toLower();
  784. std::map<AsciiString, MapMetaData>::iterator it = TheMapCache->find(lowerMap);
  785. if (it != TheMapCache->end())
  786. {
  787. TheLAN->GetMyGame()->getSlot(0)->setMapAvailability(true);
  788. TheLAN->GetMyGame()->setMapCRC( it->second.m_CRC );
  789. TheLAN->GetMyGame()->setMapSize( it->second.m_filesize );
  790. TheLAN->GetMyGame()->adjustSlotsForMap(); // BGC- adjust the slots for the selected map.
  791. }
  792. //GadgetTextEntrySetText(comboBoxPlayer[0], TheLAN->GetMyName());
  793. lanUpdateSlotList();
  794. updateGameOptions();
  795. start = 1; // leave my combo boxes usable
  796. }
  797. else
  798. {
  799. //DEBUG_LOG(("LanGameOptionsMenuInit(): map is %s\n", TheLAN->GetMyGame()->getMap().str()));
  800. buttonStart->winSetText(TheGameText->fetch("GUI:Accept"));
  801. buttonSelectMap->winEnable( FALSE );
  802. checkboxLimitSuperweapons->winEnable( FALSE ); // Can look but only host can touch
  803. comboBoxStartingCash->winEnable( FALSE ); // Ditto
  804. TheLAN->GetMyGame()->setMapCRC( TheLAN->GetMyGame()->getMapCRC() ); // force a recheck
  805. TheLAN->GetMyGame()->setMapSize( TheLAN->GetMyGame()->getMapSize() ); // of if we have the map
  806. TheLAN->RequestHasMap();
  807. lanUpdateSlotList();
  808. updateGameOptions();
  809. }
  810. for (Int i = start; i < MAX_SLOTS; ++i)
  811. {
  812. //I'm a client, disable the controls I can't touch.
  813. if (!TheLAN->AmIHost())
  814. comboBoxPlayer[i]->winEnable(FALSE);
  815. comboBoxColor[i]->winEnable(FALSE);
  816. comboBoxPlayerTemplate[i]->winEnable(FALSE);
  817. comboBoxTeam[i]->winEnable(FALSE);
  818. // buttonStartPosition[i]->winEnable(FALSE);
  819. }
  820. // for (i = 0; i < MAX_SLOTS; ++i)
  821. // {
  822. // if (buttonStartPosition[i])
  823. // buttonStartPosition[i]->winHide(TRUE); // not picking start spots this way any more
  824. // }
  825. //
  826. // Show the Menu
  827. layout->hide( FALSE );
  828. // Set Keyboard to Main Parent
  829. TheWindowManager->winSetFocus( parentLanGameOptions );
  830. s_isIniting = FALSE;
  831. if (TheLAN->AmIHost())
  832. {
  833. TheLAN->RequestGameOptions(GenerateGameOptionsString(),true);
  834. TheLAN->RequestGameAnnounce();
  835. }
  836. lanUpdateSlotList();
  837. LanPositionStartSpots();
  838. TheTransitionHandler->setGroup("LanGameOptionsFade");
  839. // animate controls
  840. //TheShell->registerWithAnimateManager(buttonBack, WIN_ANIMATION_SLIDE_RIGHT, TRUE, 1);
  841. }// void LanGameOptionsMenuInit( WindowLayout *layout, void *userData )
  842. //-------------------------------------------------------------------------------------------------
  843. /** Update options on screen */
  844. //-------------------------------------------------------------------------------------------------
  845. void updateGameOptions( void )
  846. {
  847. LANGameInfo *theGame = TheLAN->GetMyGame();
  848. UnicodeString mapDisplayName;
  849. if (theGame && AreSlotListUpdatesEnabled())
  850. {
  851. const GameSlot *localSlot = theGame->getConstSlot(theGame->getLocalSlotNum());
  852. const MapMetaData *mapData = TheMapCache->findMap( TheLAN->GetMyGame()->getMap() );
  853. if (mapData && localSlot && localSlot->hasMap())
  854. {
  855. mapDisplayName.format(L"%ls", mapData->m_displayName.str());
  856. }
  857. else
  858. {
  859. AsciiString s = TheLAN->GetMyGame()->getMap();
  860. if (s.reverseFind('\\'))
  861. {
  862. s = s.reverseFind('\\') + 1;
  863. }
  864. mapDisplayName.format(L"%hs", s.str());
  865. }
  866. UnicodeString old = GadgetStaticTextGetText(textEntryMapDisplay);
  867. if(old.compare(mapDisplayName) != 0)
  868. LanPositionStartSpots();
  869. GadgetStaticTextSetText(textEntryMapDisplay, mapDisplayName);
  870. GadgetCheckBoxSetChecked( checkboxLimitSuperweapons, theGame->getSuperweaponRestriction() != 0 );
  871. Int itemCount = GadgetComboBoxGetLength(comboBoxStartingCash);
  872. for ( Int index = 0; index < itemCount; index++ )
  873. {
  874. Int value = (Int)GadgetComboBoxGetItemData(comboBoxStartingCash, index);
  875. if ( value == theGame->getStartingCash().countMoney() )
  876. {
  877. GadgetComboBoxSetSelectedPos(comboBoxStartingCash, index, TRUE);
  878. break;
  879. }
  880. }
  881. DEBUG_ASSERTCRASH( index < itemCount, ("Could not find new starting cash amount %d in list", theGame->getStartingCash().countMoney() ) );
  882. }
  883. }
  884. //-------------------------------------------------------------------------------------------------
  885. /** This is called when a shutdown is complete for this menu */
  886. //-------------------------------------------------------------------------------------------------
  887. static void shutdownComplete( WindowLayout *layout )
  888. {
  889. DeinitLanGameGadgets();
  890. textEntryMapDisplay = NULL;
  891. LANisShuttingDown = false;
  892. // hide the layout
  893. layout->hide( TRUE );
  894. // our shutdown is complete
  895. TheShell->shutdownComplete( layout, (LANnextScreen != NULL) );
  896. if (LANnextScreen != NULL)
  897. {
  898. TheShell->push(LANnextScreen);
  899. }
  900. LANnextScreen = NULL;
  901. } // end if
  902. //-------------------------------------------------------------------------------------------------
  903. /** Lan Game Options menu shutdown method */
  904. //-------------------------------------------------------------------------------------------------
  905. void LanGameOptionsMenuShutdown( WindowLayout *layout, void *userData )
  906. {
  907. TheMouse->setCursor(Mouse::ARROW);
  908. TheMouse->setMouseText(UnicodeString::TheEmptyString,NULL,NULL);
  909. EnableSlotListUpdates(FALSE);
  910. LANisShuttingDown = true;
  911. // if we are shutting down for an immediate pop, skip the animations
  912. Bool popImmediate = *(Bool *)userData;
  913. if( popImmediate )
  914. {
  915. shutdownComplete( layout );
  916. return;
  917. } //end if
  918. TheShell->reverseAnimatewindow();
  919. TheTransitionHandler->reverse("LanGameOptionsFade");
  920. if (TheLAN)
  921. TheLAN->ResetGameStartTimer();
  922. /*
  923. // hide menu
  924. layout->hide( TRUE );
  925. // Reset the LAN singleton
  926. // TheLAN->reset();
  927. // our shutdown is complete
  928. TheShell->shutdownComplete( layout );
  929. */
  930. } // void LanGameOptionsMenuShutdown( WindowLayout *layout, void *userData )
  931. //-------------------------------------------------------------------------------------------------
  932. /** Lan Game Options menu update method */
  933. //-------------------------------------------------------------------------------------------------
  934. void LanGameOptionsMenuUpdate( WindowLayout * layout, void *userData)
  935. {
  936. if(LANisShuttingDown && TheShell->isAnimFinished() && TheTransitionHandler->isFinished())
  937. shutdownComplete(layout);
  938. //TheLAN->update(); // this is handled in the lobby
  939. }// void LanGameOptionsMenuUpdate( WindowLayout * layout, void *userData)
  940. //-------------------------------------------------------------------------------------------------
  941. /** Lan Game Options menu input callback */
  942. //-------------------------------------------------------------------------------------------------
  943. WindowMsgHandledType LanGameOptionsMenuInput( GameWindow *window, UnsignedInt msg,
  944. WindowMsgData mData1, WindowMsgData mData2 )
  945. {
  946. switch( msg )
  947. {
  948. // --------------------------------------------------------------------------------------------
  949. case GWM_CHAR:
  950. {
  951. UnsignedByte key = mData1;
  952. UnsignedByte state = mData2;
  953. if (LANbuttonPushed)
  954. break;
  955. switch( key )
  956. {
  957. // ----------------------------------------------------------------------------------------
  958. case KEY_ESC:
  959. {
  960. //
  961. // send a simulated selected event to the parent window of the
  962. // back/exit button
  963. //
  964. if( BitTest( state, KEY_STATE_UP ) )
  965. {
  966. TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  967. (WindowMsgData)buttonBack, buttonBackID );
  968. } // end if
  969. // don't let key fall through anywhere else
  970. return MSG_HANDLED;
  971. } // end escape
  972. } // end switch( key )
  973. } // end char
  974. } // end switch( msg )
  975. return MSG_IGNORED;
  976. }//WindowMsgHandledType LanGameOptionsMenuInput( GameWindow *window, UnsignedInt msg,
  977. //-------------------------------------------------------------------------------------------------
  978. /** Lan Game Options menu window system callback */
  979. //-------------------------------------------------------------------------------------------------
  980. WindowMsgHandledType LanGameOptionsMenuSystem( GameWindow *window, UnsignedInt msg,
  981. WindowMsgData mData1, WindowMsgData mData2 )
  982. {
  983. UnicodeString txtInput;
  984. switch( msg )
  985. {
  986. //-------------------------------------------------------------------------------------------------
  987. case GWM_CREATE:
  988. {
  989. break;
  990. } // case GWM_DESTROY:
  991. //-------------------------------------------------------------------------------------------------
  992. case GWM_DESTROY:
  993. {
  994. break;
  995. } // case GWM_DESTROY:
  996. //-------------------------------------------------------------------------------------------------
  997. case GWM_INPUT_FOCUS:
  998. {
  999. // if we're givin the opportunity to take the keyboard focus we must say we want it
  1000. if( mData1 == TRUE )
  1001. *(Bool *)mData2 = TRUE;
  1002. return MSG_HANDLED;
  1003. }//case GWM_INPUT_FOCUS:
  1004. //-------------------------------------------------------------------------------------------------
  1005. case GCM_SELECTED:
  1006. {
  1007. if (LANbuttonPushed)
  1008. break;
  1009. GameWindow *control = (GameWindow *)mData1;
  1010. Int controlID = control->winGetWindowId();
  1011. LANGameInfo *myGame = TheLAN->GetMyGame();
  1012. if ( controlID == comboBoxStartingCashID )
  1013. {
  1014. handleStartingCashSelection();
  1015. }
  1016. else
  1017. {
  1018. for (Int i = 0; i < MAX_SLOTS; i++)
  1019. {
  1020. if (controlID == comboBoxColorID[i])
  1021. {
  1022. handleColorSelection(i);
  1023. }
  1024. else if (controlID == comboBoxPlayerTemplateID[i])
  1025. {
  1026. handlePlayerTemplateSelection(i);
  1027. }
  1028. else if (controlID == comboBoxTeamID[i])
  1029. {
  1030. handleTeamSelection(i);
  1031. }
  1032. else if( controlID == comboBoxPlayerID[i] && myGame->amIHost() )
  1033. {
  1034. // We don't have anything that'll happen if we click on ourselves
  1035. if(i == myGame->getLocalSlotNum())
  1036. break;
  1037. // Get
  1038. Int pos = -1;
  1039. GadgetComboBoxGetSelectedPos(comboBoxPlayer[i], &pos);
  1040. if( pos != SLOT_PLAYER && pos >= 0)
  1041. {
  1042. if( myGame->getLANSlot(i)->getState() == SLOT_PLAYER )
  1043. {
  1044. UnicodeString name = myGame->getPlayerName(i);
  1045. myGame->getLANSlot(i)->setState(SlotState(pos));
  1046. myGame->resetAccepted();
  1047. TheLAN->OnPlayerLeave(name);
  1048. }
  1049. else if( myGame->getLANSlot(i)->getState() != pos )
  1050. {
  1051. Bool wasAI = (myGame->getLANSlot(i)->isAI());
  1052. myGame->getLANSlot(i)->setState(SlotState(pos));
  1053. Bool isAI = (myGame->getLANSlot(i)->isAI());
  1054. if (wasAI || isAI)
  1055. myGame->resetAccepted();
  1056. if (wasAI ^ isAI)
  1057. PopulatePlayerTemplateComboBox(i, comboBoxPlayerTemplate, myGame, wasAI);
  1058. if (!s_isIniting)
  1059. {
  1060. TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
  1061. lanUpdateSlotList();
  1062. }
  1063. }
  1064. }
  1065. break;
  1066. }
  1067. }
  1068. }
  1069. break;
  1070. }// case GCM_SELECTED:
  1071. //-------------------------------------------------------------------------------------------------
  1072. case GBM_SELECTED:
  1073. {
  1074. if (LANbuttonPushed)
  1075. break;
  1076. GameWindow *control = (GameWindow *)mData1;
  1077. Int controlID = control->winGetWindowId();
  1078. if ( controlID == buttonBackID )
  1079. {
  1080. if( mapSelectLayout )
  1081. {
  1082. mapSelectLayout->destroyWindows();
  1083. mapSelectLayout->deleteInstance();
  1084. mapSelectLayout = NULL;
  1085. }
  1086. TheLAN->RequestGameLeave();
  1087. //TheShell->pop();
  1088. } //if ( controlID == buttonBack )
  1089. else if ( controlID == buttonEmoteID )
  1090. {
  1091. // read the user's input
  1092. txtInput.set(GadgetTextEntryGetText( textEntryChat ));
  1093. // Clear the text entry line
  1094. GadgetTextEntrySetText(textEntryChat, UnicodeString::TheEmptyString);
  1095. // Clean up the text (remove leading/trailing chars, etc)
  1096. txtInput.trim();
  1097. // Echo the user's input to the chat window
  1098. if (!txtInput.isEmpty())
  1099. TheLAN->RequestChat(txtInput, LANAPIInterface::LANCHAT_EMOTE);
  1100. } //if ( controlID == buttonEmote )
  1101. else if ( controlID == buttonSelectMapID )
  1102. {
  1103. //buttonBack->winEnable( false );
  1104. mapSelectLayout = TheWindowManager->winCreateLayout( AsciiString( "Menus/LanMapSelectMenu.wnd" ) );
  1105. mapSelectLayout->runInit();
  1106. mapSelectLayout->hide( FALSE );
  1107. mapSelectLayout->bringForward();
  1108. }
  1109. else if ( controlID == buttonStartID )
  1110. {
  1111. if (TheLAN->AmIHost())
  1112. {
  1113. StartPressed();
  1114. //TheLAN->RequestGameStart();
  1115. }
  1116. else
  1117. {
  1118. //I'm the Client... send an accept message to the host.
  1119. TheLAN->RequestAccept();
  1120. // Disable the accept button
  1121. EnableAcceptControls(TRUE, TheLAN->GetMyGame(), comboBoxPlayer, comboBoxColor, comboBoxPlayerTemplate,
  1122. comboBoxTeam, buttonAccept, buttonStart, buttonMapStartPosition);
  1123. }
  1124. }
  1125. else if ( controlID == checkboxLimitSuperweaponsID )
  1126. {
  1127. handleLimitSuperweaponsClick();
  1128. }
  1129. else
  1130. {
  1131. for (Int i = 0; i < MAX_SLOTS; i++)
  1132. {
  1133. if (controlID == buttonMapStartPositionID[i])
  1134. {
  1135. LANGameInfo *game = TheLAN->GetMyGame();
  1136. Int playerIdxInPos = -1;
  1137. for (Int j=0; j<MAX_SLOTS; ++j)
  1138. {
  1139. LANGameSlot *slot = game->getLANSlot(j);
  1140. if (slot && slot->getStartPos() == i)
  1141. {
  1142. playerIdxInPos = j;
  1143. break;
  1144. }
  1145. }
  1146. if (playerIdxInPos >= 0)
  1147. {
  1148. LANGameSlot *slot = game->getLANSlot(playerIdxInPos);
  1149. if (playerIdxInPos == game->getLocalSlotNum() || (game->amIHost() && slot && slot->isAI()))
  1150. {
  1151. // it's one of my type. Try to change it.
  1152. Int nextPlayer = getNextSelectablePlayer(playerIdxInPos+1);
  1153. handleStartPositionSelection(playerIdxInPos, -1);
  1154. if (nextPlayer >= 0)
  1155. {
  1156. handleStartPositionSelection(nextPlayer, i);
  1157. }
  1158. }
  1159. }
  1160. else
  1161. {
  1162. // nobody in the slot - put us in
  1163. Int nextPlayer = getNextSelectablePlayer(0);
  1164. if (nextPlayer < 0)
  1165. nextPlayer = getFirstSelectablePlayer(game);
  1166. handleStartPositionSelection(nextPlayer, i);
  1167. }
  1168. }
  1169. }
  1170. }
  1171. break;
  1172. }// case GBM_SELECTED:
  1173. //-------------------------------------------------------------------------------------------------
  1174. case GBM_SELECTED_RIGHT:
  1175. {
  1176. if (LANbuttonPushed)
  1177. break;
  1178. GameWindow *control = (GameWindow *)mData1;
  1179. Int controlID = control->winGetWindowId();
  1180. for (Int i = 0; i < MAX_SLOTS; i++)
  1181. {
  1182. if (controlID == buttonMapStartPositionID[i])
  1183. {
  1184. LANGameInfo *game = TheLAN->GetMyGame();
  1185. Int playerIdxInPos = -1;
  1186. for (Int j=0; j<MAX_SLOTS; ++j)
  1187. {
  1188. LANGameSlot *slot = game->getLANSlot(j);
  1189. if (slot && slot->getStartPos() == i)
  1190. {
  1191. playerIdxInPos = j;
  1192. break;
  1193. }
  1194. }
  1195. if (playerIdxInPos >= 0)
  1196. {
  1197. LANGameSlot *slot = game->getLANSlot(playerIdxInPos);
  1198. if (playerIdxInPos == game->getLocalSlotNum() || (game->amIHost() && slot && slot->isAI()))
  1199. {
  1200. // it's one of my type. Remove it.
  1201. handleStartPositionSelection(playerIdxInPos, -1);
  1202. }
  1203. }
  1204. }
  1205. }
  1206. break;
  1207. }
  1208. //-------------------------------------------------------------------------------------------------
  1209. case GEM_EDIT_DONE:
  1210. {
  1211. if (LANbuttonPushed)
  1212. break;
  1213. GameWindow *control = (GameWindow *)mData1;
  1214. Int controlID = control->winGetWindowId();
  1215. // Take the user's input and echo it into the chat window as well as
  1216. // send it to the other clients on the lan
  1217. if ( controlID == textEntryChatID )
  1218. {
  1219. // read the user's input
  1220. txtInput.set(GadgetTextEntryGetText( textEntryChat ));
  1221. // Clear the text entry line
  1222. GadgetTextEntrySetText(textEntryChat, UnicodeString::TheEmptyString);
  1223. // Clean up the text (remove leading/trailing chars, etc)
  1224. txtInput.trim();
  1225. // Echo the user's input to the chat window
  1226. if (!txtInput.isEmpty())
  1227. TheLAN->RequestChat(txtInput, LANAPIInterface::LANCHAT_NORMAL);
  1228. }// if ( controlID == textEntryChatID )
  1229. break;
  1230. }
  1231. //-------------------------------------------------------------------------------------------------
  1232. default:
  1233. return MSG_IGNORED;
  1234. }//Switch
  1235. return MSG_HANDLED;
  1236. }//WindowMsgHandledType LanGameOptionsMenuSystem( GameWindow *window, UnsignedInt msg,
  1237. //-------------------------------------------------------------------------------------------------
  1238. /** Utility FUnction used as a bridge from other windows to this one */
  1239. //-------------------------------------------------------------------------------------------------
  1240. void PostToLanGameOptions( PostToLanGameType post )
  1241. {
  1242. if (post >= POST_TO_LAN_GAME_TYPE_COUNT)
  1243. return;
  1244. LanPositionStartSpots();
  1245. switch (post)
  1246. {
  1247. //-------------------------------------------------------------------------------------------------
  1248. case SEND_GAME_OPTS:
  1249. {
  1250. LANGameInfo *game = TheLAN->GetMyGame();
  1251. game->resetAccepted();
  1252. updateGameOptions();
  1253. lanUpdateSlotList();
  1254. //buttonBack->winEnable( true );
  1255. for(Int i = 0; i < MAX_SLOTS; ++i)
  1256. {
  1257. game->getSlot(i)->setStartPos(-1);
  1258. }
  1259. TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
  1260. break;
  1261. } //-------------------------------------------------------------------------------------------------
  1262. case MAP_BACK:
  1263. {
  1264. //buttonBack->winEnable( true );
  1265. }
  1266. default:
  1267. return;
  1268. }
  1269. }