Merge pull request #14313 from hrydgard/background-animation

Add a setting for choosing background animation in PPSSPP's menus
This commit is contained in:
Henrik Rydgård 2021-03-24 00:04:57 +01:00 committed by GitHub
commit a37ea1e652
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 77 additions and 40 deletions

View File

@ -494,6 +494,8 @@ static ConfigSetting generalSettings[] = {
#endif
ConfigSetting("InternalScreenRotation", &g_Config.iInternalScreenRotation, ROTATION_LOCKED_HORIZONTAL),
ConfigSetting("BackgroundAnimation", &g_Config.iBackgroundAnimation, 1, true, false),
#if defined(USING_WIN_UI)
ConfigSetting("TopMost", &g_Config.bTopMost, false),
ConfigSetting("WindowX", &g_Config.iWindowX, -1), // -1 tells us to center the window.

View File

@ -38,6 +38,11 @@ enum ChatPositions {
CENTER_RIGHT = 7,
};
enum class BackgroundAnimation {
OFF = 0,
FLOATING_SYMBOLS = 1,
};
namespace http {
class Download;
class Downloader;
@ -239,6 +244,7 @@ public:
bool bShowIDOnGameIcon;
float fGameGridScale;
bool bShowOnScreenMessages;
int iBackgroundAnimation; // enum BackgroundAnimation
// TODO: Maybe move to a separate theme system.
uint32_t uItemStyleFg;

View File

@ -860,9 +860,23 @@ void GameSettingsScreen::CreateViews() {
systemSettingsScroll->Add(systemSettings);
tabHolder->AddTab(ms->T("System"), systemSettingsScroll);
systemSettings->Add(new ItemHeader(sy->T("UI Language"))); // Should be renamed "UI"?
systemSettings->Add(new ItemHeader(sy->T("UI")));
systemSettings->Add(new Choice(dev->T("Language", "Language")))->OnClick.Handle(this, &GameSettingsScreen::OnLanguage);
systemSettings->Add(new CheckBox(&g_Config.bUISound, sy->T("UI Sound")));
const std::string bgPng = GetSysDirectory(DIRECTORY_SYSTEM) + "background.png";
const std::string bgJpg = GetSysDirectory(DIRECTORY_SYSTEM) + "background.jpg";
if (File::Exists(bgPng) || File::Exists(bgJpg)) {
backgroundChoice_ = systemSettings->Add(new Choice(sy->T("Clear UI background")));
} else if (System_GetPropertyBool(SYSPROP_HAS_IMAGE_BROWSER)) {
backgroundChoice_ = systemSettings->Add(new Choice(sy->T("Set UI background...")));
} else {
backgroundChoice_ = nullptr;
}
if (backgroundChoice_ != nullptr) {
backgroundChoice_->OnClick.Handle(this, &GameSettingsScreen::OnChangeBackground);
}
static const char *backgroundAnimations[] = { "No animation", "Floating Symbols" };
systemSettings->Add(new PopupMultiChoice(&g_Config.iBackgroundAnimation, sy->T("UI background animation"), backgroundAnimations, 0, ARRAY_SIZE(backgroundAnimations), sy->GetName(), screenManager()));
systemSettings->Add(new ItemHeader(sy->T("Help the PPSSPP team")));
enableReports_ = Reporting::IsEnabled();
@ -906,18 +920,6 @@ void GameSettingsScreen::CreateViews() {
}
#endif
systemSettings->Add(new CheckBox(&g_Config.bCheckForNewVersion, sy->T("VersionCheck", "Check for new versions of PPSSPP")));
const std::string bgPng = GetSysDirectory(DIRECTORY_SYSTEM) + "background.png";
const std::string bgJpg = GetSysDirectory(DIRECTORY_SYSTEM) + "background.jpg";
if (File::Exists(bgPng) || File::Exists(bgJpg)) {
backgroundChoice_ = systemSettings->Add(new Choice(sy->T("Clear UI background")));
} else if (System_GetPropertyBool(SYSPROP_HAS_IMAGE_BROWSER)) {
backgroundChoice_ = systemSettings->Add(new Choice(sy->T("Set UI background...")));
} else {
backgroundChoice_ = nullptr;
}
if (backgroundChoice_ != nullptr) {
backgroundChoice_->OnClick.Handle(this, &GameSettingsScreen::OnChangeBackground);
}
systemSettings->Add(new Choice(sy->T("Restore Default Settings")))->OnClick.Handle(this, &GameSettingsScreen::OnRestoreDefaultSettings);
systemSettings->Add(new CheckBox(&g_Config.bEnableStateUndo, sy->T("Savestate slot backups")));

View File

@ -73,7 +73,47 @@ static const uint32_t colors[4] = {
static std::unique_ptr<ManagedTexture> bgTexture;
static bool backgroundInited;
class Animation {
public:
virtual ~Animation() {}
virtual void Draw(UIContext &dc, double t, float alpha) = 0;
};
class FloatingSymbolsAnimation : public Animation {
public:
~FloatingSymbolsAnimation() override {}
void Draw(UIContext &dc, double t, float alpha) override {
float xres = dc.GetBounds().w;
float yres = dc.GetBounds().h;
if (xbase[0] == 0.0f || last_xres != xres || last_yres != yres) {
GMRng rng;
for (int i = 0; i < 100; i++) {
xbase[i] = rng.F() * xres;
ybase[i] = rng.F() * yres;
}
last_xres = xres;
last_yres = yres;
}
for (int i = 0; i < 100; i++) {
float x = xbase[i] + dc.GetBounds().x;
float y = ybase[i] + dc.GetBounds().y + 40 * cosf(i * 7.2f + t * 1.3f);
float angle = (float)sin(i + t);
int n = i & 3;
ui_draw2d.DrawImageRotated(symbols[n], x, y, 1.0f, angle, colorAlpha(colors[n], alpha * 0.1f));
}
}
private:
float xbase[100] = { 0 };
float ybase[100] = { 0 };
float last_xres = 0;
float last_yres = 0;
};
// TODO: Add more styles. Remember to add to the enum in Config.cpp and the selector in GameSettings too.
static BackgroundAnimation g_CurBackgroundAnimation = BackgroundAnimation::OFF;
static std::unique_ptr<Animation> g_Animation;
void UIBackgroundInit(UIContext &dc) {
const std::string bgPng = GetSysDirectory(DIRECTORY_SYSTEM) + "background.png";
@ -86,32 +126,22 @@ void UIBackgroundInit(UIContext &dc) {
void UIBackgroundShutdown() {
bgTexture.reset(nullptr);
backgroundInited = false;
g_Animation.reset(nullptr);
}
void DrawBackground(UIContext &dc, float alpha) {
if (!backgroundInited) {
UIBackgroundInit(dc);
backgroundInited = true;
}
if (g_CurBackgroundAnimation != (BackgroundAnimation)g_Config.iBackgroundAnimation) {
g_CurBackgroundAnimation = (BackgroundAnimation)g_Config.iBackgroundAnimation;
static float xbase[100] = {0};
static float ybase[100] = {0};
float xres = dc.GetBounds().w;
float yres = dc.GetBounds().h;
static int last_xres = 0;
static int last_yres = 0;
if (xbase[0] == 0.0f || last_xres != xres || last_yres != yres) {
GMRng rng;
for (int i = 0; i < 100; i++) {
xbase[i] = rng.F() * xres;
ybase[i] = rng.F() * yres;
switch (g_CurBackgroundAnimation) {
case BackgroundAnimation::FLOATING_SYMBOLS:
g_Animation.reset(new FloatingSymbolsAnimation());
break;
default:
g_Animation.reset(nullptr);
}
last_xres = xres;
last_yres = yres;
}
uint32_t bgColor = whiteAlpha(alpha);
if (bgTexture != nullptr) {
@ -135,12 +165,9 @@ void DrawBackground(UIContext &dc, float alpha) {
#else
double t = time_now_d();
#endif
for (int i = 0; i < 100; i++) {
float x = xbase[i] + dc.GetBounds().x;
float y = ybase[i] + dc.GetBounds().y + 40 * cosf(i * 7.2f + t * 1.3f);
float angle = (float)sin(i + t);
int n = i & 3;
ui_draw2d.DrawImageRotated(symbols[n], x, y, 1.0f, angle, colorAlpha(colors[n], alpha * 0.1f));
if (g_Animation) {
g_Animation->Draw(dc, t, alpha);
}
}