DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

MenuWidget_PDA_AudioFiles.cpp (6418B)


      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_AUDIO_ITEMS = 3;
     33 
     34 
     35 /*
     36 ========================
     37 idMenuWidget_PDA_AudioFiles::~idMenuWidget_PDA_AudioFiles
     38 ========================
     39 */
     40 idMenuWidget_PDA_AudioFiles::~idMenuWidget_PDA_AudioFiles() {
     41 }
     42 
     43 /*
     44 ========================
     45 idMenuWidget_PDA_AudioFiles::Initialize
     46 ========================
     47 */
     48 void idMenuWidget_PDA_AudioFiles::Initialize( idMenuHandler * data ) {
     49 
     50 	idMenuWidget_DynamicList * pdaAudioList = new (TAG_SWF) idMenuWidget_DynamicList();
     51 	
     52 	pdaAudioList->SetSpritePath( GetSpritePath(), "info", "options" );
     53 	pdaAudioList->SetNumVisibleOptions( MAX_AUDIO_ITEMS );
     54 	pdaAudioList->SetWrappingAllowed( true );
     55 
     56 	while ( pdaAudioList->GetChildren().Num() < MAX_AUDIO_ITEMS ) {
     57 		idMenuWidget_Button * const buttonWidget = new (TAG_SWF) idMenuWidget_Button();
     58 		buttonWidget->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_SELECT_PDA_AUDIO, pdaAudioList->GetChildren().Num() );
     59 		buttonWidget->Initialize( data );
     60 		pdaAudioList->AddChild( buttonWidget );
     61 	}
     62 	pdaAudioList->Initialize( data );
     63 
     64 	AddChild( pdaAudioList );
     65 }
     66 
     67 /*
     68 ========================
     69 idMenuWidget_PDA_AudioFiles::Update
     70 ========================
     71 */
     72 void idMenuWidget_PDA_AudioFiles::Update() {
     73 
     74 	if ( GetSWFObject() == NULL ) {
     75 		return;
     76 	}
     77 
     78 	idSWFScriptObject & root = GetSWFObject()->GetRootObject();
     79 	if ( !BindSprite( root ) || GetSprite() == NULL ) {
     80 		return;
     81 	}
     82 
     83 	idPlayer * player = gameLocal.GetLocalPlayer();
     84 	if ( player == NULL ) {
     85 		return;
     86 	}
     87 
     88 	if ( pdaIndex > player->GetInventory().pdas.Num() ) {
     89 		return;
     90 	}
     91 
     92 	const idDeclPDA * pda = player->GetInventory().pdas[ pdaIndex ];
     93 
     94 	idSWFScriptObject * dataObj = GetSprite()->GetScriptObject()->GetNestedObj( "info" );
     95 	if ( dataObj != NULL && pda != NULL ) {
     96 
     97 		idSWFTextInstance * txtOwner = dataObj->GetNestedText( "txtOwner" );
     98 		if ( txtOwner != NULL ) {
     99 			idStr ownerText = idLocalization::GetString( "#str_04203" );
    100 			ownerText.Append( ": ");
    101 			ownerText.Append( pda->GetFullName() );
    102 			txtOwner->SetText( ownerText.c_str() );
    103 		}
    104 
    105 		idMenuWidget_DynamicList * const audioList = dynamic_cast< idMenuWidget_DynamicList * >( &GetChildByIndex( 0 ) );
    106 		if ( audioList != NULL ) {
    107 			audioFileNames.Clear();
    108 			if ( pda->GetNumAudios() == 0 ) {
    109 				idList< idStr > audioName;
    110 				audioName.Append( idLocalization::GetString( "#str_04168" ) );
    111 				audioList->GetChildByIndex( 0 ).SetState( WIDGET_STATE_DISABLED );
    112 				audioFileNames.Append( audioName );
    113 			} else {
    114 				audioList->GetChildByIndex( 0 ).SetState( WIDGET_STATE_NORMAL );
    115 				const idDeclAudio *aud = NULL;
    116 				for ( int index = 0; index < pda->GetNumAudios(); ++index ) {
    117 					idList< idStr > audioName;
    118 					aud = pda->GetAudioByIndex( index );						
    119 					if ( aud != NULL ) {
    120 						audioName.Append( aud->GetAudioName() );
    121 					} else {
    122 						audioName.Append( "" );
    123 					}		
    124 					audioFileNames.Append( audioName );
    125 				}
    126 			}
    127 			
    128 			audioList->SetListData( audioFileNames );
    129 			if ( audioList->BindSprite( root ) ) {
    130 				audioList->Update();
    131 			}
    132 		}
    133 	}
    134 
    135 	//idSWFSpriteInstance * dataSprite = dataObj->GetSprite();
    136 }
    137 
    138 /*
    139 ========================
    140 idMenuWidget_PDA_AudioFiles::ObserveEvent
    141 ========================
    142 */
    143 void idMenuWidget_PDA_AudioFiles::ObserveEvent( const idMenuWidget & widget, const idWidgetEvent & event ) {
    144 	const idMenuWidget_Button * const button = dynamic_cast< const idMenuWidget_Button * >( &widget );
    145 	if ( button == NULL ) {
    146 		return;
    147 	}
    148 
    149 	const idMenuWidget * const listWidget = button->GetParent();
    150 
    151 	if ( listWidget == NULL ) {
    152 		return;
    153 	}
    154 
    155 	switch ( event.type ) {
    156 		case WIDGET_EVENT_FOCUS_ON: {
    157 			const idMenuWidget_DynamicList * const list = dynamic_cast< const idMenuWidget_DynamicList * const >( listWidget );
    158 			if ( GetSprite() != NULL ) {
    159 				if ( list->GetViewIndex() == 0 ) {
    160 					GetSprite()->PlayFrame( "rollOff" );
    161 				} else if ( ( pdaIndex == 0 || GetSprite()->GetCurrentFrame() <= 2 || GetSprite()->GetCurrentFrame() > GetSprite()->FindFrame( "idle" ) ) && list->GetViewIndex() != 0 ) {
    162 					GetSprite()->PlayFrame( "rollOn" );
    163 				}
    164 			}
    165 			pdaIndex = list->GetViewIndex();
    166 			if ( GetParent() != NULL && menuData != NULL && menuData->ActiveScreen() == PDA_AREA_USER_DATA ) {
    167 				GetParent()->Update();
    168 			} else {
    169 				Update();
    170 			}
    171 			idMenuWidget_DynamicList * const audioList = dynamic_cast< idMenuWidget_DynamicList * >( &GetChildByIndex( 0 ) );
    172 			if ( audioList != NULL ) {
    173 				audioList->SetFocusIndex( 0 );
    174 				audioList->SetViewIndex( 0 );
    175 			}			
    176 			break;
    177 		}
    178 		case WIDGET_EVENT_FOCUS_OFF: {
    179 			idMenuWidget_DynamicList * const audioList = dynamic_cast< idMenuWidget_DynamicList * >( &GetChildByIndex( 0 ) );
    180 			if ( audioList != NULL ) {
    181 				audioList->SetFocusIndex( 0 );
    182 				audioList->SetViewIndex( 0 );
    183 			}
    184 			Update();
    185 			break;
    186 		}
    187 	}
    188 }