//========= Copyright Valve Corporation, All rights reserved. ============// // // Purpose: // // $NoKeywords: $ //=============================================================================// #include "cbase.h" #include "tf_hud_arena_winpanel.h" #include "tf_hud_statpanel.h" #include "tf_spectatorgui.h" #include "vgui_controls/AnimationController.h" #include "iclientmode.h" #include "engine/IEngineSound.h" #include "c_tf_playerresource.h" #include "c_tf_team.h" #include "tf_clientscoreboard.h" #include #include #include #include #include "vgui_avatarimage.h" #include "fmtstr.h" #include "teamplayroundbased_gamerules.h" #include "tf_gamerules.h" #include "tf_hud_menu_taunt_selection.h" // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" extern ConVar tf_arena_max_streak; extern ConVar mp_bonusroundtime; extern const char *FormatSeconds( int seconds ); //----------------------------------------------------------------------------- // Purpose: Constructor //----------------------------------------------------------------------------- CTFArenaWinPanel::CTFArenaWinPanel( IViewPort *pViewPort ) : EditablePanel( NULL, "ArenaWinPanel" ) { SetAlpha( 0 ); SetScheme( "ClientScheme" ); m_pTeamScorePanel = new EditablePanel( this, "ArenaWinPanelScores" ); m_pWinnerPanel = new EditablePanel( this, "ArenaWinPanelWinnersPanel" ); m_pLoserPanel = new EditablePanel( this, "ArenaWinPanelLosersPanel" ); m_flTimeUpdateTeamScore = 0; m_flFlipScoresTimes = 0; m_iBlueTeamScore = 0; m_iRedTeamScore = 0; ListenForGameEvent( "arena_win_panel" ); ListenForGameEvent( "teamplay_round_start" ); ListenForGameEvent( "teamplay_game_over" ); ListenForGameEvent( "tf_game_over" ); m_bShouldBeVisible = false; vgui::ivgui()->AddTickSignal( GetVPanel(), 50 ); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFArenaWinPanel::ApplySettings( KeyValues *inResourceData ) { BaseClass::ApplySettings( inResourceData ); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFArenaWinPanel::Reset( void ) { Update(); m_bShouldBeVisible = false; } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFArenaWinPanel::Update( void ) { } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFArenaWinPanel::SetVisible( bool state ) { if ( state == IsVisible() ) return; int iRenderGroup = gHUD.LookupRenderGroupIndexByName( "mid" ); if ( state ) { gHUD.LockRenderGroup( iRenderGroup ); } else { gHUD.UnlockRenderGroup( iRenderGroup ); } BaseClass::SetVisible( state ); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFArenaWinPanel::FireGameEvent( IGameEvent * event ) { const char *pEventName = event->GetName(); if ( Q_strcmp( "teamplay_round_start", pEventName ) == 0 ) { m_bShouldBeVisible = false; } else if ( Q_strcmp( "teamplay_game_over", pEventName ) == 0 ) { m_bShouldBeVisible = false; } else if ( Q_strcmp( "tf_game_over", pEventName ) == 0 ) { m_bShouldBeVisible = false; } else if ( Q_strcmp( "arena_win_panel", pEventName ) == 0 ) { if ( !g_PR ) return; m_vecPlayerScore.RemoveAll(); InvalidateLayout( false, true ); if ( TFGameRules() && TFGameRules()->IsInArenaMode() == true && tf_arena_max_streak.GetInt() > 0 && tf_arena_use_queue.GetBool() == true ) { m_pArenaStreakPanel->SetVisible( true ); m_pArenaStreakLabel->SetVisible( true ); wchar_t wzStreaNum[16]; wchar_t wzStreakString[256]=L""; _snwprintf( wzStreaNum, ARRAYSIZE( wzStreaNum ), L"%i", tf_arena_max_streak.GetInt() ); g_pVGuiLocalize->ConstructString_safe( wzStreakString, g_pVGuiLocalize->Find( "#TF_Arena_PlayingTo" ), 1, wzStreaNum ); m_pTeamScorePanel->SetDialogVariable( "arenastreaktext", wzStreakString ); } else { m_pArenaStreakPanel->SetVisible( false ); m_pArenaStreakLabel->SetVisible( false ); } m_iWinningPlayerTeam = event->GetInt( "winning_team" ); int iWinReason = event->GetInt( "winreason" ); SetDialogVariable( "WinningTeamLabel", "" ); SetDialogVariable( "AdvancingTeamLabel", "" ); SetDialogVariable( "WinReasonLabel", "" ); SetDialogVariable( "DetailsLabel", "" ); vgui::ImagePanel *pImagePanelBG = dynamic_cast( FindChildByName("WinPanelBG") ); Assert( pImagePanelBG ); if ( !pImagePanelBG ) return; // set the appropriate background image and label text const wchar_t *pTeamLabel = L""; const wchar_t *pTopPlayersLabel = L""; const wchar_t *pLocalizedTeamName = L""; const wchar_t *pLocalizedLoserTeamName = L""; C_TFTeam *pBlueTeam = GetGlobalTFTeam( TF_TEAM_BLUE ); const wchar_t *pBlueTeamName = pBlueTeam ? pBlueTeam->Get_Localized_Name() : L"BLU"; C_TFTeam *pRedTeam = GetGlobalTFTeam( TF_TEAM_RED ); const wchar_t *pRedTeamName = pRedTeam ? pRedTeam->Get_Localized_Name() : L"RED"; switch ( m_iWinningPlayerTeam ) { case TF_TEAM_BLUE: pImagePanelBG->SetImage( "../hud/winpanel_blue_bg_main.vmt" ); pTopPlayersLabel = g_pVGuiLocalize->Find( "#Winpanel_BlueMVPs" ); pLocalizedTeamName = pBlueTeamName; pLocalizedLoserTeamName = pRedTeamName; break; case TF_TEAM_RED: pImagePanelBG->SetImage( "../hud/winpanel_red_bg_main.vmt" ); pTopPlayersLabel = g_pVGuiLocalize->Find( "#Winpanel_RedMVPs" ); pLocalizedTeamName = pRedTeamName; pLocalizedLoserTeamName = pBlueTeamName; break; case TEAM_UNASSIGNED: // stalemate pImagePanelBG->SetImage( "../hud/winpanel_black_bg_main.vmt" ); pTeamLabel = g_pVGuiLocalize->Find( "#Winpanel_Stalemate" ); pTopPlayersLabel = g_pVGuiLocalize->Find( "#Winpanel_TopPlayers" ); break; default: Assert( false ); break; } SetDialogVariable( "TopPlayersLabel", pTopPlayersLabel ); wchar_t wzTeamWin[256] = L""; if ( TFGameRules() && TFGameRules()->IsInTournamentMode() ) { g_pVGuiLocalize->ConstructString_safe( wzTeamWin, g_pVGuiLocalize->Find( "#Winpanel_TournamentTeamWins" ), 1, pLocalizedTeamName ); g_pVGuiLocalize->ConstructString_safe( m_wzTeamLose, g_pVGuiLocalize->Find( "#Winpanel_TournamentTeamLost" ), 2, pLocalizedLoserTeamName ); wchar_t wzTeamMPVs[256]; g_pVGuiLocalize->ConstructString_safe( wzTeamMPVs, g_pVGuiLocalize->Find( "#Winpanel_TournamentMVPs" ), 1, pLocalizedTeamName ); if ( m_iWinningPlayerTeam != TEAM_UNASSIGNED ) { SetDialogVariable( "TopPlayersLabel", wzTeamMPVs ); } } else if ( m_iWinningPlayerTeam != TEAM_UNASSIGNED ) { g_pVGuiLocalize->ConstructString_safe( wzTeamWin, g_pVGuiLocalize->Find( "#Winpanel_TeamWins" ), 2, pLocalizedTeamName, g_pVGuiLocalize->Find( "#Winpanel_Team1" ) ); g_pVGuiLocalize->ConstructString_safe( m_wzTeamLose, g_pVGuiLocalize->Find( "#Winpanel_TeamLost" ), 2, pLocalizedLoserTeamName, g_pVGuiLocalize->Find( "#Winpanel_Team1" ) ); } if ( m_iWinningPlayerTeam != TEAM_UNASSIGNED ) { pTeamLabel = wzTeamWin; } SetDialogVariable( "WinningTeamLabel", pTeamLabel ); SetDialogVariable( "LosingTeamLabel", "" ); wchar_t wzWinReason[256] = L""; switch ( iWinReason ) { case WINREASON_ALL_POINTS_CAPTURED: g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_AllPointsCaptured" ), 1, pLocalizedTeamName ); break; case WINREASON_OPPONENTS_DEAD: if ( TFGameRules() && TFGameRules()->IsInArenaMode() == true ) { g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_Arena" ), 1, pLocalizedTeamName ); } else { g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_OpponentsDead" ), 1, pLocalizedTeamName ); } break; case WINREASON_STALEMATE: if ( !TFGameRules() || !TFGameRules()->IsCompetitiveMode() ) { g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_Stalemate" ), 0 ); } break; default: Assert( false ); break; } SetDialogVariable( "WinReasonLabel", wzWinReason ); m_bWasFlawlessVictory = IsFlawlessVictory(); if ( WINREASON_ALL_POINTS_CAPTURED == iWinReason ) { // if this was a full round that ended with point capture or flag capture, show the winning cappers const char *pCappers = event->GetString( "cappers" ); int iCappers = Q_strlen( pCappers ); if ( iCappers > 0 ) { char szPlayerNames[256]=""; wchar_t wzPlayerNames[256]=L""; wchar_t wzCapMsg[512]=L""; for ( int i = 0; i < iCappers; i++ ) { Q_strncat( szPlayerNames, g_PR->GetPlayerName( (int) pCappers[i] ), ARRAYSIZE( szPlayerNames ) ); if ( i < iCappers - 1 ) { Q_strncat( szPlayerNames, ", ", ARRAYSIZE( szPlayerNames ) ); } } g_pVGuiLocalize->ConvertANSIToUnicode( szPlayerNames, wzPlayerNames, sizeof( wzPlayerNames ) ); g_pVGuiLocalize->ConstructString_safe( wzCapMsg, g_pVGuiLocalize->Find( "#Winpanel_WinningCapture" ), 1, wzPlayerNames ); SetDialogVariable( "DetailsLabel", wzCapMsg ); } } else if ( TFGameRules()->IsInArenaMode() == true && m_iWinningPlayerTeam != TEAM_UNASSIGNED ) { if ( m_bWasFlawlessVictory ) { SetDialogVariable( "DetailsLabel", g_pVGuiLocalize->Find( "#TF_Arena_FlawlessVictory" ) ); } } // get the current & previous team scores int iBlueTeamPrevScore = event->GetInt( "blue_score_prev", 0 ); int iRedTeamPrevScore = event->GetInt( "red_score_prev", 0 ); m_iBlueTeamScore = event->GetInt( "blue_score", 0 ); m_iRedTeamScore = event->GetInt( "red_score", 0 ); if ( m_pTeamScorePanel ) { m_pTeamScorePanel->SetDialogVariable( "blueteamname", pBlueTeamName ); m_pTeamScorePanel->SetDialogVariable( "redteamname", pRedTeamName ); // set the previous team scores in scoreboard m_pTeamScorePanel->SetDialogVariable( "blueteamscore", iBlueTeamPrevScore ); m_pTeamScorePanel->SetDialogVariable( "redteamscore", iRedTeamPrevScore ); if ( ( m_iBlueTeamScore != iBlueTeamPrevScore ) || ( m_iRedTeamScore != iRedTeamPrevScore ) ) { // if the new scores are different, set ourselves to update the scoreboard to the new values after a short delay, so players // see the scores tick up m_flTimeUpdateTeamScore = gpGlobals->curtime + 3.5f; } // only show team scores if round is complete m_pTeamScorePanel->SetVisible( true ); } if ( !g_TF_PR ) return; int iPanelIndex = 0; // look for the top 6 players sent in the event for ( int i = 1; i <= 6; i++ ) { iPanelIndex = (iPanelIndex % 3) + 1; EditablePanel *pParentPanel = NULL; if ( i <= 3 ) { pParentPanel = m_pWinnerPanel; } else { pParentPanel = m_pLoserPanel; } vgui::Label *pPlayerName = dynamic_cast