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