MenuScreen_PDA_UserEmails.cpp (16179B)
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 /* 33 ======================== 34 idMenuScreen_PDA_UserEmails::Initialize 35 ======================== 36 */ 37 void idMenuScreen_PDA_UserEmails::Initialize( idMenuHandler * data ) { 38 idMenuScreen::Initialize( data ); 39 40 if ( data != NULL ) { 41 menuGUI = data->GetGUI(); 42 } 43 SetSpritePath( "menuEmail" ); 44 45 pdaInbox.SetSpritePath( GetSpritePath(), "info", "inbox" ); 46 pdaInbox.Initialize( data ); 47 pdaInbox.SetNoAutoFree( true ); 48 49 emailScrollbar.SetSpritePath( GetSpritePath(), "info", "email", "info", "scrollbar" ); 50 emailScrollbar.Initialize( data ); 51 emailScrollbar.SetNoAutoFree( true ); 52 53 emailInfo.SetSpritePath( GetSpritePath(), "info", "email" ); 54 emailInfo.Initialize( data ); 55 emailInfo.SetScrollbar( &emailScrollbar ); 56 emailInfo.AddChild( &emailScrollbar ); 57 emailInfo.RegisterEventObserver( this ); 58 emailInfo.AddEventAction( WIDGET_EVENT_ROLL_OVER ).Set( WIDGET_ACTION_EMAIL_HOVER, 1 ); 59 emailInfo.AddEventAction( WIDGET_EVENT_ROLL_OUT ).Set( WIDGET_ACTION_EMAIL_HOVER, 0 ); 60 emailInfo.SetNoAutoFree( true ); 61 62 AddChild( &pdaInbox ); 63 AddChild( &emailInfo ); 64 65 if ( pdaInbox.GetEmailList() != NULL ) { 66 pdaInbox.GetEmailList()->RegisterEventObserver( &emailInfo ); 67 pdaInbox.GetEmailList()->RegisterEventObserver( &emailScrollbar ); 68 69 for ( int i = 0; i < pdaInbox.GetEmailList()->GetChildren().Num(); ++i ) { 70 idMenuWidget & child = pdaInbox.GetEmailList()->GetChildByIndex( i ); 71 idMenuWidget_Button * const button = dynamic_cast< idMenuWidget_Button * >( &child ); 72 if ( button != NULL ) { 73 button->RegisterEventObserver( &emailInfo ); 74 } 75 } 76 77 } 78 79 AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RSTICK ) ); 80 AddEventAction( WIDGET_EVENT_SCROLL_UP_RSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP_RSTICK ) ); 81 AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RSTICK_RELEASE ) ); 82 AddEventAction( WIDGET_EVENT_SCROLL_UP_RSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RSTICK_RELEASE ) ); 83 84 AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) ); 85 AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) ); 86 AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) ); 87 AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) ); 88 89 AddEventAction( WIDGET_EVENT_SCROLL_DOWN_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN_LSTICK ) ); 90 AddEventAction( WIDGET_EVENT_SCROLL_UP_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP_LSTICK ) ); 91 AddEventAction( WIDGET_EVENT_SCROLL_DOWN_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_LSTICK_RELEASE ) ); 92 AddEventAction( WIDGET_EVENT_SCROLL_UP_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_LSTICK_RELEASE ) ); 93 94 AddEventAction( WIDGET_EVENT_TAB_NEXT ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_TAB_NEXT, WIDGET_EVENT_TAB_NEXT ) ); 95 AddEventAction( WIDGET_EVENT_TAB_PREV ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_TAB_PREV, WIDGET_EVENT_TAB_PREV ) ); 96 97 class idInfoBoxRefresh : public idSWFScriptFunction_RefCounted { 98 public: 99 idInfoBoxRefresh( idMenuWidget_InfoBox * _widget ) : 100 widget( _widget ) { 101 } 102 103 idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) { 104 105 if ( widget == NULL ) { 106 return idSWFScriptVar(); 107 } 108 109 widget->Update(); 110 return idSWFScriptVar(); 111 } 112 private: 113 idMenuWidget_InfoBox * widget; 114 }; 115 116 if ( GetSWFObject() != NULL ) { 117 GetSWFObject()->SetGlobal( "refreshInfoBox", new (TAG_SWF) idInfoBoxRefresh( &emailInfo ) ); 118 } 119 } 120 121 /* 122 ======================== 123 idMenuScreen_PDA_UserEmails::ShowScreen 124 ======================== 125 */ 126 void idMenuScreen_PDA_UserEmails::ShowScreen( const mainMenuTransition_t transitionType ) { 127 128 if ( menuGUI != NULL ) { 129 readingEmails = false; 130 131 idSWFScriptObject & root = menuGUI->GetRootObject(); 132 idSWFSpriteInstance * pdaSprite = root.GetNestedSprite( "pda_persons" ); 133 if ( pdaSprite != NULL && menuData != NULL && menuData->ActiveScreen() != PDA_AREA_USER_DATA ) { 134 pdaSprite->SetVisible( true ); 135 pdaSprite->PlayFrame( "rollOn" ); 136 } 137 138 menuGUI->SetGlobal( "emailRollback", false ); 139 if ( pdaInbox.BindSprite( root ) && pdaInbox.GetSprite() ) { 140 pdaInbox.GetSprite()->StopFrame( 1 ); 141 } 142 if ( emailInfo.BindSprite( root ) && emailInfo.GetSprite() ) { 143 emailInfo.GetSprite()->StopFrame( 1 ); 144 } 145 } 146 147 scrollEmailInfo = false; 148 149 idMenuScreen::ShowScreen( transitionType ); 150 } 151 152 /* 153 ======================== 154 idMenuScreen_PDA_UserEmails::Update 155 ======================== 156 */ 157 void idMenuScreen_PDA_UserEmails::Update() { 158 159 if ( menuData != NULL ) { 160 161 if ( menuData->NextScreen() != PDA_AREA_USER_EMAIL ) { 162 return; 163 } 164 165 idMenuWidget_CommandBar * cmdBar = dynamic_cast< idMenuWidget_CommandBar * const >( menuData->GetChildFromIndex( PDA_WIDGET_CMD_BAR ) ); 166 if ( cmdBar != NULL ) { 167 cmdBar->ClearAllButtons(); 168 idMenuWidget_CommandBar::buttonInfo_t * buttonInfo; 169 if ( readingEmails ) { 170 buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 ); 171 if ( menuData->GetPlatform() != 2 ) { 172 buttonInfo->label = "#str_00395"; 173 } 174 buttonInfo->action.Set( WIDGET_ACTION_GO_BACK ); 175 176 } else { 177 buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 ); 178 if ( menuData->GetPlatform() != 2 ) { 179 buttonInfo->label = "#str_01345"; 180 } 181 buttonInfo->action.Set( WIDGET_ACTION_GO_BACK ); 182 183 idMenuWidget_DynamicList * pdaList = dynamic_cast< idMenuWidget_DynamicList * >( menuData->GetChildFromIndex( PDA_WIDGET_PDA_LIST ) ); 184 if ( pdaList != NULL ) { 185 int pdaIndex = pdaList->GetViewIndex(); 186 idPlayer * player = gameLocal.GetLocalPlayer(); 187 if ( player != NULL ) { 188 if ( pdaIndex < player->GetInventory().pdas.Num() ) { 189 const idDeclPDA * pda = player->GetInventory().pdas[ pdaIndex ]; 190 if ( pda != NULL && pdaInbox.GetEmailList() != NULL ) { 191 idStr pdaFullName = pda->GetFullName(); 192 int emailIndex = pdaInbox.GetEmailList()->GetViewIndex(); 193 if ( emailIndex < pda->GetNumEmails() ) { 194 buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 ); 195 if ( menuData->GetPlatform() != 2 ) { 196 buttonInfo->label = "#str_01102"; 197 } 198 buttonInfo->action.Set( WIDGET_ACTION_PDA_SELECT_EMAIL ); 199 } 200 } 201 } 202 } 203 } 204 } 205 206 buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_TAB ); 207 buttonInfo->label = ""; 208 buttonInfo->action.Set( WIDGET_ACTION_PDA_CLOSE ); 209 } 210 } 211 212 UpdateEmail(); 213 idMenuScreen::Update(); 214 215 } 216 217 /* 218 ======================== 219 idMenuScreen_PDA_UserEmails::HideScreen 220 ======================== 221 */ 222 void idMenuScreen_PDA_UserEmails::HideScreen( const mainMenuTransition_t transitionType ) { 223 224 if ( menuGUI != NULL ) { 225 idSWFScriptObject & root = menuGUI->GetRootObject(); 226 idSWFSpriteInstance * pdaSprite = root.GetNestedSprite( "pda_persons" ); 227 if ( pdaSprite != NULL && menuData != NULL ) { 228 if ( menuData->NextScreen() != PDA_AREA_USER_DATA ) { 229 pdaSprite->SetVisible( true ); 230 pdaSprite->PlayFrame( "rollOff" ); 231 readingEmails = false; 232 } else { 233 if ( readingEmails ) { 234 readingEmails = false; 235 pdaSprite->SetVisible( true ); 236 pdaSprite->PlayFrame( "rollOn" ); 237 } 238 } 239 } 240 } 241 242 idMenuScreen::HideScreen( transitionType ); 243 } 244 245 /* 246 ======================== 247 idMenuScreen_PDA_UserEmails::UpdateEmail 248 ======================== 249 */ 250 void idMenuScreen_PDA_UserEmails::UpdateEmail() { 251 idMenuWidget_DynamicList * pdaList = dynamic_cast< idMenuWidget_DynamicList * >( menuData->GetChildFromIndex( PDA_WIDGET_PDA_LIST ) ); 252 if ( pdaList != NULL ) { 253 254 int pdaIndex = pdaList->GetViewIndex(); 255 256 idPlayer * player = gameLocal.GetLocalPlayer(); 257 if ( player == NULL ) { 258 return; 259 } 260 261 if ( pdaIndex > player->GetInventory().pdas.Num() ) { 262 return; 263 } 264 265 const idDeclPDA * pda = player->GetInventory().pdas[ pdaIndex ]; 266 if ( pda != NULL && pdaInbox.GetEmailList() != NULL ) { 267 idStr pdaFullName = pda->GetFullName(); 268 int emailIndex = pdaInbox.GetEmailList()->GetViewIndex(); 269 if ( emailIndex < pda->GetNumEmails() ) { 270 const idDeclEmail * email = pda->GetEmailByIndex( emailIndex ); 271 if ( email != NULL ) { 272 emailInfo.SetHeading( email->GetSubject() ); 273 emailInfo.SetBody( email->GetBody() ); 274 emailInfo.Update(); 275 } 276 } 277 } 278 } 279 } 280 281 /* 282 ======================== 283 idMenuScreen_PDA_UserEmails::HandleAction 284 ======================== 285 */ 286 bool idMenuScreen_PDA_UserEmails::ScrollCorrectList( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget ) { 287 288 bool handled = false; 289 bool leftScroll = false; 290 if ( event.type == WIDGET_EVENT_SCROLL_UP_LSTICK || event.type == WIDGET_EVENT_SCROLL_DOWN_LSTICK || 291 event.type == WIDGET_EVENT_SCROLL_UP || event.type == WIDGET_EVENT_SCROLL_DOWN ) { 292 leftScroll = true; 293 } 294 295 if ( readingEmails ) { 296 if ( leftScroll && !scrollEmailInfo ) { 297 idMenuWidget_DynamicList * inbox = pdaInbox.GetEmailList(); 298 if ( inbox != NULL ){ 299 inbox->HandleAction( action, event, inbox ); 300 UpdateEmail(); 301 handled = true; 302 } 303 } else { 304 emailInfo.HandleAction( action, event, &emailInfo ); 305 handled = true; 306 } 307 } else if ( !leftScroll ) { 308 idMenuWidget_DynamicList * inbox = pdaInbox.GetEmailList(); 309 if ( inbox != NULL ){ 310 inbox->HandleAction( action, event, inbox ); 311 UpdateEmail(); 312 handled = true; 313 } 314 } else if ( menuData != NULL ) { 315 idMenuWidget_DynamicList * pdaList = dynamic_cast< idMenuWidget_DynamicList * const >( menuData->GetChildFromIndex( PDA_WIDGET_PDA_LIST ) ); 316 if ( pdaList != NULL ) { 317 pdaList->HandleAction( action, event, pdaList ); 318 handled = true; 319 } 320 } 321 322 return handled; 323 } 324 325 /* 326 ======================== 327 idMenuScreen_PDA_UserEmails::HandleAction 328 ======================== 329 */ 330 void idMenuScreen_PDA_UserEmails::ShowEmail( bool show ) { 331 332 idSWFSpriteInstance * pdaSprite = NULL; 333 334 if ( menuGUI != NULL ) { 335 idSWFScriptObject & root = menuGUI->GetRootObject(); 336 pdaSprite = root.GetNestedSprite( "pda_persons" ); 337 338 if ( show && !readingEmails ) { 339 340 scrollEmailInfo = false; 341 342 if ( pdaSprite != NULL ) { 343 pdaSprite->SetVisible( true ); 344 pdaSprite->PlayFrame( "rollOff" ); 345 } 346 347 if ( emailInfo.BindSprite( root ) && emailInfo.GetSprite() != NULL ) { 348 emailInfo.GetSprite()->PlayFrame( "rollOn" ); 349 emailInfo.Update(); 350 } 351 352 if ( pdaInbox.BindSprite( root ) && pdaInbox.GetSprite() != NULL ) { 353 pdaInbox.GetSprite()->PlayFrame( "rollOff" ); 354 } 355 } else if ( !show && readingEmails ) { 356 357 if ( emailInfo.BindSprite( root ) && emailInfo.GetSprite() != NULL ) { 358 emailInfo.GetSprite()->PlayFrame( "rollOff" ); 359 } 360 361 if ( pdaInbox.BindSprite( root ) && pdaInbox.GetSprite() != NULL ) { 362 pdaInbox.GetSprite()->PlayFrame( "rollOn" ); 363 } 364 365 if ( pdaSprite != NULL ) { 366 pdaSprite->SetVisible( true ); 367 pdaSprite->PlayFrame( "rollOn" ); 368 369 if ( menuData != NULL ) { 370 idMenuWidget_DynamicList * pdaList = dynamic_cast< idMenuWidget_DynamicList * const >( menuData->GetChildFromIndex( PDA_WIDGET_PDA_LIST ) ); 371 if ( pdaList != NULL ) { 372 pdaList->SetFocusIndex( pdaList->GetFocusIndex() ); 373 } 374 } 375 } 376 } 377 } 378 379 380 readingEmails = show; 381 Update(); 382 } 383 384 /* 385 ======================== 386 idMenuScreen_PDA_UserEmails::HandleAction 387 ======================== 388 */ 389 bool idMenuScreen_PDA_UserEmails::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) { 390 391 if ( menuData == NULL ) { 392 return true; 393 } 394 395 if ( menuData->ActiveScreen() != PDA_AREA_USER_EMAIL ) { 396 return false; 397 } 398 399 widgetAction_t actionType = action.GetType(); 400 const idSWFParmList & parms = action.GetParms(); 401 402 switch ( actionType ) { 403 case WIDGET_ACTION_PDA_CLOSE: { 404 menuData->SetNextScreen( PDA_AREA_INVALID, MENU_TRANSITION_ADVANCE ); 405 return true; 406 } 407 case WIDGET_ACTION_GO_BACK: { 408 if ( readingEmails ) { 409 ShowEmail( false ); 410 } else { 411 menuData->SetNextScreen( PDA_AREA_INVALID, MENU_TRANSITION_ADVANCE ); 412 } 413 return true; 414 } 415 case WIDGET_ACTION_REFRESH: { 416 UpdateEmail(); 417 return true; 418 } 419 case WIDGET_ACTION_PDA_SELECT_EMAIL: { 420 421 if ( widget->GetParent() != NULL ) { 422 idMenuWidget_DynamicList * emailList = dynamic_cast< idMenuWidget_DynamicList * >( widget->GetParent() ); 423 int index = parms[0].ToInteger(); 424 if ( emailList != NULL ) { 425 emailList->SetViewIndex( emailList->GetViewOffset() + index ); 426 emailList->SetFocusIndex( index ); 427 } 428 } 429 430 ShowEmail( true ); 431 432 return true; 433 } 434 case WIDGET_ACTION_EMAIL_HOVER: { 435 scrollEmailInfo = parms[0].ToBool(); 436 return true; 437 } 438 case WIDGET_ACTION_SCROLL_VERTICAL: { 439 if ( ScrollCorrectList( action, event, widget ) ) { 440 return true; 441 } 442 UpdateEmail(); 443 break; 444 } 445 } 446 447 return idMenuWidget::HandleAction( action, event, widget, forceHandled ); 448 } 449 450 /* 451 ======================== 452 idMenuScreen_PDA_UserEmails::ObserveEvent 453 ======================== 454 */ 455 void idMenuScreen_PDA_UserEmails::ObserveEvent( const idMenuWidget & widget, const idWidgetEvent & event ) { 456 457 if ( menuData != NULL && menuData->ActiveScreen() != PDA_AREA_USER_EMAIL ) { 458 return; 459 } 460 461 const idMenuWidget_Button * const button = dynamic_cast< const idMenuWidget_Button * >( &widget ); 462 if ( button == NULL ) { 463 return; 464 } 465 466 const idMenuWidget * const listWidget = button->GetParent(); 467 468 if ( listWidget == NULL ) { 469 return; 470 } 471 472 switch ( event.type ) { 473 case WIDGET_EVENT_FOCUS_ON: { 474 Update(); 475 break; 476 } 477 } 478 }