DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

MenuWidget_PDA_Objective.cpp (5188B)


      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 idMenuWidget_PDA_Objective::Update
     35 ========================
     36 */
     37 void idMenuWidget_PDA_Objective::Update() {
     38 
     39 	if ( GetSWFObject() == NULL ) {
     40 		return;
     41 	}
     42 
     43 	idSWFScriptObject & root = GetSWFObject()->GetRootObject();
     44 	if ( !BindSprite( root ) || GetSprite() == NULL ) {
     45 		return;
     46 	}
     47 
     48 	idPlayer * player = gameLocal.GetLocalPlayer();
     49 	if ( player == NULL ) {
     50 		return;
     51 	}
     52 	
     53 	idSWFScriptObject * dataObj = GetSprite()->GetScriptObject()->GetNestedObj( "info" );
     54 	idSWFSpriteInstance * dataSprite = dataObj->GetSprite();
     55 
     56 	if ( dataObj != NULL && dataSprite != NULL ) {
     57 
     58 		idSWFSpriteInstance * img = dataObj->GetNestedSprite( "objImg", "img" );
     59 
     60 		if ( player->GetInventory().objectiveNames.Num() == 0 ) {
     61 			dataSprite->StopFrame( 1 );
     62 		} else {
     63 			int numObjectives = player->GetInventory().objectiveNames.Num();
     64 			
     65 			int objStartIndex = 0;
     66 			if ( numObjectives == 1 ) {
     67 				dataSprite->StopFrame( 2 );			
     68 				objStartIndex = 0;
     69 			} else {
     70 				dataSprite->StopFrame( 3 );		
     71 				objStartIndex = 1;
     72 			}
     73 			
     74 			idSWFTextInstance * txtDesc = dataObj->GetNestedText( "txtDesc" );
     75 
     76 			int displayCount = 0;
     77 			for ( int index = numObjectives - 1; displayCount < 2 && index >= 0; --index ) {
     78 
     79 				if ( img != NULL ) {
     80 					if ( player->GetInventory().objectiveNames[index].screenshot == NULL ) {
     81 						img->SetVisible( false );
     82 					} else {
     83 						img->SetVisible( true );
     84 						img->SetMaterial( player->GetInventory().objectiveNames[index].screenshot );
     85 					}
     86 				}	
     87 
     88 				idSWFSpriteInstance * objSel = dataObj->GetNestedSprite( va( "obj%d", objStartIndex - displayCount ), "sel" );
     89 				idSWFTextInstance * txtNote = dataObj->GetNestedText( va( "obj%d", objStartIndex - displayCount ), "txtVal" );
     90 
     91 				if ( objSel != NULL ) {
     92 					if ( displayCount == 0 ) {
     93 						objSel->SetVisible( true );
     94 					} else {
     95 						objSel->SetVisible( false );
     96 					}
     97 				}
     98 
     99 				if ( txtNote != NULL ) {
    100 					txtNote->SetText( player->GetInventory().objectiveNames[index].title.c_str() );
    101 				}
    102 
    103 				if ( displayCount == 0 ) {
    104 					txtDesc->SetText( player->GetInventory().objectiveNames[index].text.c_str() );
    105 				}
    106 				
    107 				displayCount++;
    108 			}
    109 		} 
    110 
    111 		// Set the main objective text
    112 		idTarget_SetPrimaryObjective * mainObj = player->GetPrimaryObjective();
    113 		idSWFTextInstance * txtMainObj = dataObj->GetNestedText( "txtObj" );
    114 		if ( txtMainObj != NULL ) {
    115 			if ( mainObj != NULL ) {
    116 				txtMainObj->SetText( mainObj->spawnArgs.GetString( "text", idLocalization::GetString( "#str_04253" ) ) );
    117 			} else {
    118 				txtMainObj->SetText( idLocalization::GetString( "#str_02526" ) );
    119 			}
    120 		}
    121 	}
    122 }
    123 
    124 /*
    125 ========================
    126 idMenuWidget_Help::ObserveEvent
    127 ========================
    128 */
    129 void idMenuWidget_PDA_Objective::ObserveEvent( const idMenuWidget & widget, const idWidgetEvent & event ) {
    130 	const idMenuWidget_Button * const button = dynamic_cast< const idMenuWidget_Button * >( &widget );
    131 	if ( button == NULL ) {
    132 		return;
    133 	}
    134 
    135 	const idMenuWidget * const listWidget = button->GetParent();
    136 
    137 	if ( listWidget == NULL ) {
    138 		return;
    139 	}
    140 
    141 	switch ( event.type ) {
    142 		case WIDGET_EVENT_FOCUS_ON: {
    143 			const idMenuWidget_DynamicList * const list = dynamic_cast< const idMenuWidget_DynamicList * const >( listWidget );
    144 			if ( GetSprite() != NULL ) {
    145 				if ( list->GetViewIndex() == 0 ) {
    146 					GetSprite()->PlayFrame( "rollOn" );
    147 				} else if ( pdaIndex == 0 && list->GetViewIndex() != 0 ) {
    148 					GetSprite()->PlayFrame( "rollOff" );
    149 				}
    150 			}
    151 			pdaIndex = list->GetViewIndex();
    152 			Update();
    153 			break;
    154 		}
    155 	}
    156 }