SkirmishGameOptionsMenu.cpp 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844
  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. ///////////////////////////////////////////////////////////////////////////////////////
  24. // FILE: SkirmishGameOptionsMenu.cpp
  25. // Author: Chris Brue, August 2002
  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/BattleHonors.h"
  30. #include "Common/FileSystem.h"
  31. #include "Common/GameEngine.h"
  32. #include "Common/PlayerTemplate.h"
  33. #include "Common/QuotedPrintable.h"
  34. #include "Common/RandomValue.h"
  35. #include "Common/SkirmishBattleHonors.h"
  36. #include "Common/SkirmishPreferences.h"
  37. #include "GameLogic/GameLogic.h"
  38. #include "GameClient/AnimateWindowManager.h"
  39. #include "GameClient/WindowLayout.h"
  40. #include "GameClient/Gadget.h"
  41. #include "GameClient/Shell.h"
  42. #include "GameClient/ShellHooks.h"
  43. #include "GameClient/KeyDefs.h"
  44. #include "GameClient/GameWindowManager.h"
  45. #include "GameClient/GadgetListBox.h"
  46. #include "GameClient/GadgetComboBox.h"
  47. #include "GameClient/GadgetTextEntry.h"
  48. #include "GameClient/GadgetPushButton.h"
  49. #include "GameClient/GadgetSlider.h"
  50. #include "GameClient/GadgetStaticText.h"
  51. #include "GameClient/MapUtil.h"
  52. #include "GameClient/Mouse.h"
  53. #include "GameClient/GameWindowTransitions.h"
  54. #include "Common/MultiplayerSettings.h"
  55. #include "GameClient/GameText.h"
  56. #include "GameClient/CDCheck.h"
  57. #include "GameClient/ExtendedMessageBox.h"
  58. #include "GameClient/MessageBox.h"
  59. #include "GameNetwork/GameInfo.h"
  60. #include "GameNetwork/GUIUtil.h"
  61. #include "GameNetwork/IPEnumeration.h"
  62. #include "WWDownload/Registry.h"
  63. #ifdef _INTERNAL
  64. // for occasional debugging...
  65. //#pragma optimize("", off)
  66. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  67. #endif
  68. SkirmishGameInfo *TheSkirmishGameInfo = NULL;
  69. // window ids ------------------------------------------------------------------------------
  70. static NameKeyType parentSkirmishGameOptionsID = NAMEKEY_INVALID;
  71. static NameKeyType textEntryPlayerNameID = NAMEKEY_INVALID;
  72. static NameKeyType comboBoxPlayerID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
  73. NAMEKEY_INVALID,NAMEKEY_INVALID,
  74. NAMEKEY_INVALID,NAMEKEY_INVALID,
  75. NAMEKEY_INVALID,NAMEKEY_INVALID };
  76. static NameKeyType comboBoxColorID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
  77. NAMEKEY_INVALID,NAMEKEY_INVALID,
  78. NAMEKEY_INVALID,NAMEKEY_INVALID,
  79. NAMEKEY_INVALID,NAMEKEY_INVALID };
  80. static NameKeyType comboBoxPlayerTemplateID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
  81. NAMEKEY_INVALID,NAMEKEY_INVALID,
  82. NAMEKEY_INVALID,NAMEKEY_INVALID,
  83. NAMEKEY_INVALID,NAMEKEY_INVALID };
  84. static NameKeyType comboBoxTeamID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
  85. NAMEKEY_INVALID,NAMEKEY_INVALID,
  86. NAMEKEY_INVALID,NAMEKEY_INVALID,
  87. NAMEKEY_INVALID,NAMEKEY_INVALID };
  88. //static NameKeyType buttonStartPositionID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
  89. // NAMEKEY_INVALID,NAMEKEY_INVALID,
  90. // NAMEKEY_INVALID,NAMEKEY_INVALID,
  91. // NAMEKEY_INVALID,NAMEKEY_INVALID };
  92. static NameKeyType buttonMapStartPositionID[MAX_SLOTS] = { NAMEKEY_INVALID,NAMEKEY_INVALID,
  93. NAMEKEY_INVALID,NAMEKEY_INVALID,
  94. NAMEKEY_INVALID,NAMEKEY_INVALID,
  95. NAMEKEY_INVALID,NAMEKEY_INVALID };
  96. static NameKeyType textEntryMapDisplayID = NAMEKEY_INVALID;
  97. static NameKeyType buttonExitID = NAMEKEY_INVALID;
  98. static NameKeyType buttonStartID = NAMEKEY_INVALID;
  99. static NameKeyType buttonSelectMapID = NAMEKEY_INVALID;
  100. static NameKeyType buttonResetID = NAMEKEY_INVALID;
  101. static NameKeyType windowMapID = NAMEKEY_INVALID;
  102. static NameKeyType sliderGameSpeedID = NAMEKEY_INVALID;
  103. static NameKeyType staticTextGameSpeedID = NAMEKEY_INVALID;
  104. // Window Pointers ------------------------------------------------------------------------
  105. static GameWindow *staticTextGameSpeed = NULL;
  106. static GameWindow *parentSkirmishGameOptions = NULL;
  107. static GameWindow *buttonExit = NULL;
  108. static GameWindow *buttonStart = NULL;
  109. static GameWindow *buttonSelectMap = NULL;
  110. static GameWindow *textEntryMapDisplay = NULL;
  111. static GameWindow *buttonReset = NULL;
  112. static GameWindow *windowMap = NULL;
  113. static GameWindow *textEntryPlayerName = NULL;
  114. static GameWindow *comboBoxPlayer[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
  115. NULL,NULL,NULL,NULL };
  116. static GameWindow *comboBoxColor[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
  117. NULL,NULL,NULL,NULL };
  118. static GameWindow *comboBoxPlayerTemplate[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
  119. NULL,NULL,NULL,NULL };
  120. static GameWindow *comboBoxTeam[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
  121. NULL,NULL,NULL,NULL };
  122. //static GameWindow *buttonStartPosition[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
  123. // NULL,NULL,NULL,NULL };
  124. //
  125. static GameWindow *buttonMapStartPosition[MAX_SLOTS] = {NULL,NULL,NULL,NULL,
  126. NULL,NULL,NULL,NULL };
  127. //external declarations of the Gadgets the callbacks can use
  128. WindowLayout *skirmishMapSelectLayout = NULL;
  129. static Int initialGadgetDelay = 2;
  130. static Bool justEntered = FALSE;
  131. static Bool buttonPushed = FALSE;
  132. void skirmishUpdateSlotList( void );
  133. static void populateSkirmishBattleHonors( void );
  134. enum{ GREATER_NO_FPS_LIMIT = 60};
  135. Bool doUpdateSlotList = TRUE;
  136. static Int getNextSelectablePlayer(Int start)
  137. {
  138. if (!TheSkirmishGameInfo->amIHost())
  139. return -1;
  140. for (Int j=start; j<MAX_SLOTS; ++j)
  141. {
  142. GameSlot *slot = TheSkirmishGameInfo->getSlot(j);
  143. if (slot && slot->getStartPos() == -1 && (j==TheSkirmishGameInfo->getLocalSlotNum() || slot->isAI()))
  144. {
  145. return j;
  146. }
  147. }
  148. return -1;
  149. }
  150. SkirmishPreferences::SkirmishPreferences( void )
  151. {
  152. // note, the superclass will put this in the right dir automatically, this is just a leaf name
  153. load("Skirmish.ini");
  154. }
  155. SkirmishPreferences::~SkirmishPreferences()
  156. {
  157. }
  158. AsciiString SkirmishPreferences::getSlotList(void)
  159. {
  160. return getAsciiString("SlotList", AsciiString::TheEmptyString);
  161. }
  162. void SkirmishPreferences::setSlotList(void)
  163. {
  164. setAsciiString("SlotList", GameInfoToAsciiString(TheSkirmishGameInfo));
  165. }
  166. UnicodeString SkirmishPreferences::getUserName(void)
  167. {
  168. UnicodeString ret;
  169. SkirmishPreferences::const_iterator it = find("UserName");
  170. if (it == end())
  171. {
  172. IPEnumeration IPs;
  173. ret.translate(IPs.getMachineName());
  174. return ret;
  175. }
  176. ret = QuotedPrintableToUnicodeString(it->second);
  177. ret.trim();
  178. if (ret.isEmpty())
  179. {
  180. IPEnumeration IPs;
  181. ret.translate(IPs.getMachineName());
  182. return ret;
  183. }
  184. return ret;
  185. }
  186. Int SkirmishPreferences::getPreferredColor(void)
  187. {
  188. Int ret;
  189. SkirmishPreferences::const_iterator it = find("Color");
  190. if (it == end())
  191. {
  192. return -1;
  193. }
  194. ret = atoi(it->second.str());
  195. if (ret < -1 || ret >= TheMultiplayerSettings->getNumColors())
  196. ret = -1;
  197. return ret;
  198. }
  199. Int SkirmishPreferences::getPreferredFaction(void)
  200. {
  201. Int ret;
  202. SkirmishPreferences::const_iterator it = find("PlayerTemplate");
  203. if (it == end())
  204. {
  205. return PLAYERTEMPLATE_RANDOM;
  206. }
  207. ret = atoi(it->second.str());
  208. if (ret < PLAYERTEMPLATE_MIN || ret >= ThePlayerTemplateStore->getPlayerTemplateCount())
  209. ret = PLAYERTEMPLATE_RANDOM;
  210. if (ret >= 0)
  211. {
  212. const PlayerTemplate *fac = ThePlayerTemplateStore->getNthPlayerTemplate(ret);
  213. if (!fac)
  214. ret = PLAYERTEMPLATE_RANDOM;
  215. else if (fac->getStartingBuilding().isEmpty())
  216. ret = PLAYERTEMPLATE_RANDOM;
  217. }
  218. return ret;
  219. }
  220. Bool SkirmishPreferences::usesSystemMapDir(void)
  221. {
  222. OptionPreferences::const_iterator it = find("UseSystemMapDir");
  223. if (it == end())
  224. return TRUE;
  225. if (stricmp(it->second.str(), "yes") == 0) {
  226. return TRUE;
  227. }
  228. return FALSE;
  229. }
  230. AsciiString SkirmishPreferences::getPreferredMap(void)
  231. {
  232. AsciiString ret;
  233. SkirmishPreferences::const_iterator it = find("Map");
  234. if (it == end())
  235. {
  236. ret = getDefaultMap(TRUE);
  237. return ret;
  238. }
  239. ret = QuotedPrintableToAsciiString(it->second);
  240. ret.trim();
  241. if (ret.isEmpty() || !isValidMap(ret, TRUE))
  242. {
  243. ret = getDefaultMap(TRUE);
  244. return ret;
  245. }
  246. return ret;
  247. }
  248. Bool SkirmishPreferences::write(void)
  249. {
  250. if (!TheSkirmishGameInfo)
  251. return FALSE;
  252. AsciiString tmp;
  253. tmp.format("%d", TheSkirmishGameInfo->getConstSlot(0)->getColor());
  254. (*this)["Color"] = tmp;
  255. tmp.format("%d", TheSkirmishGameInfo->getConstSlot(0)->getPlayerTemplate());
  256. (*this)["PlayerTemplate"] = tmp;
  257. (*this)["Map"] = TheSkirmishGameInfo->getMap();
  258. (*this)["UserName"] = UnicodeStringToQuotedPrintable(TheSkirmishGameInfo->getConstSlot(0)->getName());
  259. setSlotList();
  260. // NameKeyType sliderGameSpeedID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:SliderGameSpeed" ) );
  261. GameWindow *sliderGameSpeed = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, sliderGameSpeedID );
  262. Int maxFPS = GadgetSliderGetPosition( sliderGameSpeed );
  263. setInt("FPS", maxFPS);
  264. return UserPreferences::write();
  265. }
  266. /*
  267. static void playerTooltip(GameWindow *window,
  268. WinInstanceData *instData,
  269. UnsignedInt mouse)
  270. {
  271. Int idx = -1;
  272. for (Int i=1; i<MAX_SLOTS; ++i)
  273. {
  274. if (window && window == GadgetComboBoxGetEditBox(comboBoxPlayer[i]))
  275. {
  276. idx = i;
  277. break;
  278. }
  279. }
  280. if (idx == -1)
  281. return;
  282. UnicodeString tooltip;
  283. /// @todo get this to display the correct tooltip for the player field CCB
  284. tooltip.format(TheGameText->fetch("TOOLTIP:LANPlayer") );
  285. TheMouse->setCursorTooltip( tooltip );
  286. }
  287. */
  288. void setFPSTextBox( Int sliderPos )
  289. {
  290. if(!staticTextGameSpeed)
  291. return;
  292. UnicodeString text;
  293. staticTextGameSpeed->winEnable(TRUE);
  294. if(sliderPos > GREATER_NO_FPS_LIMIT)
  295. {
  296. // set static text to --
  297. text.set(L"--");
  298. GadgetStaticTextSetText(staticTextGameSpeed, text);
  299. return;
  300. }
  301. else if( sliderPos == TheGlobalData->m_framesPerSecondLimit )
  302. {
  303. // set different color
  304. staticTextGameSpeed->winEnable(FALSE);
  305. }
  306. text.format(L"%2d", sliderPos);
  307. GadgetStaticTextSetText(staticTextGameSpeed, text);
  308. }
  309. void reallyDoStart( void )
  310. {
  311. if (TheGameLogic->isInGame())
  312. TheGameLogic->clearGameData(FALSE);
  313. //NameKeyType sliderGameSpeedID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:SliderGameSpeed" ) );
  314. GameWindow *sliderGameSpeed = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, sliderGameSpeedID );
  315. Int maxFPS = GadgetSliderGetPosition( sliderGameSpeed );
  316. DEBUG_LOG(("GameSpeedSlider was at %d\n", maxFPS));
  317. if (maxFPS > GREATER_NO_FPS_LIMIT)
  318. maxFPS = 1000;
  319. if (maxFPS < 15)
  320. maxFPS = 15;
  321. TheWritableGlobalData->m_mapName = TheSkirmishGameInfo->getMap();
  322. TheSkirmishGameInfo->startGame(0);
  323. InitGameLogicRandom(TheSkirmishGameInfo->getSeed());
  324. Bool isSkirmish = TRUE;
  325. const MapMetaData *md = TheMapCache->findMap(TheSkirmishGameInfo->getMap());
  326. if (md)
  327. {
  328. isSkirmish = md->m_isMultiplayer; // we can now select solo campaign maps in Skirmish.
  329. }
  330. if (isSkirmish)
  331. {
  332. GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_NEW_GAME );
  333. msg->appendIntegerArgument(GAME_SKIRMISH);
  334. msg->appendIntegerArgument(DIFFICULTY_NORMAL); // not really used; just specified so we can add the game speed last
  335. msg->appendIntegerArgument(0); // not really used; just specified so we can add the game speed last
  336. msg->appendIntegerArgument(maxFPS); // FPS limit
  337. }
  338. else
  339. {
  340. GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_NEW_GAME );
  341. msg->appendIntegerArgument(GAME_SINGLE_PLAYER);
  342. msg->appendIntegerArgument(DIFFICULTY_NORMAL); // not really used; just specified so we can add the game speed last
  343. msg->appendIntegerArgument(0); // not really used; just specified so we can add the game speed last
  344. msg->appendIntegerArgument(maxFPS); // FPS limit
  345. }
  346. }
  347. static MessageBoxReturnType cancelStartBecauseOfNoCD( void *userData )
  348. {
  349. buttonPushed = FALSE;
  350. return MB_RETURN_CLOSE;
  351. }
  352. Bool IsFirstCDPresent(void)
  353. {
  354. #if !defined(_INTERNAL) && !defined(_DEBUG)
  355. return TheFileSystem->areMusicFilesOnCD();
  356. #else
  357. return TRUE;
  358. #endif
  359. }
  360. static MessageBoxReturnType checkCDCallback( void *userData )
  361. {
  362. if (!IsFirstCDPresent())
  363. {
  364. return (IsFirstCDPresent())?MB_RETURN_CLOSE:MB_RETURN_KEEPOPEN;
  365. }
  366. else
  367. {
  368. gameStartCallback callback = (gameStartCallback)userData;
  369. if (callback)
  370. callback();
  371. return MB_RETURN_CLOSE;
  372. }
  373. }
  374. void CheckForCDAtGameStart( gameStartCallback callback )
  375. {
  376. if (!IsFirstCDPresent())
  377. {
  378. // popup a dialog asking for a CD
  379. ExMessageBoxOkCancel(TheGameText->fetch("GUI:InsertCDPrompt"), TheGameText->fetch("GUI:InsertCDMessage"),
  380. callback, checkCDCallback, cancelStartBecauseOfNoCD);
  381. }
  382. else
  383. {
  384. callback();
  385. }
  386. }
  387. Bool sandboxOk = FALSE;
  388. static void startPressed(void)
  389. {
  390. BOOL isReady = FALSE;
  391. Int playerCount = TheSkirmishGameInfo->getNumPlayers();
  392. AsciiString lowerMap = TheSkirmishGameInfo->getMap();
  393. lowerMap.toLower();
  394. std::map<AsciiString, MapMetaData>::iterator it = TheMapCache->find(lowerMap);
  395. if (it == TheMapCache->end())
  396. {
  397. buttonPushed = FALSE;
  398. MessageBoxOk(TheGameText->fetch("GUI:ErrorStartingGame"), TheGameText->fetch("GUI:CantFindMap"), NULL);
  399. }
  400. MapMetaData mmd = it->second;
  401. if(playerCount > mmd.m_numPlayers)
  402. {
  403. buttonPushed = FALSE;
  404. UnicodeString msg;
  405. msg.format(TheGameText->fetch("GUI:TooManyPlayers"), mmd.m_numPlayers);
  406. MessageBoxOk(TheGameText->fetch("GUI:ErrorStartingGame"), msg, NULL);
  407. }
  408. /*
  409. else if (playerCount < 2 && !sandboxOk)
  410. {
  411. sandboxOk = TRUE;
  412. MessageBoxOk(TheGameText->fetch("GUI:ErrorStartingGame"), TheGameText->fetch("GUI:SandboxWarning"), NULL);
  413. }
  414. */
  415. else
  416. {
  417. isReady = TRUE;
  418. }
  419. #if !defined(_PLAYTEST)
  420. if(isReady)
  421. {
  422. CheckForCDAtGameStart( reallyDoStart );
  423. }
  424. #endif
  425. }//void startPressed(void)
  426. /////////////////////////////////////////////////////
  427. // MapSelectorTooltip - shows tooltips for the tech buildings
  428. // and supply depots
  429. // Added By : Sadullah Nader
  430. /////////////////////////////////////////////////////
  431. void MapSelectorTooltip(GameWindow *window,
  432. WinInstanceData *instData,
  433. UnsignedInt mouse)
  434. {
  435. Int x, y;
  436. x = LOLONGTOSHORT(mouse);
  437. y = HILONGTOSHORT(mouse);
  438. Int pixelX, pixelY;
  439. window->winGetScreenPosition(&pixelX, &pixelY);
  440. const Image *image = TheMappedImageCollection->findImageByName("TecBuilding");
  441. const Image *image2 = TheMappedImageCollection->findImageByName("Cash");
  442. ICoord2DList::iterator it = TheSupplyAndTechImageLocations.m_techPosList.begin();
  443. ICoord2DList::iterator it2 = TheSupplyAndTechImageLocations.m_supplyPosList.begin();
  444. if( image )
  445. {
  446. // Check to see if we mouse over a tech building
  447. while(it != TheSupplyAndTechImageLocations.m_techPosList.end())
  448. {
  449. if ((x > (pixelX + it->x) && x < (pixelX + it->x + SUPPLY_TECH_SIZE))
  450. && ( y > (pixelY + it->y) && y < (pixelY + it->y + SUPPLY_TECH_SIZE)))
  451. {
  452. TheMouse->setCursorTooltip( TheGameText->fetch("TOOLTIP:TechBuilding"), -1, NULL); //, 1.5f
  453. return;
  454. }
  455. it++;
  456. }
  457. }
  458. if (image2)
  459. {
  460. // Check to see if we mouse over a supply dock
  461. while (it2 != TheSupplyAndTechImageLocations.m_supplyPosList.end())
  462. {
  463. if ((x > (pixelX + it2->x) && x < (pixelX + it2->x + SUPPLY_TECH_SIZE))
  464. && ( y > (pixelY + it2->y) && y < (pixelY + it2->y + SUPPLY_TECH_SIZE)))
  465. {
  466. TheMouse->setCursorTooltip( TheGameText->fetch("TOOLTIP:SupplyDock"), -1, NULL); // , 1.5f
  467. break;
  468. }
  469. it2++;
  470. }
  471. }
  472. }
  473. void positionStartSpotControls( GameWindow *win, GameWindow *mapWindow, Coord3D *pos, MapMetaData *mmd, GameWindow *buttonMapStartPositions[])
  474. {
  475. if(!win || !mmd || !mapWindow || !buttonMapStartPositions)
  476. return;
  477. DEBUG_ASSERTCRASH(win && mmd,("positionStartSpotControls:: we don't have a window to position or any mapmetadata"));
  478. ICoord2D winMapSize, winMapPos, gadgetPos, gadgetSize;
  479. mapWindow->winGetSize(&winMapSize.x, &winMapSize.y);
  480. mapWindow->winGetScreenPosition(&winMapPos.x, &winMapPos.y);
  481. win->winGetSize(&gadgetSize.x, &gadgetSize.y);
  482. ICoord2D ul, lr;
  483. findDrawPositions(0,0, winMapSize.x, winMapSize.y,mmd->m_extent, &ul, &lr);
  484. Int smallWidth = lr.x - ul.x;
  485. Int smallHeight= lr.y - ul.y;
  486. // When we actually draw the map, save off it's screen position and use that instead of the map window's position/size
  487. Real position;
  488. position = (pos->x - mmd->m_extent.lo.x) / (mmd->m_extent.hi.x - mmd->m_extent.lo.x);
  489. gadgetPos.x = (position * smallWidth) - gadgetSize.x /2 + ul.x;// + winMapPos.x;
  490. position = (pos->y - mmd->m_extent.lo.y) / (mmd->m_extent.hi.y - mmd->m_extent.lo.y);
  491. gadgetPos.y = ((1- position) * smallHeight) - gadgetSize.y /2 + ul.y;// + winMapPos.y;
  492. // loop through and make sure we're not on top of anyone else
  493. for(Int i = 0; i < MAX_SLOTS; ++i)
  494. {
  495. if(buttonMapStartPositions[i] == win)
  496. break;
  497. ICoord2D tempPos;
  498. buttonMapStartPositions[i]->winGetScreenPosition(&tempPos.x, &tempPos.y);
  499. // we're inside the other gadget
  500. if(gadgetPos.x > tempPos.x && gadgetPos.x < tempPos.x + gadgetSize.x
  501. && gadgetPos.y > tempPos.y && gadgetPos.y < tempPos.y + gadgetSize.y)
  502. {
  503. Int closerRight = tempPos.x + gadgetSize.x - gadgetPos.x;
  504. Int closerBottom = tempPos.y + gadgetSize.y - gadgetPos.y;
  505. // we're closer to the right then the bottom
  506. if( closerRight < closerBottom)
  507. gadgetPos.x = tempPos.x + gadgetSize.x + 1;
  508. else if( closerBottom < closerRight)
  509. gadgetPos.y = tempPos.y + gadgetSize.y + 1;
  510. else
  511. {
  512. gadgetPos.x = tempPos.x + gadgetSize.x + 1;
  513. gadgetPos.y = tempPos.y + gadgetSize.y + 1;
  514. }
  515. }
  516. }
  517. win->winSetPosition(gadgetPos.x,gadgetPos.y);
  518. }
  519. TechAndSupplyImages TheSupplyAndTechImageLocations;
  520. void positionAdditionalImages( MapMetaData *mmd, GameWindow *mapWindow, Bool force)
  521. {
  522. TheSupplyAndTechImageLocations.m_supplyPosList.clear();
  523. TheSupplyAndTechImageLocations.m_techPosList.clear();
  524. if( !mmd || !mapWindow || mapWindow->winIsHidden())
  525. return;
  526. static MapMetaData *prevMMD = NULL;
  527. if(force)
  528. prevMMD = NULL;
  529. // we already populated the supply and tech image locations.
  530. if(mmd == prevMMD)
  531. return;
  532. ICoord2D winMapSize, winMapPos;
  533. mapWindow->winGetSize(&winMapSize.x, &winMapSize.y);
  534. mapWindow->winGetScreenPosition(&winMapPos.x, &winMapPos.y);
  535. //SUPPLY_TECH_SIZE
  536. ICoord2D ul, lr;
  537. findDrawPositions(0,0, winMapSize.x, winMapSize.y,mmd->m_extent, &ul, &lr);
  538. Int smallWidth = lr.x - ul.x;
  539. Int smallHeight= lr.y - ul.y;
  540. Coord3DList::iterator it = mmd->m_supplyPositions.begin();
  541. // loop through and make sure we're not on top of anyone else
  542. while( it != mmd->m_supplyPositions.end())
  543. {
  544. ICoord2D markerPos;
  545. // When we actually draw the map, save off it's screen position and use that instead of the map window's position/size
  546. Real position;
  547. position = (it->x - mmd->m_extent.lo.x) / (mmd->m_extent.hi.x - mmd->m_extent.lo.x);
  548. markerPos.x = (position * smallWidth) - SUPPLY_TECH_SIZE /2 + ul.x;// + winMapPos.x;
  549. position = (it->y - mmd->m_extent.lo.y) / (mmd->m_extent.hi.y - mmd->m_extent.lo.y);
  550. markerPos.y = ((1- position) * smallHeight) - SUPPLY_TECH_SIZE /2 + ul.y;// + winMapPos.y;
  551. TheSupplyAndTechImageLocations.m_supplyPosList.push_front(markerPos);
  552. it++;
  553. }
  554. it = mmd->m_techPositions.begin();
  555. // loop through and make sure we're not on top of anyone else
  556. while( it != mmd->m_techPositions.end())
  557. {
  558. ICoord2D markerPos;
  559. // When we actually draw the map, save off it's screen position and use that instead of the map window's position/size
  560. Real position;
  561. position = (it->x - mmd->m_extent.lo.x) / (mmd->m_extent.hi.x - mmd->m_extent.lo.x);
  562. markerPos.x = (position * smallWidth) - SUPPLY_TECH_SIZE /2 + ul.x;// + winMapPos.x;
  563. position = (it->y - mmd->m_extent.lo.y) / (mmd->m_extent.hi.y - mmd->m_extent.lo.y);
  564. markerPos.y = ((1- position) * smallHeight) - SUPPLY_TECH_SIZE /2 + ul.y;// + winMapPos.y;
  565. TheSupplyAndTechImageLocations.m_techPosList.push_front(markerPos);
  566. it++;
  567. }
  568. //TheSupplyAndTechImageLocations
  569. }
  570. void positionStartSpots( AsciiString mapName, GameWindow *buttonMapStartPositions[], GameWindow *mapWindow)
  571. {
  572. AsciiString lowerMap = mapName;
  573. lowerMap.toLower();
  574. std::map<AsciiString, MapMetaData>::iterator it = TheMapCache->find(lowerMap);
  575. if (it == TheMapCache->end())
  576. {
  577. mapWindow->winSetUserData(NULL);
  578. static const Image *unknownImage = NULL;
  579. if (!unknownImage)
  580. unknownImage = TheMappedImageCollection->findImageByName("UnknownMap");
  581. if (unknownImage)
  582. {
  583. mapWindow->winSetStatus(WIN_STATUS_IMAGE);
  584. mapWindow->winSetEnabledImage(0, unknownImage);
  585. }
  586. else
  587. {
  588. mapWindow->winClearStatus(WIN_STATUS_IMAGE);
  589. }
  590. positionAdditionalImages(NULL, mapWindow, TRUE);
  591. for (Int i = 0; i < MAX_SLOTS; ++i)
  592. {
  593. if (buttonMapStartPositions[i] != NULL)
  594. {
  595. buttonMapStartPositions[i]->winHide(TRUE);
  596. }
  597. }
  598. }
  599. else
  600. {
  601. MapMetaData mmd = it->second;
  602. Image *image = getMapPreviewImage(mapName);
  603. if (mapWindow != NULL) {
  604. mapWindow->winSetUserData((void *)TheMapCache->findMap(mapName));
  605. if(image)
  606. {
  607. mapWindow->winSetStatus(WIN_STATUS_IMAGE);
  608. mapWindow->winSetEnabledImage(0, image);
  609. }
  610. else
  611. {
  612. static const Image *unknownImage = NULL;
  613. if (!unknownImage)
  614. unknownImage = TheMappedImageCollection->findImageByName("UnknownMap");
  615. if (unknownImage)
  616. {
  617. mapWindow->winSetStatus(WIN_STATUS_IMAGE);
  618. mapWindow->winSetEnabledImage(0, unknownImage);
  619. }
  620. else
  621. {
  622. mapWindow->winClearStatus(WIN_STATUS_IMAGE);
  623. }
  624. }
  625. }
  626. positionAdditionalImages(&mmd, mapWindow, TRUE);
  627. AsciiString waypointName;
  628. for(Int i = 0; i < mmd.m_numPlayers && mmd.m_isMultiplayer; ++i )
  629. {
  630. waypointName.format("Player_%d_Start", i+1); // start pos waypoints are 1-based
  631. WaypointMap::iterator wmIt = mmd.m_waypoints.find(waypointName);
  632. if( wmIt != mmd.m_waypoints.end())
  633. {
  634. Coord3D *pos = &wmIt->second;
  635. positionStartSpotControls(buttonMapStartPositions[i], mapWindow,pos, &mmd, buttonMapStartPositions);
  636. if (buttonMapStartPositions[i] != NULL)
  637. {
  638. buttonMapStartPositions[i]->winHide(FALSE);
  639. }
  640. }
  641. else
  642. {
  643. DEBUG_ASSERTCRASH(FALSE,("positionStartSpots:: someone messed with the map cash. We couldn't find waypoint <%s> in map <%s>", waypointName.str(),lowerMap.str()));
  644. }
  645. }
  646. // hide the rest
  647. for (; i < MAX_SLOTS; ++i)
  648. {
  649. if (buttonMapStartPositions[i] != NULL)
  650. {
  651. buttonMapStartPositions[i]->winHide(TRUE);
  652. }
  653. }
  654. }
  655. }
  656. void positionStartSpots( GameInfo *myGame, GameWindow *buttonMapStartPositions[], GameWindow *mapWindow)
  657. {
  658. AsciiString localMapFname = myGame->getMap();
  659. if (!myGame->isGameInProgress())
  660. {
  661. Int localIdx = myGame->getLocalSlotNum();
  662. if (localIdx == -1)
  663. localMapFname = AsciiString::TheEmptyString;
  664. else
  665. {
  666. if (!myGame->getConstSlot(localIdx)->hasMap())
  667. {
  668. localMapFname = AsciiString::TheEmptyString;
  669. }
  670. }
  671. }
  672. positionStartSpots(localMapFname, buttonMapStartPositions, mapWindow);
  673. }
  674. void updateMapStartSpots( GameInfo *myGame, GameWindow *buttonMapStartPositions[], Bool onLoadScreen )
  675. {
  676. AsciiString lowerMap = myGame->getMap();
  677. lowerMap.toLower();
  678. std::map<AsciiString, MapMetaData>::iterator it = TheMapCache->find(lowerMap);
  679. if (it == TheMapCache->end())
  680. {
  681. for (Int i = 0; i < MAX_SLOTS; ++i)
  682. buttonMapStartPositions[i]->winHide(TRUE);
  683. return;
  684. }
  685. MapMetaData mmd = it->second;
  686. for(Int i = 0; i < MAX_SLOTS; ++i)
  687. {
  688. GadgetButtonSetText(buttonMapStartPositions[i], UnicodeString::TheEmptyString);
  689. if (!onLoadScreen)
  690. {
  691. buttonMapStartPositions[i]->winSetTooltip(TheGameText->fetch("TOOLTIP:StartPosition"));
  692. }
  693. }
  694. for( i = 0; i < MAX_SLOTS; ++i)
  695. {
  696. GameSlot *gs =myGame->getSlot(i);
  697. if(onLoadScreen)
  698. {
  699. if(gs->getApparentStartPos() >=0 && gs->getApparentStartPos() < mmd.m_numPlayers && gs->getPlayerTemplate() > PLAYERTEMPLATE_MIN )
  700. {
  701. AsciiString displayNumber;
  702. displayNumber.format("NUMBER:%d",i + 1);
  703. GadgetButtonSetText(buttonMapStartPositions[gs->getApparentStartPos()], TheGameText->fetch(displayNumber));
  704. }
  705. }
  706. else
  707. {
  708. if(gs->getStartPos() >=0 && gs->getStartPos() < mmd.m_numPlayers && gs->getPlayerTemplate() > PLAYERTEMPLATE_MIN )
  709. {
  710. AsciiString displayNumber;
  711. displayNumber.format("NUMBER:%d",i + 1);
  712. GadgetButtonSetText(buttonMapStartPositions[gs->getStartPos()], TheGameText->fetch(displayNumber));
  713. //Added By Sadullah Nader
  714. //Fix for no tooltips at start positions
  715. //added start position tooltip
  716. //Fixed again to show the right number , ie "i + 1"
  717. UnicodeString temp;
  718. temp.format(TheGameText->fetch("TOOLTIP:StartPositionN"), i + 1);
  719. buttonMapStartPositions[gs->getStartPos()]->winSetTooltip(temp);
  720. }
  721. }
  722. }
  723. }
  724. static void handlePlayerSelection(int index)
  725. {
  726. if( index == 0 || index >=MAX_SLOTS)
  727. return;
  728. GameWindow *combo = comboBoxPlayer[index];
  729. Int playerType, selIndex;
  730. GadgetComboBoxGetSelectedPos(combo, &selIndex);
  731. UnicodeString title = GadgetComboBoxGetText(combo);
  732. playerType = (Int)GadgetComboBoxGetItemData(combo, selIndex);
  733. GameInfo *myGame = TheSkirmishGameInfo;
  734. if (myGame)
  735. {
  736. GameSlot * slot = myGame->getSlot(index);
  737. if(!slot)
  738. return;
  739. slot->setState(SlotState(playerType), title);
  740. }
  741. //skirmishUpdateSlotList();
  742. }
  743. static void handleColorSelection(int index)
  744. {
  745. GameWindow *combo = comboBoxColor[index];
  746. Int color, selIndex;
  747. GadgetComboBoxGetSelectedPos(combo, &selIndex);
  748. color = (Int)GadgetComboBoxGetItemData(combo, selIndex);
  749. GameInfo *myGame = TheSkirmishGameInfo;
  750. if (myGame)
  751. {
  752. GameSlot * slot = myGame->getSlot(index);
  753. if(!slot)
  754. return;
  755. if (color == slot->getColor())
  756. return;
  757. if (color >= -1 && color < TheMultiplayerSettings->getNumColors())
  758. {
  759. Bool colorAvailable = TRUE;
  760. if(color != -1 )
  761. {
  762. for(Int i=0; i <MAX_SLOTS; i++)
  763. {
  764. GameSlot *checkSlot = myGame->getSlot(i);
  765. if(checkSlot && color == checkSlot->getColor() && slot != checkSlot)
  766. {
  767. colorAvailable = FALSE;
  768. break;
  769. }
  770. }
  771. }
  772. if(!colorAvailable)
  773. return;
  774. }
  775. slot->setColor(color);
  776. }
  777. //skirmishUpdateSlotList();
  778. }
  779. static void handlePlayerTemplateSelection(int index)
  780. {
  781. GameWindow *combo = comboBoxPlayerTemplate[index];
  782. Int playerTemplate, selIndex;
  783. GadgetComboBoxGetSelectedPos(combo, &selIndex);
  784. playerTemplate = (Int)GadgetComboBoxGetItemData(combo, selIndex);
  785. GameInfo *myGame = TheSkirmishGameInfo;
  786. if (myGame)
  787. {
  788. GameSlot * slot = myGame->getSlot(index);
  789. if(!slot)
  790. return;
  791. if (playerTemplate == slot->getPlayerTemplate())
  792. return;
  793. slot->setPlayerTemplate(playerTemplate);
  794. }
  795. //skirmishUpdateSlotList();
  796. }
  797. static void handleStartPositionSelection(int index, Int position)
  798. {
  799. GameInfo *myGame = TheSkirmishGameInfo;
  800. if (myGame)
  801. {
  802. GameSlot * slot = myGame->getSlot(index);
  803. if (position == slot->getStartPos())
  804. return;
  805. if( position < 0)
  806. {
  807. slot->setStartPos(position);
  808. return;
  809. }
  810. Bool isAvailable = TRUE;
  811. for(Int i = 0; i < MAX_SLOTS; ++i)
  812. {
  813. if(i != index && myGame->getSlot(i)->getStartPos() == position)
  814. {
  815. isAvailable = FALSE;
  816. break;
  817. }
  818. }
  819. if(isAvailable)
  820. {
  821. slot->setStartPos(position);
  822. }
  823. }
  824. }
  825. static void handleTeamSelection(int index)
  826. {
  827. GameWindow *combo = comboBoxTeam[index];
  828. Int team, selIndex;
  829. GadgetComboBoxGetSelectedPos(combo, &selIndex);
  830. team = (Int)GadgetComboBoxGetItemData(combo, selIndex);
  831. GameInfo *myGame = TheSkirmishGameInfo;
  832. if (myGame)
  833. {
  834. GameSlot * slot = myGame->getSlot(index);
  835. if(!slot)
  836. return;
  837. if (team == slot->getTeamNumber())
  838. return;
  839. slot->setTeamNumber(team);
  840. }
  841. //skirmishUpdateSlotList();
  842. }
  843. //-------------------------------------------------------------------------------------------------
  844. /** Initialize the Gadgets Options Menu */
  845. //-------------------------------------------------------------------------------------------------
  846. void InitSkirmishGameGadgets( void )
  847. {
  848. //Initialize the gadget IDs
  849. parentSkirmishGameOptionsID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:SkirmishGameOptionsMenuParent" ) );
  850. buttonExitID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:ButtonBack" ) );
  851. buttonStartID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:ButtonStart" ) );
  852. textEntryMapDisplayID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:TextEntryMapDisplay" ) );
  853. buttonSelectMapID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:ButtonSelectMap" ) );
  854. buttonResetID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:ButtonReset" ) );
  855. windowMapID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:MapWindow" ) );
  856. staticTextGameSpeedID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:StaticTextGameSpeed" ) );
  857. // Initialize the pointers to our gadgets
  858. parentSkirmishGameOptions = TheWindowManager->winGetWindowFromId( NULL, parentSkirmishGameOptionsID );
  859. DEBUG_ASSERTCRASH(parentSkirmishGameOptions, ("Could not find the parentSkirmishGameOptions" ));
  860. buttonSelectMap = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions,buttonSelectMapID );
  861. DEBUG_ASSERTCRASH(buttonSelectMap, ("Could not find the buttonSelectMap"));
  862. buttonStart = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions,buttonStartID );
  863. DEBUG_ASSERTCRASH(buttonStart, ("Could not find the buttonStart"));
  864. buttonExit = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, buttonExitID);
  865. DEBUG_ASSERTCRASH(buttonExit, ("Could not find the buttonExit"));
  866. textEntryMapDisplay = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, textEntryMapDisplayID );
  867. DEBUG_ASSERTCRASH(textEntryMapDisplay, ("Could not find the textEntryMapDisplay"));
  868. buttonReset = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, buttonResetID );
  869. DEBUG_ASSERTCRASH(buttonReset, ("Could not find the buttonReset"));
  870. staticTextGameSpeed = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, staticTextGameSpeedID );
  871. DEBUG_ASSERTCRASH(staticTextGameSpeed, ("Could not find the staticTextGameSpeed"));
  872. textEntryPlayerNameID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:TextEntryPlayerName" ) );
  873. textEntryPlayerName = TheWindowManager->winGetWindowFromId( NULL, textEntryPlayerNameID );
  874. DEBUG_ASSERTCRASH(textEntryPlayerName, ("Could not find the textEntryPlayerName" ));
  875. windowMap = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions,windowMapID );
  876. DEBUG_ASSERTCRASH(windowMap, ("Could not find the SkirmishGameOptionsMenu.wnd:MapWindow" ));
  877. windowMap->winSetTooltipFunc(MapSelectorTooltip);
  878. for (Int i = 0; i < MAX_SLOTS; i++)
  879. {
  880. AsciiString tmpString;
  881. tmpString.format("SkirmishGameOptionsMenu.wnd:ComboBoxPlayer%d", i);
  882. if(i != 0)
  883. {
  884. comboBoxPlayerID[i] = TheNameKeyGenerator->nameToKey( tmpString );
  885. comboBoxPlayer[i] = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, comboBoxPlayerID[i] );
  886. GadgetComboBoxReset(comboBoxPlayer[i]);
  887. //GadgetComboBoxGetEditBox(comboBoxPlayer[i])->winSetTooltipFunc(playerTooltip);
  888. }
  889. Color white = GameMakeColor( 255, 255, 255, 255 );
  890. if( i == 0 )
  891. {
  892. GadgetTextEntrySetText(textEntryPlayerName, TheGameText->fetch("GUI:Player") );
  893. //GadgetComboBoxAddEntry(comboBoxPlayer[i], TheGameText->fetch( "GUI:Start" ), white);
  894. //GadgetComboBoxSetSelectedPos(comboBoxPlayer[i],0);
  895. }
  896. else
  897. {
  898. GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:Open"),white); // leave this first
  899. GadgetComboBoxSetItemData(comboBoxPlayer[i], 0, (void *)SLOT_OPEN);
  900. GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:Closed"),white); // leave this first
  901. GadgetComboBoxSetItemData(comboBoxPlayer[i], 1, (void *)SLOT_CLOSED);
  902. GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:EasyAI"),white);
  903. GadgetComboBoxSetItemData(comboBoxPlayer[i], 2, (void *)SLOT_EASY_AI);
  904. GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:MediumAI"),white);
  905. GadgetComboBoxSetItemData(comboBoxPlayer[i], 3, (void *)SLOT_MED_AI);
  906. GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:HardAI"),white);
  907. GadgetComboBoxSetItemData(comboBoxPlayer[i], 4, (void *)SLOT_BRUTAL_AI);
  908. GadgetComboBoxSetSelectedPos(comboBoxPlayer[i],0);
  909. }
  910. tmpString.format("SkirmishGameOptionsMenu.wnd:ComboBoxColor%d", i);
  911. comboBoxColorID[i] = TheNameKeyGenerator->nameToKey( tmpString );
  912. comboBoxColor[i] = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, comboBoxColorID[i] );
  913. DEBUG_ASSERTCRASH(comboBoxColor[i], ("Could not find the comboBoxColor[%d]",i ));
  914. tmpString.format("SkirmishGameOptionsMenu.wnd:ComboBoxPlayerTemplate%d", i);
  915. comboBoxPlayerTemplateID[i] = TheNameKeyGenerator->nameToKey( tmpString );
  916. comboBoxPlayerTemplate[i] = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, comboBoxPlayerTemplateID[i] );
  917. DEBUG_ASSERTCRASH(comboBoxPlayerTemplate[i], ("Could not find the comboBoxPlayerTemplate[%d]",i ));
  918. tmpString.format("SkirmishGameOptionsMenu.wnd:ComboBoxTeam%d", i);
  919. comboBoxTeamID[i] = TheNameKeyGenerator->nameToKey( tmpString );
  920. comboBoxTeam[i] = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, comboBoxTeamID[i] );
  921. DEBUG_ASSERTCRASH(comboBoxTeam[i], ("Could not find the comboBoxTeam[%d]",i ));
  922. // tmpString.format("SkirmishGameOptionsMenu.wnd:ButtonStartPosition%d", i);
  923. // buttonStartPositionID[i] = TheNameKeyGenerator->nameToKey( tmpString );
  924. // buttonStartPosition[i] = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, buttonStartPositionID[i] );
  925. // DEBUG_ASSERTCRASH(buttonStartPosition[i], ("Could not find the ButtonStartPosition[%d]",i ));
  926. //
  927. tmpString.format("SkirmishGameOptionsMenu.wnd:ButtonMapStartPosition%d", i);
  928. buttonMapStartPositionID[i] = TheNameKeyGenerator->nameToKey( tmpString );
  929. buttonMapStartPosition[i] = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, buttonMapStartPositionID[i] );
  930. DEBUG_ASSERTCRASH(buttonMapStartPosition[i], ("Could not find the ButtonMapStartPosition[%d]",i ));
  931. }
  932. for (i = 0; i < MAX_SLOTS; ++i)
  933. {
  934. PopulateColorComboBox(i, comboBoxColor, TheSkirmishGameInfo );
  935. GadgetComboBoxSetSelectedPos(comboBoxColor[i], 0);
  936. PopulatePlayerTemplateComboBox(i, comboBoxPlayerTemplate, TheSkirmishGameInfo, FALSE );
  937. PopulateTeamComboBox(i, comboBoxTeam, TheSkirmishGameInfo );
  938. // if (buttonStartPosition[i])
  939. // buttonStartPosition[i]->winHide(TRUE); // not using these right now
  940. }
  941. populateSkirmishBattleHonors();
  942. }
  943. void skirmishUpdateSlotList( void )
  944. {
  945. if(doUpdateSlotList)
  946. {
  947. doUpdateSlotList = FALSE;
  948. AsciiString lowerMap = TheSkirmishGameInfo->getMap();
  949. lowerMap.toLower();
  950. std::map<AsciiString, MapMetaData>::iterator it = TheMapCache->find(lowerMap);
  951. if (it != TheMapCache->end())
  952. {
  953. GadgetStaticTextSetText(textEntryMapDisplay, it->second.m_displayName);
  954. }
  955. GadgetTextEntrySetText( textEntryPlayerName, TheSkirmishGameInfo->getSlot(0)->getName() );
  956. UpdateSlotList( TheSkirmishGameInfo, comboBoxPlayer,
  957. comboBoxColor, comboBoxPlayerTemplate,
  958. comboBoxTeam, NULL, buttonStart, buttonMapStartPosition );
  959. updateMapStartSpots(TheSkirmishGameInfo, buttonMapStartPosition, FALSE);
  960. doUpdateSlotList = TRUE;
  961. }
  962. }
  963. void updateSkirmishGameOptions( void );
  964. void skirmishPositionStartSpots( void )
  965. {
  966. positionStartSpots( TheSkirmishGameInfo, buttonMapStartPosition, windowMap);
  967. updateSkirmishGameOptions();
  968. }
  969. //-------------------------------------------------------------------------------------------------
  970. /** Init TextEntryMapDisplay */
  971. //-------------------------------------------------------------------------------------------------
  972. void initSkirmishGameOptions( void )
  973. {
  974. }
  975. static const char *layoutFilename = "SkirmishGameOptionsMenu.wnd";
  976. static const char *parentName = "SkirmishGameOptionsMenuParent";
  977. static const char *gadgetsToHide[] =
  978. {
  979. "TextEntryPlayerName",
  980. "StaticTextPlayers",
  981. "StaticTextColor",
  982. "StaticTextTeam",
  983. "StaticTextFaction",
  984. NULL // keep this last
  985. };
  986. static const char *perPlayerGadgetsToHide[] =
  987. {
  988. "ComboBoxPlayer",
  989. "ComboBoxTeam",
  990. "ComboBoxColor",
  991. "ComboBoxPlayerTemplate",
  992. NULL // keep this last
  993. };
  994. //-------------------------------------------------------------------------------------------------
  995. /** Update options on screen */
  996. //-------------------------------------------------------------------------------------------------
  997. void updateSkirmishGameOptions( void )
  998. {
  999. Bool isSkirmish = TRUE;
  1000. const MapMetaData *md = TheMapCache->findMap(TheSkirmishGameInfo->getMap());
  1001. if (md)
  1002. {
  1003. isSkirmish = md->m_isMultiplayer; // we can now select solo campaign maps in Skirmish.
  1004. GadgetStaticTextSetText(textEntryMapDisplay, md->m_displayName);
  1005. }
  1006. else
  1007. {
  1008. DEBUG_CRASH(("map not found, should not happen"));
  1009. UnicodeString mapDisplay;
  1010. mapDisplay.translate(AsciiString(TheSkirmishGameInfo->getMap().str()));
  1011. GadgetStaticTextSetText(textEntryMapDisplay, mapDisplay);
  1012. }
  1013. if (isSkirmish)
  1014. {
  1015. ShowUnderlyingGUIElements(TRUE, layoutFilename, parentName, gadgetsToHide, perPlayerGadgetsToHide );
  1016. }
  1017. else
  1018. {
  1019. ShowUnderlyingGUIElements(FALSE, layoutFilename, parentName, gadgetsToHide, perPlayerGadgetsToHide );
  1020. for (Int i=1; i<MAX_SLOTS; ++i)
  1021. {
  1022. GadgetComboBoxSetSelectedPos(comboBoxPlayer[i], 0);
  1023. }
  1024. }
  1025. }
  1026. //-------------------------------------------------------------------------------------------------
  1027. /** Initialize the Skirmish Game Options Menu */
  1028. //-------------------------------------------------------------------------------------------------
  1029. void SkirmishGameOptionsMenuInit( WindowLayout *layout, void *userData )
  1030. {
  1031. if (TheGameEngine->getQuitting())
  1032. return;
  1033. sliderGameSpeedID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:SliderGameSpeed" ) );
  1034. sandboxOk = FALSE;
  1035. doUpdateSlotList = FALSE;
  1036. if( !TheSkirmishGameInfo )
  1037. {
  1038. TheSkirmishGameInfo = NEW SkirmishGameInfo;
  1039. SignalUIInteraction(SHELL_SCRIPT_HOOK_SKIRMISH_OPENED);
  1040. }
  1041. else if( TheSkirmishGameInfo->isInGame() )
  1042. {
  1043. TheSkirmishGameInfo->endGame();
  1044. }
  1045. else
  1046. {
  1047. SignalUIInteraction(SHELL_SCRIPT_HOOK_SKIRMISH_OPENED);
  1048. }
  1049. TheSkirmishGameInfo->init();
  1050. TheSkirmishGameInfo->clearSlotList();
  1051. TheSkirmishGameInfo->reset();
  1052. Int localIP = TheSkirmishGameInfo->getSlot(0)->getIP();
  1053. TheSkirmishGameInfo->setLocalIP(localIP);
  1054. TheSkirmishGameInfo->enterGame();
  1055. EnableSlotListUpdates(FALSE);
  1056. //initialize the gadgets
  1057. InitSkirmishGameGadgets();
  1058. EnableSlotListUpdates(TRUE);
  1059. SkirmishPreferences prefs;
  1060. GameSlot gSlot;
  1061. gSlot.setName(prefs.getUserName());
  1062. gSlot.setState( SLOT_PLAYER, prefs.getUserName() );
  1063. gSlot.setColor(prefs.getPreferredColor());
  1064. gSlot.setPlayerTemplate(prefs.getPreferredFaction());
  1065. TheSkirmishGameInfo->setSlot(0,gSlot);
  1066. SkirmishBattleHonors honors;
  1067. if (honors.getWins() > 10)
  1068. gSlot.setState(SLOT_BRUTAL_AI);
  1069. else if (honors.getWins() > 5)
  1070. gSlot.setState(SLOT_MED_AI);
  1071. else
  1072. gSlot.setState(SLOT_EASY_AI);
  1073. TheSkirmishGameInfo->setSlot(1, gSlot);
  1074. ParseAsciiStringToGameInfo(TheSkirmishGameInfo, prefs.getSlotList());
  1075. TheSkirmishGameInfo->setSeed(GetTickCount());
  1076. UnsignedInt isPreorder = 0;
  1077. GetUnsignedIntFromRegistry("", "Preorder", isPreorder);
  1078. if (isPreorder != 0)
  1079. {
  1080. TheSkirmishGameInfo->markPlayerAsPreorder(0);
  1081. }
  1082. TheSkirmishGameInfo->setMap(prefs.getPreferredMap());
  1083. const MapMetaData *md = TheMapCache->findMap(TheSkirmishGameInfo->getMap());
  1084. if (!md)
  1085. {
  1086. TheSkirmishGameInfo->setMapCRC(0);
  1087. TheSkirmishGameInfo->setMapSize(0);
  1088. }
  1089. else
  1090. {
  1091. TheSkirmishGameInfo->setMapCRC(md->m_CRC);
  1092. TheSkirmishGameInfo->setMapSize(md->m_filesize);
  1093. }
  1094. AsciiString lowerMap = prefs.getPreferredMap();
  1095. lowerMap.toLower();
  1096. std::map<AsciiString, MapMetaData>::iterator it = TheMapCache->find(lowerMap);
  1097. if (it != TheMapCache->end())
  1098. {
  1099. GadgetStaticTextSetText(textEntryMapDisplay, it->second.m_displayName);
  1100. }
  1101. skirmishPositionStartSpots();
  1102. //updateSkirmishGameOptions();
  1103. //initSkirmishGameOptions();
  1104. // set up the game speed slider
  1105. // NameKeyType sliderGameSpeedID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:SliderGameSpeed" ) );
  1106. GameWindow *sliderGameSpeed = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, sliderGameSpeedID );
  1107. Int sliderPos = max(15,min(61,prefs.getInt("FPS", TheGlobalData->m_framesPerSecondLimit)));
  1108. GadgetSliderSetPosition( sliderGameSpeed, sliderPos );
  1109. setFPSTextBox(sliderPos);
  1110. buttonStart->winSetText(TheGameText->fetch("GUI:Start"));
  1111. /* hey, for now we're also going to disable the map select button until it doesn't crash */
  1112. //buttonSelectMap->winEnable( FALSE );
  1113. //buttonSelectMap->winEnable( TRUE );
  1114. //updateSkirmishGameOptions();
  1115. for (Int i = 0; i < MAX_SLOTS; ++i)
  1116. {
  1117. comboBoxColor[i]->winEnable(TRUE);
  1118. comboBoxPlayerTemplate[i]->winEnable(TRUE);
  1119. comboBoxTeam[i]->winEnable(TRUE);
  1120. }
  1121. // Show the Menu
  1122. layout->hide( FALSE );
  1123. // Set Keyboard to Main Parent
  1124. TheWindowManager->winSetFocus( parentSkirmishGameOptions );
  1125. // animate controls
  1126. TheShell->showShellMap(TRUE);
  1127. // TheShell->registerWithAnimateManager(buttonExit, WIN_ANIMATION_SLIDE_RIGHT, TRUE, 1);
  1128. doUpdateSlotList = TRUE;
  1129. skirmishUpdateSlotList();
  1130. justEntered = TRUE;
  1131. initialGadgetDelay = 2;
  1132. GameWindow *win = TheWindowManager->winGetWindowFromId(NULL, TheNameKeyGenerator->nameToKey("SkirmishGameOptionsMenu.wnd:SubParent"));
  1133. if(win)
  1134. win->winHide(TRUE);
  1135. buttonPushed = FALSE;
  1136. }// void SkirmishGameOptionsMenuInit( WindowLayout *layout, void *userData )
  1137. //-------------------------------------------------------------------------------------------------
  1138. /** This is called when a shutdown is complete for this menu */
  1139. //-------------------------------------------------------------------------------------------------
  1140. static void shutdownComplete( WindowLayout *layout )
  1141. {
  1142. // hide the layout
  1143. layout->hide( TRUE );
  1144. TheShell->shutdownComplete( layout );
  1145. // our shutdown is complete
  1146. // what the munkees does this do?
  1147. //TheShell->shutdownComplete( layout, (LANnextScreen != NULL) );
  1148. //if (LANnextScreen != NULL)
  1149. //{
  1150. // TheShell->push(LANnextScreen);
  1151. //}
  1152. //LANnextScreen = NULL;
  1153. } // end if
  1154. //-------------------------------------------------------------------------------------------------
  1155. /** Skirmish Game Options menu shutdown method */
  1156. //-------------------------------------------------------------------------------------------------
  1157. void SkirmishGameOptionsMenuShutdown( WindowLayout *layout, void *userData )
  1158. {
  1159. SignalUIInteraction(SHELL_SCRIPT_HOOK_SKIRMISH_CLOSED);
  1160. TheMouse->setCursor(Mouse::ARROW);
  1161. TheMouse->setMouseText(UnicodeString::TheEmptyString,NULL,NULL);
  1162. // if we are shutting down for an immediate pop, skip the animations
  1163. Bool popImmediate = *(Bool *)userData;
  1164. if( popImmediate )
  1165. {
  1166. shutdownComplete( layout );
  1167. return;
  1168. } //end if
  1169. TheShell->reverseAnimatewindow();
  1170. // hide menu
  1171. // layout->hide( TRUE );
  1172. // our shutdown is complete
  1173. TheTransitionHandler->reverse("SkirmishGameOptionsMenuFade");
  1174. } // void SkirmishGameOptionsMenuShutdown( WindowLayout *layout, void *userData )
  1175. //-------------------------------------------------------------------------------------------------
  1176. /** Skirmish Game Options menu update method */
  1177. //-------------------------------------------------------------------------------------------------
  1178. void SkirmishGameOptionsMenuUpdate( WindowLayout * layout, void *userData)
  1179. {
  1180. if (TheGameLogic->isInShellGame() && TheGameLogic->getFrame() == 1)
  1181. {
  1182. SignalUIInteraction(SHELL_SCRIPT_HOOK_SKIRMISH_ENTERED_FROM_GAME);
  1183. }
  1184. if(justEntered)
  1185. {
  1186. if(initialGadgetDelay == 1)
  1187. {
  1188. TheTransitionHandler->setGroup("SkirmishGameOptionsMenuFade");
  1189. TheWindowManager->winSetFocus( parentSkirmishGameOptions );
  1190. initialGadgetDelay = 2;
  1191. justEntered = FALSE;
  1192. }
  1193. else
  1194. initialGadgetDelay--;
  1195. }
  1196. if(TheShell->isAnimFinished() && TheTransitionHandler->isFinished())
  1197. TheShell->shutdownComplete( layout );
  1198. }// void SkirmishGameOptionsMenuUpdate( WindowLayout * layout, void *userData)
  1199. //-------------------------------------------------------------------------------------------------
  1200. /** Skirmish Game Options menu input callback */
  1201. //-------------------------------------------------------------------------------------------------
  1202. WindowMsgHandledType SkirmishGameOptionsMenuInput( GameWindow *window, UnsignedInt msg,
  1203. WindowMsgData mData1, WindowMsgData mData2 )
  1204. {
  1205. switch( msg )
  1206. {
  1207. // --------------------------------------------------------------------------------------------
  1208. case GWM_CHAR:
  1209. {
  1210. UnsignedByte key = mData1;
  1211. UnsignedByte state = mData2;
  1212. switch( key )
  1213. {
  1214. // ----------------------------------------------------------------------------------------
  1215. case KEY_ESC:
  1216. {
  1217. //
  1218. // send a simulated selected event to the parent window of the
  1219. // back/exit button
  1220. //
  1221. if( BitTest( state, KEY_STATE_UP ) )
  1222. {
  1223. TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  1224. (WindowMsgData)buttonExit, buttonExitID );
  1225. } // end if
  1226. // don't let key fall through anywhere else
  1227. return MSG_HANDLED;
  1228. } // end escape
  1229. } // end switch( key )
  1230. } // end char
  1231. break;
  1232. } // end switch( msg )
  1233. return MSG_IGNORED;
  1234. }//WindowMsgHandledType SkirmishGameOptionsMenuInput( GameWindow *window, UnsignedInt msg,
  1235. //-------------------------------------------------------------------------------------------------
  1236. /** Skirmish Game Options menu window system callback */
  1237. //-------------------------------------------------------------------------------------------------
  1238. WindowMsgHandledType SkirmishGameOptionsMenuSystem( GameWindow *window, UnsignedInt msg,
  1239. WindowMsgData mData1, WindowMsgData mData2 )
  1240. {
  1241. UnicodeString txtInput;
  1242. switch( msg )
  1243. {
  1244. //-------------------------------------------------------------------------------------------------
  1245. case GWM_CREATE:
  1246. {
  1247. break;
  1248. } // case GWM_DESTROY:
  1249. //-------------------------------------------------------------------------------------------------
  1250. case GWM_DESTROY:
  1251. {
  1252. break;
  1253. } // case GWM_DESTROY:
  1254. //-------------------------------------------------------------------------------------------------
  1255. case GWM_INPUT_FOCUS:
  1256. {
  1257. // if we're givin the opportunity to take the keyboard focus we must say we want it
  1258. if( mData1 == TRUE )
  1259. *(Bool *)mData2 = TRUE;
  1260. return MSG_HANDLED;
  1261. }//case GWM_INPUT_FOCUS:
  1262. //-------------------------------------------------------------------------------------------------
  1263. case GCM_SELECTED:
  1264. {
  1265. GameWindow *control = (GameWindow *)mData1;
  1266. Int controlID = control->winGetWindowId();
  1267. for (Int i = 0; i < MAX_SLOTS; i++)
  1268. {
  1269. if (controlID == comboBoxColorID[i])
  1270. {
  1271. handleColorSelection(i);
  1272. }
  1273. else if (controlID == comboBoxPlayerTemplateID[i])
  1274. {
  1275. handlePlayerTemplateSelection(i);
  1276. }
  1277. else if (controlID == comboBoxTeamID[i])
  1278. {
  1279. handleTeamSelection(i);
  1280. }
  1281. else if (controlID == comboBoxPlayerID[i])
  1282. {
  1283. handlePlayerSelection(i);
  1284. }
  1285. }
  1286. sandboxOk = FALSE;
  1287. skirmishUpdateSlotList();
  1288. }// case GCM_SELECTED:
  1289. //-------------------------------------------------------------------------------------------------
  1290. case GSM_SLIDER_TRACK:
  1291. {
  1292. GameWindow *control = (GameWindow *)mData1;
  1293. Int sliderPos = (Int)mData2;
  1294. Int controlID = control->winGetWindowId();
  1295. if(controlID == sliderGameSpeedID)
  1296. {
  1297. setFPSTextBox(sliderPos);
  1298. }
  1299. }
  1300. //-------------------------------------------------------------------------------------------------
  1301. case GBM_SELECTED:
  1302. {
  1303. GameWindow *control = (GameWindow *)mData1;
  1304. Int controlID = control->winGetWindowId();
  1305. /// static NameKeyType buttonResetFPSID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:ButtonResetFPS" ) );
  1306. if(buttonPushed)
  1307. break;
  1308. if ( controlID == buttonExitID )
  1309. {
  1310. buttonPushed = TRUE;
  1311. SkirmishPreferences prefs;
  1312. prefs.write();
  1313. if( skirmishMapSelectLayout )
  1314. {
  1315. skirmishMapSelectLayout->destroyWindows();
  1316. skirmishMapSelectLayout->deleteInstance();
  1317. skirmishMapSelectLayout = NULL;
  1318. }
  1319. TheShell->pop();
  1320. delete TheSkirmishGameInfo;
  1321. TheSkirmishGameInfo = NULL;
  1322. } //if ( controlID == buttonBack )
  1323. // else if ( controlID == buttonResetFPSID )
  1324. // {
  1325. // static NameKeyType sliderGameSpeedID = TheNameKeyGenerator->nameToKey( AsciiString( "SkirmishGameOptionsMenu.wnd:SliderGameSpeed" ) );
  1326. // GameWindow *sliderGameSpeed = TheWindowManager->winGetWindowFromId( parentSkirmishGameOptions, sliderGameSpeedID );
  1327. // GadgetSliderSetPosition( sliderGameSpeed, TheGlobalData->m_framesPerSecondLimit );
  1328. // }
  1329. else if ( controlID == buttonSelectMapID )
  1330. {
  1331. sandboxOk = FALSE;
  1332. //buttonBack->winEnable( false );
  1333. skirmishMapSelectLayout = TheWindowManager->winCreateLayout( AsciiString( "Menus/SkirmishMapSelectMenu.wnd" ) );
  1334. skirmishMapSelectLayout->runInit();
  1335. skirmishMapSelectLayout->hide( FALSE );
  1336. skirmishMapSelectLayout->bringForward();
  1337. }
  1338. else if ( controlID == buttonStartID )
  1339. {
  1340. buttonPushed = TRUE;
  1341. SkirmishPreferences prefs;
  1342. prefs.write();
  1343. startPressed();
  1344. }
  1345. else if ( controlID == buttonResetID )
  1346. {
  1347. SkirmishBattleHonors stats;
  1348. stats.clear();
  1349. stats.write();
  1350. populateSkirmishBattleHonors();
  1351. }
  1352. else
  1353. {
  1354. for (Int i = 0; i < MAX_SLOTS; i++)
  1355. {
  1356. if (controlID == buttonMapStartPositionID[i])
  1357. {
  1358. Int playerIdxInPos = -1;
  1359. for (Int j=0; j<MAX_SLOTS; ++j)
  1360. {
  1361. GameSlot *slot = TheSkirmishGameInfo->getSlot(j);
  1362. if (slot && slot->getStartPos() == i)
  1363. {
  1364. playerIdxInPos = j;
  1365. break;
  1366. }
  1367. }
  1368. if (playerIdxInPos >= 0)
  1369. {
  1370. GameSlot *slot = TheSkirmishGameInfo->getSlot(playerIdxInPos);
  1371. if (playerIdxInPos == TheSkirmishGameInfo->getLocalSlotNum() || (TheSkirmishGameInfo->amIHost() && slot && slot->isAI()))
  1372. {
  1373. // it's one of my type. Try to change it.
  1374. Int nextPlayer = getNextSelectablePlayer(playerIdxInPos+1);
  1375. handleStartPositionSelection(playerIdxInPos, -1);
  1376. if (nextPlayer >= 0)
  1377. {
  1378. handleStartPositionSelection(nextPlayer, i);
  1379. }
  1380. }
  1381. }
  1382. else
  1383. {
  1384. // nobody in the slot - put us in
  1385. Int nextPlayer = getNextSelectablePlayer(0);
  1386. if (nextPlayer < 0)
  1387. nextPlayer = TheSkirmishGameInfo->getLocalSlotNum();
  1388. handleStartPositionSelection(nextPlayer, i);
  1389. }
  1390. skirmishUpdateSlotList();
  1391. sandboxOk = FALSE;
  1392. }
  1393. }
  1394. }
  1395. break;
  1396. }// case GBM_SELECTED:
  1397. //-------------------------------------------------------------------------------------------------
  1398. case GBM_SELECTED_RIGHT:
  1399. {
  1400. GameWindow *control = (GameWindow *)mData1;
  1401. Int controlID = control->winGetWindowId();
  1402. for (Int i = 0; i < MAX_SLOTS; i++)
  1403. {
  1404. if (controlID == buttonMapStartPositionID[i])
  1405. {
  1406. Int playerIdxInPos = -1;
  1407. for (Int j=0; j<MAX_SLOTS; ++j)
  1408. {
  1409. GameSlot *slot = TheSkirmishGameInfo->getSlot(j);
  1410. if (slot && slot->getStartPos() == i)
  1411. {
  1412. playerIdxInPos = j;
  1413. break;
  1414. }
  1415. }
  1416. if (playerIdxInPos >= 0)
  1417. {
  1418. GameSlot *slot = TheSkirmishGameInfo->getSlot(playerIdxInPos);
  1419. if (playerIdxInPos == TheSkirmishGameInfo->getLocalSlotNum() || (TheSkirmishGameInfo->amIHost() && slot && slot->isAI()))
  1420. {
  1421. // it's one of my type. Remove it.
  1422. handleStartPositionSelection(playerIdxInPos, -1);
  1423. }
  1424. skirmishUpdateSlotList();
  1425. sandboxOk = FALSE;
  1426. }
  1427. }
  1428. }
  1429. break;
  1430. }
  1431. //-------------------------------------------------------------------------------------------------
  1432. case GEM_EDIT_DONE:
  1433. case GEM_UPDATE_TEXT:
  1434. {
  1435. GameWindow *control = (GameWindow *)mData1;
  1436. Int controlID = control->winGetWindowId();
  1437. if( controlID == textEntryPlayerNameID)
  1438. {
  1439. TheSkirmishGameInfo->getSlot(0)->setName(GadgetTextEntryGetText(textEntryPlayerName));
  1440. //GadgetTextEntrySetText( textEntryPlayerName, TheSkirmishGameInfo->getSlot(0)->getName() );
  1441. }
  1442. break;
  1443. }
  1444. //-------------------------------------------------------------------------------------------------
  1445. default:
  1446. return MSG_IGNORED;
  1447. }//Switch
  1448. return MSG_HANDLED;
  1449. }
  1450. void populateSkirmishBattleHonors(void)
  1451. {
  1452. GameWindow *list = TheWindowManager->winGetWindowFromId(NULL, NAMEKEY("SkirmishGameOptionsMenu.wnd:ListboxInfo"));
  1453. if (!list)
  1454. return;
  1455. SkirmishBattleHonors stats;
  1456. list->winSetTooltipFunc(BattleHonorTooltip);
  1457. GadgetListBoxReset( list );
  1458. Int column = 0;
  1459. Int row = 0;
  1460. Int honors = stats.getHonors();
  1461. //Int challenge = stats.getChallengeMedals();
  1462. UnicodeString uStr;
  1463. GameWindow *streakWindow = TheWindowManager->winGetWindowFromId( NULL, NAMEKEY("SkirmishGameOptionsMenu.wnd:StaticTextStreakValue") );
  1464. if (streakWindow)
  1465. {
  1466. uStr.format(L"%d", stats.getWinStreak());
  1467. GadgetStaticTextSetText(streakWindow, uStr);
  1468. }
  1469. GameWindow *bestStreakWindow = TheWindowManager->winGetWindowFromId( NULL, NAMEKEY("SkirmishGameOptionsMenu.wnd:StaticTextBestStreakValue") );
  1470. if (bestStreakWindow)
  1471. {
  1472. uStr.format(L"%d", stats.getBestWinStreak());
  1473. GadgetStaticTextSetText(bestStreakWindow, uStr);
  1474. }
  1475. GameWindow *winsWindow = TheWindowManager->winGetWindowFromId( NULL, NAMEKEY("SkirmishGameOptionsMenu.wnd:StaticTextWinsValue") );
  1476. if (winsWindow)
  1477. {
  1478. uStr.format(L"%d", stats.getWins());
  1479. GadgetStaticTextSetText(winsWindow, uStr);
  1480. }
  1481. GameWindow *lossesWindow = TheWindowManager->winGetWindowFromId( NULL, NAMEKEY("SkirmishGameOptionsMenu.wnd:StaticTextLossesValue") );
  1482. if (lossesWindow)
  1483. {
  1484. uStr.format(L"%d", stats.getLosses());
  1485. GadgetStaticTextSetText(lossesWindow, uStr);
  1486. }
  1487. ResetBattleHonorInsertion();
  1488. GadgetListBoxAddEntryImage(list, NULL, 0, 0, 10, 10, TRUE, GameMakeColor(255,255,255,255));
  1489. row = 1;
  1490. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorCampaignChina"), (honors & BATTLE_HONOR_CAMPAIGN_CHINA),
  1491. BATTLE_HONOR_CAMPAIGN_CHINA, row, column);
  1492. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorCampaignGLA"), (honors & BATTLE_HONOR_CAMPAIGN_GLA),
  1493. BATTLE_HONOR_CAMPAIGN_GLA, row, column);
  1494. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorCampaignUSA"), (honors & BATTLE_HONOR_CAMPAIGN_USA),
  1495. BATTLE_HONOR_CAMPAIGN_USA, row, column);
  1496. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorAirWing"), (honors & BATTLE_HONOR_AIR_WING),
  1497. BATTLE_HONOR_AIR_WING, row, column);
  1498. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorBattleTank"), (honors & BATTLE_HONOR_BATTLE_TANK),
  1499. BATTLE_HONOR_BATTLE_TANK, row, column);
  1500. GadgetListBoxAddEntryImage(list, NULL, 2, 0, 10, 10, TRUE, GameMakeColor(255,255,255,255));
  1501. row = 3;
  1502. // endurance medals
  1503. MapCache::const_iterator it;
  1504. Bool missingEasy = FALSE;
  1505. Bool missingMedium = FALSE;
  1506. Bool missingBrutal = FALSE;
  1507. for (it = TheMapCache->begin(); it != TheMapCache->end(); ++it)
  1508. {
  1509. if (!it->second.m_isOfficial || !it->second.m_isMultiplayer)
  1510. continue;
  1511. Bool easy = TRUE;
  1512. Bool med = TRUE;
  1513. Bool hard = TRUE;
  1514. if (stats.getEnduranceMedal(it->first, SLOT_EASY_AI) == 0)
  1515. easy = FALSE;
  1516. if (stats.getEnduranceMedal(it->first, SLOT_MED_AI) == 0)
  1517. med = FALSE;
  1518. if (stats.getEnduranceMedal(it->first, SLOT_BRUTAL_AI) == 0)
  1519. hard = FALSE;
  1520. if (!easy && !med && !hard)
  1521. missingEasy = TRUE;
  1522. if (!med && !hard)
  1523. missingMedium = TRUE;
  1524. if (!hard)
  1525. missingBrutal = TRUE;
  1526. }
  1527. if (!missingBrutal)
  1528. {
  1529. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("Challenge_Gold"), TRUE,
  1530. BATTLE_HONOR_ENDURANCE, row, column);
  1531. }
  1532. else if (!missingMedium)
  1533. {
  1534. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("Challenge_Silver"), TRUE,
  1535. BATTLE_HONOR_ENDURANCE, row, column);
  1536. }
  1537. else if (!missingEasy)
  1538. {
  1539. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("Challenge_Bronz"), TRUE,
  1540. BATTLE_HONOR_ENDURANCE, row, column);
  1541. }
  1542. else
  1543. {
  1544. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("Challenge_Bronz"), FALSE,
  1545. BATTLE_HONOR_ENDURANCE, row, column);
  1546. }
  1547. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("Apocalypse"), (honors & BATTLE_HONOR_APOCALYPSE),
  1548. BATTLE_HONOR_APOCALYPSE, row, column);
  1549. if (honors & BATTLE_HONOR_BLITZ5)
  1550. {
  1551. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorBlitz5"), TRUE,
  1552. BATTLE_HONOR_BLITZ5, row, column);
  1553. }
  1554. else if (honors & BATTLE_HONOR_BLITZ10)
  1555. {
  1556. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorBlitz10"), TRUE,
  1557. BATTLE_HONOR_BLITZ10, row, column);
  1558. }
  1559. else
  1560. {
  1561. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorBlitz10"), FALSE,
  1562. BATTLE_HONOR_BLITZ10, row, column);
  1563. }
  1564. uStr.format(L"%10d", stats.getBestWinStreak());
  1565. if(honors & BATTLE_HONOR_STREAK_25)
  1566. {
  1567. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorStreak_G"), TRUE,
  1568. BATTLE_HONOR_STREAK_25, row, column, uStr);
  1569. }
  1570. else if(honors & BATTLE_HONOR_STREAK_10)
  1571. {
  1572. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorStreak_S"), TRUE,
  1573. BATTLE_HONOR_STREAK_10, row, column, uStr);
  1574. }
  1575. else if(honors & BATTLE_HONOR_STREAK_3)
  1576. {
  1577. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorStreak_B"), TRUE,
  1578. BATTLE_HONOR_STREAK_3, row, column, uStr);
  1579. }
  1580. else
  1581. {
  1582. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorStreak_B"), FALSE,
  1583. BATTLE_HONOR_STREAK_3, row, column);
  1584. }
  1585. /*
  1586. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("Loyalty_USA"), (honors & BATTLE_HONOR_LOYALTY_USA),
  1587. BATTLE_HONOR_LOYALTY_USA, row, column);
  1588. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("Loyalty_China"), (honors & BATTLE_HONOR_LOYALTY_CHINA),
  1589. BATTLE_HONOR_LOYALTY_CHINA, row, column);
  1590. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("Loyalty_GLA"), (honors & BATTLE_HONOR_LOYALTY_GLA),
  1591. BATTLE_HONOR_LOYALTY_GLA, row, column);
  1592. */
  1593. /*
  1594. if(BitTest(challenge, BH_CHALLENGE_MASK_7))
  1595. {
  1596. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorChallenge7"), TRUE,
  1597. BATTLE_HONOR_CHALLENGE, row, column);
  1598. }
  1599. else if (BitTest(challenge, BH_CHALLENGE_MASK_6))
  1600. {
  1601. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorChallenge6"), TRUE,
  1602. BATTLE_HONOR_CHALLENGE, row, column);
  1603. }
  1604. else if (BitTest(challenge, BH_CHALLENGE_MASK_5))
  1605. {
  1606. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorChallenge5"), TRUE,
  1607. BATTLE_HONOR_CHALLENGE, row, column);
  1608. }
  1609. else if (BitTest(challenge, BH_CHALLENGE_MASK_4))
  1610. {
  1611. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorChallenge4"), TRUE,
  1612. BATTLE_HONOR_CHALLENGE, row, column);
  1613. }
  1614. else if (BitTest(challenge, BH_CHALLENGE_MASK_3))
  1615. {
  1616. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorChallenge3"), TRUE,
  1617. BATTLE_HONOR_CHALLENGE, row, column);
  1618. }
  1619. else if (BitTest(challenge, BH_CHALLENGE_MASK_2))
  1620. {
  1621. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorChallenge2"), TRUE,
  1622. BATTLE_HONOR_CHALLENGE, row, column);
  1623. }
  1624. else if (BitTest(challenge, BH_CHALLENGE_MASK_1))
  1625. {
  1626. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorChallenge1"), TRUE,
  1627. BATTLE_HONOR_CHALLENGE, row, column);
  1628. }
  1629. else
  1630. {
  1631. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("HonorChallenge1"), FALSE,
  1632. BATTLE_HONOR_CHALLENGE, row, column);
  1633. }
  1634. */
  1635. UnsignedInt isPreorder = 0;
  1636. GetUnsignedIntFromRegistry("", "Preorder", isPreorder);
  1637. if (isPreorder != 0)
  1638. {
  1639. InsertBattleHonor(list, TheMappedImageCollection->findImageByName("OfficersClub"), TRUE,
  1640. BATTLE_HONOR_OFFICERSCLUB, row, column);
  1641. }
  1642. }