MPParameterScreen.cpp 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415
  1. #define MPPARAMETERSCREEN_CPP
  2. /*************************************************************************************************\
  3. MPParameterScreen.cpp : Implementation of the MPParameterScreen component.
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. \*************************************************************************************************/
  8. #include "MPParameterScreen.h"
  9. #include "prefs.h"
  10. #include "IniFile.h"
  11. #include "../MCLib/UserInput.h"
  12. #include "..\resource.h"
  13. #include "assert.h"
  14. #include "Multplyr.h"
  15. #include "MechBayScreen.h"
  16. #include "LogisticsData.h"
  17. #include "Comndr.h"
  18. #include "MissionBriefingScreen.h"
  19. #include "ChatWindow.h"
  20. extern bool quitGame;
  21. #ifndef GAMESOUND_H
  22. #include "gamesound.h"
  23. #endif
  24. #define MP_PLAYER_PREFS 120
  25. #define MAP_INFO 121
  26. #define CHECK_BUTTON 200
  27. #define MP_INCREMENT_DROPWEIGHT 198
  28. #define MP_DECREMENT_DROPWEIGHT 199
  29. #define MP_INCREMENT_CBILLS 200
  30. #define MP_DECREMENT_CBILLS 201
  31. #define MP_INCREMENT_TIME 202
  32. #define MP_DECREMENT_TIME 203
  33. #define MP_INCREMENT_RP 204
  34. #define MP_DECREMENT_RP 205
  35. #define MP_AIRSTRIKES 206
  36. #define MP_SENSOR_PROBE 207
  37. #define MP_MINELAYER 208
  38. #define MP_REPAIR 209
  39. #define MP_LOCKGAME 210
  40. #define MP_BOOTPLAYER 211
  41. #define MP_SCOUTS 212
  42. #define MP_RECOVERY 213
  43. #define MP_GUARDTOWER 214
  44. #define MP_RESOURCE_BLDG 215
  45. #define MP_UNLIMITED_AMMO 216
  46. #define MP_VARIANTS 217
  47. #define MP_ALLTECH 218
  48. #define MP_QUICKSTART 219
  49. #define MP_RP_FORMMECHS 220
  50. #define MP_INCREMENT_PLAYER_CBILLS 250
  51. #define MP_DECREMENT_PLAYER_CBILLS 251
  52. static const int FIRST_BUTTON_ID = 1000010;
  53. static const int OK_BUTTON_ID = 1000001;
  54. static const int CANCEL_BUTTON_ID = 1000002;
  55. MPParameterScreen* MPParameterScreen::s_instance = NULL;
  56. GUID NO_VERSION_GUID = {
  57. 0,0,0,0,0,0,0,0,0,0,0
  58. };
  59. const char* pPurchaseFiles[5] =
  60. {
  61. "purchase_Steiner",
  62. "purchase_Davion",
  63. "purchase_Liao",
  64. "purchase_Clan",
  65. "purchase_All"
  66. };
  67. MPParameterScreen::MPParameterScreen()
  68. {
  69. status = RUNNING;
  70. helpTextArrayID = 12;
  71. bMapInfoDlg = 0;
  72. bShowNoMapDlg = 0;
  73. bBootDlg = 0;
  74. bErrorDlg = 0;
  75. bHostLeftDlg = 0;
  76. bDisconnectDlg = 0;
  77. chatToSend = IDS_MP_PARAMETER_NO_MAP_CHAT;
  78. s_instance = this;
  79. }
  80. MPParameterScreen::~MPParameterScreen()
  81. {
  82. //ONLY destroy the 0 member. All of the other were set equal which means deleting their pointers will crash!!
  83. // Well DONE.
  84. //
  85. playerParameters[0].factionDropList.destroy();
  86. playerParameters[0].teamNumberDropList.destroy();
  87. for (int i=1;i<MAX_MC_PLAYERS;i++)
  88. {
  89. playerParameters[i].factionDropList.specialDestroy();
  90. playerParameters[i].teamNumberDropList.specialDestroy();
  91. }
  92. }
  93. int MPParameterScreen::indexOfButtonWithID(int id)
  94. {
  95. int i;
  96. for (i = 0; i < buttonCount; i++)
  97. {
  98. if (buttons[i].getID() == id)
  99. {
  100. return i;
  101. }
  102. }
  103. return -1;
  104. }
  105. void MPParameterScreen::init(FitIniFile* file)
  106. {
  107. LogisticsScreen::init( *file, "Static", "Text", "Rect", "Button" );
  108. if ( buttonCount )
  109. {
  110. for ( int i = 0; i < buttonCount; i++ )
  111. {
  112. long id = buttons[i].getID();
  113. if ( (id < MP_INCREMENT_DROPWEIGHT || id > MP_DECREMENT_RP)
  114. && id != MP_LOCKGAME && id != MP_BOOTPLAYER )
  115. buttons[i].setMessageOnRelease();
  116. if (buttons[i].getID() == 0)
  117. {
  118. buttons[i].setID(FIRST_BUTTON_ID + i);
  119. }
  120. if ( id != MB_MSG_NEXT && id != MB_MSG_PREV
  121. && id != MP_PLAYER_PREFS && id != MB_MSG_MAINMENU )
  122. {
  123. buttons[i].setPressFX( LOG_VIDEOBUTTONS );
  124. buttons[i].setHighlightFX( LOG_DIGITALHIGHLIGHT );
  125. buttons[i].setDisabledFX( LOG_WRONGBUTTON );
  126. }
  127. }
  128. }
  129. int curY = 0;
  130. playerParameters[0].init( file, "PlayerParams" );
  131. for ( int i = 1; i < MAX_MC_PLAYERS; i++ )
  132. {
  133. playerParameters[i] = playerParameters[0];
  134. curY = i * (playerParameters[i].bottom() - playerParameters[i].top() + 5);
  135. playerParameters[i].move( 0, curY );
  136. }
  137. FullPathFileName path;
  138. path.init( artPath, "mcl_mp_loadmap", ".fit" );
  139. FitIniFile mpFile;
  140. if ( NO_ERR != mpFile.open( path ) )
  141. {
  142. char error[256];
  143. sprintf( error, "couldn't open file %s", path );
  144. Assert( 0, 0, error );
  145. return;
  146. }
  147. mpLoadMap.init( &mpFile );
  148. mapInfoDlg.init();
  149. for ( i = 0; i < editCount; i++ )
  150. {
  151. edits[i].setNumeric( true );
  152. edits[i].allowIME( false );
  153. }
  154. edits[0].limitEntry( 4 );
  155. edits[1].limitEntry( 3 );
  156. edits[2].limitEntry( 2 );
  157. edits[3].limitEntry( 6 );
  158. }
  159. void MPParameterScreen::begin()
  160. {
  161. fadeOutTime = 0.f;
  162. fadeTime = 0.f;
  163. MPlayer->setMode(MULTIPLAYER_MODE_PARAMETERS);
  164. playerCount = 0;
  165. bLoading = 0;
  166. bMapInfoDlg = 0;
  167. bShowNoMapDlg = 0;
  168. bBootDlg = 0;
  169. bErrorDlg = 0;
  170. bDisconnectDlg = 0;
  171. MPlayer->initParametersScreen();
  172. if ( MPlayer->isHost() )
  173. setMission( MPlayer->missionSettings.map, (status != UP && status != NEXT) ? 1 : 0 );
  174. else
  175. setMissionClientOnly( MPlayer->missionSettings.map );
  176. delayTime = 0.f;
  177. status = RUNNING;
  178. bHostLeftDlg = 0;
  179. bootPlayerID = -1;
  180. for ( int i = 0; i < MAX_MC_PLAYERS; i++ )
  181. {
  182. playerParameters[i].insigniaName.Empty();
  183. }
  184. bWaitingToStart = 0;
  185. }
  186. void MPParameterScreen::end()
  187. {
  188. if ( status == PREVIOUS )
  189. MPlayer->closeSession();
  190. else if ( status == GOTOSPLASH )
  191. {
  192. MPlayer->closeSession();
  193. delete MPlayer;
  194. MPlayer = NULL;
  195. }
  196. bLoading = 0;
  197. statics[15].setTexture( ( unsigned long)0 );
  198. delayTime = 0.f;
  199. bHostLeftDlg = 0;
  200. }
  201. void MPParameterScreen::render(int xOffset, int yOffset )
  202. {
  203. if ( VERSION_STATUS_UNKNOWN == MPlayer->getVersionStatus() )
  204. {
  205. if ( bErrorDlg )
  206. {
  207. LogisticsOneButtonDialog::instance()->render();
  208. }
  209. return;
  210. }
  211. if ( status == NEXT && MPlayer->missionSettings.quickStart )
  212. {
  213. xOffset = 0;
  214. yOffset = 0;
  215. }
  216. LogisticsScreen::render(xOffset, yOffset);
  217. if ( bMapInfoDlg )
  218. {
  219. mapInfoDlg.render();
  220. }
  221. else if ( bLoading )
  222. {
  223. mpLoadMap.render( );
  224. }
  225. else if ( bShowNoMapDlg || bBootDlg || bDisconnectDlg )
  226. {
  227. LogisticsOKDialog::instance()->render();
  228. }
  229. else if ( bErrorDlg )
  230. {
  231. LogisticsOneButtonDialog::instance()->render();
  232. }
  233. else if ( !xOffset && !yOffset )
  234. {
  235. aPlayerParams* pFocus = 0;
  236. for ( int i = 0; i < playerCount; i++ )
  237. {
  238. if ( playerParameters[i].hasFocus() )
  239. pFocus = & playerParameters[i];
  240. playerParameters[i].render();
  241. }
  242. if ( pFocus )
  243. pFocus->render();
  244. ChatWindow::instance()->render(xOffset, yOffset);
  245. }
  246. if ( bHostLeftDlg )
  247. {
  248. LogisticsOneButtonDialog::instance()->render();
  249. }
  250. }
  251. void MPParameterScreen::render()
  252. {
  253. render(0, 0);
  254. }
  255. int MPParameterScreen::handleMessage( unsigned long message, unsigned long who)
  256. {
  257. if ( RUNNING == status )
  258. {
  259. switch ( who )
  260. {
  261. case 57/*MB_MSG_MAINMENU*/:
  262. {
  263. getButton( 57/*MB_MSG_MAINMENU*/ )->press( 0 );
  264. if (MPlayer->commanderID > -1) {
  265. MC2Player* pInfo = MPlayer->getPlayerInfo( MPlayer->commanderID );
  266. if ( pInfo->ready )
  267. pInfo->ready = 0;
  268. if (!MPlayer->isHost())
  269. {
  270. MPlayer->sendPlayerUpdate( 0, 5, MPlayer->commanderID );
  271. }
  272. }
  273. status = MAINMENU;
  274. }
  275. break;
  276. case 51/*MB_MSG_PREV*/:
  277. {
  278. getButton( 51/*MB_MSG_PREV*/ )->press( 0 );
  279. LogisticsOKDialog::instance()->setText( IDS_PROMPT_TO_DISCONNECT, IDS_DIALOG_NO, IDS_DIALOG_YES );
  280. LogisticsOKDialog::instance()->begin();
  281. bDisconnectDlg = true;
  282. }
  283. break;
  284. case 50/*MB_MSG_NEXT*/:
  285. {
  286. if (MPlayer->isHost())
  287. MPlayer->setInProgress(true);
  288. delayTime += frameLength;
  289. char text[256];
  290. cLoadString( IDS_MPLAYER_GAME_ABOUT_TO_START, text, 255 );
  291. MPlayer->sendChat( 0, -1, text );
  292. }
  293. break;
  294. case 101/*load map button*/:
  295. {
  296. //load map
  297. getButton( 101/*load map button*/ )->press( 0 );
  298. bLoading = true;
  299. mpLoadMap.begin();
  300. return 1;
  301. }
  302. break;
  303. case 102/*add ai player*/:
  304. {
  305. //add ai
  306. getButton( 102/*add ai player*/ )->press( 0 );
  307. status = DOWN;
  308. return 1;
  309. }
  310. break;
  311. case MAP_INFO:
  312. bMapInfoDlg = true;
  313. mapInfoDlg.setMap( MPlayer->missionSettings.map );
  314. mapInfoDlg.begin();
  315. break;
  316. case MP_PLAYER_PREFS:
  317. {
  318. MC2Player* pInfo = MPlayer->getPlayerInfo( MPlayer->commanderID );
  319. if ( pInfo->ready )
  320. pInfo->ready = 0;
  321. if (!MPlayer->isHost())
  322. {
  323. MPlayer->sendPlayerUpdate( 0, 5, MPlayer->commanderID );
  324. }
  325. status = UP;
  326. }
  327. break;
  328. case MP_LOCKGAME:
  329. if ( getButton( MP_LOCKGAME )->isPressed() )
  330. {
  331. MPlayer->setLocked( true );
  332. }
  333. else
  334. MPlayer->setLocked( false );
  335. break;
  336. case MP_BOOTPLAYER:
  337. {
  338. for( int i = 0; i < playerCount; i++ )
  339. {
  340. if ( playerParameters[i].isSelected() )
  341. {
  342. if ( MPlayer->commanderID == playerParameters[i].getCommanderID() )
  343. {
  344. soundSystem->playDigitalSample( LOG_WRONGBUTTON );
  345. return 0;
  346. }
  347. char str[256];
  348. cLoadString( IDS_MP_PARAMTERS_BOOT_PROMPT, str, 255 );
  349. char finalStr[256];
  350. for ( int j = 0; j < MAX_MC_PLAYERS; j++ )
  351. {
  352. if ( MPlayer->playerList[j].commanderID
  353. == playerParameters[i].getCommanderID() )
  354. {
  355. sprintf( finalStr, str, MPlayer->playerList[j].name );
  356. LogisticsOKDialog::instance()->setText( IDS_DIALOG_OK, IDS_DIALOG_NO, IDS_DIALOG_YES );
  357. LogisticsOKDialog::instance()->setText( finalStr );
  358. LogisticsOKDialog::instance()->begin();
  359. bBootDlg = true;
  360. bootPlayerID = MPlayer->playerList[j].commanderID;
  361. return 0;
  362. }
  363. }
  364. break;
  365. }
  366. }
  367. // if we got here, there was no selected player
  368. LogisticsOneButtonDialog::instance()->setText( IDS_MP_PARAMETERS_CANT_BOOT, IDS_DIALOG_OK, IDS_DIALOG_OK );
  369. LogisticsOneButtonDialog::instance()->begin();
  370. bErrorDlg = true;
  371. }
  372. break;
  373. case MP_INCREMENT_DROPWEIGHT:
  374. MPlayer->missionSettings.dropWeight +=10;
  375. MPParameterScreen::resetCheckBoxes();
  376. if ( MPlayer->missionSettings.dropWeight > 1200 )
  377. MPlayer->missionSettings.dropWeight = 1200;
  378. break;
  379. case MP_DECREMENT_DROPWEIGHT:
  380. MPlayer->missionSettings.dropWeight -=10;
  381. MPParameterScreen::resetCheckBoxes();
  382. if ( MPlayer->missionSettings.dropWeight < 30 )
  383. MPlayer->missionSettings.dropWeight = 30;
  384. break;
  385. case MP_INCREMENT_CBILLS:
  386. MPlayer->missionSettings.defaultCBills +=5000;
  387. if ( MPlayer->missionSettings.defaultCBills < 50000 )
  388. MPlayer->missionSettings.defaultCBills = 50000;
  389. MPlayer->redistributeRP();
  390. MPParameterScreen::resetCheckBoxes();
  391. break;
  392. case MP_DECREMENT_CBILLS:
  393. MPlayer->missionSettings.defaultCBills -=5000;
  394. if ( MPlayer->missionSettings.defaultCBills < 50000 )
  395. MPlayer->missionSettings.defaultCBills = 50000;
  396. MPlayer->redistributeRP();
  397. MPParameterScreen::resetCheckBoxes();
  398. break;
  399. case MP_INCREMENT_TIME:
  400. if ( MPlayer->missionSettings.timeLimit < 0 )
  401. {
  402. MPlayer->missionSettings.timeLimit = 0;
  403. }
  404. MPlayer->missionSettings.timeLimit += 60;
  405. MPParameterScreen::resetCheckBoxes();
  406. break;
  407. case MP_DECREMENT_TIME:
  408. if ( MPlayer->missionSettings.timeLimit <= 300 )
  409. MPlayer->missionSettings.timeLimit = -1;
  410. else
  411. MPlayer->missionSettings.timeLimit -= 60;
  412. MPParameterScreen::resetCheckBoxes();
  413. break;
  414. case MP_INCREMENT_RP:
  415. if ( MPlayer->missionSettings.resourcePoints < 0 )
  416. MPlayer->missionSettings.resourcePoints = 0;
  417. MPlayer->missionSettings.resourcePoints += 1000;
  418. MPParameterScreen::resetCheckBoxes();
  419. break;
  420. case MP_DECREMENT_RP:
  421. MPlayer->missionSettings.resourcePoints -= 1000;
  422. if ( MPlayer->missionSettings.resourcePoints < 0 )
  423. MPlayer->missionSettings.resourcePoints = 0;
  424. MPParameterScreen::resetCheckBoxes();
  425. break;
  426. case MP_AIRSTRIKES:
  427. MPlayer->missionSettings.airStrike ^= 1;
  428. MPParameterScreen::resetCheckBoxes();
  429. break;
  430. case MP_SENSOR_PROBE:
  431. MPlayer->missionSettings.sensorProbe ^= 1;
  432. MPParameterScreen::resetCheckBoxes();
  433. break;
  434. case MP_MINELAYER:
  435. MPlayer->missionSettings.mineLayer ^= 1;
  436. MPParameterScreen::resetCheckBoxes();
  437. break;
  438. case MP_REPAIR:
  439. MPlayer->missionSettings.repairVehicle ^= 1;
  440. MPParameterScreen::resetCheckBoxes();
  441. break;
  442. case MP_SCOUTS:
  443. MPlayer->missionSettings.scoutCopter ^= 1;
  444. MPParameterScreen::resetCheckBoxes();
  445. break;
  446. case MP_RECOVERY:
  447. MPlayer->missionSettings.recoveryTeam ^= 1;
  448. MPParameterScreen::resetCheckBoxes();
  449. break;
  450. case MP_GUARDTOWER:
  451. MPlayer->missionSettings.guardTower ^= 1;
  452. MPParameterScreen::resetCheckBoxes();
  453. break;
  454. case MP_RESOURCE_BLDG:
  455. MPlayer->missionSettings.resourceBuilding ^= 1;
  456. MPParameterScreen::resetCheckBoxes();
  457. break;
  458. case MP_UNLIMITED_AMMO:
  459. MPlayer->missionSettings.unlimitedAmmo ^= 1;
  460. MPParameterScreen::resetCheckBoxes();
  461. break;
  462. case MP_VARIANTS:
  463. MPlayer->missionSettings.variants ^= 1;
  464. MPParameterScreen::resetCheckBoxes();
  465. break;
  466. case MP_ALLTECH:
  467. MPlayer->missionSettings.allTech ^= 1;
  468. MPParameterScreen::resetCheckBoxes();
  469. break;
  470. case MP_RP_FORMMECHS:
  471. MPlayer->missionSettings.resourceForMechs ^= 1;
  472. MPParameterScreen::resetCheckBoxes();
  473. break;
  474. case MP_QUICKSTART:
  475. MPlayer->missionSettings.quickStart ^= 1;
  476. MPParameterScreen::resetCheckBoxes();
  477. break;
  478. }
  479. }
  480. return 0;
  481. }
  482. void MPParameterScreen::initializeMap ( const char* fileName )
  483. {
  484. s_instance->setMission(fileName, true);
  485. }
  486. void MPParameterScreen::setMission( const char* fileName, bool resetData )
  487. {
  488. FullPathFileName path;
  489. path.init( missionPath, fileName, ".fit" );
  490. FitIniFile missionFile;
  491. if ( NO_ERR != missionFile.open( (char*)(const char*)path ) )
  492. {
  493. char errorStr[256];
  494. sprintf( errorStr, "couldn't open file %s", fileName );
  495. Assert( 0, 0, errorStr );
  496. return;
  497. }
  498. if ( resetData )
  499. {
  500. long result = 0;
  501. char missionName[256];
  502. result = missionFile.seekBlock( "MissionSettings" );
  503. Assert( result == NO_ERR, 0, "Coudln't find the mission settings block in the mission file" );
  504. bool bRes;
  505. result = missionFile.readIdBoolean( "MissionNameUseResourceString", bRes );
  506. Assert( result == NO_ERR, 0, "couldn't find the MissionNameUseResourceString" );
  507. if ( bRes )
  508. {
  509. unsigned long lRes;
  510. result = missionFile.readIdULong( "MissionNameResourceStringID", lRes );
  511. Assert( result == NO_ERR, 0, "couldn't find the MissionNameResourceStringID" );
  512. cLoadString( lRes, missionName, 255 );
  513. }
  514. else
  515. {
  516. result = missionFile.readIdString( "MissionName", missionName, 255 );
  517. Assert( result == NO_ERR, 0, "couldn't find the missionName" );
  518. }
  519. gosASSERT( strlen( missionName ) < MAXLEN_MAP_NAME );
  520. strcpy( MPlayer->missionSettings.map, fileName );
  521. strcpy( MPlayer->missionSettings.name, missionName );
  522. result = missionFile.readIdLong( "ResourcePoints", MPlayer->missionSettings.resourcePoints );
  523. result = missionFile.readIdLong("AdditionalCBills", MPlayer->missionSettings.defaultCBills );
  524. if (MPlayer->isHost())
  525. MPlayer->redistributeRP();
  526. float fTmp;
  527. result = missionFile.readIdFloat( "DropWeightLimit", fTmp );
  528. MPlayer->missionSettings.dropWeight = fTmp;
  529. result = missionFile.readIdFloat( "TimeLimit", MPlayer->missionSettings.timeLimit );
  530. if ( result != NO_ERR )
  531. MPlayer->missionSettings.timeLimit = -1.f;
  532. result = missionFile.readIdBoolean( "UnlimitedAmmoEnabledDefault", MPlayer->missionSettings.unlimitedAmmo );
  533. result = missionFile.readIdBoolean( "NoVariantsEnabledDefault", MPlayer->missionSettings.variants );
  534. MPlayer->missionSettings.variants ^= 1;
  535. result = missionFile.readIdBoolean( "AllTechEnabledDefault", MPlayer->missionSettings.allTech );
  536. result = missionFile.readIdBoolean( "AirStrikesEnabledDefault", MPlayer->missionSettings.airStrike );
  537. result = missionFile.readIdBoolean( "ArtilleryPieceEnabledDefault", MPlayer->missionSettings.guardTower );
  538. result = missionFile.readIdBoolean( "RepairVehicleEnabledDefault", MPlayer->missionSettings.repairVehicle );
  539. result = missionFile.readIdBoolean( "SalvageCraftEnabledDefault", MPlayer->missionSettings.recoveryTeam );
  540. result = missionFile.readIdBoolean( "SensorProbesEnabledDefault", MPlayer->missionSettings.sensorProbe );
  541. result = missionFile.readIdBoolean( "ScoutCoptersEnabledDefault", MPlayer->missionSettings.scoutCopter );
  542. result = missionFile.readIdBoolean( "MineLayersEnabledDefault", MPlayer->missionSettings.mineLayer );
  543. result = missionFile.readIdBoolean( "ResourceBuildingsEnabledDefault", MPlayer->missionSettings.resourceBuilding );
  544. result = missionFile.readIdBoolean( "ScoutCoptersEnabledDefault", MPlayer->missionSettings.scoutCopter );
  545. result = missionFile.readIdBoolean( "RPsForMechsEnabledDefault", MPlayer->missionSettings.resourceForMechs );
  546. result = missionFile.readIdString( "DownloadURL", MPlayer->missionSettings.url, 255 );
  547. unsigned long lTmp;
  548. if ( NO_ERR == missionFile.readIdULong( "MaximumNumberOfTeams", lTmp ) )
  549. MPlayer->missionSettings.maxTeams = lTmp;
  550. else
  551. MPlayer->missionSettings.maxTeams = 8;
  552. if ( NO_ERR == missionFile.readIdULong( "MaximumNumberOfPlayers", lTmp ) )
  553. MPlayer->missionSettings.maxPlayers = lTmp;
  554. else
  555. MPlayer->missionSettings.maxPlayers = 8;
  556. unsigned long tmp;
  557. result = missionFile.readIdULong( "MissionType", tmp );
  558. MPlayer->missionSettings.missionType = tmp;
  559. // divvy up the cBills!
  560. mapName = MPlayer->missionSettings.map;
  561. }
  562. long textureHandle = MissionBriefingScreen::getMissionTGA( fileName );
  563. statics[15].setTexture( textureHandle );
  564. statics[15].setUVs(0, 127, 127, 0 );
  565. statics[15].setColor( 0xffffffff );
  566. getButton( MAP_INFO )->disable( false );
  567. GUID tmpGuid = getGUIDFromFile( fileName );
  568. MPlayer->missionSettings.mapGuid = tmpGuid;
  569. }
  570. int __cdecl sortPlayers( const void* p1, const void* p2 )
  571. {
  572. MC2Player* player1 = *(MC2Player**)p1;
  573. MC2Player* player2 = *(MC2Player**)p2;
  574. if ( player1->team < player2->team )
  575. return -1;
  576. else if ( player1->team > player2->team )
  577. return 1;
  578. else if ( player1->teamSeniority > player2->teamSeniority )
  579. return -1;
  580. return 1;
  581. }
  582. void MPParameterScreen::update()
  583. {
  584. if ( MPlayer->commanderID < 0 ) // don't do anything until we've been initalized
  585. return;
  586. if ( VERSION_STATUS_UNKNOWN == MPlayer->getVersionStatus() )
  587. {
  588. return;
  589. }
  590. else if ( VERSION_STATUS_BAD == MPlayer->getVersionStatus() )
  591. {
  592. if ( bErrorDlg )
  593. {
  594. LogisticsOneButtonDialog::instance()->update();
  595. if ( LogisticsOneButtonDialog::instance()->isDone() )
  596. {
  597. LogisticsOneButtonDialog::instance()->end();
  598. bHostLeftDlg = 0;
  599. bErrorDlg = 0;
  600. // might need to kill the game here
  601. quitGame = true;
  602. }
  603. }
  604. else
  605. {
  606. LogisticsOneButtonDialog::instance()->setText( IDS_MP_CONNECTION_ERROR_WRONG_VERSION,
  607. IDS_DIALOG_OK, IDS_DIALOG_OK );
  608. LogisticsOneButtonDialog::instance()->begin();
  609. bErrorDlg = true;
  610. }
  611. return;
  612. }
  613. char text[256];
  614. // game not front and center at the top of the screen
  615. textObjects[0].setText( MPlayer->sessionName );
  616. if ( !MPlayer->sessionName || !strlen( MPlayer->sessionName ) )
  617. {
  618. if ( MPlayer->isHost() )
  619. textObjects[0].setText( IDS_STRING26150 );
  620. else
  621. textObjects[0].setText( IDS_WAITHOST2 );
  622. }
  623. // hack for some reason we don't get here from the zone
  624. userInput->mouseOn();
  625. userInput->setMouseCursor( mState_NORMAL );
  626. //Yet Another hack. FadeOutscreen will overwriting us if we were booted and rejoined.
  627. // If our status is RUNNING, reset the FadeOutTime.
  628. if (status != GOTOSPLASH)
  629. fadeOutTime = 0.0f;
  630. if ( MPlayer->missionSettings.quickStart )
  631. {
  632. getButton( MB_MSG_NEXT )->setText( IDS_STRING27171 );
  633. }
  634. else
  635. getButton( MB_MSG_NEXT )->setText( IDS_NEXT );
  636. char str[256];
  637. cLoadString( IDS_MP_PARAM_HOST_IP, str, 255 );
  638. char IPAddressStr[256];
  639. sprintf( IPAddressStr, str, MPlayer->sessionIPAddress );
  640. textObjects[11].setText( IPAddressStr );
  641. if ( !bWaitingToStart && MPlayer->missionSettings.inProgress )
  642. {
  643. bWaitingToStart = true;
  644. soundSystem->playBettySample( BETTY_DEPLOY_MSG );
  645. }
  646. else if ( !MPlayer->missionSettings.inProgress )
  647. {
  648. bWaitingToStart = false;
  649. }
  650. if ( delayTime )
  651. delayTime += frameLength;
  652. if ( delayTime > 5.f )
  653. {
  654. if ( getButton( MB_MSG_NEXT )->isEnabled() )
  655. {
  656. getButton( 50/*MB_MSG_NEXT*/ )->press( 0 );
  657. int faction = MPlayer->getPlayerInfo( MPlayer->commanderID )->faction;
  658. if ( faction < 0 )
  659. faction = 0;
  660. if ( MPlayer->missionSettings.allTech )
  661. LogisticsData::instance->setPurchaseFile( pPurchaseFiles[4] );
  662. else
  663. LogisticsData::instance->setPurchaseFile( pPurchaseFiles[faction] );
  664. LogisticsData::instance->setCurrentMission( MPlayer->missionSettings.map );
  665. MPlayer->sendMissionSetup(0, 6, NULL);
  666. status = NEXT;
  667. }
  668. else {
  669. if (MPlayer->isHost())
  670. MPlayer->setInProgress(false);
  671. delayTime = 0.f;
  672. bWaitingToStart = 0;
  673. }
  674. }
  675. if ( MPlayer )
  676. {
  677. FullPathFileName path;
  678. path.init( missionPath, MPlayer->missionSettings.map, ".pak" );
  679. if ( !fileExists( path ) ) // disable the ready button if the map isn't around...
  680. {
  681. getButton( MAP_INFO )->disable( true );
  682. }
  683. else
  684. {
  685. getButton( MAP_INFO )->disable( false );
  686. if ( !statics[15].getColor() )
  687. {
  688. long textureHandle = MissionBriefingScreen::getMissionTGA( MPlayer->missionSettings.map );
  689. if ( textureHandle )
  690. {
  691. statics[15].setTexture( textureHandle );
  692. statics[15].setUVs( 0, 127, 127, 0 );
  693. statics[15].setColor( 0xffffffff );
  694. }
  695. }
  696. }
  697. }
  698. // load up my own icon and send out to everyone else....
  699. /* MC2Player* pPlayer = MPlayer->getPlayerInfo( MPlayer->commanderID );
  700. if ( pPlayer && !MPlayer->insigniaList[MPlayer->commanderID])
  701. {
  702. FullPathFileName path;
  703. path.init( "data\\multiplayer\\insignia\\", pPlayer->insigniaFile, ".tga" );
  704. File file;
  705. if ( NO_ERR == file.open( path ) )
  706. {
  707. long size = file.getLength();
  708. unsigned char* pData = new unsigned char[size];
  709. file.read( pData, size );
  710. MPlayer->sendPlayerInsignia( (char*)pPlayer->insigniaFile, pData, size );
  711. MPlayer->insigniaList[MPlayer->commanderID] = 1;
  712. }
  713. }*/
  714. if ( MPlayer->launchedFromLobby )
  715. getButton( MB_MSG_PREV )->disable( true );
  716. else
  717. getButton( MB_MSG_PREV )->disable( false );
  718. if ( bMapInfoDlg )
  719. {
  720. mapInfoDlg.update();
  721. if ( mapInfoDlg.isDone() )
  722. {
  723. bMapInfoDlg = 0;
  724. }
  725. }
  726. else if ( bHostLeftDlg || bErrorDlg )
  727. {
  728. LogisticsOneButtonDialog::instance()->update();
  729. if ( LogisticsOneButtonDialog::instance()->isDone() )
  730. {
  731. LogisticsOneButtonDialog::instance()->end();
  732. bHostLeftDlg = 0;
  733. bErrorDlg = 0;
  734. }
  735. }
  736. else if ( bShowNoMapDlg || bBootDlg || bDisconnectDlg)
  737. {
  738. LogisticsOKDialog::instance()->update();
  739. if ( LogisticsOKDialog::instance()->isDone() )
  740. {
  741. if ( LogisticsOKDialog::instance()->getStatus() == YES )
  742. {
  743. if ( bShowNoMapDlg )
  744. MPlayer->launchBrowser( MPlayer->missionSettings.url );
  745. else if ( bBootDlg )
  746. {
  747. MC2Player* player= MPlayer->getPlayerInfo( bootPlayerID );
  748. MPlayer->bootPlayer( player->player );
  749. }
  750. else if ( bDisconnectDlg )
  751. {
  752. MPlayer->closeSession();
  753. status = PREVIOUS;
  754. }
  755. }
  756. LogisticsOKDialog::instance()->end();
  757. if ( bShowNoMapDlg )
  758. {
  759. mapName = MPlayer->missionSettings.map;
  760. char chatStr[256];
  761. char final[1024];
  762. cLoadString( chatToSend, chatStr, 255 );
  763. sprintf( final, chatStr, prefs.playerName[0] );
  764. MPlayer->sendChat( NULL, -1, final );
  765. }
  766. bShowNoMapDlg = false;
  767. bBootDlg = false;
  768. bDisconnectDlg = false;
  769. }
  770. return;
  771. }
  772. else if ( bLoading )
  773. {
  774. mpLoadMap.update();
  775. if ( mpLoadMap.isDone() )
  776. {
  777. if ( mpLoadMap.getStatus() == YES )
  778. {
  779. // need to pull in this map information....
  780. const char* pName = mpLoadMap.getMapFileName();
  781. LogisticsData::instance->setCurrentMission( pName );
  782. // now I need to update the other people....
  783. setMission(pName);
  784. resetCheckBoxes();
  785. }
  786. bLoading = false;
  787. }
  788. return;
  789. }
  790. else
  791. {
  792. bool bEditHasFocus = 0;
  793. // disable necessary stuff
  794. if ( !MPlayer->isHost() )
  795. {
  796. if ( MPlayer->missionSettings.mapGuid == NO_VERSION_GUID )
  797. {
  798. checkVersionClientOnly( MPlayer->missionSettings.map );
  799. }
  800. if ( MPlayer->playerInfo[MPlayer->commanderID].leftSession ) // I've been booted!
  801. {
  802. if ( status != GOTOSPLASH )
  803. {
  804. status = GOTOSPLASH;
  805. beginFadeOut( .5 );
  806. }
  807. return;
  808. }
  809. for ( int i = MP_INCREMENT_DROPWEIGHT; i < MP_DECREMENT_RP+1; i++ )
  810. {
  811. aButton* pButton = getButton( i );
  812. if ( pButton )
  813. {
  814. pButton->showGUIWindow( 0 );
  815. }
  816. }
  817. for ( i = MP_DECREMENT_CBILLS+1; i < MP_RP_FORMMECHS+1; i++ )
  818. {
  819. aButton* pButton = getButton( i );
  820. if ( pButton )
  821. {
  822. pButton->disable( true );
  823. }
  824. }
  825. for ( i = 0; i < 3; i++ )
  826. edits[i].setReadOnly( true );
  827. getButton( 101/*load map button*/ )->showGUIWindow( false );
  828. getButton( MP_LOCKGAME )->showGUIWindow( false );
  829. getButton( MP_BOOTPLAYER )->showGUIWindow( false );
  830. if ( MPlayer->startLoading || MPlayer->startLogistics )
  831. {
  832. int faction = MPlayer->getPlayerInfo( MPlayer->commanderID )->faction;
  833. if ( faction < 0 )
  834. faction = 0;
  835. if ( MPlayer->missionSettings.allTech )
  836. LogisticsData::instance->setPurchaseFile( pPurchaseFiles[4] );
  837. else
  838. LogisticsData::instance->setPurchaseFile( pPurchaseFiles[faction] );
  839. LogisticsData::instance->setCurrentMission( MPlayer->missionSettings.map );
  840. status = NEXT;
  841. return;
  842. }
  843. if ( mapName != MPlayer->missionSettings.map
  844. && strlen( MPlayer->missionSettings.map )) // check for new map
  845. {
  846. //
  847. setMissionClientOnly( MPlayer->missionSettings.map );
  848. }
  849. }
  850. else
  851. {
  852. // make sure King of the hill missions have a time limit
  853. if ( MPlayer->missionSettings.timeLimit < 60 &&
  854. (MPlayer->missionSettings.missionType == MISSION_TYPE_KING_OF_THE_HILL
  855. || MPlayer->missionSettings.missionType == MISSION_TYPE_LAST_MAN_ON_THE_HILL
  856. || MPlayer->missionSettings.missionType == MISSION_TYPE_TERRITORIES) )
  857. {
  858. MPlayer->missionSettings.timeLimit = 300;
  859. }
  860. if ( MPlayer->missionSettings.dropWeight < 30 )
  861. {
  862. MPlayer->missionSettings.dropWeight = 30;
  863. }
  864. if ( MPlayer->missionSettings.defaultCBills < 50000 )
  865. {
  866. MPlayer->missionSettings.defaultCBills = 50000;
  867. MPlayer->redistributeRP();
  868. }
  869. for ( int i = MP_INCREMENT_DROPWEIGHT; i < MP_RP_FORMMECHS+1; i++ )
  870. {
  871. aButton* pButton = getButton( i );
  872. if ( pButton )
  873. {
  874. pButton->disable( false );
  875. pButton->showGUIWindow( true );
  876. }
  877. }
  878. for ( i = 0; i < 3; i++ )
  879. edits[i].setReadOnly( false );
  880. // see if they clicked the launch button and there are too many players
  881. if ( playerCount > MPlayer->missionSettings.maxPlayers )
  882. {
  883. if ( userInput->isLeftClick() &&
  884. getButton( MB_MSG_NEXT )->pointInside( userInput->getMouseX(), userInput->getMouseY() ) )
  885. {
  886. char errorStr[256];
  887. LogisticsOneButtonDialog::instance()->setText( IDS_PLAYER_LEFT,
  888. IDS_DIALOG_OK, IDS_DIALOG_OK );
  889. cLoadString( IDS_MP_PARAM_ERROR_TOO_MANY_PLAYERS, errorStr, 255 );
  890. LogisticsOneButtonDialog::instance()->setText( errorStr );
  891. LogisticsOneButtonDialog::instance()->begin();
  892. bErrorDlg = true;
  893. }
  894. }
  895. MC2Player* data = MPlayer->getPlayerInfo( MPlayer->commanderID );
  896. {
  897. if ( data )
  898. data->ready = true; // default to ready for host since they have to press launch anyway
  899. else
  900. return;
  901. }
  902. getButton( 101/*load map button*/ )->showGUIWindow( true );
  903. //now check for specifics...
  904. bool bDisable = MPlayer->missionSettings.timeLimit <= 0;
  905. getButton( MP_DECREMENT_TIME )->disable( bDisable );
  906. bDisable = MPlayer->missionSettings.timeLimit >= 3600.f;
  907. getButton( MP_INCREMENT_TIME )->disable( bDisable );
  908. bDisable = MPlayer->missionSettings.resourcePoints <= 0;
  909. getButton( MP_DECREMENT_RP )->disable( bDisable );
  910. bDisable = MPlayer->missionSettings.resourcePoints >= 99900.f;
  911. getButton( MP_INCREMENT_RP )->disable( bDisable );
  912. bDisable = MPlayer->missionSettings.defaultCBills <= 50000;
  913. getButton( MP_DECREMENT_CBILLS )->disable( bDisable );
  914. bDisable = MPlayer->missionSettings.defaultCBills >= 999000.f;
  915. getButton( MP_INCREMENT_CBILLS )->disable( bDisable );
  916. bDisable = MPlayer->missionSettings.dropWeight <= 30;
  917. getButton( MP_DECREMENT_DROPWEIGHT )->disable( bDisable );
  918. bDisable = MPlayer->missionSettings.dropWeight >= 1200.f;
  919. getButton( MP_INCREMENT_DROPWEIGHT )->disable( bDisable );
  920. getButton( MP_QUICKSTART )->disable( 0 );
  921. getButton( MP_LOCKGAME )->showGUIWindow( true );
  922. getButton( MP_BOOTPLAYER )->showGUIWindow( true );
  923. getButton( MP_BOOTPLAYER )->disable( false );
  924. for( i = 0; i < playerCount; i++ )
  925. {
  926. if ( playerParameters[i].hasFocus() )
  927. {
  928. if ( playerParameters[i].getCommanderID() == MPlayer->commanderID )
  929. getButton( MP_BOOTPLAYER )->disable( true );
  930. }
  931. }
  932. }
  933. int oldEditFocus = -1;
  934. for ( int i = 0; i < editCount; i++ )
  935. {
  936. if ( edits[i].hasFocus() )
  937. oldEditFocus = i;
  938. }
  939. if ( !ChatWindow::instance()->pointInside(userInput->getMouseX(), userInput->getMouseY()) )
  940. {
  941. LogisticsScreen::update();
  942. }
  943. if ( oldEditFocus != -1 )
  944. {
  945. bEditHasFocus = true;
  946. if ( !edits[oldEditFocus].hasFocus() )
  947. {
  948. EString text;
  949. edits[oldEditFocus].getEntry( text );
  950. long val = atoi( text );
  951. switch (oldEditFocus)
  952. {
  953. case 0:
  954. MPlayer->missionSettings.dropWeight = val;
  955. MPParameterScreen::resetCheckBoxes();
  956. break;
  957. case 1:
  958. MPlayer->missionSettings.defaultCBills = val * 1000;
  959. if (MPlayer->isHost())
  960. MPlayer->redistributeRP();
  961. MPParameterScreen::resetCheckBoxes();
  962. break;
  963. case 2:
  964. MPlayer->missionSettings.timeLimit = val * 60;
  965. MPParameterScreen::resetCheckBoxes();
  966. break;
  967. case 3:
  968. MPlayer->missionSettings.resourcePoints = val;
  969. MPParameterScreen::resetCheckBoxes();
  970. break;
  971. }
  972. }
  973. }
  974. /// now make all enabled so they draw correctly...
  975. for ( i = MP_AIRSTRIKES; i < MP_RP_FORMMECHS+1; i++ )
  976. {
  977. aButton* pButton = getButton( i );
  978. if ( pButton )
  979. {
  980. pButton->disable( false );
  981. }
  982. }
  983. getButton( MP_QUICKSTART )->disable( 0 );
  984. if ( MPlayer )
  985. {
  986. int oldPlayerCount = playerCount;
  987. const MC2Player* players = MPlayer->getPlayers(playerCount);
  988. if ( oldPlayerCount != playerCount )
  989. {
  990. // new player... need to redistribute rp
  991. int maxCommander = -1;
  992. int teamID = -1;
  993. for( int i = 0; i < playerCount; i++ )
  994. {
  995. if ( players[i].commanderID > maxCommander )
  996. {
  997. maxCommander = players[i].commanderID;
  998. teamID = players[i].team;
  999. }
  1000. }
  1001. }
  1002. bool bReady = true;
  1003. const MC2Player* sortedPlayers[MAX_MC_PLAYERS];
  1004. for ( int i = 0; i < playerCount; i++ )
  1005. {
  1006. sortedPlayers[i] = &players[i];
  1007. }
  1008. qsort( sortedPlayers, playerCount, sizeof( MC2Player* ), sortPlayers );
  1009. for( i = 0; i < playerCount; i++ )
  1010. {
  1011. playerParameters[i].setData( sortedPlayers[i] );
  1012. }
  1013. int team = -1;
  1014. if ( playerCount )
  1015. team = sortedPlayers[0]->team;
  1016. bool bUniqueTeam = 0;
  1017. for( i = 0; i < playerCount; i++ )
  1018. {
  1019. // if ( !ChatWindow::instance()->pointInside(userInput->getMouseX(), userInput->getMouseY() ) )
  1020. playerParameters[i].update();
  1021. bReady &= sortedPlayers[i]->ready;
  1022. if ( !MPlayer->missionSettings.quickStart )
  1023. bReady &= ((sortedPlayers[i]->cBills) ? 1 : 0);
  1024. if ( playerParameters[i].hasFocus() )
  1025. bEditHasFocus = true;
  1026. if ( sortedPlayers[i]->team != team )
  1027. bUniqueTeam = 1;
  1028. }
  1029. bReady &= !bEditHasFocus;
  1030. bReady &= (MPlayer->isHost());
  1031. bReady &= strlen( MPlayer->missionSettings.map ) ? 1 : 0;
  1032. bReady &= (playerCount > 1);
  1033. bReady &= (MPlayer->missionSettings.maxPlayers >= playerCount);
  1034. bReady &= bUniqueTeam;
  1035. bReady &= (MPlayer->missionSettings.dropWeight >= 30);
  1036. bool bPress = MPlayer->missionSettings.airStrike;
  1037. getButton( MP_AIRSTRIKES )->press( bPress );
  1038. bPress = MPlayer->missionSettings.sensorProbe;
  1039. getButton( MP_SENSOR_PROBE )->press( bPress );
  1040. bPress = MPlayer->missionSettings.mineLayer;
  1041. getButton( MP_MINELAYER )->press( bPress );
  1042. bPress = MPlayer->missionSettings.repairVehicle;
  1043. getButton( MP_REPAIR )->press( bPress );
  1044. bPress = MPlayer->missionSettings.scoutCopter;
  1045. getButton( MP_SCOUTS )->press( bPress );
  1046. bPress = MPlayer->missionSettings.recoveryTeam;
  1047. getButton( MP_RECOVERY )->press( bPress );
  1048. bPress = MPlayer->missionSettings.guardTower;
  1049. getButton( MP_GUARDTOWER )->press( bPress );
  1050. bPress = MPlayer->missionSettings.resourceBuilding;
  1051. getButton( MP_RESOURCE_BLDG )->press( bPress );
  1052. bPress = MPlayer->missionSettings.unlimitedAmmo;
  1053. getButton( MP_UNLIMITED_AMMO )->press( bPress );
  1054. bPress = !MPlayer->missionSettings.variants;
  1055. getButton( MP_VARIANTS )->press( bPress );
  1056. bPress = MPlayer->missionSettings.allTech;
  1057. getButton( MP_ALLTECH )->press( bPress );
  1058. bPress = MPlayer->missionSettings.resourceForMechs;
  1059. getButton( MP_RP_FORMMECHS )->press( bPress );
  1060. bPress = MPlayer->missionSettings.quickStart;
  1061. getButton( MP_QUICKSTART )->press( bPress );
  1062. bPress = MPlayer->missionSettings.locked;
  1063. getButton( MP_LOCKGAME )->press( bPress );
  1064. if ( !strlen(MPlayer->missionSettings.map) )
  1065. {
  1066. getButton( MAP_INFO )->disable( true );
  1067. }
  1068. // else
  1069. // getButton( MAP_INFO )->disable( false );
  1070. textObjects[1].setText( MPlayer->missionSettings.name );
  1071. // cLoadString( IDS_MP_LM_MAP_LIST_TYPE, tmp, 255 );
  1072. // cLoadString( IDS_MP_LM_TYPE0 + MPlayer->missionSettings.missionType, tmp2, 127 );
  1073. // sprintf( text, tmp, tmp2 );
  1074. // textObjects[7].setText( text );
  1075. sprintf( text, "%ldk", MPlayer->missionSettings.defaultCBills/1000 );
  1076. if ( !edits[1].hasFocus() )
  1077. edits[1].setEntry( text );
  1078. sprintf( text, "%ld", MPlayer->missionSettings.resourcePoints );
  1079. if ( !edits[3].hasFocus() )
  1080. edits[3].setEntry( text );
  1081. sprintf( text, "%.0lf", fabs(MPlayer->missionSettings.timeLimit/60.f) );
  1082. if ( !edits[2].hasFocus() )
  1083. {
  1084. if ( MPlayer->missionSettings.timeLimit/60.f <= 0 )
  1085. cLoadString( IDS_MP_PARAM_UNLIMITED, text, 255 );
  1086. edits[2].setEntry( text );
  1087. }
  1088. sprintf( text, "%ld", MPlayer->missionSettings.dropWeight );
  1089. if ( !edits[0].hasFocus() )
  1090. edits[0].setEntry( text );
  1091. if ( bReady )
  1092. {
  1093. getButton( MB_MSG_NEXT )->disable( false );
  1094. }
  1095. else
  1096. {
  1097. getButton( MB_MSG_NEXT )->disable( true );
  1098. if ( delayTime )
  1099. {
  1100. char text[256];
  1101. cLoadString( IDS_MP_LAUNCH_ABORTED, text, 255 );
  1102. MPlayer->sendChat( 0, -1, text );
  1103. delayTime = 0.f;
  1104. bWaitingToStart = 0;
  1105. MPlayer->setInProgress( 0 );
  1106. }
  1107. }
  1108. }
  1109. if ( !bEditHasFocus )
  1110. ChatWindow::instance()->update();
  1111. }
  1112. helpTextID = 0;
  1113. helpTextHeaderID = 0;
  1114. /*
  1115. for ( int i = 0; i < buttonCount; i++ )
  1116. {
  1117. buttons[i].update();
  1118. if ( buttons[i].pointInside( userInput->getMouseX(), userInput->getMouseY() )
  1119. && userInput->isLeftClick() )
  1120. {
  1121. handleMessage( buttons[i].getID(), buttons[i].getID() );
  1122. }
  1123. }
  1124. */
  1125. }
  1126. GUID MPParameterScreen::getGUIDFromFile( const char* pNewMapName)
  1127. {
  1128. GUID retVal;
  1129. memset( &retVal, 0xff, sizeof( GUID ) );
  1130. FullPathFileName path;
  1131. path.init( missionPath, pNewMapName, ".pak" );
  1132. PacketFile pakFile;
  1133. if ( NO_ERR != pakFile.open( (char*)(const char*)path ) )
  1134. {
  1135. return retVal;
  1136. }
  1137. int packetCount = pakFile.getNumPackets();
  1138. pakFile.seekPacket( packetCount - 1 );
  1139. if ( sizeof( GUID ) == pakFile.getPacketSize( ) )
  1140. {
  1141. pakFile.readPacket( packetCount - 1, (unsigned char*)&retVal );
  1142. return retVal;
  1143. }
  1144. else
  1145. {
  1146. memset( &retVal, 0, sizeof( GUID ) );
  1147. return retVal;
  1148. }
  1149. }
  1150. void MPParameterScreen::setMissionClientOnly( const char* pNewMapName )
  1151. {
  1152. FullPathFileName path;
  1153. path.init( missionPath, pNewMapName, ".fit" );
  1154. FitIniFile missionFile;
  1155. if ( NO_ERR != missionFile.open( (char*)(const char*)path ) )
  1156. {
  1157. char tmp[256];
  1158. char final[1024];
  1159. cLoadString( IDS_MP_PARAM_NO_MAP, tmp, 255 );
  1160. sprintf( final, tmp, MPlayer->missionSettings.map, MPlayer->missionSettings.url );
  1161. LogisticsOKDialog::instance()->setFont(IDS_MP_PARAM_NO_MAP_FONT);
  1162. LogisticsOKDialog::instance()->setText( final );
  1163. LogisticsOKDialog::instance()->begin();
  1164. bShowNoMapDlg = true;
  1165. getButton( MAP_INFO )->disable( true );
  1166. chatToSend = IDS_MP_PARAMETER_NO_MAP_CHAT;
  1167. statics[15].setColor( 0 );
  1168. return;
  1169. }
  1170. checkVersionClientOnly( pNewMapName );
  1171. getButton( MAP_INFO )->disable( false );
  1172. long textureHandle = MissionBriefingScreen::getMissionTGA( pNewMapName );
  1173. if ( textureHandle )
  1174. {
  1175. statics[15].setTexture( textureHandle );
  1176. statics[15].setUVs( 0, 127, 127, 0 );
  1177. statics[15].setColor( 0xffffffff );
  1178. }
  1179. mapName = MPlayer->missionSettings.map;
  1180. }
  1181. void MPParameterScreen::checkVersionClientOnly( const char* pNewMapName )
  1182. {
  1183. GUID version = getGUIDFromFile( pNewMapName );
  1184. if ( MPlayer->missionSettings.mapGuid != NO_VERSION_GUID &&
  1185. version != MPlayer->missionSettings.mapGuid && version != NO_VERSION_GUID) // if 0 it simply wasn't in the file at all, should take this out as soon as maps are resaved
  1186. {
  1187. char tmp[256];
  1188. char final[1024];
  1189. cLoadString( IDS_MP_PARAM_MAP_WRONG_VERSION, tmp, 255 );
  1190. sprintf( final, tmp, MPlayer->missionSettings.url );
  1191. LogisticsOKDialog::instance()->setFont(IDS_MP_PARAM_NO_MAP_FONT);
  1192. LogisticsOKDialog::instance()->setText( final );
  1193. LogisticsOKDialog::instance()->begin();
  1194. bShowNoMapDlg = true;
  1195. getButton( MAP_INFO )->disable( true );
  1196. chatToSend = IDS_MAP_WRONG_VERSION_CHAT;
  1197. statics[15].setColor( 0 );
  1198. // need to disable the ready button
  1199. for( int i = 0; i < MAX_MC_PLAYERS; i++ )
  1200. {
  1201. if ( playerParameters[i].getCommanderID() == MPlayer->commanderID )
  1202. {
  1203. playerParameters[i].disableReadyButton();
  1204. break;
  1205. }
  1206. }
  1207. }
  1208. }
  1209. void MPParameterScreen::resetCheckBoxes()
  1210. {
  1211. if ( MPlayer->isHost() )
  1212. {
  1213. long playerCount = 0;
  1214. const MC2Player* players = MPlayer->getPlayers(playerCount);
  1215. for ( int i = 0; i < playerCount; i++ )
  1216. {
  1217. MC2Player* pWrite = MPlayer->getPlayerInfo( players[i].commanderID );
  1218. if ( pWrite->commanderID != MPlayer->commanderID )
  1219. pWrite->ready = 0;
  1220. }
  1221. }
  1222. }
  1223. void MPParameterScreen::setHostLeftDlg( const char* playerName )
  1224. {
  1225. char leaveStr[256];
  1226. char formatStr[256];
  1227. cLoadString( IDS_PLAYER_LEFT, leaveStr, 255 );
  1228. sprintf( formatStr, leaveStr, playerName );
  1229. LogisticsOneButtonDialog::instance()->setText( IDS_PLAYER_LEFT,
  1230. IDS_DIALOG_OK, IDS_DIALOG_OK );
  1231. LogisticsOneButtonDialog::instance()->setText( formatStr );
  1232. LogisticsOneButtonDialog::instance()->begin();
  1233. bHostLeftDlg = true;
  1234. }
  1235. aPlayerParams::aPlayerParams()
  1236. {
  1237. statics = 0;
  1238. rects = 0;
  1239. textObjects = 0;
  1240. staticCount = rectCount = textCount = 0;
  1241. bHasFocus = 0;
  1242. }
  1243. aPlayerParams::~aPlayerParams()
  1244. {
  1245. destroy();
  1246. }
  1247. aPlayerParams& aPlayerParams::operator=( const aPlayerParams& src )
  1248. {
  1249. aObject::operator=( src );
  1250. addChild(&ReadyButton);
  1251. addChild( &CBillsSpinnerDownButton );
  1252. addChild( &CBillsSpinnerUpButton );
  1253. addChild( &edit );
  1254. ReadyButton = src.ReadyButton;
  1255. CBillsSpinnerDownButton = src.CBillsSpinnerDownButton;
  1256. CBillsSpinnerUpButton = src.CBillsSpinnerUpButton;
  1257. edit = src.edit;
  1258. insigniaName = src.insigniaName;
  1259. templateItem = src.templateItem;
  1260. staticCount = src.staticCount;
  1261. if ( staticCount )
  1262. {
  1263. statics = new aObject[staticCount];
  1264. for ( int i = 0; i < staticCount; i++ )
  1265. {
  1266. addChild( &statics[i] );
  1267. statics[i] = src.statics[i];
  1268. }
  1269. }
  1270. rectCount = src.rectCount;
  1271. if ( rectCount )
  1272. {
  1273. rects = new aRect[rectCount];
  1274. for ( int i = 0; i < rectCount; i++ )
  1275. {
  1276. addChild( &rects[i] );
  1277. rects[i] = src.rects[i];
  1278. }
  1279. }
  1280. textCount = src.textCount;
  1281. if ( textCount )
  1282. {
  1283. textObjects = new aText[textCount];
  1284. for ( int i = 0; i < textCount; i++ )
  1285. {
  1286. addChild( &textObjects[i] );
  1287. textObjects[i] = src.textObjects[i];
  1288. }
  1289. }
  1290. addChild(&teamNumberDropList);
  1291. teamNumberDropList = src.teamNumberDropList;
  1292. addChild( &factionDropList );
  1293. factionDropList = src.factionDropList;
  1294. return *this;
  1295. }
  1296. long aPlayerParams::init(long xPos, long yPos,long w, long h )
  1297. {
  1298. long err;
  1299. err = aObject::init(xPos,yPos,w,h);
  1300. if (err)
  1301. return err;
  1302. if ( !MPlayer->isHost() )
  1303. {
  1304. CBillsSpinnerDownButton.showGUIWindow( 0 );
  1305. CBillsSpinnerUpButton.showGUIWindow( 0 );
  1306. }
  1307. return (NO_ERR);
  1308. }
  1309. void aPlayerParams::init( FitIniFile* pFile, const char* blockNameParam )
  1310. {
  1311. FitIniFile &file = (*pFile);
  1312. pFile->seekBlock(blockNameParam);
  1313. ReadyButton.init( file, "PlayerParamsReadyButton" );
  1314. CBillsSpinnerDownButton.init( file, "PlayerParamsCBillsSpinnerDownButton" );
  1315. CBillsSpinnerUpButton.init( file, "PlayerParamsCBillsSpinnerUpButton" );
  1316. addChild(&ReadyButton);
  1317. addChild( &CBillsSpinnerDownButton );
  1318. addChild( &CBillsSpinnerUpButton );
  1319. edit.init( pFile, "playerparamEdit0" );
  1320. edit.setNumeric( true );
  1321. edit.limitEntry( 3 );
  1322. edit.allowIME( 0 );
  1323. addChild( &edit );
  1324. CBillsSpinnerDownButton.setPressFX( LOG_VIDEOBUTTONS );
  1325. CBillsSpinnerUpButton.setPressFX( LOG_VIDEOBUTTONS );
  1326. ReadyButton.setPressFX( LOG_VIDEOBUTTONS );
  1327. CBillsSpinnerDownButton.setHighlightFX( LOG_DIGITALHIGHLIGHT );
  1328. CBillsSpinnerUpButton.setHighlightFX( LOG_DIGITALHIGHLIGHT );
  1329. ReadyButton.setHighlightFX( LOG_DIGITALHIGHLIGHT );
  1330. CBillsSpinnerDownButton.setDisabledFX( LOG_WRONGBUTTON );
  1331. CBillsSpinnerUpButton.setDisabledFX( LOG_WRONGBUTTON );
  1332. ReadyButton.setDisabledFX( LOG_WRONGBUTTON );
  1333. const char* staticName = "PlayerParamsStatic";
  1334. const char* textName = "PlayerParamsText";
  1335. const char* rectName = "PlayerParamsRect";
  1336. char blockName[256];
  1337. // init statics
  1338. if ( staticName )
  1339. {
  1340. sprintf( blockName, "%s%c", staticName, 's' );
  1341. if ( NO_ERR == file.seekBlock( blockName ) )
  1342. {
  1343. file.readIdLong( "staticCount", staticCount );
  1344. if ( staticCount )
  1345. {
  1346. statics = new aObject[staticCount];
  1347. char blockName[128];
  1348. for ( int i = 0; i < staticCount; i++ )
  1349. {
  1350. sprintf( blockName, "%s%ld", staticName, i );
  1351. statics[i].init( &file, blockName );
  1352. addChild(&(statics[i]));
  1353. }
  1354. }
  1355. }
  1356. }
  1357. if ( rectName )
  1358. {
  1359. // init rects
  1360. sprintf( blockName, "%s%c", rectName, 's' );
  1361. if ( NO_ERR == file.seekBlock( blockName ) )
  1362. {
  1363. file.readIdLong( "rectCount", rectCount );
  1364. if ( rectCount )
  1365. {
  1366. rects = new aRect[rectCount];
  1367. char blockName[128];
  1368. for ( int i = 0; i < rectCount; i++ )
  1369. {
  1370. sprintf( blockName, "%s%ld", rectName, i );
  1371. rects[i].init( &file, blockName );
  1372. addChild(&(rects[i]));
  1373. }
  1374. }
  1375. }
  1376. }
  1377. // init texts
  1378. if ( textName )
  1379. {
  1380. sprintf( blockName, "%s%c", textName, 's' );
  1381. if ( NO_ERR == file.seekBlock( blockName ) )
  1382. {
  1383. if ( NO_ERR != file.readIdLong( "TextEntryCount", textCount ) )
  1384. file.readIdLong( "TextCount", textCount );
  1385. if ( textCount )
  1386. {
  1387. textObjects = new aText[textCount];
  1388. char blockName[64];
  1389. for ( int i = 0; i < textCount; i++ )
  1390. {
  1391. sprintf( blockName, "%s%ld", textName, i );
  1392. textObjects[i].init( &file, blockName );
  1393. addChild(&(textObjects[i]));
  1394. }
  1395. }
  1396. }
  1397. }
  1398. {
  1399. char path[256];
  1400. strcpy( path, artPath );
  1401. strcat( path, "mcl_mp_param_droplist3.fit" );
  1402. FitIniFile PNfile;
  1403. if ( NO_ERR != PNfile.open( path ) )
  1404. {
  1405. char error[256];
  1406. sprintf( error, "couldn't open file %s", path );
  1407. Assert( 0, 0, error );
  1408. return;
  1409. }
  1410. teamNumberDropList.init(&PNfile, "TeamNumberDropList");
  1411. teamNumberDropList.ListBox().setOrange( true );
  1412. PNfile.seekBlock( "Text0" );
  1413. templateItem.init(&PNfile, "Text0" );
  1414. }
  1415. addChild(&teamNumberDropList);
  1416. {
  1417. char path[256];
  1418. strcpy( path, artPath );
  1419. strcat( path, "mcl_mp_param_droplist4.fit" );
  1420. FitIniFile PNfile;
  1421. if ( NO_ERR != PNfile.open( path ) )
  1422. {
  1423. char error[256];
  1424. sprintf( error, "couldn't open file %s", path );
  1425. Assert( 0, 0, error );
  1426. return;
  1427. }
  1428. factionDropList.init(&PNfile, "FactionTypeDropList");
  1429. factionDropList.ListBox().setOrange( true );
  1430. int i;
  1431. for (i = 0; i < 4; i += 1)
  1432. {
  1433. aStyle2TextListItem *pTmp2;
  1434. pTmp2 = new aStyle2TextListItem;
  1435. *pTmp2 = templateItem;
  1436. pTmp2->setText( IDS_FACTION0 + i );
  1437. pTmp2->resize( factionDropList.width() -
  1438. factionDropList.ListBox().getScrollBarWidth() - 8,
  1439. pTmp2->height() );
  1440. pTmp2->sizeToText();
  1441. factionDropList.AddItem(pTmp2);
  1442. }
  1443. factionDropList.SelectItem(0);
  1444. }
  1445. addChild(&factionDropList);
  1446. // resize after we include drop lists
  1447. if (true)
  1448. {
  1449. float x = 1000000.0;
  1450. float y = 1000000.0;
  1451. float w = 0.0;
  1452. float h = 0.0;
  1453. int i;
  1454. for (i = 0; i < numberOfChildren(); i += 1)
  1455. {
  1456. aObject *pChild = child(i);
  1457. if (x > pChild->globalX())
  1458. {
  1459. x = pChild->globalX();
  1460. }
  1461. if (y > pChild->globalY())
  1462. {
  1463. y = pChild->globalY();
  1464. }
  1465. if (w < pChild->globalRight() )
  1466. {
  1467. w = (pChild->globalRight());
  1468. }
  1469. if (h < pChild->globalBottom() - pChild->globalTop() )
  1470. {
  1471. h = (pChild->globalBottom() - pChild->globalTop());
  1472. }
  1473. }
  1474. resize( w, h );
  1475. moveToNoRecurse( x, y );
  1476. }
  1477. }
  1478. bool aPlayerParams::hasFocus( )
  1479. {
  1480. if ( edit.hasFocus() )
  1481. return true;
  1482. if ( factionDropList.ListBox().isShowing() )
  1483. return true;
  1484. if ( teamNumberDropList.ListBox().isShowing() )
  1485. return true;
  1486. return false;
  1487. }
  1488. void aPlayerParams::destroy()
  1489. {
  1490. removeAllChildren();
  1491. if ( statics )
  1492. delete [] statics;
  1493. if ( rects )
  1494. delete [] rects;
  1495. if ( textObjects )
  1496. delete [] textObjects;
  1497. statics = 0;
  1498. rects = 0;
  1499. textObjects = 0;
  1500. aObject::destroy();
  1501. }
  1502. void aPlayerParams::update()
  1503. {
  1504. if ( !MPlayer->isHost() )
  1505. {
  1506. CBillsSpinnerDownButton.showGUIWindow( 0 );
  1507. CBillsSpinnerUpButton.showGUIWindow( 0 );
  1508. }
  1509. if ( userInput->isLeftClick() )
  1510. {
  1511. if ( pointInside( userInput->getMouseX(), userInput->getMouseY() )
  1512. || factionDropList.pointInside( userInput->getMouseX(), userInput->getMouseY())
  1513. || teamNumberDropList.pointInside( userInput->getMouseX(), userInput->getMouseY()))
  1514. bHasFocus = true;
  1515. else
  1516. bHasFocus = false;
  1517. }
  1518. if ( MPlayer->missionSettings.allTech )
  1519. {
  1520. if ( factionDropList.ListBox().GetItemCount() != 1 )
  1521. {
  1522. factionDropList.SelectItem( -1 );
  1523. factionDropList.ListBox().removeAllItems( true );
  1524. aStyle2TextListItem *pTmp2;
  1525. pTmp2 = new aStyle2TextListItem;
  1526. *pTmp2 = templateItem;
  1527. pTmp2->setText( IDS_FACTION0 + 5 );
  1528. pTmp2->resize( factionDropList.width() -
  1529. factionDropList.ListBox().getScrollBarWidth() - 8,
  1530. pTmp2->height() );
  1531. pTmp2->sizeToText();
  1532. factionDropList.AddItem(pTmp2);
  1533. factionDropList.SelectItem( 0 );
  1534. }
  1535. }
  1536. else if ( factionDropList.ListBox().GetItemCount() < 4 )
  1537. {
  1538. factionDropList.SelectItem( -1 );
  1539. factionDropList.ListBox().removeAllItems( true );
  1540. for ( int i = 0; i < 4; i += 1)
  1541. {
  1542. aStyle2TextListItem *pTmp2;
  1543. pTmp2 = new aStyle2TextListItem;
  1544. *pTmp2 = templateItem;
  1545. pTmp2->setText( IDS_FACTION0 + i );
  1546. pTmp2->resize( factionDropList.width() -
  1547. factionDropList.ListBox().getScrollBarWidth() - 8,
  1548. pTmp2->height() );
  1549. pTmp2->sizeToText();
  1550. factionDropList.AddItem(pTmp2);
  1551. factionDropList.SelectItem( 0 );
  1552. }
  1553. }
  1554. // don't accept any kind of input for anything but your own stuff....
  1555. if ( commanderID != MPlayer->commanderID && !MPlayer->isHost() )
  1556. {
  1557. CBillsSpinnerUpButton.showGUIWindow( 0 );
  1558. CBillsSpinnerDownButton.showGUIWindow( 0 );
  1559. teamNumberDropList.disable( true );
  1560. factionDropList.disable( true );
  1561. rects[2].showGUIWindow( 0 );
  1562. rects[7].showGUIWindow( 0 );
  1563. rects[8].showGUIWindow( 0 );
  1564. rects[1].showGUIWindow( 0 );
  1565. return;
  1566. }
  1567. else
  1568. {
  1569. if ( MPlayer->isHost() )
  1570. {
  1571. CBillsSpinnerUpButton.showGUIWindow( 1 );
  1572. CBillsSpinnerDownButton.showGUIWindow( 1 );
  1573. }
  1574. else
  1575. {
  1576. CBillsSpinnerUpButton.showGUIWindow( 0 );
  1577. CBillsSpinnerDownButton.showGUIWindow( 0 );
  1578. }
  1579. teamNumberDropList.disable( 0 );
  1580. factionDropList.disable( 0 );
  1581. rects[2].showGUIWindow( 1 );
  1582. rects[7].showGUIWindow( 1 );
  1583. rects[8].showGUIWindow( 1 );
  1584. rects[1].showGUIWindow( 1 );
  1585. }
  1586. if ( commanderID == MPlayer->commanderID )
  1587. {
  1588. if ( !MPlayer->isHost() )
  1589. {
  1590. FullPathFileName path;
  1591. path.init( missionPath, MPlayer->missionSettings.map, ".fit" );
  1592. if ( !fileExists( path ) ||
  1593. MPParameterScreen::getGUIDFromFile( MPlayer->missionSettings.map ) != MPlayer->missionSettings.mapGuid ) // disable the ready button if the map isn't around...
  1594. {
  1595. ReadyButton.disable( false );
  1596. ReadyButton.press( 0 );
  1597. ReadyButton.disable( true );
  1598. }
  1599. else
  1600. ReadyButton.disable( false );
  1601. }
  1602. }
  1603. if ( !bHasFocus )
  1604. return;
  1605. bool bOldReady = ReadyButton.isPressed();
  1606. if ( bOldReady ) // need to check the ready button if nothing else
  1607. {
  1608. ReadyButton.update();
  1609. }
  1610. // need to check for changes
  1611. int oldSel = teamNumberDropList.GetSelectedItem();
  1612. int oldFaction = factionDropList.GetSelectedItem();
  1613. const char* pText = textObjects[1].text;
  1614. long oldCBills = 0;
  1615. if ( pText )
  1616. {
  1617. oldCBills = atoi( pText ) * 1000;
  1618. }
  1619. bool bCBillsChanged = 0;
  1620. if ( !bOldReady || ( MPlayer->isHost() ) ) // don't do anything if all ready.
  1621. {
  1622. if ( (commanderID == MPlayer->commanderID || MPlayer->isHost() ) )
  1623. {
  1624. edit.setReadOnly( 0 );
  1625. bool bHasFocus = edit.hasFocus();
  1626. edit.update();
  1627. if ( bHasFocus && !edit.hasFocus() )
  1628. bCBillsChanged = true;
  1629. if ( commanderID == MPlayer->commanderID )
  1630. ReadyButton.update();
  1631. CBillsSpinnerDownButton.update();
  1632. CBillsSpinnerUpButton.update( );
  1633. factionDropList.update();
  1634. teamNumberDropList.update();
  1635. }
  1636. }
  1637. else
  1638. edit.setReadOnly( 1 );
  1639. int newSel = teamNumberDropList.GetSelectedItem();
  1640. int newFaction = factionDropList.GetSelectedItem();
  1641. bool bNewReady = ReadyButton.isPressed();
  1642. EString cBillsText;
  1643. edit.getEntry( cBillsText );
  1644. long newCBills = 0;
  1645. if ( cBillsText.Length() )
  1646. {
  1647. newCBills = atoi( cBillsText ) * 1000;
  1648. }
  1649. if ( bCBillsChanged )
  1650. {
  1651. MC2Player* pInfo = MPlayer->getPlayerInfo( commanderID );
  1652. pInfo->cBills = newCBills;
  1653. MPlayer->sendPlayerUpdate( 0, 5, commanderID );
  1654. char text[256];
  1655. sprintf(text, "%ld", pInfo->cBills/5000 * (5) ); // need to round to nearest 5000
  1656. edit.setEntry( text );
  1657. MPParameterScreen::resetCheckBoxes();
  1658. }
  1659. else if ( (oldSel != newSel) || (oldFaction != newFaction) ||
  1660. (bOldReady != bNewReady) )
  1661. {
  1662. // send out new info....
  1663. if ( MPlayer )
  1664. {
  1665. MC2Player* pInfo = MPlayer->getPlayerInfo( commanderID );
  1666. pInfo->cBills = newCBills;
  1667. if ( MPlayer->isHost() )
  1668. pInfo->ready = 0;
  1669. else
  1670. pInfo->ready = bNewReady;
  1671. pInfo->faction = newFaction;
  1672. if (MPlayer->isHost())
  1673. {
  1674. if (pInfo->team != newSel)
  1675. MPlayer->setPlayerTeam(commanderID, newSel);
  1676. }
  1677. else {
  1678. pInfo->team = newSel;
  1679. MPlayer->sendPlayerUpdate( 0, 5, commanderID );
  1680. }
  1681. }
  1682. bHasFocus = 0;
  1683. }
  1684. if ( userInput->getKeyDown( KEY_RETURN ) )
  1685. bHasFocus = false;
  1686. }
  1687. void aPlayerParams::disableReadyButton()
  1688. {
  1689. ReadyButton.disable( true );
  1690. }
  1691. void aPlayerParams::setData( const _MC2Player* data)
  1692. {
  1693. bool bDisable = ( data->cBills <= 0 );
  1694. CBillsSpinnerDownButton.disable( bDisable );
  1695. bDisable = ( data->cBills >= 1000000 );
  1696. CBillsSpinnerUpButton.disable( bDisable );
  1697. if ( data->ready )
  1698. {
  1699. if ( data->commanderID != MPlayer->commanderID )
  1700. ReadyButton.disable( false );
  1701. ReadyButton.press( 1 );
  1702. }
  1703. else
  1704. {
  1705. if ( ReadyButton.isPressed() )
  1706. soundSystem->playDigitalSample( LOG_UNREADY );
  1707. ReadyButton.press( 0 );
  1708. }
  1709. commanderID = data->commanderID;
  1710. long textColor = 0xff000000;
  1711. long newColor = MPlayer->colors[data->baseColor[BASECOLOR_TEAM]];
  1712. if ( ((newColor & 0xff) + ( (newColor & 0xff00)>>8 ) + ( (newColor & 0xff0000)>>16 ))/3 < 85 )
  1713. textColor = 0xffffffff;
  1714. if ( textObjects )
  1715. {
  1716. textObjects[0].setText( data->name );
  1717. textObjects[1].setText( data->unitName );
  1718. textObjects[0].setColor( textColor );
  1719. textObjects[1].setColor( textColor );
  1720. char text[256];
  1721. sprintf(text, "%ld", data->cBills/5000 * 5 );
  1722. if ( !edit.hasFocus() )
  1723. edit.setEntry( text );
  1724. }
  1725. rects[4].setColor( MPlayer->colors[data->stripeColor] );
  1726. rects[6].setColor( MPlayer->colors[data->baseColor[BASECOLOR_TEAM]] );
  1727. // set up the insignia...
  1728. // I really need to store this... really don't want to allocate a texture every time
  1729. const char* pFileName = data->insigniaFile;
  1730. if ( pFileName != insigniaName )
  1731. {
  1732. FullPathFileName path;
  1733. path.init( "data\\multiplayer\\insignia\\", data->insigniaFile, ".tga" );
  1734. if ( fileExists( path ) )
  1735. {
  1736. statics[0].setTexture( path );
  1737. statics[0].setUVs( 0, 0, 32, 32 );
  1738. insigniaName = pFileName;
  1739. MPlayer->insigniaList[data->commanderID] = 1;
  1740. }
  1741. }
  1742. if ( !teamNumberDropList.IsExpanded() )
  1743. {
  1744. int oldSel = teamNumberDropList.ListBox().GetSelectedItem();
  1745. if ( teamNumberDropList.ListBox().GetItemCount() != MPlayer->missionSettings.maxTeams )
  1746. {
  1747. teamNumberDropList.ListBox().removeAllItems( true );
  1748. for ( int i = 0; i < MPlayer->missionSettings.maxTeams; i ++ )
  1749. {
  1750. aStyle2TextListItem* pTmp2 = new aStyle2TextListItem;
  1751. char tmpStr[32];
  1752. sprintf(tmpStr, "%ld", i+1);
  1753. *pTmp2 = templateItem;
  1754. pTmp2->setText( tmpStr );
  1755. pTmp2->resize( teamNumberDropList.width() -
  1756. teamNumberDropList.ListBox().getScrollBarWidth() - 8, pTmp2->height() );
  1757. pTmp2->sizeToText();
  1758. teamNumberDropList.AddItem(pTmp2);
  1759. }
  1760. if ( oldSel < teamNumberDropList.ListBox().GetItemCount() )
  1761. teamNumberDropList.SelectItem(oldSel);
  1762. else
  1763. teamNumberDropList.SelectItem(0);
  1764. }
  1765. teamNumberDropList.SelectItem( data->team );
  1766. }
  1767. if ( !factionDropList.IsExpanded() )
  1768. {
  1769. factionDropList.SelectItem( data->faction );
  1770. }
  1771. }
  1772. int aPlayerParams::handleMessage( unsigned long message, unsigned long who )
  1773. {
  1774. float increment = 5000;
  1775. if ( message == aMSG_LEFTMOUSEHELD )
  1776. {
  1777. increment = 1000;
  1778. }
  1779. switch( who )
  1780. {
  1781. case MP_INCREMENT_PLAYER_CBILLS:
  1782. {
  1783. MC2Player* pInfo = MPlayer->getPlayerInfo( commanderID );
  1784. pInfo->cBills += increment;
  1785. char text[256];
  1786. sprintf(text, "%ld", pInfo->cBills/5000 * (5) ); // need to round to nearest 5000
  1787. edit.setEntry( text );
  1788. MPParameterScreen::resetCheckBoxes();
  1789. break;
  1790. }
  1791. case MP_DECREMENT_PLAYER_CBILLS:
  1792. {
  1793. MC2Player* pInfo = MPlayer->getPlayerInfo( commanderID );
  1794. pInfo->cBills -= increment;
  1795. char text[256];
  1796. sprintf(text, "%ld", pInfo->cBills/5000 * (5) );
  1797. edit.setEntry( text );
  1798. MPParameterScreen::resetCheckBoxes();
  1799. }
  1800. break;
  1801. }
  1802. return 0;
  1803. }
  1804. void aPlayerParams::render()
  1805. {
  1806. aObject::render();
  1807. }
  1808. void aPlayerParams::move( float offsetX, float offsetY )
  1809. {
  1810. aObject::move( offsetX, offsetY );
  1811. }
  1812. long aStyle2TextListItem::init( FitIniFile* file, const char* blockName )
  1813. {
  1814. file->seekBlock( blockName );
  1815. long fontResID = 0;
  1816. file->readIdLong( "Font", fontResID );
  1817. long textID = 0;
  1818. file->readIdLong( "TextID", textID );
  1819. aTextListItem::init(fontResID);
  1820. setText(textID);
  1821. long color = 0xff808080;
  1822. file->readIdLong( "Color", color );
  1823. normalColor = color;
  1824. setColor(color);
  1825. char tmpStr[64];
  1826. strcpy(tmpStr, "");
  1827. file->readIdString( "Animation", tmpStr, 63 );
  1828. if (0 == strcmp("", tmpStr))
  1829. {
  1830. hasAnimation = false;
  1831. }
  1832. else
  1833. {
  1834. hasAnimation = true;
  1835. animGroup.init(file, tmpStr);
  1836. }
  1837. return 0;
  1838. }
  1839. void aStyle2TextListItem::render()
  1840. {
  1841. long color = normalColor;
  1842. if ( hasAnimation )
  1843. {
  1844. if ( animGroup.getState() != getState() )
  1845. animGroup.setState( (aAnimGroup::STATE)(long)getState() );
  1846. animGroup.update();
  1847. color = animGroup.getCurrentColor( animGroup.getState() );
  1848. }
  1849. /* if (aListItem::SELECTED == getState())
  1850. {
  1851. color = 0.33 * ((unsigned long)normalColor) + 0.67 * ((unsigned long)0xffffffff);
  1852. }
  1853. else if (aListItem::HIGHLITE == getState())
  1854. {
  1855. color = 0.67 * ((unsigned long)normalColor) + 0.33 * ((unsigned long)0xffffffff);
  1856. }
  1857. else
  1858. {
  1859. color = normalColor;
  1860. }*/
  1861. aTextListItem::setColor((unsigned long)color);
  1862. aTextListItem::render();
  1863. }
  1864. CFocusManager::CFocusManager()
  1865. {
  1866. clear();
  1867. }
  1868. void CFocusManager::clear()
  1869. {
  1870. speciesOfTheControlWhichHasTheFocus = CS_NONE;
  1871. pDropListThatHasTheFocus = NULL;
  1872. listOfDropListPointers.Clear();
  1873. }
  1874. void *CFocusManager::registerDropList(aDropList &DropList)
  1875. {
  1876. listOfDropListPointers.Append(&DropList);
  1877. return ((void *)&DropList);
  1878. }
  1879. void CFocusManager::unregisterDropList(aDropList &DropList)
  1880. {
  1881. listOfDropListPointers.Delete(listOfDropListPointers.Find(&DropList));
  1882. }
  1883. void CFocusManager::update()
  1884. {
  1885. if (userInput->isLeftClick())
  1886. {
  1887. /*focus may have changed*/
  1888. if (NULL != pControlThatHasTheFocus())
  1889. {
  1890. if (pControlThatHasTheFocus()->pointInside(userInput->getMouseX(), userInput->getMouseY()))
  1891. {
  1892. /*the pointer was clicked on the control that already has the focus, so the focus
  1893. is unaffected*/
  1894. return;
  1895. }
  1896. }
  1897. /*reset focus*/
  1898. switch (speciesOfTheControlWhichHasTheFocus)
  1899. {
  1900. case CS_DROPLIST:
  1901. pDropListThatHasTheFocus = NULL;
  1902. break;
  1903. }
  1904. speciesOfTheControlWhichHasTheFocus = CS_NONE;
  1905. /*check the droplists to see the pointer was clicked in one of them*/
  1906. CListOfDropListPointers::EIterator DropListIter = listOfDropListPointers.Begin();
  1907. while (!DropListIter.IsDone())
  1908. {
  1909. if ((*DropListIter)->pointInside(userInput->getMouseX(), userInput->getMouseY()))
  1910. {
  1911. pDropListThatHasTheFocus = (*DropListIter);
  1912. speciesOfTheControlWhichHasTheFocus = CS_DROPLIST;
  1913. break;
  1914. }
  1915. DropListIter++;
  1916. }
  1917. if (CS_NONE == speciesOfTheControlWhichHasTheFocus)
  1918. {
  1919. /*No droplist got the focus. Check the other control species.*/
  1920. }
  1921. /*make sure all drop lists that do not have focus are unexpanded*/
  1922. DropListIter = listOfDropListPointers.Begin();
  1923. while (!DropListIter.IsDone())
  1924. {
  1925. if ((CS_DROPLIST != speciesOfTheControlWhichHasTheFocus)
  1926. || ((*DropListIter) != pDropListThatHasTheFocus))
  1927. {
  1928. (*DropListIter)->IsExpanded(false);
  1929. }
  1930. DropListIter++;
  1931. }
  1932. }
  1933. }
  1934. bool CFocusManager::somebodyHasTheFocus()
  1935. {
  1936. if (CS_NONE == speciesOfTheControlWhichHasTheFocus)
  1937. {
  1938. return false;
  1939. }
  1940. else
  1941. {
  1942. return true;
  1943. }
  1944. }
  1945. aObject *CFocusManager::pControlThatHasTheFocus()
  1946. {
  1947. if (CS_NONE != speciesOfTheControlWhichHasTheFocus)
  1948. {
  1949. switch(speciesOfTheControlWhichHasTheFocus)
  1950. {
  1951. case CS_DROPLIST:
  1952. return pDropListThatHasTheFocus;
  1953. break;
  1954. }
  1955. assert(false);
  1956. }
  1957. return NULL;
  1958. }
  1959. //////////////////////////////////////////////
  1960. //*************************************************************************************************
  1961. // end of file ( MPParameterScreen.cpp )