Ejemplo n.º 1
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTFDeathMatchScoreBoardDialog::ShowPanel(bool bShow)
{
	// Catch the case where we call ShowPanel before ApplySchemeSettings, eg when
	// going from windowed <-> fullscreen
	if ( m_pImageList == NULL )
	{
		InvalidateLayout( true, true );
	}

	if (!bShow && bLockInput)
	{
		return;
	}

	// Don't show in commentary mode
	if ( IsInCommentaryMode() )
	{
		bShow = false;
	}
	
	if ( IsVisible() == bShow )
	{
		return;
	}

	int iRenderGroup = gHUD.LookupRenderGroupIndexByName( "global" );

	if ( bShow )
	{		
		SetVisible(true);
		SetKeyBoardInputEnabled(false);
		gHUD.LockRenderGroup(iRenderGroup);

		// Clear the selected item, this forces the default to the local player
		SectionedListPanel *pList = GetSelectedPlayerList();
		if (pList)
		{
			pList->ClearSelection();
		}
	}
	else
	{
		SetVisible( false );
		m_pContextMenu->SetVisible(false);
		SetMouseInputEnabled(false);
		SetKeyBoardInputEnabled(false);
		bLockInput = false;
		gHUD.UnlockRenderGroup( iRenderGroup );
	}
}
//-----------------------------------------------------------------------------
// Purpose: Updates the player list
//-----------------------------------------------------------------------------
void CHL2MPClientScoreBoardDialog::UpdatePlayerList()
{
	m_pPlayerListDM->RemoveAll();
	m_pPlayerListR->RemoveAll();
	m_pPlayerListC->RemoveAll();

	C_HL2MP_Player *pLocalPlayer = C_HL2MP_Player::GetLocalHL2MPPlayer();
	if ( !pLocalPlayer )
		return;

	for( int playerIndex = 1 ; playerIndex <= MAX_PLAYERS; playerIndex++ )
	{
		if( g_PR->IsConnected( playerIndex ) )
		{
			SectionedListPanel *pPlayerList = NULL;
			
			// Not teamplay, use the DM playerlist
			if ( !HL2MPRules()->IsTeamplay() )
				pPlayerList = m_pPlayerListDM;
			else
			{
				switch ( g_PR->GetTeam( playerIndex ) )
				{
				case TEAM_REBELS:
					pPlayerList = m_pPlayerListR;
					break;
				case TEAM_COMBINE:
					pPlayerList = m_pPlayerListC;
					break;
				}
			}

			if ( pPlayerList == NULL )
			{
				continue;			
			}

			KeyValues *pKeyValues = new KeyValues( "data" );
			GetPlayerScoreInfo( playerIndex, pKeyValues );

			int itemID = pPlayerList->AddItem( 0, pKeyValues );
			Color clr = g_PR->GetTeamColor( g_PR->GetTeam( playerIndex ) );
			pPlayerList->SetItemFgColor( itemID, clr );

			pKeyValues->deleteThis();
		}
	}
}
//=========================================================
// Reinicio
//=========================================================
void CInventoryPanel::Reset()
{
	BackpackItems->RemoveAll();
	BackpackItems->RemoveAllSections();
	BackpackItems->AddSection(0, "");
	BackpackItems->AddColumnToSection(0, "name", "#Inventory_Backpack", 0, 300);
	BackpackItems->AddColumnToSection(0, "count", "", 0, 100);

	PocketItems->RemoveAll();
	PocketItems->RemoveAllSections();
	PocketItems->AddSection(0, "");
	PocketItems->AddColumnToSection(0, "name", "#Inventory_Pocket", 0, 300);
	PocketItems->AddColumnToSection(0, "count", "", 0, 100);

	BackpackProgress->SetProgress(0.0);
	InventoryProgress->SetProgress(0.0);
}
//-----------------------------------------------------------------------------
// Purpose: Updates the player list
//-----------------------------------------------------------------------------
void CCSClientScoreBoardDialog::UpdatePlayerList()
{
	m_pPlayerListT->RemoveAll();
	m_pPlayerListCT->RemoveAll();

	C_CS_PlayerResource *cs_PR = dynamic_cast<C_CS_PlayerResource *>( g_PR );
	if ( !cs_PR )
		return;

	C_CSPlayer *pLocalPlayer = C_CSPlayer::GetLocalCSPlayer();
	if ( !pLocalPlayer )
		return;

	for( int playerIndex = 1 ; playerIndex <= MAX_PLAYERS; playerIndex++ )
	{
		if( g_PR->IsConnected( playerIndex ) )
		{
			SectionedListPanel *pPlayerList = NULL;
			switch ( g_PR->GetTeam( playerIndex ) )
			{
			case TEAM_TERRORIST:
				pPlayerList = m_pPlayerListT;
				break;
			case TEAM_CT:
				pPlayerList = m_pPlayerListCT;
				break;
			}

			if ( pPlayerList == NULL )
			{
				continue;			
			}

			KeyValues *pKeyValues = new KeyValues( "data" );
			GetPlayerScoreInfo( playerIndex, pKeyValues );

			int itemID = pPlayerList->AddItem( 0, pKeyValues );
			Color clr = g_PR->GetTeamColor( g_PR->GetTeam( playerIndex ) );
			pPlayerList->SetItemFgColor( itemID, clr );

			pKeyValues->deleteThis();
		}
	}
}
void CInventoryPanel::OnCommand(const char* cmd)
{
	int Backpack_pItem			= BackpackItems->GetSelectedItem();
	int Pocket_pItem			= PocketItems->GetSelectedItem();

	const char *pItemClassName	= "";
	const char *pFrom			= "";
	KeyValues *ItemData;
	char com[100];

	// Se ha seleccionado un objeto de la mochila.
	if ( Backpack_pItem != -1 )
	{
		ItemData		= BackpackItems->GetItemData(Backpack_pItem);
		pItemClassName	= ItemData->GetString("classname");
		pFrom			= "backpack";
	}
	// Se ha seleccionado un objeto del bolsillo.
	else if ( Pocket_pItem != -1 )
	{
		ItemData		= PocketItems->GetItemData(Pocket_pItem);
		pItemClassName	= ItemData->GetString("classname");
		pFrom			= "pocket";
	}

	// Ocultar el inventario.
	if ( !Q_stricmp(cmd, "turnoff") )
		cl_inventory.SetValue(0);

	// Tirar un objeto.
	if ( !Q_stricmp(cmd, "dropitem") )
	{
		Q_snprintf(com, sizeof(com), "dropitem %s %s", pFrom, pItemClassName);

		engine->ServerCmd(com);
		cl_update_inventory.SetValue(1);
	}

	// Usar un objeto.
	if ( !Q_stricmp(cmd, "useitem") )
	{
		Q_snprintf(com, sizeof(com), "useitem %s %s", pFrom, pItemClassName);

		engine->ServerCmd(com);
		cl_update_inventory.SetValue(1);
	}

	// Mover un objeto.
	if ( !Q_stricmp(cmd, "moveitem") )
	{
		const char *pTo = "backpack";

		if ( pFrom == "backpack" )
			pTo = "pocket";

		Q_snprintf(com, sizeof(com), "moveitem %s %s %s", pFrom, pTo, pItemClassName);

		engine->ServerCmd(com);
		cl_update_inventory.SetValue(1);
	}
}
//=========================================================
// Bucle de ejecución de tareas.
//=========================================================
void CInventoryPanel::OnTick()
{
	BaseClass::OnTick();
	C_IN_Player *pPlayer = (C_IN_Player *)C_BasePlayer::GetLocalPlayer();

	if ( !pPlayer )
	{
		SetVisible(false);
		return;
	}

	if ( cl_update_inventory.GetBool() )
	{
		// Obtenemos los limites del inventario.
		ConVarRef sv_max_inventory_backpack("sv_max_inventory_backpack");
		ConVarRef sv_max_inventory_pocket("sv_max_inventory_pocket");

		// Lo devolvemos a 0
		cl_update_inventory.SetValue(0);

		// Removemos todos los objetos.
		BackpackItems->RemoveAll();
		PocketItems->RemoveAll();

		int pEntity;
		const char *pItemName;
		const char *pItemClassName;

		float pBackpackCountItems	= 0;
		float pPocketCountItems		= 0;

		int pBackpackItems[100];
		int pPocketItems[100];

		// Iniciamos los array
		for ( int i = 0; i < ARRAYSIZE(pBackpackItems); i++ )
			pBackpackItems[i]	= 0;
		for ( int i = 0; i < ARRAYSIZE(pPocketItems); i++ )
			pPocketItems[i]		= 0;
		
		// Mochila
		// Primero obtenemos todos los objetos y los agrupamos en array.
		for ( int i = 1; i < ARRAYSIZE(pBackpackItems); i++ )
		{
			pEntity	= pPlayer->Inventory_GetItem(i, INVENTORY_BACKPACK);

			// No hay nada en este Slot
			if ( pEntity == 0 )
				continue;

			// Aquí vamos contando los objetos de este mismo tipo.
			// !!!NOTE: Todo esto fue desarrollado por alguien que no sabe mucho C++... Odio los array de C++...
			pBackpackItems[pEntity] = (pBackpackItems[pEntity] + 1);
			pBackpackCountItems++;			
		}
		// Ahora obtenemos la lista de objetos con su respectiva cantidad y la mostramos.
		for ( int i = 1; i < ARRAYSIZE(pBackpackItems); i++ )
		{
			// !!!NOTE: i ahora es la ID del objeto
			if ( pBackpackItems[i] == 0 || !pBackpackItems[i] )
				continue;

			pItemName		= pPlayer->Inventory_GetItemNameByID(i);
			pItemClassName	= pPlayer->Inventory_GetItemClassNameByID(i);

			// No hay nada en este Slot
			if ( pItemName == "" || pItemClassName == "" )
				continue;

			// Agregamos el objeto.
			KeyValues *itemData = new KeyValues("data");
			itemData->SetString("name",			pItemName);
			itemData->SetString("classname",	pItemClassName);
			itemData->SetInt("count",			pBackpackItems[i]);
			BackpackItems->AddItem(0, itemData);
		}

		// Bolsillo
		// Primero obtenemos todos los objetos y los agrupamos en array.
		for ( int i = 1; i < ARRAYSIZE(pPocketItems); i++ )
		{
			pEntity	= pPlayer->Inventory_GetItem(i, INVENTORY_POCKET);

			// No hay nada en este Slot
			if ( pEntity == 0 )
				continue;

			// Aquí vamos contando los objetos de este mismo tipo.
			// !!!NOTE: Todo esto fue desarrollado por alguien que no sabe mucho C++... Odio los array de C++...
			pPocketItems[pEntity] = (pPocketItems[pEntity] + 1);
			pPocketCountItems++;			
		}
		// Ahora obtenemos la lista de objetos con su respectiva cantidad y la mostramos.
		for ( int i = 1; i < ARRAYSIZE(pPocketItems); i++ )
		{
			// !!!NOTE: i ahora es la ID del objeto
			if ( pPocketItems[i] == 0 || !pPocketItems[i] )
				continue;

			pItemName		= pPlayer->Inventory_GetItemNameByID(i);
			pItemClassName	= pPlayer->Inventory_GetItemClassNameByID(i);

			if ( pItemName == "" || pItemClassName == "" )
				continue;

			KeyValues *itemData = new KeyValues("data");
			itemData->SetString("name",			pItemName);
			itemData->SetString("classname",	pItemClassName);
			itemData->SetInt("count",			pPocketItems[i]);
			PocketItems->AddItem(0, itemData);
		}

		// Actualizamos las barras de llenado.
		BackpackProgress->SetProgress( pBackpackCountItems / sv_max_inventory_backpack.GetFloat() );
		InventoryProgress->SetProgress( pPocketCountItems / sv_max_inventory_pocket.GetFloat() );
	}

	SetVisible(cl_inventory.GetBool());
}
Ejemplo n.º 7
0
//-----------------------------------------------------------------------------
// Purpose: Updates the player list
//-----------------------------------------------------------------------------
void CTFDeathMatchScoreBoardDialog::UpdatePlayerList()
{
	int iSelectedPlayerIndex = GetLocalPlayerIndex();

	// Save off which player we had selected
	SectionedListPanel *pList = GetSelectedPlayerList();

	if ( pList )
	{
		int itemID = pList->GetSelectedItem();

		if ( itemID >= 0 )
		{
			KeyValues *pInfo = pList->GetItemData( itemID );
			if ( pInfo )
			{
				iSelectedPlayerIndex = pInfo->GetInt( "playerIndex" );
			}
		}
	}	

	m_pPlayerListRed->RemoveAll();

	C_TF_PlayerResource *tf_PR = dynamic_cast<C_TF_PlayerResource *>( g_PR );
	if ( !tf_PR )
		return;
	C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
	if ( !pLocalPlayer )
		return;

	int localteam = pLocalPlayer->GetTeamNumber();

	bool bMadeSelection = false;

	for( int playerIndex = 1 ; playerIndex <= MAX_PLAYERS; playerIndex++ )
	{
		if( g_PR->IsConnected( playerIndex ) )
		{
			SectionedListPanel *pPlayerList = NULL;
			switch ( g_PR->GetTeam( playerIndex ) )
			{
			case TF_TEAM_RED:
				pPlayerList = m_pPlayerListRed;
				break;
			}
			if ( null == pPlayerList )
				continue;			

			const char *szName = tf_PR->GetPlayerName(playerIndex);
			int score = tf_PR->GetTotalScore(playerIndex);
			int kills = tf_PR->GetPlayerScore(playerIndex);
			int deaths = tf_PR->GetDeaths(playerIndex);
			int streak = tf_PR->GetKillstreak(playerIndex);

			KeyValues *pKeyValues = new KeyValues( "data" );

			pKeyValues->SetInt( "playerIndex", playerIndex );
			pKeyValues->SetString( "name", szName );
			pKeyValues->SetInt("score", score);
			pKeyValues->SetInt("kills", kills);
			pKeyValues->SetInt("deaths", deaths);
			pKeyValues->SetInt("streak", streak);

			// can only see class information if we're on the same team
			if ( !AreEnemyTeams( g_PR->GetTeam( playerIndex ), localteam ) && !( localteam == TEAM_UNASSIGNED ) )
			{
				// class name
				if( g_PR->IsConnected( playerIndex ) )
				{
					int iClass = tf_PR->GetPlayerClass( playerIndex );
					if ( GetLocalPlayerIndex() == playerIndex && !tf_PR->IsAlive( playerIndex ) ) 
					{
						// If this is local player and he is dead, show desired class (which he will spawn as) rather than current class.
						C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
						int iDesiredClass = pPlayer->m_Shared.GetDesiredPlayerClassIndex();
						// use desired class unless it's random -- if random, his future class is not decided until moment of spawn
						if ( TF_CLASS_RANDOM != iDesiredClass )
						{
							iClass = iDesiredClass;
						}
					} 
					else 
					{
						// for non-local players, show the current class
						iClass = tf_PR->GetPlayerClass( playerIndex );
					}
				}				
			}
			else
			{
				C_TFPlayer *pPlayerOther = ToTFPlayer( UTIL_PlayerByIndex( playerIndex ) );

				if ( pPlayerOther && pPlayerOther->m_Shared.IsPlayerDominated( pLocalPlayer->entindex() ) )
				{
					// if local player is dominated by this player, show a nemesis icon
					pKeyValues->SetInt( "nemesis", m_iImageNemesis );
				}
				else if ( pLocalPlayer->m_Shared.IsPlayerDominated( playerIndex) )
				{
					// if this player is dominated by the local player, show the domination icon
					pKeyValues->SetInt( "nemesis", m_iImageDominated );
				}
			}

			// display whether player is alive or dead (all players see this for all other players on both teams)
			pKeyValues->SetInt( "status", tf_PR->IsAlive( playerIndex ) ?  0 : m_iImageDead );

			if ( g_PR->GetPing( playerIndex ) < 1 )
			{
				if ( g_PR->IsFakePlayer( playerIndex ) )
				{
					pKeyValues->SetString( "ping", "#TF_Scoreboard_Bot" );
				}
				else
				{
					pKeyValues->SetString( "ping", "" );
				}
			}
			else
			{
				pKeyValues->SetInt( "ping", g_PR->GetPing( playerIndex ) );
			}


			UpdatePlayerAvatar( playerIndex, pKeyValues );
			
			int itemID = pPlayerList->AddItem( 0, pKeyValues );

			Color clr = tf_PR->GetPlayerColor(playerIndex);
			pPlayerList->SetItemFgColor( itemID, clr );

			if ( iSelectedPlayerIndex == playerIndex )
			{
				bMadeSelection = true;
				pPlayerList->SetSelectedItem( itemID );
			}

			pKeyValues->deleteThis();
		}
	}

	// If we're on spectator, find a default selection
	if ( !bMadeSelection )
	{
		if ( m_pPlayerListRed->GetItemCount() > 0 )
		{
			m_pPlayerListRed->SetSelectedItem( 0 );
		}
	}

	ResizeScoreboard();
}