📄 counterstrikeviewport.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: $
//=============================================================================
#include "cbase.h"
#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/Cursor.h>
#include <vgui/IScheme.h>
#include <vgui/IVGUI.h>
#include <vgui/ILocalize.h>
#include <vgui/VGUI.h>
#include <vgui_controls/AnimationController.h>
// client dll/engine defines
#include "hud.h"
#include "parsemsg.h" // BEGIN_READ, READ_*
// sub dialogs - for vgui_TeamFortressViewport.h
#include <game_controls/ClientScoreBoardDialog.h>
#include <game_controls/ClientMOTD.h>
#include <game_controls/SpectatorGUI.h>
#include <game_controls/VGUITextWindow.h>
// cstrike specific dialogs
#include "CstrikeTeamMenu.h"
#include "CstrikeClassMenu.h"
#include "BuyMenu.h"
#include "CstrikeSpectatorGUI.h"
#include <game_controls/MapOverview.h>
#include "CstrikeClientScoreBoard.h"
#include "clientmode_csnormal.h"
#include "IGameUIFuncs.h"
#include <cl_dll/IVGuiClientDll.h>
// viewport definitions
#include <game_controls/vgui_TeamFortressViewport.h>
#include "CounterStrikeViewport.h"
#include "cs_gamerules.h"
#include "c_user_message_register.h"
#include "vguicenterprint.h"
#include "text_message.h"
ICSViewPortMsgs *gCSViewPortMsgs = NULL;
extern VGuiLibraryInterface_t clientInterface;
extern ConVar hud_autoreloadscript;
CON_COMMAND( buyequip, "Buy CStrike equipment" )
{
if ( gViewPortInterface )
gViewPortInterface->ShowVGUIMenu( MENU_EQUIPMENT );
}
CON_COMMAND( buy, "Buy CStrike items" )
{
C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
if ( pPlayer && pPlayer->CanShowBuyMenu() )
{
gViewPortInterface->ShowVGUIMenu( MENU_BUY );
}
else
{
internalCenterPrint->Print( hudtextmessage->LookupString( "#Cstrike_Not_In_Buy_Zone" ) );
}
}
CON_COMMAND( chooseteam, "Choose a new team" )
{
C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
if ( pPlayer && pPlayer->CanShowTeamMenu() )
gViewPortInterface->ShowVGUIMenu( MENU_TEAM );
}
CON_COMMAND( commandmenu, "Show command menu" )
{
if ( gViewPortInterface )
gViewPortInterface->ShowCommandMenu();
}
CON_COMMAND( spec_help, "Show spectator help screen")
{
if ( gViewPortInterface )
gViewPortInterface->ShowVGUIMenu( MENU_SPECHELP );
}
CON_COMMAND( spec_menu, "Activates spectator menu")
{
bool showIt = true;
if ( engine->Cmd_Argc() == 2 )
{
showIt = atoi( engine->Cmd_Argv( 1 ) ) == 1;
}
if ( !gViewPortInterface )
return;
if( showIt )
{
gViewPortInterface->GetSpectatorInterface()->ShowGUI();
}
else
{
gViewPortInterface->GetSpectatorInterface()->HideGUI();
}
}
CON_COMMAND( togglescores, "Toggles score panel")
{
if ( gViewPortInterface )
{
if (gViewPortInterface->IsScoreBoardVisible() )
{
gViewPortInterface->HideScoreBoard();
}
else
{
gViewPortInterface->ShowScoreBoard();
}
}
}
CON_COMMAND( overview_zoom, "Sets overview map zoom" )
{
if ( engine->Cmd_Argc() == 2 )
{
gViewPortInterface->GetMapOverviewInterface()->SetZoom( atof(engine->Cmd_Argv( 1 )) );
}
}
CON_COMMAND( overview_size, "Sets overview map size" )
{
if ( engine->Cmd_Argc() == 2 )
{
int s = atoi(engine->Cmd_Argv( 1 ));
gViewPortInterface->GetMapOverviewInterface()->SetBounds( 0,0, s, s );
gViewPortInterface->GetSpectatorInterface()->Update();
}
}
//-----------------------------------------------------------------------------
// Purpose: constructor
//-----------------------------------------------------------------------------
CounterStrikeViewport::CounterStrikeViewport() : m_CursorNone(vgui::dc_none)
{
gCSViewPortMsgs = this;
SetCursor( m_CursorNone );
vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFile("resource/ClientScheme.res", "ClientScheme");
SetScheme(scheme);
// use a custom scheme for the hud
m_pAnimController = new vgui::AnimationController(this);
// create our animation controller
m_pAnimController->SetScheme(scheme);
m_pAnimController->SetProportional(true);
if (!m_pAnimController->SetScriptFile("scripts/HudAnimations.txt"))
{
Assert(0);
}
SetProportional(true);
ivgui()->AddTickSignal( GetVPanel() );
}
//-----------------------------------------------------------------------------
// Purpose: destructor
//-----------------------------------------------------------------------------
CounterStrikeViewport::~CounterStrikeViewport()
{
}
void CounterStrikeViewport::Enable()
{
}
void CounterStrikeViewport::Disable()
{
}
void CounterStrikeViewport::OnThink()
{
m_pAnimController->UpdateAnimations( gpGlobals->curtime );
// check the auto-reload cvar
m_pAnimController->SetAutoReloadScript(hud_autoreloadscript.GetBool());
}
void CounterStrikeViewport::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
gHUD.InitColors( pScheme );
SetPaintBackgroundEnabled( false );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CounterStrikeViewport::ReloadScheme()
{
// See if scheme should change
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
if(!pPlayer)
return;
int team = pPlayer->GetTeamNumber();
if ( team )
{
vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFile( "resource/ClientScheme.res", "HudScheme" );
SetScheme(scheme);
SetProportional( true );
m_pAnimController->SetScheme(scheme);
}
// Force a reload
if ( !m_pAnimController->SetScriptFile("scripts/HudAnimations.txt", true) )
{
Assert( 0 );
}
SetProportional( true );
// reload the .res file from disk
LoadControlSettings("scripts/HudLayout.res");
gHUD.RefreshHudTextures();
InvalidateLayout( true, true );
}
//-----------------------------------------------------------------------------
// Purpose: called when engine starts up initially
//-----------------------------------------------------------------------------
void CounterStrikeViewport::Start( IGameUIFuncs *pGameUIFuncs, IGameEventManager * gameeventmanager )
{
// construct our panels
m_pClassMenu = NULL;
m_pTeamMenu = new CCSTeamMenu(NULL);
m_pBuyMenu = NULL; // buy menu needs money info, so create it at the last possible moment
SetClientDllInterface( &clientInterface );
BaseClass::Start( pGameUIFuncs, gameeventmanager );
m_pPrivateSpectatorGUI = new CCSSpectatorGUI( NULL );
m_pSpectatorGUI = m_pPrivateSpectatorGUI; // override spectator interface so the viewport uses our spectatorUI
m_pPrivateClientScoreBoard = new CCSClientScoreBoardDialog( NULL );
m_pClientScoreBoard = m_pPrivateClientScoreBoard;
}
//-----------------------------------------------------------------------------
// Purpose: sets the parents on our subpanels
//-----------------------------------------------------------------------------
void CounterStrikeViewport::SetParent(vgui::VPANEL parent)
{
BaseClass::SetParent( parent );
if ( m_pClassMenu )
{
m_pClassMenu->SetParent( parent );
}
m_pTeamMenu->SetParent( parent );
if ( m_pBuyMenu )
{
m_pBuyMenu->SetParent( parent );
}
}
//-----------------------------------------------------------------------------
// Purpose: called on each level change
//-----------------------------------------------------------------------------
void CounterStrikeViewport::OnLevelChange(const char * mapname)
{
BaseClass::OnLevelChange( mapname );
}
//-----------------------------------------------------------------------------
// Purpose: hides all vgui menus
//-----------------------------------------------------------------------------
void CounterStrikeViewport::HideAllVGUIMenu( void )
{
BaseClass::HideAllVGUIMenu();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -