graphicsMenu.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. // =============================================================================
  2. // GRAPHICS MENU
  3. // =============================================================================
  4. //Mesh and Textures
  5. //
  6. function GraphicsMenu::onWake(%this)
  7. {
  8. DisplaySettingsMenu.hidden = false;
  9. GeneralGraphicsSettingsMenu.hidden = true;
  10. %this.refresh();
  11. }
  12. function GraphicsMenu::refresh(%this)
  13. {
  14. //
  15. // Display Menu
  16. GraphicsMenuFullScreen.setStateOn( Canvas.isFullScreen() );
  17. GraphicsMenuVSync.setStateOn( !$pref::Video::disableVerticalSync );
  18. %this.initResMenu();
  19. %resSelId = GraphicsMenuResolution.findText( _makePrettyResString( $pref::Video::mode ) );
  20. if( %resSelId != -1 )
  21. GraphicsMenuResolution.setSelected( %resSelId );
  22. GraphicsMenuDriver.clear();
  23. %buffer = getDisplayDeviceList();
  24. %count = getFieldCount( %buffer );
  25. for(%i = 0; %i < %count; %i++)
  26. GraphicsMenuDriver.add(getField(%buffer, %i), %i);
  27. %selId = GraphicsMenuDriver.findText( getDisplayDeviceInformation() );
  28. if ( %selId == -1 )
  29. GraphicsMenuDriver.setFirstSelected();
  30. else
  31. GraphicsMenuDriver.setSelected( %selId );
  32. //
  33. //
  34. // General Graphics menu
  35. GraphicsMenuShadowQlty.init(ShadowQualityList);
  36. GraphicsMenuSoftShadow.init(SoftShadowList);
  37. GraphicsMenuModelDtl.init(MeshQualityGroup);
  38. GraphicsMenuTextureDtl.init(TextureQualityGroup);
  39. GraphicsMenuTerrainDtl.init(TerrainQualityGroup);
  40. GraphicsMenuDecalLife.init(DecalLifetimeGroup);
  41. GraphicsMenuGroundClutter.init(GroundCoverDensityGroup);
  42. GraphicsMenuMaterialQlty.init(ShaderQualityGroup);
  43. // Setup the anisotropic filtering menu.
  44. %ansioCtrl = GraphicsMenuAniso;
  45. %ansioCtrl.clear();
  46. %ansioCtrl.add( "16X", 16 );
  47. %ansioCtrl.add( "8X", 8 );
  48. %ansioCtrl.add( "4X", 4 );
  49. %ansioCtrl.add( "Off", 0 );
  50. %ansioCtrl.setSelected( $pref::Video::defaultAnisotropy, false );
  51. // set up the Refresh Rate menu.
  52. %refreshMenu = GraphicsMenuRefreshRate;
  53. %refreshMenu.clear();
  54. // %refreshMenu.add("Auto", 60);
  55. %refreshMenu.add("60", 60);
  56. %refreshMenu.add("75", 75);
  57. %refreshMenu.setSelected( $pref::Video::RefreshRate );
  58. // Populate the Anti-aliasing popup.
  59. %aaMenu = GraphicsMenuAA;
  60. %aaMenu.clear();
  61. %aaMenu.Add( "4x", 4 );
  62. %aaMenu.Add( "2x", 2 );
  63. %aaMenu.Add( "1x", 1 );
  64. %aaMenu.Add( "Off", 0 );
  65. %aaMenu.setSelected( $pref::Video::AA );
  66. //Parallax
  67. GraphicsMenuParallax.setStateOn(!$pref::Video::disableParallaxMapping);
  68. //water reflections
  69. GraphicsMenuWaterRefl.setStateOn(!$pref::Water::disableTrueReflections);
  70. GraphicsMenuParallax.setStateOn(!$pref::Video::disableParallaxMapping);
  71. GraphicsMenuAO.setStateOn($pref::PostFX::EnableSSAO);
  72. GraphicsMenuHDR.setStateOn($pref::PostFX::EnableHDR);
  73. GraphicsMenuDOF.setStateOn($pref::PostFX::EnableDOF);
  74. GraphicsMenuVignette.setStateOn($pref::PostFX::EnableVignette);
  75. GraphicsMenuLightRay.setStateOn($pref::PostFX::EnableLightRays);
  76. }
  77. function GraphicsMenuOKButton::onClick(%this)
  78. {
  79. //save the settings and then back out
  80. GraphicsMenu.apply();
  81. OptionsMenu.backOut();
  82. }
  83. function GraphicsMenu::initResMenu( %this )
  84. {
  85. // Clear out previous values
  86. %resMenu = GraphicsMenuResolution;
  87. %resMenu.clear();
  88. // If we are in a browser then we can't change our resolution through
  89. // the options dialog
  90. if (getWebDeployment())
  91. {
  92. %count = 0;
  93. %currRes = getWords(Canvas.getVideoMode(), $WORD::RES_X, $WORD::RES_Y);
  94. %resMenu.add(%currRes, %count);
  95. %count++;
  96. return;
  97. }
  98. // Loop through all and add all valid resolutions
  99. %count = 0;
  100. %resCount = Canvas.getModeCount();
  101. for (%i = 0; %i < %resCount; %i++)
  102. {
  103. %testResString = Canvas.getMode( %i );
  104. %testRes = _makePrettyResString( %testResString );
  105. // Only add to list if it isn't there already.
  106. if (%resMenu.findText(%testRes) == -1)
  107. {
  108. %resMenu.add(%testRes, %i);
  109. %count++;
  110. }
  111. }
  112. %resMenu.sort();
  113. }
  114. function GraphicsQualityPopup::init( %this, %qualityGroup )
  115. {
  116. assert( isObject( %this ) );
  117. assert( isObject( %qualityGroup ) );
  118. %this.qualityGroup = %qualityGroup;
  119. // Clear the existing content first.
  120. %this.clear();
  121. // Fill it.
  122. %select = -1;
  123. for ( %i=0; %i < %qualityGroup.getCount(); %i++ )
  124. {
  125. %level = %qualityGroup.getObject( %i );
  126. if ( %level.isCurrent() )
  127. %select = %i;
  128. %this.add( %level.displayName, %i );
  129. }
  130. // Setup a default selection.
  131. if ( %select == -1 )
  132. %this.setText( "Custom" );
  133. else
  134. %this.setSelected( %select );
  135. }
  136. function GraphicsQualityPopup::apply( %this )
  137. {
  138. %levelName = %this.getText();
  139. %this.qualityGroup.applySetting(%levelName);
  140. }
  141. //
  142. function GraphicsMenu::Autodetect(%this)
  143. {
  144. $pref::Video::autoDetect = false;
  145. %shaderVer = getPixelShaderVersion();
  146. %intel = ( strstr( strupr( getDisplayDeviceInformation() ), "INTEL" ) != -1 ) ? true : false;
  147. %videoMem = GFXCardProfilerAPI::getVideoMemoryMB();
  148. return %this.Autodetect_Apply( %shaderVer, %intel, %videoMem );
  149. }
  150. function GraphicsMenu::Autodetect_Apply(%this, %shaderVer, %intel, %videoMem )
  151. {
  152. if ( %shaderVer < 2.0 )
  153. {
  154. return "Your video card does not meet the minimum requirment of shader model 2.0.";
  155. }
  156. if ( %shaderVer < 3.0 || %intel )
  157. {
  158. // Allow specular and normals for 2.0a and 2.0b
  159. if ( %shaderVer > 2.0 )
  160. {
  161. MeshQualityGroup.applySetting("Lowest");
  162. TextureQualityGroup.applySetting("Lowest");
  163. GroundCoverDensityGroup.applySetting("Lowest");
  164. DecalLifetimeGroup.applySetting("None");
  165. TerrainQualityGroup.applySetting("Lowest");
  166. ShaderQualityGroup.applySetting("High");
  167. ShadowQualityList.applySetting("None");
  168. SoftShadowList.applySetting("Off");
  169. $pref::Shadows::useShadowCaching = true;
  170. $pref::Water::disableTrueReflections = true;
  171. $pref::Video::disableParallaxMapping = true;
  172. $pref::PostFX::EnableSSAO = false;
  173. $pref::PostFX::EnableHDR = false;
  174. $pref::PostFX::EnableDOF = false;
  175. $pref::PostFX::EnableLightRays = false;
  176. $pref::PostFX::EnableVignette = false;
  177. $pref::Video::AA = 0;
  178. $pref::Video::disableVerticalSync = 0;
  179. }
  180. else
  181. {
  182. MeshQualityGroup.applySetting("Lowest");
  183. TextureQualityGroup.applySetting("Lowest");
  184. GroundCoverDensityGroup.applySetting("Lowest");
  185. DecalLifetimeGroup.applySetting("None");
  186. TerrainQualityGroup.applySetting("Lowest");
  187. ShaderQualityGroup.applySetting("Low");
  188. ShadowQualityList.applySetting("None");
  189. SoftShadowList.applySetting("Off");
  190. $pref::Shadows::useShadowCaching = true;
  191. $pref::Water::disableTrueReflections = true;
  192. $pref::Video::disableParallaxMapping = true;
  193. $pref::PostFX::EnableSSAO = false;
  194. $pref::PostFX::EnableHDR = false;
  195. $pref::PostFX::EnableDOF = false;
  196. $pref::PostFX::EnableLightRays = false;
  197. $pref::PostFX::EnableVignette = false;
  198. $pref::Video::AA = 0;
  199. $pref::Video::disableVerticalSync = 0;
  200. }
  201. }
  202. else
  203. {
  204. if ( %videoMem > 1000 )
  205. {
  206. MeshQualityGroup.applySetting("High");
  207. TextureQualityGroup.applySetting("High");
  208. GroundCoverDensityGroup.applySetting("High");
  209. DecalLifetimeGroup.applySetting("High");
  210. TerrainQualityGroup.applySetting("High");
  211. ShaderQualityGroup.applySetting("High");
  212. ShadowQualityList.applySetting("High");
  213. SoftShadowList.applySetting("High");
  214. //Should this default to on in ultra settings?
  215. $pref::Shadows::useShadowCaching = true;
  216. $pref::Water::disableTrueReflections = false;
  217. $pref::Video::disableParallaxMapping = false;
  218. $pref::PostFX::EnableSSAO = true;
  219. $pref::PostFX::EnableHDR = true;
  220. $pref::PostFX::EnableDOF = true;
  221. $pref::PostFX::EnableLightRays = true;
  222. $pref::PostFX::EnableVignette = true;
  223. $pref::Video::AA = 4;
  224. $pref::Video::disableVerticalSync = 16;
  225. }
  226. else if ( %videoMem > 400 || %videoMem == 0 )
  227. {
  228. MeshQualityGroup.applySetting("Medium");
  229. TextureQualityGroup.applySetting("Medium");
  230. GroundCoverDensityGroup.applySetting("Medium");
  231. DecalLifetimeGroup.applySetting("Medium");
  232. TerrainQualityGroup.applySetting("Medium");
  233. ShaderQualityGroup.applySetting("High");
  234. ShadowQualityList.applySetting("Medium");
  235. SoftShadowList.applySetting("Low");
  236. $pref::Shadows::useShadowCaching = true;
  237. $pref::Water::disableTrueReflections = false;
  238. $pref::Video::disableParallaxMapping = true;
  239. $pref::PostFX::EnableSSAO = false;
  240. $pref::PostFX::EnableHDR = true;
  241. $pref::PostFX::EnableDOF = true;
  242. $pref::PostFX::EnableLightRays = true;
  243. $pref::PostFX::EnableVignette = true;
  244. $pref::Video::AA = 4;
  245. $pref::Video::disableVerticalSync = 4;
  246. if ( %videoMem == 0 )
  247. return "Torque was unable to detect available video memory. Applying 'Medium' quality.";
  248. }
  249. else
  250. {
  251. MeshQualityGroup.applySetting("Low");
  252. TextureQualityGroup.applySetting("Low");
  253. GroundCoverDensityGroup.applySetting("Low");
  254. DecalLifetimeGroup.applySetting("Low");
  255. TerrainQualityGroup.applySetting("Low");
  256. ShaderQualityGroup.applySetting("Low");
  257. ShadowQualityList.applySetting("None");
  258. SoftShadowList.applySetting("Off");
  259. $pref::Shadows::useShadowCaching = true;
  260. $pref::Water::disableTrueReflections = false;
  261. $pref::Video::disableParallaxMapping = true;
  262. $pref::PostFX::EnableSSAO = false;
  263. $pref::PostFX::EnableHDR = false;
  264. $pref::PostFX::EnableDOF = false;
  265. $pref::PostFX::EnableLightRays = false;
  266. $pref::PostFX::EnableVignette = false;
  267. $pref::Video::AA = 0;
  268. $pref::Video::disableVerticalSync = 0;
  269. }
  270. }
  271. %this.refresh();
  272. %this.apply();
  273. //force postFX updates
  274. PostFXManager.settingsEffectSetEnabled("SSAO", $pref::PostFX::EnableSSAO);
  275. PostFXManager.settingsEffectSetEnabled("HDR", $pref::PostFX::EnableHDR);
  276. PostFXManager.settingsEffectSetEnabled("DOF", $pref::PostFX::EnableDOF);
  277. PostFXManager.settingsEffectSetEnabled("LightRays", $pref::PostFX::EnableLightRays);
  278. PostFXManager.settingsEffectSetEnabled("Vignette", $pref::PostFX::EnableVignette);
  279. return "Graphics quality settings have been auto detected.";
  280. }
  281. function _makePrettyResString( %resString )
  282. {
  283. %width = getWord( %resString, $WORD::RES_X );
  284. %height = getWord( %resString, $WORD::RES_Y );
  285. %aspect = %width / %height;
  286. %aspect = mRound( %aspect * 100 ) * 0.01;
  287. switch$( %aspect )
  288. {
  289. case "1.33":
  290. %aspect = "4:3";
  291. case "1.78":
  292. %aspect = "16:9";
  293. default:
  294. %aspect = "";
  295. }
  296. %outRes = %width @ " x " @ %height;
  297. if ( %aspect !$= "" )
  298. %outRes = %outRes @ " (" @ %aspect @ ")";
  299. return %outRes;
  300. }
  301. //
  302. function GraphicsMenuSetting::init( %this )
  303. {
  304. assert( isObject( %this ) );
  305. assert( isObject( %this.qualitySettingGroup ) );
  306. // Fill it.
  307. %select = -1;
  308. %selectedName = "";
  309. for ( %i=0; %i < %this.qualitySettingGroup.getCount(); %i++ )
  310. {
  311. %level = %this.qualitySettingGroup.getObject( %i );
  312. %levelName = %level.displayName;
  313. if ( %level.isCurrent() )
  314. {
  315. %select = %i;
  316. %selectedName = %level.displayName;
  317. }
  318. }
  319. // Setup a default selection.
  320. if ( %select == -1 )
  321. {
  322. %this-->SettingText.setText( "Custom" );
  323. %this.selectedLevel = %this.qualitySettingGroup.getCount();
  324. }
  325. else
  326. {
  327. %this-->SettingText.setText(%selectedName);
  328. %this.selectedLevel = %select;
  329. }
  330. }
  331. function GraphicsQualityLevel::isCurrent( %this )
  332. {
  333. // Test each pref to see if the current value
  334. // equals our stored value.
  335. for ( %i=0; %i < %this.count(); %i++ )
  336. {
  337. %pref = %this.getKey( %i );
  338. %value = %this.getValue( %i );
  339. if ( getVariable( %pref ) !$= %value )
  340. return false;
  341. }
  342. return true;
  343. }
  344. function GraphicsQualityLevel::apply( %this )
  345. {
  346. for ( %i=0; %i < %this.count(); %i++ )
  347. {
  348. %pref = %this.getKey( %i );
  349. %value = %this.getValue( %i );
  350. setVariable( %pref, %value );
  351. }
  352. // If we have an overloaded onApply method then
  353. // call it now to finalize the changes.
  354. if ( %this.isMethod( "onApply" ) )
  355. %this.onApply();
  356. else
  357. {
  358. %group = %this.getGroup();
  359. if ( isObject( %group ) && %group.isMethod( "onApply" ) )
  360. %group.onApply( %this );
  361. }
  362. }
  363. function GraphicsOptionsMenuGroup::applySetting(%this, %settingName)
  364. {
  365. for(%i=0; %i < %this.getCount(); %i++)
  366. {
  367. %setting = %this.getObject(%i);
  368. if(%setting.displayName $= %settingName)
  369. {
  370. for ( %s=0; %s < %setting.count(); %s++ )
  371. {
  372. %pref = %setting.getKey( %s );
  373. %value = %setting.getValue( %s );
  374. setVariable( %pref, %value );
  375. }
  376. }
  377. }
  378. }
  379. function GraphicsMenu::apply(%this)
  380. {
  381. %newAdapter = GraphicsMenuDriver.getText();
  382. %numAdapters = GFXInit::getAdapterCount();
  383. %newDevice = $pref::Video::displayDevice;
  384. for( %i = 0; %i < %numAdapters; %i ++ )
  385. {
  386. if( GFXInit::getAdapterName( %i ) $= %newAdapter )
  387. {
  388. %newDevice = GFXInit::getAdapterType( %i );
  389. break;
  390. }
  391. }
  392. // Change the device.
  393. if ( %newDevice !$= $pref::Video::displayDevice )
  394. {
  395. if ( %testNeedApply )
  396. return true;
  397. $pref::Video::displayDevice = %newDevice;
  398. if( %newAdapter !$= getDisplayDeviceInformation() )
  399. MessageBoxOK( "Change requires restart", "Please restart the game for a display device change to take effect." );
  400. }
  401. GraphicsMenuShadowQlty.apply();
  402. GraphicsMenuSoftShadow.apply();
  403. GraphicsMenuModelDtl.apply();
  404. GraphicsMenuTextureDtl.apply();
  405. GraphicsMenuTerrainDtl.apply();
  406. GraphicsMenuDecalLife.apply();
  407. GraphicsMenuGroundClutter.apply();
  408. GraphicsMenuMaterialQlty.apply();
  409. //Update Textures
  410. reloadTextures();
  411. //Update lighting
  412. // Set the light manager. This should do nothing
  413. // if its already set or if its not compatible.
  414. setLightManager( $pref::lightManager );
  415. PostFXManager.settingsEffectSetEnabled("SSAO", $pref::PostFX::EnableSSAO);
  416. PostFXManager.settingsEffectSetEnabled("HDR", $pref::PostFX::EnableHDR);
  417. PostFXManager.settingsEffectSetEnabled("DOF", $pref::PostFX::EnableDOF);
  418. PostFXManager.settingsEffectSetEnabled("LightRays", $pref::PostFX::EnableLightRays);
  419. PostFXManager.settingsEffectSetEnabled("Vignette", $pref::PostFX::EnableVignette);
  420. $pref::Video::disableParallaxMapping = !GraphicsMenuParallax.isStateOn();
  421. //water reflections
  422. $pref::Water::disableTrueReflections = !GraphicsMenuWaterRefl.isStateOn();
  423. //Update the display settings now
  424. $pref::Video::Resolution = getWords( Canvas.getMode( GraphicsMenuResolution.getSelected() ), $WORD::RES_X, $WORD::RES_Y );
  425. %newBpp = 32; // ... its not 1997 anymore.
  426. $pref::Video::FullScreen = GraphicsMenuFullScreen.isStateOn() ? "true" : "false";
  427. $pref::Video::RefreshRate = GraphicsMenuRefreshRate.getSelected();
  428. $pref::Video::disableVerticalSync = !GraphicsMenuVSync.isStateOn();
  429. $pref::Video::AA = GraphicsMenuAA.getSelected();
  430. if ( %newFullScreen $= "false" )
  431. {
  432. // If we're in windowed mode switch the fullscreen check
  433. // if the resolution is bigger than the desktop.
  434. %deskRes = getDesktopResolution();
  435. %deskResX = getWord(%deskRes, $WORD::RES_X);
  436. %deskResY = getWord(%deskRes, $WORD::RES_Y);
  437. if ( getWord( %newRes, $WORD::RES_X ) > %deskResX ||
  438. getWord( %newRes, $WORD::RES_Y ) > %deskResY )
  439. {
  440. $pref::Video::FullScreen = "true";
  441. GraphicsMenuFullScreen.setStateOn( true );
  442. }
  443. }
  444. // Build the final mode string.
  445. %newMode = $pref::Video::Resolution SPC $pref::Video::FullScreen SPC %newBpp SPC $pref::Video::RefreshRate SPC $pref::Video::AA;
  446. // Change the video mode.
  447. if ( %newMode !$= $pref::Video::mode ||
  448. %newVsync != $pref::Video::disableVerticalSync )
  449. {
  450. if ( %testNeedApply )
  451. return true;
  452. $pref::Video::mode = %newMode;
  453. $pref::Video::disableVerticalSync = %newVsync;
  454. configureCanvas();
  455. }
  456. // Check the anisotropic filtering.
  457. %level = GraphicsMenuAniso.getSelected();
  458. if ( %level != $pref::Video::defaultAnisotropy )
  459. {
  460. if ( %testNeedApply )
  461. return true;
  462. $pref::Video::defaultAnisotropy = %level;
  463. }
  464. echo("Exporting client prefs");
  465. %prefPath = getPrefpath();
  466. export("$pref::*", %prefPath @ "/clientPrefs.cs", false);
  467. }