DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

MenuScreen_Shell_Resolution.cpp (11569B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 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.
     23 
     24 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.
     25 
     26 ===========================================================================
     27 */
     28 #pragma hdrstop
     29 #include "../../idLib/precompiled.h"
     30 #include "../Game_local.h"
     31 #include "../../renderer/tr_local.h"
     32 
     33 const static int NUM_SETTING_OPTIONS = 7;
     34 
     35 enum settingMenuCmds_t {
     36 	SETTING_CMD_CONTROLS,
     37 	SETTING_CMD_GAMEPLAY,
     38 	SETTING_CMD_SYSTEM,
     39 	SETTING_CMD_3D,
     40 };
     41 
     42 /*
     43 ========================
     44 idMenuScreen_Shell_Resolution::Initialize
     45 ========================
     46 */
     47 void idMenuScreen_Shell_Resolution::Initialize( idMenuHandler * data ) {
     48 	idMenuScreen::Initialize( data );
     49 
     50 	if ( data != NULL ) {
     51 		menuGUI = data->GetGUI();
     52 	}
     53 
     54 	SetSpritePath( "menuResolution" );
     55 
     56 	options = new (TAG_SWF) idMenuWidget_DynamicList();
     57 	options->SetNumVisibleOptions( NUM_SETTING_OPTIONS );
     58 	options->SetSpritePath( GetSpritePath(), "info", "options" );
     59 	options->SetWrappingAllowed( true );
     60 
     61 	while ( options->GetChildren().Num() < NUM_SETTING_OPTIONS ) {
     62 		idMenuWidget_Button * const buttonWidget = new (TAG_SWF) idMenuWidget_Button();
     63 		buttonWidget->Initialize( data );
     64 		buttonWidget->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() );
     65 		options->AddChild( buttonWidget );
     66 	}
     67 	options->Initialize( data );
     68 
     69 	AddChild( options );
     70 
     71 	btnBack = new (TAG_SWF) idMenuWidget_Button();
     72 	btnBack->Initialize( data );	
     73 	btnBack->SetLabel( "#str_00183" );
     74 	btnBack->SetSpritePath( GetSpritePath(), "info", "btnBack" );
     75 	btnBack->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_GO_BACK );
     76 
     77 	AddChild( btnBack );
     78 
     79 	options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) );
     80 	options->AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) );
     81 	options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) );
     82 	options->AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) );
     83 	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 ) );
     84 	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 ) );
     85 	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 ) );
     86 	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 ) );
     87 }
     88 
     89 /*
     90 ========================
     91 idMenuScreen_Shell_Resolution::Update
     92 ========================
     93 */
     94 void idMenuScreen_Shell_Resolution::Update() {
     95 
     96 	if ( menuData != NULL ) {
     97 		idMenuWidget_CommandBar * cmdBar = menuData->GetCmdBar();
     98 		if ( cmdBar != NULL ) {
     99 			cmdBar->ClearAllButtons();
    100 			idMenuWidget_CommandBar::buttonInfo_t * buttonInfo;
    101 			buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 );
    102 			if ( menuData->GetPlatform() != 2 ) {
    103 				buttonInfo->label = "#str_00395";
    104 			}
    105 			buttonInfo->action.Set( WIDGET_ACTION_GO_BACK );
    106 
    107 			buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 );
    108 			if ( menuData->GetPlatform() != 2 ) {
    109 				buttonInfo->label = "#str_SWF_SELECT";
    110 			}
    111 			buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED );
    112 		}		
    113 	}
    114 
    115 	idSWFScriptObject & root = GetSWFObject()->GetRootObject();
    116 	if ( BindSprite( root ) ) {
    117 		idSWFTextInstance * heading = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtHeading" );
    118 		if ( heading != NULL ) {
    119 			heading->SetText( "#str_02154" );
    120 			heading->SetStrokeInfo( true, 0.75f, 1.75f );
    121 		}
    122 
    123 		idSWFSpriteInstance * gradient = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "gradient" );
    124 		if ( gradient != NULL && heading != NULL ) {
    125 			gradient->SetXPos( heading->GetTextLength() );
    126 		}
    127 	}
    128 
    129 	if ( btnBack != NULL ) {
    130 		btnBack->BindSprite( root );
    131 	}
    132 
    133 	idMenuScreen::Update();
    134 }
    135 
    136 /*
    137 ========================
    138 idMenuScreen_Shell_Resolution::ShowScreen
    139 ========================
    140 */
    141 void idMenuScreen_Shell_Resolution::ShowScreen( const mainMenuTransition_t transitionType ) {
    142 
    143 
    144 	originalOption.fullscreen = r_fullscreen.GetInteger();
    145 	originalOption.vidmode = r_vidMode.GetInteger();
    146 
    147 	idList< idList< idStr, TAG_IDLIB_LIST_MENU >, TAG_IDLIB_LIST_MENU > menuOptions;
    148 	menuOptions.Alloc().Alloc() = "#str_swf_disabled";
    149 	optionData.Append( optionData_t( 0, 0 ) );
    150 
    151 	int viewIndex = 0;
    152 	idList< idList<vidMode_t> > displays;
    153 	for ( int displayNum = 0 ; ; displayNum++ ) {
    154 		idList<vidMode_t> & modeList = displays.Alloc();
    155 		if ( !R_GetModeListForDisplay( displayNum, modeList ) ) {
    156 			displays.RemoveIndex( displays.Num() - 1 );
    157 			break;
    158 		}
    159 	}
    160 	for ( int displayNum = 0 ; displayNum < displays.Num(); displayNum++ ) {
    161 		idList<vidMode_t> & modeList = displays[displayNum];
    162 		for ( int i = 0; i < modeList.Num(); i++ ) {
    163 			const optionData_t thisOption( displayNum + 1, i );
    164 			if ( originalOption == thisOption ) {
    165 				viewIndex = menuOptions.Num();
    166 			}
    167 			idStr str;
    168 			if ( displays.Num() > 1 ) {
    169 				str.Append( va( "%s %i: ", idLocalization::GetString( "#str_swf_monitor" ), displayNum+1 ) );
    170 			}
    171 			str.Append( va( "%4i x %4i", modeList[i].width, modeList[i].height ) );
    172 			if ( modeList[i].displayHz != 60 ) {
    173 				str.Append( va( " @ %dhz", modeList[i].displayHz ) );
    174 			}
    175 			menuOptions.Alloc().Alloc() = str;
    176 			optionData.Append( thisOption );
    177 		}
    178 	}
    179 	
    180 	options->SetListData( menuOptions );
    181 	options->SetViewIndex( viewIndex );
    182 	const int topOfLastPage = menuOptions.Num() - NUM_SETTING_OPTIONS;
    183 	if ( viewIndex < NUM_SETTING_OPTIONS ) {
    184 		options->SetViewOffset( 0 );
    185 		options->SetFocusIndex( viewIndex );
    186 	} else if ( viewIndex >= topOfLastPage ) {
    187 		options->SetViewOffset( topOfLastPage );
    188 		options->SetFocusIndex( viewIndex - topOfLastPage );
    189 	} else {
    190 		options->SetViewOffset( viewIndex );
    191 		options->SetFocusIndex( 0 );
    192 	}
    193 
    194 	idMenuScreen::ShowScreen( transitionType );
    195 }
    196 
    197 /*
    198 ========================
    199 idMenuScreen_Shell_Resolution::HideScreen
    200 ========================
    201 */
    202 void idMenuScreen_Shell_Resolution::HideScreen( const mainMenuTransition_t transitionType ) {
    203 	idMenuScreen::HideScreen( transitionType );
    204 }
    205 
    206 /*
    207 ========================
    208 idMenuScreen_Shell_Resolution::HandleAction h
    209 ========================
    210 */
    211 bool idMenuScreen_Shell_Resolution::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) {
    212 
    213 	if ( menuData == NULL ) {
    214 		return true;
    215 	}
    216 
    217 	if ( menuData->ActiveScreen() != SHELL_AREA_RESOLUTION ) {
    218 		return false;
    219 	}
    220 
    221 	widgetAction_t actionType = action.GetType();
    222 	const idSWFParmList & parms = action.GetParms();
    223 
    224 	switch ( actionType ) {
    225 		case WIDGET_ACTION_GO_BACK: {
    226 			menuData->SetNextScreen( SHELL_AREA_SYSTEM_OPTIONS, MENU_TRANSITION_SIMPLE );
    227 			return true;
    228 		}
    229 		case WIDGET_ACTION_PRESS_FOCUSED: {
    230 			if ( options != NULL ) {
    231 				int selectionIndex = options->GetFocusIndex();
    232 				if ( parms.Num() == 1 ) {
    233 					selectionIndex = parms[0].ToInteger();
    234 				}	
    235 
    236 				if ( options->GetFocusIndex() != selectionIndex ) {
    237 					options->SetFocusIndex( selectionIndex );
    238 					options->SetViewIndex( options->GetViewOffset() + selectionIndex );
    239 				}
    240 				const optionData_t & currentOption = optionData[options->GetViewIndex()];
    241 
    242 				if ( currentOption == originalOption ) {
    243 					// No change
    244 					menuData->SetNextScreen( SHELL_AREA_SYSTEM_OPTIONS, MENU_TRANSITION_SIMPLE );
    245 				} else if ( currentOption.fullscreen == 0 ) {
    246 					// Changing to windowed mode
    247 					r_fullscreen.SetInteger( 0 );
    248 					cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "vid_restart\n" );
    249 					menuData->SetNextScreen( SHELL_AREA_SYSTEM_OPTIONS, MENU_TRANSITION_SIMPLE );
    250 				} else {
    251 					// Changing to fullscreen mode
    252 					r_fullscreen.SetInteger( currentOption.fullscreen );
    253 					r_vidMode.SetInteger( currentOption.vidmode );
    254 					cvarSystem->ClearModifiedFlags( CVAR_ARCHIVE );
    255 					cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "vid_restart\n" );
    256 
    257 					class idSWFFuncAcceptVideoChanges : public idSWFScriptFunction_RefCounted {
    258 					public:
    259 						idSWFFuncAcceptVideoChanges( idMenuHandler * _menu, gameDialogMessages_t _msg, const optionData_t & _optionData, bool _accept ) {
    260 							menuHandler = _menu;
    261 							msg = _msg;
    262 							optionData = _optionData;
    263 							accept = _accept;
    264 						}
    265 						idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
    266 							common->Dialog().ClearDialog( msg );
    267 							if ( accept ) {
    268 								cvarSystem->SetModifiedFlags( CVAR_ARCHIVE );
    269 								if ( menuHandler != NULL ) {
    270 									menuHandler->SetNextScreen( SHELL_AREA_SYSTEM_OPTIONS, MENU_TRANSITION_SIMPLE );
    271 								}
    272 							} else {
    273 								r_fullscreen.SetInteger( optionData.fullscreen );
    274 								r_vidMode.SetInteger( optionData.vidmode );
    275 								cvarSystem->ClearModifiedFlags( CVAR_ARCHIVE );
    276 								cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "vid_restart\n" );
    277 							}
    278 							return idSWFScriptVar();
    279 						}
    280 					private:
    281 						idMenuHandler * menuHandler;
    282 						gameDialogMessages_t msg;
    283 						optionData_t optionData;
    284 						bool accept;
    285 					};
    286 					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 );
    287 				}
    288 				return true;
    289 			}
    290 			return true;
    291 		}
    292 	}
    293 
    294 	return idMenuWidget::HandleAction( action, event, widget, forceHandled );
    295 }