⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vgui_teamfortressviewport.cpp

📁 hl2 source code. Do not use it illegal.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		m_pMapBriefing->Activate( cTitle, pfile );
		break;

	case MENU_SPECHELP:
		m_pSpectatorGUI->SetVisible(false); // hide the spectator UI, closing the spec help one reveals it again
		m_pSpecHelp->Activate( "#Spec_Help_Title", "#Spec_Help_Text" );
		break;
		
	case MENU_CLASS:
		m_pClassMenu->Update(m_iValidClasses, 5);
		m_pClassMenu->Activate();
		break;

	default:
		break;
	}
}

//-----------------------------------------------------------------------------
// Purpose: returns true if iMenu's menu is visible (i.e active)
//-----------------------------------------------------------------------------
bool TeamFortressViewport::IsVGUIMenuActive( int iMenu )
{
	switch ( iMenu )
	{
	case MENU_TEAM:		
		return (m_pTeamMenu->IsVisible() || m_pClientScoreBoard->IsVisible());
		break;

	case MENU_INTRO:
		return (m_pMOTD->IsVisible() || m_pClientScoreBoard->IsVisible());
		break;

	case MENU_CLASSHELP:
		return m_pClassHelp->IsVisible();
		break;

	case MENU_SPECHELP:
		return m_pSpecHelp->IsVisible();
		break;

	case MENU_MAPBRIEFING:
		return m_pMapBriefing->IsVisible();
		break;
		
	case MENU_CLASS:
		return (m_pClassMenu->IsVisible() || m_pClientScoreBoard->IsVisible());
		break;

	default:
		break;
	}
	return false;
}

//-----------------------------------------------------------------------------
// Purpose: hides the menu specified by iMenu
//-----------------------------------------------------------------------------
void TeamFortressViewport::HideVGUIMenu( int iMenu )
{
	switch ( iMenu )
	{
	case MENU_TEAM:		
		m_pTeamMenu->SetVisible( false );
		break;

	case MENU_INTRO:
		m_pMOTD->SetVisible( false );
		break;

	case MENU_CLASSHELP:
		m_pClassHelp->SetVisible( false );
		break;

	case MENU_SPECHELP:
		m_pSpecHelp->SetVisible( false );
		break;

	case MENU_MAPBRIEFING:
		m_pMapBriefing->SetVisible( false );
		break;
		
	case MENU_CLASS:
		m_pClassMenu->SetVisible( false );
		break;

	default:
		break;
	}
}


// Return TRUE if the HUD's allowed to print text messages
bool TeamFortressViewport::AllowedToPrintText( void )
{
	int iId = GetCurrentMenuID();
	if ( iId == MENU_TEAM || iId == MENU_CLASS || iId == MENU_INTRO || iId == MENU_CLASSHELP )
		return false;
	return true;
}





//======================================================================================
// UPDATE HUD SECTIONS
//======================================================================================
void HudMessage(char *str)
{
	gViewPortInterface->GetClientDllInterface()->MessageHud(NULL,strlen(str)+1,static_cast<void *>(str));
}

//-----------------------------------------------------------------------------
// Purpose: returns true if a particular class is valid for this map
//-----------------------------------------------------------------------------
int GetValidClasses(int playerClass)
{
	return gViewPortInterface->GetValidClasses(playerClass);
}


//-----------------------------------------------------------------------------
// Purpose: Updates each players info structure
//-----------------------------------------------------------------------------
void TeamFortressViewport::GetAllPlayersInfo( void )
{
}

//-----------------------------------------------------------------------------
// Purpose: think function, called in hud_redraw.cpp:Think()
//-----------------------------------------------------------------------------
void TeamFortressViewport::OnTick()
{
	// See if the Spectator Menu needs to be update
	
	if ( m_pClientDllInterface->IsSpectator() && !m_pSpectatorGUI->IsVisible()  ) 
	{
		GetAllPlayersInfo();
		m_pSpectatorGUI->Activate();
	}
	else if ( !m_pClientDllInterface->IsSpectator() && m_pSpectatorGUI->IsVisible() )
	{
		m_pSpectatorGUI->Deactivate();
	}

/*	else if ( false spec panel needs an update )
	{
		UpdateSpectatorPanel();
	}
	

	if ( IsSpectatorGUIVisible() )
	{
		GetAllPlayersInfo();
	} */

	// Update the Scoreboard, if it's visible
	if ( m_pClientScoreBoard->IsVisible() && m_pClientDllInterface->HudTime() > m_flScoreBoardLastUpdated )
	{
		m_flScoreBoardLastUpdated = ((float)m_pClientDllInterface->HudTime() + 1.0);

		GetAllPlayersInfo();
		m_pClientScoreBoard->Update(m_szServerName, m_pClientDllInterface->TeamPlay(), m_pSpectatorGUI->IsVisible());
	}

	if( m_PendingDialogs.Count() > 1 && !IsVGUIMenuActive( m_PendingDialogs.Head() ) ) // last show menu isn't active, show the next
	{
		m_PendingDialogs.RemoveAtHead();
		int menu = m_PendingDialogs.Head();
	
		m_pBackGround->SetVisible( true );
	
		DisplayVGUIMenu( menu );
	}
	else if ( m_PendingDialogs.Count() == 1 && !IsVGUIMenuActive( m_PendingDialogs.Head()) )
	{
		m_PendingDialogs.RemoveAtHead(); // the menu at the top of the queue is not showing so delete it
	}
 
}

