editor_about.cpp 11 KB

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