OptionsArea.cpp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534
  1. #define OPTIONSAREA_CPP
  2. /*************************************************************************************************\
  3. OptionsArea.cpp : Implementation of the OptionsArea component.
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. \*************************************************************************************************/
  8. #include "OptionsArea.h"
  9. #include "prefs.h"
  10. #include "IniFile.h"
  11. #include "../MCLib/UserInput.h"
  12. #include "..\resource.h"
  13. #include "prefs.h"
  14. #include "missionGui.h"
  15. #include "LogisticsDialog.h"
  16. #include "gameSound.h"
  17. #include "LoadScreen.h"
  18. #ifndef GAMESOUND_H
  19. #include "gamesound.h"
  20. #endif
  21. static bool bShadows = true;
  22. static bool bDetailTexture = true;
  23. static int objectDetail = 0;
  24. static int difficulty = 0;
  25. static bool bUnLimitedAmmo = false;
  26. static long DigitalMasterVolume = 255;
  27. static long MusicVolume = 64;
  28. static long sfxVolume = 64;
  29. static long RadioVolume = 64;
  30. static long BettyVolume = 64;
  31. CPrefs prefs;
  32. CPrefs originalSettings;
  33. #include "mission.h"
  34. extern SoundSystem *sndSystem;
  35. #define MSB_TAB0 200
  36. #define MSB_TAB1 201
  37. #define MSB_TAB2 202
  38. #define MSB_TAB3 203
  39. #define MSG_NEAR 101
  40. #define MSG_FAR 102
  41. #define MSG_TAB 312
  42. #define MSG_TERRAIN_DETAIL 301
  43. #define MSG_PILOT_VIDS 302
  44. #define MSG_OBJECT_DETAIL 303
  45. #define MSG_SHADOWS 304
  46. #define MSG_NON_WEAPON 305
  47. #define MSG_LOCAL_SHADOWS 306
  48. #define MSG_ASYNC_MOUSE 307
  49. #define MSG_HARDWARE_RASTERIZER 308
  50. #define MSG_RESET 309
  51. #define MSG_GREEN 400
  52. #define MSG_REGULAR 401
  53. #define MSG_VETERAN 402
  54. #define MSG_ELITE 403
  55. #define MSG_BASE 404
  56. #define MSG_ACCENT 405
  57. #define MSG_UNLIMITED_AMMO 406
  58. #define MSG_LEFT_CLICK 407
  59. #define MSG_SAVE_TRANSCRIPT 408
  60. #define MSG_TUTORIALS 409
  61. #define CTRL 0x10000000
  62. #define SHIFT 0x01000000
  63. #define ALT 0x00100000
  64. #define WAYPT 0x20000000
  65. HotKeyListItem* HotKeyListItem::s_item = NULL;
  66. OptionsXScreen::OptionsXScreen()
  67. {
  68. statics = 0;
  69. rects = 0;
  70. staticCount = rectCount = buttonCount = textCount = 0;
  71. buttons = 0;
  72. textObjects = 0;
  73. bDone = 0;
  74. curTab = 0;
  75. helpTextArrayID = 1;
  76. }
  77. OptionsXScreen::~OptionsXScreen()
  78. {
  79. for ( int i = 0; i < 4; i++ )
  80. delete tabAreas[i];
  81. }
  82. int OptionsXScreen::indexOfButtonWithID(int id)
  83. {
  84. int i;
  85. for (i = 0; i < buttonCount; i++)
  86. {
  87. if (buttons[i].getID() == id)
  88. {
  89. return i;
  90. }
  91. }
  92. return -1;
  93. }
  94. void OptionsXScreen::init(FitIniFile* file)
  95. {
  96. LogisticsScreen::init( *file, "Static", "Text", "Rect", "Button", "Edit" );
  97. const char* fileNames[4] =
  98. {
  99. "mcl_optionsgraphics",
  100. "mcl_optionsaudio",
  101. "mcl_optionsgameplay",
  102. "mcl_optionshotkeys"
  103. };
  104. OptionsGraphics* pGraphics = new OptionsGraphics;
  105. tabAreas[0] = pGraphics;
  106. OptionsAudio* pAudio = new OptionsAudio;
  107. tabAreas[1] = pAudio;
  108. OptionsGamePlay* pPlay = new OptionsGamePlay;
  109. tabAreas[2] = pPlay;
  110. OptionsHotKeys* pKeys = new OptionsHotKeys;
  111. tabAreas[3] = pKeys;
  112. FullPathFileName path;
  113. for ( int i = 0; i < 4;i++ )
  114. {
  115. path.init( artPath, fileNames[i], ".fit" );
  116. FitIniFile tmpFile;
  117. if ( NO_ERR != tmpFile.open( path ) )
  118. {
  119. char error[256];
  120. sprintf( error, "couldn't open file %s", path );
  121. Assert( 0, 0, error );
  122. return;
  123. }
  124. tabAreas[i]->init( tmpFile, "Static", "Text", "Rect", "Button", "Edit" );
  125. tabAreas[i]->moveTo( rects[2].x(), rects[2].y() );
  126. }
  127. // 640: offset x = -80, y = -90
  128. // 800: offset none
  129. // 1024: offset x = 113, y = 54
  130. // 1280: offset x = 240, y = 182
  131. // 1600: offset x = 400, y = 270
  132. long xOffset = 0;
  133. long yOffset = 0;
  134. switch (Environment.screenWidth)
  135. {
  136. case 640:
  137. xOffset = -80;
  138. yOffset = -90;
  139. break;
  140. case 1024:
  141. xOffset = 13;
  142. yOffset = 54;
  143. break;
  144. case 1280:
  145. xOffset = 240;
  146. yOffset = 182;
  147. break;
  148. case 1600:
  149. xOffset = 400;
  150. yOffset = 270;
  151. break;
  152. }
  153. move( xOffset, yOffset );
  154. pGraphics->init(xOffset, yOffset);
  155. pAudio->init(xOffset, yOffset);
  156. pPlay->init(xOffset, yOffset);
  157. pKeys->init(xOffset, yOffset);
  158. //Needs to be 8.3 or it won't go on the CD!!
  159. originalSettings.load( "OrgPrefs" );
  160. prefs.load();
  161. for ( i = 0; i < 4; i++ )
  162. tabAreas[i]->begin();
  163. if ( mission && strlen( mission->getMissionFileName() ) )
  164. {
  165. getButton( MSB_TAB2 )->disable( true );
  166. }
  167. for ( i = 0; i < buttonCount; i++ )
  168. {
  169. if ( MSB_TAB0 > buttons[i].getID() || MSB_TAB3 < buttons[i].getID() )
  170. buttons[i].setMessageOnRelease( );
  171. }
  172. getButton( MSB_TAB0 )->press( true );
  173. bShowWarning = 0;
  174. }
  175. void OptionsXScreen::render()
  176. {
  177. GUI_RECT rect = { 0, 0, Environment.screenWidth, Environment.screenHeight };
  178. drawRect( rect, 0xff000000 );
  179. rects[1].setColor( 0xff000000 );
  180. rects[1].render();
  181. if ( curTab < 2 )
  182. tabAreas[curTab]->render();
  183. rects[1].setColor( 0 );
  184. LogisticsScreen::render();
  185. getButton( MSB_TAB0 + curTab )->render();
  186. if ( curTab >= 2 )
  187. tabAreas[curTab]->render();
  188. if ( bShowWarning )
  189. {
  190. LogisticsOneButtonDialog::instance()->render();
  191. }
  192. }
  193. int OptionsXScreen::handleMessage( unsigned long message, unsigned long who)
  194. {
  195. if ( aMSG_LEFTMOUSEDOWN == message )
  196. {
  197. switch ( who )
  198. {
  199. case MSB_TAB0:
  200. case MSB_TAB1:
  201. case MSB_TAB2:
  202. case MSB_TAB3:
  203. {
  204. for ( int i = MSB_TAB0; i < MSB_TAB3+1; i++ )
  205. getButton( i )->press( 0 );
  206. getButton( who )->press( true );
  207. curTab = who - MSB_TAB0;
  208. }
  209. break;
  210. case YES:
  211. {
  212. int oldRes = prefs.resolution;
  213. int oldDepth = prefs.bitDepth;
  214. for ( int i = 0; i < 4; i++ )
  215. tabAreas[i]->end();
  216. prefs.save();
  217. prefs.applyPrefs(0);
  218. LoadScreenWrapper::changeRes();
  219. int newRes = prefs.resolution;
  220. int newDepth = prefs.bitDepth;
  221. if ( newRes != oldRes || newDepth != oldDepth )
  222. {
  223. LogisticsOneButtonDialog::instance()->setText( IDS_SWAP_RESOLUTION_WARNING, IDS_DIALOG_OK, IDS_DIALOG_OK );
  224. LogisticsOneButtonDialog::instance()->begin();
  225. bShowWarning = true;
  226. }
  227. else
  228. bDone = true;
  229. return 1;
  230. }
  231. break;
  232. case NO:
  233. {
  234. (dynamic_cast<OptionsGamePlay *>(tabAreas[2]))->resetCamera();
  235. prefs.load();
  236. prefs.applyPrefs(0);
  237. bDone = true;
  238. return 1;
  239. }
  240. break;
  241. }
  242. }
  243. return 0;
  244. }
  245. bool OptionsXScreen::isDone()
  246. {
  247. return bDone;
  248. }
  249. void OptionsXScreen::update()
  250. {
  251. if ( bShowWarning )
  252. {
  253. LogisticsOneButtonDialog::instance()->update();
  254. if ( LogisticsOneButtonDialog::instance()->isDone() )
  255. bDone = true;
  256. return;
  257. }
  258. else
  259. {
  260. LogisticsScreen::update();
  261. tabAreas[curTab]->update();
  262. }
  263. }
  264. void OptionsXScreen::updateOptions()
  265. {
  266. }
  267. //////////////////////////////////////////////
  268. typedef struct
  269. {
  270. long xRes;
  271. long yRes;
  272. long bitDepth;
  273. } ResModes;
  274. ResModes resModes[10] = {
  275. 640, 480, 16,
  276. 640, 480, 32,
  277. 800, 600, 16,
  278. 800, 600, 32,
  279. 1024, 768, 16,
  280. 1024, 768, 32,
  281. 1280,1024, 16,
  282. 1280,1024, 32,
  283. 1600,1200, 16,
  284. 1600,1200, 32
  285. };
  286. bool availableMode[10] = {
  287. true,true,true,true,true,
  288. true,true,true,true,true
  289. };
  290. void OptionsGraphics::init(long xOffset, long yOffset)
  291. {
  292. FullPathFileName path;
  293. path.init( artPath, "mcl_options_combobox0", ".fit" );
  294. FitIniFile file;
  295. if ( NO_ERR !=file.open( path ) )
  296. {
  297. char error[256];
  298. sprintf( error, "couldn't open file %s", path );
  299. Assert( 0, 0, error );
  300. return;
  301. }
  302. getButton( MSG_RESET )->setMessageOnRelease();
  303. resolutionList.init( &file, "PlayerNameComboBox" );
  304. resolutionList.move( globalX(), globalY() );
  305. resolutionList.move( xOffset, yOffset );
  306. resolutionList.ListBox().setOrange( true );
  307. for ( int i = IDS_RESOLUTION0; i < IDS_RESOLUTION9 + 1; i++ )
  308. {
  309. if ( 1!=gos_GetMachineInformation( gos_Info_ValidMode,
  310. Environment.FullScreenDevice,
  311. resModes[i-IDS_RESOLUTION0].xRes,
  312. resModes[i-IDS_RESOLUTION0].yRes,
  313. resModes[i-IDS_RESOLUTION0].bitDepth) )
  314. {
  315. availableMode[i-IDS_RESOLUTION0] = false;
  316. }
  317. else
  318. {
  319. char cstr[256];
  320. cLoadString (i, cstr, 255 );
  321. resolutionList.AddItem( cstr, 0xffffffff );
  322. }
  323. }
  324. file.close();
  325. path.init( artPath, "mcl_options_combobox2", ".fit" );
  326. if ( NO_ERR !=file.open( path ) )
  327. {
  328. char error[256];
  329. sprintf( error, "couldn't open file %s", path );
  330. Assert( 0, 0, error );
  331. return;
  332. }
  333. getButton( MSG_RESET )->setMessageOnRelease();
  334. cardList.init( &file, "PlayerNameComboBox" );
  335. cardList.move( globalX(), globalY() );
  336. cardList.move( xOffset, yOffset );
  337. cardList.ListBox().setOrange( true );
  338. DWORD numDevices = 0;
  339. numDevices = gos_GetMachineInformation( gos_Info_NumberDevices );
  340. //Theoretically impossible but config would probably like to know if it happens!
  341. if (numDevices <= 0)
  342. STOP(("GameOS said there were no video cards in the system!"));
  343. long usableCardCount = 0;
  344. for (i=0;i<numDevices;i++)
  345. {
  346. DWORD minTextureRam = 6291456;
  347. //If we are a Voodoo 2, we may be a 4/8 or a 4/4. Try allowing a 4/4 to run
  348. // and see what happens!! NO good has come of this!
  349. /*
  350. if ((gos_GetMachineInformation(gos_Info_GetDeviceVendorID,i) == 0x121a) &&
  351. (gos_GetMachineInformation(gos_Info_GetDeviceDeviceID,i) == 0x0002))
  352. minTextureRam = 4096000;
  353. */
  354. if (gos_GetMachineInformation(gos_Info_GetDeviceLocalMemory, i) >= minTextureRam)
  355. {
  356. char *deviceName = (char*)gos_GetMachineInformation( gos_Info_GetDeviceName, i);
  357. //Save name to other string here.
  358. cardList.AddItem( deviceName, 0xffffffff );
  359. if ( Environment.FullScreenDevice == i )
  360. cardList.SelectItem( usableCardCount );
  361. usableCardCount++;
  362. }
  363. }
  364. //ALL of this is a lie. Code is now correct but I would ignore this.
  365. // Sorry Heidi!
  366. // -fs
  367. //Turns out, its the same for both.
  368. //Environment.Renderer tells you what device you are currently using as follows:
  369. // If the value is 0 or 1 you are using the default device or the primary display adapter (One and the same always)
  370. // If the value is 2 you are using the second video card.
  371. // If the value is 3 you are using BLADE software renderer.
  372. //If you set the values to any of the above, you will switch to that device.
  373. for ( i = 0; i < buttonCount; i++ )
  374. {
  375. buttons[i].setPressFX( LOG_VIDEOBUTTONS );
  376. buttons[i].setHighlightFX( LOG_DIGITALHIGHLIGHT );
  377. buttons[i].setDisabledFX( LOG_WRONGBUTTON );
  378. }
  379. move( xOffset, yOffset );
  380. helpTextArrayID = 1;
  381. }
  382. int OptionsGraphics::handleMessage( unsigned long message, unsigned long fromWho )
  383. {
  384. if ( fromWho == MSG_RESET )
  385. reset(originalSettings);
  386. return 1;
  387. }
  388. void OptionsGraphics::render()
  389. {
  390. LogisticsScreen::render();
  391. resolutionList.render();
  392. cardList.render();
  393. }
  394. void OptionsGraphics::update()
  395. {
  396. if ( resolutionList.IsExpanded() )
  397. {
  398. textObjects[helpTextArrayID].setText( "" );
  399. helpTextID = 0;
  400. resolutionList.update();
  401. if ( helpTextID )
  402. textObjects[helpTextArrayID].setText( helpTextID );
  403. bExpanded = true;
  404. }
  405. else
  406. {
  407. if ( !bExpanded )
  408. {
  409. LogisticsScreen::update();
  410. }
  411. if ( userInput->leftMouseReleased() )
  412. bExpanded = 0;
  413. }
  414. // if ( cardList.ListBox().GetItemCount() > 1 )
  415. cardList.update();
  416. if ( !mission || !strlen( mission->getMissionFileName() ) )
  417. {
  418. if ( !bExpanded )
  419. resolutionList.update(); // don't want to call 2x's
  420. }
  421. else if ( userInput->isLeftClick() &&
  422. resolutionList.pointInside( userInput->getMouseX(), userInput->getMouseY() ) )
  423. {
  424. soundSystem->playDigitalSample( LOG_WRONGBUTTON );
  425. }
  426. }
  427. void OptionsGraphics::begin()
  428. {
  429. helpTextArrayID = 1;
  430. reset(prefs);
  431. }
  432. void OptionsGraphics::end()
  433. {
  434. prefs.useWaterInterestTexture = getButton( MSG_TERRAIN_DETAIL )->isPressed( );
  435. prefs.pilotVideos = getButton( MSG_PILOT_VIDS )->isPressed();
  436. prefs.useHighObjectDetail = getButton( MSG_OBJECT_DETAIL )->isPressed();
  437. prefs.useShadows = getButton( MSG_SHADOWS )->isPressed();
  438. prefs.useNonWeaponEffects = getButton( MSG_NON_WEAPON )->isPressed();
  439. prefs.useLocalShadows = getButton( MSG_LOCAL_SHADOWS )->isPressed();
  440. prefs.asyncMouse = getButton( MSG_ASYNC_MOUSE )->isPressed();
  441. prefs.renderer = getButton( MSG_HARDWARE_RASTERIZER )->isPressed() ? 0 : 3;
  442. int sel = resolutionList.GetSelectedItem();
  443. if ( sel > -1 )
  444. {
  445. long actualSel = -1;
  446. for ( int i = IDS_RESOLUTION0; i < IDS_RESOLUTION9 + 1; i++ )
  447. {
  448. if (availableMode[i-IDS_RESOLUTION0])
  449. actualSel++;
  450. if (actualSel == sel)
  451. {
  452. switch (resModes[i-IDS_RESOLUTION0].xRes)
  453. {
  454. case 640:
  455. prefs.resolution = 0;
  456. break;
  457. case 800:
  458. prefs.resolution = 1;
  459. break;
  460. case 1024:
  461. prefs.resolution = 2;
  462. break;
  463. case 1280:
  464. prefs.resolution = 3;
  465. break;
  466. case 1600:
  467. prefs.resolution = 4;
  468. break;
  469. }
  470. switch (resModes[i-IDS_RESOLUTION0].bitDepth)
  471. {
  472. case 16:
  473. prefs.bitDepth = 0;
  474. break;
  475. case 32:
  476. prefs.bitDepth = 1;
  477. break;
  478. }
  479. break;
  480. }
  481. }
  482. }
  483. int index = cardList.GetSelectedItem( );
  484. if ( (index != -1) && (prefs.renderer != 3))
  485. prefs.renderer = index;
  486. }
  487. void OptionsGraphics::reset(const CPrefs& newPrefs)
  488. {
  489. getButton( MSG_TERRAIN_DETAIL )->press( newPrefs.useWaterInterestTexture );
  490. getButton( MSG_PILOT_VIDS )->press( newPrefs.pilotVideos );
  491. getButton( MSG_OBJECT_DETAIL )->press( newPrefs.useHighObjectDetail );
  492. getButton( MSG_SHADOWS )->press( newPrefs.useShadows );
  493. getButton( MSG_NON_WEAPON )->press( newPrefs.useNonWeaponEffects );
  494. getButton( MSG_LOCAL_SHADOWS )->press( newPrefs.useLocalShadows );
  495. getButton( MSG_ASYNC_MOUSE )->press( newPrefs.asyncMouse );
  496. getButton( MSG_HARDWARE_RASTERIZER )->press( (newPrefs.renderer != 3) );
  497. if (availableMode[1])
  498. {
  499. resolutionList.SelectItem( newPrefs.resolution * 2 + newPrefs.bitDepth );
  500. }
  501. else //Assume there are no 32-bit modes available. Not ideal, but all we can do
  502. {
  503. resolutionList.SelectItem( newPrefs.resolution );
  504. }
  505. }
  506. //*************************************************************************************************
  507. //////////////////////////////////////////////
  508. void OptionsAudio::init(long xOffset, long yOffset)
  509. {
  510. getButton( MSG_RESET )->setMessageOnRelease();
  511. for ( int i = 0; i < buttonCount; i++ )
  512. {
  513. if ( buttons[i].getID() != MSG_RESET )
  514. {
  515. buttons[i].setParent( NULL );
  516. }
  517. }
  518. move( xOffset, yOffset );
  519. for ( i = 0; i < buttonCount; i++ )
  520. {
  521. buttons[i].setPressFX( LOG_VIDEOBUTTONS );
  522. buttons[i].setHighlightFX( LOG_DIGITALHIGHLIGHT );
  523. buttons[i].setDisabledFX( LOG_WRONGBUTTON );
  524. }
  525. for ( i = 0; i < 5; i++ )
  526. {
  527. scrollBars[i].init( &buttons[i * 2], &buttons[i * 2 + 1], &buttons[i + 11] );
  528. addChild( &scrollBars[i] );
  529. scrollBars[i].move( -x(), -y() );
  530. scrollBars[i].SetScrollMax( 255 );
  531. }
  532. helpTextArrayID = 15;
  533. }
  534. int OptionsAudio::handleMessage( unsigned long message, unsigned long fromWho )
  535. {
  536. if ( fromWho == MSG_RESET )
  537. reset(originalSettings);
  538. return 1;
  539. }
  540. void OptionsAudio::render()
  541. {
  542. LogisticsScreen::render();
  543. for ( int i = 0; i < 5; i++ )
  544. {
  545. scrollBars[i].render();
  546. }
  547. }
  548. void OptionsAudio::update()
  549. {
  550. LogisticsScreen::update();
  551. for ( int i = 0; i < 5; i++ )
  552. {
  553. scrollBars[i].update();
  554. }
  555. //Lets update these on the fly so they can hear how much better it sounds.
  556. prefs.DigitalMasterVolume = scrollBars[0].GetScrollPos();
  557. prefs.MusicVolume = scrollBars[1].GetScrollPos();
  558. prefs.sfxVolume = scrollBars[2].GetScrollPos();
  559. prefs.RadioVolume = scrollBars[3].GetScrollPos();
  560. prefs.BettyVolume = scrollBars[4].GetScrollPos();
  561. if (sndSystem)
  562. {
  563. sndSystem->setDigitalMasterVolume(prefs.DigitalMasterVolume);
  564. sndSystem->setSFXVolume(prefs.sfxVolume);
  565. sndSystem->setRadioVolume(prefs.RadioVolume);
  566. sndSystem->setMusicVolume(prefs.MusicVolume);
  567. sndSystem->setBettyVolume(prefs.BettyVolume);
  568. }
  569. }
  570. void OptionsAudio::begin()
  571. {
  572. helpTextArrayID = 15;
  573. reset(prefs);
  574. }
  575. void OptionsAudio::end()
  576. {
  577. prefs.DigitalMasterVolume = scrollBars[0].GetScrollPos();
  578. prefs.MusicVolume = scrollBars[1].GetScrollPos();
  579. prefs.sfxVolume = scrollBars[2].GetScrollPos();
  580. prefs.RadioVolume = scrollBars[3].GetScrollPos();
  581. prefs.BettyVolume = scrollBars[4].GetScrollPos();
  582. }
  583. void OptionsAudio::reset(const CPrefs& newPrefs)
  584. {
  585. scrollBars[0].SetScrollPos( newPrefs.DigitalMasterVolume );
  586. scrollBars[1].SetScrollPos( newPrefs.MusicVolume );
  587. scrollBars[2].SetScrollPos( newPrefs.sfxVolume );
  588. scrollBars[3].SetScrollPos( newPrefs.RadioVolume );
  589. scrollBars[4].SetScrollPos( newPrefs.BettyVolume );
  590. }
  591. //////////////////////////////////////////////
  592. void OptionsGamePlay::resetCamera()
  593. {
  594. //Do NOT setup a camera in mission.
  595. // A. We don't need it cause the option is greyed out.
  596. // B. It creates a mech which will NOT be deleted until we
  597. // come back to logistics, at which point, THESE heaps will be gone!!
  598. // Then, CRASH!
  599. if ( mission && strlen( mission->getMissionFileName() ) )
  600. {
  601. }
  602. else
  603. {
  604. camera.setMech( NULL );
  605. }
  606. }
  607. void OptionsGamePlay::init(long xOffset, long yOffset)
  608. {
  609. camera.init(rects[1].globalX() + xOffset, rects[1].globalY() + yOffset,
  610. rects[1].globalRight() + xOffset, rects[1].globalBottom()+yOffset);
  611. camera.setInMission();
  612. getButton( MSG_BASE )->press( true );
  613. getButton( MSG_ACCENT )->press( 0 );
  614. for ( int i = 0; i < buttonCount; i++ )
  615. {
  616. buttons[i].setPressFX( LOG_VIDEOBUTTONS );
  617. buttons[i].setHighlightFX( LOG_DIGITALHIGHLIGHT );
  618. buttons[i].setDisabledFX( LOG_WRONGBUTTON );
  619. }
  620. move( xOffset, yOffset );
  621. helpTextArrayID = 2;
  622. }
  623. int OptionsGamePlay::handleMessage( unsigned long message, unsigned long fromWho )
  624. {
  625. if ( fromWho >= MSG_GREEN && fromWho < MSG_ELITE+1 )
  626. {
  627. for ( int i = MSG_GREEN; i < MSG_ELITE+1; i++ )
  628. {
  629. getButton( i )->press( 0 );
  630. }
  631. getButton( fromWho )->press( true );
  632. }
  633. switch( fromWho )
  634. {
  635. case MSG_RESET:
  636. reset(originalSettings);
  637. break;
  638. case MSG_BASE:
  639. case MSG_ACCENT:
  640. getButton( MSG_BASE )->press( 0 );
  641. getButton( MSG_ACCENT )->press( 0 );
  642. getButton( fromWho )->press( true );
  643. break;
  644. }
  645. return 1;
  646. }
  647. void OptionsGamePlay::render()
  648. {
  649. LogisticsScreen::render();
  650. long colorToMatch = getButton( MSG_BASE )->isPressed() ?
  651. rects[36].getColor() : rects[37].getColor();
  652. for ( int i = 4; i < 36; i++ )
  653. {
  654. if ( rects[i].getColor() == colorToMatch )
  655. {
  656. GUI_RECT tmp = { rects[i].globalX() - 2,
  657. rects[i].globalY() - 2,
  658. rects[i].globalRight() + 1,
  659. rects[i].globalBottom() + 1 };
  660. drawEmptyRect( tmp, 0xffffffff, 0xffffffff );
  661. break;
  662. }
  663. }
  664. rects[37].render();
  665. rects[36].render();
  666. camera.render();
  667. }
  668. void OptionsGamePlay::update()
  669. {
  670. camera.update();
  671. LogisticsScreen::update();
  672. aRect* pRect = getButton( MSG_BASE )->isPressed() ?
  673. &rects[36] : &rects[37];
  674. bool bChanged = 0;
  675. if ( userInput->isLeftClick() )
  676. {
  677. for ( int i = 4; i < 36; i++ )
  678. {
  679. if ( rects[i].pointInside( userInput->getMouseX(),
  680. userInput->getMouseY() ) )
  681. {
  682. pRect->setColor( rects[i].getColor() );
  683. bChanged = 1;
  684. break;
  685. }
  686. }
  687. }
  688. if ( bChanged )
  689. camera.setMech( "Bushwacker", rects[36].getColor(), rects[37].getColor(), rects[37].getColor() );
  690. }
  691. void OptionsGamePlay::begin()
  692. {
  693. helpTextArrayID = 2;
  694. reset(prefs);
  695. //Do NOT setup a camera in mission.
  696. // A. We don't need it cause the option is greyed out.
  697. // B. It creates a mech which will NOT be deleted until we
  698. // come back to logistics, at which point, THESE heaps will be gone!!
  699. // Then, CRASH!
  700. if ( mission && strlen( mission->getMissionFileName() ) )
  701. {
  702. }
  703. else
  704. {
  705. camera.setMech( "Bushwacker", prefs.baseColor,
  706. prefs.highlightColor, prefs.highlightColor );
  707. }
  708. }
  709. void OptionsGamePlay::end()
  710. {
  711. for ( int i = MSG_GREEN; i < MSG_ELITE + 1; i++ )
  712. {
  713. if ( getButton( i )->isPressed() )
  714. prefs.GameDifficulty = i - MSG_GREEN;
  715. }
  716. prefs.baseColor = rects[36].getColor( );
  717. prefs.highlightColor = rects[37].getColor( );
  718. prefs.useUnlimitedAmmo = getButton( MSG_UNLIMITED_AMMO )->isPressed();
  719. prefs.useLeftRightMouseProfile = getButton( MSG_LEFT_CLICK )->isPressed();
  720. //prefs.tutorials = getButton( MSG_TUTORIALS )->isPressed();
  721. //Do NOT setup a camera in mission.
  722. // A. We don't need it cause the option is greyed out.
  723. // B. It creates a mech which will NOT be deleted until we
  724. // come back to logistics, at which point, THESE heaps will be gone!!
  725. // Then, CRASH!
  726. if ( mission && strlen( mission->getMissionFileName() ) )
  727. {
  728. }
  729. else
  730. {
  731. camera.setMech( NULL );
  732. }
  733. }
  734. void OptionsGamePlay::reset(const CPrefs& newPrefs)
  735. {
  736. for ( int i = MSG_GREEN; i < MSG_ELITE + 1; i++ )
  737. {
  738. getButton( i )->press( 0 );
  739. }
  740. getButton( MSG_GREEN + newPrefs.GameDifficulty )->press( true );
  741. rects[36].setColor( newPrefs.baseColor );
  742. rects[37].setColor( newPrefs.highlightColor );
  743. getButton( MSG_UNLIMITED_AMMO )->press( newPrefs.useUnlimitedAmmo );
  744. getButton( MSG_LEFT_CLICK )->press( newPrefs.useLeftRightMouseProfile );
  745. // getButton( MSG_TUTORIALS )->press( newPrefs.tutorials );
  746. }
  747. //*************************************************************************************************
  748. //////////////////////////////////////////////
  749. void OptionsHotKeys::init(long xOffset, long yOffset)
  750. {
  751. hotKeyList.init( rects[0].x(), rects[0].y(), rects[0].width(), rects[0].height() );
  752. helpTextArrayID = 2;
  753. HotKeyListItem::init();
  754. hotKeyList.setOrange(true);
  755. bShowDlg = 0;
  756. move( xOffset, yOffset );
  757. hotKeyList.move( xOffset, yOffset );
  758. helpTextArrayID = 2;
  759. }
  760. int OptionsHotKeys::handleMessage( unsigned long message, unsigned long fromWho )
  761. {
  762. switch( fromWho )
  763. {
  764. case MSG_RESET:
  765. reset(true);
  766. break;
  767. }
  768. return 1;
  769. }
  770. void OptionsHotKeys::render()
  771. {
  772. hotKeyList.render();
  773. LogisticsScreen::render();
  774. if ( bShowDlg )
  775. {
  776. LogisticsOKDialog::instance()->render();
  777. }
  778. }
  779. void OptionsHotKeys::update()
  780. {
  781. if ( bShowDlg )
  782. {
  783. LogisticsOKDialog::instance()->update();
  784. if ( LogisticsOKDialog::instance()->isDone() )
  785. {
  786. bShowDlg = 0;
  787. if ( LogisticsDialog::YES == LogisticsOKDialog::instance()->getStatus() )
  788. {
  789. char keysString[256];
  790. keysString[0] = 0;
  791. makeKeyString( curHotKey, keysString );
  792. long index = hotKeyList.GetSelectedItem();
  793. long oldKey = -1;
  794. if ( index > -1 )
  795. {
  796. HotKeyListItem* pItemToSet = (HotKeyListItem*)hotKeyList.GetItem( index );
  797. // now I've got to find the other one with th new key and set it to the old key
  798. for ( int i = 0; i < hotKeyList.GetItemCount(); i++ )
  799. {
  800. HotKeyListItem* pTmpItem = (HotKeyListItem*)hotKeyList.GetItem( i );
  801. if ( pTmpItem->getHotKey() == curHotKey && pTmpItem != pItemToSet )
  802. {
  803. // first we've got to see if we can set to the default
  804. long* defaultKeys = MissionInterfaceManager::getOldKeys();
  805. int defaultKey = defaultKeys[pTmpItem->getCommand()];
  806. for ( int j = 0; j < hotKeyList.GetItemCount(); j++ )
  807. {
  808. HotKeyListItem* pCheckItem = (HotKeyListItem*)hotKeyList.GetItem( j );
  809. if ( pCheckItem->getHotKey() == defaultKey )
  810. {
  811. defaultKey = -1;
  812. break;
  813. }
  814. }
  815. if ( defaultKey != -1 )
  816. oldKey = defaultKey;
  817. else if ( pItemToSet )
  818. oldKey = pItemToSet->getHotKey();
  819. char tmpKeyStr[256];
  820. tmpKeyStr[0] = 0;
  821. makeKeyString( oldKey, tmpKeyStr );
  822. pTmpItem->setHotKey( oldKey );
  823. pTmpItem->setKey( tmpKeyStr );
  824. }
  825. }
  826. pItemToSet->setKey( keysString );
  827. pItemToSet->setHotKey( curHotKey );
  828. hotKeyList.SelectItem( -1 );
  829. }
  830. }
  831. }
  832. return;
  833. }
  834. LogisticsScreen::update();
  835. hotKeyList.update();
  836. long tmpKey = 1;
  837. while( tmpKey ) // empty out keyboard buffers...
  838. {
  839. int index = hotKeyList.GetSelectedItem( );
  840. tmpKey = 0;
  841. if ( index > -1 )
  842. {
  843. HotKeyListItem* pItem = (HotKeyListItem*)hotKeyList.GetItem( index );
  844. tmpKey = gos_GetKey();
  845. if ( tmpKey )
  846. {
  847. char hotKeyString[256];
  848. hotKeyString[0] = 0;
  849. if ( 0 != makeInputKeyString( tmpKey, hotKeyString ) )
  850. return;
  851. curHotKey = tmpKey;
  852. // check and see if anyone else is using this one...
  853. for ( int i = 0; i < hotKeyList.GetItemCount(); i++ )
  854. {
  855. HotKeyListItem* pTmpItem = (HotKeyListItem*)hotKeyList.GetItem( i );
  856. if ( pTmpItem->getHotKey() == curHotKey && pTmpItem != pItem )
  857. {
  858. LogisticsOKDialog::instance()->setText( IDS_OPTIONS_HOTKEY_ERROR, IDS_DIALOG_NO, IDS_DIALOG_YES );
  859. LogisticsOKDialog::instance()->begin();
  860. bShowDlg = true;
  861. }
  862. }
  863. if ( !bShowDlg )
  864. {
  865. pItem->setHotKey( tmpKey );
  866. pItem->setKey( hotKeyString );
  867. hotKeyList.SelectItem( -1 );
  868. }
  869. }
  870. }
  871. }
  872. }
  873. void OptionsHotKeys::makeKeyString( long newKey, char* keysString )
  874. {
  875. char shift[32];
  876. char control[32];
  877. char alt[32];
  878. cLoadString( IDS_SHIFT, shift, 31 );
  879. cLoadString( IDS_CONTROL, control, 31 );
  880. cLoadString( IDS_ALT, alt, 31 );
  881. long key = newKey;
  882. char* pKey = gos_DescribeKey( (key & 0x000fffff) << 8 );
  883. if ( ((key & SHIFT)) )
  884. {
  885. strcat( keysString, shift );
  886. strcat( keysString, " + " );
  887. }
  888. if ( ((key & CTRL)) )
  889. {
  890. strcat( keysString, control );
  891. strcat( keysString, " + " );
  892. }
  893. if ( ((key & ALT)) )
  894. {
  895. strcat( keysString, alt );
  896. strcat( keysString, " + " );
  897. }
  898. strcat( keysString, pKey );
  899. }
  900. int OptionsHotKeys::makeInputKeyString( long& tmpKey, char* hotKeyString )
  901. {
  902. const char* pText = gos_DescribeKey( tmpKey & 0x0001ff00 );
  903. long tmp = ( tmpKey >> 8 ) & 0x01ff;
  904. if ( tmp == KEY_LSHIFT || tmp == KEY_LMENU || tmp == KEY_LCONTROL )
  905. return -1;
  906. long hotKey = tmp;
  907. bool shiftDn = userInput->shift();
  908. if ( shiftDn )
  909. {
  910. char shift[32];
  911. cLoadString( IDS_SHIFT, shift, 31 );
  912. hotKey |= SHIFT;
  913. strcat( hotKeyString, shift );
  914. strcat( hotKeyString, " + " );
  915. }
  916. bool ctrlDn = userInput->ctrl();
  917. if ( ctrlDn )
  918. {
  919. char control[32];
  920. cLoadString( IDS_CONTROL, control, 31 );
  921. hotKey |= CTRL;
  922. strcat( hotKeyString, control );
  923. strcat( hotKeyString, " + " );
  924. }
  925. bool altDn = userInput->alt();
  926. if ( altDn )
  927. {
  928. char alt[32];
  929. cLoadString( IDS_ALT, alt, 31 );
  930. hotKey |= ALT;
  931. strcat( hotKeyString, alt );
  932. strcat( hotKeyString, " + " );
  933. }
  934. strcat( hotKeyString, pText );
  935. tmpKey = hotKey;
  936. return 0;
  937. }
  938. void OptionsHotKeys::begin()
  939. {
  940. helpTextArrayID = 2;
  941. reset(0);
  942. }
  943. void OptionsHotKeys::end()
  944. {
  945. for ( int i= 0; i < hotKeyList.GetItemCount(); i++ )
  946. {
  947. HotKeyListItem* pItem = (HotKeyListItem*)hotKeyList.GetItem( i );
  948. if ( pItem )
  949. {
  950. int Command = pItem->getCommand();
  951. int Key = pItem->getHotKey();
  952. MissionInterfaceManager::setHotKey( Command, (gosEnum_KeyIndex)(Key & 0x000ffff),
  953. Key & SHIFT,Key & CTRL, Key & ALT );
  954. }
  955. }
  956. bShowDlg= 0;
  957. hotKeyList.removeAllItems( true );
  958. // MissionInterfaceManager::setHotKey(
  959. }
  960. void OptionsHotKeys::reset( bool useOld )
  961. {
  962. hotKeyList.removeAllItems( true );
  963. char shift[32];
  964. char control[32];
  965. char alt[32];
  966. char descText[128];
  967. char keysString[128];
  968. cLoadString( IDS_SHIFT, shift, 31 );
  969. cLoadString( IDS_CONTROL, control, 31 );
  970. cLoadString( IDS_ALT, alt, 31 );
  971. MissionInterfaceManager::Command* commands = MissionInterfaceManager::getCommands();
  972. long* oldKeys = MissionInterfaceManager::getOldKeys();
  973. for ( int i = 0; i < MAX_COMMAND; i++ )
  974. {
  975. if ( commands[i].hotKeyDescriptionText != -1 )
  976. {
  977. keysString[0] = 0;
  978. cLoadString( commands[i].hotKeyDescriptionText, descText, 127 );
  979. long key = useOld ? oldKeys[i] : commands[i].key;
  980. makeKeyString( key, keysString );
  981. HotKeyListItem* item = new HotKeyListItem();
  982. item->setDescription( descText );
  983. item->setKey( keysString );
  984. item->setHotKey( key );
  985. item->setCommand( i );
  986. hotKeyList.AddItem( item );
  987. }
  988. }
  989. }
  990. //*************************************************************************************************
  991. ScrollX::ScrollX()
  992. {
  993. scrollMax = 0;
  994. scrollPos = 0;
  995. lastX = 0;
  996. scrollInc = 1;
  997. pageInc = 5;
  998. }
  999. long ScrollX::init(aButton* pLeft, aButton* pRight, aButton* pTab)
  1000. {
  1001. aObject::init( pLeft->globalX(), pLeft->top(),
  1002. pRight->globalRight() - pLeft->globalX(),
  1003. pRight->bottom() - pRight->top() );
  1004. buttons[0] = pLeft;
  1005. buttons[1] = pRight;
  1006. buttons[2] = pTab;
  1007. pLeft->setPressFX( -1 );
  1008. pLeft->setHighlightFX( -1 );
  1009. pLeft->setDisabledFX( -1 );
  1010. for ( int i = 0; i < 3; i++ )
  1011. buttons[i]->setHoldTime( .01f );
  1012. pLeft->moveTo( 0, 0 );
  1013. pRight->moveTo( width() - pRight->width(), 0 );
  1014. pTab->moveTo( pLeft->width() + 1, -1 );
  1015. addChild( pLeft );
  1016. addChild( pRight );
  1017. addChild( pTab );
  1018. setColor( 0 );
  1019. return (NO_ERR);
  1020. }
  1021. void ScrollX::SetScrollMax(float newMax)
  1022. {
  1023. scrollMax = newMax;
  1024. buttons[2]->showGUIWindow(newMax != 0);
  1025. ResizeAreas();
  1026. }
  1027. void ScrollX::SetScrollPos(float newPos)
  1028. {
  1029. if (newPos < 0)
  1030. newPos = 0;
  1031. if (newPos > scrollMax)
  1032. newPos = scrollMax;
  1033. scrollPos = newPos;
  1034. ResizeAreas();
  1035. }
  1036. void ScrollX::SetScroll( long newScrollPos )
  1037. {
  1038. if ( newScrollPos < 0 )
  1039. newScrollPos = 0;
  1040. if ( newScrollPos > scrollMax )
  1041. newScrollPos = scrollMax;
  1042. if ( getParent() )
  1043. getParent()->handleMessage( aMSG_SCROLLTO, newScrollPos );
  1044. SetScrollPos( newScrollPos );
  1045. }
  1046. void ScrollX::update()
  1047. {
  1048. long mouseX = userInput->getMouseX();
  1049. long mouseY = userInput->getMouseY();
  1050. if ( userInput->isLeftDrag() && lastX ) // dragging the little tab
  1051. {
  1052. float delta = (float)mouseX - (buttons[0]->globalX() + buttons[0]->width() );
  1053. // figure out what this translates to
  1054. float physicalRange = width() - buttons[0]->width() - buttons[1]->width() - buttons[2]->width();
  1055. float RealRange = scrollMax;
  1056. if ( !physicalRange )
  1057. physicalRange = RealRange;
  1058. float newScrollPos = .5 + (delta)*RealRange/physicalRange;
  1059. if ( newScrollPos < 0 )
  1060. newScrollPos = 0;
  1061. if ( newScrollPos > scrollMax )
  1062. newScrollPos = scrollMax;
  1063. getParent()->handleMessage( aMSG_SCROLLTO, newScrollPos );
  1064. SetScrollPos( newScrollPos );
  1065. }
  1066. else if ( pointInside( mouseX, mouseY ) )
  1067. {
  1068. if ( userInput->isLeftClick() || gos_GetKeyStatus(KEY_LMOUSE) == KEY_HELD )
  1069. {
  1070. lastX = 0;
  1071. if ( buttons[2]->pointInside( mouseX, mouseY ) &&
  1072. buttons[2]->pointInside( userInput->getMouseDragX(), userInput->getMouseDragY() ) )
  1073. lastX = mouseX;
  1074. else if ( getParent() )
  1075. {
  1076. buttons[2]->press( 0 );
  1077. if ( !buttons[0]->pointInside( mouseX, mouseY )
  1078. && !buttons[1]->pointInside( mouseX, mouseY )
  1079. && pointInside(userInput->getMouseDragX(), userInput->getMouseDragY()) )
  1080. {
  1081. float physicalRange = width() - buttons[0]->width() - buttons[1]->width() - buttons[2]->width();
  1082. float RealRange = scrollMax;
  1083. float delta = (float)mouseX - (buttons[0]->globalX() + buttons[0]->width());
  1084. // if above the thumb, page up, otherwise page down
  1085. if ( mouseY < buttons[2]->top() )
  1086. {
  1087. float newScrollPos = (delta)*RealRange/physicalRange;
  1088. if ( scrollPos - newScrollPos > pageInc )
  1089. {
  1090. newScrollPos = scrollPos - pageInc;
  1091. }
  1092. getParent()->handleMessage( aMSG_SCROLLTO, newScrollPos );
  1093. SetScrollPos( newScrollPos );
  1094. }
  1095. else
  1096. {
  1097. float newScrollPos = (delta)*RealRange/physicalRange;
  1098. if ( newScrollPos - scrollPos > pageInc )
  1099. {
  1100. newScrollPos = scrollPos + pageInc;
  1101. }
  1102. getParent()->handleMessage( aMSG_SCROLLTO, newScrollPos );
  1103. SetScrollPos( newScrollPos );
  1104. }
  1105. }
  1106. }
  1107. }
  1108. else
  1109. buttons[2]->press( 0 );
  1110. }
  1111. else
  1112. buttons[2]->press( 0 );
  1113. if ( userInput->leftMouseReleased() )
  1114. lastX = 0;
  1115. aObject::update();
  1116. }
  1117. int ScrollX::handleMessage( unsigned long message, unsigned long who )
  1118. {
  1119. switch (who )
  1120. {
  1121. case aMSG_SCROLLUP:
  1122. SetScrollPos( scrollPos - scrollInc );
  1123. break;
  1124. case aMSG_SCROLLDOWN:
  1125. SetScrollPos( scrollPos + scrollInc );
  1126. break;
  1127. }
  1128. return getParent()->handleMessage( who, who );
  1129. }
  1130. void ScrollX::ResizeAreas(void)
  1131. {
  1132. float range, position;
  1133. if (scrollMax == 0)
  1134. return;
  1135. range = width() - buttons[0]->width() - buttons[1]->width() - buttons[2]->width() - 4.f; // one scrollwidth for buttons, one for tab. 2 for lines at either end.
  1136. position = range * scrollPos / scrollMax; // center of scroll tab;
  1137. buttons[2]->moveTo( globalX() + position + buttons[0]->width() + 2, globalY() + 1);
  1138. }
  1139. void ScrollX::Enable( bool enable )
  1140. {
  1141. buttons[2]->disable( !enable );
  1142. buttons[0]->disable( !enable );
  1143. buttons[1]->disable( !enable );
  1144. }
  1145. void HotKeyListItem::init()
  1146. {
  1147. if ( s_item )
  1148. return;
  1149. s_item = new HotKeyListItem();
  1150. FitIniFile file;
  1151. FullPathFileName path;
  1152. path.init( artPath, "mcl_options_combobox1", ".fit" );
  1153. if ( NO_ERR != file.open( path ) )
  1154. {
  1155. char error[256];
  1156. sprintf( error, "couldn't open file %s", path );
  1157. Assert( 0, 0, error );
  1158. return;
  1159. }
  1160. s_item->description.init( &file, "Text0" );
  1161. s_item->text.init( &file, "Text1" );
  1162. s_item->animations[0].init( &file, "Animation0" );
  1163. s_item->animations[1].init( &file, "Animation1" );
  1164. s_item->animations[2].init( &file, "Animation2" );
  1165. s_item->rects[0].init( &file, "Rect0" );
  1166. s_item->rects[1].init( &file, "Rect1" );
  1167. }
  1168. void HotKeyListItem::render()
  1169. {
  1170. aAnimGroup::STATE curState = (aAnimGroup::STATE)getState();
  1171. for ( int i = 0; i < 3; i++ )
  1172. {
  1173. animations[i].setState( curState );
  1174. animations[i].update();
  1175. }
  1176. text.setColor( animations[1].getCurrentColor( curState ) );
  1177. description.setColor( animations[0].getCurrentColor( curState ) );
  1178. rects[1].setColor( animations[2].getCurrentColor( curState ) );
  1179. aObject::render();
  1180. }
  1181. void HotKeyListItem::update()
  1182. {
  1183. }
  1184. void HotKeyListItem::setDescription( const char* pText )
  1185. {
  1186. description.setText( pText );
  1187. }
  1188. void HotKeyListItem::setKey( const char* pText )
  1189. {
  1190. text.setText( pText );
  1191. }
  1192. HotKeyListItem::~HotKeyListItem()
  1193. {
  1194. removeAllChildren( 0 );
  1195. }
  1196. HotKeyListItem::HotKeyListItem( )
  1197. {
  1198. if ( s_item )
  1199. {
  1200. description = s_item->description;
  1201. text = s_item->text;
  1202. for ( int i = 0; i < 3; i++ )
  1203. animations[i] = s_item->animations[i];
  1204. rects[0] = s_item->rects[0];
  1205. rects[1] = s_item->rects[1];
  1206. aObject::init( 0, 0, rects[1].right(), rects[0].bottom()+1 );
  1207. addChild( &rects[1] );
  1208. addChild( &description );
  1209. addChild( &text );
  1210. addChild( &rects[0] );
  1211. }
  1212. }