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.

336 lines
11 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "c_vguiscreen.h"
  10. #include <vgui/IVGui.h>
  11. #include "ienginevgui.h"
  12. #include "vgui_bitmapimage.h"
  13. #include "vgui_bitmappanel.h"
  14. #include "vgui_controls/Label.h"
  15. #include "tf_weapon_pda.h"
  16. #include "vgui/ISurface.h"
  17. #include "tf_controls.h"
  18. #include "c_tf_player.h"
  19. #include "tf_weapon_invis.h"
  20. #include <vgui_controls/RadioButton.h>
  21. #include "clientmode.h"
  22. #include <vgui_controls/ProgressBar.h>
  23. #include <vgui_controls/CircularProgressBar.h>
  24. using namespace vgui;
  25. //-----------------------------------------------------------------------------
  26. // Control screen
  27. //-----------------------------------------------------------------------------
  28. class CPDAPanel : public CVGuiScreenPanel
  29. {
  30. DECLARE_CLASS( CPDAPanel, CVGuiScreenPanel );
  31. public:
  32. CPDAPanel( vgui::Panel *parent, const char *panelName );
  33. ~CPDAPanel();
  34. virtual bool Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData );
  35. virtual void OnTick();
  36. protected:
  37. C_BaseCombatWeapon *GetOwningWeapon();
  38. };
  39. DECLARE_VGUI_SCREEN_FACTORY( CPDAPanel, "pda_panel" );
  40. //-----------------------------------------------------------------------------
  41. // Constructor:
  42. //-----------------------------------------------------------------------------
  43. CPDAPanel::CPDAPanel( vgui::Panel *parent, const char *panelName )
  44. : BaseClass( parent, "CPDAPanel", vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), "resource/PDAControlPanelScheme.res", "TFBase" ) )
  45. {
  46. }
  47. CPDAPanel::~CPDAPanel()
  48. {
  49. }
  50. //-----------------------------------------------------------------------------
  51. // Initialization
  52. //-----------------------------------------------------------------------------
  53. bool CPDAPanel::Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData )
  54. {
  55. // Make sure we get ticked...
  56. vgui::ivgui()->AddTickSignal( GetVPanel() );
  57. if (!BaseClass::Init(pKeyValues, pInitData))
  58. return false;
  59. return true;
  60. }
  61. //-----------------------------------------------------------------------------
  62. // Returns the object it's attached to
  63. //-----------------------------------------------------------------------------
  64. C_BaseCombatWeapon *CPDAPanel::GetOwningWeapon()
  65. {
  66. C_BaseEntity *pScreenEnt = GetEntity();
  67. if (!pScreenEnt)
  68. return NULL;
  69. C_BaseEntity *pOwner = pScreenEnt->GetOwnerEntity();
  70. if (!pOwner)
  71. return NULL;
  72. C_BaseViewModel *pViewModel = dynamic_cast< C_BaseViewModel * >( pOwner );
  73. if ( !pViewModel )
  74. return NULL;
  75. return pViewModel->GetOwningWeapon();
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Frame-based update
  79. //-----------------------------------------------------------------------------
  80. void CPDAPanel::OnTick()
  81. {
  82. BaseClass::OnTick();
  83. SetVisible( true );
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Engineer Destroy PDA
  87. //-----------------------------------------------------------------------------
  88. class CPDAPanel_Engineer_Destroy : public CPDAPanel
  89. {
  90. DECLARE_CLASS( CPDAPanel_Engineer_Destroy, CPDAPanel );
  91. public:
  92. CPDAPanel_Engineer_Destroy( vgui::Panel *parent, const char *panelName );
  93. };
  94. DECLARE_VGUI_SCREEN_FACTORY( CPDAPanel_Engineer_Destroy, "pda_panel_engineer_destroy" );
  95. //-----------------------------------------------------------------------------
  96. // Constructor:
  97. //-----------------------------------------------------------------------------
  98. CPDAPanel_Engineer_Destroy::CPDAPanel_Engineer_Destroy( vgui::Panel *parent, const char *panelName )
  99. : CPDAPanel( parent, "CPDAPanel_Engineer_Destroy" )
  100. {
  101. }
  102. //-----------------------------------------------------------------------------
  103. // Engineer Build PDA
  104. //-----------------------------------------------------------------------------
  105. class CPDAPanel_Engineer_Build : public CPDAPanel
  106. {
  107. DECLARE_CLASS( CPDAPanel_Engineer_Build, CPDAPanel );
  108. public:
  109. CPDAPanel_Engineer_Build( vgui::Panel *parent, const char *panelName );
  110. };
  111. DECLARE_VGUI_SCREEN_FACTORY( CPDAPanel_Engineer_Build, "pda_panel_engineer_build" );
  112. //-----------------------------------------------------------------------------
  113. // Constructor:
  114. //-----------------------------------------------------------------------------
  115. CPDAPanel_Engineer_Build::CPDAPanel_Engineer_Build( vgui::Panel *parent, const char *panelName )
  116. : CPDAPanel( parent, "CPDAPanel_Engineer" )
  117. {
  118. }
  119. //-----------------------------------------------------------------------------
  120. // Spy PDA
  121. //-----------------------------------------------------------------------------
  122. class CPDAPanel_Spy : public CPDAPanel
  123. {
  124. DECLARE_CLASS( CPDAPanel_Spy, CPDAPanel );
  125. public:
  126. CPDAPanel_Spy( vgui::Panel *parent, const char *panelName );
  127. };
  128. DECLARE_VGUI_SCREEN_FACTORY( CPDAPanel_Spy, "pda_panel_spy" );
  129. //-----------------------------------------------------------------------------
  130. // Constructor:
  131. //-----------------------------------------------------------------------------
  132. CPDAPanel_Spy::CPDAPanel_Spy( vgui::Panel *parent, const char *panelName )
  133. : CPDAPanel( parent, "CPDAPanel_Spy" )
  134. {
  135. }
  136. //-----------------------------------------------------------------------------
  137. // Spy Invis PDA
  138. //-----------------------------------------------------------------------------
  139. class CPDAPanel_Spy_Invis : public CPDAPanel
  140. {
  141. DECLARE_CLASS( CPDAPanel_Spy_Invis, CPDAPanel );
  142. public:
  143. CPDAPanel_Spy_Invis( vgui::Panel *parent, const char *panelName );
  144. virtual void OnTick();
  145. private:
  146. ProgressBar *m_pInvisProgress;
  147. };
  148. DECLARE_VGUI_SCREEN_FACTORY( CPDAPanel_Spy_Invis, "pda_panel_spy_invis" );
  149. //-----------------------------------------------------------------------------
  150. // Constructor:
  151. //-----------------------------------------------------------------------------
  152. CPDAPanel_Spy_Invis::CPDAPanel_Spy_Invis( vgui::Panel *parent, const char *panelName )
  153. : CPDAPanel( parent, "CPDAPanel_Spy_Invis" )
  154. {
  155. vgui::ivgui()->AddTickSignal( GetVPanel() );
  156. m_pInvisProgress = new ProgressBar( this, "InvisProgress" );
  157. }
  158. //-----------------------------------------------------------------------------
  159. // Update the progress bar with how much invis we have left
  160. //-----------------------------------------------------------------------------
  161. void CPDAPanel_Spy_Invis::OnTick( void )
  162. {
  163. C_BaseCombatWeapon *pInvisWeapon = GetOwningWeapon();
  164. if ( !pInvisWeapon )
  165. return;
  166. C_TFPlayer *pPlayer = ToTFPlayer( pInvisWeapon->GetOwner() );
  167. if ( pPlayer && !pPlayer->IsDormant() )
  168. {
  169. if ( m_pInvisProgress )
  170. {
  171. float flMeter = pPlayer->m_Shared.GetSpyCloakMeter();
  172. m_pInvisProgress->SetProgress( flMeter / 100.0f );
  173. }
  174. }
  175. }
  176. //-----------------------------------------------------------------------------
  177. // Spy Invis PDA panel for the pocketwatch
  178. //-----------------------------------------------------------------------------
  179. class CPDAPanel_Spy_Invis_Pocket : public CPDAPanel
  180. {
  181. DECLARE_CLASS( CPDAPanel_Spy_Invis_Pocket, CPDAPanel );
  182. public:
  183. CPDAPanel_Spy_Invis_Pocket( vgui::Panel *parent, const char *panelName );
  184. virtual void OnTick();
  185. protected:
  186. ProgressBar *m_pInvisProgress;
  187. float m_flPrevProgress;
  188. };
  189. DECLARE_VGUI_SCREEN_FACTORY( CPDAPanel_Spy_Invis_Pocket, "pda_panel_spy_invis_pocket" );
  190. //-----------------------------------------------------------------------------
  191. // Constructor:
  192. //-----------------------------------------------------------------------------
  193. CPDAPanel_Spy_Invis_Pocket::CPDAPanel_Spy_Invis_Pocket( vgui::Panel *parent, const char *panelName )
  194. : CPDAPanel( parent, "CPDAPanel_Spy_Invis_Pocket" )
  195. {
  196. vgui::ivgui()->AddTickSignal( GetVPanel() );
  197. CircularProgressBar* pCircularProgressBar = new CircularProgressBar( this, "InvisProgress" );
  198. pCircularProgressBar->SetReverseProgress( true );
  199. m_pInvisProgress = pCircularProgressBar;
  200. m_flPrevProgress = -1;
  201. }
  202. //-----------------------------------------------------------------------------
  203. // Update the progress bar with how much invis we have left
  204. //-----------------------------------------------------------------------------
  205. void CPDAPanel_Spy_Invis_Pocket::OnTick( void )
  206. {
  207. C_BaseCombatWeapon *pInvisWeapon = GetOwningWeapon();
  208. if ( !pInvisWeapon )
  209. return;
  210. C_TFPlayer *pPlayer = ToTFPlayer( pInvisWeapon->GetOwner() );
  211. if ( pPlayer && !pPlayer->IsDormant() )
  212. {
  213. if ( m_pInvisProgress )
  214. {
  215. float flMeter = pPlayer->m_Shared.GetSpyCloakMeter();
  216. if ( m_flPrevProgress != flMeter )
  217. {
  218. m_flPrevProgress = flMeter;
  219. if ( flMeter == 100.f )
  220. {
  221. m_pInvisProgress->SetFgColor( COLOR_GREEN );
  222. }
  223. else if ( flMeter < 40.f )
  224. {
  225. m_pInvisProgress->SetFgColor( COLOR_RED );
  226. }
  227. else
  228. {
  229. m_pInvisProgress->SetFgColor( COLOR_YELLOW );
  230. }
  231. m_pInvisProgress->SetProgress( flMeter / 100.0f );
  232. }
  233. }
  234. }
  235. }
  236. //-----------------------------------------------------------------------------
  237. // Spy Invis PDA panel for the TTG pocketwatch
  238. //-----------------------------------------------------------------------------
  239. class CPDAPanel_Spy_Invis_Pocket_TTG : public CPDAPanel_Spy_Invis_Pocket
  240. {
  241. DECLARE_CLASS( CPDAPanel_Spy_Invis_Pocket_TTG, CPDAPanel_Spy_Invis_Pocket );
  242. public:
  243. CPDAPanel_Spy_Invis_Pocket_TTG( vgui::Panel *parent, const char *panelName );
  244. };
  245. DECLARE_VGUI_SCREEN_FACTORY( CPDAPanel_Spy_Invis_Pocket_TTG, "pda_panel_spy_invis_pocket_ttg" );
  246. //-----------------------------------------------------------------------------
  247. // Constructor:
  248. //-----------------------------------------------------------------------------
  249. CPDAPanel_Spy_Invis_Pocket_TTG::CPDAPanel_Spy_Invis_Pocket_TTG( vgui::Panel *parent, const char *panelName )
  250. : CPDAPanel_Spy_Invis_Pocket( parent, "CPDAPanel_Spy_Invis_Pocket_TTG" )
  251. {
  252. dynamic_cast<CircularProgressBar*>(m_pInvisProgress)->SetStartSegment( 7 ); // Do the pellet first.
  253. }
  254. //-----------------------------------------------------------------------------
  255. // Spy Invis PDA panel for the Hitman pocketwatch
  256. //-----------------------------------------------------------------------------
  257. class CPDAPanel_Spy_Invis_Pocket_HM : public CPDAPanel_Spy_Invis_Pocket
  258. {
  259. DECLARE_CLASS( CPDAPanel_Spy_Invis_Pocket_HM, CPDAPanel_Spy_Invis_Pocket );
  260. public:
  261. CPDAPanel_Spy_Invis_Pocket_HM( vgui::Panel *parent, const char *panelName );
  262. };
  263. DECLARE_VGUI_SCREEN_FACTORY( CPDAPanel_Spy_Invis_Pocket_HM, "pda_panel_spy_invis_pocket_hm" );
  264. //-----------------------------------------------------------------------------
  265. // Constructor:
  266. //-----------------------------------------------------------------------------
  267. CPDAPanel_Spy_Invis_Pocket_HM::CPDAPanel_Spy_Invis_Pocket_HM( vgui::Panel *parent, const char *panelName )
  268. : CPDAPanel_Spy_Invis_Pocket( parent, "CPDAPanel_Spy_Invis_Pocket_HM" )
  269. {
  270. }