DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

MenuWidget_PDA_UserData.cpp (5524B)


      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_UserData::Update
     35 ========================
     36 */
     37 void idMenuWidget_PDA_UserData::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 	if ( pdaIndex > player->GetInventory().pdas.Num() ) {
     54 		return;
     55 	}
     56 
     57 	const idDeclPDA * pda = player->GetInventory().pdas[ pdaIndex ];
     58 
     59 	idSWFScriptObject * dataObj = GetSprite()->GetScriptObject();
     60 
     61 	if ( dataObj != NULL && pda != NULL ) {
     62 
     63 		idSWFTextInstance * txtName = dataObj->GetNestedText( "txtName" );
     64 		idSWFTextInstance * txtId = dataObj->GetNestedText( "txtId" );
     65 		idSWFTextInstance * txtLocation = dataObj->GetNestedText( "txtLocation" );
     66 		idSWFTextInstance * txtRank = dataObj->GetNestedText( "txtRank" );
     67 		idSWFTextInstance * txtClearance = dataObj->GetNestedText( "txtClearance" );
     68 		idSWFTextInstance * txtLocHeading = dataObj->GetNestedText( "txtLocHeading" );
     69 
     70 		if ( txtName != NULL ) {
     71 
     72 			if ( pdaIndex == 0 ) {
     73 				txtName->SetIgnoreColor( false );
     74 				txtName->SetText( session->GetLocalUserName(0) );
     75 			} else {
     76 				txtName->SetIgnoreColor( false );
     77 				txtName->SetText( pda->GetFullName() );
     78 			}
     79 		}
     80 
     81 		if ( txtLocHeading != NULL ) {
     82 			if ( pdaIndex == 0 ) {
     83 				txtLocHeading->SetText( idLocalization::GetString( "#str_02516" ) );	// location 
     84 			} else {
     85 				txtLocHeading->SetText( idLocalization::GetString( "#str_02515" ) );	// post
     86 			}
     87 		}
     88 
     89 		if ( txtId != NULL ) {
     90 			txtId->SetText( pda->GetID() );
     91 		}
     92 
     93 		if ( txtLocation != NULL ) {
     94 			if ( pdaIndex == 0 ) {
     95 				idLocationEntity *locationEntity = gameLocal.LocationForPoint( player->GetEyePosition() );
     96 				if ( locationEntity ) {
     97 					txtLocation->SetText( locationEntity->GetLocation() );
     98 				} else {
     99 					txtLocation->SetText( idLocalization::GetString( "#str_02911" ) );
    100 				}
    101 			} else {
    102 				txtLocation->SetText( pda->GetPost() );
    103 			}
    104 		}
    105 
    106 		if ( txtRank != NULL ) {
    107 			txtRank->SetText( pda->GetTitle() );
    108 		}
    109 
    110 		if ( txtClearance != NULL ) {
    111 			const char *security = pda->GetSecurity();
    112 			if ( *security == NULL ) {
    113 				txtClearance->SetText( idLocalization::GetString( "#str_00066" ) );
    114 			} else {
    115 				txtClearance->SetText( security );
    116 			}
    117 		}
    118 	}
    119 }
    120 
    121 /*
    122 ========================
    123 idMenuWidget_Help::ObserveEvent
    124 ========================
    125 */
    126 void idMenuWidget_PDA_UserData::ObserveEvent( const idMenuWidget & widget, const idWidgetEvent & event ) {
    127 	const idMenuWidget_Button * const button = dynamic_cast< const idMenuWidget_Button * >( &widget );
    128 	if ( button == NULL ) {
    129 		return;
    130 	}
    131 
    132 	const idMenuWidget * const listWidget = button->GetParent();
    133 
    134 	if ( listWidget == NULL ) {
    135 		return;
    136 	}
    137 
    138 	switch ( event.type ) {
    139 		case WIDGET_EVENT_FOCUS_ON: {
    140 			const idMenuWidget_DynamicList * const list = dynamic_cast< const idMenuWidget_DynamicList * const >( listWidget );
    141 			pdaIndex = list->GetViewIndex();
    142 			if ( GetParent() != NULL && menuData != NULL && menuData->ActiveScreen() == PDA_AREA_USER_DATA ) {
    143 				GetParent()->Update();
    144 			} else {
    145 				Update();
    146 			}
    147 			break;
    148 		}
    149 		case WIDGET_EVENT_FOCUS_OFF: {
    150 			// Don't do anything when losing focus. Focus updates come in pairs, so we can
    151 			// skip doing anything on the "lost focus" event, and instead do updates on the
    152 			// "got focus" event.
    153 			break;
    154 		}
    155 		case WIDGET_EVENT_ROLL_OVER: {
    156 			const idMenuWidget_DynamicList * const list = dynamic_cast< const idMenuWidget_DynamicList * const >( listWidget );
    157 			pdaIndex = list->GetViewIndex();
    158 			Update();
    159 			break;
    160 		}
    161 		case WIDGET_EVENT_ROLL_OUT: {
    162 			const idMenuWidget_DynamicList * const list = dynamic_cast< const idMenuWidget_DynamicList * const >( listWidget );
    163 			pdaIndex = list->GetViewIndex();
    164 			Update();
    165 			break;
    166 		}
    167 	}
    168 }