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.

421 lines
12 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef TF_HUD_BUILDING_STATUS_H
  8. #define TF_HUD_BUILDING_STATUS_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "hudelement.h"
  13. #include "tf_controls.h"
  14. #include <vgui_controls/EditablePanel.h>
  15. #include <vgui/IScheme.h>
  16. #include <vgui_controls/ProgressBar.h>
  17. #include "utlpriorityqueue.h"
  18. class C_BaseObject;
  19. class CIconPanel;
  20. //-----------------------------------------------------------------------------
  21. // Purpose:
  22. //-----------------------------------------------------------------------------
  23. class CBuildingHealthBar : public vgui::ProgressBar
  24. {
  25. DECLARE_CLASS_SIMPLE( CBuildingHealthBar, vgui::ProgressBar );
  26. public:
  27. CBuildingHealthBar(Panel *parent, const char *panelName);
  28. virtual void Paint();
  29. virtual void PaintBackground();
  30. virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
  31. private:
  32. Color m_cHealthColor;
  33. Color m_cLowHealthColor;
  34. };
  35. //-----------------------------------------------------------------------------
  36. // Purpose:
  37. //-----------------------------------------------------------------------------
  38. class CBuildingStatusAlertTray : public vgui::Panel
  39. {
  40. DECLARE_CLASS_SIMPLE( CBuildingStatusAlertTray, vgui::Panel );
  41. public:
  42. CBuildingStatusAlertTray(Panel *parent, const char *panelName);
  43. void ApplySettings( KeyValues *inResourceData );
  44. virtual void Paint( void );
  45. virtual void PaintBackground( void );
  46. void LevelInit( void );
  47. void ShowTray( void );
  48. void HideTray( void );
  49. bool IsTrayOut( void ) { return m_bIsTrayOut; }
  50. void SetAlertType( BuildingHudAlert_t alertLevel );
  51. float GetPercentDeployed( void ) { return m_flAlertDeployedPercent; }
  52. BuildingHudAlert_t GetAlertType( void ) { return m_lastAlertType; }
  53. private:
  54. bool m_bIsTrayOut;
  55. bool m_bUseTallImage;
  56. CHudTexture *m_pAlertPanelHudTexture;
  57. IMaterial *m_pAlertPanelMaterial;
  58. BuildingHudAlert_t m_lastAlertType;
  59. CPanelAnimationVar( float, m_flAlertDeployedPercent, "deployed", "0.0" );
  60. };
  61. //-----------------------------------------------------------------------------
  62. // Purpose:
  63. //-----------------------------------------------------------------------------
  64. class CBuildingStatusItem : public vgui::EditablePanel
  65. {
  66. DECLARE_CLASS_SIMPLE( CBuildingStatusItem, vgui::EditablePanel );
  67. public:
  68. // actual panel constructor
  69. CBuildingStatusItem( Panel *parent, const char *szLayout, int iObjectType, int iObjectMode );
  70. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  71. virtual void Paint( void );
  72. virtual void PaintBackground( void );
  73. virtual void OnTick( void );
  74. virtual void PerformLayout( void );
  75. virtual void LevelInit( void );
  76. bool HasBeenPositioned() const { return bPositioned; }
  77. void SetPositioned(bool val) { bPositioned = val; }
  78. int GetRepresentativeObjectType();
  79. int GetRepresentativeObjectMode();
  80. C_BaseObject *GetRepresentativeObject();
  81. virtual int GetObjectPriority();
  82. virtual const char *GetBackgroundImage( void );
  83. virtual const char *GetInactiveBackgroundImage( void );
  84. vgui::EditablePanel *GetBuiltPanel() { return m_pBuiltPanel; }
  85. vgui::EditablePanel *GetNotBuiltPanel() { return m_pNotBuiltPanel; }
  86. vgui::EditablePanel *GetBuildingPanel() { return m_pBuildingPanel; }
  87. vgui::EditablePanel *GetRunningPanel() { return m_pRunningPanel; }
  88. virtual bool IsRealObject( void ) { return true; }
  89. void SetObject( C_BaseObject *pObj );
  90. bool IsActive( void ) { return m_bActive; }
  91. private:
  92. bool bPositioned; // false if we have not yet faded in and been positioned
  93. char m_szLayout[128];
  94. int m_iObjectType;
  95. int m_iObjectMode;
  96. bool m_bActive;
  97. // Two main subpanels
  98. vgui::EditablePanel *m_pNotBuiltPanel;
  99. vgui::EditablePanel *m_pBuiltPanel;
  100. // Subpanels of the m_pBuiltPanel
  101. vgui::EditablePanel *m_pBuildingPanel; // subpanel shown while building
  102. vgui::EditablePanel *m_pRunningPanel; // subpanel shown while built and running
  103. vgui::ProgressBar *m_pHealthBar; // health bar element
  104. CHandle<C_BaseObject> m_pObject; // pointer to the object we represent
  105. // Alert side panel
  106. CBuildingStatusAlertTray *m_pAlertTray;
  107. CIconPanel *m_pWrenchIcon;
  108. CIconPanel *m_pSapperIcon;
  109. CIconPanel *m_pUpgradeIcons[3];
  110. int m_iUpgradeLevel;
  111. // children of buildingPanel
  112. vgui::ContinuousProgressBar *m_pBuildingProgress;
  113. // elements that are always on
  114. // background
  115. CIconPanel *m_pBackground;
  116. };
  117. //-----------------------------------------------------------------------------
  118. // Purpose:
  119. //-----------------------------------------------------------------------------
  120. class CBuildingStatusItem_SentryGun : public CBuildingStatusItem
  121. {
  122. DECLARE_CLASS_SIMPLE( CBuildingStatusItem_SentryGun, CBuildingStatusItem );
  123. public:
  124. CBuildingStatusItem_SentryGun( Panel *parent );
  125. virtual void OnTick( void );
  126. virtual void PerformLayout( void );
  127. virtual void ApplySchemeSettings( vgui::IScheme *scheme );
  128. virtual const char *GetBackgroundImage( void );
  129. virtual const char *GetInactiveBackgroundImage( void );
  130. private:
  131. CIconPanel *m_pSentryIcons[3];
  132. vgui::ImagePanel *m_pRocketIcon;
  133. CIconPanel *m_pUpgradeIcon;
  134. vgui::ContinuousProgressBar *m_pShellsProgress;
  135. vgui::ContinuousProgressBar *m_pRocketsProgress;
  136. vgui::ContinuousProgressBar *m_pUpgradeProgress;
  137. int m_iUpgradeLevel;
  138. // Ammo
  139. Color m_cLowAmmoColor;
  140. Color m_cNormalAmmoColor;
  141. };
  142. //-----------------------------------------------------------------------------
  143. // Purpose:
  144. //-----------------------------------------------------------------------------
  145. class CBuildingStatusItem_SentryGun_Disposable : public CBuildingStatusItem
  146. {
  147. DECLARE_CLASS_SIMPLE( CBuildingStatusItem_SentryGun_Disposable, CBuildingStatusItem );
  148. public:
  149. CBuildingStatusItem_SentryGun_Disposable( Panel *parent );
  150. virtual void OnTick( void );
  151. virtual void PerformLayout( void );
  152. virtual void ApplySchemeSettings( vgui::IScheme *scheme );
  153. virtual const char *GetBackgroundImage( void );
  154. virtual const char *GetInactiveBackgroundImage( void );
  155. private:
  156. CIconPanel *m_pSentryIcons[3];
  157. CIconPanel *m_pUpgradeIcon;
  158. vgui::ContinuousProgressBar *m_pShellsProgress;
  159. int m_iUpgradeLevel;
  160. // Ammo
  161. Color m_cLowAmmoColor;
  162. Color m_cNormalAmmoColor;
  163. };
  164. //-----------------------------------------------------------------------------
  165. // Purpose:
  166. //-----------------------------------------------------------------------------
  167. class CBuildingStatusItem_Dispenser : public CBuildingStatusItem
  168. {
  169. DECLARE_CLASS_SIMPLE( CBuildingStatusItem_Dispenser, CBuildingStatusItem );
  170. public:
  171. CBuildingStatusItem_Dispenser( Panel *parent );
  172. virtual void PerformLayout( void );
  173. private:
  174. CIconPanel *m_pUpgradeIcon;
  175. vgui::ContinuousProgressBar *m_pAmmoProgress;
  176. vgui::ContinuousProgressBar *m_pUpgradeProgress;
  177. };
  178. //-----------------------------------------------------------------------------
  179. // Purpose:
  180. //-----------------------------------------------------------------------------
  181. class CBuildingStatusItem_TeleporterEntrance : public CBuildingStatusItem
  182. {
  183. DECLARE_CLASS_SIMPLE( CBuildingStatusItem_TeleporterEntrance, CBuildingStatusItem );
  184. public:
  185. CBuildingStatusItem_TeleporterEntrance( Panel *parent );
  186. virtual void OnTick( void );
  187. virtual void PerformLayout( void );
  188. private:
  189. // 2 subpanels
  190. vgui::EditablePanel *m_pChargingPanel;
  191. vgui::EditablePanel *m_pFullyChargedPanel;
  192. // children of m_pChargingPanel
  193. vgui::ContinuousProgressBar *m_pRechargeTimer;
  194. // local state
  195. int m_iTeleporterState;
  196. int m_iTimesUsed;
  197. CIconPanel *m_pUpgradeIcon;
  198. vgui::ContinuousProgressBar *m_pUpgradeProgress;
  199. };
  200. //-----------------------------------------------------------------------------
  201. // Purpose:
  202. //-----------------------------------------------------------------------------
  203. class CBuildingStatusItem_TeleporterExit : public CBuildingStatusItem
  204. {
  205. DECLARE_CLASS_SIMPLE( CBuildingStatusItem_TeleporterExit, CBuildingStatusItem );
  206. public:
  207. CBuildingStatusItem_TeleporterExit( Panel *parent );
  208. virtual void PerformLayout( void );
  209. private:
  210. CIconPanel *m_pUpgradeIcon;
  211. vgui::ContinuousProgressBar *m_pUpgradeProgress;
  212. };
  213. #ifdef STAGING_ONLY
  214. //-----------------------------------------------------------------------------
  215. class CBuildingStatusItem_TeleporterSpeed : public CBuildingStatusItem
  216. {
  217. DECLARE_CLASS_SIMPLE( CBuildingStatusItem_TeleporterSpeed, CBuildingStatusItem );
  218. public:
  219. CBuildingStatusItem_TeleporterSpeed( Panel *parent, int ETeleporterMode );
  220. virtual void OnTick( void );
  221. virtual void PerformLayout( void );
  222. private:
  223. // 2 subpanels
  224. vgui::EditablePanel *m_pChargingPanel;
  225. vgui::EditablePanel *m_pFullyChargedPanel;
  226. // children of m_pChargingPanel
  227. vgui::ContinuousProgressBar *m_pRechargeTimer;
  228. // local state
  229. int m_iTeleporterState;
  230. int m_iTimesUsed;
  231. CIconPanel *m_pUpgradeIcon;
  232. vgui::ContinuousProgressBar *m_pUpgradeProgress;
  233. };
  234. #endif
  235. //-----------------------------------------------------------------------------
  236. // Purpose:
  237. //-----------------------------------------------------------------------------
  238. class CBuildingStatusItem_Sapper : public CBuildingStatusItem
  239. {
  240. DECLARE_CLASS_SIMPLE( CBuildingStatusItem_Sapper, CBuildingStatusItem );
  241. public:
  242. CBuildingStatusItem_Sapper( Panel *parent );
  243. virtual void PerformLayout( void );
  244. private:
  245. // Health of target building
  246. vgui::ContinuousProgressBar *m_pTargetHealthBar;
  247. // image of target building
  248. CIconPanel *m_pTargetIcon;
  249. int m_iTargetType;
  250. };
  251. //-----------------------------------------------------------------------------
  252. // Purpose: Container panel for object status panels
  253. //-----------------------------------------------------------------------------
  254. class CHudBuildingStatusContainer : public CHudElement, public vgui::Panel
  255. {
  256. DECLARE_CLASS_SIMPLE( CHudBuildingStatusContainer, vgui::Panel );
  257. public:
  258. CHudBuildingStatusContainer( const char *pElementName );
  259. virtual bool ShouldDraw( void );
  260. virtual void ApplySchemeSettings( vgui::IScheme *scheme );
  261. virtual void OnTick( void );
  262. virtual void LevelInit( void );
  263. void AddBuildingPanel( int iBuildingType, int iBuildingMode=0 );
  264. CBuildingStatusItem *CreateItemPanel( int iObjectType, int iObjectMode );
  265. void UpdateAllBuildings( void );
  266. void OnBuildingChanged( int iBuildingType, int iBuildingMode, bool bBuildingIsDead );
  267. void RepositionObjectPanels();
  268. void FireGameEvent( IGameEvent *event );
  269. void RecalculateAlertState( void );
  270. protected:
  271. // a list of CBuildingStatusItems that we're showing
  272. CUtlPriorityQueue< CBuildingStatusItem * > m_BuildingPanels;
  273. private:
  274. BuildingHudAlert_t m_AlertLevel;
  275. float m_flNextBeep;
  276. int m_iNumBeepsToBeep;
  277. };
  278. //-----------------------------------------------------------------------------
  279. // Purpose: Separate panels for spy
  280. //-----------------------------------------------------------------------------
  281. class CHudBuildingStatusContainer_Spy : public CHudBuildingStatusContainer
  282. {
  283. DECLARE_CLASS_SIMPLE( CHudBuildingStatusContainer_Spy, CHudBuildingStatusContainer );
  284. public:
  285. CHudBuildingStatusContainer_Spy( const char *pElementName );
  286. virtual bool ShouldDraw( void );
  287. };
  288. //-----------------------------------------------------------------------------
  289. // Purpose: Separate panels for engineer
  290. //-----------------------------------------------------------------------------
  291. class CHudBuildingStatusContainer_Engineer : public CHudBuildingStatusContainer
  292. {
  293. DECLARE_CLASS_SIMPLE( CHudBuildingStatusContainer_Engineer, CHudBuildingStatusContainer );
  294. public:
  295. CHudBuildingStatusContainer_Engineer( const char *pElementName );
  296. virtual bool ShouldDraw( void );
  297. virtual void OnTick( void );
  298. };
  299. #endif //TF_HUD_BUILDING_STATUS_H