Debian Codegraph @

editor/gui/editor_about.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* editor_about.cpp */
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 #include "editor_about.h"
32
33 #include "core/authors.gen.h"
34 #include "core/donors.gen.h"
35 #include "core/license.gen.h"
36 #include "editor/editor_node.h"
37 #include "editor/editor_string_names.h"
38 #include "editor/gui/credits_roll.h"
39 #include "editor/gui/editor_toaster.h"
40 #include "editor/gui/editor_version_button.h"
41 #include "editor/run/editor_run_bar.h"
42 #include "editor/themes/editor_scale.h"
43 #include "scene/gui/item_list.h"
44 #include "scene/gui/rich_text_label.h"
45 #include "scene/gui/scroll_container.h"
46 #include "scene/gui/separator.h"
47 #include "scene/gui/split_container.h"
48 #include "scene/gui/tab_container.h"
49 #include "scene/gui/texture_rect.h"
50 #include "scene/gui/tree.h"
51 #include "scene/resources/style_box.h"
52
53 void EditorAbout::_notification(int p_what) {
54 switch (p_what) {
55 case NOTIFICATION_TRANSLATION_CHANGED: {
56 _about_text_label->set_text(
57 String(U"© 2014-present ") + TTR("Godot Engine contributors") + ".\n" +
58 String(U"© 2007-2014 Juan Linietsky, Ariel Manzur.\n"));
59
60 _project_manager_label->set_text(TTR("Project Manager", "Job Title"));
61
62 for (ItemList *il : name_lists) {
63 for (int i = 0; i < il->get_item_count(); i++) {
64 const Variant val = il->get_item_metadata(i);
65 if (val.get_type() == Variant::STRING) {
66 il->set_item_tooltip(i, val.operator String() + "\n\n" + TTR("Double-click to open in browser."));
67 }
68 }
69 }
70 } break;
71
72 case NOTIFICATION_THEME_CHANGED: {
73 const Ref<Font> font = get_theme_font(SNAME("source"), EditorStringName(EditorFonts));
74 const int font_size = get_theme_font_size(SNAME("source_size"), EditorStringName(EditorFonts));
75
76 _tpl_text->begin_bulk_theme_override();
77 _tpl_text->add_theme_font_override("normal_font", font);
78 _tpl_text->add_theme_font_size_override("normal_font_size", font_size);
79 _tpl_text->add_theme_constant_override(SceneStringName(line_separation), 4 * EDSCALE);
80 _tpl_text->end_bulk_theme_override();
81
82 license_text_label->begin_bulk_theme_override();
83 license_text_label->add_theme_font_override("normal_font", font);
84 license_text_label->add_theme_font_size_override("normal_font_size", font_size);
85 license_text_label->add_theme_constant_override(SceneStringName(line_separation), 4 * EDSCALE);
86 license_text_label->end_bulk_theme_override();
87
88 _logo->set_texture(get_editor_theme_icon(SNAME("Logo")));
89
90 for (ItemList *il : name_lists) {
91 for (int i = 0; i < il->get_item_count(); i++) {
92 if (il->get_item_metadata(i)) {
93 il->set_item_icon(i, get_theme_icon(SNAME("ExternalLink"), EditorStringName(EditorIcons)));
94 il->set_item_icon_modulate(i, get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
95 }
96 }
97 }
98 } break;
99 }
100 }
101
102 void EditorAbout::_license_tree_selected() {
103 TreeItem *selected = _tpl_tree->get_selected();
104 _tpl_text->scroll_to_line(0);
105 _tpl_text->set_text(selected->get_metadata(0));
106 }
107
108 void EditorAbout::_credits_visibility_changed() {
109 if (!credits_roll->is_visible()) {
110 credits_roll->queue_free();
111 credits_roll = nullptr;
112
113 show();
114 }
115 }
116
117 void EditorAbout::_item_activated(int p_idx, ItemList *p_il) {
118 const Variant val = p_il->get_item_metadata(p_idx);
119 if (val.get_type() == Variant::STRING) {
120 OS::get_singleton()->shell_open(val);
121 } else {
122 // Easter egg! :D
123 if (EditorRunBar::get_singleton()->is_playing()) {
124 // Don't allow if the game is running, as it will look weird if it's embedded.
125 EditorToaster::get_singleton()->popup_str(TTR("No distractions for this, close that game first."));
126 return;
127 }
128
129 if (!credits_roll) {
130 credits_roll = memnew(CreditsRoll);
131 credits_roll->connect("visibility_changed", callable_mp(this, &EditorAbout::_credits_visibility_changed));
132 get_tree()->get_root()->add_child(credits_roll);
133 }
134 credits_roll->roll_credits();
135 hide();
136 }
137 }
138
139 void EditorAbout::_item_list_resized(ItemList *p_il) {
140 p_il->set_fixed_column_width(p_il->get_size().x / 3.0 - 16 * EDSCALE * 2.5); // Weird. Should be 3.0 and that's it?.
141 }
142
143 Label *EditorAbout::_create_section(Control *p_parent, const String &p_name, const char *const *p_src, BitField<SectionFlags> p_flags) {
144 Label *lbl = memnew(Label(p_name));
145 lbl->set_theme_type_variation("HeaderSmall");
146 lbl->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
147 p_parent->add_child(lbl);
148
149 ItemList *il = memnew(ItemList);
150 il->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
151 il->set_h_size_flags(Control::SIZE_EXPAND_FILL);
152 il->set_same_column_width(true);
153 il->set_auto_height(true);
154 il->set_max_columns(p_flags.has_flag(FLAG_SINGLE_COLUMN) ? 1 : 16);
155 il->add_theme_constant_override("h_separation", 16 * EDSCALE);
156
157 // Don't allow the Easter egg in the Project Manager.
158 if (p_flags.has_flag(FLAG_ALLOW_WEBSITE) || (p_flags.has_flag(FLAG_EASTER_EGG) && EditorNode::get_singleton())) {
159 Ref<StyleBoxEmpty> empty_stylebox = memnew(StyleBoxEmpty);
160 il->add_theme_style_override("focus", empty_stylebox);
161 il->add_theme_style_override("selected", empty_stylebox);
162
163 il->connect("item_activated", callable_mp(this, &EditorAbout::_item_activated).bind(il));
164 } else {
165 il->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
166 il->set_focus_mode(Control::FOCUS_NONE);
167 }
168
169 const char *const *names_ptr = p_src;
170 if (p_flags.has_flag(FLAG_ALLOW_WEBSITE)) {
171 il->connect(SceneStringName(resized), callable_mp(this, &EditorAbout::_item_list_resized).bind(il));
172 il->connect(SceneStringName(focus_exited), callable_mp(il, &ItemList::deselect_all));
173
174 while (*names_ptr) {
175 const String name = String::utf8(*names_ptr++);
176 const String identifier = name.get_slicec('<', 0);
177 const String website = name.get_slice_count("<") == 1 ? "" : name.get_slicec('<', 1).trim_suffix(">");
178
179 il->add_item(identifier, nullptr, !website.is_empty());
180
181 if (website.is_empty()) {
182 il->set_item_tooltip_enabled(-1, false);
183 } else {
184 il->set_item_metadata(-1, website);
185 }
186
187 if (!*names_ptr && name.contains(" anonymous ")) {
188 il->set_item_disabled(-1, true);
189 }
190 }
191 } else {
192 while (*names_ptr) {
193 il->add_item(String::utf8(*names_ptr++), nullptr, false);
194 il->set_item_tooltip_enabled(-1, false);
195 }
196 }
197
198 name_lists.append(il);
199
200 p_parent->add_child(il);
201
202 HSeparator *hs = memnew(HSeparator);
203 hs->set_modulate(Color(0, 0, 0, 0));
204 p_parent->add_child(hs);
205
206 return lbl;
207 }
208
209 EditorAbout::EditorAbout() {
210 set_title(TTRC("Thanks from the Godot community!"));
211 set_hide_on_ok(true);
212
213 VBoxContainer *vbc = memnew(VBoxContainer);
214 add_child(vbc);
215
216 HBoxContainer *hbc = memnew(HBoxContainer);
217 hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
218 hbc->set_alignment(BoxContainer::ALIGNMENT_CENTER);
219 hbc->add_theme_constant_override("separation", 30 * EDSCALE);
220 vbc->add_child(hbc);
221
222 _logo = memnew(TextureRect);
223 _logo->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED);
224 hbc->add_child(_logo);
225
226 VBoxContainer *version_info_vbc = memnew(VBoxContainer);
227
228 // Add a dummy control node for spacing.
229 Control *v_spacer = memnew(Control);
230 version_info_vbc->add_child(v_spacer);
231
232 version_info_vbc->add_child(memnew(EditorVersionButton(EditorVersionButton::FORMAT_WITH_NAME_AND_BUILD)));
233
234 _about_text_label = memnew(Label);
235 _about_text_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
236 _about_text_label->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
237 _about_text_label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
238 version_info_vbc->add_child(_about_text_label);
239
240 hbc->add_child(version_info_vbc);
241
242 TabContainer *tc = memnew(TabContainer);
243 tc->set_tab_alignment(TabBar::ALIGNMENT_CENTER);
244 tc->set_custom_minimum_size(Size2(400, 200) * EDSCALE);
245 tc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
246 tc->set_theme_type_variation("TabContainerOdd");
247 vbc->add_child(tc);
248
249 {
250 ScrollContainer *sc = memnew(ScrollContainer);
251 sc->set_name(TTRC("Authors"));
252 sc->set_v_size_flags(Control::SIZE_EXPAND);
253 tc->add_child(sc);
254
255 VBoxContainer *vb = memnew(VBoxContainer);
256 vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
257 sc->add_child(vb);
258
259 _create_section(vb, TTRC("Project Founders"), AUTHORS_FOUNDERS, FLAG_SINGLE_COLUMN);
260 _create_section(vb, TTRC("Lead Developer"), AUTHORS_LEAD_DEVELOPERS);
261 // The section title will be updated in NOTIFICATION_TRANSLATION_CHANGED.
262 _project_manager_label = _create_section(vb, "", AUTHORS_PROJECT_MANAGERS, FLAG_EASTER_EGG);
263 _project_manager_label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
264 _create_section(vb, TTRC("Developers"), AUTHORS_DEVELOPERS);
265 }
266
267 {
268 ScrollContainer *sc = memnew(ScrollContainer);
269 sc->set_name(TTRC("Donors"));
270 sc->set_v_size_flags(Control::SIZE_EXPAND);
271 tc->add_child(sc);
272
273 VBoxContainer *vb = memnew(VBoxContainer);
274 vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
275 sc->add_child(vb);
276
277 _create_section(vb, TTRC("Patrons"), DONORS_PATRONS, FLAG_ALLOW_WEBSITE | FLAG_SINGLE_COLUMN);
278 _create_section(vb, TTRC("Platinum Sponsors"), DONORS_SPONSORS_PLATINUM, FLAG_ALLOW_WEBSITE);
279 _create_section(vb, TTRC("Gold Sponsors"), DONORS_SPONSORS_GOLD, FLAG_ALLOW_WEBSITE);
280 _create_section(vb, TTRC("Silver Sponsors"), DONORS_SPONSORS_SILVER, FLAG_ALLOW_WEBSITE);
281 _create_section(vb, TTRC("Diamond Members"), DONORS_MEMBERS_DIAMOND, FLAG_ALLOW_WEBSITE);
282 _create_section(vb, TTRC("Titanium Members"), DONORS_MEMBERS_TITANIUM, FLAG_ALLOW_WEBSITE);
283 _create_section(vb, TTRC("Platinum Members"), DONORS_MEMBERS_PLATINUM, FLAG_ALLOW_WEBSITE);
284 _create_section(vb, TTRC("Gold Members"), DONORS_MEMBERS_GOLD, FLAG_ALLOW_WEBSITE);
285 }
286
287 // License.
288
289 license_text_label = memnew(RichTextLabel);
290 license_text_label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
291 license_text_label->set_threaded(true);
292 license_text_label->set_name(TTRC("License"));
293 license_text_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
294 license_text_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
295 license_text_label->set_text(String::utf8(GODOT_LICENSE_TEXT));
296 tc->add_child(license_text_label);
297
298 // Thirdparty License.
299
300 VBoxContainer *license_thirdparty = memnew(VBoxContainer);
301 license_thirdparty->set_name(TTRC("Third-party Licenses"));
302 license_thirdparty->set_h_size_flags(Control::SIZE_EXPAND_FILL);
303 tc->add_child(license_thirdparty);
304
305 Label *tpl_label = memnew(Label(TTRC("Godot Engine relies on a number of third-party free and open source libraries, all compatible with the terms of its MIT license. The following is an exhaustive list of all such third-party components with their respective copyright statements and license terms.")));
306 tpl_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
307 tpl_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
308 tpl_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
309 tpl_label->set_size(Size2(630, 1) * EDSCALE);
310 license_thirdparty->add_child(tpl_label);
311
312 HSplitContainer *tpl_hbc = memnew(HSplitContainer);
313 tpl_hbc->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
314 tpl_hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
315 tpl_hbc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
316 tpl_hbc->set_split_offset(240 * EDSCALE);
317 license_thirdparty->add_child(tpl_hbc);
318
319 _tpl_tree = memnew(Tree);
320 _tpl_tree->set_hide_root(true);
321 TreeItem *root = _tpl_tree->create_item();
322 TreeItem *tpl_ti_all = _tpl_tree->create_item(root);
323 tpl_ti_all->set_text(0, TTRC("All Components"));
324 tpl_ti_all->set_auto_translate_mode(0, AUTO_TRANSLATE_MODE_ALWAYS);
325 TreeItem *tpl_ti_tp = _tpl_tree->create_item(root);
326 tpl_ti_tp->set_text(0, TTRC("Components"));
327 tpl_ti_tp->set_auto_translate_mode(0, AUTO_TRANSLATE_MODE_ALWAYS);
328 tpl_ti_tp->set_selectable(0, false);
329 TreeItem *tpl_ti_lc = _tpl_tree->create_item(root);
330 tpl_ti_lc->set_text(0, TTRC("Licenses"));
331 tpl_ti_lc->set_auto_translate_mode(0, AUTO_TRANSLATE_MODE_ALWAYS);
332 tpl_ti_lc->set_selectable(0, false);
333 String long_text = "";
334 for (int component_index = 0; component_index < COPYRIGHT_INFO_COUNT; component_index++) {
335 const ComponentCopyright &component = COPYRIGHT_INFO[component_index];
336 TreeItem *ti = _tpl_tree->create_item(tpl_ti_tp);
337 String component_name = String::utf8(component.name);
338 ti->set_text(0, component_name);
339 String text = component_name + "\n";
340 long_text += "- " + component_name + "\n";
341 for (int part_index = 0; part_index < component.part_count; part_index++) {
342 const ComponentCopyrightPart &part = component.parts[part_index];
343 text += "\n Files:";
344 for (int file_num = 0; file_num < part.file_count; file_num++) {
345 text += "\n " + String::utf8(part.files[file_num]);
346 }
347 String copyright;
348 for (int copyright_index = 0; copyright_index < part.copyright_count; copyright_index++) {
349 copyright += String::utf8("\n \xc2\xa9 ") + String::utf8(part.copyright_statements[copyright_index]);
350 }
351 text += copyright;
352 long_text += copyright;
353 String license = "\n License: " + String::utf8(part.license) + "\n";
354 text += license;
355 long_text += license + "\n";
356 }
357 ti->set_metadata(0, text);
358 }
359 for (int i = 0; i < LICENSE_COUNT; i++) {
360 TreeItem *ti = _tpl_tree->create_item(tpl_ti_lc);
361 String licensename = String::utf8(LICENSE_NAMES[i]);
362 ti->set_text(0, licensename);
363 long_text += "- " + licensename + "\n\n";
364 String licensebody = String::utf8(LICENSE_BODIES[i]);
365 ti->set_metadata(0, licensebody);
366 long_text += " " + licensebody.replace("\n", "\n ") + "\n\n";
367 }
368 tpl_ti_all->set_metadata(0, long_text);
369 tpl_hbc->add_child(_tpl_tree);
370
371 _tpl_text = memnew(RichTextLabel);
372 _tpl_text->set_threaded(true);
373 _tpl_text->set_h_size_flags(Control::SIZE_EXPAND_FILL);
374 _tpl_text->set_v_size_flags(Control::SIZE_EXPAND_FILL);
375 tpl_hbc->add_child(_tpl_text);
376
377 _tpl_tree->connect(SceneStringName(item_selected), callable_mp(this, &EditorAbout::_license_tree_selected));
378 tpl_ti_all->select(0);
379 _tpl_text->set_text(tpl_ti_all->get_metadata(0));
380 }