//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFWinPanel::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( "teamplay_win_panel", pEventName ) == 0 ) { if ( !g_PR ) return; int iWinningTeam = event->GetInt( "winning_team" ); int iWinReason = event->GetInt( "winreason" ); int iFlagCapLimit = event->GetInt( "flagcaplimit" ); bool bRoundComplete = (bool) event->GetInt( "round_complete" ); int iRoundsRemaining = event->GetInt( "rounds_remaining" ); LoadControlSettings( "resource/UI/WinPanel.res" ); InvalidateLayout( false, true ); SetDialogVariable( "WinningTeamLabel", "" ); SetDialogVariable( "AdvancingTeamLabel", "" ); SetDialogVariable( "WinReasonLabel", "" ); SetDialogVariable( "DetailsLabel", "" ); vgui::ImagePanel *pImagePanelBG = dynamic_cast<vgui::ImagePanel *>( FindChildByName("WinPanelBG") ); Assert( pImagePanelBG ); if ( !pImagePanelBG ) return; // set the appropriate background image and label text const char *pTeamLabel = NULL; const char *pTopPlayersLabel = NULL; const wchar_t *pLocalizedTeamName = NULL; // this is an area defense, but not a round win, if this was a successful defend until time limit but not a complete round bool bIsAreaDefense = ( ( WINREASON_DEFEND_UNTIL_TIME_LIMIT == iWinReason ) && !bRoundComplete ); switch ( iWinningTeam ) { case TF_TEAM_BLUE: pImagePanelBG->SetImage( "../hud/winpanel_blue_bg_main.vmt" ); pTeamLabel = ( bRoundComplete ? "#Winpanel_BlueWins" : ( bIsAreaDefense ? "#Winpanel_BlueDefends" : "#Winpanel_BlueAdvances" ) ); pTopPlayersLabel = "#Winpanel_BlueMVPs"; pLocalizedTeamName = g_pVGuiLocalize->Find( "TF_BlueTeam_Name" ); break; case TF_TEAM_RED: pImagePanelBG->SetImage( "../hud/winpanel_red_bg_main.vmt" ); pTeamLabel = ( bRoundComplete ? "#Winpanel_RedWins" : ( bIsAreaDefense ? "#Winpanel_RedDefends" : "#Winpanel_RedAdvances" ) ); pTopPlayersLabel = "#Winpanel_RedMVPs"; pLocalizedTeamName = g_pVGuiLocalize->Find( "TF_RedTeam_Name" ); break; case TEAM_UNASSIGNED: // stalemate pImagePanelBG->SetImage( "../hud/winpanel_black_bg_main.vmt" ); pTeamLabel = "#Winpanel_Stalemate"; pTopPlayersLabel = "#Winpanel_TopPlayers"; break; default: Assert( false ); break; } SetDialogVariable( bRoundComplete ? "WinningTeamLabel" : "AdvancingTeamLabel", g_pVGuiLocalize->Find( pTeamLabel ) ); SetDialogVariable( "TopPlayersLabel", g_pVGuiLocalize->Find( pTopPlayersLabel ) ); wchar_t wzWinReason[256]=L""; switch ( iWinReason ) { case WINREASON_ALL_POINTS_CAPTURED: g_pVGuiLocalize->ConstructString( wzWinReason, sizeof( wzWinReason ), g_pVGuiLocalize->Find( "#Winreason_AllPointsCaptured" ), 1, pLocalizedTeamName ); break; case WINREASON_FLAG_CAPTURE_LIMIT: { wchar_t wzFlagCaptureLimit[16]; _snwprintf( wzFlagCaptureLimit, ARRAYSIZE( wzFlagCaptureLimit), L"%i", iFlagCapLimit ); g_pVGuiLocalize->ConstructString( wzWinReason, sizeof( wzWinReason ), g_pVGuiLocalize->Find( "#Winreason_FlagCaptureLimit" ), 2, pLocalizedTeamName, wzFlagCaptureLimit ); } break; case WINREASON_OPPONENTS_DEAD: g_pVGuiLocalize->ConstructString( wzWinReason, sizeof( wzWinReason ), g_pVGuiLocalize->Find( "#Winreason_OpponentsDead" ), 1, pLocalizedTeamName ); break; case WINREASON_DEFEND_UNTIL_TIME_LIMIT: g_pVGuiLocalize->ConstructString( wzWinReason, sizeof( wzWinReason ), g_pVGuiLocalize->Find( "#Winreason_DefendedUntilTimeLimit" ), 1, pLocalizedTeamName ); break; case WINREASON_STALEMATE: g_pVGuiLocalize->ConstructString( wzWinReason, sizeof( wzWinReason ), g_pVGuiLocalize->Find( "#Winreason_Stalemate" ), 0 ); break; default: Assert( false ); break; } SetDialogVariable( "WinReasonLabel", wzWinReason ); if ( !bRoundComplete && ( WINREASON_STALEMATE != iWinReason ) ) { // if this was a mini-round, show # of capture points remaining wchar_t wzNumCapturesRemaining[16]; wchar_t wzCapturesRemainingMsg[256]=L""; _snwprintf( wzNumCapturesRemaining, ARRAYSIZE( wzNumCapturesRemaining ), L"%i", iRoundsRemaining ); g_pVGuiLocalize->ConstructString( wzCapturesRemainingMsg, sizeof( wzCapturesRemainingMsg ), g_pVGuiLocalize->Find( 1 == iRoundsRemaining ? "#Winpanel_CapturePointRemaining" : "Winpanel_CapturePointsRemaining" ), 1, wzNumCapturesRemaining ); SetDialogVariable( "DetailsLabel", wzCapturesRemainingMsg ); } else if ( ( WINREASON_ALL_POINTS_CAPTURED == iWinReason ) || ( WINREASON_FLAG_CAPTURE_LIMIT == 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( wzCapMsg, sizeof( wzCapMsg ), g_pVGuiLocalize->Find( "#Winpanel_WinningCapture" ), 1, wzPlayerNames ); SetDialogVariable( "DetailsLabel", wzCapMsg ); } } // 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 ) { if ( bRoundComplete ) { // 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 + 2.0f; } } // only show team scores if round is complete m_pTeamScorePanel->SetVisible( bRoundComplete ); } C_TF_PlayerResource *tf_PR = dynamic_cast<C_TF_PlayerResource *>( g_PR ); if ( !tf_PR ) return; // look for the top 3 players sent in the event for ( int i = 1; i <= 3; i++ ) { bool bShow = false; char szPlayerIndexVal[64]="", szPlayerScoreVal[64]=""; // get player index and round points from the event Q_snprintf( szPlayerIndexVal, ARRAYSIZE( szPlayerIndexVal ), "player_%d", i ); Q_snprintf( szPlayerScoreVal, ARRAYSIZE( szPlayerScoreVal ), "player_%d_points", i ); int iPlayerIndex = event->GetInt( szPlayerIndexVal, 0 ); int iRoundScore = event->GetInt( szPlayerScoreVal, 0 ); // round score of 0 means no player to show for that position (not enough players, or didn't score any points that round) if ( iRoundScore > 0 ) bShow = true; #if !defined( _X360 ) CAvatarImagePanel *pPlayerAvatar = dynamic_cast<CAvatarImagePanel *>( FindChildByName( CFmtStr( "Player%dAvatar", i ) ) ); if ( pPlayerAvatar ) { if ( bShow ) { CBasePlayer *pPlayer = UTIL_PlayerByIndex( iPlayerIndex ); pPlayerAvatar->SetPlayer( pPlayer ); } pPlayerAvatar->SetVisible( bShow ); } #endif vgui::Label *pPlayerName = dynamic_cast<Label *>( FindChildByName( CFmtStr( "Player%dName", i ) ) ); vgui::Label *pPlayerClass = dynamic_cast<Label *>( FindChildByName( CFmtStr( "Player%dClass", i ) ) ); vgui::Label *pPlayerScore = dynamic_cast<Label *>( FindChildByName( CFmtStr( "Player%dScore", i ) ) ); if ( !pPlayerName || !pPlayerClass || !pPlayerScore ) return; if ( bShow ) { // set the player labels to team color Color clr = g_PR->GetTeamColor( g_PR->GetTeam( iPlayerIndex ) ); pPlayerName->SetFgColor( clr ); pPlayerClass->SetFgColor( clr ); pPlayerScore->SetFgColor( clr ); // set label contents pPlayerName->SetText( g_PR->GetPlayerName( iPlayerIndex ) ); pPlayerClass->SetText( g_aPlayerClassNames[tf_PR->GetPlayerClass( iPlayerIndex )] ); pPlayerScore->SetText( CFmtStr( "%d", iRoundScore ) ); } // show or hide labels for this player position pPlayerName->SetVisible( bShow ); pPlayerClass->SetVisible( bShow ); pPlayerScore->SetVisible( bShow ); } m_bShouldBeVisible = true; MoveToFront(); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CControlPointIcon::PerformLayout( void ) { BaseClass::PerformLayout(); int iBaseXPos, iBaseYPos; ipanel()->GetAbsPos(GetVPanel(), iBaseXPos, iBaseYPos ); m_pBaseImage->SetBounds( 0, 0, GetWide(), GetTall() ); if ( m_pCapImage->IsVisible() ) { m_pCapImage->SetBounds( 0, 0, GetWide(), GetTall() ); } if ( m_pCapHighlightImage->IsVisible() ) { int iHeight = ScreenHeight() * 0.75; m_pCapHighlightImage->SetBounds( iBaseXPos + CAP_BOX_INDENT_X, iBaseYPos - iHeight, GetWide() - (CAP_BOX_INDENT_X*2), iHeight + GetTall() -CAP_BOX_INDENT_Y ); } int iCappingTeam = ObjectiveResource()->GetCappingTeam( m_iCPIndex ); int iPlayers = ObjectiveResource()->GetNumPlayersInArea( m_iCPIndex, iCappingTeam ); if ( !m_pCapPlayerImage->IsVisible() && iPlayers ) { m_pCapPlayerImage->SetVisible(true); } if ( m_pCapPlayerImage->IsVisible() ) { if ( !iPlayers ) { // We're a deteriorating point m_pCapPlayerImage->SetVisible( false ); m_pCapNumPlayers->SetVisible( false ); } else { int iXPos, iYPos; if ( iPlayers < 2 || !m_pCapNumPlayers ) { iXPos = (GetWide() - m_pCapPlayerImage->GetWide()) * 0.5; } else { iXPos = (GetWide() - m_pCapPlayerImage->GetWide()) * 0.5 - XRES(4); } iYPos = (GetTall() - m_pCapPlayerImage->GetTall()) * 0.5; m_pCapPlayerImage->SetPos( iXPos, iYPos ); if ( m_pCapNumPlayers ) { m_pCapNumPlayers->SetVisible( (iPlayers>1) ); SetDialogVariable( "numcappers", iPlayers ); m_pCapNumPlayers->SetFgColor( Color(0,0,0,255) ); } } } if ( m_pCapPulseImage ) { int iSize = GetWide() * 3; int iXpos = iBaseXPos - ((iSize-GetWide()) * 0.5); int iYpos = iBaseYPos - ((iSize-GetTall()) * 0.5); m_pCapPulseImage->SetBounds( iXpos, iYpos, iSize, iSize ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFStatPanel::ShowStatPanel( int iClass, int iTeam, int iCurStatValue, TFStatType_t statType, RecordBreakType_t recordBreakType, bool bAlive ) { ClassStats_t &classStats = GetClassStats( iClass ); vgui::Label *pLabel = dynamic_cast<Label *>( FindChildByName( "summaryLabel" ) ); if ( !pLabel ) return; const char *pRecordTextSuffix[RECORDBREAK_MAX] = { "", "close", "tie", "best" }; const char *pLocalizedTitle = bAlive ? "#StatPanel_Title_Alive" : "#StatPanel_Title_Dead"; SetDialogVariable( "title", g_pVGuiLocalize->Find( pLocalizedTitle ) ); SetDialogVariable( "stattextlarge", "" ); SetDialogVariable( "stattextsmall", "" ); if ( recordBreakType == RECORDBREAK_CLOSE ) { // if we are displaying that the player got close to a record, show current & best values char szCur[32],szBest[32]; wchar_t wzCur[32],wzBest[32]; GetStatValueAsString( iCurStatValue, statType, szCur, ARRAYSIZE( szCur ) ); GetStatValueAsString( classStats.max.m_iStat[statType], statType, szBest, ARRAYSIZE( szBest ) ); g_pVGuiLocalize->ConvertANSIToUnicode( szCur, wzCur, sizeof( wzCur ) ); g_pVGuiLocalize->ConvertANSIToUnicode( szBest, wzBest, sizeof( wzBest ) ); wchar_t *wzFormat = g_pVGuiLocalize->Find( "#StatPanel_Format_Close" ); wchar_t wzText[256]; g_pVGuiLocalize->ConstructString( wzText, sizeof( wzText ), wzFormat, 2, wzCur, wzBest ); SetDialogVariable( "stattextsmall", wzText ); } else { // player broke or tied a record, just show current value char szValue[32]; GetStatValueAsString( iCurStatValue, statType, szValue, ARRAYSIZE( szValue ) ); SetDialogVariable( "stattextlarge", szValue ); } SetDialogVariable( "statdesc", g_pVGuiLocalize->Find( CFmtStr( "%s_%s", g_szLocalizedRecordText[statType], pRecordTextSuffix[recordBreakType] ) ) ); // Set the class name. We can't use a dialog variable because it's a string that's already // been set using a dialog variable, and apparently we don't support nested dialog variables. wchar_t szOriginalSummary[ 256 ]; wchar_t szSummary[ 256 ]; // This is the field that "statdesc" completed for us pLabel->GetText( szOriginalSummary, sizeof( szOriginalSummary ) ); const wchar_t *pszPlayerClass = L"undefined"; if ( ( iClass >= TF_FIRST_NORMAL_CLASS ) && ( iClass <= TF_LAST_NORMAL_CLASS ) ) { pszPlayerClass = g_pVGuiLocalize->Find( g_aPlayerClassNames[ iClass ] ); } g_pVGuiLocalize->ConstructString( szSummary, sizeof( szSummary ), szOriginalSummary, 1, pszPlayerClass ); pLabel->SetText( szSummary ); if ( m_pClassImage ) { m_pClassImage->SetClass( iTeam, iClass, 0 ); } Show(); }