editor_feature_profile.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /**************************************************************************/
  2. /* editor_feature_profile.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef EDITOR_FEATURE_PROFILE_H
  31. #define EDITOR_FEATURE_PROFILE_H
  32. #include "core/io/file_access.h"
  33. #include "core/object/ref_counted.h"
  34. #include "editor/editor_help.h"
  35. #include "scene/gui/dialogs.h"
  36. #include "scene/gui/option_button.h"
  37. #include "scene/gui/separator.h"
  38. #include "scene/gui/split_container.h"
  39. #include "scene/gui/tree.h"
  40. class EditorFileDialog;
  41. class EditorFeatureProfile : public RefCounted {
  42. GDCLASS(EditorFeatureProfile, RefCounted);
  43. public:
  44. enum Feature {
  45. FEATURE_3D,
  46. FEATURE_SCRIPT,
  47. FEATURE_ASSET_LIB,
  48. FEATURE_SCENE_TREE,
  49. FEATURE_NODE_DOCK,
  50. FEATURE_FILESYSTEM_DOCK,
  51. FEATURE_IMPORT_DOCK,
  52. FEATURE_HISTORY_DOCK,
  53. FEATURE_GAME,
  54. FEATURE_MAX
  55. };
  56. private:
  57. HashSet<StringName> disabled_classes;
  58. HashSet<StringName> disabled_editors;
  59. HashMap<StringName, HashSet<StringName>> disabled_properties;
  60. HashSet<StringName> collapsed_classes;
  61. bool features_disabled[FEATURE_MAX];
  62. static const char *feature_names[FEATURE_MAX];
  63. static const char *feature_descriptions[FEATURE_MAX];
  64. static const char *feature_identifiers[FEATURE_MAX];
  65. String _get_feature_name(Feature p_feature) { return get_feature_name(p_feature); }
  66. protected:
  67. static void _bind_methods();
  68. public:
  69. void set_disable_class(const StringName &p_class, bool p_disabled);
  70. bool is_class_disabled(const StringName &p_class) const;
  71. void set_disable_class_editor(const StringName &p_class, bool p_disabled);
  72. bool is_class_editor_disabled(const StringName &p_class) const;
  73. void set_disable_class_property(const StringName &p_class, const StringName &p_property, bool p_disabled);
  74. bool is_class_property_disabled(const StringName &p_class, const StringName &p_property) const;
  75. bool has_class_properties_disabled(const StringName &p_class) const;
  76. void set_item_collapsed(const StringName &p_class, bool p_collapsed);
  77. bool is_item_collapsed(const StringName &p_class) const;
  78. void set_disable_feature(Feature p_feature, bool p_disable);
  79. bool is_feature_disabled(Feature p_feature) const;
  80. Error save_to_file(const String &p_path);
  81. Error load_from_file(const String &p_path);
  82. static String get_feature_name(Feature p_feature);
  83. static String get_feature_description(Feature p_feature);
  84. EditorFeatureProfile();
  85. };
  86. VARIANT_ENUM_CAST(EditorFeatureProfile::Feature)
  87. class EditorFeatureProfileManager : public AcceptDialog {
  88. GDCLASS(EditorFeatureProfileManager, AcceptDialog);
  89. enum Action {
  90. PROFILE_CLEAR,
  91. PROFILE_SET,
  92. PROFILE_IMPORT,
  93. PROFILE_EXPORT,
  94. PROFILE_NEW,
  95. PROFILE_ERASE,
  96. PROFILE_MAX
  97. };
  98. enum ClassOptions {
  99. CLASS_OPTION_DISABLE_EDITOR
  100. };
  101. ConfirmationDialog *erase_profile_dialog = nullptr;
  102. ConfirmationDialog *new_profile_dialog = nullptr;
  103. LineEdit *new_profile_name = nullptr;
  104. LineEdit *current_profile_name = nullptr;
  105. OptionButton *profile_list = nullptr;
  106. Button *profile_actions[PROFILE_MAX];
  107. HSplitContainer *h_split = nullptr;
  108. VBoxContainer *class_list_vbc = nullptr;
  109. Tree *class_list = nullptr;
  110. VBoxContainer *property_list_vbc = nullptr;
  111. Tree *property_list = nullptr;
  112. EditorHelpBit *description_bit = nullptr;
  113. Label *no_profile_selected_help = nullptr;
  114. EditorFileDialog *import_profiles = nullptr;
  115. EditorFileDialog *export_profile = nullptr;
  116. void _profile_action(int p_action);
  117. void _profile_selected(int p_what);
  118. void _hide_requested();
  119. String current_profile;
  120. void _update_profile_list(const String &p_select_profile = String());
  121. void _update_selected_profile();
  122. void _update_profile_tree_from(TreeItem *p_edited);
  123. void _fill_classes_from(TreeItem *p_parent, const String &p_class, const String &p_selected, int p_class_insert_index = -1);
  124. Ref<EditorFeatureProfile> current;
  125. Ref<EditorFeatureProfile> edited;
  126. void _erase_selected_profile();
  127. void _create_new_profile();
  128. String _get_selected_profile();
  129. void _import_profiles(const Vector<String> &p_paths);
  130. void _export_profile(const String &p_path);
  131. bool updating_features = false;
  132. void _class_list_item_selected();
  133. void _class_list_item_edited();
  134. void _class_list_item_collapsed(Object *p_item);
  135. void _property_item_edited();
  136. void _save_and_update();
  137. Timer *update_timer = nullptr;
  138. void _emit_current_profile_changed();
  139. static EditorFeatureProfileManager *singleton;
  140. protected:
  141. static void _bind_methods();
  142. void _notification(int p_what);
  143. public:
  144. Ref<EditorFeatureProfile> get_current_profile();
  145. String get_current_profile_name() const;
  146. void set_current_profile(const String &p_profile_name, bool p_validate_profile);
  147. void notify_changed();
  148. static EditorFeatureProfileManager *get_singleton() { return singleton; }
  149. EditorFeatureProfileManager();
  150. };
  151. #endif // EDITOR_FEATURE_PROFILE_H