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