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 | |
31 | #ifndef EDITOR_BUILD_PROFILE_H |
32 | #define EDITOR_BUILD_PROFILE_H |
33 | |
34 | #include "core/io/file_access.h" |
35 | #include "core/object/ref_counted.h" |
36 | #include "editor/editor_help.h" |
37 | #include "scene/gui/dialogs.h" |
38 | #include "scene/gui/option_button.h" |
39 | #include "scene/gui/separator.h" |
40 | #include "scene/gui/split_container.h" |
41 | #include "scene/gui/tree.h" |
42 | |
43 | class EditorBuildProfile : public RefCounted { |
44 | GDCLASS(EditorBuildProfile, RefCounted); |
45 | |
46 | public: |
47 | enum BuildOption { |
48 | BUILD_OPTION_3D, |
49 | BUILD_OPTION_PHYSICS_2D, |
50 | BUILD_OPTION_PHYSICS_3D, |
51 | BUILD_OPTION_NAVIGATION, |
52 | BUILD_OPTION_XR, |
53 | BUILD_OPTION_RENDERING_DEVICE, |
54 | BUILD_OPTION_OPENGL, |
55 | BUILD_OPTION_VULKAN, |
56 | BUILD_OPTION_TEXT_SERVER_FALLBACK, |
57 | BUILD_OPTION_TEXT_SERVER_ADVANCED, |
58 | BUILD_OPTION_DYNAMIC_FONTS, |
59 | BUILD_OPTION_WOFF2_FONTS, |
60 | BUILD_OPTION_GRPAHITE_FONTS, |
61 | BUILD_OPTION_MSDFGEN, |
62 | BUILD_OPTION_MAX, |
63 | }; |
64 | |
65 | enum BuildOptionCategory { |
66 | BUILD_OPTION_CATEGORY_GENERAL, |
67 | BUILD_OPTION_CATEGORY_TEXT_SERVER, |
68 | BUILD_OPTION_CATEGORY_MAX, |
69 | }; |
70 | |
71 | private: |
72 | HashSet<StringName> disabled_classes; |
73 | |
74 | HashSet<StringName> collapsed_classes; |
75 | |
76 | String force_detect_classes; |
77 | |
78 | bool build_options_disabled[BUILD_OPTION_MAX] = {}; |
79 | static const char *build_option_identifiers[BUILD_OPTION_MAX]; |
80 | static const bool build_option_disabled_by_default[BUILD_OPTION_MAX]; |
81 | static const bool build_option_disable_values[BUILD_OPTION_MAX]; |
82 | static const BuildOptionCategory build_option_category[BUILD_OPTION_MAX]; |
83 | |
84 | String _get_build_option_name(BuildOption p_build_option) { return get_build_option_name(p_build_option); } |
85 | |
86 | protected: |
87 | static void _bind_methods(); |
88 | |
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 | |
93 | void set_item_collapsed(const StringName &p_class, bool p_collapsed); |
94 | bool is_item_collapsed(const StringName &p_class) const; |
95 | |
96 | void set_disable_build_option(BuildOption p_build_option, bool p_disable); |
97 | bool is_build_option_disabled(BuildOption p_build_option) const; |
98 | |
99 | void set_force_detect_classes(const String &p_classes); |
100 | String get_force_detect_classes() const; |
101 | |
102 | void clear_disabled_classes(); |
103 | |
104 | Error save_to_file(const String &p_path); |
105 | Error load_from_file(const String &p_path); |
106 | |
107 | static String get_build_option_name(BuildOption p_build_option); |
108 | static String get_build_option_description(BuildOption p_build_option); |
109 | static bool get_build_option_disable_value(BuildOption p_build_option); |
110 | static BuildOptionCategory get_build_option_category(BuildOption p_build_option); |
111 | |
112 | static String get_build_option_category_name(BuildOptionCategory p_build_option_category); |
113 | |
114 | EditorBuildProfile(); |
115 | }; |
116 | |
117 | VARIANT_ENUM_CAST(EditorBuildProfile::BuildOption) |
118 | VARIANT_ENUM_CAST(EditorBuildProfile::BuildOptionCategory) |
119 | |
120 | class EditorFileDialog; |
121 | class EditorFileSystemDirectory; |
122 | |
123 | class EditorBuildProfileManager : public AcceptDialog { |
124 | GDCLASS(EditorBuildProfileManager, AcceptDialog); |
125 | |
126 | enum Action { |
127 | ACTION_NEW, |
128 | ACTION_RESET, |
129 | ACTION_LOAD, |
130 | ACTION_SAVE, |
131 | ACTION_SAVE_AS, |
132 | ACTION_DETECT, |
133 | ACTION_MAX |
134 | }; |
135 | |
136 | Action last_action = ACTION_NEW; |
137 | |
138 | ConfirmationDialog *confirm_dialog = nullptr; |
139 | Button *profile_actions[ACTION_MAX]; |
140 | |
141 | Tree *class_list = nullptr; |
142 | EditorHelpBit *description_bit = nullptr; |
143 | |
144 | EditorFileDialog *import_profile = nullptr; |
145 | EditorFileDialog *export_profile = nullptr; |
146 | |
147 | LineEdit *profile_path = nullptr; |
148 | |
149 | LineEdit *force_detect_classes = nullptr; |
150 | |
151 | void _profile_action(int p_action); |
152 | void _action_confirm(); |
153 | |
154 | void _update_edited_profile(); |
155 | void _fill_classes_from(TreeItem *p_parent, const String &p_class, const String &p_selected); |
156 | |
157 | Ref<EditorBuildProfile> edited; |
158 | |
159 | void _import_profile(const String &p_path); |
160 | void _export_profile(const String &p_path); |
161 | |
162 | bool updating_build_options = false; |
163 | |
164 | void _class_list_item_selected(); |
165 | void _class_list_item_edited(); |
166 | void _class_list_item_collapsed(Object *p_item); |
167 | void _detect_classes(); |
168 | |
169 | void _force_detect_classes_changed(const String &p_text); |
170 | |
171 | struct DetectedFile { |
172 | uint32_t timestamp = 0; |
173 | String md5; |
174 | Vector<String> classes; |
175 | }; |
176 | |
177 | void _find_files(EditorFileSystemDirectory *p_dir, const HashMap<String, DetectedFile> &p_cache, HashMap<String, DetectedFile> &r_detected); |
178 | |
179 | static EditorBuildProfileManager *singleton; |
180 | |
181 | protected: |
182 | static void _bind_methods(); |
183 | void _notification(int p_what); |
184 | |
185 | public: |
186 | Ref<EditorBuildProfile> get_current_profile(); |
187 | |
188 | static EditorBuildProfileManager *get_singleton() { return singleton; } |
189 | EditorBuildProfileManager(); |
190 | }; |
191 | |
192 | #endif // EDITOR_BUILD_PROFILE_H |
193 | |