SkirmishGameOptionsMenu.cpp 70 KB

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