optionsMenu.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. //options settings
  2. //Screen and Display menu
  3. //Renderer Mode
  4. //Screen resolution
  5. //Windowed/fullscreen(borderless?)
  6. //VSync
  7. //Screen brightness
  8. //screen brightness
  9. //screen gamma
  10. //Lighting Menu
  11. //Shadow Distance(Distance shadows are drawn to. Also affects shadowmap slices)
  12. //Shadow Quality(Resolution of shadows rendered, setting to none disables dynamic shadows)
  13. //Soft Shadows(Whether shadow softening is used)
  14. //Shadow caching(If the lights enable it, shadow caching is activated)
  15. //Light Draw Distance(How far away lights are still drawn. Doesn't impact vector lights like the sun)
  16. //Mesh and Textures Menu
  17. //Draw distance(Overall draw distance) -slider
  18. //Object draw distance(Draw distance from small/unimportant objects) -slider
  19. //Mesh quality
  20. //Texture quality
  21. //Foliage draw distance
  22. //Terrain Quality
  23. //Decal Quality
  24. //Effects Menu
  25. //Parallax
  26. //HDR
  27. //Light shafts
  28. //Motion Blur
  29. //Depth of Field
  30. //SSAO
  31. //AA(ModelXAmount)[defualt is FXAA]
  32. //Anisotropic filtering
  33. //Keybinds
  34. //Camera
  35. //horizontal mouse sensitivity
  36. //vert mouse sensitivity
  37. //invert vertical
  38. //zoom mouse sensitivities(both horz/vert)
  39. //headbob
  40. //FOV
  41. function OptionsMenu::onWake(%this)
  42. {
  43. OptionsMain.hidden = false;
  44. ControlsMenu.hidden = true;
  45. GraphicsMenu.hidden = true;
  46. AudioMenu.hidden = true;
  47. CameraMenu.hidden = true;
  48. ScreenBrightnessMenu.hidden = true;
  49. OptionsOKButton.hidden = false;
  50. OptionsCancelButton.hidden = false;
  51. OptionsDefaultsButton.hidden = false;
  52. }
  53. function OptionsMenuOKButton::onClick(%this)
  54. {
  55. //save the settings and then back out
  56. OptionsMenu.backOut();
  57. }
  58. function OptionsMenuCancelButton::onClick(%this)
  59. {
  60. //we don't save, so go straight to backing out of the menu
  61. OptionsMenu.backOut();
  62. }
  63. function OptionsMenuDefaultsButton::onClick(%this)
  64. {
  65. //we don't save, so go straight to backing out of the menu
  66. OptionsMenu.backOut();
  67. }
  68. function ControlsSettingsMenuButton::onClick(%this)
  69. {
  70. OptionsMain.hidden = true;
  71. ControlsMenu.hidden = false;
  72. KeyboardControlPanel.hidden = false;
  73. MouseControlPanel.hidden = true;
  74. ControlsMenu.reload();
  75. }
  76. function GraphicsSettingsMenuButton::onClick(%this)
  77. {
  78. OptionsMain.hidden = true;
  79. GraphicsMenu.hidden = false;
  80. }
  81. function CameraSettingsMenuButton::onClick(%this)
  82. {
  83. OptionsMain.hidden = true;
  84. CameraMenu.hidden = false;
  85. CameraMenu.loadSettings();
  86. }
  87. function AudioSettingsMenuButton::onClick(%this)
  88. {
  89. OptionsMain.hidden = true;
  90. AudioMenu.hidden = false;
  91. AudioMenu.loadSettings();
  92. }
  93. function ScreenBrSettingsMenuButton::onClick(%this)
  94. {
  95. OptionsMain.hidden = true;
  96. ScreenBrightnessMenu.hidden = false;
  97. }
  98. function OptionsMenu::backOut(%this)
  99. {
  100. //save the settings and then back out
  101. if(OptionsMain.hidden == false)
  102. {
  103. //we're not in a specific menu, so we're actually exiting
  104. Canvas.popDialog(OptionsMenu);
  105. if(isObject(OptionsMenu.returnGui) && OptionsMenu.returnGui.isMethod("onReturnTo"))
  106. OptionsMenu.returnGui.onReturnTo();
  107. }
  108. else
  109. {
  110. OptionsMain.hidden = false;
  111. ControlsMenu.hidden = true;
  112. GraphicsMenu.hidden = true;
  113. CameraMenu.hidden = true;
  114. AudioMenu.hidden = true;
  115. ScreenBrightnessMenu.hidden = true;
  116. }
  117. }
  118. function OptionsMenu::addSettingOption(%this, %arrayTarget)
  119. {
  120. %graphicsOption = OptionsMenu.tamlReader.read("data/ui/scripts/guis/graphicsMenuSettingsCtrl.taml");
  121. %arrayTarget.add(%graphicsOption);
  122. return %graphicsOption;
  123. }
  124. function OptionsMenu::addSliderOption(%this, %arrayTarget, %range, %ticks, %variable, %value, %class)
  125. {
  126. %graphicsOption = OptionsMenu.tamlReader.read("data/ui/scripts/guis/graphicsMenuSettingsSlider.taml");
  127. %arrayTarget.add(%graphicsOption);
  128. if(%range !$= "")
  129. {
  130. %graphicsOption-->slider.range = %range;
  131. }
  132. if(%ticks !$= "")
  133. {
  134. %graphicsOption-->slider.ticks = %ticks;
  135. }
  136. if(%variable !$= "")
  137. {
  138. %graphicsOption-->slider.variable = %variable;
  139. }
  140. if(%value !$= "")
  141. {
  142. %graphicsOption-->slider.setValue(%value);
  143. }
  144. if(%class !$= "")
  145. {
  146. %graphicsOption-->slider.className = %class;
  147. }
  148. else
  149. %graphicsOption-->slider.className = OptionsMenuSlider;
  150. %graphicsOption-->slider.snap = true;
  151. %graphicsOption-->slider.onValueSet();
  152. return %graphicsOption;
  153. }
  154. function OptionsMenuSlider::onMouseDragged(%this)
  155. {
  156. %this.onValueSet();
  157. }
  158. function OptionsMenuSlider::onValueSet(%this)
  159. {
  160. %this.getParent().getParent()-->valueText.setText(mRound(%this.value * 10));
  161. }
  162. function FOVOptionSlider::onMouseDragged(%this)
  163. {
  164. %this.onValueSet();
  165. }
  166. function FOVOptionSlider::onValueSet(%this)
  167. {
  168. %this.getParent().getParent()-->valueText.setText(mRound(%this.value));
  169. }
  170. /// Returns true if the current quality settings equal
  171. /// this graphics quality level.
  172. function OptionsMenuSettingLevel::isCurrent( %this )
  173. {
  174. // Test each pref to see if the current value
  175. // equals our stored value.
  176. for ( %i=0; %i < %this.count(); %i++ )
  177. {
  178. %pref = %this.getKey( %i );
  179. %value = %this.getValue( %i );
  180. %prefVarValue = getVariable( %pref );
  181. if ( getVariable( %pref ) !$= %value )
  182. return false;
  183. }
  184. return true;
  185. }
  186. // =============================================================================
  187. // CAMERA MENU
  188. // =============================================================================
  189. function CameraMenu::onWake(%this)
  190. {
  191. }
  192. function CameraMenu::apply(%this)
  193. {
  194. setFOV($pref::Player::defaultFov);
  195. }
  196. function CameraMenu::loadSettings(%this)
  197. {
  198. CameraMenuOptionsArray.clear();
  199. %option = OptionsMenu.addSettingOption(CameraMenuOptionsArray);
  200. %option-->nameText.setText("Invert Vertical");
  201. %option.qualitySettingGroup = InvertVerticalMouse;
  202. %option.init();
  203. %option = OptionsMenu.addSliderOption(CameraMenuOptionsArray, "0.1 1", 8, "$pref::Input::VertMouseSensitivity", $pref::Input::VertMouseSensitivity);
  204. %option-->nameText.setText("Vertical Sensitivity");
  205. %option = OptionsMenu.addSliderOption(CameraMenuOptionsArray, "0.1 1", 8, "$pref::Input::HorzMouseSensitivity", $pref::Input::HorzMouseSensitivity);
  206. %option-->nameText.setText("Horizontal Sensitivity");
  207. %option = OptionsMenu.addSliderOption(CameraMenuOptionsArray, "0.1 1", 8, "$pref::Input::ZoomVertMouseSensitivity", $pref::Input::ZoomVertMouseSensitivity);
  208. %option-->nameText.setText("Zoom Vertical Sensitivity");
  209. %option = OptionsMenu.addSliderOption(CameraMenuOptionsArray, "0.1 1", 8, "$pref::Input::ZoomHorzMouseSensitivity", $pref::Input::ZoomHorzMouseSensitivity);
  210. %option-->nameText.setText("Zoom Horizontal Sensitivity");
  211. %option = OptionsMenu.addSliderOption(CameraMenuOptionsArray, "65 90", 25, "$pref::Player::defaultFov", $pref::Player::defaultFov, FOVOptionSlider);
  212. %option-->nameText.setText("Field of View");
  213. CameraMenuOptionsArray.refresh();
  214. }
  215. function CameraMenuOKButton::onClick(%this)
  216. {
  217. //save the settings and then back out
  218. CameraMenu.apply();
  219. OptionsMenu.backOut();
  220. }
  221. function CameraMenuDefaultsButton::onClick(%this)
  222. {
  223. }
  224. // =============================================================================
  225. // AUDIO MENU
  226. // =============================================================================
  227. $AudioTestHandle = 0;
  228. // Description to use for playing the volume test sound. This isn't
  229. // played with the description of the channel that has its volume changed
  230. // because we know nothing about the playback state of the channel. If it
  231. // is paused or stopped, the test sound would not play then.
  232. $AudioTestDescription = new SFXDescription()
  233. {
  234. sourceGroup = AudioChannelMaster;
  235. };
  236. function AudioMenu::loadSettings(%this)
  237. {
  238. // Audio
  239. //OptAudioHardwareToggle.setStateOn($pref::SFX::useHardware);
  240. //OptAudioHardwareToggle.setActive( true );
  241. %this-->OptAudioVolumeMaster.setValue( $pref::SFX::masterVolume );
  242. %this-->OptAudioVolumeShell.setValue( $pref::SFX::channelVolume[ $GuiAudioType] );
  243. %this-->OptAudioVolumeSim.setValue( $pref::SFX::channelVolume[ $SimAudioType ] );
  244. %this-->OptAudioVolumeMusic.setValue( $pref::SFX::channelVolume[ $MusicAudioType ] );
  245. AudioMenuSoundDriver.clear();
  246. %buffer = sfxGetAvailableDevices();
  247. %count = getRecordCount( %buffer );
  248. for(%i = 0; %i < %count; %i++)
  249. {
  250. %record = getRecord(%buffer, %i);
  251. %provider = getField(%record, 0);
  252. if ( AudioMenuSoundDriver.findText( %provider ) == -1 )
  253. AudioMenuSoundDriver.add( %provider, %i );
  254. }
  255. AudioMenuSoundDriver.sort();
  256. %selId = AudioMenuSoundDriver.findText($pref::SFX::provider);
  257. if ( %selId == -1 )
  258. AudioMenuSoundDriver.setFirstSelected();
  259. else
  260. AudioMenuSoundDriver.setSelected( %selId );
  261. }
  262. function AudioMenu::loadDevices(%this)
  263. {
  264. if(!isObject(SoundDeviceGroup))
  265. {
  266. new SimGroup( SoundDeviceGroup );
  267. }
  268. else
  269. {
  270. SoundDeviceGroup.clear();
  271. }
  272. %buffer = sfxGetAvailableDevices();
  273. %count = getRecordCount( %buffer );
  274. for (%i = 0; %i < %count; %i++)
  275. {
  276. %record = getRecord(%buffer, %i);
  277. %provider = getField(%record, 0);
  278. %device = getField(%record, 1);
  279. if($pref::SFX::provider !$= %provider)
  280. continue;
  281. %setting = new ArrayObject()
  282. {
  283. class = "OptionsMenuSettingLevel";
  284. caseSensitive = true;
  285. displayName = %device;
  286. key["$pref::SFX::Device"] = %device;
  287. };
  288. SoundDeviceGroup.add(%setting);
  289. }
  290. }
  291. function AudioMenu::apply(%this)
  292. {
  293. sfxSetMasterVolume( $pref::SFX::masterVolume );
  294. sfxSetChannelVolume( $GuiAudioType, $pref::SFX::channelVolume[ $GuiAudioType ] );
  295. sfxSetChannelVolume( $SimAudioType, $pref::SFX::channelVolume[ $SimAudioType ] );
  296. sfxSetChannelVolume( $MusicAudioType, $pref::SFX::channelVolume[ $MusicAudioType ] );
  297. if ( !sfxCreateDevice( $pref::SFX::provider,
  298. $pref::SFX::device,
  299. $pref::SFX::useHardware,
  300. -1 ) )
  301. error( "Unable to create SFX device: " @ $pref::SFX::provider
  302. SPC $pref::SFX::device
  303. SPC $pref::SFX::useHardware );
  304. if( !isObject( $AudioTestHandle ) )
  305. {
  306. sfxPlay(menuButtonPressed);
  307. }
  308. }
  309. function AudioMenuOKButton::onClick(%this)
  310. {
  311. //save the settings and then back out
  312. AudioMenu.apply();
  313. OptionsMenu.backOut();
  314. }
  315. function AudioMenuDefaultsButton::onClick(%this)
  316. {
  317. sfxInit();
  318. AudioMenu.loadSettings();
  319. }
  320. function OptAudioUpdateMasterVolume( %volume )
  321. {
  322. if( %volume == $pref::SFX::masterVolume )
  323. return;
  324. sfxSetMasterVolume( %volume );
  325. $pref::SFX::masterVolume = %volume;
  326. if( !isObject( $AudioTestHandle ) )
  327. $AudioTestHandle = sfxPlayOnce( AudioChannel, "art/sound/ui/volumeTest.wav" );
  328. }
  329. function OptAudioUpdateChannelVolume( %description, %volume )
  330. {
  331. %channel = sfxGroupToOldChannel( %description.sourceGroup );
  332. if( %volume == $pref::SFX::channelVolume[ %channel ] )
  333. return;
  334. sfxSetChannelVolume( %channel, %volume );
  335. $pref::SFX::channelVolume[ %channel ] = %volume;
  336. if( !isObject( $AudioTestHandle ) )
  337. {
  338. $AudioTestDescription.volume = %volume;
  339. $AudioTestHandle = sfxPlayOnce( $AudioTestDescription, "art/sound/ui/volumeTest.wav" );
  340. }
  341. }
  342. function AudioMenuSoundDriver::onSelect( %this, %id, %text )
  343. {
  344. // Skip empty provider selections.
  345. if ( %text $= "" )
  346. return;
  347. $pref::SFX::provider = %text;
  348. AudioMenuSoundDevice.clear();
  349. %buffer = sfxGetAvailableDevices();
  350. %count = getRecordCount( %buffer );
  351. for(%i = 0; %i < %count; %i++)
  352. {
  353. %record = getRecord(%buffer, %i);
  354. %provider = getField(%record, 0);
  355. %device = getField(%record, 1);
  356. if (%provider !$= %text)
  357. continue;
  358. if ( AudioMenuSoundDevice.findText( %device ) == -1 )
  359. AudioMenuSoundDevice.add( %device, %i );
  360. }
  361. // Find the previous selected device.
  362. %selId = AudioMenuSoundDevice.findText($pref::SFX::device);
  363. if ( %selId == -1 )
  364. AudioMenuSoundDevice.setFirstSelected();
  365. else
  366. AudioMenuSoundDevice.setSelected( %selId );
  367. }
  368. function AudioMenuSoundDevice::onSelect( %this, %id, %text )
  369. {
  370. // Skip empty selections.
  371. if ( %text $= "" )
  372. return;
  373. $pref::SFX::device = %text;
  374. if ( !sfxCreateDevice( $pref::SFX::provider,
  375. $pref::SFX::device,
  376. $pref::SFX::useHardware,
  377. -1 ) )
  378. error( "Unable to create SFX device: " @ $pref::SFX::provider
  379. SPC $pref::SFX::device
  380. SPC $pref::SFX::useHardware );
  381. }