editor_feature_profile.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*************************************************************************/
  2. /* editor_feature_profile.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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/object/reference.h"
  33. #include "core/os/file_access.h"
  34. #include "editor/editor_file_dialog.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 EditorFeatureProfile : public Reference {
  41. GDCLASS(EditorFeatureProfile, Reference);
  42. public:
  43. enum Feature {
  44. FEATURE_3D,
  45. FEATURE_SCRIPT,
  46. FEATURE_ASSET_LIB,
  47. FEATURE_SCENE_TREE,
  48. FEATURE_NODE_DOCK,
  49. FEATURE_FILESYSTEM_DOCK,
  50. FEATURE_IMPORT_DOCK,
  51. FEATURE_MAX
  52. };
  53. private:
  54. Set<StringName> disabled_classes;
  55. Set<StringName> disabled_editors;
  56. Map<StringName, Set<StringName>> disabled_properties;
  57. bool features_disabled[FEATURE_MAX];
  58. static const char *feature_names[FEATURE_MAX];
  59. static const char *feature_identifiers[FEATURE_MAX];
  60. String _get_feature_name(Feature p_feature) { return get_feature_name(p_feature); }
  61. protected:
  62. static void _bind_methods();
  63. public:
  64. void set_disable_class(const StringName &p_class, bool p_disabled);
  65. bool is_class_disabled(const StringName &p_class) const;
  66. void set_disable_class_editor(const StringName &p_class, bool p_disabled);
  67. bool is_class_editor_disabled(const StringName &p_class) const;
  68. void set_disable_class_property(const StringName &p_class, const StringName &p_property, bool p_disabled);
  69. bool is_class_property_disabled(const StringName &p_class, const StringName &p_property) const;
  70. bool has_class_properties_disabled(const StringName &p_class) const;
  71. void set_disable_feature(Feature p_feature, bool p_disable);
  72. bool is_feature_disabled(Feature p_feature) const;
  73. Error save_to_file(const String &p_path);
  74. Error load_from_file(const String &p_path);
  75. static String get_feature_name(Feature p_feature);
  76. EditorFeatureProfile();
  77. };
  78. VARIANT_ENUM_CAST(EditorFeatureProfile::Feature)
  79. class EditorFeatureProfileManager : public AcceptDialog {
  80. GDCLASS(EditorFeatureProfileManager, AcceptDialog);
  81. enum Action {
  82. PROFILE_CLEAR,
  83. PROFILE_SET,
  84. PROFILE_IMPORT,
  85. PROFILE_EXPORT,
  86. PROFILE_NEW,
  87. PROFILE_ERASE,
  88. PROFILE_MAX
  89. };
  90. enum ClassOptions {
  91. CLASS_OPTION_DISABLE_EDITOR
  92. };
  93. ConfirmationDialog *erase_profile_dialog;
  94. ConfirmationDialog *new_profile_dialog;
  95. LineEdit *new_profile_name;
  96. LineEdit *current_profile_name;
  97. OptionButton *profile_list;
  98. Button *profile_actions[PROFILE_MAX];
  99. HSplitContainer *h_split;
  100. VBoxContainer *class_list_vbc;
  101. Tree *class_list;
  102. VBoxContainer *property_list_vbc;
  103. Tree *property_list;
  104. Label *no_profile_selected_help;
  105. EditorFileDialog *import_profiles;
  106. EditorFileDialog *export_profile;
  107. void _profile_action(int p_action);
  108. void _profile_selected(int p_what);
  109. String current_profile;
  110. void _update_profile_list(const String &p_select_profile = String());
  111. void _update_selected_profile();
  112. void _fill_classes_from(TreeItem *p_parent, const String &p_class, const String &p_selected);
  113. Ref<EditorFeatureProfile> current;
  114. Ref<EditorFeatureProfile> edited;
  115. void _erase_selected_profile();
  116. void _create_new_profile();
  117. String _get_selected_profile();
  118. void _import_profiles(const Vector<String> &p_paths);
  119. void _export_profile(const String &p_path);
  120. bool updating_features;
  121. void _class_list_item_selected();
  122. void _class_list_item_edited();
  123. void _property_item_edited();
  124. void _save_and_update();
  125. Timer *update_timer;
  126. void _emit_current_profile_changed();
  127. static EditorFeatureProfileManager *singleton;
  128. protected:
  129. static void _bind_methods();
  130. void _notification(int p_what);
  131. public:
  132. Ref<EditorFeatureProfile> get_current_profile();
  133. void notify_changed();
  134. static EditorFeatureProfileManager *get_singleton() { return singleton; }
  135. EditorFeatureProfileManager();
  136. };
  137. #endif // EDITOR_FEATURE_PROFILE_H