editor_about.cpp 11 KB

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