summaryrefslogtreecommitdiff
path: root/game/client/tf/vgui/tf_leaderboardpanel.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/client/tf/vgui/tf_leaderboardpanel.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'game/client/tf/vgui/tf_leaderboardpanel.cpp')
-rw-r--r--game/client/tf/vgui/tf_leaderboardpanel.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/game/client/tf/vgui/tf_leaderboardpanel.cpp b/game/client/tf/vgui/tf_leaderboardpanel.cpp
new file mode 100644
index 0000000..2e0327d
--- /dev/null
+++ b/game/client/tf/vgui/tf_leaderboardpanel.cpp
@@ -0,0 +1,103 @@
+#include "cbase.h"
+#include "tf_leaderboardpanel.h"
+#include "econ_controls.h"
+#include "tf_asyncpanel.h"
+#include "tf_mapinfo.h"
+#include "vgui_avatarimage.h"
+#include "tf_item_inventory.h"
+
+
+CTFLeaderboardPanel::CTFLeaderboardPanel( Panel *pParent, const char *pszPanelName )
+ : CBaseASyncPanel( pParent, pszPanelName )
+{}
+
+//-----------------------------------------------------------------------------
+// Purpose: Create leaderboard panels
+//-----------------------------------------------------------------------------
+void CTFLeaderboardPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
+{
+ BaseClass::ApplySchemeSettings( pScheme );
+
+ LoadControlSettings( "Resource/UI/econ/LeaderboardPanel.res" );
+}
+
+void CTFLeaderboardPanel::ApplySettings( KeyValues *inResourceData )
+{
+ BaseClass::ApplySettings( inResourceData );
+
+ IScheme *pScheme = vgui::scheme()->GetIScheme( GetScheme() );
+ m_EvenTextColor = GetSchemeColor( inResourceData->GetString( "EvenTextColor" ), pScheme);
+ m_OddTextColor = GetSchemeColor( inResourceData->GetString( "OddTextColor" ), pScheme);
+ m_LocalPlayerTextColor = GetSchemeColor( inResourceData->GetString( "LocalPlayerTextColor" ), pScheme);
+
+ EditablePanel *pScoresContainer = dynamic_cast< EditablePanel* >( FindChildByName( "ScoresContainer", true ) );
+
+ if ( pScoresContainer )
+ {
+ m_vecLeaderboardEntries.Purge();
+ for ( int i = 0; i < 7; ++ i )
+ {
+ vgui::EditablePanel *pEntryUI = new vgui::EditablePanel( pScoresContainer, "LeaderboardEntry" );
+ pEntryUI->ApplySchemeSettings( pScheme );
+ pEntryUI->LoadControlSettings( "Resource/UI/LeaderboardSpreadEntry.res" );
+ m_vecLeaderboardEntries.AddToTail( pEntryUI );
+ }
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Check for leaderboard data
+//-----------------------------------------------------------------------------
+bool CTFLeaderboardPanel::CheckForData_Internal()
+{
+ return UpdateLeaderboards();
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Checks if we have friends leaderboard data downloaded. If so, sets
+// the data into the panels
+//-----------------------------------------------------------------------------
+bool CTFLeaderboardPanel::UpdateLeaderboards()
+{
+ CUtlVector< LeaderboardEntry_t* > scores;
+ if ( !GetLeaderboardData( scores ) )
+ return false;
+
+ int x=0,y=0;
+ FOR_EACH_VEC( m_vecLeaderboardEntries, i )
+ {
+ Color colorToUse = i % 2 == 1 ? m_OddTextColor : m_EvenTextColor;
+ EditablePanel *pContainer = dynamic_cast< EditablePanel* >( m_vecLeaderboardEntries[i] );
+ if ( pContainer )
+ {
+ bool bIsEntryVisible = i < scores.Count();
+ pContainer->SetVisible( bIsEntryVisible );
+ pContainer->SetPos( x, y );
+ y += m_yEntryStep;
+ if ( bIsEntryVisible )
+ {
+ const LeaderboardEntry_t* leaderboardEntry = scores[i];
+ const CSteamID &steamID = leaderboardEntry->m_steamIDUser;
+ bool bIsLocalPlayer = steamapicontext && steamapicontext->SteamUser() && steamapicontext->SteamUser()->GetSteamID() == steamID;
+ pContainer->SetDialogVariable( "rank", leaderboardEntry->m_nGlobalRank );
+ pContainer->SetDialogVariable( "username", InventoryManager()->PersonaName_Get( steamID.GetAccountID() ) );
+ pContainer->SetDialogVariable( "score", leaderboardEntry->m_nScore );
+
+ CExLabel *pText = dynamic_cast< CExLabel* >( pContainer->FindChildByName( "UserName" ) );
+ if ( pText )
+ {
+ pText->SetColorStr( bIsLocalPlayer ? m_LocalPlayerTextColor : colorToUse );
+ }
+
+ CAvatarImagePanel *pAvatar = dynamic_cast< CAvatarImagePanel* >( pContainer->FindChildByName( "AvatarImage" ) );
+ if ( pAvatar )
+ {
+ pAvatar->SetShouldDrawFriendIcon( false );
+ pAvatar->SetPlayer( steamID, k_EAvatarSize32x32 );
+ }
+ }
+ }
+ }
+
+ return true;
+}