DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

MenuWidget_PDA_EmailInbox.cpp (5760B)


      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_EMAIL_ITEMS = 7;
     33 
     34 /*
     35 ========================
     36 idMenuWidget_PDA_EmailInbox::Initialize
     37 ========================
     38 */
     39 void idMenuWidget_PDA_EmailInbox::Initialize( idMenuHandler * data ) {
     40 
     41 	idMenuWidget_ScrollBar * scrollbar = new (TAG_SWF) idMenuWidget_ScrollBar();
     42 	scrollbar->SetSpritePath( GetSpritePath(), "info", "scrollbar" );
     43 	scrollbar->Initialize( data );
     44 
     45 	emailList = new (TAG_SWF) idMenuWidget_DynamicList();
     46 	emailList->SetSpritePath( GetSpritePath(), "info", "options" );
     47 	emailList->SetNumVisibleOptions( MAX_EMAIL_ITEMS );
     48 	emailList->SetWrappingAllowed( true );
     49 	while ( emailList->GetChildren().Num() < MAX_EMAIL_ITEMS ) {
     50 		idMenuWidget_Button * const buttonWidget = new (TAG_SWF) idMenuWidget_Button();
     51 		buttonWidget->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PDA_SELECT_EMAIL, emailList->GetChildren().Num() );
     52 		buttonWidget->AddEventAction( WIDGET_EVENT_FOCUS_ON ).Set( WIDGET_ACTION_REFRESH );
     53 		buttonWidget->Initialize( data );
     54 		buttonWidget->RegisterEventObserver( scrollbar );
     55 		emailList->AddChild( buttonWidget );
     56 	}
     57 	emailList->Initialize( data );
     58 	emailList->AddChild( scrollbar );
     59 
     60 	AddChild( emailList );
     61 }
     62 
     63 /*
     64 ========================
     65 idMenuWidget_PDA_EmailInbox::Update
     66 ========================
     67 */
     68 void idMenuWidget_PDA_EmailInbox::Update() {
     69 
     70 	if ( GetSWFObject() == NULL ) {
     71 		return;
     72 	}
     73 
     74 	idSWFScriptObject & root = GetSWFObject()->GetRootObject();
     75 	if ( !BindSprite( root ) || GetSprite() == NULL ) {
     76 		return;
     77 	}
     78 
     79 	idPlayer * player = gameLocal.GetLocalPlayer();
     80 	if ( player == NULL ) {
     81 		return;
     82 	}
     83 
     84 	if ( pdaIndex > player->GetInventory().pdas.Num() ) {
     85 		return;
     86 	}
     87 
     88 	const idDeclPDA * pda = player->GetInventory().pdas[ pdaIndex ];
     89 
     90 	idSWFScriptObject * dataObj = GetSprite()->GetScriptObject()->GetNestedObj( "info" );
     91 	if ( dataObj != NULL && pda != NULL ) {
     92 
     93 		idSWFTextInstance * txtOwner = dataObj->GetNestedText( "heading", "txtOwner" );
     94 		if ( txtOwner != NULL ) {
     95 			idStr ownerText = idLocalization::GetString( "#str_01474" );
     96 			ownerText.Append( ": ");
     97 
     98 			if ( pdaIndex == 0 ) {
     99 				ownerText.Append( session->GetLocalUserName(0) );
    100 			} else {
    101 				ownerText.Append( pda->GetFullName() );
    102 			}
    103 			txtOwner->SetText( ownerText.c_str() );
    104 
    105 			if ( pdaIndex == 0 ) {
    106 				txtOwner->SetIgnoreColor( false );
    107 			} else {
    108 				txtOwner->SetIgnoreColor( false );
    109 				txtOwner->SetText( pda->GetFullName() );
    110 			}
    111 
    112 		}
    113 
    114 		if ( emailList != NULL ) {
    115 			const idDeclEmail *email = NULL;
    116 			emailInfo.Clear();
    117 			for ( int index = 0; index < pda->GetNumEmails(); ++index ) {
    118 				idList< idStr > emailData;
    119 				email = pda->GetEmailByIndex( index );						
    120 				if ( email != NULL ) {
    121 					emailData.Append( email->GetFrom() );
    122 					emailData.Append( email->GetSubject() );
    123 					emailData.Append( email->GetDate() );
    124 				}
    125 				emailInfo.Append( emailData );
    126 			}
    127 
    128 			emailList->SetListData( emailInfo );
    129 			if ( emailList->BindSprite( root ) ) {
    130 				emailList->Update();
    131 			}
    132 		}
    133 	}
    134 }
    135 
    136 /*
    137 ========================
    138 idMenuWidget_PDA_EmailInbox::ObserveEvent
    139 ========================
    140 */
    141 void idMenuWidget_PDA_EmailInbox::ObserveEvent( const idMenuWidget & widget, const idWidgetEvent & event ) {
    142 	const idMenuWidget_Button * const button = dynamic_cast< const idMenuWidget_Button * >( &widget );
    143 	if ( button == NULL ) {
    144 		return;
    145 	}
    146 
    147 	const idMenuWidget * const listWidget = button->GetParent();
    148 
    149 	if ( listWidget == NULL ) {
    150 		return;
    151 	}
    152 
    153 	switch ( event.type ) {
    154 		case WIDGET_EVENT_FOCUS_ON: {
    155 			const idMenuWidget_DynamicList * const list = dynamic_cast< const idMenuWidget_DynamicList * const >( listWidget );
    156 			int oldIndex = pdaIndex;
    157 			if ( list != NULL ) {
    158 				pdaIndex = list->GetViewIndex();
    159 				Update();
    160 			}
    161 			if ( emailList != NULL && oldIndex != pdaIndex ) {
    162 				emailList->SetFocusIndex( 0 );
    163 				emailList->SetViewIndex( 0 );
    164 				emailList->SetViewOffset( 0 );
    165 			}			
    166 			break;
    167 									}
    168 		case WIDGET_EVENT_FOCUS_OFF: {
    169 			Update();
    170 			if ( emailList != NULL ) {
    171 				emailList->SetFocusIndex( 0 );
    172 				emailList->SetViewIndex( 0 );
    173 				emailList->SetViewOffset( 0 );
    174 			}
    175 			break;
    176 		}
    177 	}
    178 }