MenuScreen_PDA_VideoDisks.cpp (10988B)
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 static const int MAX_VIDEO_ITEMS = 5; 33 34 /* 35 ======================== 36 idMenuScreen_PDA_VideoDisks::Initialize 37 ======================== 38 */ 39 void idMenuScreen_PDA_VideoDisks::Initialize( idMenuHandler * data ) { 40 41 if ( data != NULL ) { 42 menuGUI = data->GetGUI(); 43 } 44 SetSpritePath( "menuVideo" ); 45 46 47 videoDetails.SetSpritePath( GetSpritePath(), "info", "details" ); 48 videoDetails.Initialize( data ); 49 videoDetails.SetNoAutoFree( true ); 50 51 scrollbar.SetSpritePath( GetSpritePath(), "info", "videoList", "scrollbar" ); 52 scrollbar.Initialize( data ); 53 scrollbar.SetNoAutoFree( true ); 54 55 pdaVideoList.SetSpritePath( GetSpritePath(), "info", "videoList", "options" ); 56 pdaVideoList.SetNumVisibleOptions( MAX_VIDEO_ITEMS ); 57 pdaVideoList.SetWrappingAllowed( true ); 58 pdaVideoList.SetNoAutoFree( true ); 59 while ( pdaVideoList.GetChildren().Num() < MAX_VIDEO_ITEMS ) { 60 idMenuWidget_Button * const buttonWidget = new (TAG_SWF) idMenuWidget_Button(); 61 buttonWidget->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_SELECT_PDA_VIDEO, pdaVideoList.GetChildren().Num() ); 62 buttonWidget->RegisterEventObserver( &videoDetails ); 63 buttonWidget->RegisterEventObserver( &scrollbar ); 64 buttonWidget->Initialize( data ); 65 pdaVideoList.AddChild( buttonWidget ); 66 } 67 pdaVideoList.Initialize( data ); 68 pdaVideoList.AddChild( &scrollbar ); 69 70 AddChild( &pdaVideoList ); 71 AddChild( &videoDetails ); 72 73 AddEventAction( WIDGET_EVENT_SCROLL_DOWN_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( &pdaVideoList, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN_LSTICK ) ); 74 AddEventAction( WIDGET_EVENT_SCROLL_UP_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( &pdaVideoList, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP_LSTICK ) ); 75 AddEventAction( WIDGET_EVENT_SCROLL_DOWN_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( &pdaVideoList, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_LSTICK_RELEASE ) ); 76 AddEventAction( WIDGET_EVENT_SCROLL_UP_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( &pdaVideoList, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_LSTICK_RELEASE ) ); 77 AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( &pdaVideoList, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) ); 78 AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( &pdaVideoList, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) ); 79 AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( &pdaVideoList, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) ); 80 AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( &pdaVideoList, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) ); 81 AddEventAction( WIDGET_EVENT_TAB_NEXT ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_TAB_NEXT, WIDGET_EVENT_TAB_NEXT ) ); 82 AddEventAction( WIDGET_EVENT_TAB_PREV ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_TAB_PREV, WIDGET_EVENT_TAB_PREV ) ); 83 84 idMenuScreen::Initialize( data ); 85 } 86 87 /* 88 ======================== 89 idMenuScreen_PDA_VideoDisks::Update 90 ======================== 91 */ 92 void idMenuScreen_PDA_VideoDisks::Update() { 93 94 idPlayer * player = gameLocal.GetLocalPlayer(); 95 96 if ( menuData != NULL ) { 97 idMenuWidget_CommandBar * cmdBar = dynamic_cast< idMenuWidget_CommandBar * const >( menuData->GetChildFromIndex( PDA_WIDGET_CMD_BAR ) ); 98 if ( cmdBar != NULL ) { 99 cmdBar->ClearAllButtons(); 100 idMenuWidget_CommandBar::buttonInfo_t * buttonInfo; 101 102 buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 ); 103 if ( menuData->GetPlatform() != 2 ) { 104 buttonInfo->label = "#str_01345"; 105 } 106 buttonInfo->action.Set( WIDGET_ACTION_GO_BACK ); 107 108 buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_TAB ); 109 buttonInfo->label = ""; 110 buttonInfo->action.Set( WIDGET_ACTION_GO_BACK ); 111 112 if ( player != NULL && player->GetInventory().videos.Num() > 0 ) { 113 if ( player->GetVideoMaterial() == NULL ) { 114 buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 ); 115 if ( menuData->GetPlatform() != 2 ) { 116 buttonInfo->label = "#str_swf_play"; 117 } 118 buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED ); 119 } else { 120 buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 ); 121 if ( menuData->GetPlatform() != 2 ) { 122 buttonInfo->label = "#str_swf_stop"; 123 } 124 buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED ); 125 } 126 } 127 } 128 } 129 130 if ( player != NULL ) { 131 //if ( pdaVideoList == NULL ) { 132 // idMenuScreen::Update(); 133 // return; 134 //} 135 136 idSWFScriptObject & root = GetSWFObject()->GetRootObject(); 137 int index = pdaVideoList.GetViewIndex(); 138 const idDeclVideo * video = player->GetVideo( index ); 139 140 if ( video == NULL ) { 141 idMenuScreen::Update(); 142 return; 143 } 144 145 if ( player->GetVideoMaterial() != NULL ) { 146 // update video material 147 if ( BindSprite( root ) && GetSprite() != NULL ) { 148 idSWFSpriteInstance * videoSprite = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "details", "video", "img" ); 149 const idMaterial * mat = player->GetVideoMaterial(); 150 151 if ( videoSprite != NULL && mat != NULL ) { 152 videoSprite->SetMaterial( mat ); 153 } 154 } 155 } else { 156 idSWFSpriteInstance * videoSprite = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "details", "video", "img" ); 157 if ( videoSprite != NULL ) { 158 videoSprite->SetMaterial( video->GetPreview() ); 159 } 160 } 161 } 162 163 idMenuScreen::Update(); 164 } 165 166 /* 167 ======================== 168 idMenuScreen_PDA_VideoDisks::ShowScreen 169 ======================== 170 */ 171 void idMenuScreen_PDA_VideoDisks::ShowScreen( const mainMenuTransition_t transitionType ) { 172 173 videoItems.Clear(); 174 idPlayer * player = gameLocal.GetLocalPlayer(); 175 if ( player != NULL ) { 176 int numVideos = player->GetInventory().videos.Num(); 177 for ( int i = 0; i < numVideos; ++i ) { 178 const idDeclVideo * video = player->GetVideo( i ); 179 if( video != NULL ) { 180 idList< idStr > item; 181 item.Append( video->GetVideoName() ); 182 videoItems.Append( item ); 183 } 184 } 185 } 186 187 pdaVideoList.SetListData( videoItems ); 188 189 idMenuScreen::ShowScreen( transitionType ); 190 } 191 192 /* 193 ======================== 194 idMenuScreen_PDA_VideoDisks::ToggleVideoDiskPlay 195 ======================== 196 */ 197 void idMenuScreen_PDA_VideoDisks::ToggleVideoDiskPlay() { 198 199 idPlayer * player = gameLocal.GetLocalPlayer(); 200 if ( player == NULL ) { 201 return; 202 } 203 204 205 int index = pdaVideoList.GetViewIndex(); 206 const idDeclVideo * video = player->GetVideo( index ); 207 208 if ( video == NULL ) { 209 return; 210 } 211 212 if ( video == activeVideo ) { 213 player->EndVideoDisk(); 214 activeVideo = NULL; 215 return; 216 } 217 218 activeVideo = video; 219 220 if ( player->GetVideoMaterial() == NULL ) { 221 player->PlayVideoDisk( video ); 222 } else { 223 player->EndVideoDisk(); 224 } 225 } 226 227 /* 228 ======================== 229 idMenuScreen_PDA_VideoDisks::SelectedVideoToPlay 230 ======================== 231 */ 232 void idMenuScreen_PDA_VideoDisks::SelectedVideoToPlay( int index ) { 233 234 idPlayer * player = gameLocal.GetLocalPlayer(); 235 if ( player == NULL ) { 236 return; 237 } 238 239 player->EndVideoDisk(); 240 if ( menuData != NULL ) { 241 idMenuHandler_PDA * pdaHandler = dynamic_cast< idMenuHandler_PDA * const >( menuData ); 242 pdaHandler->ClearVideoPlaying(); 243 } 244 245 246 pdaVideoList.SetViewIndex( pdaVideoList.GetViewOffset() + index ); 247 pdaVideoList.SetFocusIndex( index ); 248 const idDeclVideo * video = player->GetVideo( pdaVideoList.GetViewOffset() + index ); 249 250 if ( video == NULL ) { 251 return; 252 } 253 254 if ( video == activeVideo ) { 255 activeVideo = NULL; 256 return; 257 } 258 259 activeVideo = video; 260 261 player->PlayVideoDisk( video ); 262 263 264 } 265 266 /* 267 ======================== 268 idMenuScreen_PDA_VideoDisks::HideScreen 269 ======================== 270 */ 271 void idMenuScreen_PDA_VideoDisks::HideScreen( const mainMenuTransition_t transitionType ) { 272 idMenuScreen::HideScreen( transitionType ); 273 } 274 275 /* 276 ======================== 277 idMenuScreen_PDA_VideoDisks::HandleAction 278 ======================== 279 */ 280 bool idMenuScreen_PDA_VideoDisks::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) { 281 282 if ( menuData == NULL ) { 283 return true; 284 } 285 286 if ( menuData->ActiveScreen() != PDA_AREA_VIDEO_DISKS ) { 287 return false; 288 } 289 290 widgetAction_t actionType = action.GetType(); 291 const idSWFParmList & parms = action.GetParms(); 292 293 switch ( actionType ) { 294 case WIDGET_ACTION_GO_BACK: { 295 menuData->SetNextScreen( PDA_AREA_INVALID, MENU_TRANSITION_ADVANCE ); 296 return true; 297 } 298 case WIDGET_ACTION_START_REPEATER: { 299 idWidgetAction repeatAction; 300 widgetAction_t repeatActionType = static_cast< widgetAction_t >( parms[ 0 ].ToInteger() ); 301 assert( parms.Num() == 2 ); 302 repeatAction.Set( repeatActionType, parms[ 1 ] ); 303 if ( menuData != NULL ) { 304 menuData->StartWidgetActionRepeater( widget, repeatAction, event ); 305 } 306 return true; 307 } 308 case WIDGET_ACTION_STOP_REPEATER: { 309 if ( menuData != NULL ) { 310 menuData->ClearWidgetActionRepeater(); 311 } 312 return true; 313 } 314 case WIDGET_ACTION_PRESS_FOCUSED: { 315 ToggleVideoDiskPlay(); 316 Update(); 317 return true; 318 } 319 } 320 321 return idMenuWidget::HandleAction( action, event, widget, forceHandled ); 322 }