//-----------------------------------------------------------------------------
// Purpose: Direct Key Input
//-----------------------------------------------------------------------------
int	TeamFortressViewport::KeyInput( int down, int keynum, const char *pszCurrentBinding )
{
	// Enter gets out of Spectator Mode by bringing up the Team Menu
	if ( m_pClientDllInterface->IsSpectator() )
	{
		if ( down && (keynum == K_ENTER || keynum == K_KP_ENTER) )
			ShowVGUIMenu( MENU_TEAM );
	}
	return 1;
}

//-----------------------------------------------------------------------------
// Purpose: Activate's the player special ability
//			called when the player hits their "special" key
//-----------------------------------------------------------------------------
void TeamFortressViewport::InputPlayerSpecial( void )
{
	if (!m_bInitialized)
		return;

	// if it's any other class, just send the command down to the server
	m_pClientDllInterface->ClientCmd( "_special" );
}



//-----------------------------------------------------------------------------
// Purpose: Sets the parent for each panel to use
//-----------------------------------------------------------------------------
void TeamFortressViewport::SetParent(vgui::VPANEL parent)
{
	EditablePanel::SetParent( parent );

	m_pBackGround->SetParent( (vgui::VPANEL)parent );
	m_pClientScoreBoard->SetParent((vgui::VPANEL)parent);
	m_pMOTD->SetParent((vgui::VPANEL)parent);
	m_pSpectatorGUI->SetParent((vgui::VPANEL)parent);
	m_pTeamMenu->SetParent((vgui::VPANEL)parent);
	m_pClassMenu->SetParent((vgui::VPANEL)parent);
	m_pSpecHelp->SetParent((vgui::VPANEL)parent);
	m_pClassHelp->SetParent((vgui::VPANEL)parent);
	m_pMapBriefing->SetParent((vgui::VPANEL)parent);
	m_pCommandMenu->SetParent((vgui::VPANEL)parent);
	m_pMapOverview->SetParent((vgui::VPANEL)parent);
	
	m_pClientScoreBoard->SetMouseInputEnabled(false); // the SetParent() call resets this	
}

//-----------------------------------------------------------------------------
// Purpose: called when the engine shows the base client VGUI panel (i.e when entering a new level or exiting GameUI )
//-----------------------------------------------------------------------------
void TeamFortressViewport::ActivateClientUI() 
{
}

//-----------------------------------------------------------------------------
// Purpose: called when the engine hides the base client VGUI panel (i.e when the GameUI is comming up ) 
//-----------------------------------------------------------------------------
void TeamFortressViewport::HideClientUI()
{
}


//-----------------------------------------------------------------------------
// Purpose: updates the scoreboard when something changes
//-----------------------------------------------------------------------------
void TeamFortressViewport::UpdateScoreBoard()
{
	GetAllPlayersInfo();
	m_pClientScoreBoard->RebuildTeams(m_szServerName,m_pClientDllInterface->TeamPlay(),  m_pSpectatorGUI->IsVisible());
}

//-----------------------------------------------------------------------------
// Purpose: passes death msgs to the scoreboard to display specially
//-----------------------------------------------------------------------------
void TeamFortressViewport::DeathMsg( int killer, int victim )
{
	m_pClientScoreBoard->DeathMsg(killer,victim);
	if ( victim == m_pClientDllInterface->GetLocalPlayerIndex() )
	{
		UpdateSpectatorPanel();
	}
}

//-----------------------------------------------------------------------------
// Purpose: Hides all the VGUI menus at once (except the scoreboard, as it is used in intermissions)
//-----------------------------------------------------------------------------
void TeamFortressViewport::HideAllVGUIMenu()
{
	m_pTeamMenu->SetVisible(false);
	m_pClassMenu->SetVisible(false);
	m_pMOTD->SetVisible(false);
	m_pSpecHelp->SetVisible(false);
	m_pClassHelp->SetVisible(false);
	m_pMapBriefing->SetVisible(false);
	m_pSpectatorGUI->SetVisible(false);
	m_pCommandMenu->SetVisible(false);
		
	m_PendingDialogs.Purge(); // clear the dialog queue
}


