DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

MenuScreen_Shell_Difficulty.cpp (10376B)


      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 
     32 const static int NUM_SETTING_OPTIONS = 8;
     33 extern idCVar g_nightmare;
     34 extern idCVar g_roeNightmare;
     35 extern idCVar g_leNightmare;
     36 extern idCVar g_skill;
     37 /*
     38 ========================
     39 idMenuScreen_Shell_Difficulty::Initialize
     40 ========================
     41 */
     42 void idMenuScreen_Shell_Difficulty::Initialize( idMenuHandler * data ) {
     43 	idMenuScreen::Initialize( data );
     44 
     45 	if ( data != NULL ) {
     46 		menuGUI = data->GetGUI();
     47 	}
     48 
     49 	SetSpritePath( "menuDifficulty" );
     50 
     51 	options = new (TAG_SWF) idMenuWidget_DynamicList();
     52 	idList< idList< idStr, TAG_IDLIB_LIST_MENU >, TAG_IDLIB_LIST_MENU > menuOptions;	
     53 	idList< idStr > option;
     54 	option.Append( "#str_04089" );	// Easy
     55 	menuOptions.Append( option );
     56 	option.Clear();
     57 	option.Append( "#str_04091" );	// Medium
     58 	menuOptions.Append( option );
     59 	option.Clear();
     60 	option.Append( "#str_04093" );	// Hard
     61 	menuOptions.Append( option );
     62 	option.Clear();
     63 	option.Append( "#str_02357" );	// Nightmare
     64 	menuOptions.Append( option );
     65 
     66 	options->SetListData( menuOptions );
     67 	options->SetNumVisibleOptions( NUM_SETTING_OPTIONS );
     68 	options->SetSpritePath( GetSpritePath(), "info", "options" );
     69 	options->SetWrappingAllowed( true );
     70 	AddChild( options );
     71 
     72 	idMenuWidget_Help * const helpWidget = new ( TAG_SWF ) idMenuWidget_Help();
     73 	helpWidget->SetSpritePath( GetSpritePath(), "info",  "helpTooltip" );
     74 	AddChild( helpWidget );
     75 
     76 	const char * tips[] = { "#str_02358", "#str_02360", "#str_02362", "#str_02364" };
     77 
     78 	while ( options->GetChildren().Num() < NUM_SETTING_OPTIONS ) {
     79 		idMenuWidget_Button * const buttonWidget = new (TAG_SWF) idMenuWidget_Button();
     80 		buttonWidget->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() );
     81 		buttonWidget->Initialize( data );
     82 
     83 		if ( options->GetChildren().Num() < menuOptions.Num() ) {
     84 			buttonWidget->SetDescription( tips[options->GetChildren().Num()] );
     85 		}
     86 
     87 		buttonWidget->RegisterEventObserver( helpWidget );
     88 		options->AddChild( buttonWidget );
     89 	}
     90 	options->Initialize( data );
     91 
     92 	btnBack = new (TAG_SWF) idMenuWidget_Button();
     93 	btnBack->Initialize( data );	
     94 	btnBack->SetLabel( "#str_02207" );
     95 	btnBack->SetSpritePath( GetSpritePath(), "info", "btnBack" );
     96 	btnBack->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_GO_BACK );
     97 
     98 	AddChild( btnBack );
     99 
    100 	options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER_VARIABLE, WIDGET_EVENT_SCROLL_DOWN ) );
    101 	options->AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER_VARIABLE, WIDGET_EVENT_SCROLL_UP ) );
    102 	options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) );
    103 	options->AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) );
    104 	options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER_VARIABLE, WIDGET_EVENT_SCROLL_DOWN_LSTICK ) );
    105 	options->AddEventAction( WIDGET_EVENT_SCROLL_UP_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER_VARIABLE, WIDGET_EVENT_SCROLL_UP_LSTICK ) );
    106 	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 ) );
    107 	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 ) );
    108 }
    109 
    110 /*
    111 ========================
    112 idMenuScreen_Shell_Difficulty::Update
    113 ========================
    114 */
    115 void idMenuScreen_Shell_Difficulty::Update() {
    116 
    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 
    128 			buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 );
    129 			if ( menuData->GetPlatform() != 2 ) {
    130 				buttonInfo->label = "#str_SWF_SELECT";
    131 			}
    132 			buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED );
    133 		}		
    134 	}
    135 
    136 	idSWFScriptObject & root = GetSWFObject()->GetRootObject();
    137 	if ( BindSprite( root ) ) {
    138 		idSWFTextInstance * heading = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtHeading" );
    139 		if ( heading != NULL ) {
    140 			heading->SetText( "#str_04088" );
    141 			heading->SetStrokeInfo( true, 0.75f, 1.75f );
    142 		}
    143 
    144 		idSWFSpriteInstance * gradient = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "gradient" );
    145 		if ( gradient != NULL && heading != NULL ) {
    146 			gradient->SetXPos( heading->GetTextLength() );
    147 		}
    148 	}
    149 
    150 	if ( btnBack != NULL ) {
    151 		btnBack->BindSprite( root );
    152 	}
    153 
    154 	idMenuScreen::Update();
    155 }
    156 
    157 /*
    158 ========================
    159 idMenuScreen_Shell_Difficulty::ShowScreen
    160 ========================
    161 */
    162 void idMenuScreen_Shell_Difficulty::ShowScreen( const mainMenuTransition_t transitionType ) {
    163 	idMenuScreen::ShowScreen( transitionType );
    164 
    165 	nightmareUnlocked = false;
    166 
    167 	idMenuHandler_Shell * shell = dynamic_cast< idMenuHandler_Shell * >( menuData );
    168 	int type = 0;
    169 	if ( shell != NULL ) {
    170 		type = shell->GetNewGameType();
    171 	}
    172 
    173 	if ( type == 0 ) {
    174 		nightmareUnlocked = g_nightmare.GetBool();
    175 	} else if ( type == 1 ) {
    176 		nightmareUnlocked = g_roeNightmare.GetBool();
    177 	} else if ( type == 2 ) {
    178 		nightmareUnlocked = g_leNightmare.GetBool();
    179 	}
    180 
    181 	int skill = Max( 0, g_skill.GetInteger() );
    182 	if ( !nightmareUnlocked ) {
    183 		options->GetChildByIndex( 3 ).SetState( WIDGET_STATE_DISABLED );
    184 		skill = Min( skill, 2 );
    185 	} else {
    186 		options->GetChildByIndex( 3 ).SetState( WIDGET_STATE_NORMAL );
    187 		skill = Min( skill, 3 );
    188 	}
    189 	options->SetFocusIndex( skill );
    190 	options->SetViewIndex( options->GetViewOffset() + skill );
    191 }
    192 
    193 /*
    194 ========================
    195 idMenuScreen_Shell_Difficulty::HideScreen
    196 ========================
    197 */
    198 void idMenuScreen_Shell_Difficulty::HideScreen( const mainMenuTransition_t transitionType ) {
    199 	idMenuScreen::HideScreen( transitionType );
    200 }
    201 
    202 /*
    203 ========================
    204 idMenuScreen_Shell_Difficulty::HandleAction h
    205 ========================
    206 */
    207 bool idMenuScreen_Shell_Difficulty::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) {
    208 
    209 	if ( menuData == NULL ) {
    210 		return true;
    211 	}
    212 
    213 	if ( menuData->ActiveScreen() != SHELL_AREA_DIFFICULTY ) {
    214 		return false;
    215 	}
    216 
    217 	widgetAction_t actionType = action.GetType();
    218 	const idSWFParmList & parms = action.GetParms();
    219 
    220 	switch ( actionType ) {
    221 		case WIDGET_ACTION_SCROLL_VERTICAL_VARIABLE: {
    222 
    223 			if ( parms.Num() == 0 ) {
    224 				return true;
    225 			}
    226 
    227 			if ( options == NULL ) {
    228 				return true;
    229 			}
    230 
    231 			int dir = parms[ 0 ].ToInteger();
    232 			int scroll = dir;
    233 
    234 			bool nightmareEnabled = nightmareUnlocked;
    235 			int curIndex = options->GetFocusIndex();
    236 
    237 			if ( ( curIndex + scroll < 0 && !nightmareEnabled ) || ( curIndex + scroll == 3 && !nightmareEnabled ) ) {
    238 				scroll *= 2;
    239 				options->Scroll( scroll, true );
    240 			} else {
    241 				options->Scroll( scroll );
    242 			}
    243 
    244 			return true;
    245 		}
    246 		case WIDGET_ACTION_GO_BACK: {
    247 			menuData->SetNextScreen( SHELL_AREA_NEW_GAME, MENU_TRANSITION_SIMPLE );
    248 			return true;
    249 		}
    250 		case WIDGET_ACTION_PRESS_FOCUSED: {
    251 			if ( options == NULL ) {
    252 				return true;
    253 			}
    254 
    255 			int selectionIndex = options->GetViewIndex();
    256 			if ( parms.Num() == 1 ) {
    257 				selectionIndex = parms[0].ToInteger();
    258 			}	
    259 
    260 			if ( selectionIndex == 3 && !nightmareUnlocked ) {
    261 				return true;
    262 			}
    263 
    264 			if ( options->GetFocusIndex() != selectionIndex ) {
    265 				options->SetFocusIndex( selectionIndex );
    266 				options->SetViewIndex( options->GetViewOffset() + selectionIndex );
    267 			}
    268 
    269 			idMenuHandler_Shell * shell = dynamic_cast< idMenuHandler_Shell * >( menuData );
    270 			int type = 0;
    271 			if ( shell != NULL ) {
    272 				type = shell->GetNewGameType();
    273 			}
    274 
    275 			g_skill.SetInteger( selectionIndex );
    276 
    277 			idMenuHandler_Shell * shellMgr = dynamic_cast< idMenuHandler_Shell * >( menuData );
    278 			if ( shellMgr ) {
    279 				if ( type == 0 ) {
    280 					shellMgr->ShowDoomIntro();
    281 				} else if ( type == 1 ) {
    282 					shellMgr->ShowROEIntro();
    283 				} else if ( type == 2 ) {
    284 					shellMgr->ShowLEIntro();
    285 				}
    286 			}
    287 
    288 			return true;
    289 		}
    290 	}
    291 
    292 	return idMenuWidget::HandleAction( action, event, widget, forceHandled );
    293 }