📄 vgui_teamfortressviewport.cpp
字号:
//=========== (C) Copyright 1999 Valve, L.L.C. All rights reserved. ===========
//
// The copyright to the contents herein is the property of Valve, L.L.C.
// The contents may be used and/or copied only with the written permission of
// Valve, L.L.C., or in accordance with the terms and conditions stipulated in
// the agreement/contract under which the contents have been supplied.
//
// Purpose: Client DLL VGUI2 Viewport
//
// $Workfile: $
// $Date: $
//
//-----------------------------------------------------------------------------
// $Log: $
//
// $NoKeywords: $
//=============================================================================
#pragma warning( disable : 4800 ) // disable forcing int to bool performance warning
// VGUI panel includes
#include <vgui_controls/Panel.h>
#include <vgui/ISurface.h>
#include <KeyValues.h>
#include <vgui/IScheme.h>
#include <vgui/IVGui.h>
#include <vgui/ILocalize.h>
// client dll/engine defines
//#include "pm_shared.h" // OBS_ defines
//#include "quakedef.h" // MAX_OSPATH, byte
//#include "util.h" // common\util.h
#include <keydefs.h> // K_ENTER, ... define
// sub dialogs
#include <game_controls/ClientScoreBoardDialog.h>
#include <game_controls/ClientMOTD.h>
#include <game_controls/SpectatorGUI.h>
#include <game_controls/TeamMenu.h>
#include <game_controls/ClassMenu.h>
#include <game_controls/VGUITextWindow.h>
#include "IGameUIFuncs.h"
#include <game_controls/commandmenu.h>
#include <game_controls/mapoverview.h>
// our definition
#include <game_controls/vgui_TeamFortressViewport.h>
#include "filesystem.h"
void DuckMessage(const char *str);
IViewPort *gViewPortInterface = NULL;
IViewPortMsgs *gViewPortMsgs = NULL;
vgui::Panel *g_lastPanel = NULL; // used for mouseover buttons, keeps track of the last active panel
using namespace vgui;
bool Helper_LoadFile( IBaseFileSystem *pFileSystem, const char *pFilename, CUtlVector<char> &buf )
{
FileHandle_t hFile = pFileSystem->Open( pFilename, "rt" );
if ( hFile == FILESYSTEM_INVALID_HANDLE )
{
Warning( "Helper_LoadFile: missing %s", pFilename );
return false;
}
unsigned long len = pFileSystem->Size( hFile );
buf.SetSize( len );
pFileSystem->Read( buf.Base(), buf.Count(), hFile );
pFileSystem->Close( hFile );
return true;
}
//================================================================
TeamFortressViewport::TeamFortressViewport() : vgui::EditablePanel( NULL, "TeamFortressViewport")
{
gViewPortInterface = this;
gViewPortMsgs = this;
m_pClientDllInterface = NULL;
m_bInitialized = false;
m_iNumTeams = 0;
m_PendingDialogs.Purge();
m_szServerName[0] = 0;
m_GameuiFuncs = NULL;
m_GameEventManager = NULL;
SetKeyBoardInputEnabled( false );
SetMouseInputEnabled( false );
}
TeamFortressViewport::~TeamFortressViewport()
{
m_bInitialized = false;
for (int i = 0; i < 5; i++)
{
if ( m_sTeamNames[i] )
{
free( m_sTeamNames[i] );
}
}
}
//-----------------------------------------------------------------------------
// Purpose: called when the VGUI subsystem starts up
// Creates the sub panels and initialises them
//-----------------------------------------------------------------------------
void TeamFortressViewport::Start( IGameUIFuncs *pGameUIFuncs, IGameEventManager * pGameEventManager )
{
m_GameuiFuncs = pGameUIFuncs;
m_GameEventManager = pGameEventManager;
m_pBackGround = new CBackGroundPanel( NULL );
m_pBackGround->SetZPos( -20 ); // send it to the back
m_pBackGround->SetVisible( false );
m_pPrivateClientScoreBoard = SETUP_PANEL(new CClientScoreBoardDialog(NULL));
m_pClientScoreBoard = m_pPrivateClientScoreBoard;
m_pMOTD = new CClientMOTD(NULL);
m_pPrivateSpectatorGUI = new CSpectatorGUI(NULL);
m_pSpectatorGUI = m_pPrivateSpectatorGUI;
m_pTeamMenu = new CTeamMenu(NULL);
m_pClassMenu = new CClassMenu(NULL);
m_pSpecHelp = new CSpecHelpWindow(NULL, m_pSpectatorGUI);
m_pClassHelp = new CVGUITextWindow(NULL);
m_pMapBriefing = new CVGUITextWindow(NULL);
m_pMapOverview = new CMapOverview(NULL, m_GameEventManager );
m_iCurrentTeamNumber = 0;
Q_strcpy(m_szCurrentMap, "");
m_pCommandMenu = new CommandMenu(NULL, "commandmenu", gViewPortInterface );
m_pCommandMenu->LoadFromFile("Resource/commandmenu.res");
// Make sure all menus are hidden
HideAllVGUIMenu();
m_pClientScoreBoard->Reset();
// Clear out some data
m_iGotAllMOTD = true;
m_iRandomPC = false;
m_flScoreBoardLastUpdated = 0;
// strcpy(m_sMapName, "");
Q_strcpy(m_szServerName, "");
for (int i = 0; i < 5; i++)
{
m_iValidClasses[i] = 0;
m_sTeamNames[i] = NULL;
}
m_bInitialized = true;
}
/*
//-----------------------------------------------------------------------------
// Purpose: displays the spectator gui
//-----------------------------------------------------------------------------
void TeamFortressViewport::ShowSpectatorGUI()
{
if (!m_bInitialized)
return;
m_pBackGround->SetVisible( false );
m_pSpectatorGUI->Activate();
}
void TeamFortressViewport::ShowSpectatorGUIBar()
{
if (!m_bInitialized)
return;
m_pBackGround->SetVisible( false );
m_pSpectatorGUI->ShowBottomBar();
}
//-----------------------------------------------------------------------------
// Purpose: hides the spectator gui
//-----------------------------------------------------------------------------
void TeamFortressViewport::HideSpectatorGUI()
{
if (!m_bInitialized)
return;
if( m_pSpectatorGUI->IsVisible() && m_pClientDllInterface->IsSpectator())
{
DuckMessage( "#Spec_Duck");
}
m_pSpectatorGUI->HideGUI();
}
void TeamFortressViewport::DeactivateSpectatorGUI()
{
if (!m_bInitialized)
return;
m_pSpectatorGUI->DeactivateGUI();
DuckMessage( "#Spec_Duck" );
}
//-----------------------------------------------------------------------------
// Purpose: returns true if ANY of the spectator GUI is visible
//-----------------------------------------------------------------------------
bool TeamFortressViewport::IsSpectatorGUIVisible()
{
if (!m_bInitialized)
return false;
return m_pSpectatorGUI->IsGUIVisible();
}
//-----------------------------------------------------------------------------
// Purpose: returns true if the bottom bar of the spectator GUI is visible (i.e the input bit)
//-----------------------------------------------------------------------------
bool TeamFortressViewport::IsSpectatorBarVisible()
{
if (!m_bInitialized)
return false;
return m_pSpectatorGUI->IsActiveGUIVisible();
} */
ISpectatorInterface * TeamFortressViewport::GetSpectatorInterface()
{
return (ISpectatorInterface*) m_pSpectatorGUI;
}
IMapOverview * TeamFortressViewport::GetMapOverviewInterface()
{
return (IMapOverview*) m_pMapOverview;
}
//-----------------------------------------------------------------------------
// Purpose: sets the image for the spectator banner of the spectator GUI to use
/*-----------------------------------------------------------------------------
void TeamFortressViewport::SetSpectatorBanner(char const *image)
{
m_pSpectatorGUI->SetImage(image);
}*/
//-----------------------------------------------------------------------------
// Purpose: Bring up the scoreboard
//-----------------------------------------------------------------------------
void TeamFortressViewport::ShowScoreBoard( void )
{
// No Scoreboard in single-player
if( CanShowScoreBoard() )
{
GetAllPlayersInfo();
if (!m_bInitialized)
return;
m_pClientScoreBoard->Activate( false /*m_pSpectatorGUI->IsVisible()*/ );
m_pClientScoreBoard->MoveToFront();
}
}
//-----------------------------------------------------------------------------
// Purpose: Check if we should be drawing a scoreboard
// default is no for single player
//-----------------------------------------------------------------------------
bool TeamFortressViewport::CanShowScoreBoard( void )
{
return ( m_pClientDllInterface->GetMaxPlayers() > 1 );
}
//-----------------------------------------------------------------------------
// Purpose: Returns true if the scoreboard is up
//-----------------------------------------------------------------------------
bool TeamFortressViewport::IsScoreBoardVisible( void )
{
if (!m_bInitialized)
return false;
return m_pClientScoreBoard->IsVisible();
}
//-----------------------------------------------------------------------------
// Purpose: Hide the scoreboard
//-----------------------------------------------------------------------------
void TeamFortressViewport::HideScoreBoard( void )
{
// Prevent removal of scoreboard during intermission
if ( m_pClientDllInterface->InIntermission() || !m_bInitialized)
return;
m_pClientScoreBoard->SetVisible(false);
if( m_PendingDialogs.Count() >= 1 ) // show any active menus on the queue
{
int menu = m_PendingDialogs.Head();
m_pBackGround->SetVisible( true );
if( m_pSpectatorGUI->IsGUIVisible() )
{
m_pSpectatorGUI->HideGUI();
}
DisplayVGUIMenu( menu );
}
m_pClientDllInterface->GameVoice_StopSquelchMode();
}
//-----------------------------------------------------------------------------
// Purpose: Updates the spectator panel with new player info
//-----------------------------------------------------------------------------
void TeamFortressViewport::UpdateSpectatorPanel()
{
/* MIKETODO: spectator
char bottomText[128];
int player = -1;
const char *name;
sprintf(bottomText,"#Spec_Mode%d", m_pClientDllInterface->SpectatorMode() );
m_pClientDllInterface->CheckSettings();
// check if we're locked onto a target, show the player's name
if ( (m_pClientDllInterface->SpectatorTarget() > 0) && (m_pClientDllInterface->SpectatorTarget() <= m_pClientDllInterface->GetMaxPlayers()) && (m_pClientDllInterface->SpectatorMode() != OBS_ROAMING) )
{
player = m_pClientDllInterface->SpectatorTarget();
}
// special case in free map and inset off, don't show names
if ( ((m_pClientDllInterface->SpectatorMode() == OBS_MAP_FREE) && !m_pClientDllInterface->PipInsetOff()) || player == -1 )
name = NULL;
else
name = m_pClientDllInterface->GetPlayerInfo(player).name;
// create player & health string
if ( player && name )
{
strcpy( bottomText, name );
}
char szMapName[64];
m_pClientDllInterface->COM_FileBase( const_cast<char *>(m_pClientDllInterface->GetLevelName()), szMapName );
m_pSpectatorGUI->Update(bottomText, player, m_pClientDllInterface->SpectatorMode(), m_pClientDllInterface->IsSpectateOnly(), m_pClientDllInterface->SpectatorNumber(), szMapName );
m_pSpectatorGUI->UpdateSpectatorPlayerList();
*/
}
//================================================================
// VGUI Menus
//-----------------------------------------------------------------------------
// Purpose: Queues the menu iMenu to be displayed when possible
//-----------------------------------------------------------------------------
void TeamFortressViewport::ShowVGUIMenu( int iMenu )
{
if (!m_bInitialized)
return;
// Don't open menus in demo playback
if ( m_pClientDllInterface->IsDemoPlayingBack() )
return;
// Don't open any menus except the MOTD during intermission
// MOTD needs to be accepted because it's sent down to the client
// after map change, before intermission's turned off
if ( m_pClientDllInterface->InIntermission() && iMenu != MENU_INTRO )
return;
if(m_PendingDialogs.Count() == 0 )
{
m_PendingDialogs.Insert( iMenu ); // we have a new current menu
m_pBackGround->SetVisible( true );
if( m_pSpectatorGUI->IsVisible() )
{
m_pSpectatorGUI->Deactivate();
}
DisplayVGUIMenu( iMenu );
}
else
{
if ( ! m_PendingDialogs.Check( iMenu ) ) // TFC sends a MENU_TEAM every 2 seconds until a team is chosen...
// this stops multiple queueing of the same menu
{
m_PendingDialogs.Insert( iMenu );
}
}
}
//-----------------------------------------------------------------------------
// Purpose: Displays the menu specified by iMenu
//-----------------------------------------------------------------------------
void TeamFortressViewport::DisplayVGUIMenu( int iMenu )
{
char cTitle[32];
char sz[64];
char *pfile = NULL;
CUtlVector<char> fileData;
char mapName[64];
m_pBackGround->SetVisible( true );
if( m_pSpectatorGUI->IsVisible() )
{
m_pSpectatorGUI->Deactivate();
}
m_pClientDllInterface->COM_FileBase( const_cast<char *>(m_pClientDllInterface->GetLevelName()), mapName );
switch ( iMenu )
{
case MENU_TEAM:
m_pTeamMenu->Update( mapName, m_pClientDllInterface->IsSpectatingAllowed(), (const char **)m_sTeamNames, m_iNumTeams );
m_pTeamMenu->Activate();
break;
case MENU_INTRO:
if (!m_szServerName || !m_szServerName[0])
strncpy( cTitle, "Half-Life" ,MAX_SERVERNAME_LENGTH);
else
strncpy( cTitle, m_szServerName, MAX_SERVERNAME_LENGTH );
cTitle[ MAX_SERVERNAME_LENGTH -1 ] = '\0';
m_pMOTD->Activate( cTitle, m_szMOTD);
break;
case MENU_MAPBRIEFING: // I don't think this option is actually used...
// Get the current mapname, and open it's map briefing text
if ( mapName[0] )
{
strcpy( sz, "maps/");
strcat( sz, mapName );
strcat( sz, ".txt" );
}
else
return;
if ( !Helper_LoadFile( filesystem(), sz, fileData ) )
{
Error( "MENU_MAPBRIEFING: %s missing", sz );
}
pfile = fileData.Base();
strncpy( cTitle, mapName, sizeof( cTitle ) );
cTitle[sizeof( cTitle )-1] = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -