Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.7 KiB

  1. #include "cbase.h"
  2. #include "tf_leaderboardpanel.h"
  3. #include "econ_controls.h"
  4. #include "tf_asyncpanel.h"
  5. #include "tf_mapinfo.h"
  6. #include "vgui_avatarimage.h"
  7. #include "tf_item_inventory.h"
  8. CTFLeaderboardPanel::CTFLeaderboardPanel( Panel *pParent, const char *pszPanelName )
  9. : CBaseASyncPanel( pParent, pszPanelName )
  10. {}
  11. //-----------------------------------------------------------------------------
  12. // Purpose: Create leaderboard panels
  13. //-----------------------------------------------------------------------------
  14. void CTFLeaderboardPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
  15. {
  16. BaseClass::ApplySchemeSettings( pScheme );
  17. LoadControlSettings( "Resource/UI/econ/LeaderboardPanel.res" );
  18. }
  19. void CTFLeaderboardPanel::ApplySettings( KeyValues *inResourceData )
  20. {
  21. BaseClass::ApplySettings( inResourceData );
  22. IScheme *pScheme = vgui::scheme()->GetIScheme( GetScheme() );
  23. m_EvenTextColor = GetSchemeColor( inResourceData->GetString( "EvenTextColor" ), pScheme);
  24. m_OddTextColor = GetSchemeColor( inResourceData->GetString( "OddTextColor" ), pScheme);
  25. m_LocalPlayerTextColor = GetSchemeColor( inResourceData->GetString( "LocalPlayerTextColor" ), pScheme);
  26. EditablePanel *pScoresContainer = dynamic_cast< EditablePanel* >( FindChildByName( "ScoresContainer", true ) );
  27. if ( pScoresContainer )
  28. {
  29. m_vecLeaderboardEntries.Purge();
  30. for ( int i = 0; i < 7; ++ i )
  31. {
  32. vgui::EditablePanel *pEntryUI = new vgui::EditablePanel( pScoresContainer, "LeaderboardEntry" );
  33. pEntryUI->ApplySchemeSettings( pScheme );
  34. pEntryUI->LoadControlSettings( "Resource/UI/LeaderboardSpreadEntry.res" );
  35. m_vecLeaderboardEntries.AddToTail( pEntryUI );
  36. }
  37. }
  38. }
  39. //-----------------------------------------------------------------------------
  40. // Purpose: Check for leaderboard data
  41. //-----------------------------------------------------------------------------
  42. bool CTFLeaderboardPanel::CheckForData_Internal()
  43. {
  44. return UpdateLeaderboards();
  45. }
  46. //-----------------------------------------------------------------------------
  47. // Purpose: Checks if we have friends leaderboard data downloaded. If so, sets
  48. // the data into the panels
  49. //-----------------------------------------------------------------------------
  50. bool CTFLeaderboardPanel::UpdateLeaderboards()
  51. {
  52. CUtlVector< LeaderboardEntry_t* > scores;
  53. if ( !GetLeaderboardData( scores ) )
  54. return false;
  55. int x=0,y=0;
  56. FOR_EACH_VEC( m_vecLeaderboardEntries, i )
  57. {
  58. Color colorToUse = i % 2 == 1 ? m_OddTextColor : m_EvenTextColor;
  59. EditablePanel *pContainer = dynamic_cast< EditablePanel* >( m_vecLeaderboardEntries[i] );
  60. if ( pContainer )
  61. {
  62. bool bIsEntryVisible = i < scores.Count();
  63. pContainer->SetVisible( bIsEntryVisible );
  64. pContainer->SetPos( x, y );
  65. y += m_yEntryStep;
  66. if ( bIsEntryVisible )
  67. {
  68. const LeaderboardEntry_t* leaderboardEntry = scores[i];
  69. const CSteamID &steamID = leaderboardEntry->m_steamIDUser;
  70. bool bIsLocalPlayer = steamapicontext && steamapicontext->SteamUser() && steamapicontext->SteamUser()->GetSteamID() == steamID;
  71. pContainer->SetDialogVariable( "rank", leaderboardEntry->m_nGlobalRank );
  72. pContainer->SetDialogVariable( "username", InventoryManager()->PersonaName_Get( steamID.GetAccountID() ) );
  73. pContainer->SetDialogVariable( "score", leaderboardEntry->m_nScore );
  74. CExLabel *pText = dynamic_cast< CExLabel* >( pContainer->FindChildByName( "UserName" ) );
  75. if ( pText )
  76. {
  77. pText->SetColorStr( bIsLocalPlayer ? m_LocalPlayerTextColor : colorToUse );
  78. }
  79. CAvatarImagePanel *pAvatar = dynamic_cast< CAvatarImagePanel* >( pContainer->FindChildByName( "AvatarImage" ) );
  80. if ( pAvatar )
  81. {
  82. pAvatar->SetShouldDrawFriendIcon( false );
  83. pAvatar->SetPlayer( steamID, k_EAvatarSize32x32 );
  84. }
  85. }
  86. }
  87. }
  88. return true;
  89. }