editor_about.cpp 14 KB

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