diff --git a/editor/gui/editor_motion.cpp b/editor/gui/editor_motion.cpp index 91453189..d26b8d0a 100644 --- a/editor/gui/editor_motion.cpp +++ b/editor/gui/editor_motion.cpp @@ -4,8 +4,8 @@ #include "editor_motion.h" #include "core/object/callable_mp.h" +#include "core/math/random_pcg.h" #include "core/os/os.h" -#include "core/version.h" #include "editor/editor_interface.h" #include "editor/editor_node.h" #include "editor/editor_string_names.h" @@ -22,6 +22,7 @@ #include "scene/main/scene_tree.h" #include "scene/main/window.h" #include "scene/resources/dpi_texture.h" +#include "scene/resources/image_texture.h" #include "scene/resources/style_box_flat.h" #include "servers/display/display_server.h" @@ -29,10 +30,6 @@ namespace { // The intro's moments, in seconds. constexpr double LOGO_IN = 0.15; constexpr double LOGO_IN_END = 0.75; -constexpr double LINE_IN = 0.5; -constexpr double LINE_IN_END = 1.0; -constexpr double VERSION_IN = 0.75; -constexpr double VERSION_IN_END = 1.1; constexpr double SHORTEST = 1.7; // It stays at least this long, unless skipped. constexpr double LONGEST = 8.0; // And leaves by then even if the level is still loading. constexpr double LEAVE = 0.55; @@ -60,6 +57,26 @@ Ref editor_logo(float p_scale) { } return Ref(); } + +// A soft round glow: gold fading out smoothly with the distance. The alpha carries a little noise, +// so the fade has no visible steps even where it changes by less than one level per pixel. +Ref make_glow() { + const int size = 512; + Ref image = Image::create_empty(size, size, false, Image::FORMAT_RGBA8); + RandomPCG rng(1); + for (int y = 0; y < size; y++) { + for (int x = 0; x < size; x++) { + const float dx = (x + 0.5f) / size * 2.0f - 1.0f; + const float dy = (y + 0.5f) / size * 2.0f - 1.0f; + const float d = MIN(1.0f, Math::sqrt(dx * dx + dy * dy)); + const float fall = (1.0f - d) * (1.0f - d); + const float noise = rng.randf() - rng.randf(); // Triangular, +-1 level. + const float a = CLAMP(Math::round(0.11f * fall * 255.0f + noise * 0.5f), 0.0f, 255.0f) / 255.0f; + image->set_pixel(x, y, Color(GOLD.r, GOLD.g, GOLD.b, d >= 1.0f ? 0.0f : a)); + } + } + return ImageTexture::create_from_image(image); +} } // namespace // ---- The intro ---------------------------------------------------------------------------------- @@ -74,6 +91,46 @@ double EditorIntro::_now() const { return clock; } +// Everything on the intro is sized from the window, so it keeps its proportions from a small window to a big one. +float EditorIntro::_unit() const { + return MAX((float)EDSCALE, get_size().y / 720.0f); +} + +// Follows the progress dialog: new text fades in, and the last text fades out a moment after the dialog goes quiet. +double EditorIntro::_loading_alpha(double p_now) { + const String current = leave_at < 0 && ProgressDialog::get_singleton() ? ProgressDialog::get_singleton()->get_state_text() : String(); + if (!current.is_empty()) { + if (current != loading_text) { + loading_text = current; + loading_since = p_now; + } + loading_seen = p_now; + } + if (loading_text.is_empty()) { + return 0.0; + } + const double fade_out = 1.0 - phase(p_now, loading_seen + 1.0, loading_seen + 1.4); + if (fade_out <= 0.0 || leave_at >= 0) { + loading_text = String(); + return 0.0; + } + return ease_out(phase(p_now, loading_since, loading_since + 0.25)) * fade_out; +} + +float EditorIntro::_logo_width() const { + const Size2 size = get_size(); + return MIN(size.x * 0.5f, size.y * 0.9f); +} + +void EditorIntro::_update_logo() { + // Sharp at any size: the logo is drawn from its SVG at the size it is shown. + const float width = _logo_width(); + if (width > 1.0f && !Math::is_equal_approx(width, logo_width)) { + logo_width = width; + logo = editor_logo(width / 2039.0f); // The README's logo. + } +} + void EditorIntro::_finish() { if (leave_at < 0 || leave_at > _now()) { leave_at = MAX(_now(), LOGO_IN_END * 0.5); @@ -99,8 +156,8 @@ void EditorIntro::input(const Ref &p_event) { void EditorIntro::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { - // Sharp at any size: the logo is drawn from its SVG at the size it is shown. - logo = editor_logo(get_size().x * 0.5f / 2039.0f); // The README's logo, half the editor wide. + glow_texture = make_glow(); + _update_logo(); set_process(true); set_process_input(true); if (ProgressDialog::get_singleton()) { @@ -108,6 +165,10 @@ void EditorIntro::_notification(int p_what) { } } break; + case NOTIFICATION_RESIZED: { + _update_logo(); + } break; + case NOTIFICATION_EXIT_TREE: { if (ProgressDialog::get_singleton()) { ProgressDialog::get_singleton()->set_quiet(false); @@ -151,11 +212,11 @@ void EditorIntro::_notification(int p_what) { draw_rect(Rect2(Vector2(), size), Color(COAL, alpha)); - // A warm glow that breathes in behind the logo. + // A warm glow that breathes in behind the logo, and keeps breathing slowly. const double glow = ease_out(phase(t, 0.0, 1.2)); - for (int i = 6; i >= 1; i--) { - const float r = size.y * (0.12 + 0.07 * i) * (0.85 + 0.15 * glow); - draw_circle(center, r, Color(GOLD, 0.022 * glow * alpha * (7 - i) / 6.0), true, -1, true); + if (glow_texture.is_valid()) { + const float r = size.y * 0.56f * (0.85f + 0.15f * glow) * (1.0f + 0.025f * Math::sin(t * 1.4)); + draw_texture_rect(glow_texture, Rect2(center - Vector2(r, r), Vector2(2 * r, 2 * r)), false, Color(1, 1, 1, glow * alpha)); } if (logo.is_null()) { @@ -165,38 +226,21 @@ void EditorIntro::_notification(int p_what) { const double in = ease_out(phase(t, LOGO_IN, LOGO_IN_END)); const float grow = 0.94 + 0.06 * in + 0.08 * gone; const Size2 logo_size = logo->get_size() * grow; - const Vector2 logo_pos = center - logo_size / 2 + Vector2(0, -size.y * 0.04 + 18 * EDSCALE * (1.0 - in)); + const float unit = _unit(); + const Vector2 logo_pos = center - logo_size / 2 + Vector2(0, 18 * unit * (1.0 - in)); // Dead centre. draw_texture_rect(logo, Rect2(logo_pos, logo_size), false, Color(1, 1, 1, in * alpha)); - // A gold line opens out from the middle under the logo. - const double line = ease_in_out(phase(t, LINE_IN, LINE_IN_END)); - const float line_y = logo_pos.y + logo_size.y + 20 * EDSCALE; - const float half = logo_size.x * 0.4 * line; - const int pieces = 24; - for (int i = 0; i < pieces; i++) { - // Brightest in the middle, fading out to its ends. - const float a = 1.0 - Math::abs((i + 0.5f) / pieces * 2.0f - 1.0f); - const float x0 = center.x - half + (2 * half) * i / pieces; - draw_rect(Rect2(x0, line_y, 2 * half / pieces + 0.5f, Math::round(2 * EDSCALE)), Color(GOLD, a * alpha * line)); - } - - // The version fades in, quietly, under the line. - const double version_in = ease_out(phase(t, VERSION_IN, VERSION_IN_END)); - if (version_in > 0) { - const Ref main = get_theme_font(SNAME("main"), EditorStringName(EditorFonts)); - const int small = Math::round(12 * EDSCALE); - const String version = OPENRAC_EDITOR_VERSION; - const float vw = main->get_string_size(version, HORIZONTAL_ALIGNMENT_LEFT, -1, small).x; - draw_string(main, Vector2(center.x - vw / 2, line_y + (30 + 6 * (1.0 - version_in)) * EDSCALE), version, HORIZONTAL_ALIGNMENT_LEFT, -1, small, Color(0.7, 0.67, 0.6, 0.8 * alpha * version_in)); - } - - // What is loading, quietly at the bottom. - const String loading = ProgressDialog::get_singleton() && leave_at < 0 ? ProgressDialog::get_singleton()->get_state_text() : String(); - if (!loading.is_empty()) { + // What is loading right now, small in the bottom right corner. The last thing stays a moment, + // so quick steps can still be read. + const double text_alpha = _loading_alpha(t); + if (text_alpha > 0.0) { const Ref main = get_theme_font(SNAME("main"), EditorStringName(EditorFonts)); - const int small = Math::round(12 * EDSCALE); - const float lw = main->get_string_size(loading, HORIZONTAL_ALIGNMENT_LEFT, -1, small).x; - draw_string(main, Vector2(center.x - lw / 2, size.y - 40 * EDSCALE), loading, HORIZONTAL_ALIGNMENT_LEFT, -1, small, Color(0.7, 0.67, 0.6, 0.6 * alpha * in)); + const int small = Math::round(16 * unit); + const float margin = 36 * unit; + const float max_width = size.x * 0.5f; + const float lw = MIN(max_width, main->get_string_size(loading_text, HORIZONTAL_ALIGNMENT_LEFT, -1, small).x); + const float rise = 6 * unit * (1.0 - text_alpha); + draw_string(main, Vector2(size.x - margin - lw, size.y - margin + rise), loading_text, HORIZONTAL_ALIGNMENT_LEFT, lw, small, Color(0.78, 0.74, 0.66, 0.85 * alpha * text_alpha)); } } break; } diff --git a/editor/gui/editor_motion.h b/editor/gui/editor_motion.h index 8f09d270..cebb4aa7 100644 --- a/editor/gui/editor_motion.h +++ b/editor/gui/editor_motion.h @@ -7,6 +7,7 @@ #include "scene/main/node.h" class DPITexture; +class ImageTexture; class TabContainer; class Window; @@ -17,12 +18,21 @@ class EditorIntro : public Control { GDCLASS(EditorIntro, Control); Ref logo; + Ref glow_texture; + float logo_width = 0.0f; + String loading_text; // What is shown in the corner. + double loading_since = 0.0; + double loading_seen = 0.0; uint64_t last_usec = 0; double clock = 0.0; // Its own time: a long freeze while loading does not skip the show. double leave_at = -1.0; // On its clock; -1 until the editor is ready. double _now() const; void _finish(); + float _unit() const; + double _loading_alpha(double p_now); + float _logo_width() const; + void _update_logo(); protected: void _notification(int p_what);