MenuScreen_Shell_SystemOptions.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #pragma hdrstop
  21. #include "../../idLib/precompiled.h"
  22. #include "../Game_local.h"
  23. const static int NUM_SYSTEM_OPTIONS_OPTIONS = 8;
  24. extern idCVar r_multiSamples;
  25. extern idCVar r_motionBlur;
  26. extern idCVar r_swapInterval;
  27. extern idCVar s_volume_dB;
  28. extern idCVar r_lightScale;
  29. /*
  30. ========================
  31. idMenuScreen_Shell_SystemOptions::Initialize
  32. ========================
  33. */
  34. void idMenuScreen_Shell_SystemOptions::Initialize( idMenuHandler * data ) {
  35. idMenuScreen::Initialize( data );
  36. if ( data != NULL ) {
  37. menuGUI = data->GetGUI();
  38. }
  39. SetSpritePath( "menuSystemOptions" );
  40. options = new (TAG_SWF) idMenuWidget_DynamicList();
  41. options->SetNumVisibleOptions( NUM_SYSTEM_OPTIONS_OPTIONS );
  42. options->SetSpritePath( GetSpritePath(), "info", "options" );
  43. options->SetWrappingAllowed( true );
  44. options->SetControlList( true );
  45. options->Initialize( data );
  46. btnBack = new (TAG_SWF) idMenuWidget_Button();
  47. btnBack->Initialize( data );
  48. btnBack->SetLabel( "#str_swf_settings" );
  49. btnBack->SetSpritePath( GetSpritePath(), "info", "btnBack" );
  50. btnBack->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_GO_BACK );
  51. AddChild( options );
  52. AddChild( btnBack );
  53. idMenuWidget_ControlButton * control;
  54. control = new (TAG_SWF) idMenuWidget_ControlButton();
  55. control->SetOptionType( OPTION_SLIDER_TEXT );
  56. control->SetLabel( "#str_02154" );
  57. control->SetDataSource( &systemData, idMenuDataSource_SystemSettings::SYSTEM_FIELD_FULLSCREEN );
  58. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  59. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, idMenuDataSource_SystemSettings::SYSTEM_FIELD_FULLSCREEN );
  60. options->AddChild( control );
  61. control = new (TAG_SWF) idMenuWidget_ControlButton();
  62. control->SetOptionType( OPTION_SLIDER_TEXT );
  63. control->SetLabel( "#str_swf_framerate" );
  64. control->SetDataSource( &systemData, idMenuDataSource_SystemSettings::SYSTEM_FIELD_FRAMERATE );
  65. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  66. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, idMenuDataSource_SystemSettings::SYSTEM_FIELD_FRAMERATE );
  67. options->AddChild( control );
  68. control = new (TAG_SWF) idMenuWidget_ControlButton();
  69. control->SetOptionType( OPTION_SLIDER_TEXT );
  70. control->SetLabel( "#str_04126" );
  71. control->SetDataSource( &systemData, idMenuDataSource_SystemSettings::SYSTEM_FIELD_VSYNC );
  72. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  73. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, idMenuDataSource_SystemSettings::SYSTEM_FIELD_VSYNC );
  74. options->AddChild( control );
  75. control = new (TAG_SWF) idMenuWidget_ControlButton();
  76. control->SetOptionType( OPTION_SLIDER_TEXT );
  77. control->SetLabel( "#str_04128" );
  78. control->SetDataSource( &systemData, idMenuDataSource_SystemSettings::SYSTEM_FIELD_ANTIALIASING );
  79. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  80. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, idMenuDataSource_SystemSettings::SYSTEM_FIELD_ANTIALIASING );
  81. options->AddChild( control );
  82. control = new (TAG_SWF) idMenuWidget_ControlButton();
  83. control->SetOptionType( OPTION_SLIDER_TEXT );
  84. control->SetLabel( "#str_swf_motionblur" );
  85. control->SetDataSource( &systemData, idMenuDataSource_SystemSettings::SYSTEM_FIELD_MOTIONBLUR );
  86. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  87. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, idMenuDataSource_SystemSettings::SYSTEM_FIELD_MOTIONBLUR );
  88. options->AddChild( control );
  89. control = new (TAG_SWF) idMenuWidget_ControlButton();
  90. control->SetOptionType( OPTION_SLIDER_BAR );
  91. control->SetLabel( "#str_swf_lodbias" );
  92. control->SetDataSource( &systemData, idMenuDataSource_SystemSettings::SYSTEM_FIELD_LODBIAS );
  93. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  94. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, idMenuDataSource_SystemSettings::SYSTEM_FIELD_LODBIAS );
  95. options->AddChild( control );
  96. control = new (TAG_SWF) idMenuWidget_ControlButton();
  97. control->SetOptionType( OPTION_SLIDER_BAR );
  98. control->SetLabel( "#str_02155" ); // Brightness
  99. control->SetDataSource( &systemData, idMenuDataSource_SystemSettings::SYSTEM_FIELD_BRIGHTNESS );
  100. control->SetupEvents( 2, options->GetChildren().Num() );
  101. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, idMenuDataSource_SystemSettings::SYSTEM_FIELD_BRIGHTNESS );
  102. options->AddChild( control );
  103. control = new (TAG_SWF) idMenuWidget_ControlButton();
  104. control->SetOptionType( OPTION_SLIDER_BAR );
  105. control->SetLabel( "#str_02163" ); // Volume
  106. control->SetDataSource( &systemData, idMenuDataSource_SystemSettings::SYSTEM_FIELD_VOLUME );
  107. control->SetupEvents( 2, options->GetChildren().Num() );
  108. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, idMenuDataSource_SystemSettings::SYSTEM_FIELD_VOLUME );
  109. options->AddChild( control );
  110. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) );
  111. options->AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) );
  112. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) );
  113. options->AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) );
  114. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN_LSTICK ) );
  115. options->AddEventAction( WIDGET_EVENT_SCROLL_UP_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP_LSTICK ) );
  116. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_LSTICK_RELEASE ) );
  117. options->AddEventAction( WIDGET_EVENT_SCROLL_UP_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_LSTICK_RELEASE ) );
  118. }
  119. /*
  120. ========================
  121. idMenuScreen_Shell_SystemOptions::Update
  122. ========================
  123. */
  124. void idMenuScreen_Shell_SystemOptions::Update() {
  125. if ( menuData != NULL ) {
  126. idMenuWidget_CommandBar * cmdBar = menuData->GetCmdBar();
  127. if ( cmdBar != NULL ) {
  128. cmdBar->ClearAllButtons();
  129. idMenuWidget_CommandBar::buttonInfo_t * buttonInfo;
  130. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 );
  131. if ( menuData->GetPlatform() != 2 ) {
  132. buttonInfo->label = "#str_00395";
  133. }
  134. buttonInfo->action.Set( WIDGET_ACTION_GO_BACK );
  135. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 );
  136. buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED );
  137. }
  138. }
  139. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  140. if ( BindSprite( root ) ) {
  141. idSWFTextInstance * heading = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtHeading" );
  142. if ( heading != NULL ) {
  143. heading->SetText( "#str_00183" ); // FULLSCREEN
  144. heading->SetStrokeInfo( true, 0.75f, 1.75f );
  145. }
  146. idSWFSpriteInstance * gradient = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "gradient" );
  147. if ( gradient != NULL && heading != NULL ) {
  148. gradient->SetXPos( heading->GetTextLength() );
  149. }
  150. }
  151. if ( btnBack != NULL ) {
  152. btnBack->BindSprite( root );
  153. }
  154. idMenuScreen::Update();
  155. }
  156. /*
  157. ========================
  158. idMenuScreen_Shell_SystemOptions::ShowScreen
  159. ========================
  160. */
  161. void idMenuScreen_Shell_SystemOptions::ShowScreen( const mainMenuTransition_t transitionType ) {
  162. systemData.LoadData();
  163. idMenuScreen::ShowScreen( transitionType );
  164. }
  165. /*
  166. ========================
  167. idMenuScreen_Shell_SystemOptions::HideScreen
  168. ========================
  169. */
  170. void idMenuScreen_Shell_SystemOptions::HideScreen( const mainMenuTransition_t transitionType ) {
  171. if ( systemData.IsRestartRequired() ) {
  172. class idSWFScriptFunction_Restart : public idSWFScriptFunction_RefCounted {
  173. public:
  174. idSWFScriptFunction_Restart( gameDialogMessages_t _msg, bool _restart ) {
  175. msg = _msg;
  176. restart = _restart;
  177. }
  178. idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  179. common->Dialog().ClearDialog( msg );
  180. if ( restart ) {
  181. idStr cmdLine = Sys_GetCmdLine();
  182. if ( cmdLine.Find( "com_skipIntroVideos" ) < 0 ) {
  183. cmdLine.Append( " +set com_skipIntroVideos 1" );
  184. }
  185. Sys_ReLaunch( (void*)cmdLine.c_str(), cmdLine.Length() );
  186. }
  187. return idSWFScriptVar();
  188. }
  189. private:
  190. gameDialogMessages_t msg;
  191. bool restart;
  192. };
  193. idStaticList<idSWFScriptFunction *, 4> callbacks;
  194. idStaticList<idStrId, 4> optionText;
  195. callbacks.Append( new idSWFScriptFunction_Restart( GDM_GAME_RESTART_REQUIRED, false ) );
  196. callbacks.Append( new idSWFScriptFunction_Restart( GDM_GAME_RESTART_REQUIRED, true ) );
  197. optionText.Append( idStrId( "#str_00100113" ) ); // Continue
  198. optionText.Append( idStrId( "#str_02487" ) ); // Restart Now
  199. common->Dialog().AddDynamicDialog( GDM_GAME_RESTART_REQUIRED, callbacks, optionText, true, idStr() );
  200. }
  201. if ( systemData.IsDataChanged() ) {
  202. systemData.CommitData();
  203. }
  204. idMenuScreen::HideScreen( transitionType );
  205. }
  206. /*
  207. ========================
  208. idMenuScreen_Shell_SystemOptions::HandleAction h
  209. ========================
  210. */
  211. bool idMenuScreen_Shell_SystemOptions::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) {
  212. if ( menuData == NULL ) {
  213. return true;
  214. }
  215. if ( menuData->ActiveScreen() != SHELL_AREA_SYSTEM_OPTIONS ) {
  216. return false;
  217. }
  218. widgetAction_t actionType = action.GetType();
  219. const idSWFParmList & parms = action.GetParms();
  220. switch ( actionType ) {
  221. case WIDGET_ACTION_GO_BACK: {
  222. if ( menuData != NULL ) {
  223. menuData->SetNextScreen( SHELL_AREA_SETTINGS, MENU_TRANSITION_SIMPLE );
  224. }
  225. return true;
  226. }
  227. case WIDGET_ACTION_ADJUST_FIELD:
  228. if ( widget->GetDataSourceFieldIndex() == idMenuDataSource_SystemSettings::SYSTEM_FIELD_FULLSCREEN ) {
  229. menuData->SetNextScreen( SHELL_AREA_RESOLUTION, MENU_TRANSITION_SIMPLE );
  230. return true;
  231. }
  232. break;
  233. case WIDGET_ACTION_COMMAND: {
  234. if ( options == NULL ) {
  235. return true;
  236. }
  237. int selectionIndex = options->GetFocusIndex();
  238. if ( parms.Num() > 0 ) {
  239. selectionIndex = parms[0].ToInteger();
  240. }
  241. if ( options && selectionIndex != options->GetFocusIndex() ) {
  242. options->SetViewIndex( options->GetViewOffset() + selectionIndex );
  243. options->SetFocusIndex( selectionIndex );
  244. }
  245. switch ( parms[0].ToInteger() ) {
  246. case idMenuDataSource_SystemSettings::SYSTEM_FIELD_FULLSCREEN: {
  247. menuData->SetNextScreen( SHELL_AREA_RESOLUTION, MENU_TRANSITION_SIMPLE );
  248. return true;
  249. }
  250. default: {
  251. systemData.AdjustField( parms[0].ToInteger(), 1 );
  252. options->Update();
  253. }
  254. }
  255. return true;
  256. }
  257. case WIDGET_ACTION_START_REPEATER: {
  258. if ( options == NULL ) {
  259. return true;
  260. }
  261. if ( parms.Num() == 4 ) {
  262. int selectionIndex = parms[3].ToInteger();
  263. if ( selectionIndex != options->GetFocusIndex() ) {
  264. options->SetViewIndex( options->GetViewOffset() + selectionIndex );
  265. options->SetFocusIndex( selectionIndex );
  266. }
  267. }
  268. break;
  269. }
  270. }
  271. return idMenuWidget::HandleAction( action, event, widget, forceHandled );
  272. }
  273. /////////////////////////////////
  274. // SCREEN SETTINGS
  275. /////////////////////////////////
  276. /*
  277. ========================
  278. idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings::idMenuDataSource_SystemSettings
  279. ========================
  280. */
  281. idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings::idMenuDataSource_SystemSettings() {
  282. }
  283. /*
  284. ========================
  285. idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings::LoadData
  286. ========================
  287. */
  288. void idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings::LoadData() {
  289. originalFramerate = com_engineHz.GetInteger();
  290. originalAntialias = r_multiSamples.GetInteger();
  291. originalMotionBlur = r_motionBlur.GetInteger();
  292. originalVsync = r_swapInterval.GetInteger();
  293. originalBrightness = r_lightScale.GetFloat();
  294. originalVolume = s_volume_dB.GetFloat();
  295. const int fullscreen = r_fullscreen.GetInteger();
  296. if ( fullscreen > 0 ) {
  297. R_GetModeListForDisplay( fullscreen - 1, modeList );
  298. } else {
  299. modeList.Clear();
  300. }
  301. }
  302. /*
  303. ========================
  304. idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings::IsRestartRequired
  305. ========================
  306. */
  307. bool idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings::IsRestartRequired() const {
  308. if ( originalAntialias != r_multiSamples.GetInteger() ) {
  309. return true;
  310. }
  311. if ( originalFramerate != com_engineHz.GetInteger() ) {
  312. return true;
  313. }
  314. return false;
  315. }
  316. /*
  317. ========================
  318. idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings::CommitData
  319. ========================
  320. */
  321. void idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings::CommitData() {
  322. cvarSystem->SetModifiedFlags( CVAR_ARCHIVE );
  323. }
  324. /*
  325. ========================
  326. AdjustOption
  327. Given a current value in an array of possible values, returns the next n value
  328. ========================
  329. */
  330. int AdjustOption( int currentValue, const int values[], int numValues, int adjustment ) {
  331. int index = 0;
  332. for ( int i = 0; i < numValues; i++ ) {
  333. if ( currentValue == values[i] ) {
  334. index = i;
  335. break;
  336. }
  337. }
  338. index += adjustment;
  339. while ( index < 0 ) {
  340. index += numValues;
  341. }
  342. index %= numValues;
  343. return values[index];
  344. }
  345. /*
  346. ========================
  347. LinearAdjust
  348. Linearly converts a float from one scale to another
  349. ========================
  350. */
  351. float LinearAdjust( float input, float currentMin, float currentMax, float desiredMin, float desiredMax ) {
  352. return ( ( input - currentMin ) / ( currentMax - currentMin ) ) * ( desiredMax - desiredMin ) + desiredMin;
  353. }
  354. /*
  355. ========================
  356. idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings::AdjustField
  357. ========================
  358. */
  359. void idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings::AdjustField( const int fieldIndex, const int adjustAmount ) {
  360. switch ( fieldIndex ) {
  361. case SYSTEM_FIELD_FRAMERATE: {
  362. static const int numValues = 2;
  363. static const int values[numValues] = { 60, 120 };
  364. com_engineHz.SetInteger( AdjustOption( com_engineHz.GetInteger(), values, numValues, adjustAmount ) );
  365. break;
  366. }
  367. case SYSTEM_FIELD_VSYNC: {
  368. static const int numValues = 3;
  369. static const int values[numValues] = { 0, 1, 2 };
  370. r_swapInterval.SetInteger( AdjustOption( r_swapInterval.GetInteger(), values, numValues, adjustAmount ) );
  371. break;
  372. }
  373. case SYSTEM_FIELD_ANTIALIASING: {
  374. static const int numValues = 5;
  375. static const int values[numValues] = { 0, 2, 4, 8, 16 };
  376. r_multiSamples.SetInteger( AdjustOption( r_multiSamples.GetInteger(), values, numValues, adjustAmount ) );
  377. break;
  378. }
  379. case SYSTEM_FIELD_MOTIONBLUR: {
  380. static const int numValues = 5;
  381. static const int values[numValues] = { 0, 2, 3, 4, 5 };
  382. r_motionBlur.SetInteger( AdjustOption( r_motionBlur.GetInteger(), values, numValues, adjustAmount ) );
  383. break;
  384. }
  385. case SYSTEM_FIELD_LODBIAS: {
  386. const float percent = LinearAdjust( r_lodBias.GetFloat(), -1.0f, 1.0f, 0.0f, 100.0f );
  387. const float adjusted = percent + (float)adjustAmount * 5.0f;
  388. const float clamped = idMath::ClampFloat( 0.0f, 100.0f, adjusted );
  389. r_lodBias.SetFloat( LinearAdjust( clamped, 0.0f, 100.0f, -1.0f, 1.0f ) );
  390. break;
  391. }
  392. case SYSTEM_FIELD_BRIGHTNESS: {
  393. const float percent = LinearAdjust( r_lightScale.GetFloat(), 2.0f, 4.0f, 0.0f, 100.0f );
  394. const float adjusted = percent + (float)adjustAmount;
  395. const float clamped = idMath::ClampFloat( 0.0f, 100.0f, adjusted );
  396. r_lightScale.SetFloat( LinearAdjust( clamped, 0.0f, 100.0f, 2.0f, 4.0f ) );
  397. break;
  398. }
  399. case SYSTEM_FIELD_VOLUME: {
  400. const float percent = 100.0f * Square( 1.0f - ( s_volume_dB.GetFloat() / DB_SILENCE ) );
  401. const float adjusted = percent + (float)adjustAmount;
  402. const float clamped = idMath::ClampFloat( 0.0f, 100.0f, adjusted );
  403. s_volume_dB.SetFloat( DB_SILENCE - ( idMath::Sqrt( clamped / 100.0f ) * DB_SILENCE ) );
  404. break;
  405. }
  406. }
  407. cvarSystem->ClearModifiedFlags( CVAR_ARCHIVE );
  408. }
  409. /*
  410. ========================
  411. idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings::GetField
  412. ========================
  413. */
  414. idSWFScriptVar idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings::GetField( const int fieldIndex ) const {
  415. switch ( fieldIndex ) {
  416. case SYSTEM_FIELD_FULLSCREEN: {
  417. const int fullscreen = r_fullscreen.GetInteger();
  418. const int vidmode = r_vidMode.GetInteger();
  419. if ( fullscreen == 0 ) {
  420. return "#str_swf_disabled";
  421. }
  422. if ( fullscreen < 0 || vidmode < 0 || vidmode >= modeList.Num() ) {
  423. return "???";
  424. }
  425. if ( modeList[vidmode].displayHz == 60 ) {
  426. return va( "%4i x %4i", modeList[vidmode].width, modeList[vidmode].height );
  427. } else {
  428. return va( "%4i x %4i @ %dhz", modeList[vidmode].width, modeList[vidmode].height, modeList[vidmode].displayHz );
  429. }
  430. }
  431. case SYSTEM_FIELD_FRAMERATE:
  432. return va( "%d FPS", com_engineHz.GetInteger() );
  433. case SYSTEM_FIELD_VSYNC:
  434. if ( r_swapInterval.GetInteger() == 1 ) {
  435. return "#str_swf_smart";
  436. } else if ( r_swapInterval.GetInteger() == 2 ) {
  437. return "#str_swf_enabled";
  438. } else {
  439. return "#str_swf_disabled";
  440. }
  441. case SYSTEM_FIELD_ANTIALIASING:
  442. if ( r_multiSamples.GetInteger() == 0 ) {
  443. return "#str_swf_disabled";
  444. }
  445. return va( "%dx", r_multiSamples.GetInteger() );
  446. case SYSTEM_FIELD_MOTIONBLUR:
  447. if ( r_motionBlur.GetInteger() == 0 ) {
  448. return "#str_swf_disabled";
  449. }
  450. return va( "%dx", idMath::IPow( 2, r_motionBlur.GetInteger() ) );
  451. case SYSTEM_FIELD_LODBIAS:
  452. return LinearAdjust( r_lodBias.GetFloat(), -1.0f, 1.0f, 0.0f, 100.0f );
  453. case SYSTEM_FIELD_BRIGHTNESS:
  454. return LinearAdjust( r_lightScale.GetFloat(), 2.0f, 4.0f, 0.0f, 100.0f );
  455. case SYSTEM_FIELD_VOLUME: {
  456. return 100.0f * Square( 1.0f - ( s_volume_dB.GetFloat() / DB_SILENCE ) );
  457. }
  458. }
  459. return false;
  460. }
  461. /*
  462. ========================
  463. idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings::IsDataChanged
  464. ========================
  465. */
  466. bool idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings::IsDataChanged() const {
  467. if ( originalFramerate != com_engineHz.GetInteger() ) {
  468. return true;
  469. }
  470. if ( originalAntialias != r_multiSamples.GetInteger() ) {
  471. return true;
  472. }
  473. if ( originalMotionBlur != r_motionBlur.GetInteger() ) {
  474. return true;
  475. }
  476. if ( originalVsync != r_swapInterval.GetInteger() ) {
  477. return true;
  478. }
  479. if ( originalBrightness != r_lightScale.GetFloat() ) {
  480. return true;
  481. }
  482. if ( originalVolume != s_volume_dB.GetFloat() ) {
  483. return true;
  484. }
  485. return false;
  486. }