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.

308 lines
9.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef TF_CONTROLS_H
  8. #define TF_CONTROLS_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <vgui/IScheme.h>
  13. #include <vgui/KeyCode.h>
  14. #include <KeyValues.h>
  15. #include <vgui/IVGui.h>
  16. #include <vgui_controls/ScrollBar.h>
  17. #include <vgui_controls/EditablePanel.h>
  18. #include <vgui_controls/Button.h>
  19. #include <vgui_controls/Label.h>
  20. #include <vgui_controls/RichText.h>
  21. #include "utlvector.h"
  22. #include "vgui_controls/PHandle.h"
  23. #include <vgui_controls/Tooltip.h>
  24. #include "econ_controls.h"
  25. #include "sc_hinticon.h"
  26. #if defined( TF_CLIENT_DLL )
  27. #include "tf_shareddefs.h"
  28. #include "tf_imagepanel.h"
  29. #endif
  30. #include <vgui_controls/Frame.h>
  31. #include <../common/GameUI/scriptobject.h>
  32. #include <vgui/KeyCode.h>
  33. #include <vgui_controls/Tooltip.h>
  34. #include <vgui_controls/CheckButton.h>
  35. wchar_t* LocalizeNumberWithToken( const char* pszLocToken, int nValue );
  36. //-----------------------------------------------------------------------------
  37. // Purpose: Xbox-specific panel that displays button icons text labels
  38. //-----------------------------------------------------------------------------
  39. class CTFFooter : public vgui::EditablePanel
  40. {
  41. DECLARE_CLASS_SIMPLE( CTFFooter, vgui::EditablePanel );
  42. public:
  43. CTFFooter( Panel *parent, const char *panelName );
  44. virtual ~CTFFooter();
  45. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  46. virtual void ApplySettings( KeyValues *pResourceData );
  47. virtual void Paint( void );
  48. virtual void PaintBackground( void );
  49. void ShowButtonLabel( const char *name, bool show = true );
  50. void AddNewButtonLabel( const char *name, const char *text, const char *icon );
  51. void ClearButtons();
  52. private:
  53. struct FooterButton_t
  54. {
  55. bool bVisible;
  56. char name[MAX_PATH];
  57. wchar_t text[MAX_PATH];
  58. wchar_t icon[3]; // icon can be one or two characters
  59. };
  60. CUtlVector< FooterButton_t* > m_Buttons;
  61. bool m_bPaintBackground; // fill the background?
  62. int m_nButtonGap; // space between buttons
  63. int m_FooterTall; // height of the footer
  64. int m_ButtonOffsetFromTop; // how far below the top the buttons should be drawn
  65. int m_ButtonSeparator; // space between the button icon and text
  66. int m_TextAdjust; // extra adjustment for the text (vertically)...text is centered on the button icon and then this value is applied
  67. bool m_bCenterHorizontal; // center buttons horizontally?
  68. int m_ButtonPinRight; // if not centered, this is the distance from the right margin that we use to start drawing buttons (right to left)
  69. char m_szTextFont[64]; // font for the button text
  70. char m_szButtonFont[64]; // font for the button icon
  71. char m_szFGColor[64]; // foreground color (text)
  72. char m_szBGColor[64]; // background color (fill color)
  73. vgui::HFont m_hButtonFont;
  74. vgui::HFont m_hTextFont;
  75. };
  76. //-----------------------------------------------------------------------------
  77. // Purpose: Tooltip for the main menu. Isn't a panel, it just wraps the
  78. // show/hide/position handling for the embedded panel.
  79. //-----------------------------------------------------------------------------
  80. class CMainMenuToolTip : public vgui::BaseTooltip
  81. {
  82. DECLARE_CLASS_SIMPLE( CMainMenuToolTip, vgui::BaseTooltip );
  83. public:
  84. CMainMenuToolTip(vgui::Panel *parent, const char *text = NULL) : vgui::BaseTooltip( parent, text )
  85. {
  86. m_pEmbeddedPanel = NULL;
  87. }
  88. virtual ~CMainMenuToolTip() {}
  89. virtual void SetText(const char *text);
  90. const char *GetText() { return NULL; }
  91. virtual void HideTooltip();
  92. virtual void PerformLayout();
  93. void SetEmbeddedPanel( vgui::EditablePanel *pPanel )
  94. {
  95. m_pEmbeddedPanel = pPanel;
  96. }
  97. protected:
  98. vgui::EditablePanel *m_pEmbeddedPanel;
  99. };
  100. //-----------------------------------------------------------------------------
  101. // Purpose: Simple TF-styled text tooltip
  102. //-----------------------------------------------------------------------------
  103. class CTFTextToolTip : public CMainMenuToolTip
  104. {
  105. DECLARE_CLASS_SIMPLE( CTFTextToolTip, CMainMenuToolTip );
  106. public:
  107. CTFTextToolTip(vgui::Panel *parent, const char *text = NULL) : CMainMenuToolTip( parent, text )
  108. {
  109. }
  110. virtual void PerformLayout();
  111. virtual void PositionWindow( vgui::Panel *pTipPanel );
  112. virtual void SetText(const char *text)
  113. {
  114. _isDirty = true;
  115. BaseClass::SetText( text );
  116. }
  117. };
  118. //-----------------------------------------------------------------------------
  119. // Purpose: Displays a TF specific list of options
  120. // This is essentially a TF-styled version of the GameUI Advanced Multiplayer Options Dialog
  121. //-----------------------------------------------------------------------------
  122. class CTFAdvancedOptionsDialog : public vgui::EditablePanel
  123. {
  124. DECLARE_CLASS_SIMPLE( CTFAdvancedOptionsDialog, vgui::EditablePanel );
  125. public:
  126. CTFAdvancedOptionsDialog(vgui::Panel *parent);
  127. ~CTFAdvancedOptionsDialog();
  128. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  129. virtual void ApplySettings( KeyValues *pResourceData );
  130. void Deploy( void );
  131. private:
  132. void CreateControls();
  133. void DestroyControls();
  134. void GatherCurrentValues();
  135. void SaveValues();
  136. virtual void OnCommand( const char *command );
  137. virtual void OnClose();
  138. virtual void OnKeyCodeTyped(vgui::KeyCode code);
  139. virtual void OnKeyCodePressed(vgui::KeyCode code);
  140. private:
  141. CInfoDescription *m_pDescription;
  142. mpcontrol_t *m_pList;
  143. vgui::PanelListPanel *m_pListPanel;
  144. CTFTextToolTip *m_pToolTip;
  145. vgui::EditablePanel *m_pToolTipEmbeddedPanel;
  146. CPanelAnimationVarAliasType( int, m_iControlW, "control_w", "0", "proportional_int" );
  147. CPanelAnimationVarAliasType( int, m_iControlH, "control_h", "0", "proportional_int" );
  148. CPanelAnimationVarAliasType( int, m_iSliderW, "slider_w", "0", "proportional_int" );
  149. CPanelAnimationVarAliasType( int, m_iSliderH, "slider_h", "0", "proportional_int" );
  150. };
  151. //-----------------------------------------------------------------------------
  152. // Purpose: Scrollable panel where you can define children within the .res file
  153. //-----------------------------------------------------------------------------
  154. class CExScrollingEditablePanel : public vgui::EditablePanel
  155. {
  156. DECLARE_CLASS_SIMPLE( CExScrollingEditablePanel, vgui::EditablePanel );
  157. public:
  158. CExScrollingEditablePanel( Panel *pParent, const char *pszName );
  159. virtual ~CExScrollingEditablePanel();
  160. virtual void ApplySettings( KeyValues *inResourceData ) OVERRIDE;
  161. virtual void PerformLayout() OVERRIDE;
  162. virtual void OnSizeChanged( int newWide, int newTall ) OVERRIDE;
  163. MESSAGE_FUNC( OnScrollBarSliderMoved, "ScrollBarSliderMoved" );
  164. virtual void OnMouseWheeled( int delta ) OVERRIDE; // respond to mouse wheel events
  165. void ResetScrollAmount() { m_nLastScrollValue = 0; m_pScrollBar->SetValue(0); }
  166. protected:
  167. void ShiftChildren( int nDistance );
  168. vgui::ScrollBar *m_pScrollBar;
  169. int m_nLastScrollValue;
  170. bool m_bUseMouseWheelToScroll;
  171. CPanelAnimationVarAliasType( int, m_iScrollStep, "scroll_step", "10", "proportional_xpos" );
  172. CPanelAnimationVarAliasType( int, m_iBottomBuffer, "bottom_buffer", "0", "proportional_int" );
  173. CPanelAnimationVarAliasType( int, m_bRestrictWidth, "restrict_width", "1", "proportional_int" );
  174. };
  175. //-----------------------------------------------------------------------------
  176. // An extension of CExScrollingEditablePanel where panels can be added to form
  177. // a list.
  178. //-----------------------------------------------------------------------------
  179. class CScrollableList : public CExScrollingEditablePanel
  180. {
  181. DECLARE_CLASS_SIMPLE( CScrollableList, CExScrollingEditablePanel );
  182. public:
  183. CScrollableList( Panel* pParent, const char* pszName )
  184. : CExScrollingEditablePanel( pParent, pszName )
  185. {}
  186. virtual ~CScrollableList();
  187. virtual void PerformLayout() OVERRIDE;
  188. void AddPanel( Panel* pPanel, int nGap );
  189. void ClearAutoLayoutPanels();
  190. private:
  191. struct LayoutInfo_t
  192. {
  193. Panel* m_pPanel;
  194. int m_nGap;
  195. };
  196. CUtlVector< LayoutInfo_t > m_vecAutoLayoutPanels;
  197. };
  198. //-----------------------------------------------------------------------------
  199. // A checkbox where keyvalue data can be stored and retrieved (typically in OnCheckButtonChecked)
  200. // so that you don't need a pointer to the checkbox in order to determine WHICH
  201. // checkbox got checked.
  202. //-----------------------------------------------------------------------------
  203. class CExCheckButton : public vgui::CheckButton
  204. {
  205. DECLARE_CLASS_SIMPLE( CExCheckButton, vgui::CheckButton );
  206. public:
  207. CExCheckButton( Panel* pParent, const char* pszName )
  208. : BaseClass( pParent, pszName, NULL )
  209. , m_pKVData( NULL )
  210. {}
  211. virtual ~CExCheckButton()
  212. {
  213. if ( m_pKVData )
  214. m_pKVData->deleteThis();
  215. }
  216. void SetData( KeyValues* pKVData )
  217. {
  218. if ( m_pKVData )
  219. {
  220. m_pKVData->deleteThis();
  221. m_pKVData = NULL;
  222. }
  223. m_pKVData = pKVData;
  224. }
  225. KeyValues* GetData() const
  226. {
  227. return m_pKVData;
  228. }
  229. private:
  230. KeyValues *m_pKVData;
  231. };
  232. class CExpandablePanel : public vgui::EditablePanel
  233. {
  234. DECLARE_CLASS_SIMPLE( CExpandablePanel, vgui::EditablePanel );
  235. public:
  236. CExpandablePanel( Panel* pParent, const char* pszName );
  237. virtual void OnCommand( const char *command ) OVERRIDE;
  238. virtual void OnThink() OVERRIDE;
  239. virtual void OnToggleCollapse( bool bIsExpanded ) {}
  240. void SetCollapsed( bool bCollapsed );
  241. void ToggleCollapse();
  242. bool BIsExpanded() const { return m_bExpanded; }
  243. void SetExpandedHeight( int nNewHeight );
  244. float GetPercentAnimated() const;
  245. protected:
  246. CPanelAnimationVarAliasType( float, m_flResizeTime, "resize_time", "0.4", "float" );
  247. CPanelAnimationVarAliasType( int, m_nCollapsedHeight, "collapsed_height", "17", "proportional_int" );
  248. CPanelAnimationVarAliasType( int, m_nExpandedHeight, "expanded_height", "50", "proportional_int" );
  249. private:
  250. bool m_bExpanded;
  251. float m_flAnimEndTime;
  252. };
  253. #endif // TF_CONTROLS_H