editor_about.cpp 14 KB

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