MenuScreen_Shell_Resolution.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. #include "../../renderer/tr_local.h"
  24. const static int NUM_SETTING_OPTIONS = 7;
  25. enum settingMenuCmds_t {
  26. SETTING_CMD_CONTROLS,
  27. SETTING_CMD_GAMEPLAY,
  28. SETTING_CMD_SYSTEM,
  29. SETTING_CMD_3D,
  30. };
  31. /*
  32. ========================
  33. idMenuScreen_Shell_Resolution::Initialize
  34. ========================
  35. */
  36. void idMenuScreen_Shell_Resolution::Initialize( idMenuHandler * data ) {
  37. idMenuScreen::Initialize( data );
  38. if ( data != NULL ) {
  39. menuGUI = data->GetGUI();
  40. }
  41. SetSpritePath( "menuResolution" );
  42. options = new (TAG_SWF) idMenuWidget_DynamicList();
  43. options->SetNumVisibleOptions( NUM_SETTING_OPTIONS );
  44. options->SetSpritePath( GetSpritePath(), "info", "options" );
  45. options->SetWrappingAllowed( true );
  46. while ( options->GetChildren().Num() < NUM_SETTING_OPTIONS ) {
  47. idMenuWidget_Button * const buttonWidget = new (TAG_SWF) idMenuWidget_Button();
  48. buttonWidget->Initialize( data );
  49. buttonWidget->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() );
  50. options->AddChild( buttonWidget );
  51. }
  52. options->Initialize( data );
  53. AddChild( options );
  54. btnBack = new (TAG_SWF) idMenuWidget_Button();
  55. btnBack->Initialize( data );
  56. btnBack->SetLabel( "#str_00183" );
  57. btnBack->SetSpritePath( GetSpritePath(), "info", "btnBack" );
  58. btnBack->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_GO_BACK );
  59. AddChild( btnBack );
  60. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) );
  61. options->AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) );
  62. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) );
  63. options->AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) );
  64. 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 ) );
  65. 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 ) );
  66. 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 ) );
  67. 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 ) );
  68. }
  69. /*
  70. ========================
  71. idMenuScreen_Shell_Resolution::Update
  72. ========================
  73. */
  74. void idMenuScreen_Shell_Resolution::Update() {
  75. if ( menuData != NULL ) {
  76. idMenuWidget_CommandBar * cmdBar = menuData->GetCmdBar();
  77. if ( cmdBar != NULL ) {
  78. cmdBar->ClearAllButtons();
  79. idMenuWidget_CommandBar::buttonInfo_t * buttonInfo;
  80. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 );
  81. if ( menuData->GetPlatform() != 2 ) {
  82. buttonInfo->label = "#str_00395";
  83. }
  84. buttonInfo->action.Set( WIDGET_ACTION_GO_BACK );
  85. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 );
  86. if ( menuData->GetPlatform() != 2 ) {
  87. buttonInfo->label = "#str_SWF_SELECT";
  88. }
  89. buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED );
  90. }
  91. }
  92. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  93. if ( BindSprite( root ) ) {
  94. idSWFTextInstance * heading = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtHeading" );
  95. if ( heading != NULL ) {
  96. heading->SetText( "#str_02154" );
  97. heading->SetStrokeInfo( true, 0.75f, 1.75f );
  98. }
  99. idSWFSpriteInstance * gradient = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "gradient" );
  100. if ( gradient != NULL && heading != NULL ) {
  101. gradient->SetXPos( heading->GetTextLength() );
  102. }
  103. }
  104. if ( btnBack != NULL ) {
  105. btnBack->BindSprite( root );
  106. }
  107. idMenuScreen::Update();
  108. }
  109. /*
  110. ========================
  111. idMenuScreen_Shell_Resolution::ShowScreen
  112. ========================
  113. */
  114. void idMenuScreen_Shell_Resolution::ShowScreen( const mainMenuTransition_t transitionType ) {
  115. originalOption.fullscreen = r_fullscreen.GetInteger();
  116. originalOption.vidmode = r_vidMode.GetInteger();
  117. idList< idList< idStr, TAG_IDLIB_LIST_MENU >, TAG_IDLIB_LIST_MENU > menuOptions;
  118. menuOptions.Alloc().Alloc() = "#str_swf_disabled";
  119. optionData.Append( optionData_t( 0, 0 ) );
  120. int viewIndex = 0;
  121. idList< idList<vidMode_t> > displays;
  122. for ( int displayNum = 0 ; ; displayNum++ ) {
  123. idList<vidMode_t> & modeList = displays.Alloc();
  124. if ( !R_GetModeListForDisplay( displayNum, modeList ) ) {
  125. displays.RemoveIndex( displays.Num() - 1 );
  126. break;
  127. }
  128. }
  129. for ( int displayNum = 0 ; displayNum < displays.Num(); displayNum++ ) {
  130. idList<vidMode_t> & modeList = displays[displayNum];
  131. for ( int i = 0; i < modeList.Num(); i++ ) {
  132. const optionData_t thisOption( displayNum + 1, i );
  133. if ( originalOption == thisOption ) {
  134. viewIndex = menuOptions.Num();
  135. }
  136. idStr str;
  137. if ( displays.Num() > 1 ) {
  138. str.Append( va( "%s %i: ", idLocalization::GetString( "#str_swf_monitor" ), displayNum+1 ) );
  139. }
  140. str.Append( va( "%4i x %4i", modeList[i].width, modeList[i].height ) );
  141. if ( modeList[i].displayHz != 60 ) {
  142. str.Append( va( " @ %dhz", modeList[i].displayHz ) );
  143. }
  144. menuOptions.Alloc().Alloc() = str;
  145. optionData.Append( thisOption );
  146. }
  147. }
  148. options->SetListData( menuOptions );
  149. options->SetViewIndex( viewIndex );
  150. const int topOfLastPage = menuOptions.Num() - NUM_SETTING_OPTIONS;
  151. if ( viewIndex < NUM_SETTING_OPTIONS ) {
  152. options->SetViewOffset( 0 );
  153. options->SetFocusIndex( viewIndex );
  154. } else if ( viewIndex >= topOfLastPage ) {
  155. options->SetViewOffset( topOfLastPage );
  156. options->SetFocusIndex( viewIndex - topOfLastPage );
  157. } else {
  158. options->SetViewOffset( viewIndex );
  159. options->SetFocusIndex( 0 );
  160. }
  161. idMenuScreen::ShowScreen( transitionType );
  162. }
  163. /*
  164. ========================
  165. idMenuScreen_Shell_Resolution::HideScreen
  166. ========================
  167. */
  168. void idMenuScreen_Shell_Resolution::HideScreen( const mainMenuTransition_t transitionType ) {
  169. idMenuScreen::HideScreen( transitionType );
  170. }
  171. /*
  172. ========================
  173. idMenuScreen_Shell_Resolution::HandleAction h
  174. ========================
  175. */
  176. bool idMenuScreen_Shell_Resolution::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) {
  177. if ( menuData == NULL ) {
  178. return true;
  179. }
  180. if ( menuData->ActiveScreen() != SHELL_AREA_RESOLUTION ) {
  181. return false;
  182. }
  183. widgetAction_t actionType = action.GetType();
  184. const idSWFParmList & parms = action.GetParms();
  185. switch ( actionType ) {
  186. case WIDGET_ACTION_GO_BACK: {
  187. menuData->SetNextScreen( SHELL_AREA_SYSTEM_OPTIONS, MENU_TRANSITION_SIMPLE );
  188. return true;
  189. }
  190. case WIDGET_ACTION_PRESS_FOCUSED: {
  191. if ( options != NULL ) {
  192. int selectionIndex = options->GetFocusIndex();
  193. if ( parms.Num() == 1 ) {
  194. selectionIndex = parms[0].ToInteger();
  195. }
  196. if ( options->GetFocusIndex() != selectionIndex ) {
  197. options->SetFocusIndex( selectionIndex );
  198. options->SetViewIndex( options->GetViewOffset() + selectionIndex );
  199. }
  200. const optionData_t & currentOption = optionData[options->GetViewIndex()];
  201. if ( currentOption == originalOption ) {
  202. // No change
  203. menuData->SetNextScreen( SHELL_AREA_SYSTEM_OPTIONS, MENU_TRANSITION_SIMPLE );
  204. } else if ( currentOption.fullscreen == 0 ) {
  205. // Changing to windowed mode
  206. r_fullscreen.SetInteger( 0 );
  207. cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "vid_restart\n" );
  208. menuData->SetNextScreen( SHELL_AREA_SYSTEM_OPTIONS, MENU_TRANSITION_SIMPLE );
  209. } else {
  210. // Changing to fullscreen mode
  211. r_fullscreen.SetInteger( currentOption.fullscreen );
  212. r_vidMode.SetInteger( currentOption.vidmode );
  213. cvarSystem->ClearModifiedFlags( CVAR_ARCHIVE );
  214. cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "vid_restart\n" );
  215. class idSWFFuncAcceptVideoChanges : public idSWFScriptFunction_RefCounted {
  216. public:
  217. idSWFFuncAcceptVideoChanges( idMenuHandler * _menu, gameDialogMessages_t _msg, const optionData_t & _optionData, bool _accept ) {
  218. menuHandler = _menu;
  219. msg = _msg;
  220. optionData = _optionData;
  221. accept = _accept;
  222. }
  223. idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  224. common->Dialog().ClearDialog( msg );
  225. if ( accept ) {
  226. cvarSystem->SetModifiedFlags( CVAR_ARCHIVE );
  227. if ( menuHandler != NULL ) {
  228. menuHandler->SetNextScreen( SHELL_AREA_SYSTEM_OPTIONS, MENU_TRANSITION_SIMPLE );
  229. }
  230. } else {
  231. r_fullscreen.SetInteger( optionData.fullscreen );
  232. r_vidMode.SetInteger( optionData.vidmode );
  233. cvarSystem->ClearModifiedFlags( CVAR_ARCHIVE );
  234. cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "vid_restart\n" );
  235. }
  236. return idSWFScriptVar();
  237. }
  238. private:
  239. idMenuHandler * menuHandler;
  240. gameDialogMessages_t msg;
  241. optionData_t optionData;
  242. bool accept;
  243. };
  244. common->Dialog().AddDialog( GDM_CONFIRM_VIDEO_CHANGES, DIALOG_TIMER_ACCEPT_REVERT, new ( TAG_SWF ) idSWFFuncAcceptVideoChanges( menuData, GDM_CONFIRM_VIDEO_CHANGES, currentOption, true ), new ( TAG_SWF ) idSWFFuncAcceptVideoChanges( menuData, GDM_CONFIRM_VIDEO_CHANGES, originalOption, false ), false );
  245. }
  246. return true;
  247. }
  248. return true;
  249. }
  250. }
  251. return idMenuWidget::HandleAction( action, event, widget, forceHandled );
  252. }