MenuScreen_Shell_Controls.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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_CONTROLS_OPTIONS = 8;
  24. enum contorlsMenuCmds_t {
  25. CONTROLS_CMD_BINDINGS,
  26. CONTROLS_CMD_GAMEPAD,
  27. CONTROLS_CMD_GAMEPAD_ENABLED,
  28. CONTROLS_CMD_INVERT,
  29. CONTROLS_CMD_MOUSE_SENS
  30. };
  31. /*
  32. ========================
  33. idMenuScreen_Shell_Controls::Initialize
  34. ========================
  35. */
  36. void idMenuScreen_Shell_Controls::Initialize( idMenuHandler * data ) {
  37. idMenuScreen::Initialize( data );
  38. if ( data != NULL ) {
  39. menuGUI = data->GetGUI();
  40. }
  41. SetSpritePath( "menuControls" );
  42. options = new (TAG_SWF) idMenuWidget_DynamicList();
  43. options->SetNumVisibleOptions( NUM_CONTROLS_OPTIONS );
  44. options->SetSpritePath( GetSpritePath(), "info", "options" );
  45. options->SetWrappingAllowed( true );
  46. options->SetControlList( true );
  47. options->Initialize( data );
  48. AddChild( options );
  49. idMenuWidget_Help * const helpWidget = new ( TAG_SWF ) idMenuWidget_Help();
  50. helpWidget->SetSpritePath( GetSpritePath(), "info", "helpTooltip" );
  51. AddChild( helpWidget );
  52. btnBack = new (TAG_SWF) idMenuWidget_Button();
  53. btnBack->Initialize( data );
  54. btnBack->SetLabel( "#str_swf_settings" );
  55. btnBack->SetSpritePath( GetSpritePath(), "info", "btnBack" );
  56. btnBack->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_GO_BACK );
  57. AddChild( btnBack );
  58. idMenuWidget_ControlButton * control;
  59. control = new (TAG_SWF) idMenuWidget_ControlButton();
  60. control->SetOptionType( OPTION_BUTTON_TEXT );
  61. control->SetLabel( "#str_swf_keyboard" ); // KEY BINDINGS
  62. control->SetDescription( "#str_swf_binding_desc" );
  63. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, CONTROLS_CMD_BINDINGS );
  64. control->RegisterEventObserver( helpWidget );
  65. options->AddChild( control );
  66. control = new (TAG_SWF) idMenuWidget_ControlButton();
  67. control->SetOptionType( OPTION_BUTTON_TEXT );
  68. control->SetLabel( "#str_swf_gamepad" ); // Gamepad
  69. control->SetDescription( "#str_swf_gamepad_desc" );
  70. control->RegisterEventObserver( helpWidget );
  71. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, CONTROLS_CMD_GAMEPAD );
  72. options->AddChild( control );
  73. control = new (TAG_SWF) idMenuWidget_ControlButton();
  74. control->SetOptionType( OPTION_SLIDER_TOGGLE );
  75. control->SetLabel( "#str_swf_gamepad_enabled" ); // Gamepad Enabled
  76. control->SetDataSource( &controlData, idMenuDataSource_ControlSettings::CONTROLS_FIELD_GAMEPAD_ENABLED );
  77. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  78. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, CONTROLS_CMD_GAMEPAD_ENABLED );
  79. control->RegisterEventObserver( helpWidget );
  80. options->AddChild( control );
  81. control = new (TAG_SWF) idMenuWidget_ControlButton();
  82. control->SetOptionType( OPTION_SLIDER_TOGGLE );
  83. control->SetLabel( "#str_swf_invert_mouse" ); // Invert Mouse
  84. control->SetDataSource( &controlData, idMenuDataSource_ControlSettings::CONTROLS_FIELD_INVERT_MOUSE );
  85. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  86. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, CONTROLS_CMD_INVERT );
  87. control->RegisterEventObserver( helpWidget );
  88. options->AddChild( control );
  89. control = new (TAG_SWF) idMenuWidget_ControlButton();
  90. control->SetOptionType( OPTION_SLIDER_BAR );
  91. control->SetLabel( "#str_swf_mouse_sens" ); // Mouse Sensitivity
  92. control->SetDataSource( &controlData, idMenuDataSource_ControlSettings::CONTROLS_FIELD_MOUSE_SENS );
  93. control->SetupEvents( 2, options->GetChildren().Num() );
  94. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, CONTROLS_CMD_MOUSE_SENS );
  95. control->RegisterEventObserver( helpWidget );
  96. options->AddChild( control );
  97. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) );
  98. options->AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) );
  99. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) );
  100. options->AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) );
  101. 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 ) );
  102. 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 ) );
  103. 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 ) );
  104. 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 ) );
  105. }
  106. /*
  107. ========================
  108. idMenuScreen_Shell_Controls::Update
  109. ========================
  110. */
  111. void idMenuScreen_Shell_Controls::Update() {
  112. if ( menuData != NULL ) {
  113. idMenuWidget_CommandBar * cmdBar = menuData->GetCmdBar();
  114. if ( cmdBar != NULL ) {
  115. cmdBar->ClearAllButtons();
  116. idMenuWidget_CommandBar::buttonInfo_t * buttonInfo;
  117. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 );
  118. if ( menuData->GetPlatform() != 2 ) {
  119. buttonInfo->label = "#str_00395";
  120. }
  121. buttonInfo->action.Set( WIDGET_ACTION_GO_BACK );
  122. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 );
  123. if ( menuData->GetPlatform() != 2 ) {
  124. buttonInfo->label = "#str_SWF_SELECT";
  125. }
  126. buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED );
  127. }
  128. }
  129. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  130. if ( BindSprite( root ) ) {
  131. idSWFTextInstance * heading = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtHeading" );
  132. if ( heading != NULL ) {
  133. idStr controls( idLocalization::GetString( "#str_04158" ) );
  134. controls.ToUpper();
  135. heading->SetText( controls ); // CONTROLS
  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_Controls::ShowScreen
  151. ========================
  152. */
  153. void idMenuScreen_Shell_Controls::ShowScreen( const mainMenuTransition_t transitionType ) {
  154. controlData.LoadData();
  155. idMenuScreen::ShowScreen( transitionType );
  156. }
  157. /*
  158. ========================
  159. idMenuScreen_Shell_Controls::HideScreen
  160. ========================
  161. */
  162. void idMenuScreen_Shell_Controls::HideScreen( const mainMenuTransition_t transitionType ) {
  163. if ( controlData.IsDataChanged() ) {
  164. controlData.CommitData();
  165. }
  166. if ( menuData != NULL ) {
  167. idMenuHandler_Shell * handler = dynamic_cast< idMenuHandler_Shell * >( menuData );
  168. if ( handler != NULL ) {
  169. handler->SetupPCOptions();
  170. }
  171. }
  172. idMenuScreen::HideScreen( transitionType );
  173. }
  174. /*
  175. ========================
  176. idMenuScreen_Shell_Controls::HandleAction
  177. ========================
  178. */
  179. bool idMenuScreen_Shell_Controls::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) {
  180. if ( menuData == NULL ) {
  181. return true;
  182. }
  183. if ( menuData->ActiveScreen() != SHELL_AREA_CONTROLS ) {
  184. return false;
  185. }
  186. widgetAction_t actionType = action.GetType();
  187. const idSWFParmList & parms = action.GetParms();
  188. switch ( actionType ) {
  189. case WIDGET_ACTION_GO_BACK: {
  190. menuData->SetNextScreen( SHELL_AREA_SETTINGS, MENU_TRANSITION_SIMPLE );
  191. return true;
  192. }
  193. case WIDGET_ACTION_COMMAND: {
  194. if ( options == NULL ) {
  195. return true;
  196. }
  197. int selectionIndex = options->GetFocusIndex();
  198. if ( parms.Num() > 0 ) {
  199. selectionIndex = parms[0].ToInteger();
  200. }
  201. if ( selectionIndex != options->GetFocusIndex() ) {
  202. options->SetViewIndex( options->GetViewOffset() + selectionIndex );
  203. options->SetFocusIndex( selectionIndex );
  204. }
  205. switch ( parms[0].ToInteger() ) {
  206. case CONTROLS_CMD_BINDINGS: {
  207. menuData->SetNextScreen( SHELL_AREA_KEYBOARD, MENU_TRANSITION_SIMPLE );
  208. break;
  209. }
  210. case CONTROLS_CMD_GAMEPAD: {
  211. menuData->SetNextScreen( SHELL_AREA_GAMEPAD, MENU_TRANSITION_SIMPLE );
  212. break;
  213. }
  214. case CONTROLS_CMD_INVERT: {
  215. controlData.AdjustField( idMenuDataSource_ControlSettings::CONTROLS_FIELD_INVERT_MOUSE, 1 );
  216. if ( options != NULL ) {
  217. options->Update();
  218. }
  219. break;
  220. }
  221. case CONTROLS_CMD_MOUSE_SENS: {
  222. controlData.AdjustField( idMenuDataSource_ControlSettings::CONTROLS_FIELD_MOUSE_SENS, 1 );
  223. if ( options != NULL ) {
  224. options->Update();
  225. }
  226. break;
  227. }
  228. case CONTROLS_CMD_GAMEPAD_ENABLED: {
  229. controlData.AdjustField( idMenuDataSource_ControlSettings::CONTROLS_FIELD_GAMEPAD_ENABLED, 1 );
  230. if ( options != NULL ) {
  231. options->Update();
  232. }
  233. break;
  234. }
  235. }
  236. return true;
  237. }
  238. case WIDGET_ACTION_START_REPEATER: {
  239. if ( options == NULL ) {
  240. return true;
  241. }
  242. if ( parms.Num() == 4 ) {
  243. int selectionIndex = parms[3].ToInteger();
  244. if ( selectionIndex != options->GetFocusIndex() ) {
  245. options->SetViewIndex( options->GetViewOffset() + selectionIndex );
  246. options->SetFocusIndex( selectionIndex );
  247. }
  248. }
  249. break;
  250. }
  251. }
  252. return idMenuWidget::HandleAction( action, event, widget, forceHandled );
  253. }
  254. /////////////////////////////////
  255. // SCREEN SETTINGS
  256. /////////////////////////////////
  257. extern idCVar in_mouseInvertLook;
  258. extern idCVar in_mouseSpeed;
  259. extern idCVar in_useJoystick;
  260. /*
  261. ========================
  262. idMenuScreen_Shell_Controls::idMenuDataSource_AudioSettings::idMenuDataSource_AudioSettings
  263. ========================
  264. */
  265. idMenuScreen_Shell_Controls::idMenuDataSource_ControlSettings::idMenuDataSource_ControlSettings() {
  266. fields.SetNum( MAX_CONTROL_FIELDS );
  267. originalFields.SetNum( MAX_CONTROL_FIELDS );
  268. }
  269. /*
  270. ========================
  271. idMenuScreen_Shell_Controls::idMenuDataSource_AudioSettings::LoadData
  272. ========================
  273. */
  274. void idMenuScreen_Shell_Controls::idMenuDataSource_ControlSettings::LoadData() {
  275. fields[ CONTROLS_FIELD_INVERT_MOUSE ].SetBool( in_mouseInvertLook.GetBool() );
  276. float mouseSpeed = ( ( in_mouseSpeed.GetFloat() - 0.25f ) / ( 4.0f - 0.25 ) ) * 100.0f;
  277. fields[ CONTROLS_FIELD_MOUSE_SENS ].SetFloat( mouseSpeed );
  278. fields[ CONTROLS_FIELD_GAMEPAD_ENABLED ].SetBool( in_useJoystick.GetBool() );
  279. originalFields = fields;
  280. }
  281. /*
  282. ========================
  283. idMenuScreen_Shell_Controls::idMenuDataSource_AudioSettings::CommitData
  284. ========================
  285. */
  286. void idMenuScreen_Shell_Controls::idMenuDataSource_ControlSettings::CommitData() {
  287. in_mouseInvertLook.SetBool( fields[ CONTROLS_FIELD_INVERT_MOUSE ].ToBool() );
  288. float mouseSpeed = 0.25f + ( ( 4.0f - 0.25 ) * ( fields[ CONTROLS_FIELD_MOUSE_SENS ].ToFloat() / 100.0f ) );
  289. in_mouseSpeed.SetFloat( mouseSpeed );
  290. in_useJoystick.SetBool( fields[ CONTROLS_FIELD_GAMEPAD_ENABLED ].ToBool() );
  291. cvarSystem->SetModifiedFlags( CVAR_ARCHIVE );
  292. // make the committed fields into the backup fields
  293. originalFields = fields;
  294. }
  295. /*
  296. ========================
  297. idMenuScreen_Shell_Controls::idMenuDataSource_AudioSettings::AdjustField
  298. ========================
  299. */
  300. void idMenuScreen_Shell_Controls::idMenuDataSource_ControlSettings::AdjustField( const int fieldIndex, const int adjustAmount ) {
  301. if ( fieldIndex == CONTROLS_FIELD_INVERT_MOUSE || fieldIndex == CONTROLS_FIELD_GAMEPAD_ENABLED ) {
  302. fields[ fieldIndex ].SetBool( !fields[ fieldIndex ].ToBool() );
  303. } else if ( fieldIndex == CONTROLS_FIELD_MOUSE_SENS ) {
  304. float newValue = idMath::ClampFloat( 0.0f, 100.0f, fields[ fieldIndex ].ToFloat() + adjustAmount );
  305. fields[ fieldIndex ].SetFloat( newValue );
  306. }
  307. }
  308. /*
  309. ========================
  310. idMenuScreen_Shell_Controls::idMenuDataSource_AudioSettings::IsDataChanged
  311. ========================
  312. */
  313. bool idMenuScreen_Shell_Controls::idMenuDataSource_ControlSettings::IsDataChanged() const {
  314. if ( fields[ CONTROLS_FIELD_INVERT_MOUSE ].ToBool() != originalFields[ CONTROLS_FIELD_INVERT_MOUSE ].ToBool() ) {
  315. return true;
  316. }
  317. if ( fields[ CONTROLS_FIELD_MOUSE_SENS ].ToFloat() != originalFields[ CONTROLS_FIELD_MOUSE_SENS ].ToFloat() ) {
  318. return true;
  319. }
  320. if ( fields[ CONTROLS_FIELD_GAMEPAD_ENABLED ].ToFloat() != originalFields[ CONTROLS_FIELD_GAMEPAD_ENABLED ].ToFloat() ) {
  321. return true;
  322. }
  323. return false;
  324. }