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