editor_about.cpp 12 KB

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