//-----------------------------------------------------------------------------
// Purpose: returns the current map, tries to determine it if the string is empty
/*-----------------------------------------------------------------------------
const char *TeamFortressViewport::GetMapName()
{
	if( strlen(m_sMapName) <= 0 )
	{
		m_pClientDllInterface->COM_FileBase( const_cast<char *>(m_pClientDllInterface->GetLevelName()), m_sMapName );
	}
	return m_sMapName; 
}*/


//-----------------------------------------------------------------------------
// Purpose: called on each level change, resets the map name and hides all vgui menus
//-----------------------------------------------------------------------------
void TeamFortressViewport::OnLevelChange(const char * mapname)
{
	m_flScoreBoardLastUpdated = 0;
	
	HideAllVGUIMenu();

	m_pClientScoreBoard->Reset();

	if ( m_pSpectatorGUI )
	{
		m_pSpectatorGUI->SetVisible(false);
	}
	
	if ( m_pClientScoreBoard )
	{
		m_pClientScoreBoard->SetVisible(false);
	}

	if ( m_pMapOverview )
	{
		m_pMapOverview->SetMap( mapname );
	}

}

//-----------------------------------------------------------------------------
// Purpose: handle showing and hiding of the command menu
//-----------------------------------------------------------------------------
void TeamFortressViewport::ShowCommandMenu()
{
	// m_pCommandPanel->ShowCommandPanel();

	if ( m_pCommandMenu->IsVisible() )
		return;

	// check, if we must update command menu before showing it

	bool bNeedUpdate = false;

	// has our team number changed?
	if ( m_iCurrentTeamNumber != gViewPortInterface->GetClientDllInterface()->TeamNumber() )
	{
		m_iCurrentTeamNumber = gViewPortInterface->GetClientDllInterface()->TeamNumber();
		bNeedUpdate = true;
	}

	// has the map changed?
	const char *pszLevel = gViewPortInterface->GetClientDllInterface()->GetLevelName();
	
	if ( pszLevel )
	{
		// Does it match the current map name?
		if ( strcmp( pszLevel, m_szCurrentMap ) != 0 )
		{
			strncpy( m_szCurrentMap, pszLevel, 256 - 1 );
			m_szCurrentMap[256 - 1] = '\0';
			bNeedUpdate = true;
		}
	}

	if ( bNeedUpdate )
	{
		UpdateCommandMenu();
	}

	m_pCommandMenu->SetVisible( true );
}

void TeamFortressViewport::UpdateCommandMenu()
{
	int iWide, iTall, screenW, screenH;

	m_pCommandMenu->RebuildMenu();
	
	// check screen position

	m_pCommandMenu->GetSize( iWide, iTall);
	surface()->GetScreenSize( screenW, screenH );

	// center it vertically on the left-hand side of the screen
	int y =  ( screenH - iTall ) / 2;
	if ( y < 0 ) // make sure the beginning of the menu is on the screen
	{
		y = 0;
	}

	m_pCommandMenu->SetPos( 0, y );
}

void TeamFortressViewport::HideCommandMenu()
{
	// m_pCommandPanel->HideCommandPanel();
	m_pCommandMenu->SetVisible( false );

}

int TeamFortressViewport::IsCommandMenuVisible()
{
	return m_pCommandMenu->IsVisible();
}

//================================================================
// Number Key Input
bool TeamFortressViewport::SlotInput( int iSlot )
{
	// If the command menu is up, give it the input
	return false; // m_pCommandPanel->SlotInput( iSlot ); TODO ?
}

void TeamFortressViewport::ChatInputPosition(int *x, int *y )
{
	if ( m_pClientDllInterface->GetSpectatorMode() != 0 || m_pClientDllInterface->IsHLTVMode() )
	{
		if ( m_pClientDllInterface->PipInsetOff() )
		{
			*y = m_pSpectatorGUI->GetTopBarHeight() + 5;
		}
		else
		{
			// int tmpX, tmpY, dummy;

			// m_pClientDllInterface->InsetValues( tmpX, tmpY, dummy, dummy);
			// *y =  tmpY + 5 ;
			*y = 0;
			*x = 0;

		}
	}
}

//-----------------------------------------------------------------------------
// Purpose: handle showing and hiding of the command menu
//-----------------------------------------------------------------------------
VGuiLibraryInterface_t *TeamFortressViewport::GetClientDllInterface()
{
	return m_pClientDllInterface;
}

void TeamFortressViewport::SetClientDllInterface(VGuiLibraryInterface_t *clientInterface)
{
	m_pClientDllInterface = clientInterface;
	Assert( m_pClientDllInterface );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -