Skip to content

Commit 099d491

Browse files
committed
Merge pull request #90092 from KoBeWi/casually_adding_credits_roll_to_a_GAME_engine
Add credits roll
2 parents eb6e8e5 + 336bf52 commit 099d491

File tree

4 files changed

+351
-5
lines changed

4 files changed

+351
-5
lines changed

editor/credits_roll.cpp

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
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+
31+
#include "credits_roll.h"
32+
33+
#include "core/authors.gen.h"
34+
#include "core/donors.gen.h"
35+
#include "core/input/input.h"
36+
#include "core/license.gen.h"
37+
#include "core/string/string_builder.h"
38+
#include "editor/editor_string_names.h"
39+
#include "editor/themes/editor_scale.h"
40+
#include "scene/gui/box_container.h"
41+
#include "scene/gui/color_rect.h"
42+
#include "scene/gui/label.h"
43+
#include "scene/gui/texture_rect.h"
44+
45+
Label *CreditsRoll::_create_label(const String &p_with_text, LabelSize p_size) {
46+
Label *label = memnew(Label);
47+
label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
48+
label->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
49+
label->set_text(p_with_text);
50+
51+
switch (p_size) {
52+
case LabelSize::NORMAL: {
53+
label->add_theme_font_size_override(SceneStringName(font_size), font_size_normal);
54+
} break;
55+
56+
case LabelSize::HEADER: {
57+
label->add_theme_font_size_override(SceneStringName(font_size), font_size_header);
58+
label->add_theme_font_override(SceneStringName(font), bold_font);
59+
} break;
60+
61+
case LabelSize::BIG_HEADER: {
62+
label->add_theme_font_size_override(SceneStringName(font_size), font_size_big_header);
63+
label->add_theme_font_override(SceneStringName(font), bold_font);
64+
} break;
65+
}
66+
content->add_child(label);
67+
return label;
68+
}
69+
70+
void CreditsRoll::_create_nothing(int p_size) {
71+
if (p_size == -1) {
72+
p_size = 30 * EDSCALE;
73+
}
74+
Control *c = memnew(Control);
75+
c->set_custom_minimum_size(Vector2(0, p_size));
76+
content->add_child(c);
77+
}
78+
79+
String CreditsRoll::_build_string(const char *const *p_from) const {
80+
StringBuilder sb;
81+
82+
while (*p_from) {
83+
sb.append(String::utf8(*p_from));
84+
sb.append("\n");
85+
p_from++;
86+
}
87+
return sb.as_string();
88+
}
89+
90+
void CreditsRoll::_notification(int p_what) {
91+
switch (p_what) {
92+
case NOTIFICATION_VISIBILITY_CHANGED: {
93+
if (!is_visible()) {
94+
set_process_internal(false);
95+
mouse_enabled = false;
96+
}
97+
} break;
98+
99+
case NOTIFICATION_TRANSLATION_CHANGED: {
100+
if (project_manager) {
101+
project_manager->set_text(TTR("Project Manager", "Job Title"));
102+
}
103+
} break;
104+
105+
case NOTIFICATION_WM_GO_BACK_REQUEST: {
106+
hide();
107+
} break;
108+
109+
case NOTIFICATION_INTERNAL_PROCESS: {
110+
const Vector2 pos = content->get_position();
111+
if (pos.y < -content->get_size().y - 30) {
112+
hide();
113+
break;
114+
}
115+
116+
if (Input::get_singleton()->is_mouse_button_pressed(MouseButton::RIGHT)) {
117+
hide();
118+
break;
119+
}
120+
121+
bool lmb = Input::get_singleton()->is_mouse_button_pressed(MouseButton::LEFT);
122+
if (!mouse_enabled && !lmb) {
123+
// Makes sure that the initial double click does not speed up text.
124+
mouse_enabled = true;
125+
}
126+
127+
if ((mouse_enabled && lmb) || Input::get_singleton()->is_action_pressed(SNAME("ui_accept"))) {
128+
content->set_position(Vector2(pos.x, pos.y - 2000 * get_process_delta_time()));
129+
} else {
130+
content->set_position(Vector2(pos.x, pos.y - 100 * get_process_delta_time()));
131+
}
132+
} break;
133+
}
134+
}
135+
136+
void CreditsRoll::roll_credits() {
137+
if (!project_manager) {
138+
font_size_normal = get_theme_font_size("main_size", EditorStringName(EditorFonts)) * 2;
139+
font_size_header = font_size_normal + 10 * EDSCALE;
140+
font_size_big_header = font_size_header + 20 * EDSCALE;
141+
bold_font = get_theme_font("bold", EditorStringName(EditorFonts));
142+
143+
{
144+
const Ref<Texture2D> logo_texture = get_editor_theme_icon("Logo");
145+
146+
TextureRect *logo = memnew(TextureRect);
147+
logo->set_custom_minimum_size(Vector2(0, logo_texture->get_height() * 3));
148+
logo->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED);
149+
logo->set_texture(logo_texture);
150+
content->add_child(logo);
151+
}
152+
153+
_create_label(TTRC("Credits"), LabelSize::BIG_HEADER);
154+
155+
_create_nothing();
156+
157+
_create_label(TTRC("Project Founders"), LabelSize::HEADER);
158+
_create_label(_build_string(AUTHORS_FOUNDERS));
159+
160+
_create_nothing();
161+
162+
_create_label(TTRC("Lead Developer"), LabelSize::HEADER);
163+
_create_label(_build_string(AUTHORS_LEAD_DEVELOPERS));
164+
165+
_create_nothing();
166+
167+
project_manager = _create_label(TTR("Project Manager", "Job Title"), LabelSize::HEADER);
168+
_create_label(_build_string(AUTHORS_PROJECT_MANAGERS));
169+
170+
_create_nothing();
171+
172+
_create_label(TTRC("Developers"), LabelSize::HEADER);
173+
_create_label(_build_string(AUTHORS_DEVELOPERS));
174+
175+
_create_nothing();
176+
177+
_create_label(TTRC("Patrons"), LabelSize::HEADER);
178+
_create_label(_build_string(DONORS_PATRONS));
179+
180+
_create_nothing();
181+
182+
_create_label(TTRC("Platinum Sponsors"), LabelSize::HEADER);
183+
_create_label(_build_string(DONORS_SPONSORS_PLATINUM));
184+
185+
_create_nothing();
186+
187+
_create_label(TTRC("Gold Sponsors"), LabelSize::HEADER);
188+
_create_label(_build_string(DONORS_SPONSORS_GOLD));
189+
190+
_create_nothing();
191+
192+
_create_label(TTRC("Silver Sponsors"), LabelSize::HEADER);
193+
_create_label(_build_string(DONORS_SPONSORS_SILVER));
194+
195+
_create_nothing();
196+
197+
_create_label(TTRC("Diamond Members"), LabelSize::HEADER);
198+
_create_label(_build_string(DONORS_MEMBERS_DIAMOND));
199+
200+
_create_nothing();
201+
202+
_create_label(TTRC("Titanium Members"), LabelSize::HEADER);
203+
_create_label(_build_string(DONORS_MEMBERS_TITANIUM));
204+
205+
_create_nothing();
206+
207+
_create_label(TTRC("Platinum Members"), LabelSize::HEADER);
208+
_create_label(_build_string(DONORS_MEMBERS_PLATINUM));
209+
210+
_create_nothing();
211+
212+
_create_label(TTRC("Gold Members"), LabelSize::HEADER);
213+
_create_label(_build_string(DONORS_MEMBERS_GOLD));
214+
215+
_create_nothing();
216+
_create_label(String::utf8(GODOT_LICENSE_TEXT));
217+
218+
_create_nothing(400 * EDSCALE);
219+
_create_label(TTRC("Thank you for choosing Godot Engine!"), LabelSize::BIG_HEADER);
220+
}
221+
222+
Window *root = get_tree()->get_root();
223+
content->set_position(Vector2(content->get_position().x, root->get_size().y + 30));
224+
225+
set_position(root->get_position());
226+
set_size(root->get_size());
227+
228+
popup();
229+
set_process_internal(true);
230+
}
231+
232+
CreditsRoll::CreditsRoll() {
233+
set_wrap_controls(false);
234+
235+
{
236+
ColorRect *background = memnew(ColorRect);
237+
background->set_color(Color(0, 0, 0, 1));
238+
background->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
239+
add_child(background);
240+
}
241+
242+
content = memnew(VBoxContainer);
243+
content->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
244+
add_child(content);
245+
}

editor/credits_roll.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**************************************************************************/
2+
/* credits_roll.h */
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+
31+
#pragma once
32+
33+
#include "scene/gui/popup.h"
34+
35+
class Label;
36+
class VBoxContainer;
37+
class Font;
38+
39+
class CreditsRoll : public Popup {
40+
GDCLASS(CreditsRoll, Popup);
41+
42+
enum class LabelSize {
43+
NORMAL,
44+
HEADER,
45+
BIG_HEADER,
46+
};
47+
48+
int font_size_normal = 0;
49+
int font_size_header = 0;
50+
int font_size_big_header = 0;
51+
Ref<Font> bold_font;
52+
53+
bool mouse_enabled = false;
54+
VBoxContainer *content = nullptr;
55+
Label *project_manager = nullptr;
56+
57+
Label *_create_label(const String &p_with_text, LabelSize p_size = LabelSize::NORMAL);
58+
void _create_nothing(int p_size = -1);
59+
String _build_string(const char *const *p_from) const;
60+
61+
protected:
62+
void _notification(int p_what);
63+
64+
public:
65+
void roll_credits();
66+
67+
CreditsRoll();
68+
};

0 commit comments

Comments
 (0)