editor_build_profile.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /**************************************************************************/
  2. /* editor_build_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. #pragma once
  31. #include "core/object/ref_counted.h"
  32. #include "editor/editor_help.h"
  33. #include "scene/gui/dialogs.h"
  34. #include "scene/gui/tree.h"
  35. class EditorBuildProfile : public RefCounted {
  36. GDCLASS(EditorBuildProfile, RefCounted);
  37. public:
  38. enum BuildOption {
  39. BUILD_OPTION_3D,
  40. BUILD_OPTION_NAVIGATION_2D,
  41. BUILD_OPTION_NAVIGATION_3D,
  42. BUILD_OPTION_XR,
  43. BUILD_OPTION_OPENXR,
  44. BUILD_OPTION_WAYLAND,
  45. BUILD_OPTION_X11,
  46. BUILD_OPTION_RENDERING_DEVICE,
  47. BUILD_OPTION_FORWARD_RENDERER,
  48. BUILD_OPTION_MOBILE_RENDERER,
  49. BUILD_OPTION_VULKAN,
  50. BUILD_OPTION_D3D12,
  51. BUILD_OPTION_METAL,
  52. BUILD_OPTION_OPENGL,
  53. BUILD_OPTION_PHYSICS_2D,
  54. BUILD_OPTION_PHYSICS_GODOT_2D,
  55. BUILD_OPTION_PHYSICS_3D,
  56. BUILD_OPTION_PHYSICS_GODOT_3D,
  57. BUILD_OPTION_PHYSICS_JOLT,
  58. BUILD_OPTION_TEXT_SERVER_FALLBACK,
  59. BUILD_OPTION_TEXT_SERVER_ADVANCED,
  60. BUILD_OPTION_DYNAMIC_FONTS,
  61. BUILD_OPTION_WOFF2_FONTS,
  62. BUILD_OPTION_GRAPHITE_FONTS,
  63. BUILD_OPTION_MSDFGEN,
  64. BUILD_OPTION_MAX,
  65. };
  66. enum BuildOptionCategory {
  67. BUILD_OPTION_CATEGORY_GENERAL,
  68. BUILD_OPTION_CATEGORY_GRAPHICS,
  69. BUILD_OPTION_CATEGORY_PHYSICS,
  70. BUILD_OPTION_CATEGORY_TEXT_SERVER,
  71. BUILD_OPTION_CATEGORY_MAX,
  72. };
  73. private:
  74. HashSet<StringName> disabled_classes;
  75. HashSet<StringName> collapsed_classes;
  76. String force_detect_classes;
  77. bool build_options_disabled[BUILD_OPTION_MAX] = {};
  78. static const char *build_option_identifiers[BUILD_OPTION_MAX];
  79. static const bool build_option_disabled_by_default[BUILD_OPTION_MAX];
  80. static const bool build_option_disable_values[BUILD_OPTION_MAX];
  81. static const bool build_option_explicit_use[BUILD_OPTION_MAX];
  82. static const BuildOptionCategory build_option_category[BUILD_OPTION_MAX];
  83. static const HashMap<BuildOption, LocalVector<BuildOption>> build_option_dependencies;
  84. static HashMap<BuildOption, HashMap<String, LocalVector<Variant>>> build_option_settings;
  85. static const HashMap<BuildOption, LocalVector<String>> build_option_classes;
  86. String _get_build_option_name(BuildOption p_build_option) { return get_build_option_name(p_build_option); }
  87. protected:
  88. static void _bind_methods();
  89. public:
  90. void set_disable_class(const StringName &p_class, bool p_disabled);
  91. bool is_class_disabled(const StringName &p_class) const;
  92. void set_item_collapsed(const StringName &p_class, bool p_collapsed);
  93. bool is_item_collapsed(const StringName &p_class) const;
  94. void set_disable_build_option(BuildOption p_build_option, bool p_disable);
  95. bool is_build_option_disabled(BuildOption p_build_option) const;
  96. void reset_build_options();
  97. void set_force_detect_classes(const String &p_classes);
  98. String get_force_detect_classes() const;
  99. void clear_disabled_classes();
  100. Error save_to_file(const String &p_path);
  101. Error load_from_file(const String &p_path);
  102. static String get_build_option_name(BuildOption p_build_option);
  103. static String get_build_option_description(BuildOption p_build_option);
  104. static String get_build_option_identifier(BuildOption p_build_option);
  105. static bool get_build_option_disable_value(BuildOption p_build_option);
  106. static bool get_build_option_explicit_use(BuildOption p_build_option);
  107. static BuildOptionCategory get_build_option_category(BuildOption p_build_option);
  108. static LocalVector<BuildOption> get_build_option_dependencies(BuildOption p_build_option);
  109. static HashMap<String, LocalVector<Variant>> get_build_option_settings(BuildOption p_build_option);
  110. static LocalVector<String> get_build_option_classes(BuildOption p_build_option);
  111. static String get_build_option_category_name(BuildOptionCategory p_build_option_category);
  112. EditorBuildProfile();
  113. };
  114. VARIANT_ENUM_CAST(EditorBuildProfile::BuildOption)
  115. VARIANT_ENUM_CAST(EditorBuildProfile::BuildOptionCategory)
  116. class EditorFileDialog;
  117. class EditorFileSystemDirectory;
  118. class EditorBuildProfileManager : public AcceptDialog {
  119. GDCLASS(EditorBuildProfileManager, AcceptDialog);
  120. enum Action {
  121. ACTION_NEW,
  122. ACTION_RESET,
  123. ACTION_LOAD,
  124. ACTION_SAVE,
  125. ACTION_SAVE_AS,
  126. ACTION_DETECT,
  127. ACTION_MAX
  128. };
  129. Action last_action = ACTION_NEW;
  130. ConfirmationDialog *confirm_dialog = nullptr;
  131. Button *profile_actions[ACTION_MAX];
  132. Tree *class_list = nullptr;
  133. EditorHelpBit *description_bit = nullptr;
  134. EditorFileDialog *import_profile = nullptr;
  135. EditorFileDialog *export_profile = nullptr;
  136. LineEdit *profile_path = nullptr;
  137. LineEdit *force_detect_classes = nullptr;
  138. void _profile_action(int p_action);
  139. void _action_confirm();
  140. void _hide_requested();
  141. void _update_edited_profile();
  142. void _fill_classes_from(TreeItem *p_parent, const String &p_class, const String &p_selected);
  143. Ref<EditorBuildProfile> edited;
  144. void _import_profile(const String &p_path);
  145. void _export_profile(const String &p_path);
  146. bool updating_build_options = false;
  147. void _class_list_item_selected();
  148. void _class_list_item_edited();
  149. void _class_list_item_collapsed(Object *p_item);
  150. bool project_scan_canceled = false;
  151. void _detect_from_project();
  152. void _force_detect_classes_changed(const String &p_text);
  153. struct DetectedFile {
  154. uint32_t timestamp = 0;
  155. String md5;
  156. Vector<String> classes;
  157. Vector<String> build_deps;
  158. };
  159. void _find_files(EditorFileSystemDirectory *p_dir, const HashMap<String, DetectedFile> &p_cache, HashMap<String, DetectedFile> &r_detected);
  160. static EditorBuildProfileManager *singleton;
  161. protected:
  162. static void _bind_methods();
  163. void _notification(int p_what);
  164. public:
  165. Ref<EditorBuildProfile> get_current_profile();
  166. static EditorBuildProfileManager *get_singleton() { return singleton; }
  167. EditorBuildProfileManager();
  168. };