Counter Strike : Global Offensive Source Code
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.3 KiB

  1. //========= Copyright � 1996-2005, 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. virtual void PerformLayout();
  32. // sets the name of this dialog so it can be saved in the user config area
  33. // use dialogID to differentiate multiple instances of the same dialog
  34. virtual void LoadUserConfig(const char *configName, int dialogID = 0);
  35. virtual void SaveUserConfig();
  36. // combines both of the above, LoadControlSettings & LoadUserConfig
  37. virtual void LoadControlSettingsAndUserConfig(const char *dialogResourceName, int dialogID = 0);
  38. // Override to change how build mode is activated
  39. virtual void ActivateBuildMode();
  40. // Return the buildgroup that this panel is part of.
  41. virtual BuildGroup *GetBuildGroup();
  42. // Virtual factory for control creation
  43. // controlName is a string which is the same as the class name
  44. virtual Panel *CreateControlByName(const char *controlName);
  45. // Shortcut function to set data in child controls
  46. virtual void SetControlString(const char *controlName, const char *string);
  47. // Shortcut function to set data in child controls
  48. virtual void SetControlString(const char *controlName, const wchar_t *string);
  49. // Shortcut function to set data in child controls
  50. virtual void SetControlInt(const char *controlName, int state);
  51. // Shortcut function to get data in child controls
  52. virtual int GetControlInt(const char *controlName, int defaultState);
  53. // Shortcut function to get data in child controls
  54. // Returns a maximum of 511 characters in the string
  55. virtual const char *GetControlString(const char *controlName, const char *defaultString = "");
  56. // as above, but copies the result into the specified buffer instead of a static buffer
  57. virtual void GetControlString(const char *controlName, char *buf, int bufSize, const char *defaultString = "");
  58. // sets the enabled state of a control
  59. virtual void SetControlEnabled(const char *controlName, bool enabled);
  60. virtual void SetControlVisible(const char *controlName, bool visible);
  61. // localization variables (used in constructing UI strings)
  62. // after the variable is set, causes all the necessary sub-panels to update
  63. virtual void SetDialogVariable(const char *varName, const char *value);
  64. virtual void SetDialogVariable(const char *varName, const wchar_t *value);
  65. virtual void SetDialogVariable(const char *varName, int value);
  66. virtual void SetDialogVariable(const char *varName, float value);
  67. // Focus handling
  68. // Delegate focus to a sub panel
  69. virtual void RequestFocus(int direction = 0);
  70. virtual bool RequestFocusNext(VPANEL panel);
  71. virtual bool RequestFocusPrev(VPANEL panel);
  72. // Pass the focus down onto the last used panel
  73. virtual void OnSetFocus();
  74. // Update focus info for navigation
  75. virtual void OnRequestFocus(VPANEL subFocus, VPANEL defaultPanel);
  76. // Get the panel that currently has keyfocus
  77. virtual VPANEL GetCurrentKeyFocus();
  78. // Get the panel with the specified hotkey
  79. virtual Panel *HasHotkey(wchar_t key);
  80. virtual void OnKeyCodeTyped( KeyCode code );
  81. // Handle information requests
  82. virtual bool RequestInfo(KeyValues *data);
  83. /* INFO HANDLING
  84. "BuildDialog"
  85. input:
  86. "BuildGroupPtr" - pointer to the panel/dialog to edit
  87. returns:
  88. "PanelPtr" - pointer to a new BuildModeDialog()
  89. "ControlFactory"
  90. input:
  91. "ControlName" - class name of the control to create
  92. returns:
  93. "PanelPtr" - pointer to the newly created panel, or NULL if no such class exists
  94. */
  95. // registers a file in the list of control settings, so the vgui dialog can choose between them to edit
  96. virtual void RegisterControlSettingsFile(const char *dialogResourceName, const char *pathID = NULL);
  97. // localization variables - only use this if you need to iterate the variables, use the SetLoc*() to set them
  98. KeyValues *GetDialogVariables();
  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. };
  130. } // namespace vgui
  131. #endif // EDITABLEPANEL_H