credits_roll.cpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /**************************************************************************/
  2. /* credits_roll.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 "credits_roll.h"
  31. #include "core/authors.gen.h"
  32. #include "core/donors.gen.h"
  33. #include "core/input/input.h"
  34. #include "core/license.gen.h"
  35. #include "core/string/string_builder.h"
  36. #include "editor/editor_node.h"
  37. #include "editor/editor_string_names.h"
  38. #include "editor/themes/editor_scale.h"
  39. #include "scene/gui/box_container.h"
  40. #include "scene/gui/color_rect.h"
  41. #include "scene/gui/label.h"
  42. #include "scene/gui/texture_rect.h"
  43. #include "scene/main/window.h"
  44. Label *CreditsRoll::_create_label(const String &p_with_text, LabelSize p_size) {
  45. Label *label = memnew(Label);
  46. label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  47. label->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
  48. label->set_text(p_with_text);
  49. switch (p_size) {
  50. case LabelSize::NORMAL: {
  51. label->add_theme_font_size_override(SceneStringName(font_size), font_size_normal);
  52. label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  53. } break;
  54. case LabelSize::HEADER: {
  55. label->add_theme_font_size_override(SceneStringName(font_size), font_size_header);
  56. label->add_theme_font_override(SceneStringName(font), bold_font);
  57. } break;
  58. case LabelSize::BIG_HEADER: {
  59. label->add_theme_font_size_override(SceneStringName(font_size), font_size_big_header);
  60. label->add_theme_font_override(SceneStringName(font), bold_font);
  61. } break;
  62. }
  63. content->add_child(label);
  64. return label;
  65. }
  66. void CreditsRoll::_create_nothing(int p_size) {
  67. if (p_size == -1) {
  68. p_size = 30 * EDSCALE;
  69. }
  70. Control *c = memnew(Control);
  71. c->set_custom_minimum_size(Vector2(0, p_size));
  72. content->add_child(c);
  73. }
  74. String CreditsRoll::_build_string(const char *const *p_from) const {
  75. StringBuilder sb;
  76. while (*p_from) {
  77. sb.append(String::utf8(*p_from));
  78. sb.append("\n");
  79. p_from++;
  80. }
  81. return sb.as_string();
  82. }
  83. void CreditsRoll::_visibility_changed() {
  84. if (!is_visible()) {
  85. mouse_enabled = false;
  86. set_process_internal(false);
  87. set_process_input(false);
  88. }
  89. }
  90. void CreditsRoll::input(const Ref<InputEvent> &p_event) {
  91. // Block inputs from going elsewhere while the credits roll.
  92. get_tree()->get_root()->set_input_as_handled();
  93. }
  94. void CreditsRoll::_notification(int p_what) {
  95. switch (p_what) {
  96. case NOTIFICATION_POSTINITIALIZE: {
  97. connect("visibility_changed", callable_mp(this, &CreditsRoll::_visibility_changed));
  98. } break;
  99. case NOTIFICATION_TRANSLATION_CHANGED: {
  100. if (project_manager) {
  101. project_manager->set_text(TTR("Project Manager", "Job Title"));
  102. }
  103. } break;
  104. case NOTIFICATION_INTERNAL_PROCESS: {
  105. const Vector2 pos = content->get_position();
  106. if (pos.y < -content->get_size().y - 30) {
  107. hide(); // No more credits left, show's over.
  108. break;
  109. }
  110. if (Input::get_singleton()->is_mouse_button_pressed(MouseButton::RIGHT) || Input::get_singleton()->is_action_pressed(SNAME("ui_cancel"))) {
  111. hide();
  112. break;
  113. }
  114. bool lmb = Input::get_singleton()->is_mouse_button_pressed(MouseButton::LEFT);
  115. if (!mouse_enabled && !lmb) {
  116. // Makes sure that the initial double click does not speed up text.
  117. mouse_enabled = true;
  118. }
  119. if ((mouse_enabled && lmb) || Input::get_singleton()->is_action_pressed(SNAME("ui_accept"))) {
  120. content->set_position(Vector2(pos.x, pos.y - 2000 * get_process_delta_time()));
  121. } else {
  122. content->set_position(Vector2(pos.x, pos.y - 100 * get_process_delta_time()));
  123. }
  124. } break;
  125. }
  126. }
  127. void CreditsRoll::roll_credits() {
  128. if (!project_manager) {
  129. font_size_normal = EditorNode::get_singleton()->get_editor_theme()->get_font_size("main_size", EditorStringName(EditorFonts)) * 2;
  130. font_size_header = font_size_normal + 10 * EDSCALE;
  131. font_size_big_header = font_size_header + 20 * EDSCALE;
  132. bold_font = EditorNode::get_singleton()->get_editor_theme()->get_font("bold", EditorStringName(EditorFonts));
  133. {
  134. const Ref<Texture2D> logo_texture = EditorNode::get_singleton()->get_editor_theme()->get_icon("Logo", EditorStringName(EditorIcons));
  135. TextureRect *logo = memnew(TextureRect);
  136. logo->set_custom_minimum_size(Vector2(0, logo_texture->get_height() * 3));
  137. logo->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED);
  138. logo->set_texture(logo_texture);
  139. content->add_child(logo);
  140. }
  141. _create_label(TTRC("Credits"), LabelSize::BIG_HEADER);
  142. _create_nothing();
  143. _create_label(TTRC("Project Founders"), LabelSize::HEADER);
  144. _create_label(_build_string(AUTHORS_FOUNDERS));
  145. _create_nothing();
  146. _create_label(TTRC("Lead Developer"), LabelSize::HEADER);
  147. _create_label(_build_string(AUTHORS_LEAD_DEVELOPERS));
  148. _create_nothing();
  149. project_manager = _create_label(TTR("Project Manager", "Job Title"), LabelSize::HEADER);
  150. project_manager->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  151. _create_label(_build_string(AUTHORS_PROJECT_MANAGERS));
  152. _create_nothing();
  153. _create_label(TTRC("Developers"), LabelSize::HEADER);
  154. _create_label(_build_string(AUTHORS_DEVELOPERS));
  155. _create_nothing();
  156. _create_label(TTRC("Patrons"), LabelSize::HEADER);
  157. _create_label(_build_string(DONORS_PATRONS));
  158. _create_nothing();
  159. _create_label(TTRC("Platinum Sponsors"), LabelSize::HEADER);
  160. _create_label(_build_string(DONORS_SPONSORS_PLATINUM));
  161. _create_nothing();
  162. _create_label(TTRC("Gold Sponsors"), LabelSize::HEADER);
  163. _create_label(_build_string(DONORS_SPONSORS_GOLD));
  164. _create_nothing();
  165. _create_label(TTRC("Silver Sponsors"), LabelSize::HEADER);
  166. _create_label(_build_string(DONORS_SPONSORS_SILVER));
  167. _create_nothing();
  168. _create_label(TTRC("Diamond Members"), LabelSize::HEADER);
  169. _create_label(_build_string(DONORS_MEMBERS_DIAMOND));
  170. _create_nothing();
  171. _create_label(TTRC("Titanium Members"), LabelSize::HEADER);
  172. _create_label(_build_string(DONORS_MEMBERS_TITANIUM));
  173. _create_nothing();
  174. _create_label(TTRC("Platinum Members"), LabelSize::HEADER);
  175. _create_label(_build_string(DONORS_MEMBERS_PLATINUM));
  176. _create_nothing();
  177. _create_label(TTRC("Gold Members"), LabelSize::HEADER);
  178. _create_label(_build_string(DONORS_MEMBERS_GOLD));
  179. _create_nothing();
  180. _create_label(String::utf8(GODOT_LICENSE_TEXT));
  181. _create_nothing(400 * EDSCALE);
  182. _create_label(TTRC("Thank you for choosing Godot Engine!"), LabelSize::BIG_HEADER);
  183. }
  184. // Needs to be set here, so it stays centered even if the window is resized.
  185. content->set_anchors_and_offsets_preset(Control::PRESET_VCENTER_WIDE);
  186. Window *root = get_tree()->get_root();
  187. content->set_position(Vector2(content->get_position().x, root->get_size().y + 30));
  188. set_process_internal(true);
  189. set_process_input(true);
  190. }
  191. CreditsRoll::CreditsRoll() {
  192. ColorRect *background = memnew(ColorRect);
  193. background->set_color(Color(0, 0, 0, 1));
  194. background->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
  195. add_child(background);
  196. content = memnew(VBoxContainer);
  197. add_child(content);
  198. }