editor_about.cpp 15 KB

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