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 "core/version.h" |
37 | #include "editor/editor_string_names.h" |
38 | |
39 | // The metadata key used to store and retrieve the version text to copy to the clipboard. |
40 | const String EditorAbout::META_TEXT_TO_COPY = "text_to_copy" ; |
41 | |
42 | void EditorAbout::_theme_changed() { |
43 | const Ref<Font> font = get_theme_font(SNAME("source" ), EditorStringName(EditorFonts)); |
44 | const int font_size = get_theme_font_size(SNAME("source_size" ), EditorStringName(EditorFonts)); |
45 | _tpl_text->add_theme_font_override("normal_font" , font); |
46 | _tpl_text->add_theme_font_size_override("normal_font_size" , font_size); |
47 | _tpl_text->add_theme_constant_override("line_separation" , 4 * EDSCALE); |
48 | _license_text->add_theme_font_override("normal_font" , font); |
49 | _license_text->add_theme_font_size_override("normal_font_size" , font_size); |
50 | _license_text->add_theme_constant_override("line_separation" , 4 * EDSCALE); |
51 | _logo->set_texture(get_editor_theme_icon(SNAME("Logo" ))); |
52 | } |
53 | |
54 | void EditorAbout::_notification(int p_what) { |
55 | switch (p_what) { |
56 | case NOTIFICATION_ENTER_TREE: { |
57 | _theme_changed(); |
58 | } break; |
59 | } |
60 | } |
61 | |
62 | void EditorAbout::_license_tree_selected() { |
63 | TreeItem *selected = _tpl_tree->get_selected(); |
64 | _tpl_text->scroll_to_line(0); |
65 | _tpl_text->set_text(selected->get_metadata(0)); |
66 | } |
67 | |
68 | void EditorAbout::_version_button_pressed() { |
69 | DisplayServer::get_singleton()->clipboard_set(version_btn->get_meta(META_TEXT_TO_COPY)); |
70 | } |
71 | |
72 | void EditorAbout::_bind_methods() { |
73 | ClassDB::bind_method(D_METHOD("_version_button_pressed" ), &EditorAbout::_version_button_pressed); |
74 | } |
75 | |
76 | TextureRect *EditorAbout::get_logo() const { |
77 | return _logo; |
78 | } |
79 | |
80 | ScrollContainer *EditorAbout::_populate_list(const String &p_name, const List<String> &p_sections, const char *const *const p_src[], const int p_flag_single_column) { |
81 | ScrollContainer *sc = memnew(ScrollContainer); |
82 | sc->set_name(p_name); |
83 | sc->set_v_size_flags(Control::SIZE_EXPAND); |
84 | |
85 | VBoxContainer *vbc = memnew(VBoxContainer); |
86 | vbc->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
87 | sc->add_child(vbc); |
88 | |
89 | for (int i = 0; i < p_sections.size(); i++) { |
90 | bool single_column = p_flag_single_column & 1 << i; |
91 | const char *const *names_ptr = p_src[i]; |
92 | if (*names_ptr) { |
93 | Label *lbl = memnew(Label); |
94 | lbl->set_theme_type_variation("HeaderSmall" ); |
95 | lbl->set_text(p_sections[i]); |
96 | vbc->add_child(lbl); |
97 | |
98 | ItemList *il = memnew(ItemList); |
99 | il->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
100 | il->set_same_column_width(true); |
101 | il->set_auto_height(true); |
102 | il->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); |
103 | il->add_theme_constant_override("h_separation" , 16 * EDSCALE); |
104 | while (*names_ptr) { |
105 | il->add_item(String::utf8(*names_ptr++), nullptr, false); |
106 | } |
107 | il->set_max_columns(il->get_item_count() < 4 || single_column ? 1 : 16); |
108 | vbc->add_child(il); |
109 | |
110 | HSeparator *hs = memnew(HSeparator); |
111 | hs->set_modulate(Color(0, 0, 0, 0)); |
112 | vbc->add_child(hs); |
113 | } |
114 | } |
115 | |
116 | return sc; |
117 | } |
118 | |
119 | EditorAbout::EditorAbout() { |
120 | set_title(TTR("Thanks from the Godot community!" )); |
121 | set_hide_on_ok(true); |
122 | |
123 | VBoxContainer *vbc = memnew(VBoxContainer); |
124 | vbc->connect("theme_changed" , callable_mp(this, &EditorAbout::_theme_changed)); |
125 | HBoxContainer *hbc = memnew(HBoxContainer); |
126 | hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
127 | hbc->set_alignment(BoxContainer::ALIGNMENT_CENTER); |
128 | hbc->add_theme_constant_override("separation" , 30 * EDSCALE); |
129 | add_child(vbc); |
130 | vbc->add_child(hbc); |
131 | |
132 | _logo = memnew(TextureRect); |
133 | _logo->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED); |
134 | hbc->add_child(_logo); |
135 | |
136 | VBoxContainer *version_info_vbc = memnew(VBoxContainer); |
137 | |
138 | // Add a dummy control node for spacing. |
139 | Control *v_spacer = memnew(Control); |
140 | version_info_vbc->add_child(v_spacer); |
141 | |
142 | version_btn = memnew(LinkButton); |
143 | String hash = String(VERSION_HASH); |
144 | if (hash.length() != 0) { |
145 | hash = " " + vformat("[%s]" , hash.left(9)); |
146 | } |
147 | version_btn->set_text(VERSION_FULL_NAME + hash); |
148 | // Set the text to copy in metadata as it slightly differs from the button's text. |
149 | version_btn->set_meta(META_TEXT_TO_COPY, "v" VERSION_FULL_BUILD + hash); |
150 | version_btn->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); |
151 | version_btn->set_tooltip_text(TTR("Click to copy." )); |
152 | version_btn->connect("pressed" , callable_mp(this, &EditorAbout::_version_button_pressed)); |
153 | version_info_vbc->add_child(version_btn); |
154 | |
155 | Label *about_text = memnew(Label); |
156 | about_text->set_v_size_flags(Control::SIZE_SHRINK_CENTER); |
157 | about_text->set_text(String::utf8("\xc2\xa9 2014-present " ) + TTR("Godot Engine contributors" ) + "." + |
158 | String::utf8("\n\xc2\xa9 2007-2014 Juan Linietsky, Ariel Manzur.\n" )); |
159 | version_info_vbc->add_child(about_text); |
160 | |
161 | hbc->add_child(version_info_vbc); |
162 | |
163 | TabContainer *tc = memnew(TabContainer); |
164 | tc->set_tab_alignment(TabBar::ALIGNMENT_CENTER); |
165 | tc->set_custom_minimum_size(Size2(400, 200) * EDSCALE); |
166 | tc->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
167 | tc->set_theme_type_variation("TabContainerOdd" ); |
168 | vbc->add_child(tc); |
169 | |
170 | // Authors |
171 | |
172 | List<String> dev_sections; |
173 | dev_sections.push_back(TTR("Project Founders" )); |
174 | dev_sections.push_back(TTR("Lead Developer" )); |
175 | // TRANSLATORS: This refers to a job title. |
176 | dev_sections.push_back(TTR("Project Manager" , "Job Title" )); |
177 | dev_sections.push_back(TTR("Developers" )); |
178 | const char *const *dev_src[] = { AUTHORS_FOUNDERS, AUTHORS_LEAD_DEVELOPERS, |
179 | AUTHORS_PROJECT_MANAGERS, AUTHORS_DEVELOPERS }; |
180 | tc->add_child(_populate_list(TTR("Authors" ), dev_sections, dev_src, 1)); |
181 | |
182 | // Donors |
183 | |
184 | List<String> donor_sections; |
185 | donor_sections.push_back(TTR("Platinum Sponsors" )); |
186 | donor_sections.push_back(TTR("Gold Sponsors" )); |
187 | donor_sections.push_back(TTR("Silver Sponsors" )); |
188 | donor_sections.push_back(TTR("Bronze Sponsors" )); |
189 | donor_sections.push_back(TTR("Mini Sponsors" )); |
190 | donor_sections.push_back(TTR("Gold Donors" )); |
191 | donor_sections.push_back(TTR("Silver Donors" )); |
192 | donor_sections.push_back(TTR("Bronze Donors" )); |
193 | const char *const *donor_src[] = { DONORS_SPONSOR_PLATINUM, DONORS_SPONSOR_GOLD, |
194 | DONORS_SPONSOR_SILVER, DONORS_SPONSOR_BRONZE, DONORS_SPONSOR_MINI, |
195 | DONORS_GOLD, DONORS_SILVER, DONORS_BRONZE }; |
196 | tc->add_child(_populate_list(TTR("Donors" ), donor_sections, donor_src, 3)); |
197 | |
198 | // License |
199 | |
200 | _license_text = memnew(RichTextLabel); |
201 | _license_text->set_threaded(true); |
202 | _license_text->set_name(TTR("License" )); |
203 | _license_text->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
204 | _license_text->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
205 | _license_text->set_text(String::utf8(GODOT_LICENSE_TEXT)); |
206 | tc->add_child(_license_text); |
207 | |
208 | // Thirdparty License |
209 | |
210 | VBoxContainer *license_thirdparty = memnew(VBoxContainer); |
211 | license_thirdparty->set_name(TTR("Third-party Licenses" )); |
212 | license_thirdparty->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
213 | tc->add_child(license_thirdparty); |
214 | |
215 | Label *tpl_label = memnew(Label); |
216 | tpl_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
217 | tpl_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART); |
218 | tpl_label->set_text(TTR("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." )); |
219 | tpl_label->set_size(Size2(630, 1) * EDSCALE); |
220 | license_thirdparty->add_child(tpl_label); |
221 | |
222 | HSplitContainer *tpl_hbc = memnew(HSplitContainer); |
223 | tpl_hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
224 | tpl_hbc->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
225 | tpl_hbc->set_split_offset(240 * EDSCALE); |
226 | license_thirdparty->add_child(tpl_hbc); |
227 | |
228 | _tpl_tree = memnew(Tree); |
229 | _tpl_tree->set_hide_root(true); |
230 | TreeItem *root = _tpl_tree->create_item(); |
231 | TreeItem *tpl_ti_all = _tpl_tree->create_item(root); |
232 | tpl_ti_all->set_text(0, TTR("All Components" )); |
233 | TreeItem *tpl_ti_tp = _tpl_tree->create_item(root); |
234 | tpl_ti_tp->set_text(0, TTR("Components" )); |
235 | tpl_ti_tp->set_selectable(0, false); |
236 | TreeItem *tpl_ti_lc = _tpl_tree->create_item(root); |
237 | tpl_ti_lc->set_text(0, TTR("Licenses" )); |
238 | tpl_ti_lc->set_selectable(0, false); |
239 | String long_text = "" ; |
240 | for (int component_index = 0; component_index < COPYRIGHT_INFO_COUNT; component_index++) { |
241 | const ComponentCopyright &component = COPYRIGHT_INFO[component_index]; |
242 | TreeItem *ti = _tpl_tree->create_item(tpl_ti_tp); |
243 | String component_name = String::utf8(component.name); |
244 | ti->set_text(0, component_name); |
245 | String text = component_name + "\n" ; |
246 | long_text += "- " + component_name + "\n" ; |
247 | for (int part_index = 0; part_index < component.part_count; part_index++) { |
248 | const ComponentCopyrightPart &part = component.parts[part_index]; |
249 | text += "\n Files:" ; |
250 | for (int file_num = 0; file_num < part.file_count; file_num++) { |
251 | text += "\n " + String::utf8(part.files[file_num]); |
252 | } |
253 | String copyright; |
254 | for (int copyright_index = 0; copyright_index < part.copyright_count; copyright_index++) { |
255 | copyright += String::utf8("\n \xc2\xa9 " ) + String::utf8(part.copyright_statements[copyright_index]); |
256 | } |
257 | text += copyright; |
258 | long_text += copyright; |
259 | String license = "\n License: " + String::utf8(part.license) + "\n" ; |
260 | text += license; |
261 | long_text += license + "\n" ; |
262 | } |
263 | ti->set_metadata(0, text); |
264 | } |
265 | for (int i = 0; i < LICENSE_COUNT; i++) { |
266 | TreeItem *ti = _tpl_tree->create_item(tpl_ti_lc); |
267 | String licensename = String::utf8(LICENSE_NAMES[i]); |
268 | ti->set_text(0, licensename); |
269 | long_text += "- " + licensename + "\n\n" ; |
270 | String licensebody = String::utf8(LICENSE_BODIES[i]); |
271 | ti->set_metadata(0, licensebody); |
272 | long_text += " " + licensebody.replace("\n" , "\n " ) + "\n\n" ; |
273 | } |
274 | tpl_ti_all->set_metadata(0, long_text); |
275 | tpl_hbc->add_child(_tpl_tree); |
276 | |
277 | _tpl_text = memnew(RichTextLabel); |
278 | _tpl_text->set_threaded(true); |
279 | _tpl_text->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
280 | _tpl_text->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
281 | tpl_hbc->add_child(_tpl_text); |
282 | |
283 | _tpl_tree->connect("item_selected" , callable_mp(this, &EditorAbout::_license_tree_selected)); |
284 | tpl_ti_all->select(0); |
285 | _tpl_text->set_text(tpl_ti_all->get_metadata(0)); |
286 | } |
287 | |
288 | EditorAbout::~EditorAbout() {} |
289 | |