//========= Copyright Valve Corporation, All rights reserved. ============// // // Purpose: // // $NoKeywords: $ //=============================================================================// #include "cbase.h" #include "c_func_passtime_goal.h" #include "c_tf_passtime_ball.h" #include "c_tf_passtime_logic.h" #include "tf_hud_passtime.h" #include "tf_hud_passtime_ball_offscreen_arrow.h" #include "tf_weapon_passtime_gun.h" #include "passtime_convars.h" #include "passtime_game_events.h" #include "tf_hud_freezepanel.h" #include "tf_gamerules.h" #include "c_tf_team.h" #include "c_tf_player.h" #include "c_tf_playerresource.h" #include "iclientmode.h" #include "vgui_controls/AnimationController.h" #include "vgui_controls/CircularProgressBar.h" #include "vgui_controls/ProgressBar.h" #include "vgui/ISurface.h" #include // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" //----------------------------------------------------------------------------- using namespace vgui; //----------------------------------------------------------------------------- // The team colors from g_PR are wrong for probably good reasons that I don't understand. static Color GetTeamColor( int iTeam, byte alpha = 255 ) { switch ( iTeam ) { case TF_TEAM_RED: return Color( 159, 55, 34, alpha ); case TF_TEAM_BLUE: return Color( 76, 109, 128, alpha ); default: return Color( 245, 231, 222, alpha ); } } //----------------------------------------------------------------------------- static const char *GetProgressBallImageForTeam( int iTeam ) { switch( iTeam ) { case TF_TEAM_RED: return "../passtime/hud/passtime_ballcontrol_red"; case TF_TEAM_BLUE: return "../passtime/hud/passtime_ballcontrol_blue"; default: return "../passtime/hud/passtime_ballcontrol_none"; }; } static const char *GetProgressBallImageForTeam( C_BaseEntity *pEnt ) { if ( !pEnt ) { return "../passtime/hud/passtime_ball"; } return GetProgressBallImageForTeam( pEnt->GetTeamNumber() ); } //----------------------------------------------------------------------------- static const char *GetPlayerProgressPortrait( C_TFPlayer *pPlayer ) { if ( !pPlayer ) { return "../passtime/hud/portrait_scout_red"; } int iTeam = pPlayer->GetTeamNumber(); int iClass = pPlayer->GetPlayerClass()->GetClassIndex(); switch(iClass) { case TF_CLASS_SOLDIER: return (iTeam == TF_TEAM_RED) ? "../passtime/hud/portrait_soldier_red" : "../passtime/hud/portrait_soldier_blu"; case TF_CLASS_SCOUT: return (iTeam == TF_TEAM_RED) ? "../passtime/hud/portrait_scout_red" : "../passtime/hud/portrait_scout_blu"; case TF_CLASS_SNIPER: return (iTeam == TF_TEAM_RED) ? "../passtime/hud/portrait_sniper_red" : "../passtime/hud/portrait_sniper_blu"; case TF_CLASS_DEMOMAN: return (iTeam == TF_TEAM_RED) ? "../passtime/hud/portrait_demo_red" : "../passtime/hud/portrait_demo_blu"; case TF_CLASS_MEDIC: return (iTeam == TF_TEAM_RED) ? "../passtime/hud/portrait_medic_red" : "../passtime/hud/portrait_medic_blu"; case TF_CLASS_HEAVYWEAPONS: return (iTeam == TF_TEAM_RED) ? "../passtime/hud/portrait_heavy_red" : "../passtime/hud/portrait_heavy_blu"; case TF_CLASS_PYRO: return (iTeam == TF_TEAM_RED) ? "../passtime/hud/portrait_pyro_red" : "../passtime/hud/portrait_pyro_blu"; case TF_CLASS_SPY: return (iTeam == TF_TEAM_RED) ? "../passtime/hud/portrait_spy_red" : "../passtime/hud/portrait_spy_blu"; case TF_CLASS_ENGINEER: return (iTeam == TF_TEAM_RED) ? "../passtime/hud/portrait_eng_red" : "../passtime/hud/portrait_eng_blu"; default: return (iTeam == TF_TEAM_RED) ? "../passtime/hud/portrait_scout_red" : "../passtime/hud/portrait_scout_blu"; } } //----------------------------------------------------------------------------- static const char *GetProgressGoalImage( const C_FuncPasstimeGoal *pGoal ) { if ( !pGoal ) { return ""; } // NOTE: keep in mind that a goal that's on team blue is the goal where blue scores // and should look red on the hud since it's in the red part of the map. oops. bool bRedIcon = pGoal->GetTeamNumber() == TF_TEAM_BLUE; if ( pGoal->GetGoalType() == C_FuncPasstimeGoal::TYPE_TOWER ) { if ( pGoal->BGoalTriggerDisabled() ) { return bRedIcon ? "../passtime/hud/passtime_goal_red_locked" : "../passtime/hud/passtime_goal_blue_locked"; } else { return bRedIcon ? "../passtime/hud/passtime_goal_red_unlocked" : "../passtime/hud/passtime_goal_blue_unlocked"; } } else if ( pGoal->GetGoalType() == C_FuncPasstimeGoal::TYPE_ENDZONE ) { return bRedIcon ? "../passtime/hud/passtime_endzone_red_icon" : "../passtime/hud/passtime_endzone_blue_icon"; } else { return bRedIcon ? "../passtime/hud/passtime_goal_red_icon" : "../passtime/hud/passtime_goal_blue_icon"; } } //----------------------------------------------------------------------------- // CTFHudPasstimePanel //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- CTFHudPasstimePanel::CTFHudPasstimePanel( vgui::Panel *pParent, const char* name ) : EditablePanel( pParent, name ) {} //----------------------------------------------------------------------------- bool CTFHudPasstimePanel::IsVisible() { if ( IsTakingAFreezecamScreenshot() ) { return false; } return BaseClass::IsVisible(); } //----------------------------------------------------------------------------- // CTFHudTeamScore //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- CTFHudTeamScore::CTFHudTeamScore( vgui::Panel *pParent ) : CTFHudPasstimePanel( pParent, "HudTeamScore" ) , m_pPlayingToCluster( 0 ) { } //----------------------------------------------------------------------------- void CTFHudTeamScore::ApplySchemeSettings( vgui::IScheme *pScheme ) { BaseClass::ApplySchemeSettings( pScheme ); LoadControlSettings( "resource/UI/HudPasstimeTeamScore.res", NULL, NULL, NULL ); m_pPlayingToCluster = FindControl( "PlayingToCluster" ); if ( m_pPlayingToCluster ) { m_pPlayingToCluster->SetVisible( true ); } OnTick(); vgui::ivgui()->AddTickSignal( GetVPanel() ); } //----------------------------------------------------------------------------- void CTFHudTeamScore::OnTick() { // I would rather not do this every tick, but i couldn't find a reliable way // to do it from events. if( !g_pPasstimeLogic ) { return; } int iBlueScore = 0; int iRedScore = 0; C_TFTeam *pTeam = GetGlobalTFTeam( TF_TEAM_BLUE ); if ( pTeam ) { iBlueScore = pTeam->GetFlagCaptures(); } pTeam = GetGlobalTFTeam( TF_TEAM_RED ); if ( pTeam ) { iRedScore = pTeam->GetFlagCaptures(); } if ( m_pPlayingToCluster ) { m_pPlayingToCluster->SetDialogVariable( "rounds", tf_passtime_scores_per_round.GetInt() ); } SetDialogVariable( "bluescore", iBlueScore ); SetDialogVariable( "redscore", iRedScore ); } //----------------------------------------------------------------------------- int CTFHudTeamScore::GetTeamScore( int iTeam ) { C_TFTeam *pTeam = GetGlobalTFTeam( iTeam ); return pTeam ? pTeam->Get_Score() : 0; } //----------------------------------------------------------------------------- // CTFHudPasstimePassNotify //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- CTFHudPasstimePassNotify::CTFHudPasstimePassNotify( vgui::Panel *pParent ) : CTFHudPasstimePanel( pParent, "HudPasstimePassNotify" ) { } //----------------------------------------------------------------------------- void CTFHudPasstimePassNotify::ApplySchemeSettings( vgui::IScheme *pScheme ) { BaseClass::ApplySchemeSettings( pScheme ); LoadControlSettings( "resource/UI/HudPasstimePassNotify.res", NULL, NULL, NULL ); m_pTextBox = FindControl( "TextBox" ); m_pTextInPassRange = m_pTextBox ? m_pTextBox->FindControl