PilotReviewArea.cpp 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782
  1. #define SALVAGEMECHAREA_CPP
  2. /*************************************************************************************************\
  3. SalvageMechArea.cpp : Implementation of the SalvageMechArea component.
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. \*************************************************************************************************/
  8. #include "PilotReviewArea.h"
  9. #include "IniFile.h"
  10. #include "objMgr.h"
  11. #include "LogisticsPilot.h"
  12. #include "LogisticsData.h"
  13. #include "..\resource.h"
  14. #include "mech.h"
  15. #include <malloc.h>
  16. #include "MechIcon.h"
  17. #include "windows.h"
  18. #include "gameSound.h"
  19. aText* DeadPilotListItem::s_nameText = NULL;
  20. aText* DeadPilotListItem::s_rankText = NULL;
  21. aText* DeadPilotListItem::s_missionText = NULL;
  22. aText* DeadPilotListItem::s_killsText = NULL;
  23. aRect* DeadPilotListItem::s_area = NULL;
  24. aRect* DeadPilotListItem::s_liveIconRect = NULL;
  25. aRect* DeadPilotListItem::s_deadIconRect = NULL;
  26. long DeadPilotListItem::s_itemCount = 0;
  27. aText* ActivePilotListItem::s_nameText = NULL;
  28. aText* ActivePilotListItem::s_missionText = NULL;
  29. aText* ActivePilotListItem::s_killsText = NULL;
  30. aText* ActivePilotListItem::s_rankText = NULL;
  31. aText* ActivePilotListItem::s_gunneryText = NULL;
  32. aText* ActivePilotListItem::s_pilotingText = NULL;
  33. long ActivePilotListItem::s_itemCount = 0;
  34. aRect* ActivePilotListItem::s_outline[5];
  35. aObject* ActivePilotListItem::s_icons[8];
  36. aRect* ActivePilotListItem::s_area = NULL;
  37. aRect* ActivePilotListItem::s_iconRect = NULL;
  38. AttributeMeter* ActivePilotListItem::s_attributeMeters[2] = { 0,0};
  39. aRect* ActivePilotListItem::s_killIconRect = NULL;
  40. PilotPromotionArea* ActivePilotListItem::s_pilotPromotionArea = NULL;
  41. aText* ActivePilotListItem::s_medalAwardedText = 0;
  42. aText* ActivePilotListItem::s_medalText= 0;
  43. aText* ActivePilotListItem::s_promotionText = 0;
  44. aObject* ActivePilotListItem::s_medals[MAX_MEDAL] = {0};
  45. aAnimation* ActivePilotListItem::s_skillAnim = NULL;
  46. aAnimation* ActivePilotListItem::s_medalAwardedAnim = NULL;
  47. aAnimation* ActivePilotListItem::s_pilotPromotedAnim = NULL;
  48. long ActivePilotListItem::s_totalWidth = 0;
  49. PilotPromotionArea* PilotReviewScreen::s_curPromotion = NULL;;
  50. aButton* SpecialtyListItem::s_radioButton = 0;
  51. aObject* SpecialtyListItem::s_skillIcons[4] = {0,0,0,0};
  52. aAnimation* SpecialtyListItem::s_highlightAnim = 0;
  53. aAnimation* SpecialtyListItem::s_normalAnim = 0;
  54. aAnimation* SpecialtyListItem::s_pressedAnim = 0;
  55. aText* SpecialtyListItem::s_description = 0;
  56. aRect* SpecialtyListItem::s_area = 0;
  57. aRect* SpecialtyListItem::s_outline = 0;
  58. long SpecialtyListItem::s_itemCount = 0; // hack, we really don't want to delete these each time
  59. PilotReviewScreen* PilotReviewScreen::instance = NULL;
  60. extern float frameLength;
  61. #define RP_TEXTID 3
  62. #define HELP_TEXTID 2
  63. #define NAME_TEXTID 0
  64. #define WEIGHT_TEXTID 2
  65. #define ARMOR_TEXTID 3
  66. #define SPEED_TEXTID 4
  67. #define JUMP_TEXTID 5
  68. #define APPEARTIME .5f
  69. #define CHECK_BUTTON 200
  70. PilotReviewScreen::PilotReviewScreen()
  71. {
  72. statics = 0;
  73. rects = 0;
  74. staticCount = rectCount = buttonCount = textCount = 0;
  75. buttons = 0;
  76. textObjects = 0;
  77. bDone = 0;
  78. instance = this;
  79. // this MUST be initialized
  80. LogisticsData::instance->init();
  81. fadeOutMaxColor = 0x7f000000;
  82. }
  83. PilotReviewScreen::~PilotReviewScreen()
  84. {
  85. pilotListBox.removeAllItems( true );
  86. long count = LogisticsData::instance->getPilotCount();
  87. LogisticsPilot** pPilots = (LogisticsPilot**)_alloca( count * sizeof(LogisticsPilot*) );
  88. LogisticsData::instance->getPilots( pPilots, count );
  89. bool bDeadTextAdded = 0;
  90. bool bFirst = 0;
  91. for ( int i = 0; i < count; i++ )
  92. {
  93. pPilots[i]->clearIcons();
  94. pPilots[i]->setJustDied( 0 );
  95. }
  96. }
  97. void PilotReviewScreen::init(FitIniFile* file)
  98. {
  99. LogisticsScreen::init( *file, "PilotReviewStatic",
  100. "PilotReviewText", "PilotReviewRect", "PilotReviewButton" );
  101. file->seekBlock( "PilotReviewMisc" );
  102. long tmp;
  103. file->readIdLong( "PilotReviewSmallSkip", tmp );
  104. pilotListBox.setSpaceBetweenItems( tmp );
  105. long color, font;
  106. file->readIdLong( "color", color );
  107. file->readIdLong( "font", font );
  108. pilotListBox.init( rects[0].left(), rects[0].top(),
  109. rects[0].width(), rects[0].height() );
  110. DeadPilotListItem::init( file );
  111. ActivePilotListItem::init( file );
  112. ActivePilotListItem::s_totalWidth = pilotListBox.width() - 70;
  113. long count = LogisticsData::instance->getPilotCount();
  114. LogisticsPilot** pPilots = (LogisticsPilot**)_alloca( count * sizeof(LogisticsPilot*) );
  115. LogisticsData::instance->getPilots( pPilots, count );
  116. bool bDeadTextAdded = 0;
  117. bool bFirst = 0;
  118. for ( int i = 0; i < count; i++ )
  119. {
  120. if ( pPilots[i]->justDied() && pPilots[i]->isUsed() )
  121. {
  122. if ( !bDeadTextAdded )
  123. {
  124. aTextListItem* pItem = new aTextListItem( font );
  125. pItem->setText( IDS_KILLED_IN_ACTION );
  126. pItem->setColor( color ) ;
  127. pilotListBox.AddItem( pItem );
  128. bDeadTextAdded = true;
  129. }
  130. DeadPilotListItem* pItem = new DeadPilotListItem( pPilots[i] );
  131. if ( !bFirst )
  132. {
  133. pItem->begin();
  134. pItem->showGUIWindow(0);
  135. }
  136. bFirst = 1;
  137. pilotListBox.AddItem( pItem );
  138. }
  139. }
  140. if ( bDeadTextAdded )
  141. {
  142. aTextListItem* pItem = new aTextListItem( font );
  143. pItem->setText( "" );
  144. pItem->setColor( color ) ;
  145. pilotListBox.AddItem( pItem );
  146. }
  147. bool bLiveTextAdded = 0;
  148. bool bJustPromoted = 0;
  149. for ( i = 0; i < count; i++ )
  150. {
  151. if ( !pPilots[i]->isDead() && pPilots[i]->isUsed() )
  152. {
  153. if ( !bLiveTextAdded )
  154. {
  155. aTextListItem* pItem = new aTextListItem( font );
  156. pItem->setText( IDS_ACTIVE_DUTY );
  157. pItem->setColor( color ) ;
  158. long oldHeight = pItem->height();
  159. pItem->resize( pItem->width(), oldHeight + 20 );
  160. if ( bDeadTextAdded )
  161. pItem->showGUIWindow( 0 );
  162. pilotListBox.AddItem( pItem );
  163. bLiveTextAdded = true;
  164. }
  165. ActivePilotListItem* pItem = new ActivePilotListItem( pPilots[i] );
  166. pilotListBox.AddItem( pItem );
  167. if ( pPilots[i]->promotePilot() )
  168. bJustPromoted = true;
  169. }
  170. }
  171. entryAnim.initWithBlockName( file, "PilotAreaBeginAnimation" );
  172. entryAnim.begin();
  173. exitAnim.initWithBlockName( file, "PilotReviewFadeOutAnimation" );
  174. beginFadeIn( 0 );
  175. gosASSERT( rects ); // need this for the list box
  176. if ( bJustPromoted ) // disable done button if promotion is going to happen
  177. buttons[0].disable( true );
  178. }
  179. void PilotReviewScreen::render()
  180. {
  181. long xOffset = 0;
  182. long yOffset = 0;
  183. if ( !entryAnim.isDone() )
  184. {
  185. xOffset = entryAnim.getXDelta();
  186. yOffset = entryAnim.getYDelta();
  187. }
  188. else if ( bDone )
  189. {
  190. xOffset = exitAnim.getXDelta();
  191. yOffset = exitAnim.getYDelta();
  192. }
  193. pilotListBox.move( xOffset, yOffset );
  194. pilotListBox.render();
  195. pilotListBox.move( -xOffset, -yOffset );
  196. LogisticsScreen::render( xOffset, yOffset );
  197. if ( s_curPromotion )
  198. s_curPromotion->render();
  199. }
  200. int PilotReviewScreen::handleMessage( unsigned long message, unsigned long who)
  201. {
  202. if ( who == aMSG_DONE && entryAnim.isDone() )
  203. {
  204. bDone = true;
  205. exitAnim.begin();
  206. beginFadeOut( 1.0 );
  207. soundSystem->stopBettySample(); // don't want to carry droning on to next screen
  208. return 1;
  209. }
  210. return 0;
  211. }
  212. bool PilotReviewScreen::isDone()
  213. {
  214. return bDone && exitAnim.isDone();
  215. }
  216. void PilotReviewScreen::update()
  217. {
  218. if ( s_curPromotion && !bDone )
  219. {
  220. s_curPromotion->update();
  221. if ( s_curPromotion->isDone() )
  222. s_curPromotion = 0;
  223. return;
  224. }
  225. if ( entryAnim.isDone() )
  226. pilotListBox.update();
  227. for ( int i = 0; i < buttonCount; i++ )
  228. {
  229. buttons[i].update();
  230. if ( buttons[i].pointInside( userInput->getMouseX(), userInput->getMouseY() )
  231. && userInput->isLeftClick()
  232. && buttons[i].isEnabled() )
  233. {
  234. handleMessage( aMSG_DONE, aMSG_DONE );
  235. }
  236. }
  237. if ( pilotListBox.isDone() )
  238. buttons[0].disable( false );
  239. entryAnim.update();
  240. exitAnim.update();
  241. }
  242. void PilotReviewScreen::updatePilots()
  243. {
  244. }
  245. //////////////////////////////////////////////
  246. DeadPilotListItem::~DeadPilotListItem()
  247. {
  248. removeAllChildren( false ); // don't delete
  249. if ( liveIcon )
  250. delete liveIcon;
  251. if ( deadIcon )
  252. delete deadIcon;
  253. deadIcon = liveIcon = NULL;
  254. s_itemCount--;
  255. if ( s_itemCount < 1 )
  256. {
  257. if ( s_area )
  258. delete s_area;
  259. s_area = NULL;
  260. if ( s_missionText )
  261. delete s_missionText;
  262. s_missionText = NULL;
  263. if ( s_killsText )
  264. delete s_killsText;
  265. s_killsText = NULL;
  266. if ( s_rankText )
  267. delete s_rankText;
  268. s_rankText = NULL;
  269. if ( s_nameText )
  270. delete s_nameText;
  271. s_nameText = NULL;
  272. if ( s_liveIconRect )
  273. delete s_liveIconRect;
  274. s_liveIconRect = NULL;
  275. if ( s_deadIconRect )
  276. delete s_deadIconRect;
  277. s_deadIconRect = NULL;
  278. }
  279. }
  280. bool DeadPilotListItem::isDone()
  281. {
  282. return currentTime > APPEARTIME ? 1 : 0;
  283. }
  284. void DeadPilotListItem::init( FitIniFile* file )
  285. {
  286. s_area = new aRect;
  287. s_missionText = new aText;
  288. s_killsText = new aText;
  289. s_rankText = new aText;
  290. s_nameText = new aText;
  291. s_liveIconRect = new aRect;
  292. s_deadIconRect = new aRect;
  293. s_area->init( file, "PilotReviewKIABox" );
  294. s_liveIconRect->init( file, "KIABoxPilotIcon" );
  295. s_deadIconRect->init( file, "KIABoxDeadIcon" );
  296. s_missionText->init( file, "KIAMissionsText" );
  297. s_rankText->init( file, "KIARankText" );
  298. s_nameText->init( file, "KIAPilotNameText" );
  299. s_killsText->init( file, "KIAKillsText" );
  300. }
  301. DeadPilotListItem::DeadPilotListItem( LogisticsPilot* pPilot )
  302. {
  303. char tmpText[256];
  304. char realText[256];
  305. aObject::init( s_area->left(), s_area->top(), s_area->width(), s_area->height() );
  306. killsText = *s_killsText;
  307. nameText = *s_nameText;
  308. rankText = *s_rankText;
  309. missionText = *s_missionText;
  310. int missions = pPilot->getNumberMissions();
  311. cLoadString( IDS_PILOT_MISSIONS, tmpText, 255 );
  312. sprintf( realText, tmpText, missions );
  313. missionText.setText( realText);
  314. int numberOfKills = pPilot->getInfantryKills() + pPilot->getMechKills() + pPilot->getVehicleKills();
  315. cLoadString( IDS_PILOT_KILLS, tmpText, 255 );
  316. sprintf( realText, tmpText, numberOfKills );
  317. killsText.setText( realText);
  318. const char* name = pPilot->getName();
  319. cLoadString( IDS_PILOT_NAME, tmpText, 255 );
  320. sprintf( realText, tmpText, name );
  321. nameText.setText( realText);
  322. long rank = pPilot->getRank();
  323. char rankStr[32];
  324. //ACE Not Contiguous with other ranks. Added too late.
  325. if (rank != 4)
  326. cLoadString( rank + IDS_GREEN, rankStr, 31 );
  327. else
  328. cLoadString( IDS_ACE, rankStr, 31 );
  329. cLoadString( IDS_PILOT_RANK, tmpText, 255 );
  330. sprintf( realText, tmpText, rankStr );
  331. rankText.setText( realText);
  332. addChild( &killsText );
  333. addChild( &nameText );
  334. addChild( &rankText );
  335. addChild( &missionText );
  336. liveIcon = new PilotIcon( );
  337. liveIcon->setTextureIndex( pPilot->getPhotoIndex() );
  338. deadIcon = new PilotIcon( );
  339. deadIcon->setTextureIndex( PilotIcon::DEAD_PILOT_INDEX );
  340. showWindow = 0;
  341. }
  342. void DeadPilotListItem::update()
  343. {
  344. PilotListItem::update();
  345. }
  346. void DeadPilotListItem::render()
  347. {
  348. if ( !showWindow )
  349. return;
  350. GUI_RECT tmp;
  351. tmp.left = globalX();
  352. tmp.right = globalX() + width();
  353. tmp.top = globalY();
  354. tmp.bottom = globalY() + height();
  355. aObject::render();
  356. drawEmptyRect( tmp, s_area->getColor(), s_area->getColor() );
  357. liveIcon->render( globalX() + s_liveIconRect->left(),
  358. globalY() + s_liveIconRect->top(),
  359. globalX() + s_liveIconRect->left() + s_liveIconRect->width(),
  360. globalY() + s_liveIconRect->top() + s_liveIconRect->height() );
  361. tmp.left = globalX() + s_liveIconRect->left();
  362. tmp.top = globalY() + s_liveIconRect->top();
  363. tmp.right = globalX() + s_liveIconRect->left() + s_liveIconRect->width();
  364. tmp.bottom = globalY() + s_liveIconRect->top() + s_liveIconRect->height();
  365. drawEmptyRect( tmp, s_liveIconRect->getColor(), s_liveIconRect->getColor() );
  366. deadIcon->render( globalX() + s_deadIconRect->left(),
  367. globalY() + s_deadIconRect->top(),
  368. globalX() + s_deadIconRect->left() + s_deadIconRect->width(),
  369. globalY() + s_deadIconRect->top() + s_deadIconRect->height() );
  370. tmp.left = globalX() + s_deadIconRect->left();
  371. tmp.top = globalY() + s_deadIconRect->top();
  372. tmp.right = globalX() + s_deadIconRect->left() + s_deadIconRect->width();
  373. tmp.bottom = globalY() + s_deadIconRect->top() + s_deadIconRect->height();
  374. drawEmptyRect( tmp, s_deadIconRect->getColor(), s_deadIconRect->getColor() );
  375. }
  376. long PilotListBox::AddItem( aListItem* add )
  377. {
  378. bDone= 0;
  379. DeadPilotListItem* pItem = dynamic_cast< DeadPilotListItem* >( add );
  380. if ( pItem )
  381. {
  382. if (itemCount >= MAX_LIST_ITEMS)
  383. return TOO_MANY_ITEMS;
  384. float lastX = x() + add->x();
  385. float lastY = y() + skipAmount;
  386. if ( itemCount > 1 )
  387. {
  388. lastX = items[itemCount-2]->x();
  389. lastY = items[itemCount-2]->bottom() + skipAmount;
  390. }
  391. else if ( itemCount )
  392. {
  393. lastY = items[itemCount-1]->bottom() + skipAmount;
  394. }
  395. if ( (itemCount && !(itemCount % 2)) ) // even ones go somewhere else
  396. {
  397. lastX = items[itemCount-1]->x() + add->width() + skipAmount;
  398. lastY = items[itemCount-1]->y();
  399. }
  400. items[itemCount++] = add;
  401. add->moveTo( lastX, lastY );
  402. if ( add->right() > right() ) // can't have it hanging over the edge
  403. {
  404. float shrink = right() - add->right();
  405. add->resize( add->width() + shrink, add->height() );
  406. }
  407. if ( scrollBar && !(itemCount % 2))
  408. {
  409. int itemsTotalHeight = 0;
  410. if ( items )
  411. itemsTotalHeight = items[itemCount-1]->bottom() - items[0]->top();
  412. if ( itemsTotalHeight > scrollBar->height() )
  413. scrollBar->SetScrollMax( itemsTotalHeight - scrollBar->height() );
  414. else
  415. scrollBar->SetScrollMax( 0 );
  416. }
  417. }
  418. else
  419. {
  420. aListBox::AddItem( add );
  421. }
  422. return NO_ERR;
  423. }
  424. void PilotListBox::update()
  425. {
  426. aObject::update();
  427. timeSinceStart += frameLength;
  428. if ( timeSinceStart < 1.0 )
  429. return;
  430. if ( this->curItem >= itemCount )
  431. {
  432. for ( int i = 0; i < itemCount; i++ )
  433. {
  434. GetItem( i )->showGUIWindow( true );
  435. GetItem( i )->update();
  436. }
  437. bDone = true;
  438. return;
  439. }// done
  440. for ( int i = 0; i < itemCount; i++ )
  441. {
  442. bDone = 0;
  443. aListItem* item = GetItem( i );
  444. if ( item )
  445. {
  446. if ( i < curItem )
  447. {
  448. item->showGUIWindow( true );
  449. }
  450. else if ( i == curItem )
  451. {
  452. PilotListItem* pilotItem = dynamic_cast<PilotListItem*>(item);
  453. if ( pilotItem )
  454. {
  455. if ( pilotItem->isDone() )
  456. {
  457. pilotItem = NULL;
  458. while ( !pilotItem )
  459. {
  460. curItem++;
  461. scrollTime = 0.f;
  462. oldScroll = scrollBar->GetScrollPos();
  463. if ( curItem <= itemCount )
  464. {
  465. item = GetItem( curItem );
  466. pilotItem = dynamic_cast<PilotListItem*>(item);
  467. }
  468. else
  469. {
  470. curItem++;
  471. break;
  472. }
  473. }
  474. if ( pilotItem )
  475. {
  476. pilotItem->begin();
  477. }
  478. }
  479. else
  480. pilotItem->update();
  481. }
  482. else
  483. curItem++;
  484. if ( item )
  485. {
  486. float itemTop = item->globalY();
  487. if ( itemTop > bottom() - 3 * height() / 4 && !newScroll )
  488. {
  489. // need to scroll
  490. oldScroll = scrollBar->GetScrollPos();
  491. newScroll = oldScroll + itemTop - bottom() + 3 * height() / 4;
  492. if ( newScroll < oldScroll )
  493. newScroll = 0;
  494. }
  495. else if ( !newScroll )
  496. items[curItem]->showGUIWindow(1);
  497. }
  498. }
  499. else
  500. {
  501. item->showGUIWindow( false );
  502. }
  503. }
  504. }
  505. if ( newScroll )
  506. {
  507. scrollTime += frameLength;
  508. long delta = 140.f * scrollTime;
  509. if ( delta + oldScroll < newScroll && delta + oldScroll < scrollBar->GetScrollMax() )
  510. scrollBar->SetScroll( oldScroll + delta );
  511. else
  512. {
  513. scrollBar->SetScroll( newScroll );
  514. if ( items[curItem] )
  515. items[curItem]->showGUIWindow(1);
  516. newScroll = 0;
  517. scrollTime = 0;
  518. }
  519. }
  520. }
  521. PilotListBox::PilotListBox()
  522. {
  523. timeSinceStart = 0;
  524. curItem = 0;
  525. scrollTime = 0.f;
  526. oldScroll = 0.f;
  527. newScroll = 0.f;
  528. topSkip = 2.f;
  529. bDone = 0;
  530. }
  531. //////////////////////////////////
  532. void ActivePilotListItem::render()
  533. {
  534. if ( !showWindow )
  535. return;
  536. float timeOffset = 0;
  537. if ( pilot->killedIcons.Count() )
  538. timeOffset += 1.5 + .5 * pilot->killedIcons.Count();
  539. if ( currentTime - timeOffset > 0 )
  540. {
  541. medalAwardedText.setColor( s_medalAwardedAnim->getColor( currentTime - timeOffset ) );
  542. if ( currentTime - timeOffset > 1.5 )
  543. {
  544. float tmpTime = currentTime - timeOffset - 1.5;
  545. for ( int i = 0; i < medalCount; i++ )
  546. {
  547. if ( tmpTime > 0.f )
  548. {
  549. if ( !medalIcons[i]->isShowing() ) // play sound when it shows up
  550. {
  551. soundSystem->playDigitalSample( LOG_PILOTMEDAL );
  552. }
  553. medalIcons[i]->showGUIWindow( true );
  554. medalTexts[i]->showGUIWindow( true );
  555. }
  556. tmpTime -= .5f;
  557. }
  558. }
  559. }
  560. else
  561. {
  562. medalAwardedText.setColor( 0 );
  563. for ( int i = 0; i < medalCount; i++ )
  564. {
  565. medalIcons[i]->showGUIWindow( 0 );
  566. medalTexts[i]->showGUIWindow( 0 );
  567. }
  568. }
  569. if ( medalCount )
  570. timeOffset += (1.5 + .5 * medalCount);
  571. if ( currentTime - timeOffset > 0 )
  572. {
  573. if ( promotionText.getColor() == 0 && currentTime - timeOffset < .3
  574. && pilot->promotePilot() )
  575. {
  576. soundSystem->playDigitalSample( LOG_PROMOTED );
  577. }
  578. promotionText.setColor( s_pilotPromotedAnim->getColor( currentTime -timeOffset ) );
  579. }
  580. else
  581. {
  582. promotionText.setColor( 0 );
  583. }
  584. bool bCanBeDone = currentTime > flashTime();
  585. aObject::render();
  586. GUI_RECT tmp;
  587. tmp.left = s_area->left();
  588. tmp.top = globalY() + s_area->top();
  589. tmp.right = tmp.left + s_area->width();
  590. tmp.bottom = tmp.top + s_area->height();
  591. drawEmptyRect( tmp, s_area->getColor(), s_area->getColor() );
  592. // now do same thing with line....
  593. tmp.right = tmp.left + s_totalWidth;
  594. tmp.top -= 12;
  595. tmp.bottom = tmp.top + 2;
  596. drawRect( tmp, 0xff002f55 );
  597. pilotIcon->render( globalX() + s_iconRect->left(),
  598. globalY() + s_iconRect->top(),
  599. globalX() + s_iconRect->right(),
  600. globalY() + s_iconRect->bottom() );
  601. long color = s_skillAnim->getColor( currentTime );
  602. for ( int i = 0; i < 2; i++ )
  603. {
  604. attributeMeters[i].setAddedColorMax( color );
  605. attributeMeters[i].setAddedColorMin( color );
  606. attributeMeters[i].render(globalX(), globalY());
  607. }
  608. for ( i = 0; i < 5; i++ )
  609. {
  610. tmp = s_outline[i]->getGUI_RECT();
  611. tmp.left += globalX();
  612. tmp.top += globalY();
  613. tmp.right += globalX();
  614. tmp.bottom += globalY();
  615. drawEmptyRect( tmp, s_outline[i]->getColor(), s_outline[i]->getColor() );
  616. }
  617. long x = globalX() + s_killIconRect->left();
  618. long y = globalY() + s_killIconRect->top();
  619. int counter = 0;
  620. int oldPossible = 2.0 * (currentTime - frameLength - 1.5);
  621. int numPossible = 2.0 * (currentTime - 1.5);
  622. if ( currentTime - 1.5 < 0 )
  623. numPossible = -1;
  624. if (currentTime - 1.5 - frameLength < 0 )
  625. oldPossible = -1;
  626. if ( numPossible > 0 && promotionShown && bCanBeDone ) // finish when all of the dead guys are rendered
  627. bDone = true;
  628. // when adding a new icon, play sound
  629. if ( oldPossible != numPossible && numPossible < pilot->killedIcons.Count() )
  630. {
  631. soundSystem->playDigitalSample( LOG_KILLMARKER, Stuff::Vector3D(-9999.0f,-9999.0,-9999.0f), true );
  632. }
  633. for ( EList< ForceGroupIcon*, ForceGroupIcon* >::EIterator iter = pilot->killedIcons.Begin();
  634. !iter.IsDone(); iter++ )
  635. {
  636. if ( counter > numPossible )
  637. break;
  638. if ( counter && !(counter % 8) )
  639. {
  640. y += s_killIconRect->height() + 1;
  641. x = globalX() + s_killIconRect->left();
  642. }
  643. (*iter)->renderUnitIcon( x, y, x + s_killIconRect->width(), y + s_killIconRect->height() );
  644. x += s_killIconRect->width() + 1;
  645. counter++;
  646. }
  647. }
  648. void ActivePilotListItem::update()
  649. {
  650. if ( !isShowing() ) // do nothing until active
  651. return;
  652. if ( showingPromotion )// if in promotion area, do that...
  653. {
  654. s_pilotPromotionArea->update();
  655. PilotReviewScreen::s_curPromotion = s_pilotPromotionArea;
  656. if ( s_pilotPromotionArea->isDone() )
  657. {
  658. promotionShown = true;
  659. PilotReviewScreen::s_curPromotion = NULL;
  660. showingPromotion = false;
  661. }
  662. }
  663. else if ( !showingPromotion && !promotionShown && pilot->promotePilot() )
  664. {
  665. if ( currentTime > flashTime() + .5f ) // wait five seconds before bringing in the doors
  666. {
  667. s_pilotPromotionArea->setPilot( pilot, pilotIcon );
  668. showingPromotion = true;
  669. promotionShown = false;
  670. showGUIWindow( true );
  671. }
  672. }
  673. else if ( !pilot->promotePilot() )
  674. {
  675. promotionShown = true;
  676. showingPromotion = false;
  677. }
  678. PilotListItem::update();
  679. }
  680. float ActivePilotListItem::flashTime()
  681. {
  682. float flashTime = 1.5f * (float)pilot->promotePilot();
  683. flashTime += medalCount ? 2.0f : 0.f;
  684. flashTime += .5 * medalCount;
  685. flashTime += 1.5 + .5 * pilot->killedIcons.Count();
  686. return flashTime;
  687. }
  688. ActivePilotListItem::~ActivePilotListItem()
  689. {
  690. delete pilotIcon;
  691. pilotIcon = NULL;
  692. for ( int i = 0; i < MAX_MEDAL; i++ )
  693. {
  694. if ( medalIcons[i] )
  695. {
  696. delete medalIcons[i];
  697. medalIcons[i] = 0;
  698. }
  699. if ( medalTexts[i] )
  700. {
  701. delete medalTexts[i];
  702. medalTexts[i] = NULL;
  703. }
  704. }
  705. s_itemCount --;
  706. if ( s_itemCount < 1 )
  707. {
  708. if ( s_area )
  709. delete s_area;
  710. s_area =0;
  711. if ( s_missionText )
  712. delete s_missionText;
  713. s_missionText = 0;
  714. if ( s_killsText )
  715. delete s_killsText;
  716. s_killsText = 0;
  717. if ( s_rankText )
  718. delete s_rankText;
  719. s_rankText = 0;
  720. if ( s_nameText )
  721. delete s_nameText;
  722. s_nameText = 0;
  723. if ( s_iconRect )
  724. delete s_iconRect;
  725. s_iconRect = 0;
  726. if ( s_gunneryText )
  727. delete s_gunneryText;
  728. s_gunneryText = 0;
  729. if ( s_pilotingText )
  730. delete s_pilotingText;
  731. s_pilotingText = 0;
  732. if ( s_killIconRect )
  733. delete s_killIconRect;
  734. s_killIconRect = 0;
  735. for ( i = 0; i < 5; i++ )
  736. {
  737. if ( s_outline[i] )
  738. delete s_outline[i];
  739. s_outline[i] = 0;
  740. }
  741. for ( i = 0; i < 7; i++ )
  742. {
  743. if ( s_icons[i] )
  744. delete s_icons[i];
  745. s_icons[i]= 0;
  746. }
  747. for ( i = 0; i < MAX_MEDAL; i++ )
  748. {
  749. if ( s_medals[i] )
  750. delete s_medals[i];
  751. s_medals[i] = 0;
  752. }
  753. if ( s_promotionText )
  754. delete s_promotionText;
  755. s_promotionText = 0;
  756. if ( s_medalText )
  757. delete s_medalText;
  758. s_medalText = 0;
  759. if ( s_medalAwardedText )
  760. delete s_medalAwardedText;
  761. s_medalAwardedText = 0;
  762. if ( s_pilotPromotedAnim )
  763. delete s_pilotPromotedAnim;
  764. s_pilotPromotedAnim = 0;
  765. if ( s_medalAwardedAnim )
  766. delete s_medalAwardedAnim;
  767. s_medalAwardedAnim = 0;
  768. if ( s_skillAnim )
  769. delete s_skillAnim;
  770. s_skillAnim = 0;
  771. if ( s_pilotPromotionArea )
  772. delete s_pilotPromotionArea;
  773. s_pilotPromotionArea = NULL;
  774. }
  775. }
  776. void ActivePilotListItem::init( FitIniFile* file )
  777. {
  778. if ( s_area )
  779. return;
  780. s_area = new aRect;
  781. s_missionText = new aText;
  782. s_killsText = new aText;
  783. s_rankText = new aText;
  784. s_nameText = new aText;
  785. s_iconRect = new aRect;
  786. s_area = new aRect;
  787. s_rankText = new aText;
  788. s_gunneryText = new aText;
  789. s_pilotingText = new aText;
  790. s_killIconRect = new aRect;
  791. s_pilotPromotionArea = new PilotPromotionArea;
  792. for ( int i = 0; i < MAX_MEDAL; i++ )
  793. s_medals[i] = new aObject;
  794. s_promotionText = new aText;
  795. s_medalText = new aText;
  796. s_medalAwardedText = new aText;
  797. s_pilotPromotedAnim = new aAnimation;
  798. s_skillAnim = new aAnimation;
  799. s_medalAwardedAnim = new aAnimation;
  800. s_nameText->init( file, "ActivePilotNameText" );
  801. s_missionText->init( file, "ActiveMissionsText" );
  802. s_rankText->init( file, "ActiveRankText" );
  803. s_gunneryText->init( file, "ActiveGunneryText" );
  804. s_pilotingText->init( file, "ActivePilotingText" );
  805. s_killsText->init( file, "ActiveKillsNameText" );
  806. s_pilotPromotionArea->init( *file );
  807. s_promotionText->init( file, "PromotionHeader" );
  808. s_medalText->init( file, "MedalDescriptionText" );
  809. s_medalAwardedText->init( file, "MedalAwardedHeader" );
  810. char name[64];
  811. // last three are missing, remove this
  812. for ( i = 0; i < MAX_MEDAL; i++ )
  813. {
  814. sprintf( name, "MedalIcon%ld", i );
  815. s_medals[i]->init( file, name );
  816. }
  817. char buffer[256];
  818. for ( i = 0; i < 5; i++ )
  819. {
  820. s_outline[i] = new aRect;
  821. sprintf( buffer, "ActiveDutyBoxRect%ld", i );
  822. s_outline[i]->init( file, buffer );
  823. }
  824. for ( i = 0; i < 2; i++ )
  825. {
  826. s_icons[i] = new aObject;
  827. sprintf( buffer, "ActiveDutyBoxSkill%ld", i );
  828. s_icons[i]->init( file, buffer );
  829. sprintf( buffer, "ActiveDutyBoxSkillMeter%ld", i );
  830. s_attributeMeters[i] = new AttributeMeter();
  831. s_attributeMeters[i]->init( file, buffer );
  832. s_attributeMeters[i]->setAddedColorMax( 0xffffffff );
  833. s_attributeMeters[i]->setAddedColorMin( 0xffffffff );
  834. }
  835. for ( i = 0; i < 5; i++ )
  836. {
  837. s_icons[i+3] = new aObject;
  838. sprintf( buffer, "ActiveDutyBoxRankIcon%ld", i );
  839. s_icons[i+3]->init( file, buffer );
  840. }
  841. s_area->init( file, "ActiveDutyBox" );
  842. s_iconRect->init( file, "ActiveDutyBoxPilotIconRect" );
  843. s_killIconRect->init( file, "KillIcons" );
  844. s_skillAnim->initWithBlockName( file, "SkillMeterAnimation" );
  845. s_pilotPromotedAnim->initWithBlockName( file, "PilotPromotedHeaderAnimation" );
  846. s_medalAwardedAnim->initWithBlockName( file, "MedalAwardedAnimation" );
  847. }
  848. bool ActivePilotListItem::isDone()
  849. {
  850. return bDone;
  851. }
  852. ActivePilotListItem::ActivePilotListItem( LogisticsPilot* pPilot )
  853. {
  854. char tmpText[256];
  855. char realText[256];
  856. memset( medalIcons, 0, MAX_MEDAL * sizeof (aObject*) );
  857. memset( medalTexts, 0, MAX_MEDAL * sizeof(aText*) );
  858. promotionShown = 0;
  859. showingPromotion = 0;
  860. currentTime = 0;
  861. const bool* pMedals = pPilot->getNewMedalArray();
  862. medalCount = 0;
  863. int offset = 0;
  864. int killCount = pPilot->killedIcons.Count();
  865. if ( killCount > 32 )
  866. offset = (killCount - 32)/8 + 1;
  867. offset *= s_killIconRect->height();
  868. for( int i = 0; i < MAX_MEDAL; i++ )
  869. {
  870. if ( pMedals[i] )
  871. {
  872. medalIcons[medalCount] = new aObject;
  873. medalTexts[medalCount] = new aText;
  874. *medalIcons[medalCount] = *s_medals[i];
  875. *medalTexts[medalCount] = *s_medalText;
  876. medalIcons[medalCount]->move( 0, medalCount* medalIcons[medalCount]->height() + offset );
  877. medalTexts[medalCount]->move( 0, medalCount* medalIcons[medalCount]->height() + offset );
  878. medalTexts[medalCount]->setText( IDS_MEDAL + i );
  879. medalCount++;
  880. }
  881. }
  882. pilot = pPilot;
  883. showingPromotion = 0;
  884. int top = s_area->top();
  885. killsText = *s_killsText;
  886. nameText = *s_nameText;
  887. rankText = *s_rankText;
  888. missionText = *s_missionText;
  889. pilotingText = *s_pilotingText;
  890. gunneryText = *s_gunneryText;
  891. promotionText = *s_promotionText;
  892. medalAwardedText = *s_medalAwardedText;
  893. if ( medalCount )
  894. promotionText.moveTo( promotionText.left(), medalIcons[medalCount-1]->bottom() + 15 );
  895. if ( medalCount > 1 )
  896. medalAwardedText.setText( IDS_ONE_MEDAL_AWARD2 );
  897. else
  898. medalAwardedText.setText( IDS_ONE_MEDAL_AWARD );
  899. //Gotta promote the pilot before we decide what rank he/she is!
  900. bool pilotPromoted = pilot->promotePilot();
  901. char text[256];
  902. cLoadString( IDS_PILOT_PROMOTED, text, 255 );
  903. char finalText[256];
  904. char tmpRank[64];
  905. //ACE not contiguous with other ranks. Added too late!
  906. if (pilot->getRank() != 4)
  907. cLoadString( IDS_GREEN + pilot->getRank(), tmpRank, 63 );
  908. else
  909. cLoadString( IDS_ACE, tmpRank, 63 );
  910. CharUpper( tmpRank );
  911. sprintf( finalText, text, tmpRank );
  912. promotionText.setText( finalText );
  913. long bottom = promotionText.top() + promotionText.font.height() + 34;
  914. if ( !pilotPromoted )
  915. {
  916. if ( medalCount )
  917. bottom = medalIcons[medalCount-1]->bottom() + 34;
  918. else
  919. bottom = promotionText.top() + 34;
  920. }
  921. aObject::init( 30, top, s_area->width(), bottom );
  922. int missions = pPilot->getNumberMissions();
  923. cLoadString( IDS_PILOT_MISSIONS, tmpText, 255 );
  924. sprintf( realText, tmpText, missions );
  925. missionText.setText( realText);
  926. cLoadString( IDS_KILLS_NO_COUNT, tmpText, 255 );
  927. killsText.setText( tmpText);
  928. const char* name = pPilot->getName();
  929. cLoadString( IDS_PILOT_NAME, tmpText, 255 );
  930. sprintf( realText, tmpText, name );
  931. nameText.setText( realText);
  932. long rank = pPilot->getRank();
  933. char rankStr[32];
  934. //ACE not Contiguous with other Ranks. Added too late.
  935. if (rank != 4)
  936. cLoadString( rank + IDS_GREEN, rankStr, 31 );
  937. else
  938. cLoadString( IDS_ACE, rankStr, 31 );
  939. rankText.setText( rankStr);
  940. char buffer[32];
  941. sprintf( buffer, "%ld", (long)pPilot->getGunnery() );
  942. gunneryText.setText( buffer );
  943. sprintf( buffer, "%ld", (long)pPilot->getPiloting() );
  944. pilotingText.setText( buffer );
  945. for ( i = 0; i < 2; i++ )
  946. {
  947. icons[i] = *s_icons[i];
  948. addChild( &icons[i] );
  949. attributeMeters[i] = *s_attributeMeters[i];
  950. }
  951. attributeMeters[0].setValue( pPilot->getGunnery()/100.f - pPilot->getNewGunnery()/100.f );
  952. attributeMeters[1].setValue( pPilot->getPiloting()/100.f - pPilot->getNewPiloting()/100.f);
  953. attributeMeters[0].setAddedValue( pPilot->getNewGunnery()/100.f );
  954. attributeMeters[1].setAddedValue( pPilot->getNewPiloting()/100.f );
  955. icons[3] = *s_icons[3 + pPilot->getRank()];
  956. addChild( &icons[3] );
  957. addChild( &killsText );
  958. addChild( &nameText );
  959. addChild( &rankText );
  960. addChild( &missionText );
  961. addChild( &gunneryText );
  962. addChild( &pilotingText );
  963. if ( medalCount )
  964. {
  965. addChild( &medalAwardedText );
  966. for ( int i = 0; i < medalCount; i++ )
  967. {
  968. addChild( medalIcons[i] );
  969. addChild( medalTexts[i] );
  970. }
  971. }
  972. if ( pPilot->promotePilot() )
  973. {
  974. addChild( &promotionText );
  975. }
  976. pilotIcon = new PilotIcon( );
  977. pilotIcon->setTextureIndex( pPilot->getPhotoIndex() );
  978. s_itemCount++;
  979. showWindow = 0;
  980. }
  981. void PilotListItem::begin()
  982. {
  983. currentTime = 0.f;
  984. }
  985. void PilotListItem::update()
  986. {
  987. currentTime += frameLength;
  988. }
  989. void PilotPromotionArea::init( FitIniFile& file )
  990. {
  991. areaLeft.init( file, "PromoteGadgetLeftStatic", "PromoteGadgetLeftText",
  992. "PromoteGadgetLeftRect", NULL );
  993. areaRight.init( file, "PromoteGadgetRightStatic", "PromoteGadgetRightText",
  994. "PromoteGadgetRightRect", "PromoteGadgetRightButton" );
  995. file.seekBlock( "PromoteGadgetLeftEnterAnimation" );
  996. leftInfo.init( &file, "" );
  997. file.seekBlock( "PromoteGadgetRightEnterAnimation" );
  998. rightInfo.init( &file, "" );
  999. file.seekBlock( "PromoteGadgetLeftExitAnimation");
  1000. leftExitInfo.init( &file, "" );
  1001. file.seekBlock( "PromoteGadgetRightExitAnimation" );
  1002. rightExitInfo.init( &file, "" );
  1003. SpecialtyListItem::init( &file );
  1004. char buffer[32];
  1005. for ( int i = 0; i < 2; i++ )
  1006. {
  1007. sprintf( buffer, "PromoteGadgetLeftSkillMeter%ld", i );
  1008. attributeMeters[i].init( &file, buffer );
  1009. attributeMeters[i].setAddedColorMax( 0xffffffff );
  1010. attributeMeters[i].setAddedColorMin( 0xffffffff );
  1011. }
  1012. file.seekBlock( "SkillSelectionAnimation" );
  1013. selSkillAnim.init(&file, "" );
  1014. pilot = NULL;
  1015. }
  1016. void PilotPromotionArea::render()
  1017. {
  1018. int xOffset = leftInfo.getXDelta();
  1019. int yOffset = leftInfo.getYDelta();
  1020. if ( bDone )
  1021. {
  1022. xOffset = leftExitInfo.getXDelta();
  1023. yOffset = leftExitInfo.getYDelta();
  1024. }
  1025. areaLeft.render(xOffset, yOffset );
  1026. pilotIcon->render( areaLeft.rects[3].left() + xOffset + 1, areaLeft.rects[3].top() + yOffset + 1,
  1027. areaLeft.rects[3].right() + xOffset - 1, areaLeft.rects[3].bottom() + yOffset - 1);
  1028. for ( int i = 0; i < 2; i++ )
  1029. attributeMeters[i].render( xOffset, yOffset );
  1030. xOffset = rightInfo.getXDelta();
  1031. yOffset = rightInfo.getYDelta();
  1032. if ( bDone )
  1033. {
  1034. xOffset = rightExitInfo.getXDelta();
  1035. yOffset = rightExitInfo.getYDelta();
  1036. }
  1037. skillListBox.move( xOffset, yOffset );
  1038. skillListBox.setColor( 0xff000000, 0 );
  1039. skillListBox.render();
  1040. skillListBox.move( -xOffset, -yOffset );
  1041. areaRight.render(xOffset, yOffset);
  1042. }
  1043. void PilotPromotionArea::update()
  1044. {
  1045. leftInfo.update();
  1046. rightInfo.update();
  1047. rightExitInfo.update();
  1048. leftExitInfo.update();
  1049. areaLeft.update();
  1050. areaRight.update();
  1051. for ( int i = 0; i < areaRight.buttonCount; i++ )
  1052. {
  1053. if ( areaRight.buttons[i].isPressed() )
  1054. {
  1055. handleMessage( aMSG_DONE, aMSG_DONE );
  1056. areaRight.buttons[i].press( 0 );
  1057. }
  1058. }
  1059. if ( !bDone )
  1060. skillListBox.update();
  1061. int index = skillListBox.GetCheckedItem();
  1062. if ( index != -1 && (index != lastCheck || bDone ) )
  1063. {
  1064. aListItem* pItem = skillListBox.GetItem( index);
  1065. SpecialtyListItem* pTmp = dynamic_cast<SpecialtyListItem*>(pItem );
  1066. if ( pTmp )
  1067. {
  1068. int skillID = pTmp->getID();
  1069. if ( bDone )
  1070. {
  1071. pilot->setSpecialtySkill( skillID, 1 );
  1072. pTmp->setCheck(0);
  1073. }
  1074. int specSkills = pilot->getSpecialtySkillCount();
  1075. if ( !bDone )
  1076. {
  1077. if ( 8 + specSkills < areaLeft.textCount )
  1078. areaLeft.textObjects[8+specSkills].setText(IDS_SPECIALTY + skillID);
  1079. selSkillAnim.begin();
  1080. }
  1081. }
  1082. lastCheck = index;
  1083. areaRight.buttons[0].disable( false );
  1084. }
  1085. else if ( index == -1 )
  1086. {
  1087. areaRight.buttons[0].disable( true );
  1088. }
  1089. selSkillAnim.update();
  1090. int specSkills = pilot->getSpecialtySkillCount();
  1091. if ( 8 + specSkills < areaLeft.textCount )
  1092. areaLeft.textObjects[8+specSkills].setColor( selSkillAnim.getColor() );
  1093. }
  1094. void PilotPromotionArea::setPilot( LogisticsPilot* pPilot, PilotIcon* pIcon )
  1095. {
  1096. PilotReviewScreen::instance->beginFadeOut( 1.0f );
  1097. lastCheck = -1;
  1098. if ( !areaLeft.staticCount ) // haven't been initialized
  1099. return;
  1100. pilot = pPilot;
  1101. bDone = 0;
  1102. char tmpText[255];
  1103. char realText[255];
  1104. int missions = pPilot->getNumberMissions();
  1105. cLoadString( IDS_PILOT_MISSIONS, tmpText, 255 );
  1106. sprintf( realText, tmpText, missions );
  1107. areaLeft.textObjects[2].setText( realText );
  1108. const char* name = pPilot->getName();
  1109. cLoadString( IDS_PILOT_NAME, tmpText, 255 );
  1110. sprintf( realText, tmpText, name );
  1111. areaLeft.textObjects[1].setText( realText );
  1112. long rank = pPilot->getRank();
  1113. for ( int i = 12; i < 17; i++ )
  1114. {
  1115. if ( i - 12 == rank )
  1116. areaLeft.statics[i].showGUIWindow( true );
  1117. else
  1118. areaLeft.statics[i].showGUIWindow( false );
  1119. }
  1120. char rankStr[32];
  1121. //ACE not Contiguous with other Ranks. Added too late.
  1122. if (rank != 4)
  1123. cLoadString( rank + IDS_GREEN, rankStr, 31 );
  1124. else
  1125. cLoadString( IDS_ACE, rankStr, 31 );
  1126. areaLeft.textObjects[3].setText( rankStr );
  1127. char buffer[32];
  1128. sprintf( buffer, "%ld", (long)pPilot->getGunnery() );
  1129. areaLeft.textObjects[4].setText( buffer );
  1130. sprintf( buffer, "%ld", (long)pPilot->getPiloting() );
  1131. areaLeft.textObjects[5].setText( buffer );
  1132. int specSkills = pPilot->getSpecialtySkillCount();
  1133. if ( specSkills )
  1134. {
  1135. const char* tmp[NUM_SPECIALTY_SKILLS];
  1136. specSkills = 10;
  1137. pPilot->getSpecialtySkills( tmp, specSkills );
  1138. for ( int i = 0; i < specSkills; i++ )
  1139. {
  1140. if ( 8 + i < 12 )
  1141. areaLeft.textObjects[8+i].setText(tmp[i]);
  1142. }
  1143. }
  1144. for ( int j = specSkills; j < 4; j++ )
  1145. {
  1146. if ( 8 + j < 12 )
  1147. areaLeft.textObjects[8+j].setText( "" );
  1148. }
  1149. int skillArray[NUM_SPECIALTY_SKILLS];
  1150. specSkills = NUM_SPECIALTY_SKILLS;
  1151. pPilot->getSpecialtySkills( skillArray, specSkills );
  1152. attributeMeters[0].setValue( pPilot->getGunnery()/100.f - pPilot->getNewGunnery()/100.f );
  1153. attributeMeters[1].setValue( pPilot->getPiloting()/100.f - pPilot->getNewPiloting()/100.f);
  1154. attributeMeters[0].setAddedValue( pPilot->getNewGunnery()/100.f );
  1155. attributeMeters[1].setAddedValue( pPilot->getNewPiloting()/100.f );
  1156. pilot = pPilot;
  1157. leftInfo.begin();
  1158. rightInfo.begin();
  1159. bDone = 0;
  1160. skillListBox.init( areaRight.rects[2].left(), areaRight.rects[2].top(),
  1161. areaRight.rects[2].width(), areaRight.rects[2].height() );
  1162. skillListBox.setSpaceBetweenItems( 5 );
  1163. skillListBox.setScrollPos( 0 );
  1164. skillListBox.removeAllItems( true );
  1165. int maxSkill = 0;
  1166. if ( rank > WARRIOR_RANK_ELITE )
  1167. {
  1168. maxSkill = NUM_SPECIALTY_SKILLS;
  1169. soundSystem->playBettySample( BETTY_PROMOACE );
  1170. }
  1171. else if ( rank > WARRIOR_RANK_VETERAN )
  1172. {
  1173. maxSkill = FIRST_ACE_SPECIALTY;
  1174. soundSystem->playBettySample( BETTY_PROMOELI );
  1175. }
  1176. else if ( rank > WARRIOR_RANK_REGULAR )
  1177. {
  1178. maxSkill = FIRST_ELITE_SPECIALTY;
  1179. soundSystem->playBettySample( BETTY_PROMOVET );
  1180. }
  1181. else
  1182. {
  1183. maxSkill = FIRST_VETERAN_SPECIALTY;
  1184. soundSystem->playBettySample( BETTY_PROMOREG );
  1185. }
  1186. for ( i = 0; i < maxSkill; i++ )
  1187. {
  1188. SpecialtyListItem* pItem = new SpecialtyListItem( i );
  1189. aTextListItem* tmpItem = NULL;
  1190. if ( i == FIRST_REGULAR_SPECIALTY )
  1191. {
  1192. tmpItem = new aTextListItem( IDS_PROMOTION_LISTBOX_FONT );
  1193. tmpItem->setText( IDS_REGULAR_SKILLS );
  1194. tmpItem->setColor( 0xffffffff );
  1195. }
  1196. else if ( i == FIRST_VETERAN_SPECIALTY )
  1197. {
  1198. tmpItem = new aTextListItem( IDS_PROMOTION_LISTBOX_FONT );
  1199. tmpItem->setText( IDS_VETERAN_SKILLS );
  1200. tmpItem->setColor( 0xffffffff );
  1201. }
  1202. else if ( i == FIRST_ELITE_SPECIALTY )
  1203. {
  1204. tmpItem = new aTextListItem( IDS_PROMOTION_LISTBOX_FONT );
  1205. tmpItem->setText( IDS_ELITE_SKILLS3 );
  1206. tmpItem->setColor( 0xffffffff );
  1207. }
  1208. else if ( i == FIRST_ACE_SPECIALTY )
  1209. {
  1210. tmpItem = new aTextListItem( IDS_PROMOTION_LISTBOX_FONT );
  1211. tmpItem->setText( IDS_ACE_SKILLS );
  1212. tmpItem->setColor( 0xffffffff );
  1213. }
  1214. if ( tmpItem )
  1215. {
  1216. tmpItem->resize( tmpItem->width(), pItem->height()/2 );
  1217. skillListBox.AddItem( tmpItem );
  1218. }
  1219. bool bAdd = 1;
  1220. for ( int j = 0; j < specSkills; j++ )
  1221. {
  1222. if ( skillArray[j] == i )
  1223. {
  1224. delete pItem;
  1225. bAdd = 0;
  1226. break;
  1227. }
  1228. }
  1229. if ( bAdd )
  1230. skillListBox.AddItem( pItem );
  1231. }
  1232. pilotIcon = pIcon;
  1233. }
  1234. int PilotPromotionArea::handleMessage( unsigned long msg, unsigned long who )
  1235. {
  1236. if ( who == aMSG_DONE )
  1237. {
  1238. rightExitInfo.begin();
  1239. leftExitInfo.begin();
  1240. bDone = true;
  1241. PilotReviewScreen::instance->beginFadeIn( 1.0f );
  1242. }
  1243. return 0;
  1244. }
  1245. bool PilotPromotionArea::isDone()
  1246. {
  1247. if ( bDone && rightExitInfo.isDone() && leftExitInfo.isDone() )
  1248. return true;
  1249. return false;
  1250. }
  1251. PilotPromotionArea::~PilotPromotionArea()
  1252. {
  1253. SpecialtyListItem::deleteStatics();
  1254. }
  1255. void SpecialtyListItem::render()
  1256. {
  1257. aObject::render();
  1258. }
  1259. void SpecialtyListItem::update()
  1260. {
  1261. normalAnim.update();
  1262. unsigned long color = normalAnim.getColor();
  1263. if ( PilotReviewScreen::s_curPromotion )
  1264. {
  1265. aListBox* skillListBox = PilotReviewScreen::s_curPromotion->getSkillListBox();
  1266. if ( skillListBox && skillListBox->pointInside(userInput->getMouseX(), userInput->getMouseY() ) )
  1267. aObject::update();
  1268. if ( userInput->isLeftClick() && pointInside( userInput->getMouseX(), userInput->getMouseY() )
  1269. && ( skillListBox && skillListBox->pointInside(userInput->getMouseX(), userInput->getMouseY() ) ) )
  1270. {
  1271. state = SELECTED;
  1272. if ( !radioButton.isPressed() )
  1273. radioButton.press( true );
  1274. pressedAnim.begin();
  1275. }
  1276. }
  1277. // set the texts and colors appropriately
  1278. if ( state == SELECTED )
  1279. {
  1280. if ( !radioButton.isPressed() )
  1281. radioButton.press( true );
  1282. if ( !pressedAnim.isAnimating() )
  1283. pressedAnim.begin();
  1284. pressedAnim.update();
  1285. color = pressedAnim.getColor();
  1286. }
  1287. else if ( state == HIGHLITE )
  1288. {
  1289. if ( !highlightAnim.isAnimating() )
  1290. highlightAnim.begin();
  1291. highlightAnim.update();
  1292. color = highlightAnim.getColor();
  1293. }
  1294. setColor( color, true );
  1295. // make sure the background stays black
  1296. setColor( 0xff000000, 0 );
  1297. }
  1298. void SpecialtyListItem::deleteStatics()
  1299. {
  1300. if ( s_itemCount < 1 )
  1301. {
  1302. if ( s_radioButton )
  1303. delete s_radioButton;
  1304. s_radioButton = 0;
  1305. if ( s_highlightAnim )
  1306. delete s_highlightAnim;
  1307. s_highlightAnim = 0;
  1308. if ( s_normalAnim )
  1309. delete s_normalAnim;
  1310. s_normalAnim = 0;
  1311. if ( s_pressedAnim )
  1312. delete s_pressedAnim;
  1313. s_pressedAnim = 0;
  1314. if ( s_description )
  1315. delete s_description;
  1316. s_description = 0;
  1317. if ( s_area )
  1318. delete s_area;
  1319. s_area = 0;
  1320. if ( s_outline )
  1321. delete s_outline;
  1322. s_outline = 0;
  1323. for ( int i = 0; i < 4; i++ )
  1324. {
  1325. if ( s_skillIcons[i] )
  1326. delete s_skillIcons[i];
  1327. s_skillIcons[i] = 0;
  1328. }
  1329. }
  1330. }
  1331. SpecialtyListItem::~SpecialtyListItem()
  1332. {
  1333. s_itemCount--;
  1334. }
  1335. void SpecialtyListItem::init( FitIniFile* file )
  1336. {
  1337. s_radioButton = new aButton;
  1338. s_highlightAnim = new aAnimation;
  1339. s_normalAnim = new aAnimation;
  1340. s_pressedAnim = new aAnimation;
  1341. s_description = new aText;
  1342. s_area = new aRect;
  1343. s_outline = new aRect;
  1344. s_radioButton->init( *file, "PromoteGadgetRightRadioButton" );
  1345. char buffer[64];
  1346. for ( int i =0; i < 4; i++ )
  1347. {
  1348. s_skillIcons[i] = new aObject;
  1349. sprintf( buffer, "SkillTypeIcon%ld", i );
  1350. s_skillIcons[i]->init( file, buffer );
  1351. }
  1352. s_description->init( file, "SkillDescriptionText" );
  1353. file->seekBlock( "PromoteGadgetRightSkillEntryBox" );
  1354. s_highlightAnim->init( file, "Highlight" );
  1355. s_normalAnim->init( file, "Normal" );
  1356. s_pressedAnim->init( file, "Pressed" );
  1357. s_outline->init( file, "PromoteGadgetRightSkillEntryOutline" );
  1358. s_area->init( file, "PromoteGadgetRightSkillEntryBox" );
  1359. }
  1360. int SpecialtyListItem::handleMessage( unsigned long message, unsigned long who )
  1361. {
  1362. return 0;
  1363. }
  1364. bool SpecialtyListItem::isChecked()
  1365. {
  1366. return radioButton.isPressed();
  1367. }
  1368. int SpecialtyListItem::getID()
  1369. {
  1370. return ID;
  1371. }
  1372. SpecialtyListItem::SpecialtyListItem( int newID )
  1373. {
  1374. s_itemCount++;
  1375. ID = newID;
  1376. aObject::init( s_area->left(), s_area->top(), s_area->right(), s_area->bottom() );
  1377. normalAnim = *s_normalAnim;
  1378. pressedAnim = *s_pressedAnim;
  1379. highlightAnim = *s_highlightAnim;
  1380. description = *s_description;
  1381. int iconType = MechWarrior::skillTypes[newID];
  1382. icon = *s_skillIcons[iconType];
  1383. radioButton = *s_radioButton;
  1384. outline = *s_outline;
  1385. outline.bOutline = true;
  1386. addChild( &description );
  1387. addChild( &icon );
  1388. addChild( &radioButton );
  1389. addChild( &outline );
  1390. description.setText( IDS_PROMOTION_SKILL + newID );
  1391. normalAnim.begin();
  1392. }
  1393. void SpecialtyListItem::setCheck( bool press )
  1394. {
  1395. radioButton.press( press );
  1396. state = press ? SELECTED : ENABLED;
  1397. }