MenuScreen_Shell_GameOptions.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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_GAME_OPTIONS_OPTIONS = 8;
  24. const float MIN_FOV = 80.0f;
  25. const float MAX_FOV = 100.0f;
  26. const float MIN_FOV_GUN = 3.0f;
  27. const float MAX_FOV_GUN = 0.0f;
  28. /*
  29. ========================
  30. idMenuScreen_Shell_GameOptions::Initialize
  31. ========================
  32. */
  33. void idMenuScreen_Shell_GameOptions::Initialize( idMenuHandler * data ) {
  34. idMenuScreen::Initialize( data );
  35. if ( data != NULL ) {
  36. menuGUI = data->GetGUI();
  37. }
  38. SetSpritePath( "menuGameOptions" );
  39. options = new (TAG_SWF) idMenuWidget_DynamicList();
  40. options->SetNumVisibleOptions( NUM_GAME_OPTIONS_OPTIONS );
  41. options->SetSpritePath( GetSpritePath(), "info", "options" );
  42. options->SetWrappingAllowed( true );
  43. options->SetControlList( true );
  44. options->Initialize( data );
  45. AddChild( options );
  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( btnBack );
  52. idMenuWidget_ControlButton * control;
  53. control = new (TAG_SWF) idMenuWidget_ControlButton();
  54. control->SetOptionType( OPTION_SLIDER_TEXT );
  55. control->SetLabel( "#str_swf_fov" );
  56. control->SetDataSource( &systemData, idMenuDataSource_GameSettings::GAME_FIELD_FOV );
  57. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  58. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() );
  59. options->AddChild( control );
  60. control = new (TAG_SWF) idMenuWidget_ControlButton();
  61. control->SetOptionType( OPTION_SLIDER_TOGGLE );
  62. control->SetLabel( "#str_swf_checkpoints" );
  63. control->SetDataSource( &systemData, idMenuDataSource_GameSettings::GAME_FIELD_CHECKPOINTS );
  64. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  65. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() );
  66. options->AddChild( control );
  67. control = new (TAG_SWF) idMenuWidget_ControlButton();
  68. control->SetOptionType( OPTION_SLIDER_TOGGLE );
  69. control->SetLabel( "#str_02135" ); // Auto Weapon Switch
  70. control->SetDataSource( &systemData, idMenuDataSource_GameSettings::GAME_FIELD_AUTO_SWITCH );
  71. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  72. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() );
  73. options->AddChild( control );
  74. control = new (TAG_SWF) idMenuWidget_ControlButton();
  75. control->SetOptionType( OPTION_SLIDER_TOGGLE );
  76. control->SetLabel( "#str_02134" ); // Auto Weapon Reload
  77. control->SetDataSource( &systemData, idMenuDataSource_GameSettings::GAME_FIELD_AUTO_RELOAD );
  78. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  79. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() );
  80. options->AddChild( control );
  81. control = new (TAG_SWF) idMenuWidget_ControlButton();
  82. control->SetOptionType( OPTION_SLIDER_TOGGLE );
  83. control->SetLabel( "#str_swf_aim_assist" ); // Aim Assist
  84. control->SetDataSource( &systemData, idMenuDataSource_GameSettings::GAME_FIELD_AIM_ASSIST );
  85. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  86. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() );
  87. options->AddChild( control );
  88. control = new (TAG_SWF) idMenuWidget_ControlButton();
  89. control->SetOptionType( OPTION_SLIDER_TOGGLE );
  90. control->SetLabel( "#str_04102" ); // Always Run
  91. control->SetDataSource( &systemData, idMenuDataSource_GameSettings::GAME_FIELD_ALWAYS_SPRINT );
  92. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  93. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() );
  94. options->AddChild( control );
  95. control = new (TAG_SWF) idMenuWidget_ControlButton();
  96. control->SetOptionType( OPTION_SLIDER_TOGGLE );
  97. control->SetLabel( "#str_swf_flashlight_shadows" );
  98. control->SetDataSource( &systemData, idMenuDataSource_GameSettings::GAME_FIELD_FLASHLIGHT_SHADOWS );
  99. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  100. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() );
  101. options->AddChild( control );
  102. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) );
  103. options->AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) );
  104. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) );
  105. options->AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) );
  106. 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 ) );
  107. 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 ) );
  108. 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 ) );
  109. 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 ) );
  110. }
  111. /*
  112. ========================
  113. idMenuScreen_Shell_GameOptions::Update
  114. ========================
  115. */
  116. void idMenuScreen_Shell_GameOptions::Update() {
  117. if ( menuData != NULL ) {
  118. idMenuWidget_CommandBar * cmdBar = menuData->GetCmdBar();
  119. if ( cmdBar != NULL ) {
  120. cmdBar->ClearAllButtons();
  121. idMenuWidget_CommandBar::buttonInfo_t * buttonInfo;
  122. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 );
  123. if ( menuData->GetPlatform() != 2 ) {
  124. buttonInfo->label = "#str_00395";
  125. }
  126. buttonInfo->action.Set( WIDGET_ACTION_GO_BACK );
  127. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 );
  128. buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED );
  129. }
  130. }
  131. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  132. if ( BindSprite( root ) ) {
  133. idSWFTextInstance * heading = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtHeading" );
  134. if ( heading != NULL ) {
  135. heading->SetText( "#str_02129" ); // SYSTEM SETTINGS
  136. heading->SetStrokeInfo( true, 0.75f, 1.75f );
  137. }
  138. idSWFSpriteInstance * gradient = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "gradient" );
  139. if ( gradient != NULL && heading != NULL ) {
  140. gradient->SetXPos( heading->GetTextLength() );
  141. }
  142. }
  143. if ( btnBack != NULL ) {
  144. btnBack->BindSprite( root );
  145. }
  146. idMenuScreen::Update();
  147. }
  148. /*
  149. ========================
  150. idMenuScreen_Shell_GameOptions::ShowScreen
  151. ========================
  152. */
  153. void idMenuScreen_Shell_GameOptions::ShowScreen( const mainMenuTransition_t transitionType ) {
  154. systemData.LoadData();
  155. idMenuScreen::ShowScreen( transitionType );
  156. }
  157. /*
  158. ========================
  159. idMenuScreen_Shell_GameOptions::HideScreen
  160. ========================
  161. */
  162. void idMenuScreen_Shell_GameOptions::HideScreen( const mainMenuTransition_t transitionType ) {
  163. if ( systemData.IsDataChanged() ) {
  164. systemData.CommitData();
  165. }
  166. idMenuScreen::HideScreen( transitionType );
  167. }
  168. /*
  169. ========================
  170. idMenuScreen_Shell_GameOptions::HandleAction h
  171. ========================
  172. */
  173. bool idMenuScreen_Shell_GameOptions::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) {
  174. if ( menuData == NULL ) {
  175. return true;
  176. }
  177. if ( menuData->ActiveScreen() != SHELL_AREA_GAME_OPTIONS ) {
  178. return false;
  179. }
  180. widgetAction_t actionType = action.GetType();
  181. const idSWFParmList & parms = action.GetParms();
  182. switch ( actionType ) {
  183. case WIDGET_ACTION_GO_BACK: {
  184. menuData->SetNextScreen( SHELL_AREA_SETTINGS, MENU_TRANSITION_SIMPLE );
  185. return true;
  186. }
  187. case WIDGET_ACTION_PRESS_FOCUSED: {
  188. if ( options == NULL ) {
  189. return true;
  190. }
  191. int selectionIndex = options->GetFocusIndex();
  192. if ( parms.Num() > 0 ) {
  193. selectionIndex = parms[0].ToInteger();
  194. }
  195. if ( selectionIndex != options->GetFocusIndex() ) {
  196. options->SetViewIndex( options->GetViewOffset() + selectionIndex );
  197. options->SetFocusIndex( selectionIndex );
  198. }
  199. systemData.AdjustField( selectionIndex, 1 );
  200. options->Update();
  201. return true;
  202. }
  203. case WIDGET_ACTION_START_REPEATER: {
  204. if ( parms.Num() == 4 ) {
  205. int selectionIndex = parms[3].ToInteger();
  206. if ( selectionIndex != options->GetFocusIndex() ) {
  207. options->SetViewIndex( options->GetViewOffset() + selectionIndex );
  208. options->SetFocusIndex( selectionIndex );
  209. }
  210. }
  211. break;
  212. }
  213. }
  214. return idMenuWidget::HandleAction( action, event, widget, forceHandled );
  215. }
  216. /////////////////////////////////
  217. // SCREEN SETTINGS
  218. /////////////////////////////////
  219. extern idCVar ui_autoSwitch;
  220. extern idCVar ui_autoReload;
  221. extern idCVar aa_targetAimAssistEnable;
  222. extern idCVar in_alwaysRun;
  223. extern idCVar g_checkpoints;
  224. extern idCVar g_weaponShadows;
  225. /*
  226. ========================
  227. idMenuScreen_Shell_GameOptions::idMenuDataSource_AudioSettings::idMenuDataSource_AudioSettings
  228. ========================
  229. */
  230. idMenuScreen_Shell_GameOptions::idMenuDataSource_GameSettings::idMenuDataSource_GameSettings() {
  231. fields.SetNum( MAX_GAME_FIELDS );
  232. originalFields.SetNum( MAX_GAME_FIELDS );
  233. }
  234. /*
  235. ========================
  236. idMenuScreen_Shell_GameOptions::idMenuDataSource_AudioSettings::LoadData
  237. ========================
  238. */
  239. void idMenuScreen_Shell_GameOptions::idMenuDataSource_GameSettings::LoadData() {
  240. fields[ GAME_FIELD_FOV ].SetInteger( g_fov.GetFloat() );
  241. fields[ GAME_FIELD_CHECKPOINTS ].SetBool( g_checkpoints.GetBool() );
  242. fields[ GAME_FIELD_AUTO_SWITCH ].SetBool( ui_autoSwitch.GetBool() );
  243. fields[ GAME_FIELD_AUTO_RELOAD ].SetBool( ui_autoReload.GetBool() );
  244. fields[ GAME_FIELD_AIM_ASSIST ].SetBool( aa_targetAimAssistEnable.GetBool() );
  245. fields[ GAME_FIELD_ALWAYS_SPRINT ].SetBool( in_alwaysRun.GetBool() );
  246. fields[ GAME_FIELD_FLASHLIGHT_SHADOWS ].SetBool( g_weaponShadows.GetBool() );
  247. originalFields = fields;
  248. }
  249. /*
  250. ========================
  251. idMenuScreen_Shell_GameOptions::idMenuDataSource_AudioSettings::CommitData
  252. ========================
  253. */
  254. void idMenuScreen_Shell_GameOptions::idMenuDataSource_GameSettings::CommitData() {
  255. g_fov.SetFloat( fields[ GAME_FIELD_FOV ].ToFloat() );
  256. g_gun_x.SetFloat( Lerp( MIN_FOV_GUN, MAX_FOV_GUN, ( fields[ GAME_FIELD_FOV ].ToFloat() - MIN_FOV ) / ( MAX_FOV - MIN_FOV ) ) );
  257. g_checkpoints.SetBool( fields[ GAME_FIELD_CHECKPOINTS ].ToBool() );
  258. ui_autoSwitch.SetBool( fields[ GAME_FIELD_AUTO_SWITCH ].ToBool() );
  259. ui_autoReload.SetBool( fields[ GAME_FIELD_AUTO_RELOAD ].ToBool() );
  260. aa_targetAimAssistEnable.SetBool( fields[ GAME_FIELD_AIM_ASSIST ].ToBool() );
  261. in_alwaysRun.SetBool( fields[ GAME_FIELD_ALWAYS_SPRINT ].ToBool() );
  262. g_weaponShadows.SetBool( fields[ GAME_FIELD_FLASHLIGHT_SHADOWS ].ToBool() );
  263. cvarSystem->SetModifiedFlags( CVAR_ARCHIVE );
  264. // make the committed fields into the backup fields
  265. originalFields = fields;
  266. }
  267. /*
  268. ========================
  269. idMenuScreen_Shell_GameOptions::idMenuDataSource_AudioSettings::AdjustField
  270. ========================
  271. */
  272. void idMenuScreen_Shell_GameOptions::idMenuDataSource_GameSettings::AdjustField( const int fieldIndex, const int adjustAmount ) {
  273. if ( fieldIndex == GAME_FIELD_FOV ) {
  274. fields[ fieldIndex ].SetInteger( idMath::ClampInt( MIN_FOV, MAX_FOV, fields[ fieldIndex ].ToInteger() + adjustAmount * 5 ) );
  275. } else {
  276. fields[ fieldIndex ].SetBool( !fields[ fieldIndex ].ToBool() );
  277. }
  278. }
  279. /*
  280. ========================
  281. idMenuScreen_Shell_GameOptions::idMenuDataSource_AudioSettings::IsDataChanged
  282. ========================
  283. */
  284. bool idMenuScreen_Shell_GameOptions::idMenuDataSource_GameSettings::IsDataChanged() const {
  285. if ( fields[ GAME_FIELD_FOV ].ToInteger() != originalFields[ GAME_FIELD_FOV ].ToInteger() ) {
  286. return true;
  287. }
  288. if ( fields[ GAME_FIELD_CHECKPOINTS ].ToBool() != originalFields[ GAME_FIELD_CHECKPOINTS ].ToBool() ) {
  289. return true;
  290. }
  291. if ( fields[ GAME_FIELD_AUTO_SWITCH ].ToBool() != originalFields[ GAME_FIELD_AUTO_SWITCH ].ToBool() ) {
  292. return true;
  293. }
  294. if ( fields[ GAME_FIELD_AUTO_RELOAD ].ToBool() != originalFields[ GAME_FIELD_AUTO_RELOAD ].ToBool() ) {
  295. return true;
  296. }
  297. if ( fields[ GAME_FIELD_AIM_ASSIST ].ToBool() != originalFields[ GAME_FIELD_AIM_ASSIST ].ToBool() ) {
  298. return true;
  299. }
  300. if ( fields[ GAME_FIELD_ALWAYS_SPRINT ].ToBool() != originalFields[ GAME_FIELD_ALWAYS_SPRINT ].ToBool() ) {
  301. return true;
  302. }
  303. if ( fields[ GAME_FIELD_FLASHLIGHT_SHADOWS ].ToBool() != originalFields[ GAME_FIELD_FLASHLIGHT_SHADOWS ].ToBool() ) {
  304. return true;
  305. }
  306. return false;
  307. }