//========= Copyright © 1996-2002, Valve LLC, All rights reserved. ============ // // Purpose: // // $NoKeywords: $ //============================================================================= #include "cbase.h" #include #include #include #include #include #include #include #include #include #include #include "ienginevgui.h" #include #include "tf_tips.h" #include "tf_statsummary.h" #include #include "fmtstr.h" using namespace vgui; CTFStatsSummaryPanel *g_pTFStatsSummaryPanel = NULL; //----------------------------------------------------------------------------- // Purpose: Returns the global stats summary panel //----------------------------------------------------------------------------- CTFStatsSummaryPanel *GStatsSummaryPanel() { if ( NULL == g_pTFStatsSummaryPanel ) { g_pTFStatsSummaryPanel = new CTFStatsSummaryPanel(); } return g_pTFStatsSummaryPanel; } //----------------------------------------------------------------------------- // Purpose: Destroys the global stats summary panel //----------------------------------------------------------------------------- void DestroyStatsSummaryPanel() { if ( NULL != g_pTFStatsSummaryPanel ) { delete g_pTFStatsSummaryPanel; g_pTFStatsSummaryPanel = NULL; } } //----------------------------------------------------------------------------- // Purpose: Constructor //----------------------------------------------------------------------------- CTFStatsSummaryPanel::CTFStatsSummaryPanel() : vgui::EditablePanel( NULL, "TFStatsSummary", vgui::scheme()->LoadSchemeFromFile( "Resource/ClientScheme.res", "ClientScheme" ) ) { m_bControlsLoaded = false; m_bInteractive = false; m_xStartLHBar = 0; m_xStartRHBar = 0; m_iBarHeight = 1; m_iBarMaxWidth = 1; m_pPlayerData = new vgui::EditablePanel( this, "statdata" ); m_pInteractiveHeaders = new vgui::EditablePanel( m_pPlayerData, "InteractiveHeaders" ); m_pNonInteractiveHeaders = new vgui::EditablePanel( m_pPlayerData, "NonInteractiveHeaders" ); m_pBarChartComboBoxA = new vgui::ComboBox( m_pInteractiveHeaders, "BarChartComboA", 10, false ); m_pBarChartComboBoxB = new vgui::ComboBox( m_pInteractiveHeaders, "BarChartComboB", 10, false ); m_pClassComboBox = new vgui::ComboBox( m_pInteractiveHeaders, "ClassCombo", 10, false ); m_pTipLabel = new vgui::Label( this, "TipLabel", "" ); m_pTipText = new vgui::Label( this, "TipText", "" ); #ifdef _X360 m_pFooter = new CTFFooter( this, "Footer" ); m_bShowBackButton = false; #else m_pNextTipButton = new vgui::Button( this, "NextTipButton", "" ); m_pCloseButton = new vgui::Button( this, "CloseButton", "" ); #endif m_pBarChartComboBoxA->AddActionSignalTarget( this ); m_pBarChartComboBoxB->AddActionSignalTarget( this ); m_pClassComboBox->AddActionSignalTarget( this ); ListenForGameEvent( "server_spawn" ); Reset(); } //----------------------------------------------------------------------------- // Purpose: Shows this dialog as a modal dialog //----------------------------------------------------------------------------- void CTFStatsSummaryPanel::ShowModal() { #ifdef _X360 m_bInteractive = false; m_bShowBackButton = true; #else // we are in interactive mode, enable controls m_bInteractive = true; #endif SetParent( enginevgui->GetPanel( PANEL_GAMEUIDLL ) ); UpdateDialog(); SetVisible( true ); MoveToFront(); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFStatsSummaryPanel::PerformLayout() { BaseClass::PerformLayout(); #ifndef _X360 /* if ( m_pTipLabel && m_pTipText ) { m_pTipLabel->SizeToContents(); int width = m_pTipLabel->GetWide(); int x, y, w, t; m_pTipText->GetBounds( x, y, w, t ); m_pTipText->SetPos( ( ScreenWidth() * 0.0125 ) + ( x + w ), y ); m_pTipText->InvalidateLayout( false, true ); // have it re-layout the contents so it's wrapped correctly now that we've changed the size } */ if ( m_pNextTipButton ) { m_pNextTipButton->SizeToContents(); } #endif } //----------------------------------------------------------------------------- // Purpose: Command handler //----------------------------------------------------------------------------- void CTFStatsSummaryPanel::OnCommand( const char *command ) { if ( 0 == Q_stricmp( command, "vguicancel" ) ) { m_bInteractive = false; UpdateDialog(); SetVisible( false ); SetParent( (VPANEL) NULL ); SetDefaultSelections(); #ifdef _X360 m_bShowBackButton = true; #endif } else if ( 0 == Q_stricmp( command, "nexttip" ) ) { UpdateTip(); } BaseClass::OnCommand( command ); } //----------------------------------------------------------------------------- // Purpose: Resets the dialog //----------------------------------------------------------------------------- void CTFStatsSummaryPanel::Reset() { m_aClassStats.RemoveAll(); SetDefaultSelections(); } //----------------------------------------------------------------------------- // Purpose: Sets all user-controllable dialog settings to default values //----------------------------------------------------------------------------- void CTFStatsSummaryPanel::SetDefaultSelections() { m_iSelectedClass = TF_CLASS_UNDEFINED; m_statBarGraph[0] = TFSTAT_POINTSSCORED; m_displayBarGraph[0]= SHOW_MAX; m_statBarGraph[1] = TFSTAT_PLAYTIME; m_displayBarGraph[1] = SHOW_TOTAL; m_pBarChartComboBoxA->ActivateItemByRow( 0 ); m_pBarChartComboBoxB->ActivateItemByRow( 10 ); } //----------------------------------------------------------------------------- // Purpose: Applies scheme settings //----------------------------------------------------------------------------- void CTFStatsSummaryPanel::ApplySchemeSettings(vgui::IScheme *pScheme) { BaseClass::ApplySchemeSettings( pScheme ); SetProportional( true ); LoadControlSettings( "Resource/UI/StatSummary.res" ); m_bControlsLoaded = true; // set the background image if ( IsPC() ) { ImagePanel *pImagePanel = dynamic_cast( FindChildByName( "MainBackground" ) ); if ( pImagePanel ) { // determine if we're in widescreen or not and select the appropriate image int screenWide, screenTall; surface()->GetScreenSize( screenWide, screenTall ); float aspectRatio = (float)screenWide/(float)screenTall; bool bIsWidescreen = aspectRatio >= 1.6f; pImagePanel->SetImage( bIsWidescreen ? "../console/background01_widescreen" : "../console/background01" ); } } // get the dimensions and position of a left-hand bar and a right-hand bar so we can do bar sizing later Panel *pLHBar = m_pPlayerData->FindChildByName( "ClassBar1A" ); Panel *pRHBar = m_pPlayerData->FindChildByName( "ClassBar1B" ); if ( pLHBar && pRHBar ) { int y; pLHBar->GetBounds( m_xStartLHBar, y, m_iBarMaxWidth, m_iBarHeight ); pRHBar->GetBounds( m_xStartRHBar, y, m_iBarMaxWidth, m_iBarHeight ); } // fill the combo box selections appropriately InitBarChartComboBox( m_pBarChartComboBoxA ); InitBarChartComboBox( m_pBarChartComboBoxB ); // fill the class names in the class combo box HFont hFont = scheme()->GetIScheme( GetScheme() )->GetFont( "ScoreboardSmall", true ); m_pClassComboBox->SetFont( hFont ); m_pClassComboBox->RemoveAll(); KeyValues *pKeyValues = new KeyValues( "data" ); pKeyValues->SetInt( "class", TF_CLASS_UNDEFINED ); m_pClassComboBox->AddItem( "#StatSummary_Label_AsAnyClass", pKeyValues ); for ( int iClass = TF_FIRST_NORMAL_CLASS; iClass <= TF_LAST_NORMAL_CLASS; iClass++ ) { pKeyValues = new KeyValues( "data" ); pKeyValues->SetInt( "class", iClass ); m_pClassComboBox->AddItem( g_aPlayerClassNames[iClass], pKeyValues ); } m_pClassComboBox->ActivateItemByRow( 0 ); SetDefaultSelections(); UpdateDialog(); SetVisible( false ); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFStatsSummaryPanel::OnKeyCodePressed( KeyCode code ) { if ( IsX360() ) { if ( code == KEY_XBUTTON_A ) { OnCommand( "nexttip" ) ; } else if ( code == KEY_XBUTTON_B ) { OnCommand( "vguicancel" ); } } } //----------------------------------------------------------------------------- // Purpose: Sets stats to use //----------------------------------------------------------------------------- void CTFStatsSummaryPanel::SetStats( CUtlVector &vecClassStats ) { m_aClassStats = vecClassStats; if ( m_bControlsLoaded ) { UpdateDialog(); } } //----------------------------------------------------------------------------- // Purpose: Updates the dialog //----------------------------------------------------------------------------- void CTFStatsSummaryPanel::ClearMapLabel() { SetDialogVariable( "maplabel", "" ); vgui::Label *pLabel = dynamic_cast