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.

302 lines
6.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef BUYPRESET_WEAPONSETLABEL_H
  7. #define BUYPRESET_WEAPONSETLABEL_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include <vgui/VGUI.h>
  12. #include <vgui_controls/Panel.h>
  13. #include <vgui/IImage.h>
  14. namespace vgui
  15. {
  16. class TextImage;
  17. class TextEntry;
  18. };
  19. //--------------------------------------------------------------------------------------------------------------
  20. /// Helper function: draws a simple dashed line
  21. void DrawDashedLine(int x0, int y0, int x1, int y1, int dashLen, int gapLen);
  22. //--------------------------------------------------------------------------------------------------------------
  23. // Purpose: Wraps an IImage to perform resizes properly
  24. class BuyPresetImage : public vgui::IImage
  25. {
  26. public:
  27. BuyPresetImage( vgui::IImage *realImage )
  28. {
  29. m_image = realImage;
  30. if ( m_image )
  31. {
  32. m_image->GetSize( m_wide, m_tall );
  33. }
  34. else
  35. {
  36. m_wide = m_tall = 0;
  37. }
  38. }
  39. // Call to Paint the image
  40. // Image will draw within the current panel context at the specified position
  41. virtual void Paint()
  42. {
  43. if ( !m_image )
  44. return;
  45. m_image->Paint();
  46. }
  47. // Set the position of the image
  48. virtual void SetPos(int x, int y)
  49. {
  50. if ( !m_image )
  51. return;
  52. m_image->SetPos( x, y );
  53. }
  54. // Gets the size of the content
  55. virtual void GetContentSize(int &wide, int &tall)
  56. {
  57. if ( !m_image )
  58. return;
  59. m_image->GetSize( wide, tall );
  60. }
  61. // Get the size the image will actually draw in (usually defaults to the content size)
  62. virtual void GetSize(int &wide, int &tall)
  63. {
  64. if ( !m_image )
  65. {
  66. wide = tall = 0;
  67. return;
  68. }
  69. wide = m_wide;
  70. tall = m_tall;
  71. }
  72. // Sets the size of the image
  73. virtual void SetSize(int wide, int tall)
  74. {
  75. m_wide = wide;
  76. m_tall = tall;
  77. if ( !m_image )
  78. return;
  79. m_image->SetSize( wide, tall );
  80. }
  81. // Set the draw color
  82. virtual void SetColor(Color col)
  83. {
  84. if ( !m_image )
  85. return;
  86. m_image->SetColor( col );
  87. }
  88. virtual bool Evict()
  89. {
  90. return false;
  91. }
  92. virtual int GetNumFrames()
  93. {
  94. return 0;
  95. }
  96. virtual void SetFrame( int nFrame )
  97. {
  98. }
  99. virtual vgui::HTexture GetID()
  100. {
  101. return 0;
  102. }
  103. virtual void SetRotation( int iRotation )
  104. {
  105. return;
  106. }
  107. private:
  108. vgui::IImage *m_image;
  109. int m_wide, m_tall;
  110. };
  111. //--------------------------------------------------------------------------------------------------------------
  112. struct ImageInfo {
  113. vgui::IImage *image;
  114. int w;
  115. int h;
  116. int x;
  117. int y;
  118. int fullW;
  119. int fullH;
  120. void FitInBounds( int baseX, int baseY, int width, int height, bool center, int scaleAt1024, bool halfHeight = false );
  121. void Paint();
  122. };
  123. //--------------------------------------------------------------------------------------------------------------
  124. class WeaponImageInfo
  125. {
  126. public:
  127. WeaponImageInfo();
  128. ~WeaponImageInfo();
  129. void SetBounds( int left, int top, int wide, int tall );
  130. void SetCentered( bool isCentered );
  131. void SetScaleAt1024( int weaponScale, int ammoScale );
  132. void SetWeapon( const BuyPresetWeapon *pWeapon, bool isPrimary, bool useCurrentAmmoType );
  133. void ApplyTextSettings( vgui::IScheme *pScheme, bool isProportional );
  134. void Paint();
  135. void PaintText();
  136. private:
  137. void PerformLayout();
  138. int m_left;
  139. int m_top;
  140. int m_wide;
  141. int m_tall;
  142. bool m_isPrimary;
  143. int m_weaponScale;
  144. int m_ammoScale;
  145. bool m_needLayout;
  146. bool m_isCentered;
  147. ImageInfo m_weapon;
  148. ImageInfo m_ammo;
  149. vgui::TextImage *m_pAmmoText;
  150. };
  151. //--------------------------------------------------------------------------------------------------------------
  152. class ItemImageInfo
  153. {
  154. public:
  155. ItemImageInfo();
  156. ~ItemImageInfo();
  157. void SetBounds( int left, int top, int wide, int tall );
  158. void SetItem( const char *imageFname, int count );
  159. void ApplyTextSettings( vgui::IScheme *pScheme, bool isProportional );
  160. void Paint();
  161. void PaintText();
  162. private:
  163. void PerformLayout();
  164. int m_left;
  165. int m_top;
  166. int m_wide;
  167. int m_tall;
  168. int m_count;
  169. bool m_needLayout;
  170. ImageInfo m_image;
  171. vgui::TextImage *m_pText;
  172. };
  173. //--------------------------------------------------------------------------------------------------------------
  174. class WeaponLabel : public vgui::Panel
  175. {
  176. typedef vgui::Panel BaseClass;
  177. public:
  178. WeaponLabel(vgui::Panel *parent, const char *panelName);
  179. ~WeaponLabel();
  180. void SetWeapon( const BuyPresetWeapon *pWeapon, bool isPrimary, bool showAmmo = false );
  181. virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
  182. virtual void PerformLayout();
  183. virtual void Paint();
  184. protected:
  185. WeaponImageInfo m_weapon;
  186. };
  187. //--------------------------------------------------------------------------------------------------------------
  188. class EquipmentLabel : public vgui::Panel
  189. {
  190. typedef vgui::Panel BaseClass;
  191. public:
  192. EquipmentLabel(vgui::Panel *parent, const char *panelName, const char *imageFname = NULL);
  193. ~EquipmentLabel();
  194. void SetItem( const char *imageFname, int count );
  195. virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
  196. virtual void PerformLayout();
  197. virtual void Paint();
  198. protected:
  199. ItemImageInfo m_item;
  200. };
  201. //--------------------------------------------------------------------------------------------------------------
  202. /**
  203. * BuyPresetEditPanel is a panel displaying a graphical representation of a buy preset.
  204. */
  205. class BuyPresetEditPanel : public vgui::EditablePanel
  206. {
  207. typedef vgui::EditablePanel BaseClass;
  208. public:
  209. BuyPresetEditPanel( vgui::Panel *parent, const char *panelName, const char *resourceFilename, int fallbackIndex, bool editableName );
  210. virtual ~BuyPresetEditPanel();
  211. void SetWeaponSet( const WeaponSet *pWeaponSet, bool current );
  212. virtual void SetText( const wchar_t *text );
  213. virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
  214. void OnCommand( const char *command); ///< Handle command callbacks
  215. virtual void OnSizeChanged( int wide, int tall );
  216. void SetPanelBgColor( Color color ) { if (m_pBgPanel) m_pBgPanel->SetBgColor( color ); }
  217. protected:
  218. void Reset();
  219. vgui::Panel *m_pBgPanel;
  220. vgui::TextEntry *m_pTitleEntry;
  221. vgui::Label *m_pTitleLabel;
  222. vgui::Label *m_pCostLabel;
  223. WeaponLabel *m_pPrimaryWeapon;
  224. WeaponLabel *m_pSecondaryWeapon;
  225. EquipmentLabel *m_pHEGrenade;
  226. EquipmentLabel *m_pSmokeGrenade;
  227. EquipmentLabel *m_pFlashbangs;
  228. EquipmentLabel *m_pDefuser;
  229. EquipmentLabel *m_pNightvision;
  230. EquipmentLabel *m_pArmor;
  231. int m_baseWide;
  232. int m_baseTall;
  233. int m_fallbackIndex;
  234. };
  235. #endif // BUYPRESET_WEAPONSETLABEL_H