2
0

editor_about.cpp 12 KB

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