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.

429 lines
16 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef ECON_CONTROLS_H
  8. #define ECON_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 <vgui_controls/ImagePanel.h>
  22. #include "utlvector.h"
  23. #include "vgui_controls/PHandle.h"
  24. #include <vgui_controls/Tooltip.h>
  25. #include "GameEventListener.h"
  26. //-----------------------------------------------------------------------------
  27. // Purpose: Changes the visibility of the child panel if it is different.
  28. // Returns true if the child exists, false otherwise.
  29. //-----------------------------------------------------------------------------
  30. bool SetChildPanelVisible( vgui::Panel *pParent, const char *pChildName, bool bVisible, bool bSearchForChildRecursively = false );
  31. //-----------------------------------------------------------------------------
  32. // Purpose: Changes the enable state of the child panel if it is different.
  33. // Returns true if the child exists, false otherwise.
  34. //-----------------------------------------------------------------------------
  35. bool SetChildPanelEnabled( vgui::Panel *pParent, const char *pChildName, bool bEnabled, bool bSearchForChildRecursively = false );
  36. //-----------------------------------------------------------------------------
  37. // Purpose: Changes the selected state of the child button if it is different.
  38. // Returns true if the child exists, false otherwise.
  39. //-----------------------------------------------------------------------------
  40. bool SetChildButtonSelected( vgui::Panel *pParent, const char *pChildName, bool bSelected, bool bSearchForChildRecursively = false );
  41. //-----------------------------------------------------------------------------
  42. // Purpose: Returns true if the child button exists and is selected, false otherwise.
  43. //-----------------------------------------------------------------------------
  44. bool IsChildButtonSelected( vgui::Panel *pParent, const char *pChildName, bool bSearchForChildRecursively = false );
  45. //-----------------------------------------------------------------------------
  46. // Purpose: Adds the child panel as an action signal target. Returns true if the child exists, false otherwise.
  47. //-----------------------------------------------------------------------------
  48. bool AddChildActionSignalTarget( vgui::Panel *pParent, const char *pChildName, vgui::Panel *messageTarget, bool bSearchForChildRecursively = false );
  49. //-----------------------------------------------------------------------------
  50. // Purpose: Modify the color of a label/button's text - if it starts with "X "
  51. // or "x ", set the X to red.
  52. //-----------------------------------------------------------------------------
  53. bool SetXToRed( vgui::Label *pPanel );
  54. //-----------------------------------------------------------------------------
  55. // Purpose: Simple panel tooltip. Just calls setvisible on the other panel.
  56. // Ignores all other input.
  57. //-----------------------------------------------------------------------------
  58. class CSimplePanelToolTip : public vgui::BaseTooltip
  59. {
  60. DECLARE_CLASS_SIMPLE( CSimplePanelToolTip, vgui::BaseTooltip );
  61. public:
  62. CSimplePanelToolTip(vgui::Panel *parent, const char *text = NULL) : vgui::BaseTooltip( parent, text )
  63. {
  64. m_pControlledPanel = NULL;
  65. }
  66. void SetText(const char *text) { return; }
  67. const char *GetText() { return NULL; }
  68. virtual void ShowTooltip( vgui::Panel *currentPanel ) { if ( m_pControlledPanel ) m_pControlledPanel->SetVisible( true ); }
  69. virtual void HideTooltip() { if ( m_pControlledPanel ) m_pControlledPanel->SetVisible( false ); }
  70. void SetControlledPanel( vgui::EditablePanel *pPanel ) { m_pControlledPanel = pPanel; }
  71. protected:
  72. vgui::Panel *m_pControlledPanel;
  73. };
  74. //-----------------------------------------------------------------------------
  75. // Purpose: Expanded Button class that allows font & color overriding in .res files
  76. //-----------------------------------------------------------------------------
  77. class CExButton : public vgui::Button
  78. {
  79. public:
  80. DECLARE_CLASS_SIMPLE( CExButton, vgui::Button );
  81. CExButton( vgui::Panel *parent, const char *name, const char *text, vgui::Panel *pActionSignalTarget = NULL, const char *cmd = NULL );
  82. CExButton( vgui::Panel *parent, const char *name, const wchar_t *wszText, vgui::Panel *pActionSignalTarget = NULL, const char *cmd = NULL );
  83. virtual void ApplySettings( KeyValues *inResourceData );
  84. void SetFontStr( const char *pFont );
  85. void SetColorStr( const char *pColor );
  86. virtual vgui::IBorder *GetBorder(bool depressed, bool armed, bool selected, bool keyfocus);
  87. virtual void OnMouseFocusTicked() OVERRIDE;
  88. virtual void OnCursorEntered() OVERRIDE;
  89. virtual void OnCursorExited() OVERRIDE;
  90. void PassMouseTicksTo( vgui::Panel *pPanel, bool bCursorEnterExitEvent = false )
  91. {
  92. m_hMouseTickTarget.Set( pPanel ? pPanel->GetVPanel() : NULL );
  93. m_bbCursorEnterExitEvent = bCursorEnterExitEvent;
  94. }
  95. private:
  96. char m_szFont[64];
  97. char m_szColor[64];
  98. vgui::IBorder *m_pArmedBorder;
  99. vgui::IBorder *m_pDefaultBorderOverride;
  100. vgui::IBorder *m_pSelectedBorder;
  101. vgui::IBorder *m_pDisabledBorder;
  102. vgui::VPanelHandle m_hMouseTickTarget;
  103. bool m_bbCursorEnterExitEvent;
  104. };
  105. //-----------------------------------------------------------------------------
  106. // Purpose: Expanded image button, that handles images per button state, and color control in the .res file
  107. //-----------------------------------------------------------------------------
  108. class CExImageButton : public CExButton
  109. {
  110. public:
  111. DECLARE_CLASS_SIMPLE( CExImageButton, CExButton );
  112. CExImageButton( vgui::Panel *parent, const char *name, const char *text = "", vgui::Panel *pActionSignalTarget = NULL, const char *cmd = NULL );
  113. CExImageButton( vgui::Panel *parent, const char *name, const wchar_t *wszText = L"", vgui::Panel *pActionSignalTarget = NULL, const char *cmd = NULL );
  114. ~CExImageButton( void );
  115. virtual void ApplySettings( KeyValues *inResourceData );
  116. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  117. virtual void SetArmed(bool state);
  118. virtual void SetEnabled(bool state);
  119. virtual void SetSelected(bool state);
  120. void SetSubImage( const char *pszImage );
  121. void SetImageDefault( const char *pszImageDefault );
  122. void SetImageArmed( const char *pszImageArmed );
  123. void SetImageSelected( const char *pszImageSelected );
  124. Color GetImageColor( void );
  125. vgui::ImagePanel *GetImage( void ) { return m_pEmbeddedImagePanel; }
  126. private:
  127. // Embedded image panels
  128. vgui::ImagePanel *m_pEmbeddedImagePanel;
  129. Color m_ImageDrawColor;
  130. Color m_ImageArmedColor;
  131. Color m_ImageDisabledColor;
  132. Color m_ImageSelectedColor;
  133. Color m_ImageDepressedColor;
  134. char m_szImageDefault[MAX_PATH];
  135. char m_szImageArmed[MAX_PATH];
  136. char m_szImageSelected[MAX_PATH];
  137. };
  138. //-----------------------------------------------------------------------------
  139. // Purpose: Expanded Label class that allows color control in .res files
  140. //-----------------------------------------------------------------------------
  141. class CExLabel : public vgui::Label
  142. {
  143. public:
  144. DECLARE_CLASS_SIMPLE( CExLabel, vgui::Label );
  145. CExLabel( vgui::Panel *parent, const char *panelName, const char *text );
  146. CExLabel( vgui::Panel *parent, const char *panelName, const wchar_t *wszText );
  147. virtual void ApplySettings( KeyValues *inResourceData );
  148. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  149. void SetColorStr( const char *pColor );
  150. void SetColorStr( Color cColor );
  151. private:
  152. char m_szColor[64];
  153. };
  154. //-----------------------------------------------------------------------------
  155. // Purpose: Expanded Richtext control that allows customization of scrollbar display, font, and color .res controls.
  156. //-----------------------------------------------------------------------------
  157. class CExRichText : public vgui::RichText
  158. {
  159. public:
  160. DECLARE_CLASS_SIMPLE( CExRichText, vgui::RichText );
  161. CExRichText( vgui::Panel *parent, const char *panelName );
  162. virtual void ApplySettings( KeyValues *inResourceData );
  163. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  164. virtual void PerformLayout();
  165. virtual void SetText( const char *text );
  166. virtual void SetText( const wchar_t *text );
  167. virtual void OnTick( void );
  168. void SetScrollBarImagesVisible( bool visible );
  169. void SetFontStr( const char *pFont );
  170. void SetColorStr( const char *pColor );
  171. void SetCustomImage( vgui::Panel *pImage, const char *pszImage, char *pszStorage );
  172. void CreateImagePanels( void );
  173. protected:
  174. char m_szFont[64];
  175. char m_szColor[64];
  176. char m_szImageUpArrow[MAX_PATH];
  177. char m_szImageDownArrow[MAX_PATH];
  178. char m_szImageLine[MAX_PATH];
  179. char m_szImageBox[MAX_PATH];
  180. bool m_bUseImageBorders;
  181. CExImageButton *m_pUpArrow;
  182. vgui::Panel *m_pLine;
  183. CExImageButton *m_pDownArrow;
  184. vgui::Panel *m_pBox;
  185. };
  186. //-----------------------------------------------------------------------------
  187. // Purpose: Rich text control that knows how to fill itself with information
  188. // that describes a specific item definition.
  189. //-----------------------------------------------------------------------------
  190. class CRichTextWithScrollbarBorders : public CExRichText
  191. {
  192. public:
  193. DECLARE_CLASS_SIMPLE( CRichTextWithScrollbarBorders, CExRichText );
  194. CRichTextWithScrollbarBorders( vgui::Panel *parent, const char *panelName ) : BaseClass( parent, panelName )
  195. {
  196. m_bUseImageBorders = true;
  197. }
  198. };
  199. //-----------------------------------------------------------------------------
  200. // Purpose: Rich text control that knows how to fill itself with information
  201. // that describes a specific item definition.
  202. //-----------------------------------------------------------------------------
  203. class CEconItemDetailsRichText : public CRichTextWithScrollbarBorders
  204. {
  205. public:
  206. DECLARE_CLASS_SIMPLE( CEconItemDetailsRichText, CRichTextWithScrollbarBorders );
  207. CEconItemDetailsRichText( vgui::Panel *parent, const char *panelName );
  208. virtual void ApplySettings( KeyValues *inResourceData );
  209. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  210. void UpdateDetailsForItem( const CEconItemDefinition *pDef );
  211. void AllowItemSetLinks( bool bAllow ) { m_bAllowItemSetLinks = bAllow; }
  212. void SetLimitedItem( bool bLimited ) { m_bLimitedItem = bLimited; }
  213. private:
  214. void InsertItemLink( const wchar_t *pwzItemName, int nItemIndex, Color *pColorOverride = NULL );
  215. void AddDataText( const char *pszText, bool bAddPostLines = true, const wchar_t *wpszArg = NULL, const wchar_t *wpszArg2 = NULL, const int *pItemDefIndex = NULL );
  216. void DataText_AppendStoreFlags( const CEconItemDefinition *pDef );
  217. void DataText_AppendItemData( const CEconItemDefinition *pDef );
  218. void DataText_AppendBundleData( const CEconItemDefinition *pDef );
  219. void DataText_AppendUsageData( const CEconItemDefinition *pBaseDef );
  220. void DataText_AppendAttributeData( const CEconItemDefinition *pDef );
  221. void DataText_AppendSetData( const CEconItemDefinition *pDef );
  222. void DataText_AppendToolUsage( const CEconItemDefinition *pDef );
  223. void UpdateToolList( void );
  224. private:
  225. Color m_colTextHighlight;
  226. Color m_colItemSet;
  227. Color m_colLink;
  228. bool m_bAllowItemSetLinks;
  229. vgui::HFont m_hLinkFont;
  230. CUtlVector<item_definition_index_t> m_ToolList;
  231. bool m_bLimitedItem;
  232. };
  233. #define EXC_SIDE_TOP 0
  234. #define EXC_SIDE_RIGHT 1
  235. #define EXC_SIDE_BOTTOM 2
  236. #define EXC_SIDE_LEFT 3
  237. //-----------------------------------------------------------------------------
  238. // Purpose: A small callout arrow that's created by a CExplanationPopup to
  239. // connect to the point that the explanation is referring to.
  240. //-----------------------------------------------------------------------------
  241. class CExplanationPopupCalloutArrow : public vgui::Panel
  242. {
  243. public:
  244. CExplanationPopupCalloutArrow( Panel *parent ) : vgui::Panel( parent, "calloutarrow" )
  245. {
  246. SetPaintBackgroundEnabled( false );
  247. SetMouseInputEnabled( false );
  248. PrecacheMaterial( "vgui/callout_tail" );
  249. }
  250. void SetArrowPoints( int iAx, int iAy, int iBx, int iBy, int iCx, int iCy )
  251. {
  252. m_iArrowA[0] = iAx;
  253. m_iArrowA[1] = iAy;
  254. m_iArrowB[0] = iBx;
  255. m_iArrowB[1] = iBy;
  256. m_iArrowC[0] = iCx;
  257. m_iArrowC[1] = iCy;
  258. }
  259. virtual void Paint( void );
  260. private:
  261. int m_iArrowA[2];
  262. int m_iArrowB[2];
  263. int m_iArrowC[2];
  264. };
  265. //-----------------------------------------------------------------------------
  266. // Purpose: A bubble that contains a blob of text and an arrow to a specific place onscreen
  267. //-----------------------------------------------------------------------------
  268. class CExplanationPopup : public vgui::EditablePanel, public CGameEventListener
  269. {
  270. DECLARE_CLASS_SIMPLE( CExplanationPopup, vgui::EditablePanel );
  271. public:
  272. CExplanationPopup(Panel *parent, const char *panelName);
  273. ~CExplanationPopup( void );
  274. void SetCalloutInParentsX( int nXPos ) { m_iCalloutInParentsX = nXPos; }
  275. void SetCalloutInParentsY( int nYPos ) { m_iCalloutInParentsY = nYPos; }
  276. void Popup( int iPosition = 0, int iTotalPanels = 0 );
  277. void Hide( int iExplanationDelta = 0 );
  278. const char *GetNextExplanation( void ) { return m_szNextExplanation; }
  279. void SetPrevExplanation( const char *pszPrev );
  280. virtual void ApplySettings( KeyValues *inResourceData );
  281. virtual void OnCommand( const char *command );
  282. virtual void OnTick( void );
  283. virtual void OnKeyCodeTyped( vgui::KeyCode code );
  284. virtual void OnKeyCodePressed( vgui::KeyCode code );
  285. void PositionCallout( float flElapsed );
  286. virtual void FireGameEvent( IGameEvent *event );
  287. private:
  288. int m_iCalloutSide;
  289. float m_flStartTime;
  290. float m_flEndTime;
  291. char m_szNextExplanation[128];
  292. char m_szPrevExplanation[128];
  293. CExplanationPopupCalloutArrow *m_pCallout;
  294. int m_iPositionInChain;
  295. int m_iTotalInChain;
  296. bool m_bFinishedPopup;
  297. CPanelAnimationVar( bool, m_bForceClose, "force_close", "0" );
  298. CPanelAnimationVarAliasType( int, m_iCalloutInParentsX, "callout_inparents_x", "0", "proportional_xpos" );
  299. CPanelAnimationVarAliasType( int, m_iCalloutInParentsY, "callout_inparents_y", "0", "proportional_ypos" );
  300. CPanelAnimationVarAliasType( int, m_iStartX, "start_x", "0", "proportional_xpos" );
  301. CPanelAnimationVarAliasType( int, m_iStartY, "start_y", "0", "proportional_ypos" );
  302. CPanelAnimationVarAliasType( int, m_iStartW, "start_wide", "0", "proportional_int" );
  303. CPanelAnimationVarAliasType( int, m_iStartH, "start_tall", "0", "proportional_int" );
  304. CPanelAnimationVarAliasType( int, m_iEndX, "end_x", "0", "proportional_xpos" );
  305. CPanelAnimationVarAliasType( int, m_iEndY, "end_y", "0", "proportional_ypos" );
  306. CPanelAnimationVarAliasType( int, m_iEndW, "end_wide", "0", "proportional_int" );
  307. CPanelAnimationVarAliasType( int, m_iEndH, "end_tall", "0", "proportional_int" );
  308. };
  309. //-----------------------------------------------------------------------------
  310. // Purpose: A stack to keep track of the modal dialogs that have been popped up.
  311. //-----------------------------------------------------------------------------
  312. class CPanelModalStack
  313. {
  314. public:
  315. void PushModal( vgui::Panel *pDialog );
  316. void PopModal( vgui::Panel *pDialog );
  317. void Update( void );
  318. vgui::VPanelHandle Top();
  319. bool IsEmpty() const;
  320. private:
  321. void PopModal( int iIdx );
  322. private:
  323. CUtlVector<vgui::VPanelHandle> m_pDialogs;
  324. };
  325. CPanelModalStack *TFModalStack( void );
  326. //-----------------------------------------------------------------------------
  327. // Purpose: Generic waiting dialog
  328. //-----------------------------------------------------------------------------
  329. class CGenericWaitingDialog : public vgui::EditablePanel
  330. {
  331. DECLARE_CLASS_SIMPLE( CGenericWaitingDialog, vgui::EditablePanel );
  332. public:
  333. CGenericWaitingDialog( vgui::Panel *pParent );
  334. void Close();
  335. void ShowStatusUpdate( bool bAnimateEllipses, bool bAllowClose, float flMaxWaitTime = 0 );
  336. protected:
  337. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  338. virtual void OnCommand( const char *command );
  339. virtual void OnTick( void );
  340. virtual void OnTimeout();
  341. virtual void OnUserClose();
  342. virtual const char *GetResFile() const { return "resource/UI/econ/GenericWaitingDialog.res"; }
  343. virtual const char *GetResFilePathId() const { return "MOD"; }
  344. bool m_bAnimateEllipses;
  345. int m_iNumEllipses;
  346. CountdownTimer m_timer;
  347. };
  348. void ShowWaitingDialog( CGenericWaitingDialog *pWaitingDialog, const char* pUpdateText, bool bAnimate, bool bShowCancel, float flMaxDuration );
  349. void CloseWaitingDialog();
  350. #endif // ECON_CONTROLS_H