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.

363 lines
9.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: HUD Target ID element
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "cbase.h"
  8. #include "c_tf_player.h"
  9. #include "c_playerresource.h"
  10. #include "c_tf_playerresource.h"
  11. #include "tf_classdata.h"
  12. #include "hud.h"
  13. #include "hudelement.h"
  14. #include "iclientmode.h"
  15. #include "tf_imagepanel.h"
  16. #include "item_model_panel.h"
  17. #include "tf_hud_playerstatus.h"
  18. #include "tf_spectatorgui.h"
  19. #include "vgui/ILocalize.h"
  20. #include "vgui/ISurface.h"
  21. #include "vgui/IInput.h"
  22. #include <vgui/IVGui.h>
  23. #include <vgui/IScheme.h>
  24. #include <vgui_controls/Panel.h>
  25. #include <vgui_controls/Frame.h>
  26. #include "vgui_controls/TextImage.h"
  27. #include "vgui_controls/Label.h"
  28. #include "vgui_controls/Button.h"
  29. #include "ienginevgui.h"
  30. #include "hud_chat.h"
  31. // memdbgon must be the last include file in a .cpp file!!!
  32. #include "tier0/memdbgon.h"
  33. using namespace vgui;
  34. //-----------------------------------------------------------------------------
  35. // Purpose:
  36. //-----------------------------------------------------------------------------
  37. class CDisguiseStatus : public CHudElement, public EditablePanel
  38. {
  39. DECLARE_CLASS_SIMPLE( CDisguiseStatus, EditablePanel );
  40. public:
  41. CDisguiseStatus( const char *pElementName );
  42. void Init( void );
  43. virtual void ApplySchemeSettings( IScheme *scheme );
  44. virtual void PerformLayout( void );
  45. virtual void Paint( void );
  46. void ShowAndUpdateStatus( void );
  47. void HideStatus( void );
  48. virtual bool ShouldDraw( void );
  49. void CheckName( void );
  50. void CheckWeapon( void );
  51. void CheckHealth( void );
  52. private:
  53. CPanelAnimationVar( HFont, m_hFont, "TextFont", "TargetID" );
  54. CTFImagePanel *m_pBGPanel;
  55. CEmbeddedItemModelPanel *m_pModelPanel;
  56. CTFSpectatorGUIHealth *m_pDisguiseHealth;
  57. Label *m_pDisguiseNameLabel;
  58. Label *m_pWeaponNameLabel;
  59. bool m_bDisguised;
  60. CTFWeaponBase *m_pDisguiseWeapon;
  61. int m_iDisguiseTeam;
  62. };
  63. DECLARE_HUDELEMENT( CDisguiseStatus );
  64. //-----------------------------------------------------------------------------
  65. // Purpose:
  66. //-----------------------------------------------------------------------------
  67. CDisguiseStatus::CDisguiseStatus( const char *pElementName ) :
  68. CHudElement( pElementName ), BaseClass( NULL, "DisguiseStatus" )
  69. {
  70. Panel *pParent = g_pClientMode->GetViewport();
  71. SetParent( pParent );
  72. SetHiddenBits( HIDEHUD_MISCSTATUS );
  73. m_pModelPanel = NULL;
  74. m_pBGPanel = NULL;
  75. m_pDisguiseNameLabel = NULL;
  76. m_pWeaponNameLabel = NULL;
  77. m_pDisguiseHealth = new CTFSpectatorGUIHealth( this, "SpectatorGUIHealth" );
  78. m_bDisguised = true;
  79. m_pDisguiseWeapon = NULL;
  80. m_iDisguiseTeam = TEAM_UNASSIGNED;
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Purpose: Setup
  84. //-----------------------------------------------------------------------------
  85. void CDisguiseStatus::Init( void )
  86. {
  87. HideStatus();
  88. }
  89. //-----------------------------------------------------------------------------
  90. // Purpose:
  91. //-----------------------------------------------------------------------------
  92. void CDisguiseStatus::ApplySchemeSettings( vgui::IScheme *scheme )
  93. {
  94. BaseClass::ApplySchemeSettings( scheme );
  95. LoadControlSettings( "Resource/UI/DisguiseStatusPanel.res" );
  96. m_pModelPanel = dynamic_cast<CEmbeddedItemModelPanel*>( FindChildByName("itemmodelpanel") );
  97. m_pBGPanel = dynamic_cast<CTFImagePanel *> ( FindChildByName("DisguiseStatusBG") );
  98. m_pDisguiseNameLabel = dynamic_cast<Label *>(FindChildByName("DisguiseNameLabel"));
  99. m_pWeaponNameLabel = dynamic_cast<Label *>(FindChildByName("WeaponNameLabel"));
  100. SetPaintBackgroundEnabled( false );
  101. HideStatus();
  102. }
  103. //-----------------------------------------------------------------------------
  104. // Purpose:
  105. //-----------------------------------------------------------------------------
  106. bool CDisguiseStatus::ShouldDraw( void )
  107. {
  108. bool bShow = false;
  109. CTFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
  110. if ( !pPlayer )
  111. return false;
  112. if ( !pPlayer->m_Shared.InCond( TF_COND_DISGUISED ) )
  113. {
  114. bShow = false;
  115. }
  116. else
  117. {
  118. bShow = true;
  119. }
  120. if ( bShow && (!m_bDisguised || (m_pDisguiseWeapon != pPlayer->m_Shared.GetDisguiseWeapon()) || (m_iDisguiseTeam != pPlayer->m_Shared.GetDisguiseTeam()) ) )
  121. {
  122. ShowAndUpdateStatus();
  123. }
  124. else if ( !bShow && m_bDisguised )
  125. {
  126. HideStatus();
  127. }
  128. return bShow;
  129. }
  130. //-----------------------------------------------------------------------------
  131. // Purpose:
  132. //-----------------------------------------------------------------------------
  133. void CDisguiseStatus::ShowAndUpdateStatus( void )
  134. {
  135. CTFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
  136. if ( !pPlayer )
  137. return;
  138. m_iDisguiseTeam = pPlayer->m_Shared.GetDisguiseTeam();
  139. // m_pModelPanel->SetVisible( false );
  140. if ( m_pBGPanel )
  141. {
  142. m_pBGPanel->SetVisible( true );
  143. m_pBGPanel->SetBGTeam( m_iDisguiseTeam );
  144. m_pBGPanel->UpdateBGImage();
  145. }
  146. if ( m_pDisguiseNameLabel )
  147. {
  148. m_pDisguiseNameLabel->SetVisible( true );
  149. CheckName();
  150. }
  151. if ( m_pWeaponNameLabel )
  152. {
  153. m_pWeaponNameLabel->SetVisible( true );
  154. CheckWeapon();
  155. }
  156. if ( m_pDisguiseHealth )
  157. {
  158. m_pDisguiseHealth->SetVisible( true );
  159. CheckHealth();
  160. }
  161. m_bDisguised = true;
  162. }
  163. //-----------------------------------------------------------------------------
  164. // Purpose:
  165. //-----------------------------------------------------------------------------
  166. void CDisguiseStatus::HideStatus( void )
  167. {
  168. if ( m_pModelPanel )
  169. {
  170. m_pModelPanel->SetVisible( false );
  171. }
  172. if ( m_pBGPanel )
  173. {
  174. m_pBGPanel->SetVisible( false );
  175. }
  176. if ( m_pDisguiseNameLabel )
  177. {
  178. m_pDisguiseNameLabel->SetVisible( false );
  179. }
  180. if ( m_pWeaponNameLabel )
  181. {
  182. m_pWeaponNameLabel->SetVisible( false );
  183. }
  184. if ( m_pDisguiseHealth )
  185. {
  186. m_pDisguiseHealth->SetVisible( false );
  187. }
  188. m_bDisguised = false;
  189. }
  190. //-----------------------------------------------------------------------------
  191. // Purpose:
  192. //-----------------------------------------------------------------------------
  193. void CDisguiseStatus::CheckName( void )
  194. {
  195. CTFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
  196. if ( !pPlayer )
  197. return;
  198. int nIndex = pPlayer->m_Shared.GetDisguiseTargetIndex();
  199. if ( nIndex != TF_DISGUISE_TARGET_INDEX_NONE )
  200. {
  201. if ( g_PR != NULL )
  202. {
  203. const char *pszName = g_PR->GetPlayerName( nIndex );
  204. if ( pszName && pszName[0] )
  205. {
  206. SetDialogVariable( "disguisename", pszName );
  207. return;
  208. }
  209. }
  210. }
  211. SetDialogVariable( "disguisename", pPlayer->GetPlayerName() );
  212. }
  213. //-----------------------------------------------------------------------------
  214. // Purpose:
  215. //-----------------------------------------------------------------------------
  216. void CDisguiseStatus::CheckWeapon( void )
  217. {
  218. CTFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
  219. if ( !pPlayer )
  220. return;
  221. m_pDisguiseWeapon = pPlayer->m_Shared.GetDisguiseWeapon();
  222. if ( m_pDisguiseWeapon )
  223. {
  224. const wchar_t *pszDisguiseWeapon = g_pVGuiLocalize->Find( m_pDisguiseWeapon->GetTFWpnData().szPrintName );
  225. CAttributeContainer *pContainer = m_pDisguiseWeapon->GetAttributeContainer();
  226. if ( pContainer )
  227. {
  228. CEconItemView *pItem = pContainer->GetItem();
  229. if ( pItem )
  230. {
  231. pszDisguiseWeapon = pItem->GetItemName();
  232. }
  233. }
  234. SetDialogVariable( "weaponname", pszDisguiseWeapon );
  235. }
  236. }
  237. //-----------------------------------------------------------------------------
  238. // Purpose:
  239. //-----------------------------------------------------------------------------
  240. void CDisguiseStatus::CheckHealth( void )
  241. {
  242. CTFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
  243. if ( !pPlayer )
  244. return;
  245. if ( !m_pDisguiseHealth )
  246. return;
  247. m_pDisguiseHealth->SetHealth( pPlayer->m_Shared.GetDisguiseHealth(), pPlayer->m_Shared.GetDisguiseMaxHealth(), pPlayer->m_Shared.GetDisguiseMaxBuffedHealth() );
  248. }
  249. //-----------------------------------------------------------------------------
  250. // Purpose:
  251. //-----------------------------------------------------------------------------
  252. void CDisguiseStatus::PerformLayout( void )
  253. {
  254. /*
  255. int iXIndent = XRES(5);
  256. int iXPostdent = XRES(10);
  257. int iWidth = m_pTargetHealth->GetWide() + iXIndent + iXPostdent;
  258. int iTextW, iTextH;
  259. int iDataW, iDataH;
  260. if ( m_pTargetNameLabel && m_pTargetDataLabel )
  261. {
  262. m_pTargetNameLabel->GetContentSize( iTextW, iTextH );
  263. m_pTargetDataLabel->GetContentSize( iDataW, iDataH );
  264. iWidth += max(iTextW,iDataW);
  265. SetSize( iWidth, GetTall() );
  266. int nOffset = m_bArenaPanelVisible ? YRES (120) : 0; // HACK: move the targetID up a bit so it won't overlap the panel
  267. SetPos( (ScreenWidth() - iWidth) * 0.5, m_nOriginalY - nOffset );
  268. if ( m_pBGPanel )
  269. {
  270. m_pBGPanel->SetSize( iWidth, GetTall() );
  271. }
  272. }
  273. */
  274. BaseClass::PerformLayout();
  275. };
  276. //-----------------------------------------------------------------------------
  277. // Purpose: Draw function for the element
  278. //-----------------------------------------------------------------------------
  279. void CDisguiseStatus::Paint()
  280. {
  281. C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
  282. if ( !pPlayer )
  283. return;
  284. if ( !pPlayer->m_Shared.InCond( TF_COND_DISGUISED ) )
  285. return;
  286. // ConVarRef cl_hud_minmode( "cl_hud_minmode", true );
  287. // if ( cl_hud_minmode.IsValid() && cl_hud_minmode.GetBool() )
  288. // {
  289. // HideStatus();
  290. // return;
  291. // }
  292. CheckName();
  293. CheckWeapon();
  294. CheckHealth();
  295. }