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.

164 lines
6.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef EDITABLEPANEL_H
  8. #define EDITABLEPANEL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <vgui_controls/Panel.h>
  13. #include <vgui_controls/FocusNavGroup.h>
  14. namespace vgui
  15. {
  16. //-----------------------------------------------------------------------------
  17. // Purpose: Panel that supports editing via the build dialog
  18. //-----------------------------------------------------------------------------
  19. class EditablePanel : public Panel
  20. {
  21. DECLARE_CLASS_SIMPLE( EditablePanel, Panel );
  22. public:
  23. EditablePanel(Panel *parent, const char *panelName);
  24. EditablePanel(Panel *parent, const char *panelName, HScheme hScheme);
  25. virtual ~EditablePanel();
  26. // Load the control settings - should be done after all the children are added
  27. // If you pass in pPreloadedKeyValues, it won't actually load the file. That way, you can cache
  28. // the keyvalues outside of here if you want to prevent file accesses in the middle of the game.
  29. virtual void LoadControlSettings(const char *dialogResourceName, const char *pathID = NULL, KeyValues *pPreloadedKeyValues = NULL, KeyValues *pConditions = NULL);
  30. virtual void ApplySettings(KeyValues *inResourceData);
  31. // sets the name of this dialog so it can be saved in the user config area
  32. // use dialogID to differentiate multiple instances of the same dialog
  33. virtual void LoadUserConfig(const char *configName, int dialogID = 0);
  34. virtual void SaveUserConfig();
  35. // combines both of the above, LoadControlSettings & LoadUserConfig
  36. virtual void LoadControlSettingsAndUserConfig(const char *dialogResourceName, int dialogID = 0);
  37. // Override to change how build mode is activated
  38. virtual void ActivateBuildMode();
  39. // Return the buildgroup that this panel is part of.
  40. virtual BuildGroup *GetBuildGroup();
  41. // Virtual factory for control creation
  42. // controlName is a string which is the same as the class name
  43. virtual Panel *CreateControlByName(const char *controlName);
  44. // Shortcut function to set data in child controls
  45. virtual void SetControlString(const char *controlName, const char *string);
  46. // Shortcut function to set data in child controls
  47. virtual void SetControlString(const char *controlName, const wchar_t *string);
  48. // Shortcut function to set data in child controls
  49. virtual void SetControlInt(const char *controlName, int state);
  50. // Shortcut function to get data in child controls
  51. virtual int GetControlInt(const char *controlName, int defaultState);
  52. // Shortcut function to get data in child controls
  53. // Returns a maximum of 511 characters in the string
  54. virtual const char *GetControlString(const char *controlName, const char *defaultString = "");
  55. // as above, but copies the result into the specified buffer instead of a static buffer
  56. virtual void GetControlString(const char *controlName, char *buf, int bufSize, const char *defaultString = "");
  57. // sets the enabled state of a control
  58. virtual void SetControlEnabled(const char *controlName, bool enabled);
  59. virtual void SetControlVisible(const char *controlName, bool visible, bool bRecurseDown = false );
  60. // localization variables (used in constructing UI strings)
  61. // after the variable is set, causes all the necessary sub-panels to update
  62. virtual void SetDialogVariable(const char *varName, const char *value);
  63. virtual void SetDialogVariable(const char *varName, const wchar_t *value);
  64. virtual void SetDialogVariable(const char *varName, int value);
  65. virtual void SetDialogVariable(const char *varName, float value);
  66. // Focus handling
  67. // Delegate focus to a sub panel
  68. virtual void RequestFocus(int direction = 0);
  69. virtual bool RequestFocusNext(VPANEL panel);
  70. virtual bool RequestFocusPrev(VPANEL panel);
  71. // Pass the focus down onto the last used panel
  72. virtual void OnSetFocus();
  73. // Update focus info for navigation
  74. virtual void OnRequestFocus(VPANEL subFocus, VPANEL defaultPanel);
  75. // Get the panel that currently has keyfocus
  76. virtual VPANEL GetCurrentKeyFocus();
  77. // Get the panel with the specified hotkey
  78. virtual Panel *HasHotkey(wchar_t key);
  79. virtual void OnKeyCodePressed( KeyCode code );
  80. // Handle information requests
  81. virtual bool RequestInfo(KeyValues *data);
  82. /* INFO HANDLING
  83. "BuildDialog"
  84. input:
  85. "BuildGroupPtr" - pointer to the panel/dialog to edit
  86. returns:
  87. "PanelPtr" - pointer to a new BuildModeDialog()
  88. "ControlFactory"
  89. input:
  90. "ControlName" - class name of the control to create
  91. returns:
  92. "PanelPtr" - pointer to the newly created panel, or NULL if no such class exists
  93. */
  94. // registers a file in the list of control settings, so the vgui dialog can choose between them to edit
  95. virtual void RegisterControlSettingsFile(const char *dialogResourceName, const char *pathID = NULL);
  96. // localization variables - only use this if you need to iterate the variables, use the SetLoc*() to set them
  97. KeyValues *GetDialogVariables();
  98. bool ShouldSkipAutoResize() const { return m_bShouldSkipAutoResize; }
  99. protected:
  100. virtual void PaintBackground();
  101. // nav group access
  102. virtual FocusNavGroup &GetFocusNavGroup();
  103. // called when default button has been set
  104. MESSAGE_FUNC_HANDLE( OnDefaultButtonSet, "DefaultButtonSet", button );
  105. // called when the current default button has been set
  106. MESSAGE_FUNC_HANDLE( OnCurrentDefaultButtonSet, "CurrentDefaultButtonSet", button );
  107. MESSAGE_FUNC( OnFindDefaultButton, "FindDefaultButton" );
  108. // overrides
  109. virtual void OnChildAdded(VPANEL child);
  110. virtual void OnSizeChanged(int wide, int tall);
  111. virtual void OnClose();
  112. // user configuration settings
  113. // this is used for any control details the user wants saved between sessions
  114. // eg. dialog positions, last directory opened, list column width
  115. virtual void ApplyUserConfigSettings(KeyValues *userConfig);
  116. // returns user config settings for this control
  117. virtual void GetUserConfigSettings(KeyValues *userConfig);
  118. // optimization for text rendering, returns true if text should be rendered immediately after Paint()
  119. // disabled for now
  120. // virtual bool ShouldFlushText();
  121. private:
  122. void ForceSubPanelsToUpdateWithNewDialogVariables();
  123. BuildGroup *_buildGroup;
  124. FocusNavGroup m_NavGroup;
  125. KeyValues *m_pDialogVariables;
  126. // the wide and tall to which all controls are locked - used for autolayout deltas
  127. char *m_pszConfigName;
  128. int m_iConfigID;
  129. bool m_bShouldSkipAutoResize;
  130. };
  131. } // namespace vgui
  132. #endif // EDITABLEPANEL_H