DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

MenuHandler_HUD.cpp (5173B)


      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 TIP_DISPLAY_TIME = 5000;
     33 
     34 /*
     35 ========================
     36 idMenuHandler_HUD::Update
     37 ========================
     38 */
     39 void idMenuHandler_HUD::Update() {
     40 
     41 	if ( gui == NULL || !gui->IsActive() ) {
     42 		return;
     43 	}
     44 
     45 	if ( nextScreen != activeScreen ) {
     46 	
     47 		if ( activeScreen > HUD_AREA_INVALID && activeScreen < HUD_NUM_AREAS && menuScreens[ activeScreen ] != NULL ) {
     48 			menuScreens[ activeScreen ]->HideScreen( static_cast<mainMenuTransition_t>(transition) );
     49 		}
     50 
     51 		if ( nextScreen > HUD_AREA_INVALID && nextScreen < HUD_NUM_AREAS && menuScreens[ nextScreen ] != NULL ) {
     52 			menuScreens[ nextScreen ]->ShowScreen( static_cast<mainMenuTransition_t>(transition) );			
     53 		}
     54 
     55 		transition = MENU_TRANSITION_INVALID;
     56 		activeScreen = nextScreen;
     57 	}
     58 
     59 	idPlayer * player = gameLocal.GetLocalPlayer();
     60 	if ( player != NULL ) {
     61 		if ( player->IsTipVisible() && autoHideTip && !hiding ) {		
     62 			if ( gameLocal.time >= tipStartTime + TIP_DISPLAY_TIME ) {
     63 				player->HideTip();
     64 			}
     65 		}
     66 
     67 		if ( player->IsSoundChannelPlaying( SND_CHANNEL_PDA_AUDIO ) && GetHud() != NULL ) {
     68 			GetHud()->UpdateAudioLog( true );
     69 		} else {
     70 			GetHud()->UpdateAudioLog( false );
     71 		}
     72 
     73 		if ( radioMessage ) {
     74 			GetHud()->UpdateCommunication( true, player );
     75 		} else {
     76 			GetHud()->UpdateCommunication( false, player );
     77 		}
     78 
     79 	}
     80 
     81 	idMenuHandler::Update();
     82 }
     83 
     84 /*
     85 ========================
     86 idMenuHandler_HUD::ActivateMenu
     87 ========================
     88 */
     89 void idMenuHandler_HUD::ActivateMenu( bool show ) {
     90 
     91 	idMenuHandler::ActivateMenu( show );
     92 	
     93 	idPlayer * player = gameLocal.GetLocalPlayer();
     94 	if ( player == NULL ) {
     95 		return;
     96 	}  	
     97 
     98 	if ( show ) {
     99 		activeScreen = HUD_AREA_INVALID;
    100 		nextScreen = HUD_AREA_PLAYING;
    101 	} else {
    102 		activeScreen = HUD_AREA_INVALID;
    103 		nextScreen = HUD_AREA_INVALID;
    104 	}
    105 
    106 }
    107 
    108 /*
    109 ========================
    110 idMenuHandler_HUD::Initialize
    111 ========================
    112 */
    113 void idMenuHandler_HUD::Initialize( const char * swfFile, idSoundWorld * sw ) {
    114 	idMenuHandler::Initialize( swfFile, sw );
    115 
    116 	//---------------------
    117 	// Initialize the menus
    118 	//---------------------
    119 #define BIND_HUD_SCREEN( screenId, className, menuHandler )				\
    120 	menuScreens[ (screenId) ] = new className();						\
    121 	menuScreens[ (screenId) ]->Initialize( menuHandler );				\
    122 	menuScreens[ (screenId) ]->AddRef();
    123 
    124 	for ( int i = 0; i < HUD_NUM_AREAS; ++i ) {
    125 		menuScreens[ i ] = NULL;
    126 	}
    127 
    128 	BIND_HUD_SCREEN( HUD_AREA_PLAYING, idMenuScreen_HUD, this );
    129 }
    130 
    131 /*
    132 ========================
    133 idMenuHandler_HUD::GetMenuScreen
    134 ========================
    135 */
    136 idMenuScreen * idMenuHandler_HUD::GetMenuScreen( int index ) {
    137 
    138 	if ( index < 0 || index >= HUD_NUM_AREAS ) {
    139 		return NULL;
    140 	}
    141 
    142 	return menuScreens[ index ];
    143 
    144 }
    145 
    146 /*
    147 ========================
    148 idMenuHandler_HUD::GetHud
    149 ========================
    150 */
    151 idMenuScreen_HUD * idMenuHandler_HUD::GetHud() {
    152 	idMenuScreen_HUD * screen = dynamic_cast< idMenuScreen_HUD * >( menuScreens[ HUD_AREA_PLAYING ] );
    153 	return screen;
    154 }
    155 
    156 /*
    157 ========================
    158 idMenuHandler_HUD::ShowTip
    159 ========================
    160 */
    161 void idMenuHandler_HUD::ShowTip( const char * title, const char * tip, bool autoHide ) {	
    162 	autoHideTip = autoHideTip;
    163 	tipStartTime = gameLocal.time;
    164 	hiding = false;
    165 	idMenuScreen_HUD * screen = GetHud();
    166 	if ( screen != NULL ) {
    167 		screen->ShowTip( title, tip );
    168 	}
    169 }
    170 
    171 /*
    172 ========================
    173 idMenuHandler_HUD::HideTip
    174 ========================
    175 */
    176 void idMenuHandler_HUD::HideTip() {
    177 	idMenuScreen_HUD * screen = GetHud();
    178 	if ( screen != NULL && !hiding ) {
    179 		screen->HideTip();
    180 	}
    181 	hiding = true;
    182 }