MenuScreen_Shell_ControllerLayout.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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_LAYOUT_OPTIONS = 1;
  24. const static int MAX_CONTROLLER_CONFIGS = 2;
  25. typedef struct {
  26. const char * textField;
  27. int keyNum;
  28. } gamepadBindInfo_t;
  29. static gamepadBindInfo_t gamepadBinds[] = {
  30. { "txtJoy1", K_JOY1 },
  31. { "txtJoy2", K_JOY2 },
  32. { "txtJoy3", K_JOY3 },
  33. { "txtJoy4", K_JOY4 },
  34. { "txtDpad", K_JOY_DPAD_UP },
  35. { "txtStart", K_JOY9 },
  36. { "txtBack", K_JOY10 },
  37. { "txtLClick", K_JOY7 },
  38. { "txtRClick", K_JOY8 },
  39. { "txtLBumper", K_JOY5 },
  40. { "txtRBumper", K_JOY6 },
  41. { "txtLStick", K_JOY_STICK1_UP },
  42. { "txtRStick", K_JOY_STICK2_UP },
  43. { "txtLTrigger", K_JOY_TRIGGER1 },
  44. { "txtRTrigger", K_JOY_TRIGGER2 }
  45. };
  46. static const int numGamepadBinds = sizeof( gamepadBinds ) / sizeof( gamepadBinds[0] );
  47. /*
  48. ========================
  49. idMenuScreen_Shell_ControllerLayout::Initialize
  50. ========================
  51. */
  52. void idMenuScreen_Shell_ControllerLayout::Initialize( idMenuHandler * data ) {
  53. idMenuScreen::Initialize( data );
  54. if ( data != NULL ) {
  55. menuGUI = data->GetGUI();
  56. }
  57. SetSpritePath( "menuControllerLayout" );
  58. options = new (TAG_SWF) idMenuWidget_DynamicList();
  59. options->SetNumVisibleOptions( NUM_LAYOUT_OPTIONS );
  60. options->SetSpritePath( GetSpritePath(), "info", "controlInfo", "options" );
  61. options->SetWrappingAllowed( true );
  62. options->SetControlList( true );
  63. options->Initialize( data );
  64. AddChild( options );
  65. btnBack = new (TAG_SWF) idMenuWidget_Button();
  66. btnBack->Initialize( data );
  67. btnBack->SetLabel( "#str_swf_gamepad_heading" ); // CONTROLS
  68. btnBack->SetSpritePath( GetSpritePath(), "info", "btnBack" );
  69. btnBack->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_GO_BACK );
  70. AddChild( btnBack );
  71. idMenuWidget_ControlButton * control = new (TAG_SWF) idMenuWidget_ControlButton();
  72. control->SetOptionType( OPTION_BUTTON_FULL_TEXT_SLIDER );
  73. control->SetLabel( "CONTROL LAYOUT" ); // Auto Weapon Reload
  74. control->SetDataSource( &layoutData, idMenuDataSource_LayoutSettings::LAYOUT_FIELD_LAYOUT );
  75. control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() );
  76. control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() );
  77. options->AddChild( control );
  78. }
  79. /*
  80. ========================
  81. idMenuScreen_Shell_ControllerLayout::Update
  82. ========================
  83. */
  84. void idMenuScreen_Shell_ControllerLayout::Update() {
  85. if ( menuData != NULL ) {
  86. idMenuWidget_CommandBar * cmdBar = menuData->GetCmdBar();
  87. if ( cmdBar != NULL ) {
  88. cmdBar->ClearAllButtons();
  89. idMenuWidget_CommandBar::buttonInfo_t * buttonInfo;
  90. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 );
  91. if ( menuData->GetPlatform() != 2 ) {
  92. buttonInfo->label = "#str_00395";
  93. }
  94. buttonInfo->action.Set( WIDGET_ACTION_GO_BACK );
  95. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 );
  96. buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED );
  97. }
  98. }
  99. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  100. if ( BindSprite( root ) ) {
  101. idSWFTextInstance * heading = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtHeading" );
  102. if ( heading != NULL ) {
  103. heading->SetText( "#str_swf_controller_layout" ); // CONTROLLER LAYOUT
  104. heading->SetStrokeInfo( true, 0.75f, 1.75f );
  105. }
  106. idSWFSpriteInstance * gradient = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "gradient" );
  107. if ( gradient != NULL && heading != NULL ) {
  108. gradient->SetXPos( heading->GetTextLength() );
  109. }
  110. if ( menuData != NULL ) {
  111. idSWFSpriteInstance * layout = NULL;
  112. layout = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "controlInfo", "layout360" );
  113. if ( layout != NULL ) {
  114. if ( menuData->GetPlatform( true ) == 2 ) {
  115. layout->StopFrame( 1 );
  116. } else {
  117. layout->StopFrame( menuData->GetPlatform( true ) + 1 );
  118. }
  119. }
  120. }
  121. }
  122. if ( btnBack != NULL ) {
  123. btnBack->BindSprite( root );
  124. }
  125. idMenuScreen::Update();
  126. }
  127. /*
  128. ========================
  129. idMenuScreen_Shell_ControllerLayout::ShowScreen
  130. ========================
  131. */
  132. void idMenuScreen_Shell_ControllerLayout::ShowScreen( const mainMenuTransition_t transitionType ) {
  133. layoutData.LoadData();
  134. idMenuScreen::ShowScreen( transitionType );
  135. if ( GetSprite() != NULL ) {
  136. idSWFSpriteInstance * layout360 = NULL;
  137. idSWFSpriteInstance * layoutPS3 = NULL;
  138. layout360 = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "controlInfo", "layout360" );
  139. layoutPS3 = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "controlInfo", "layoutPS3" );
  140. if ( layout360 != NULL && layoutPS3 != NULL ) {
  141. layout360->SetVisible( true );
  142. layoutPS3->SetVisible( false );
  143. }
  144. }
  145. UpdateBindingInfo();
  146. }
  147. /*
  148. ========================
  149. idMenuScreen_Shell_ControllerLayout::HideScreen
  150. ========================
  151. */
  152. void idMenuScreen_Shell_ControllerLayout::HideScreen( const mainMenuTransition_t transitionType ) {
  153. layoutData.CommitData();
  154. idMenuScreen::HideScreen( transitionType );
  155. }
  156. /*
  157. ========================
  158. idMenuScreen_Shell_ControllerLayout::UpdateBindingInfo
  159. ========================
  160. */
  161. void idMenuScreen_Shell_ControllerLayout::UpdateBindingInfo() {
  162. if ( !GetSprite() ) {
  163. return;
  164. }
  165. for ( int i = 0; i < numGamepadBinds; ++i ) {
  166. const char * txtField = gamepadBinds[i].textField;
  167. int keyNum = gamepadBinds[i].keyNum;
  168. idSWFTextInstance * txtVal = NULL;
  169. txtVal = GetSprite()->GetScriptObject()->GetNestedText( "info", "controlInfo", "layout360", txtField );
  170. if ( txtVal != NULL ) {
  171. const char * binding = idKeyInput::GetBinding( keyNum );
  172. if ( binding == NULL || binding[0] == 0 ) {
  173. txtVal->SetText( "" );
  174. } else if ( keyNum == K_JOY7 ) {
  175. idStr action = idLocalization::GetString( va( "#str_swf_action%s", binding ) );
  176. txtVal->SetText( action.c_str() );
  177. } else if ( keyNum == K_JOY8 ) {
  178. idStr action = idLocalization::GetString( va( "#str_swf_action%s", binding ) );
  179. txtVal->SetText( action.c_str() );
  180. } else {
  181. txtVal->SetText( va( "#str_swf_action%s", binding ) );
  182. }
  183. }
  184. }
  185. }
  186. /*
  187. ========================
  188. idMenuScreen_Shell_ControllerLayout::HandleAction h
  189. ========================
  190. */
  191. bool idMenuScreen_Shell_ControllerLayout::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) {
  192. if ( menuData == NULL ) {
  193. return true;
  194. }
  195. if ( menuData->ActiveScreen() != SHELL_AREA_CONTROLLER_LAYOUT ) {
  196. return false;
  197. }
  198. widgetAction_t actionType = action.GetType();
  199. const idSWFParmList & parms = action.GetParms();
  200. switch ( actionType ) {
  201. case WIDGET_ACTION_GO_BACK: {
  202. menuData->SetNextScreen( SHELL_AREA_GAMEPAD, MENU_TRANSITION_SIMPLE );
  203. return true;
  204. }
  205. case WIDGET_ACTION_PRESS_FOCUSED: {
  206. if ( parms.Num() != 1 ) {
  207. return true;
  208. }
  209. if ( options == NULL ) {
  210. return true;
  211. }
  212. int selectionIndex = parms[0].ToInteger();
  213. if ( selectionIndex != options->GetFocusIndex() ) {
  214. options->SetViewIndex( options->GetViewOffset() + selectionIndex );
  215. options->SetFocusIndex( selectionIndex );
  216. }
  217. layoutData.AdjustField( selectionIndex, 1 );
  218. options->Update();
  219. UpdateBindingInfo();
  220. return true;
  221. }
  222. case WIDGET_ACTION_START_REPEATER: {
  223. if ( options == NULL ) {
  224. return true;
  225. }
  226. if ( parms.Num() == 4 ) {
  227. int selectionIndex = parms[3].ToInteger();
  228. if ( selectionIndex != options->GetFocusIndex() ) {
  229. options->SetViewIndex( options->GetViewOffset() + selectionIndex );
  230. options->SetFocusIndex( selectionIndex );
  231. }
  232. }
  233. break;
  234. }
  235. case WIDGET_ACTION_ADJUST_FIELD: {
  236. if ( widget != NULL && widget->GetDataSource() != NULL ) {
  237. widget->GetDataSource()->AdjustField( widget->GetDataSourceFieldIndex(), parms[ 0 ].ToInteger() );
  238. widget->Update();
  239. }
  240. UpdateBindingInfo();
  241. return true;
  242. }
  243. }
  244. return idMenuWidget::HandleAction( action, event, widget, forceHandled );
  245. }
  246. /*
  247. ========================
  248. idMenuScreen_Shell_ControllerLayout::idMenuDataSource_AudioSettings::idMenuDataSource_AudioSettings
  249. ========================
  250. */
  251. idMenuScreen_Shell_ControllerLayout::idMenuDataSource_LayoutSettings::idMenuDataSource_LayoutSettings() {
  252. fields.SetNum( MAX_LAYOUT_FIELDS );
  253. originalFields.SetNum( MAX_LAYOUT_FIELDS );
  254. }
  255. /*
  256. ========================
  257. idMenuScreen_Shell_ControllerLayout::idMenuDataSource_AudioSettings::LoadData
  258. ========================
  259. */
  260. void idMenuScreen_Shell_ControllerLayout::idMenuDataSource_LayoutSettings::LoadData() {
  261. idPlayerProfile * profile = session->GetProfileFromMasterLocalUser();
  262. if ( profile == NULL ) {
  263. return;
  264. }
  265. int configSet = profile->GetConfig();
  266. fields[ LAYOUT_FIELD_LAYOUT ].SetString( idLocalization::GetString( va( "#str_swf_config_360_%i", configSet ) ) );
  267. originalFields = fields;
  268. }
  269. /*
  270. ========================
  271. idMenuScreen_Shell_ControllerLayout::idMenuDataSource_AudioSettings::CommitData
  272. ========================
  273. */
  274. void idMenuScreen_Shell_ControllerLayout::idMenuDataSource_LayoutSettings::CommitData() {
  275. if ( IsDataChanged() ) {
  276. cvarSystem->SetModifiedFlags( CVAR_ARCHIVE );
  277. }
  278. // make the committed fields into the backup fields
  279. originalFields = fields;
  280. }
  281. /*
  282. ========================
  283. idMenuScreen_Shell_ControllerLayout::idMenuDataSource_AudioSettings::AdjustField
  284. ========================
  285. */
  286. void idMenuScreen_Shell_ControllerLayout::idMenuDataSource_LayoutSettings::AdjustField( const int fieldIndex, const int adjustAmount ) {
  287. idPlayerProfile * profile = session->GetProfileFromMasterLocalUser();
  288. if ( profile == NULL ) {
  289. return;
  290. }
  291. int configSet = profile->GetConfig();
  292. if ( fieldIndex == LAYOUT_FIELD_LAYOUT ) {
  293. configSet += adjustAmount;
  294. if ( configSet < 0 ) {
  295. configSet = MAX_CONTROLLER_CONFIGS - 1;
  296. } else if ( configSet >= MAX_CONTROLLER_CONFIGS ) {
  297. configSet = 0;
  298. }
  299. }
  300. fields[ LAYOUT_FIELD_LAYOUT ].SetString( idLocalization::GetString( va( "#str_swf_config_360_%i", configSet ) ) );
  301. profile->SetConfig( configSet, false );
  302. }
  303. /*
  304. ========================
  305. idMenuScreen_Shell_ControllerLayout::idMenuDataSource_AudioSettings::IsDataChanged
  306. ========================
  307. */
  308. bool idMenuScreen_Shell_ControllerLayout::idMenuDataSource_LayoutSettings::IsDataChanged() const {
  309. bool hasLocalChanges = false;
  310. if ( fields[ LAYOUT_FIELD_LAYOUT ].ToString() != originalFields[ LAYOUT_FIELD_LAYOUT ].ToString() ) {
  311. return true;
  312. }
  313. return hasLocalChanges;
  314. }