editor_about.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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/version.h"
  35. #include "editor/editor_string_names.h"
  36. // The metadata key used to store and retrieve the version text to copy to the clipboard.
  37. const String EditorAbout::META_TEXT_TO_COPY = "text_to_copy";
  38. void EditorAbout::_notification(int p_what) {
  39. switch (p_what) {
  40. case NOTIFICATION_THEME_CHANGED: {
  41. const Ref<Font> font = get_theme_font(SNAME("source"), EditorStringName(EditorFonts));
  42. const int font_size = get_theme_font_size(SNAME("source_size"), EditorStringName(EditorFonts));
  43. _tpl_text->begin_bulk_theme_override();
  44. _tpl_text->add_theme_font_override("normal_font", font);
  45. _tpl_text->add_theme_font_size_override("normal_font_size", font_size);
  46. _tpl_text->add_theme_constant_override("line_separation", 4 * EDSCALE);
  47. _tpl_text->end_bulk_theme_override();
  48. _license_text->begin_bulk_theme_override();
  49. _license_text->add_theme_font_override("normal_font", font);
  50. _license_text->add_theme_font_size_override("normal_font_size", font_size);
  51. _license_text->add_theme_constant_override("line_separation", 4 * EDSCALE);
  52. _license_text->end_bulk_theme_override();
  53. _logo->set_texture(get_editor_theme_icon(SNAME("Logo")));
  54. } break;
  55. }
  56. }
  57. void EditorAbout::_license_tree_selected() {
  58. TreeItem *selected = _tpl_tree->get_selected();
  59. _tpl_text->scroll_to_line(0);
  60. _tpl_text->set_text(selected->get_metadata(0));
  61. }
  62. void EditorAbout::_version_button_pressed() {
  63. DisplayServer::get_singleton()->clipboard_set(version_btn->get_meta(META_TEXT_TO_COPY));
  64. }
  65. void EditorAbout::_bind_methods() {
  66. ClassDB::bind_method(D_METHOD("_version_button_pressed"), &EditorAbout::_version_button_pressed);
  67. }
  68. TextureRect *EditorAbout::get_logo() const {
  69. return _logo;
  70. }
  71. ScrollContainer *EditorAbout::_populate_list(const String &p_name, const List<String> &p_sections, const char *const *const p_src[], const int p_flag_single_column) {
  72. ScrollContainer *sc = memnew(ScrollContainer);
  73. sc->set_name(p_name);
  74. sc->set_v_size_flags(Control::SIZE_EXPAND);
  75. VBoxContainer *vbc = memnew(VBoxContainer);
  76. vbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  77. sc->add_child(vbc);
  78. for (int i = 0; i < p_sections.size(); i++) {
  79. bool single_column = p_flag_single_column & 1 << i;
  80. const char *const *names_ptr = p_src[i];
  81. if (*names_ptr) {
  82. Label *lbl = memnew(Label);
  83. lbl->set_theme_type_variation("HeaderSmall");
  84. lbl->set_text(p_sections[i]);
  85. vbc->add_child(lbl);
  86. ItemList *il = memnew(ItemList);
  87. il->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  88. il->set_same_column_width(true);
  89. il->set_auto_height(true);
  90. il->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
  91. il->add_theme_constant_override("h_separation", 16 * EDSCALE);
  92. while (*names_ptr) {
  93. il->add_item(String::utf8(*names_ptr++), nullptr, false);
  94. }
  95. il->set_max_columns(il->get_item_count() < 4 || single_column ? 1 : 16);
  96. vbc->add_child(il);
  97. HSeparator *hs = memnew(HSeparator);
  98. hs->set_modulate(Color(0, 0, 0, 0));
  99. vbc->add_child(hs);
  100. }
  101. }
  102. return sc;
  103. }
  104. EditorAbout::EditorAbout() {
  105. set_title(TTR("Thanks from the Godot community!"));
  106. set_hide_on_ok(true);
  107. VBoxContainer *vbc = memnew(VBoxContainer);
  108. add_child(vbc);
  109. HBoxContainer *hbc = memnew(HBoxContainer);
  110. hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  111. hbc->set_alignment(BoxContainer::ALIGNMENT_CENTER);
  112. hbc->add_theme_constant_override("separation", 30 * EDSCALE);
  113. vbc->add_child(hbc);
  114. _logo = memnew(TextureRect);
  115. _logo->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED);
  116. hbc->add_child(_logo);
  117. VBoxContainer *version_info_vbc = memnew(VBoxContainer);
  118. // Add a dummy control node for spacing.
  119. Control *v_spacer = memnew(Control);
  120. version_info_vbc->add_child(v_spacer);
  121. version_btn = memnew(LinkButton);
  122. String hash = String(VERSION_HASH);
  123. if (hash.length() != 0) {
  124. hash = " " + vformat("[%s]", hash.left(9));
  125. }
  126. version_btn->set_text(VERSION_FULL_NAME + hash);
  127. // Set the text to copy in metadata as it slightly differs from the button's text.
  128. version_btn->set_meta(META_TEXT_TO_COPY, "v" VERSION_FULL_BUILD + hash);
  129. version_btn->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
  130. version_btn->set_tooltip_text(TTR("Click to copy."));
  131. version_btn->connect("pressed", callable_mp(this, &EditorAbout::_version_button_pressed));
  132. version_info_vbc->add_child(version_btn);
  133. Label *about_text = memnew(Label);
  134. about_text->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  135. about_text->set_text(
  136. String::utf8("\xc2\xa9 2014-present ") + TTR("Godot Engine contributors") + "." +
  137. String::utf8("\n\xc2\xa9 2007-2014 Juan Linietsky, Ariel Manzur.\n"));
  138. version_info_vbc->add_child(about_text);
  139. hbc->add_child(version_info_vbc);
  140. TabContainer *tc = memnew(TabContainer);
  141. tc->set_tab_alignment(TabBar::ALIGNMENT_CENTER);
  142. tc->set_custom_minimum_size(Size2(400, 200) * EDSCALE);
  143. tc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  144. tc->set_theme_type_variation("TabContainerOdd");
  145. vbc->add_child(tc);
  146. // Authors
  147. List<String> dev_sections;
  148. dev_sections.push_back(TTR("Project Founders"));
  149. dev_sections.push_back(TTR("Lead Developer"));
  150. // TRANSLATORS: This refers to a job title.
  151. dev_sections.push_back(TTR("Project Manager", "Job Title"));
  152. dev_sections.push_back(TTR("Developers"));
  153. const char *const *dev_src[] = {
  154. AUTHORS_FOUNDERS,
  155. AUTHORS_LEAD_DEVELOPERS,
  156. AUTHORS_PROJECT_MANAGERS,
  157. AUTHORS_DEVELOPERS,
  158. };
  159. tc->add_child(_populate_list(TTR("Authors"), dev_sections, dev_src, 1));
  160. // Donors
  161. List<String> donor_sections;
  162. donor_sections.push_back(TTR("Patrons"));
  163. donor_sections.push_back(TTR("Platinum Sponsors"));
  164. donor_sections.push_back(TTR("Gold Sponsors"));
  165. donor_sections.push_back(TTR("Silver Sponsors"));
  166. donor_sections.push_back(TTR("Diamond Members"));
  167. donor_sections.push_back(TTR("Titanium Members"));
  168. donor_sections.push_back(TTR("Platinum Members"));
  169. donor_sections.push_back(TTR("Gold Members"));
  170. const char *const *donor_src[] = {
  171. DONORS_PATRONS,
  172. DONORS_SPONSORS_PLATINUM,
  173. DONORS_SPONSORS_GOLD,
  174. DONORS_SPONSORS_SILVER,
  175. DONORS_MEMBERS_DIAMOND,
  176. DONORS_MEMBERS_TITANIUM,
  177. DONORS_MEMBERS_PLATINUM,
  178. DONORS_MEMBERS_GOLD,
  179. };
  180. tc->add_child(_populate_list(TTR("Donors"), donor_sections, donor_src, 3));
  181. // License
  182. _license_text = memnew(RichTextLabel);
  183. _license_text->set_threaded(true);
  184. _license_text->set_name(TTR("License"));
  185. _license_text->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  186. _license_text->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  187. _license_text->set_text(String::utf8(GODOT_LICENSE_TEXT));
  188. tc->add_child(_license_text);
  189. // Thirdparty License
  190. VBoxContainer *license_thirdparty = memnew(VBoxContainer);
  191. license_thirdparty->set_name(TTR("Third-party Licenses"));
  192. license_thirdparty->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  193. tc->add_child(license_thirdparty);
  194. Label *tpl_label = memnew(Label);
  195. tpl_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  196. tpl_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  197. 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."));
  198. tpl_label->set_size(Size2(630, 1) * EDSCALE);
  199. license_thirdparty->add_child(tpl_label);
  200. HSplitContainer *tpl_hbc = memnew(HSplitContainer);
  201. tpl_hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  202. tpl_hbc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  203. tpl_hbc->set_split_offset(240 * EDSCALE);
  204. license_thirdparty->add_child(tpl_hbc);
  205. _tpl_tree = memnew(Tree);
  206. _tpl_tree->set_hide_root(true);
  207. TreeItem *root = _tpl_tree->create_item();
  208. TreeItem *tpl_ti_all = _tpl_tree->create_item(root);
  209. tpl_ti_all->set_text(0, TTR("All Components"));
  210. TreeItem *tpl_ti_tp = _tpl_tree->create_item(root);
  211. tpl_ti_tp->set_text(0, TTR("Components"));
  212. tpl_ti_tp->set_selectable(0, false);
  213. TreeItem *tpl_ti_lc = _tpl_tree->create_item(root);
  214. tpl_ti_lc->set_text(0, TTR("Licenses"));
  215. tpl_ti_lc->set_selectable(0, false);
  216. String long_text = "";
  217. for (int component_index = 0; component_index < COPYRIGHT_INFO_COUNT; component_index++) {
  218. const ComponentCopyright &component = COPYRIGHT_INFO[component_index];
  219. TreeItem *ti = _tpl_tree->create_item(tpl_ti_tp);
  220. String component_name = String::utf8(component.name);
  221. ti->set_text(0, component_name);
  222. String text = component_name + "\n";
  223. long_text += "- " + component_name + "\n";
  224. for (int part_index = 0; part_index < component.part_count; part_index++) {
  225. const ComponentCopyrightPart &part = component.parts[part_index];
  226. text += "\n Files:";
  227. for (int file_num = 0; file_num < part.file_count; file_num++) {
  228. text += "\n " + String::utf8(part.files[file_num]);
  229. }
  230. String copyright;
  231. for (int copyright_index = 0; copyright_index < part.copyright_count; copyright_index++) {
  232. copyright += String::utf8("\n \xc2\xa9 ") + String::utf8(part.copyright_statements[copyright_index]);
  233. }
  234. text += copyright;
  235. long_text += copyright;
  236. String license = "\n License: " + String::utf8(part.license) + "\n";
  237. text += license;
  238. long_text += license + "\n";
  239. }
  240. ti->set_metadata(0, text);
  241. }
  242. for (int i = 0; i < LICENSE_COUNT; i++) {
  243. TreeItem *ti = _tpl_tree->create_item(tpl_ti_lc);
  244. String licensename = String::utf8(LICENSE_NAMES[i]);
  245. ti->set_text(0, licensename);
  246. long_text += "- " + licensename + "\n\n";
  247. String licensebody = String::utf8(LICENSE_BODIES[i]);
  248. ti->set_metadata(0, licensebody);
  249. long_text += " " + licensebody.replace("\n", "\n ") + "\n\n";
  250. }
  251. tpl_ti_all->set_metadata(0, long_text);
  252. tpl_hbc->add_child(_tpl_tree);
  253. _tpl_text = memnew(RichTextLabel);
  254. _tpl_text->set_threaded(true);
  255. _tpl_text->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  256. _tpl_text->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  257. tpl_hbc->add_child(_tpl_text);
  258. _tpl_tree->connect("item_selected", callable_mp(this, &EditorAbout::_license_tree_selected));
  259. tpl_ti_all->select(0);
  260. _tpl_text->set_text(tpl_ti_all->get_metadata(0));
  261. }
  262. EditorAbout::~EditorAbout() {}