Skip to content

Commit f8c251a

Browse files
committed
Fix various problems with the credits roll
1 parent 7ed0b61 commit f8c251a

File tree

4 files changed

+54
-34
lines changed

4 files changed

+54
-34
lines changed

editor/gui/credits_roll.cpp

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "core/input/input.h"
3636
#include "core/license.gen.h"
3737
#include "core/string/string_builder.h"
38+
#include "editor/editor_node.h"
3839
#include "editor/editor_string_names.h"
3940
#include "editor/themes/editor_scale.h"
4041
#include "scene/gui/box_container.h"
@@ -88,13 +89,23 @@ String CreditsRoll::_build_string(const char *const *p_from) const {
8889
return sb.as_string();
8990
}
9091

92+
void CreditsRoll::_visibility_changed() {
93+
if (!is_visible()) {
94+
mouse_enabled = false;
95+
set_process_internal(false);
96+
set_process_input(false);
97+
}
98+
}
99+
100+
void CreditsRoll::input(const Ref<InputEvent> &p_event) {
101+
// Block inputs from going elsewhere while the credits roll.
102+
get_tree()->get_root()->set_input_as_handled();
103+
}
104+
91105
void CreditsRoll::_notification(int p_what) {
92106
switch (p_what) {
93-
case NOTIFICATION_VISIBILITY_CHANGED: {
94-
if (!is_visible()) {
95-
set_process_internal(false);
96-
mouse_enabled = false;
97-
}
107+
case NOTIFICATION_POSTINITIALIZE: {
108+
connect("visibility_changed", callable_mp(this, &CreditsRoll::_visibility_changed));
98109
} break;
99110

100111
case NOTIFICATION_TRANSLATION_CHANGED: {
@@ -103,18 +114,14 @@ void CreditsRoll::_notification(int p_what) {
103114
}
104115
} break;
105116

106-
case NOTIFICATION_WM_GO_BACK_REQUEST: {
107-
hide();
108-
} break;
109-
110117
case NOTIFICATION_INTERNAL_PROCESS: {
111118
const Vector2 pos = content->get_position();
112119
if (pos.y < -content->get_size().y - 30) {
113-
hide();
120+
hide(); // No more credits left, show's over.
114121
break;
115122
}
116123

117-
if (Input::get_singleton()->is_mouse_button_pressed(MouseButton::RIGHT)) {
124+
if (Input::get_singleton()->is_mouse_button_pressed(MouseButton::RIGHT) || Input::get_singleton()->is_action_pressed(SNAME("ui_cancel"))) {
118125
hide();
119126
break;
120127
}
@@ -136,13 +143,13 @@ void CreditsRoll::_notification(int p_what) {
136143

137144
void CreditsRoll::roll_credits() {
138145
if (!project_manager) {
139-
font_size_normal = get_theme_font_size("main_size", EditorStringName(EditorFonts)) * 2;
146+
font_size_normal = EditorNode::get_singleton()->get_editor_theme()->get_font_size("main_size", EditorStringName(EditorFonts)) * 2;
140147
font_size_header = font_size_normal + 10 * EDSCALE;
141148
font_size_big_header = font_size_header + 20 * EDSCALE;
142-
bold_font = get_theme_font("bold", EditorStringName(EditorFonts));
149+
bold_font = EditorNode::get_singleton()->get_editor_theme()->get_font("bold", EditorStringName(EditorFonts));
143150

144151
{
145-
const Ref<Texture2D> logo_texture = get_editor_theme_icon("Logo");
152+
const Ref<Texture2D> logo_texture = EditorNode::get_singleton()->get_editor_theme()->get_icon("Logo", EditorStringName(EditorIcons));
146153

147154
TextureRect *logo = memnew(TextureRect);
148155
logo->set_custom_minimum_size(Vector2(0, logo_texture->get_height() * 3));
@@ -220,28 +227,22 @@ void CreditsRoll::roll_credits() {
220227
_create_nothing(400 * EDSCALE);
221228
_create_label(TTRC("Thank you for choosing Godot Engine!"), LabelSize::BIG_HEADER);
222229
}
230+
// Needs to be set here, so it stays centered even if the window is resized.
231+
content->set_anchors_and_offsets_preset(Control::PRESET_VCENTER_WIDE);
223232

224233
Window *root = get_tree()->get_root();
225234
content->set_position(Vector2(content->get_position().x, root->get_size().y + 30));
226235

227-
set_position(root->get_position());
228-
set_size(root->get_size());
229-
230-
popup();
231236
set_process_internal(true);
237+
set_process_input(true);
232238
}
233239

234240
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-
}
241+
ColorRect *background = memnew(ColorRect);
242+
background->set_color(Color(0, 0, 0, 1));
243+
background->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
244+
add_child(background);
243245

244246
content = memnew(VBoxContainer);
245-
content->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
246247
add_child(content);
247248
}

editor/gui/credits_roll.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030

3131
#pragma once
3232

33-
#include "scene/gui/popup.h"
33+
#include "scene/main/canvas_layer.h"
3434

3535
class Label;
3636
class VBoxContainer;
3737
class Font;
3838

39-
class CreditsRoll : public Popup {
40-
GDCLASS(CreditsRoll, Popup);
39+
class CreditsRoll : public CanvasLayer {
40+
GDCLASS(CreditsRoll, CanvasLayer);
4141

4242
enum class LabelSize {
4343
NORMAL,
@@ -57,6 +57,9 @@ class CreditsRoll : public Popup {
5757
Label *_create_label(const String &p_with_text, LabelSize p_size = LabelSize::NORMAL);
5858
void _create_nothing(int p_size = -1);
5959
String _build_string(const char *const *p_from) const;
60+
void _visibility_changed();
61+
62+
virtual void input(const Ref<InputEvent> &p_event) override;
6063

6164
protected:
6265
void _notification(int p_what);

editor/gui/editor_about.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
#include "editor/editor_node.h"
3737
#include "editor/editor_string_names.h"
3838
#include "editor/gui/credits_roll.h"
39+
#include "editor/gui/editor_toaster.h"
3940
#include "editor/gui/editor_version_button.h"
41+
#include "editor/run/editor_run_bar.h"
4042
#include "editor/themes/editor_scale.h"
4143
#include "scene/gui/item_list.h"
4244
#include "scene/gui/rich_text_label.h"
@@ -103,22 +105,34 @@ void EditorAbout::_license_tree_selected() {
103105
_tpl_text->set_text(selected->get_metadata(0));
104106
}
105107

108+
void EditorAbout::_credits_visibility_changed() {
109+
if (!credits_roll->is_visible()) {
110+
credits_roll->queue_free();
111+
credits_roll = nullptr;
112+
113+
show();
114+
}
115+
}
116+
106117
void EditorAbout::_item_activated(int p_idx, ItemList *p_il) {
107118
const Variant val = p_il->get_item_metadata(p_idx);
108119
if (val.get_type() == Variant::STRING) {
109120
OS::get_singleton()->shell_open(val);
110121
} else {
111-
// Easter egg :D
112-
if (!EditorNode::get_singleton()) {
113-
// Don't allow in Project Manager.
122+
// Easter egg! :D
123+
if (EditorRunBar::get_singleton()->is_playing()) {
124+
// Don't allow if the game is running, as it will look weird if it's embedded.
125+
EditorToaster::get_singleton()->popup_str(TTR("No distractions for this, close that game first."));
114126
return;
115127
}
116128

117129
if (!credits_roll) {
118130
credits_roll = memnew(CreditsRoll);
119-
add_child(credits_roll);
131+
credits_roll->connect("visibility_changed", callable_mp(this, &EditorAbout::_credits_visibility_changed));
132+
get_tree()->get_root()->add_child(credits_roll);
120133
}
121134
credits_roll->roll_credits();
135+
hide();
122136
}
123137
}
124138

@@ -140,6 +154,7 @@ Label *EditorAbout::_create_section(Control *p_parent, const String &p_name, con
140154
il->set_max_columns(p_flags.has_flag(FLAG_SINGLE_COLUMN) ? 1 : 16);
141155
il->add_theme_constant_override("h_separation", 16 * EDSCALE);
142156

157+
// Don't allow the Easter egg in the Project Manager.
143158
if (p_flags.has_flag(FLAG_ALLOW_WEBSITE) || (p_flags.has_flag(FLAG_EASTER_EGG) && EditorNode::get_singleton())) {
144159
Ref<StyleBoxEmpty> empty_stylebox = memnew(StyleBoxEmpty);
145160
il->add_theme_style_override("focus", empty_stylebox);

editor/gui/editor_about.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class EditorAbout : public AcceptDialog {
5454
};
5555

5656
void _license_tree_selected();
57+
void _credits_visibility_changed();
5758
void _item_activated(int p_idx, ItemList *p_il);
5859
void _item_list_resized(ItemList *p_il);
5960
Label *_create_section(Control *p_parent, const String &p_name, const char *const *p_src, BitField<SectionFlags> p_flags = 0);

0 commit comments

Comments
 (0)