editor_about.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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 "core/os/time.h"
  35. #include "core/version.h"
  36. #include "editor/editor_string_names.h"
  37. #include "editor/themes/editor_scale.h"
  38. #include "scene/gui/item_list.h"
  39. #include "scene/resources/style_box.h"
  40. // The metadata key used to store and retrieve the version text to copy to the clipboard.
  41. const String EditorAbout::META_TEXT_TO_COPY = "text_to_copy";
  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::_version_button_pressed() {
  75. DisplayServer::get_singleton()->clipboard_set(version_btn->get_meta(META_TEXT_TO_COPY));
  76. }
  77. void EditorAbout::_item_with_website_selected(int p_id, ItemList *p_il) {
  78. const String website = p_il->get_item_metadata(p_id);
  79. if (!website.is_empty()) {
  80. OS::get_singleton()->shell_open(website);
  81. }
  82. }
  83. void EditorAbout::_item_list_resized(ItemList *p_il) {
  84. 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?.
  85. }
  86. 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) {
  87. ScrollContainer *sc = memnew(ScrollContainer);
  88. sc->set_name(p_name);
  89. sc->set_v_size_flags(Control::SIZE_EXPAND);
  90. VBoxContainer *vbc = memnew(VBoxContainer);
  91. vbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  92. sc->add_child(vbc);
  93. Ref<StyleBoxEmpty> empty_stylebox = memnew(StyleBoxEmpty);
  94. int i = 0;
  95. for (List<String>::ConstIterator itr = p_sections.begin(); itr != p_sections.end(); ++itr, ++i) {
  96. bool single_column = p_single_column_flags & (1 << i);
  97. const char *const *names_ptr = p_src[i];
  98. if (*names_ptr) {
  99. Label *lbl = memnew(Label);
  100. lbl->set_theme_type_variation("HeaderSmall");
  101. lbl->set_text(*itr);
  102. vbc->add_child(lbl);
  103. ItemList *il = memnew(ItemList);
  104. il->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  105. il->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  106. il->set_same_column_width(true);
  107. il->set_auto_height(true);
  108. il->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
  109. il->set_focus_mode(Control::FOCUS_NONE);
  110. il->add_theme_constant_override("h_separation", 16 * EDSCALE);
  111. if (p_allow_website) {
  112. il->set_focus_mode(Control::FOCUS_CLICK);
  113. il->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  114. il->connect("item_activated", callable_mp(this, &EditorAbout::_item_with_website_selected).bind(il));
  115. il->connect(SceneStringName(resized), callable_mp(this, &EditorAbout::_item_list_resized).bind(il));
  116. il->connect(SceneStringName(focus_exited), callable_mp(il, &ItemList::deselect_all));
  117. il->add_theme_style_override("focus", empty_stylebox);
  118. il->add_theme_style_override("selected", empty_stylebox);
  119. while (*names_ptr) {
  120. const String name = String::utf8(*names_ptr++);
  121. const String identifier = name.get_slice("<", 0);
  122. const String website = name.get_slice_count("<") == 1 ? "" : name.get_slice("<", 1).trim_suffix(">");
  123. const int name_item_id = il->add_item(identifier, nullptr, false);
  124. il->set_item_tooltip_enabled(name_item_id, false);
  125. if (!website.is_empty()) {
  126. il->set_item_selectable(name_item_id, true);
  127. il->set_item_metadata(name_item_id, website);
  128. il->set_item_tooltip(name_item_id, website + "\n\n" + TTR("Double-click to open in browser."));
  129. il->set_item_tooltip_enabled(name_item_id, true);
  130. }
  131. if (!*names_ptr && name.contains(" anonymous ")) {
  132. il->set_item_disabled(name_item_id, true);
  133. }
  134. }
  135. } else {
  136. while (*names_ptr) {
  137. il->add_item(String::utf8(*names_ptr++), nullptr, false);
  138. }
  139. }
  140. il->set_max_columns(single_column ? 1 : 16);
  141. name_lists.append(il);
  142. vbc->add_child(il);
  143. HSeparator *hs = memnew(HSeparator);
  144. hs->set_modulate(Color(0, 0, 0, 0));
  145. vbc->add_child(hs);
  146. }
  147. }
  148. return sc;
  149. }
  150. EditorAbout::EditorAbout() {
  151. set_title(TTR("Thanks from the Godot community!"));
  152. set_hide_on_ok(true);
  153. VBoxContainer *vbc = memnew(VBoxContainer);
  154. add_child(vbc);
  155. HBoxContainer *hbc = memnew(HBoxContainer);
  156. hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  157. hbc->set_alignment(BoxContainer::ALIGNMENT_CENTER);
  158. hbc->add_theme_constant_override("separation", 30 * EDSCALE);
  159. vbc->add_child(hbc);
  160. _logo = memnew(TextureRect);
  161. _logo->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED);
  162. hbc->add_child(_logo);
  163. VBoxContainer *version_info_vbc = memnew(VBoxContainer);
  164. // Add a dummy control node for spacing.
  165. Control *v_spacer = memnew(Control);
  166. version_info_vbc->add_child(v_spacer);
  167. version_btn = memnew(LinkButton);
  168. String hash = String(VERSION_HASH);
  169. if (hash.length() != 0) {
  170. hash = " " + vformat("[%s]", hash.left(9));
  171. }
  172. version_btn->set_text(VERSION_FULL_NAME + hash);
  173. // Set the text to copy in metadata as it slightly differs from the button's text.
  174. version_btn->set_meta(META_TEXT_TO_COPY, "v" VERSION_FULL_BUILD + hash);
  175. version_btn->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
  176. String build_date;
  177. if (VERSION_TIMESTAMP > 0) {
  178. build_date = Time::get_singleton()->get_datetime_string_from_unix_time(VERSION_TIMESTAMP, true) + " UTC";
  179. } else {
  180. build_date = TTR("(unknown)");
  181. }
  182. version_btn->set_tooltip_text(vformat(TTR("Git commit date: %s\nClick to copy the version number."), build_date));
  183. version_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorAbout::_version_button_pressed));
  184. version_info_vbc->add_child(version_btn);
  185. Label *about_text = memnew(Label);
  186. about_text->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  187. about_text->set_text(
  188. String::utf8("\xc2\xa9 2014-present ") + TTR("Godot Engine contributors") + "." +
  189. String::utf8("\n\xc2\xa9 2007-2014 Juan Linietsky, Ariel Manzur.\n"));
  190. version_info_vbc->add_child(about_text);
  191. hbc->add_child(version_info_vbc);
  192. TabContainer *tc = memnew(TabContainer);
  193. tc->set_tab_alignment(TabBar::ALIGNMENT_CENTER);
  194. tc->set_custom_minimum_size(Size2(400, 200) * EDSCALE);
  195. tc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  196. tc->set_theme_type_variation("TabContainerOdd");
  197. vbc->add_child(tc);
  198. // Authors.
  199. List<String> dev_sections;
  200. dev_sections.push_back(TTR("Project Founders"));
  201. dev_sections.push_back(TTR("Lead Developer"));
  202. // TRANSLATORS: This refers to a job title.
  203. dev_sections.push_back(TTR("Project Manager", "Job Title"));
  204. dev_sections.push_back(TTR("Developers"));
  205. const char *const *dev_src[] = {
  206. AUTHORS_FOUNDERS,
  207. AUTHORS_LEAD_DEVELOPERS,
  208. AUTHORS_PROJECT_MANAGERS,
  209. AUTHORS_DEVELOPERS,
  210. };
  211. tc->add_child(_populate_list(TTR("Authors"), dev_sections, dev_src, 0b1)); // First section (Project Founders) is always one column.
  212. // Donors.
  213. List<String> donor_sections;
  214. donor_sections.push_back(TTR("Patrons"));
  215. donor_sections.push_back(TTR("Platinum Sponsors"));
  216. donor_sections.push_back(TTR("Gold Sponsors"));
  217. donor_sections.push_back(TTR("Silver Sponsors"));
  218. donor_sections.push_back(TTR("Diamond Members"));
  219. donor_sections.push_back(TTR("Titanium Members"));
  220. donor_sections.push_back(TTR("Platinum Members"));
  221. donor_sections.push_back(TTR("Gold Members"));
  222. const char *const *donor_src[] = {
  223. DONORS_PATRONS,
  224. DONORS_SPONSORS_PLATINUM,
  225. DONORS_SPONSORS_GOLD,
  226. DONORS_SPONSORS_SILVER,
  227. DONORS_MEMBERS_DIAMOND,
  228. DONORS_MEMBERS_TITANIUM,
  229. DONORS_MEMBERS_PLATINUM,
  230. DONORS_MEMBERS_GOLD,
  231. };
  232. tc->add_child(_populate_list(TTR("Donors"), donor_sections, donor_src, 0b1, true)); // First section (Patron) is one column.
  233. // License.
  234. license_text_label = memnew(RichTextLabel);
  235. license_text_label->set_threaded(true);
  236. license_text_label->set_name(TTR("License"));
  237. license_text_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  238. license_text_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  239. license_text_label->set_text(String::utf8(GODOT_LICENSE_TEXT));
  240. tc->add_child(license_text_label);
  241. // Thirdparty License.
  242. VBoxContainer *license_thirdparty = memnew(VBoxContainer);
  243. license_thirdparty->set_name(TTR("Third-party Licenses"));
  244. license_thirdparty->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  245. tc->add_child(license_thirdparty);
  246. Label *tpl_label = memnew(Label);
  247. tpl_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  248. tpl_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  249. 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."));
  250. tpl_label->set_size(Size2(630, 1) * EDSCALE);
  251. license_thirdparty->add_child(tpl_label);
  252. HSplitContainer *tpl_hbc = memnew(HSplitContainer);
  253. tpl_hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  254. tpl_hbc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  255. tpl_hbc->set_split_offset(240 * EDSCALE);
  256. license_thirdparty->add_child(tpl_hbc);
  257. _tpl_tree = memnew(Tree);
  258. _tpl_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  259. _tpl_tree->set_hide_root(true);
  260. TreeItem *root = _tpl_tree->create_item();
  261. TreeItem *tpl_ti_all = _tpl_tree->create_item(root);
  262. tpl_ti_all->set_text(0, TTR("All Components"));
  263. TreeItem *tpl_ti_tp = _tpl_tree->create_item(root);
  264. tpl_ti_tp->set_text(0, TTR("Components"));
  265. tpl_ti_tp->set_selectable(0, false);
  266. TreeItem *tpl_ti_lc = _tpl_tree->create_item(root);
  267. tpl_ti_lc->set_text(0, TTR("Licenses"));
  268. tpl_ti_lc->set_selectable(0, false);
  269. String long_text = "";
  270. for (int component_index = 0; component_index < COPYRIGHT_INFO_COUNT; component_index++) {
  271. const ComponentCopyright &component = COPYRIGHT_INFO[component_index];
  272. TreeItem *ti = _tpl_tree->create_item(tpl_ti_tp);
  273. String component_name = String::utf8(component.name);
  274. ti->set_text(0, component_name);
  275. String text = component_name + "\n";
  276. long_text += "- " + component_name + "\n";
  277. for (int part_index = 0; part_index < component.part_count; part_index++) {
  278. const ComponentCopyrightPart &part = component.parts[part_index];
  279. text += "\n Files:";
  280. for (int file_num = 0; file_num < part.file_count; file_num++) {
  281. text += "\n " + String::utf8(part.files[file_num]);
  282. }
  283. String copyright;
  284. for (int copyright_index = 0; copyright_index < part.copyright_count; copyright_index++) {
  285. copyright += String::utf8("\n \xc2\xa9 ") + String::utf8(part.copyright_statements[copyright_index]);
  286. }
  287. text += copyright;
  288. long_text += copyright;
  289. String license = "\n License: " + String::utf8(part.license) + "\n";
  290. text += license;
  291. long_text += license + "\n";
  292. }
  293. ti->set_metadata(0, text);
  294. }
  295. for (int i = 0; i < LICENSE_COUNT; i++) {
  296. TreeItem *ti = _tpl_tree->create_item(tpl_ti_lc);
  297. String licensename = String::utf8(LICENSE_NAMES[i]);
  298. ti->set_text(0, licensename);
  299. long_text += "- " + licensename + "\n\n";
  300. String licensebody = String::utf8(LICENSE_BODIES[i]);
  301. ti->set_metadata(0, licensebody);
  302. long_text += " " + licensebody.replace("\n", "\n ") + "\n\n";
  303. }
  304. tpl_ti_all->set_metadata(0, long_text);
  305. tpl_hbc->add_child(_tpl_tree);
  306. _tpl_text = memnew(RichTextLabel);
  307. _tpl_text->set_threaded(true);
  308. _tpl_text->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  309. _tpl_text->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  310. tpl_hbc->add_child(_tpl_text);
  311. _tpl_tree->connect(SceneStringName(item_selected), callable_mp(this, &EditorAbout::_license_tree_selected));
  312. tpl_ti_all->select(0);
  313. _tpl_text->set_text(tpl_ti_all->get_metadata(0));
  314. }
  315. EditorAbout::~EditorAbout() {}