Mechlopedia.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  1. #define MECHLOPEDIA_CPP
  2. /*************************************************************************************************\
  3. Mechlopedia.cpp : Implementation of the Mechlopedia component.
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. \*************************************************************************************************/
  8. #include "Mechlopedia.h"
  9. #include "iniFile.h"
  10. #include "mclib.h"
  11. #include "LogisticsData.h"
  12. #include "..\resource.h"
  13. #include "prefs.h"
  14. #include "cmponent.h"
  15. #define ENCYCLO_MECHS 130
  16. #define ENCYCLO_BUILD 131
  17. #define ENCYCLO_VEHIC 132
  18. #define ENCYCLO_WEAPONS 133
  19. #define ENCYCLO_PILOTS 134
  20. #define ENCYCLO_HISTORY 135
  21. #define ENCYCLO_MM 136
  22. #define PERSONALITY_COUNT 11
  23. MechlopediaListItem* MechlopediaListItem::s_templateItem = NULL;
  24. Mechlopedia::Mechlopedia( )
  25. {
  26. helpTextArrayID = 1;
  27. for ( int i = 0; i < 6; i++ )
  28. {
  29. subScreens[i] = 0;
  30. }
  31. currentScreen = 0;
  32. }
  33. //-------------------------------------------------------------------------------------------------
  34. Mechlopedia::~Mechlopedia()
  35. {
  36. }
  37. int Mechlopedia::init()
  38. {
  39. FullPathFileName path;
  40. path.init( artPath, "mcl_en", ".fit" );
  41. FitIniFile file;
  42. if ( NO_ERR != file.open( path ) )
  43. {
  44. char errorStr[256];
  45. sprintf( errorStr, "couldn't open file %s", (char*)path );
  46. Assert( 0, 0, errorStr );
  47. return 0;
  48. }
  49. LogisticsScreen::init( file, "Static", "Text", "Rect", "Button" );
  50. buttons[buttonCount-1].setMessageOnRelease();
  51. listBox.init( rects[0].left(), rects[0].top(), rects[0].width(), rects[0].height() );
  52. listBox.setOrange(true);
  53. Mechlopedia::MechScreen* pMechScreen = new Mechlopedia::MechScreen;
  54. pMechScreen->setListBox( &listBox );
  55. pMechScreen->setVehicle( false );
  56. pMechScreen->init();
  57. subScreens[0] = pMechScreen;
  58. Mechlopedia::BuildingScreen* pBuildingScreen = new Mechlopedia::BuildingScreen;
  59. pBuildingScreen->setListBox( &listBox );
  60. pBuildingScreen->init();
  61. subScreens[1] = pBuildingScreen;
  62. Mechlopedia::WeaponScreen* pWeaponScreen = new Mechlopedia::WeaponScreen;
  63. pWeaponScreen->setListBox( &listBox );
  64. pWeaponScreen->init();
  65. subScreens[3] = pWeaponScreen;
  66. pMechScreen = new Mechlopedia::MechScreen;
  67. pMechScreen->setVehicle( true );
  68. pMechScreen->setListBox( &listBox );
  69. pMechScreen->init();
  70. subScreens[2] = pMechScreen;
  71. Mechlopedia::PersonalityScreen* pPersScreen = new Mechlopedia::PersonalityScreen;
  72. pPersScreen->setListBox( &listBox );
  73. pPersScreen->init();
  74. pPersScreen->setIsHistory( false );
  75. subScreens[4] = pPersScreen;
  76. Mechlopedia::PersonalityScreen* pHistroyScreen = new Mechlopedia::PersonalityScreen;
  77. pHistroyScreen->setListBox( &listBox );
  78. pHistroyScreen->init();
  79. pHistroyScreen->setIsHistory( true );
  80. subScreens[5] = pHistroyScreen;
  81. MechlopediaListItem::init();
  82. for ( int i = ENCYCLO_MECHS; i < ENCYCLO_MM; i++ )
  83. {
  84. getButton( i )->setPressFX( LOG_VIDEOBUTTONS );
  85. getButton( i )->setHighlightFX( LOG_DIGITALHIGHLIGHT );
  86. getButton( i )->setDisabledFX( -1 );
  87. }
  88. return true;
  89. }
  90. int Mechlopedia::handleMessage( unsigned long, unsigned long who)
  91. {
  92. // unpress all the others
  93. for ( int i = ENCYCLO_MECHS; i < ENCYCLO_MM; i++ )
  94. getButton( i )->press( 0 );
  95. if ( getButton( who ) )
  96. getButton( who )->press( true );
  97. if ( who < ENCYCLO_MM )
  98. {
  99. if ( subScreens[currentScreen] )
  100. subScreens[currentScreen]->end();
  101. currentScreen = who - ENCYCLO_MECHS;
  102. if ( subScreens[currentScreen] )
  103. subScreens[currentScreen]->begin();
  104. }
  105. else
  106. {
  107. for ( int i= 0;i < 6; i++ )
  108. {
  109. subScreens[i]->end();
  110. }
  111. beginFadeOut( .5f );
  112. status = NEXT;
  113. }
  114. return 1;
  115. }
  116. void Mechlopedia::update()
  117. {
  118. LogisticsScreen::update();
  119. if ( subScreens[currentScreen] )
  120. subScreens[currentScreen]->update();
  121. }
  122. void Mechlopedia::render()
  123. {
  124. GUI_RECT rect = { 0, 0, Environment.screenWidth, Environment.screenHeight };
  125. drawRect( rect, 0xff000000 );
  126. if ( subScreens[currentScreen] )
  127. subScreens[currentScreen]->render();
  128. LogisticsScreen::render();
  129. }
  130. //////////////////////////////////////////////////////////
  131. int Mechlopedia::SubScreen::init( FitIniFile& file )
  132. {
  133. LogisticsScreen::init( file, "Static", "Text", "Rect", "Button" );
  134. for ( int i = 0; i < buttonCount; i++ )
  135. buttons[i].setMessageOnRelease();
  136. descriptionListBox.init( rects[0].left(), rects[0].top(), rects[0].width(), rects[0].height() );
  137. descriptionListBox.move( 285, 58 );
  138. descriptionListBox.setDisabledFX( -1 );
  139. descriptionListBox.setHighlightFX( -1 );
  140. descriptionListBox.setPressFX( -1 );
  141. return 0;
  142. }
  143. void Mechlopedia::SubScreen::end( )
  144. {
  145. camera.setMech( NULL );
  146. }
  147. void Mechlopedia::SubScreen::update()
  148. {
  149. int mouseX = userInput->getMouseX();
  150. int mouseY = userInput->getMouseY();
  151. // check for new selection....
  152. groupListBox->update();
  153. if ( groupListBox->pointInside( mouseX, mouseY) && userInput->isLeftClick() )
  154. {
  155. int index = groupListBox->GetSelectedItem();
  156. if ( index != -1 )
  157. {
  158. // for ( int i = 0; i < groupListBox->GetItemCount(); i++ )
  159. // {
  160. // groupListBox->GetItem( i )->setColor( 0xff43311C );
  161. // }
  162. aTextListItem* pItem = (aTextListItem*)groupListBox->GetItem( index );
  163. // pItem->setColor( 0xff866234 );
  164. select( pItem );
  165. }
  166. }
  167. descriptionListBox.update();
  168. camera.update();
  169. }
  170. void Mechlopedia::begin()
  171. {
  172. beginFadeIn( 2.0f );
  173. status = RUNNING;
  174. if ( !currentScreen )
  175. {
  176. getButton( ENCYCLO_MECHS )->press( true );
  177. handleMessage( 0, ENCYCLO_MECHS );
  178. listBox.setScrollPos( 0 );
  179. }
  180. }
  181. //////////////////////////////////////////////////////////
  182. void Mechlopedia::MechScreen::init()
  183. {
  184. FullPathFileName path;
  185. path.init( artPath, "mcl_en_mechs", ".fit" );
  186. FitIniFile file;
  187. if ( NO_ERR != file.open( path ) )
  188. {
  189. char errorStr[256];
  190. sprintf( errorStr, "couldn't open file %s", (char*)path );
  191. Assert( 0, 0, errorStr );
  192. return;
  193. }
  194. SubScreen::init( file );
  195. compListBox.init( rects[2].left(), rects[2].top(), rects[2].width(), rects[2].height() );
  196. compListBox.move( 285, 58 );
  197. statsListBox.init( rects[1].left(), rects[1].top(), rects[1].width(), rects[1].height() );
  198. statsListBox.move( 285, 58 );
  199. statsListBox.setDisabledFX( -1 );
  200. statsListBox.setHighlightFX( -1 );
  201. statsListBox.setPressFX( -1 );
  202. camera.init( statics[4].left() + 285, statics[4].top() + 58, statics[4].right() + 285, statics[4].bottom() + 58 );
  203. statics[4].setColor( 0 );
  204. textObjects[0].setText( "" );
  205. }
  206. void Mechlopedia::MechScreen::begin()
  207. {
  208. // need to fill that list box
  209. if ( bIsVehicle )
  210. {
  211. textObjects[1].setText( IDS_VEHICLE_STATS );
  212. int count = 256;
  213. const LogisticsVehicle* pVehicles[256];
  214. LogisticsData::instance->getVehicles( pVehicles, count );
  215. const LogisticsVariant* pCopters[256];
  216. int copterCount = 256;
  217. LogisticsData::instance->getHelicopters( pCopters, copterCount );
  218. for ( int i = 1; i < count; ++i )
  219. {
  220. const LogisticsVehicle* cur = pVehicles[i];
  221. for ( int j = 0; j < i; ++j )
  222. {
  223. if ( cur->getNameID() == pVehicles[j]->getNameID() && j != i )
  224. {
  225. pVehicles[i] = pVehicles[j];
  226. pVehicles[j] = cur;
  227. break;
  228. }
  229. }
  230. }
  231. groupListBox->removeAllItems( true );
  232. for ( i = 0; i < count; i++ )
  233. {
  234. MechlopediaListItem* pEntry = new MechlopediaListItem();
  235. char name[256];
  236. cLoadString( pVehicles[i]->getNameID(), name, 255 );
  237. EString text = name;
  238. text.MakeUpper();
  239. pEntry->setText( text );
  240. pEntry->resize( groupListBox->width() - groupListBox->getScrollBarWidth() - 18, pEntry->height() );
  241. bool bFound = 0;
  242. for ( int j = 0; j < groupListBox->GetItemCount(); j++ )
  243. {
  244. aTextListItem* pItem = (aTextListItem*)groupListBox->GetItem( j );
  245. if ( stricmp( name, pItem->getText() ) < 0 )
  246. {
  247. groupListBox->InsertItem( pEntry, j );
  248. bFound = true;
  249. break;
  250. }
  251. }
  252. if ( !bFound )
  253. groupListBox->AddItem( pEntry );
  254. }
  255. for ( i = 0; i < copterCount; i++ )
  256. {
  257. MechlopediaListItem* pEntry = new MechlopediaListItem();
  258. EString text = pCopters[i]->getName();
  259. text.MakeUpper();
  260. pEntry->setText( text );
  261. pEntry->resize( groupListBox->width() - groupListBox->getScrollBarWidth() - 18,
  262. pEntry->height() );
  263. bool bFound = 0;
  264. for ( int j = 0; j < groupListBox->GetItemCount(); j++ )
  265. {
  266. aTextListItem* pItem = (aTextListItem*)groupListBox->GetItem( j );
  267. if ( stricmp( pCopters[i]->getName(), pItem->getText() ) < 0 )
  268. {
  269. groupListBox->InsertItem( pEntry, j );
  270. bFound = true;
  271. break;
  272. }
  273. }
  274. if ( !bFound )
  275. groupListBox->AddItem( pEntry );
  276. }
  277. }
  278. else
  279. {
  280. textObjects[1].setText( IDS_MECH_STATS );
  281. int count = 256;
  282. const LogisticsVariant* pChassis[256];
  283. LogisticsData::instance->getEncyclopediaMechs( pChassis, count );
  284. for ( int i = 1; i < count; ++i )
  285. {
  286. const LogisticsVariant* cur = pChassis[i];
  287. for ( int j = 0; j <= i; ++j )
  288. {
  289. if ( stricmp( cur->getName(), pChassis[j]->getName() ) < 0 )
  290. {
  291. for ( int l = i-1; l >= j; l-- )
  292. {
  293. pChassis[l+1] = pChassis[l];
  294. }
  295. pChassis[j] = cur;
  296. break;
  297. }
  298. }
  299. }
  300. groupListBox->removeAllItems( true );
  301. for ( i = 0; i < count; i++ )
  302. {
  303. MechlopediaListItem* pEntry = new MechlopediaListItem();
  304. pEntry->setText( pChassis[i]->getChassisName() );
  305. pEntry->resize( groupListBox->width() - groupListBox->getScrollBarWidth() - 18,
  306. pEntry->height() );
  307. groupListBox->AddItem( pEntry );
  308. }
  309. }
  310. aTextListItem* pEntry = (aTextListItem*)groupListBox->GetItem( 0 );
  311. if ( pEntry )
  312. {
  313. select( pEntry );
  314. groupListBox->SelectItem( 0 );
  315. pEntry->setColor( 0xff866234 );
  316. }
  317. groupListBox->setScrollPos( 0 );
  318. }
  319. void Mechlopedia::MechScreen::update()
  320. {
  321. SubScreen::update();
  322. compListBox.update();
  323. statsListBox.update();
  324. }
  325. void Mechlopedia::MechScreen::select( aTextListItem* pItem )
  326. {
  327. const char* pText = pItem->getText();
  328. if ( !bIsVehicle )
  329. {
  330. EString name = pText;
  331. name += " Prime";
  332. LogisticsVariant* pChassis = LogisticsData::instance->getVariant( name );
  333. setMech( pChassis, 1 );
  334. }
  335. else
  336. {
  337. LogisticsVehicle* pVehicle = LogisticsData::instance->getVehicle( pText );
  338. if ( pVehicle )
  339. setVehicle( pVehicle );
  340. else // copter
  341. {
  342. LogisticsVariant* pMech = LogisticsData::instance->getVariant( pText );
  343. if ( pMech )
  344. setMech( pMech, 0 );
  345. }
  346. }
  347. }
  348. void Mechlopedia::MechScreen::render()
  349. {
  350. groupListBox->render();
  351. descriptionListBox.render();
  352. camera.render();
  353. statsListBox.render();
  354. compListBox.render();
  355. LogisticsScreen::render(285, 58);
  356. }
  357. void Mechlopedia::MechScreen::setVehicle( LogisticsVehicle* pVehicle )
  358. {
  359. if ( !pVehicle )
  360. return;
  361. int descID = pVehicle->getEncyclopediaID();
  362. char text[256];
  363. cLoadString( pVehicle->getNameID(), text, 255 );
  364. EString tmpStr = text;
  365. tmpStr.MakeUpper();
  366. descriptionListBox.removeAllItems( true );
  367. aTextListItem* pItem = new aTextListItem( IDS_EN_LISTBOX_FONT );
  368. pItem->forceToTop( true );
  369. pItem->resize( descriptionListBox.width() - descriptionListBox.getScrollBarWidth() - 16, pItem->height() );
  370. pItem->setText( descID );
  371. pItem->sizeToText( );
  372. pItem->setColor( 0xff005392 );
  373. descriptionListBox.AddItem( pItem );
  374. compListBox.setVehicle( pVehicle );
  375. camera.setVehicle( pVehicle->getFileName(), prefs.baseColor, prefs.highlightColor, prefs.highlightColor );
  376. camera.setScale( pVehicle->getScale() );
  377. textObjects[0].setText( tmpStr );
  378. statsListBox.removeAllItems( true );
  379. char formatText[256];
  380. char tmp[256];
  381. long color = textObjects[0].getColor();
  382. // pItem = new aTextListItem( IDS_EN_LISTBOX_FONT );
  383. // add house stats NO HOUSE FOR VEHICLES
  384. // long houseID = pVehicle->getHouseID();
  385. // cLoadString( IDS_HOUSE0 + houseID, tmp, 255 );
  386. // cLoadString( IDS_EN_HOUSE, text, 255 );
  387. // sprintf( formatText, text, tmp );
  388. // pItem->setText( formatText );
  389. // pItem->setColor( color );
  390. // statsListBox.AddItem( pItem );
  391. pItem = new aTextListItem( IDS_EN_LISTBOX_FONT );
  392. // add weight stats
  393. cLoadString( IDS_EN_WEIGHT, text, 255 );
  394. sprintf( formatText, text, pVehicle->getMaxWeight() );
  395. pItem->setText( formatText );
  396. pItem->setColor( color );
  397. statsListBox.AddItem( pItem );
  398. // add weight class stats
  399. pItem = new aTextListItem( IDS_EN_LISTBOX_FONT );
  400. cLoadString( IDS_EN_CLASS, text, 255 );
  401. sprintf( formatText, text, (const char*)pVehicle->getMechClass() );
  402. pItem->setText( formatText );
  403. pItem->setColor( color );
  404. statsListBox.AddItem( pItem );
  405. // now armor
  406. pItem = new aTextListItem( IDS_EN_LISTBOX_FONT );
  407. cLoadString( IDS_EN_ARMOR, text, 255 );
  408. cLoadString( pVehicle->getArmorClass(), tmp, 255 );
  409. sprintf( formatText, text, tmp, pVehicle->getArmor() );
  410. pItem->setText( formatText );
  411. pItem->setColor( color );
  412. statsListBox.AddItem( pItem );
  413. // now speed
  414. pItem = new aTextListItem( IDS_EN_LISTBOX_FONT );
  415. cLoadString( IDS_EN_SPEED, text, 255 );
  416. sprintf( formatText, text, (long)pVehicle->getDisplaySpeed());
  417. pItem->setText( formatText );
  418. pItem->setColor( color );
  419. statsListBox.AddItem( pItem );
  420. }
  421. void Mechlopedia::MechScreen::setMech( LogisticsVariant* pChassis, bool bShowJump )
  422. {
  423. if ( !pChassis )
  424. return;
  425. int descID = pChassis->getEncyclopediaID();
  426. descriptionListBox.removeAllItems( true );
  427. aTextListItem* pItem = new aTextListItem( IDS_EN_LISTBOX_FONT );
  428. pItem->resize( descriptionListBox.width() - descriptionListBox.getScrollBarWidth()- 16, pItem->height() );
  429. pItem->setText( descID );
  430. pItem->sizeToText( );
  431. pItem->setColor( 0xff005392 );
  432. pItem->forceToTop( true );
  433. descriptionListBox.AddItem( pItem );
  434. compListBox.setMech( pChassis );
  435. camera.setMech( pChassis->getFileName(), prefs.baseColor, prefs.highlightColor, prefs.highlightColor );
  436. char name[256];
  437. cLoadString( pChassis->getChassisName(), name, 255 );
  438. EString upper = name;
  439. upper.MakeUpper();
  440. textObjects[0].setText( upper );
  441. statsListBox.removeAllItems( true );
  442. char text[256];
  443. char formatText[256];
  444. char tmp[256];
  445. pItem = new aTextListItem( IDS_EN_LISTBOX_FONT );
  446. long color = textObjects[0].getColor();
  447. // add house stats
  448. if ( !bIsVehicle )
  449. {
  450. long houseID = pChassis->getHouseID();
  451. cLoadString( IDS_HOUSE0 + houseID, tmp, 255 );
  452. cLoadString( IDS_EN_HOUSE, text, 255 );
  453. sprintf( formatText, text, tmp );
  454. pItem->setText( formatText );
  455. pItem->setColor( color );
  456. statsListBox.AddItem( pItem );
  457. }
  458. pItem = new aTextListItem( IDS_EN_LISTBOX_FONT );
  459. // add weight stats
  460. cLoadString( IDS_EN_WEIGHT, text, 255 );
  461. sprintf( formatText, text, pChassis->getMaxWeight() );
  462. pItem->setText( formatText );
  463. pItem->setColor( color );
  464. statsListBox.AddItem( pItem );
  465. // add weight class stats
  466. pItem = new aTextListItem( IDS_EN_LISTBOX_FONT );
  467. cLoadString( IDS_EN_CLASS, text, 255 );
  468. sprintf( formatText, text, (const char*)pChassis->getMechClass() );
  469. pItem->setText( formatText );
  470. pItem->setColor( color );
  471. statsListBox.AddItem( pItem );
  472. // now armor
  473. pItem = new aTextListItem( IDS_EN_LISTBOX_FONT );
  474. cLoadString( IDS_EN_ARMOR, text, 255 );
  475. cLoadString( pChassis->getArmorClass(), tmp, 255 );
  476. sprintf( formatText, text, tmp, pChassis->getArmor() );
  477. pItem->setText( formatText );
  478. pItem->setColor( color );
  479. statsListBox.AddItem( pItem );
  480. // now speed
  481. pItem = new aTextListItem( IDS_EN_LISTBOX_FONT );
  482. cLoadString( IDS_EN_SPEED, text, 255 );
  483. sprintf( formatText, text, (long)pChassis->getDisplaySpeed());
  484. pItem->setText( formatText );
  485. pItem->setColor( color );
  486. statsListBox.AddItem( pItem );
  487. // now jump range
  488. if ( bShowJump )
  489. {
  490. pItem = new aTextListItem( IDS_EN_LISTBOX_FONT );
  491. cLoadString( IDS_EN_JUMP, text, 255 );
  492. sprintf( formatText, text, (long)pChassis->getJumpRange() * 25 );
  493. pItem->setText( formatText );
  494. pItem->setColor( color );
  495. statsListBox.AddItem( pItem );
  496. }
  497. }
  498. //////////////////////////////////////////////////////////
  499. void Mechlopedia::WeaponScreen::init()
  500. {
  501. FullPathFileName path;
  502. path.init( artPath, "mcl_en_wep", ".fit" );
  503. FitIniFile file;
  504. if ( NO_ERR != file.open( path ) )
  505. {
  506. char errorStr[256];
  507. sprintf( errorStr, "couldn't open file %s", (char*)path );
  508. Assert( 0, 0, errorStr );
  509. }
  510. SubScreen::init( file );
  511. statsListBox.init( rects[2].left(), rects[2].top(), rects[2].right(), rects[2].bottom() );
  512. statsListBox.move( 285, 58 );
  513. camera.init( statics[4].left() + 285, statics[4].top() + 58, statics[4].right() + 285, statics[4].bottom() + 58 );
  514. statics[4].setColor( 0 );
  515. textObjects[0].setText( "" );
  516. }
  517. void Mechlopedia::WeaponScreen::update()
  518. {
  519. SubScreen::update();
  520. statsListBox.update();
  521. }
  522. void Mechlopedia::WeaponScreen::render()
  523. {
  524. descriptionListBox.render();
  525. statsListBox.render();
  526. groupListBox->render();
  527. LogisticsScreen::render( 285, 58 );
  528. camera.render();
  529. }
  530. void Mechlopedia::WeaponScreen::select( aTextListItem* pEntry )
  531. {
  532. LogisticsComponent* pComponent = LogisticsData::instance->getComponent( pEntry->getID() );
  533. setWeapon( pComponent );
  534. }
  535. int __cdecl sortWeapon( const void* pW1, const void* pW2 )
  536. {
  537. LogisticsComponent* p1 = *(LogisticsComponent**)pW1;
  538. LogisticsComponent* p2 = *(LogisticsComponent**)pW2;
  539. return stricmp( p1->getName(), p2->getName() );
  540. }
  541. void Mechlopedia::WeaponScreen::begin()
  542. {
  543. groupListBox->removeAllItems( true );
  544. LogisticsComponent* comps[256];
  545. int count = 256;
  546. LogisticsData::instance->getAllComponents( comps, count );
  547. qsort( comps, count, sizeof( LogisticsComponent* ), sortWeapon );
  548. for ( int i = 0; i < count; i++ )
  549. {
  550. MechlopediaListItem* pItem = new MechlopediaListItem();
  551. EString text = comps[i]->getName();
  552. text.MakeUpper();
  553. pItem->setText( text );
  554. pItem->setID( comps[i]->getID() );
  555. pItem->resize( groupListBox->width() - groupListBox->getScrollBarWidth() - 18, pItem->height() );
  556. groupListBox->AddItem( pItem );
  557. }
  558. aTextListItem* pEntry = (aTextListItem*)groupListBox->GetItem( 0 );
  559. if ( pEntry )
  560. {
  561. select( pEntry );
  562. groupListBox->SelectItem( 0 );
  563. pEntry->setColor( 0xff866234 );
  564. }
  565. groupListBox->setScrollPos( 0 );
  566. }
  567. void Mechlopedia::WeaponScreen::setWeapon ( LogisticsComponent* pComponent )
  568. {
  569. if ( !pComponent )
  570. return;
  571. statsListBox.removeAllItems( true );
  572. descriptionListBox.removeAllItems( true );
  573. //set header
  574. EString name = pComponent->getName();
  575. name.MakeUpper();
  576. textObjects[0].setText( name );
  577. // set description
  578. aTextListItem* pEntry = new aTextListItem( IDS_EN_WEAPON_FONT );
  579. pEntry->setColor( 0xff005392 );
  580. pEntry->setText( pComponent->getHelpID() );
  581. pEntry->resize( descriptionListBox.width() - descriptionListBox.getScrollBarWidth() - 16, pEntry->height() );
  582. pEntry->sizeToText();
  583. pEntry->forceToTop( true );
  584. descriptionListBox.AddItem( pEntry );
  585. char buffer[256];
  586. char final[256];
  587. char tmp[256];
  588. /*
  589. RATE OF FIRE
  590. HEAT
  591. AMMO (if the Ammo Tracking option is set to on in the Options Screen)
  592. COST*/
  593. // set stats
  594. /* pEntry = new aTextListItem( IDS_EN_WEAPON_FONT );
  595. cLoadString( IDS_EN_WEAPON_WEIGHT, buffer, 255 );
  596. sprintf( final, buffer, pComponent->getWeight() );
  597. pEntry->setText( final );
  598. pEntry->setColor( textObjects[0].getColor() );
  599. statsListBox.AddItem( pEntry );*/
  600. // RANGE
  601. if ( pComponent->isWeapon() )
  602. {
  603. pEntry = new aTextListItem( IDS_EN_WEAPON_FONT );
  604. cLoadString( IDS_EN_WEAPON_RANGE, buffer, 255 );
  605. cLoadString( IDS_HOTKEY1 + pComponent->getRangeType(), tmp, 255 );
  606. sprintf( final, buffer, tmp );
  607. pEntry->setText( final );
  608. pEntry->setColor( textObjects[0].getColor() );
  609. statsListBox.AddItem( pEntry );
  610. // DAMAGE
  611. pEntry = new aTextListItem( IDS_EN_WEAPON_FONT );
  612. cLoadString( IDS_EN_WEAPON_DAMAGE, buffer, 255 );
  613. sprintf( final, buffer, (long)pComponent->getDamage() );
  614. pEntry->setText( final );
  615. pEntry->setColor( textObjects[0].getColor() );
  616. statsListBox.AddItem( pEntry );
  617. }
  618. else if ( pComponent->getType() == COMPONENT_FORM_BULK )
  619. {
  620. pEntry = new aTextListItem( IDS_EN_WEAPON_FONT );
  621. cLoadString( IDS_EN_WEAPON_ARMOR, buffer, 255 );
  622. sprintf( final, buffer, 32 );
  623. pEntry->setText( final );
  624. pEntry->setColor( textObjects[0].getColor() );
  625. // pEntry->setHelpID( IDS_EN_WEAPON_ARMOR_HELP );
  626. statsListBox.AddItem( pEntry );
  627. }
  628. // RATE OF FIRE
  629. if ( pComponent->getRecycleTime() )
  630. {
  631. pEntry = new aTextListItem( IDS_EN_WEAPON_FONT );
  632. cLoadString( IDS_EN_WEAPON_RATEOFFIRE, buffer, 255 );
  633. sprintf( final, buffer, (10.f/pComponent->getRecycleTime()) );
  634. pEntry->setText( final );
  635. pEntry->setColor( textObjects[0].getColor() );
  636. statsListBox.AddItem( pEntry );
  637. }
  638. // heat
  639. pEntry = new aTextListItem( IDS_EN_WEAPON_FONT );
  640. cLoadString( IDS_EN_WEAPON_HEAT, buffer, 255 );
  641. sprintf( final, buffer, (long)pComponent->getHeat() );
  642. pEntry->setText( final );
  643. pEntry->setColor( textObjects[0].getColor() );
  644. statsListBox.AddItem( pEntry );
  645. // AMMO
  646. if ( !prefs.useUnlimitedAmmo && pComponent->getAmmo() )
  647. {
  648. pEntry = new aTextListItem( IDS_EN_WEAPON_FONT );
  649. cLoadString( IDS_EN_WEAPON_AMMO, buffer, 255 );
  650. sprintf( final, buffer, (long)pComponent->getAmmo() );
  651. pEntry->setText( final );
  652. pEntry->setColor( textObjects[0].getColor() );
  653. statsListBox.AddItem( pEntry );
  654. }
  655. // COST
  656. pEntry = new aTextListItem( IDS_EN_WEAPON_FONT );
  657. cLoadString( IDS_EN_WEAPON_COST, buffer, 255 );
  658. sprintf( final, buffer, (long)pComponent->getCost() );
  659. pEntry->setText( final );
  660. pEntry->setColor( textObjects[0].getColor() );
  661. statsListBox.AddItem( pEntry );
  662. FullPathFileName path;
  663. path.init( artPath, pComponent->getIconFileName(), ".tga" );
  664. int sizeX = pComponent->getComponentWidth();
  665. int sizeY = pComponent->getComponentHeight();
  666. float oldMidX = (rects[1].right() + rects[1].left())/2.f;
  667. float oldMidY = (rects[1].bottom() + rects[1].top())/2.f;
  668. statics[9].setTexture( path);
  669. statics[9].resize( sizeX * LogisticsComponent::XICON_FACTOR, sizeY * LogisticsComponent::YICON_FACTOR);
  670. statics[9].setUVs( 0.f, 0.f, sizeX * 48.f, sizeY * 32.f );
  671. statics[9].moveTo( oldMidX - .5 * statics[9].width(), oldMidY - .5 * statics[9].height() );
  672. camera.setComponent( pComponent->getPictureFileName() );
  673. camera.setScale( 1.5 );
  674. }
  675. //*************************************************************************************************
  676. void Mechlopedia::PersonalityScreen::init()
  677. {
  678. FullPathFileName path;
  679. path.init( artPath, "mcl_en_person", ".fit" );
  680. FitIniFile file;
  681. if ( NO_ERR != file.open( path ) )
  682. {
  683. char errorStr[256];
  684. sprintf( errorStr, "couldn't open file %s", (char*)path );
  685. Assert( 0, 0, errorStr );
  686. return;
  687. }
  688. SubScreen::init( file );
  689. }
  690. void Mechlopedia::PersonalityScreen::update()
  691. {
  692. groupListBox->update();
  693. SubScreen::update();
  694. }
  695. void Mechlopedia::PersonalityScreen::render()
  696. {
  697. descriptionListBox.render();
  698. groupListBox->render();
  699. LogisticsScreen::render(285, 58);
  700. }
  701. void Mechlopedia::PersonalityScreen::begin()
  702. {
  703. groupListBox->removeAllItems(true);
  704. int FirstID = bIsHistory ? IDS_HISTORY_0 : IDS_PERSONALITY_0;
  705. int count = bIsHistory ? 5 : PERSONALITY_COUNT;
  706. for ( int i = 0; i < count; i++ )
  707. {
  708. MechlopediaListItem* pItem = new MechlopediaListItem();
  709. char text[256];
  710. cLoadString( FirstID + i, text, 255 );
  711. EString upper = text;
  712. upper.MakeUpper();
  713. pItem->setText( upper );
  714. pItem->setID( i );
  715. pItem->resize( groupListBox->width() - groupListBox->getScrollBarWidth() - 18, pItem->height() );
  716. bool bAdded = 0;
  717. if ( !bIsHistory ) // turns out we need to sort 'em
  718. {
  719. for ( int j = 0; j < groupListBox->GetItemCount(); j++ )
  720. {
  721. MechlopediaListItem* pTmpItem = (MechlopediaListItem*)groupListBox->GetItem( j );
  722. if ( upper.Compare( pTmpItem->getText(), 1 ) < 0 )
  723. {
  724. groupListBox->InsertItem( pItem, j );
  725. bAdded = 1;
  726. break;
  727. }
  728. }
  729. if ( !bAdded )
  730. groupListBox->AddItem( pItem );
  731. }
  732. else
  733. groupListBox->AddItem( pItem );
  734. }
  735. aTextListItem* pItem = (aTextListItem*)groupListBox->GetItem( 0 );
  736. if ( pItem )
  737. {
  738. select( pItem );
  739. groupListBox->SelectItem( 0 );
  740. }
  741. groupListBox->setScrollPos( 0 );
  742. }
  743. void Mechlopedia::PersonalityScreen::select( aTextListItem* pEntry )
  744. {
  745. int ID = pEntry->getID();
  746. descriptionListBox.removeAllItems( true );
  747. int PictureID = bIsHistory ? IDS_HISTORY_PICTURE0 : IDS_PERSONALITY_PICTURE0;
  748. int DescriptionID = bIsHistory ? IDS_HISTORY_DESCRIPTION_0 : IDS_PERONSALITY_DESCRIPTION0;
  749. aTextListItem* pItem = new aTextListItem( IDS_EN_WEAPON_FONT );
  750. pItem->setColor( 0xff005392);
  751. pItem->resize( descriptionListBox.width() - descriptionListBox.getScrollBarWidth() - 16, pEntry->height() );
  752. pItem->setText( DescriptionID + ID );
  753. pItem->sizeToText();
  754. pItem->forceToTop( true );
  755. descriptionListBox.AddItem( pItem );
  756. textObjects[0].setText( pEntry->getText() );
  757. char fileName[256];
  758. cLoadString( PictureID + ID, fileName, 255 );
  759. FullPathFileName path;
  760. path.init( artPath, fileName, ".tga" );
  761. statics[4].setTexture( path );
  762. statics[4].setUVs( 0, 0, statics[4].width(), statics[4].height() );
  763. }
  764. ////////////////////////////////////////////////////////
  765. void MechlopediaListItem::render()
  766. {
  767. bmpAnim.setState( (aAnimGroup::STATE)state );
  768. bmpAnim.update();
  769. long color = bmpAnim.getCurrentColor( (aAnimGroup::STATE)state );
  770. bmp.setColor( color );
  771. bmp.render();
  772. aAnimTextListItem::render();
  773. }
  774. void MechlopediaListItem::init( )
  775. {
  776. FitIniFile file;
  777. FullPathFileName path;
  778. path.init( artPath, "mcl_en_sub", ".fit" );
  779. if ( NO_ERR != file.open( path ) )
  780. {
  781. char errorStr[256];
  782. sprintf( errorStr, "couldn' open file %s", (char*)path );
  783. Assert( 0, 0, errorStr );
  784. return;
  785. }
  786. if ( !s_templateItem )
  787. {
  788. s_templateItem = new MechlopediaListItem();
  789. s_templateItem->bmp.init( &file, "Static0" );
  790. s_templateItem->bmpAnim.init( &file, "Animation1" );
  791. ((aAnimTextListItem*)s_templateItem)->init( file );
  792. }
  793. }
  794. MechlopediaListItem::MechlopediaListItem()
  795. : aAnimTextListItem(IDS_EN_LISTBOX_FONT)
  796. {
  797. if ( s_templateItem&& this != s_templateItem )
  798. {
  799. operator=( *s_templateItem );
  800. bmp = s_templateItem->bmp;
  801. bmpAnim = s_templateItem->bmpAnim;
  802. resize( bmp.width(), bmp.height()+2 );
  803. }
  804. addChild( &bmp );
  805. }
  806. ///////////////////////////////////////////////////////////////////////////////////
  807. void Mechlopedia::BuildingScreen::init()
  808. {
  809. FullPathFileName path;
  810. path.init( artPath, "mcl_en_bldg", ".fit" );
  811. FitIniFile file;
  812. if ( NO_ERR != file.open( path ) )
  813. {
  814. char errorStr[256];
  815. sprintf( errorStr, "couldn't open file %s", (char*)path );
  816. Assert( 0, 0, errorStr );
  817. return;
  818. }
  819. SubScreen::init( file );
  820. compListBox.init( rects[2].left(), rects[2].top(), rects[2].width(), rects[2].height() );
  821. compListBox.move( 285, 58 );
  822. camera.init( statics[4].left() + 285, statics[4].top() + 58, statics[4].right() + 285, statics[4].bottom() + 58 );
  823. statics[4].setColor( 0 );
  824. textObjects[0].setText( "" );
  825. descriptionListBox.init( rects[1].left() + 285, rects[1].top() + 58, rects[1].width(), rects[1].height() );
  826. }
  827. void Mechlopedia::BuildingScreen::update()
  828. {
  829. SubScreen::update();
  830. compListBox.update();
  831. }
  832. void Mechlopedia::BuildingScreen::render()
  833. {
  834. compListBox.render();
  835. descriptionListBox.render();
  836. groupListBox->render();
  837. LogisticsScreen::render(285, 58);
  838. camera.render();
  839. }
  840. void Mechlopedia::BuildingScreen::begin()
  841. {
  842. groupListBox->removeAllItems( true );
  843. LogisticsData::Building* pBldgs[256];
  844. int count = 255;
  845. LogisticsData::instance->getBuildings( pBldgs, count );
  846. for ( int i = 0; i < count; i++ )
  847. {
  848. char tmp[256];
  849. cLoadString( pBldgs[i]->nameID, tmp, 255 );
  850. EString str = tmp;
  851. str.MakeUpper();
  852. EString liao = "Liao ";
  853. str.Remove( liao);
  854. liao = "LIAO ";
  855. str.Remove( liao );
  856. bool bFound = 0;
  857. for ( int j = 0; j < groupListBox->GetItemCount(); j++ )
  858. {
  859. if ( stricmp( str, ((aTextListItem*)groupListBox->GetItem( j ))->getText() ) < 0 )
  860. {
  861. MechlopediaListItem* pItem = new MechlopediaListItem();
  862. pItem->setText( str );
  863. pItem->setID( pBldgs[i]->nameID );
  864. pItem->resize( groupListBox->width() - groupListBox->getScrollBarWidth() - 18, pItem->height() );
  865. groupListBox->InsertItem( pItem, j );
  866. bFound = true;
  867. break;
  868. }
  869. }
  870. if ( !bFound )
  871. {
  872. MechlopediaListItem* pItem = new MechlopediaListItem();
  873. pItem->setText( str );
  874. pItem->setID( pBldgs[i]->nameID );
  875. pItem->resize( groupListBox->width() - groupListBox->getScrollBarWidth() - 18, pItem->height() );
  876. groupListBox->AddItem( pItem );
  877. }
  878. }
  879. aTextListItem* pItem = (aTextListItem*)groupListBox->GetItem( 0 );
  880. select( pItem );
  881. }
  882. void Mechlopedia::BuildingScreen::select( aTextListItem* pEntry )
  883. {
  884. if ( !pEntry )
  885. return;
  886. LogisticsData::Building* pBldg = LogisticsData::instance->getBuilding( pEntry->getID() );
  887. if ( pBldg )
  888. {
  889. char name[256];
  890. cLoadString( pBldg->nameID, name, 255 );
  891. EString tmpStr = name;
  892. tmpStr.MakeUpper();
  893. EString liao = "LIAO ";
  894. tmpStr.Remove( liao );
  895. textObjects[0].setText( tmpStr );
  896. cLoadString( IDS_EN_BUILDING_WEIGHT, name, 255 );
  897. char formatted[256];
  898. sprintf( formatted, name, pBldg->weight );
  899. textObjects[1].setText( formatted );
  900. descriptionListBox.removeAllItems( true );
  901. aTextListItem* pItem = new aTextListItem( IDS_EN_LISTBOX_FONT );
  902. pItem->resize( descriptionListBox.width() - descriptionListBox.getScrollBarWidth() - 16, pItem->height() );
  903. pItem->setText( pBldg->encycloID );
  904. pItem->sizeToText( );
  905. pItem->setColor( 0xff005392 );
  906. pItem->forceToTop( true );
  907. descriptionListBox.AddItem( pItem );
  908. camera.setBuilding( pBldg->fileName );
  909. camera.setScale( pBldg->scale );
  910. LogisticsComponent* pComps[4];
  911. compListBox.removeAllItems( true );
  912. int count= 0;
  913. for ( int i = 0; i < 4; i++ )
  914. {
  915. int ID = pBldg->componentIDs[i];
  916. if ( ID )
  917. {
  918. LogisticsComponent* pComp = LogisticsData::instance->getComponent( ID );
  919. if ( pComp )
  920. {
  921. pComps[count++] = pComp;
  922. }
  923. }
  924. }
  925. if ( count )
  926. compListBox.setComponents( count, pComps );
  927. }
  928. }
  929. //*************************************************************************************************
  930. // end of file ( Mechlopedia.cpp )