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.

106 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Create and display a win panel at the end of a round displaying interesting stats and info about the round.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "stat_card.h"
  9. #include "vgui_controls/AnimationController.h"
  10. #include "iclientmode.h"
  11. #include "c_playerresource.h"
  12. #include <vgui_controls/Label.h>
  13. #include <vgui/ILocalize.h>
  14. #include <vgui/ISurface.h>
  15. #include "fmtstr.h"
  16. #include "../../public/steam/steam_api.h"
  17. #include "c_cs_player.h"
  18. #include "cs_gamestats_shared.h"
  19. #include "cs_client_gamestats.h"
  20. // memdbgon must be the last include file in a .cpp file!!!
  21. #include "tier0/memdbgon.h"
  22. //-----------------------------------------------------------------------------
  23. // Purpose: Constructor
  24. //-----------------------------------------------------------------------------
  25. StatCard::StatCard(vgui::Panel *parent, const char *name) : BaseClass(parent, "CSStatCard")
  26. {
  27. //m_pAvatarDefault = new ImagePanel(this, "");
  28. //m_pBackgroundArt = new ImagePanel(this, "BackgroundArt");
  29. m_pAvatar = new CAvatarImagePanel(this, "Avatar");
  30. m_pAvatar->SetShouldScaleImage(true);
  31. m_pAvatar->SetShouldDrawFriendIcon(false);
  32. m_pAvatar->SetSize(64,64);
  33. m_pName= new Label(this, "Name", "Name");
  34. m_pKillToDeathRatio = new Label(this, "KillToDeath", "KillToDeath");
  35. m_pStars = new Label(this, "Stars", "Stars");
  36. }
  37. StatCard::~StatCard()
  38. {
  39. }
  40. void StatCard::ApplySchemeSettings( vgui::IScheme *pScheme )
  41. {
  42. BaseClass::ApplySchemeSettings( pScheme );
  43. LoadControlSettings("Resource/UI/CSStatCard.res");
  44. //m_pBackgroundArt->SetShouldScaleImage(true);
  45. //m_pBackgroundArt->SetImage("../VGUI/achievements/achievement-btn-up");
  46. SetBgColor(Color(0,0,0,0));
  47. UpdateInfo();
  48. }
  49. void StatCard::UpdateInfo()
  50. {
  51. const StatsCollection_t& personalLifetimeStats = g_CSClientGameStats.GetLifetimeStats();
  52. int stars = personalLifetimeStats[CSSTAT_MVPS];
  53. float kills = personalLifetimeStats[CSSTAT_KILLS];
  54. float deaths = personalLifetimeStats[CSSTAT_DEATHS];
  55. wchar_t buf[64], numBuf[64];
  56. if (deaths > 0)
  57. {
  58. float killToDeath = kills / deaths;
  59. _snwprintf( numBuf, ARRAYSIZE( numBuf ), L"%.2f", killToDeath);
  60. g_pVGuiLocalize->ConstructString( buf, sizeof(buf),
  61. g_pVGuiLocalize->Find( "#GameUI_Stats_LastMatch_KDRatio" ), 1, numBuf );
  62. m_pKillToDeathRatio->SetText( buf );
  63. }
  64. else
  65. {
  66. m_pKillToDeathRatio->SetText("");
  67. }
  68. _snwprintf( numBuf, ARRAYSIZE( numBuf ), L"%i", stars);
  69. g_pVGuiLocalize->ConstructString( buf, sizeof(buf),
  70. g_pVGuiLocalize->Find( "#GameUI_Stats_LastMatch_MVPS" ), 1, numBuf );
  71. m_pStars->SetText( buf );
  72. if (steamapicontext)
  73. {
  74. ISteamFriends* friends = steamapicontext->SteamFriends();
  75. if (friends)
  76. {
  77. m_pName->SetText(friends->GetPersonaName());
  78. }
  79. }
  80. // Display the player avatar
  81. if (m_pAvatar && steamapicontext && steamapicontext->SteamUser())
  82. {
  83. m_pAvatar->SetPlayer( steamapicontext->SteamUser()->GetSteamID(), k_EAvatarSize64x64 );
  84. m_pAvatar->SetVisible( true );
  85. }
  86. }