editor_about.cpp 16 KB

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