//========= Copyright Valve Corporation, All rights reserved. ============// // // Purpose: // // $NoKeywords: $ //============================================================================= #include "cbase.h" #include "tf_hud_item_progress_tracker.h" #include "iclientmode.h" #include #include #include "gc_clientsystem.h" #include "engine/IEngineSound.h" #include "quest_log_panel.h" #include "econ_controls.h" #include "tf_item_inventory.h" #include "c_tf_player.h" #include "quest_objective_manager.h" #include "tf_spectatorgui.h" #include "econ_quests.h" #include "inputsystem/iinputsystem.h" // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" using namespace vgui; const float ATTRIB_TRACK_GLOW_HOLD_TIME = 2.f; const float ATTRIB_TRACK_BAR_GROW_RATE = 0.3f; const float ATTRIB_TRACK_COMPLETE_PULSE_RATE = 2.f; const float ATTRIB_TRACK_COMPLETE_PULSE_DIM_HOLD = 0.3f; const float ATTRIB_TRACK_COMPLETE_PULSE_GLOW_HOLD = 0.9f; enum EContractHUDVisibility { CONTRACT_HUD_SHOW_NONE = 0, CONTRACT_HUD_SHOW_EVERYTHING, CONTRACT_HUD_SHOW_ACTIVE, }; void cc_contract_progress_show_update( IConVar *pConVar, const char *pOldString, float flOldValue ) { CHudItemAttributeTracker *pTrackerPanel = (CHudItemAttributeTracker *)GET_HUDELEMENT( CHudItemAttributeTracker ); if ( pTrackerPanel ) { pTrackerPanel->InvalidateLayout(); } } ConVar tf_contract_progress_show( "tf_contract_progress_show", "1", FCVAR_CLIENTDLL | FCVAR_DONTRECORD | FCVAR_ARCHIVE, "Settings for the contract HUD element: 0 show nothing, 1 show everything, 2 show only active contracts.", cc_contract_progress_show_update ); ConVar tf_contract_competitive_show( "tf_contract_competitive_show", "2", FCVAR_CLIENTDLL | FCVAR_DONTRECORD | FCVAR_ARCHIVE, "Settings for the contract HUD element during competitive matches: 0 show nothing, 1 show everything, 2 show only active contracts.", cc_contract_progress_show_update ); EContractHUDVisibility GetContractHUDVisibility() { if ( TFGameRules() && TFGameRules()->IsMatchTypeCompetitive() ) return (EContractHUDVisibility)tf_contract_competitive_show.GetInt(); return (EContractHUDVisibility)tf_contract_progress_show.GetInt(); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- CItemAttributeProgressPanel::CItemAttributeProgressPanel( Panel* pParent, const char *pElementName, const CQuestObjectiveDefinition *pObjectiveDef, const char* pszResFileName ) : EditablePanel( pParent, pElementName ) , m_nDefIndex( pObjectiveDef->GetDefinitionIndex() ) , m_flUpdateTime( 0.f ) , m_flLastThink( 0.f ) , m_bAdvanced( pObjectiveDef->IsAdvanced() ) , m_strResFileName( pszResFileName ) { Assert( !m_strResFileName.IsEmpty() ); m_pAttribBlur = new Label( this, "AttribBlur", "" ); m_pAttribGlow = new Label( this, "AttribGlow", "" ); m_pAttribDesc = new Label( this, "AttribDesc", "" ); REGISTER_COLOR_AS_OVERRIDABLE( m_enabledTextColor, "enabled_text_color_override" ); REGISTER_COLOR_AS_OVERRIDABLE( m_disabledTextColor, "disabled_text_color_override" ); // We're being set for the first time, instantly be progressed m_pAttribBlur->SetAlpha( 0 ); m_pAttribGlow->SetAlpha( 0 ); m_flUpdateTime = Plat_FloatTime() - ATTRIB_TRACK_GLOW_HOLD_TIME; } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CItemAttributeProgressPanel::ApplySchemeSettings( vgui::IScheme *pScheme ) { BaseClass::ApplySchemeSettings( pScheme ); LoadControlSettings( m_strResFileName ); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CItemAttributeProgressPanel::ApplySettings( KeyValues *inResourceData ) { BaseClass::ApplySettings( inResourceData ); m_strNormalPointLocToken = inResourceData->GetString( "normal_token" ); m_strAdvancedLocToken = inResourceData->GetString( "advanced_token" ); const CQuestObjectiveDefinition *pObjectiveDef = GEconItemSchema().GetQuestObjectiveByDefIndex( m_nDefIndex ); if ( pObjectiveDef ) { const char *pszDescriptionToken = pObjectiveDef->GetDescriptionToken(); locchar_t loc_ItemDescription[MAX_ITEM_NAME_LENGTH]; const locchar_t *pLocalizedObjectiveName = GLocalizationProvider()->Find( pszDescriptionToken ); if ( !pLocalizedObjectiveName || !pLocalizedObjectiveName[0] ) { // Couldn't localize it, just use it raw GLocalizationProvider()->ConvertUTF8ToLocchar( pszDescriptionToken, loc_ItemDescription, ARRAYSIZE( loc_ItemDescription ) ); } else { locchar_t loc_IntermediateName[ MAX_ITEM_NAME_LENGTH ]; locchar_t locValue[ MAX_ITEM_NAME_LENGTH ]; loc_sprintf_safe( locValue, LOCCHAR( "%d" ), pObjectiveDef->GetPoints() ); loc_scpy_safe( loc_IntermediateName, CConstructLocalizedString( pLocalizedObjectiveName, locValue ) ); locchar_t *pszLocString = GLocalizationProvider()->Find( pObjectiveDef->IsAdvanced() ? m_strAdvancedLocToken : m_strNormalPointLocToken ); loc_scpy_safe( loc_ItemDescription, CConstructLocalizedString( pszLocString, loc_IntermediateName ) ); } SetDialogVariable( "attr_desc", loc_ItemDescription ); } //SetTall( GetContentTall() ); //m_pAttribDesc->SetTall( GetTall() ); InvalidateLayout(); } void CItemAttributeProgressPanel::SetIsValid( bool bIsValid ) { if ( bIsValid ) { m_pAttribDesc->SetFgColor( m_enabledTextColor ); } else { m_pAttribDesc->SetFgColor( m_disabledTextColor ); } } int CItemAttributeProgressPanel::GetContentTall() const { // Find the bottom of the text int nTextWide = 0, nTextTall = 0; m_pAttribDesc->GetContentSize( nTextWide, nTextTall ); int nTextYpos = m_pAttribDesc->GetYPos(); return nTextYpos + nTextTall; } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CItemAttributeProgressPanel::SetProgress( Color glowColor ) { m_flUpdateTime = Plat_FloatTime(); m_pAttribBlur->SetAlpha( 255 ); m_pAttribGlow->SetAlpha( 255 ); m_pAttribDesc->SetAlpha( 0 ); m_pAttribBlur->SetFgColor( glowColor ); m_pAttribGlow->SetFgColor( glowColor ); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CItemAttributeProgressPanel::OnThink() { float flGlowTime = Plat_FloatTime() - m_flUpdateTime; if ( flGlowTime > ATTRIB_TRACK_GLOW_HOLD_TIME ) { float flGlowAlpha = RemapValClamped( flGlowTime, ATTRIB_TRACK_GLOW_HOLD_TIME, ATTRIB_TRACK_GLOW_HOLD_TIME + 0.25f, 1.f, 0.f ); m_pAttribBlur->SetAlpha( 255 * flGlowAlpha ); m_pAttribGlow->SetAlpha( 255 * flGlowAlpha ); m_pAttribDesc->SetAlpha( 255 * ( 1.f - flGlowAlpha ) ); } m_flLastThink = Plat_FloatTime(); } float CItemTrackerPanel::m_sflEventRecievedTime = 0.f; //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- CItemTrackerPanel::CItemTrackerPanel( Panel* pParent, const char *pElementName, const CEconItem* pItem, const char* pszItemTrackerResFile ) : EditablePanel( pParent, pElementName ) , m_pItem( NULL ) , m_pCompletedContainer( NULL ) , m_pCompletedDescGlow( NULL ) , m_pCompletedNameGlow( NULL ) , m_flStandardTargetProgress( 0.f ) , m_flStandardCurrentProgress( 0.f ) , m_flBonusCurrentProgress( 0.f ) , m_flBonusTargetProgress( 0.f ) , m_flUpdateTime( 0.f ) , m_flLastThink( 0.f ) , m_nMaxStandardPoints( 0 ) , m_nMaxBonusPoints( 0 ) , m_eSoundToPlay( SOUND_NONE ) , m_nContentTall( 0 ) , m_bNoEffects( false ) , m_strItemTrackerResFile( pszItemTrackerResFile ) { Assert( pszItemTrackerResFile ); SetItem( pItem ); ListenForGameEvent( "quest_objective_completed" ); ListenForGameEvent( "player_spawn" ); ListenForGameEvent( "inventory_updated" ); ListenForGameEvent( "localplayer_changeclass" ); ListenForGameEvent( "schema_updated" ); m_pItemName = new Label( this, "ItemName", "" ); m_pCompletedContainer = new EditablePanel( this, "CompletedContainer" ); m_pProgressBarBackground = new EditablePanel( this, "ProgressBarBG" ); m_pProgressBarStandard = new EditablePanel( m_pProgressBarBackground, "ProgressBarStandard" ); m_pProgressBarBonus = new EditablePanel( m_pProgressBarBackground, "ProgressBarBonus" ); m_pProgressBarStandardHighlight = new EditablePanel( m_pProgressBarBackground, "ProgressBarStandardHighlight" ); m_pProgressBarBonusHighlight = new EditablePanel( m_pProgressBarBackground, "ProgressBarBonusHighlight" ); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- CItemTrackerPanel::~CItemTrackerPanel() {} //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CItemTrackerPanel::ApplySettings( KeyValues *inResourceData ) { BaseClass::ApplySettings( inResourceData ); m_strItemAttributeResFile = inResourceData->GetString( "item_attribute_res_file" ); m_strProgressBarStandardLocToken = inResourceData->GetString( "progress_bar_standard_loc_token" ); m_strProgressBarAdvancedLocToken = inResourceData->GetString( "progress_bar_advanced_loc_token" ); Assert( !m_strItemAttributeResFile.IsEmpty() ); Assert( !m_strProgressBarStandardLocToken.IsEmpty() ); Assert( !m_strProgressBarAdvancedLocToken.IsEmpty() ); m_strStandardObjectiveTick = inResourceData->GetString( "standard_objective_tick_sound", NULL ); m_strStandardPointsComplete = inResourceData->GetString( "standard_points_complete_sound", NULL ); m_strAdvancedObjectiveComplete = inResourceData->GetString( "advanced_objective_sound_complete", NULL ); m_strAdvancedPointsComplete = inResourceData->GetString( "advanced_points_complete_sound", NULL ); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CItemTrackerPanel::ApplySchemeSettings( IScheme *pScheme ) { BaseClass::ApplySchemeSettings( pScheme ); LoadControlSettings( m_strItemTrackerResFile ); m_pCompletedDescGlow = FindControl