From 748e2e980e5fbb87f79083c507560d648fce9dff Mon Sep 17 00:00:00 2001 From: Nab <22328803+NABN00B@users.noreply.github.com> Date: Mon, 31 Mar 2025 20:59:28 +0200 Subject: [PATCH] Add bouncing icon background animation --- Core/ConfigValues.h | 1 + UI/GameSettingsScreen.cpp | 2 +- UI/MiscScreens.cpp | 100 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 1 deletion(-) diff --git a/Core/ConfigValues.h b/Core/ConfigValues.h index 065ad069f1..73691206bb 100644 --- a/Core/ConfigValues.h +++ b/Core/ConfigValues.h @@ -150,6 +150,7 @@ enum class BackgroundAnimation { RECENT_GAMES = 2, WAVE = 3, MOVING_BACKGROUND = 4, + BOUNCING_ICON = 5, }; // iOS only diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index b41fc853ef..b652116246 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1164,7 +1164,7 @@ void GameSettingsScreen::CreateSystemSettings(UI::ViewGroup *systemSettings) { systemSettings->Add(new PopupMultiChoice(&g_Config.iNotificationPos, sy->T("Notification screen position"), positions, -1, ARRAY_SIZE(positions), I18NCat::DIALOG, screenManager())); - static const char *backgroundAnimations[] = { "No animation", "Floating symbols", "Recent games", "Waves", "Moving background" }; + static const char *backgroundAnimations[] = { "No animation", "Floating symbols", "Recent games", "Waves", "Moving background", "Bouncing icon" }; systemSettings->Add(new PopupMultiChoice(&g_Config.iBackgroundAnimation, sy->T("UI background animation"), backgroundAnimations, 0, ARRAY_SIZE(backgroundAnimations), I18NCat::SYSTEM, screenManager())); PopupMultiChoiceDynamic *theme = systemSettings->Add(new PopupMultiChoiceDynamic(&g_Config.sThemeName, sy->T("Theme"), GetThemeInfoNames(), I18NCat::THEMES, screenManager())); diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index 8129c51217..c7f4183191 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -18,6 +18,7 @@ #include "ppsspp_config.h" #include +#include #include #include "Common/Render/DrawBuffer.h" @@ -288,6 +289,102 @@ private: double nextT_ = -INTERVAL; }; +class BouncingIconAnimation : public Animation { + public: + void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) override { + dc.Flush(); + dc.Begin(); + + // Handle change in resolution. + float xres = dc.GetBounds().w; + float yres = dc.GetBounds().h; + if (last_xres != xres || last_yres != yres) { + Recalculate(xres, yres); + } + + // Draw the image. + float xpos = xbase + dc.GetBounds().x; + float ypos = ybase + dc.GetBounds().y; + ImageID icon = !color_ix && System_GetPropertyBool(SYSPROP_APP_GOLD) ? ImageID("I_ICONGOLD") : ImageID("I_ICON"); + ui_draw2d.DrawImage(icon, xpos, ypos, scale, colors[color_ix], ALIGN_CENTER); + dc.Flush(); + + // Switch direction if within border. + bool should_recolor = true; + if (xbase > xres - border || xbase < border) { + xspeed *= -1.0f; + RandomizeColor(); + should_recolor = false; + } + + if (ybase > yres - border || ybase < border) { + yspeed *= -1.0f; + + if (should_recolor) { + RandomizeColor(); + } + } + + // Place to border if out of bounds. + if (xbase > xres - border) xbase = xres - border; + else if (xbase < border) xbase = border; + if (ybase > yres - border) ybase = yres - border; + else if (ybase < border) ybase = border; + + // Update location. + xbase += xspeed; + ybase += yspeed; + } + + private: + static constexpr int COLOR_COUNT = 11; + static constexpr Color colors[COLOR_COUNT] = { 0xFFFFFFFF, 0xFFFFFF00, 0xFFFF0000, 0xFF00FF00, 0xFF00FF00, + 0xFF00FFFF, 0xFFFF00FF, 0xFF4111D1, 0xFF3577F3, 0xFFAA77FF, 0xFF623B84 }; + + float xbase = 0.0f; + float ybase = 0.0f; + float last_xres = 0.0f; + float last_yres = 0.0f; + float xspeed = 1.0f; + float yspeed = 1.0f; + float scale = 1.0f; + float border = 35.0f; + int color_ix = 0; + int last_color_ix = -1; + GMRng rng; + + void Recalculate(int xres, int yres) { + // First calculation. + if (last_color_ix == -1) { + xbase = xres / 2.0f; + ybase = yres / 2.0f; + last_color_ix = 0; + + // Determine initial direction. + if ((int)(rng.F() * xres) % 2) xspeed *= -1.0f; + if ((int)(rng.F() * yres) % 2) yspeed *= -1.0f; + } + + // Scale certain attributes to resolution. + scale = std::min(xres, yres) / 400.0f; + float speed = scale < 2.5f ? scale * 0.58f : scale * 0.46f; + xspeed = std::signbit(xspeed) ? speed * -1.0f : speed; + yspeed = std::signbit(yspeed) ? speed * -1.0f : speed; + border = 35.0f * scale; + + last_xres = xres; + last_yres = yres; + } + + void RandomizeColor() { + do { + color_ix = (int)(rng.F() * xbase) % COLOR_COUNT; + } while (color_ix == last_color_ix); + + last_color_ix = color_ix; + } +}; + // TODO: Add more styles. Remember to add to the enum in ConfigValues.h and the selector in GameSettings too. static BackgroundAnimation g_CurBackgroundAnimation = BackgroundAnimation::OFF; @@ -334,6 +431,9 @@ void DrawBackground(UIContext &dc, float alpha, float x, float y, float z) { case BackgroundAnimation::MOVING_BACKGROUND: g_Animation.reset(new MovingBackground()); break; + case BackgroundAnimation::BOUNCING_ICON: + g_Animation.reset(new BouncingIconAnimation()); + break; default: g_Animation.reset(nullptr); }