CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/UI/MiscScreens.cpp
Views: 1401
// Copyright (c) 2013- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#include "ppsspp_config.h"1819#include <algorithm>20#include <functional>2122#include "Common/Render/DrawBuffer.h"23#include "Common/UI/Context.h"24#include "Common/UI/View.h"25#include "Common/UI/ViewGroup.h"26#include "Common/UI/UI.h"2728#include "Common/System/Display.h"29#include "Common/System/NativeApp.h"30#include "Common/System/System.h"31#include "Common/System/Request.h"32#include "Common/Math/curves.h"33#include "Common/File/VFS/VFS.h"3435#include "Common/Data/Color/RGBAUtil.h"36#include "Common/Data/Encoding/Utf8.h"37#include "Common/Data/Text/I18n.h"38#include "Common/Data/Random/Rng.h"39#include "Common/TimeUtil.h"40#include "Common/File/FileUtil.h"41#include "Common/Render/ManagedTexture.h"4243#include "Core/Config.h"44#include "Core/System.h"45#include "Core/MIPS/JitCommon/JitCommon.h"46#include "Core/HLE/sceUtility.h"47#include "GPU/GPUState.h"48#include "GPU/GPUInterface.h"49#include "GPU/Common/PostShader.h"5051#include "UI/ControlMappingScreen.h"52#include "UI/DisplayLayoutScreen.h"53#include "UI/EmuScreen.h"54#include "UI/GameInfoCache.h"55#include "UI/GameSettingsScreen.h"56#include "UI/MainScreen.h"57#include "UI/MiscScreens.h"58#include "UI/MemStickScreen.h"5960#ifdef _MSC_VER61#pragma execution_character_set("utf-8")62#endif6364static const ImageID symbols[4] = {65ImageID("I_CROSS"),66ImageID("I_CIRCLE"),67ImageID("I_SQUARE"),68ImageID("I_TRIANGLE"),69};7071static const uint32_t colors[4] = {720xC0FFFFFF,730xC0FFFFFF,740xC0FFFFFF,750xC0FFFFFF,76};7778static Draw::Texture *bgTexture;7980class Animation {81public:82virtual ~Animation() {}83virtual void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) = 0;84};8586static constexpr float XFAC = 0.3f;87static constexpr float YFAC = 0.3f;88static constexpr float ZFAC = 0.12f;89static constexpr float XSPEED = 0.05f;90static constexpr float YSPEED = 0.05f;91static constexpr float ZSPEED = 0.1f;9293class MovingBackground : public Animation {94public:95void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) override {96if (!bgTexture)97return;9899dc.Flush();100dc.GetDrawContext()->BindTexture(0, bgTexture);101Bounds bounds = dc.GetBounds();102103x = std::min(std::max(x/bounds.w, 0.0f), 1.0f) * XFAC;104y = std::min(std::max(y/bounds.h, 0.0f), 1.0f) * YFAC;105z = 1.0f + std::max(XFAC, YFAC) + (z-1.0f) * ZFAC;106107lastX_ = abs(x-lastX_) > 0.001f ? x*XSPEED+lastX_*(1.0f-XSPEED) : x;108lastY_ = abs(y-lastY_) > 0.001f ? y*YSPEED+lastY_*(1.0f-YSPEED) : y;109lastZ_ = abs(z-lastZ_) > 0.001f ? z*ZSPEED+lastZ_*(1.0f-ZSPEED) : z;110111float u1 = lastX_/lastZ_;112float v1 = lastY_/lastZ_;113float u2 = (1.0f+lastX_)/lastZ_;114float v2 = (1.0f+lastY_)/lastZ_;115116dc.Draw()->DrawTexRect(bounds, u1, v1, u2, v2, whiteAlpha(alpha));117118dc.Flush();119dc.RebindTexture();120}121122private:123float lastX_ = 0.0f;124float lastY_ = 0.0f;125float lastZ_ = 1.0f + std::max(XFAC, YFAC);126};127128class WaveAnimation : public Animation {129public:130void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) override {131const uint32_t color = colorAlpha(0xFFFFFFFF, alpha * 0.2f);132const float speed = 1.0;133134Bounds bounds = dc.GetBounds();135dc.Flush();136dc.BeginNoTex();137138// 500 is enough for any resolution really. 24 * 500 = 12000 which fits handily in our UI vertex buffer (max 65536 per flush).139const int steps = std::max(20, std::min((int)g_display.dp_xres, 500));140float step = (float)g_display.dp_xres / (float)steps;141t *= speed;142143for (int n = 0; n < steps; n++) {144float x = (float)n * step;145float nextX = (float)(n + 1) * step;146float i = x * 1280 / bounds.w;147148float wave0 = sin(i*0.005+t*0.8)*0.05 + sin(i*0.002+t*0.25)*0.02 + sin(i*0.001+t*0.3)*0.03 + 0.625;149float wave1 = sin(i*0.0044+t*0.4)*0.07 + sin(i*0.003+t*0.1)*0.02 + sin(i*0.001+t*0.3)*0.01 + 0.625;150dc.Draw()->RectVGradient(x, wave0*bounds.h, nextX, bounds.h, color, 0x00000000);151dc.Draw()->RectVGradient(x, wave1*bounds.h, nextX, bounds.h, color, 0x00000000);152153// Add some "antialiasing"154dc.Draw()->RectVGradient(x, wave0*bounds.h-3.0f * g_display.pixel_in_dps_y, nextX, wave0 * bounds.h, 0x00000000, color);155dc.Draw()->RectVGradient(x, wave1*bounds.h-3.0f * g_display.pixel_in_dps_y, nextX, wave1 * bounds.h, 0x00000000, color);156}157158dc.Flush();159dc.Begin();160}161};162163class FloatingSymbolsAnimation : public Animation {164public:165void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) override {166dc.Flush();167dc.Begin();168float xres = dc.GetBounds().w;169float yres = dc.GetBounds().h;170if (last_xres != xres || last_yres != yres) {171Regenerate(xres, yres);172}173174for (int i = 0; i < COUNT; i++) {175float x = xbase[i] + dc.GetBounds().x;176float y = ybase[i] + dc.GetBounds().y + 40 * cosf(i * 7.2f + t * 1.3f);177float angle = (float)sin(i + t);178int n = i & 3;179ui_draw2d.DrawImageRotated(symbols[n], x, y, 1.0f, angle, colorAlpha(colors[n], alpha * 0.1f));180}181dc.Flush();182}183184private:185static constexpr int COUNT = 100;186187float xbase[COUNT]{};188float ybase[COUNT]{};189float last_xres = 0;190float last_yres = 0;191192void Regenerate(int xres, int yres) {193GMRng rng;194for (int i = 0; i < COUNT; i++) {195xbase[i] = rng.F() * xres;196ybase[i] = rng.F() * yres;197}198199last_xres = xres;200last_yres = yres;201}202};203204class RecentGamesAnimation : public Animation {205public:206void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) override {207if (lastIndex_ == nextIndex_) {208CheckNext(dc, t);209} else if (t > nextT_) {210lastIndex_ = nextIndex_;211}212213if (g_Config.HasRecentIsos()) {214std::shared_ptr<GameInfo> lastInfo = GetInfo(dc, lastIndex_);215std::shared_ptr<GameInfo> nextInfo = GetInfo(dc, nextIndex_);216dc.Flush();217218float lastAmount = Clamp((float)(nextT_ - t) * 1.0f / TRANSITION, 0.0f, 1.0f);219DrawTex(dc, lastInfo, lastAmount * alpha * 0.2f);220221float nextAmount = lastAmount <= 0.0f ? 1.0f : 1.0f - lastAmount;222DrawTex(dc, nextInfo, nextAmount * alpha * 0.2f);223224dc.RebindTexture();225}226}227228private:229void CheckNext(UIContext &dc, double t) {230if (!g_Config.HasRecentIsos()) {231return;232}233234for (int index = lastIndex_ + 1; index != lastIndex_; ++index) {235if (index < 0 || index >= (int)g_Config.RecentIsos().size()) {236if (lastIndex_ == -1)237break;238index = 0;239}240241std::shared_ptr<GameInfo> ginfo = GetInfo(dc, index);242if (ginfo && !ginfo->Ready(GameInfoFlags::BG)) {243// Wait for it to load. It might be the next one.244break;245}246if (ginfo && (ginfo->pic1.texture || ginfo->pic0.texture)) {247nextIndex_ = index;248nextT_ = t + INTERVAL;249break;250}251252// Otherwise, keep going. This skips games with no BG.253}254}255256std::shared_ptr<GameInfo> GetInfo(UIContext &dc, int index) {257if (index < 0) {258return nullptr;259}260const auto recentIsos = g_Config.RecentIsos();261if (index >= (int)recentIsos.size())262return nullptr;263return g_gameInfoCache->GetInfo(dc.GetDrawContext(), Path(recentIsos[index]), GameInfoFlags::BG);264}265266void DrawTex(UIContext &dc, std::shared_ptr<GameInfo> &ginfo, float amount) {267if (!ginfo || amount <= 0.0f)268return;269GameInfoTex *pic = ginfo->GetBGPic();270if (!pic)271return;272273dc.GetDrawContext()->BindTexture(0, pic->texture);274uint32_t color = whiteAlpha(amount) & 0xFFc0c0c0;275dc.Draw()->DrawTexRect(dc.GetBounds(), 0, 0, 1, 1, color);276dc.Flush();277}278279static constexpr double INTERVAL = 8.0;280static constexpr float TRANSITION = 3.0f;281282int lastIndex_ = -1;283int nextIndex_ = -1;284double nextT_ = -INTERVAL;285};286287// TODO: Add more styles. Remember to add to the enum in ConfigValues.h and the selector in GameSettings too.288289static BackgroundAnimation g_CurBackgroundAnimation = BackgroundAnimation::OFF;290static std::unique_ptr<Animation> g_Animation;291static bool bgTextureInited = false; // Separate variable because init could fail.292293void UIBackgroundInit(UIContext &dc) {294const Path bgPng = GetSysDirectory(DIRECTORY_SYSTEM) / "background.png";295const Path bgJpg = GetSysDirectory(DIRECTORY_SYSTEM) / "background.jpg";296if (File::Exists(bgPng) || File::Exists(bgJpg)) {297const Path &bgFile = File::Exists(bgPng) ? bgPng : bgJpg;298bgTexture = CreateTextureFromFile(dc.GetDrawContext(), bgFile.c_str(), ImageFileType::DETECT, true);299}300}301302void UIBackgroundShutdown() {303if (bgTexture) {304bgTexture->Release();305bgTexture = nullptr;306}307bgTextureInited = false;308g_Animation.reset(nullptr);309g_CurBackgroundAnimation = BackgroundAnimation::OFF;310}311312void DrawBackground(UIContext &dc, float alpha, float x, float y, float z) {313if (!bgTextureInited) {314UIBackgroundInit(dc);315bgTextureInited = true;316}317if (g_CurBackgroundAnimation != (BackgroundAnimation)g_Config.iBackgroundAnimation) {318g_CurBackgroundAnimation = (BackgroundAnimation)g_Config.iBackgroundAnimation;319320switch (g_CurBackgroundAnimation) {321case BackgroundAnimation::FLOATING_SYMBOLS:322g_Animation.reset(new FloatingSymbolsAnimation());323break;324case BackgroundAnimation::RECENT_GAMES:325g_Animation.reset(new RecentGamesAnimation());326break;327case BackgroundAnimation::WAVE:328g_Animation.reset(new WaveAnimation());329break;330case BackgroundAnimation::MOVING_BACKGROUND:331g_Animation.reset(new MovingBackground());332break;333default:334g_Animation.reset(nullptr);335}336}337338uint32_t bgColor = whiteAlpha(alpha);339340if (bgTexture != nullptr) {341dc.Flush();342dc.Begin();343dc.GetDrawContext()->BindTexture(0, bgTexture);344dc.Draw()->DrawTexRect(dc.GetBounds(), 0, 0, 1, 1, bgColor);345346dc.Flush();347dc.RebindTexture();348} else {349// I_BG original color: 0xFF754D24350ImageID img = ImageID("I_BG");351dc.Begin();352dc.Draw()->DrawImageStretch(img, dc.GetBounds(), bgColor & dc.theme->backgroundColor);353dc.Flush();354}355356#if PPSSPP_PLATFORM(IOS)357// iOS uses an old screenshot when restoring the task, so to avoid an ugly358// jitter we accumulate time instead.359static int frameCount = 0.0;360frameCount++;361double t = (double)frameCount / System_GetPropertyFloat(SYSPROP_DISPLAY_REFRESH_RATE);362#else363double t = time_now_d();364#endif365366if (g_Animation) {367g_Animation->Draw(dc, t, alpha, x, y, z);368}369}370371uint32_t GetBackgroundColorWithAlpha(const UIContext &dc) {372return colorAlpha(colorBlend(dc.GetTheme().backgroundColor, 0, 0.5f), 0.65f); // 0.65 = 166 = A6373}374375void DrawGameBackground(UIContext &dc, const Path &gamePath, float x, float y, float z) {376using namespace Draw;377using namespace UI;378dc.Flush();379380std::shared_ptr<GameInfo> ginfo;381if (!gamePath.empty()) {382ginfo = g_gameInfoCache->GetInfo(dc.GetDrawContext(), gamePath, GameInfoFlags::BG);383}384385GameInfoTex *pic = (ginfo && ginfo->Ready(GameInfoFlags::BG)) ? ginfo->GetBGPic() : nullptr;386if (pic) {387dc.GetDrawContext()->BindTexture(0, pic->texture);388uint32_t color = whiteAlpha(ease((time_now_d() - pic->timeLoaded) * 3)) & 0xFFc0c0c0;389dc.Draw()->DrawTexRect(dc.GetBounds(), 0,0,1,1, color);390dc.Flush();391dc.RebindTexture();392} else {393::DrawBackground(dc, 1.0f, x, y, z);394dc.RebindTexture();395dc.Flush();396}397}398399void HandleCommonMessages(UIMessage message, const char *value, ScreenManager *manager, const Screen *activeScreen) {400bool isActiveScreen = manager->topScreen() == activeScreen;401402if (message == UIMessage::REQUEST_CLEAR_JIT && PSP_IsInited()) {403// TODO: This seems to clearly be the wrong place to handle this.404if (MIPSComp::jit) {405std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);406if (MIPSComp::jit)407MIPSComp::jit->ClearCache();408}409currentMIPS->UpdateCore((CPUCore)g_Config.iCpuCore);410} else if (message == UIMessage::SHOW_CONTROL_MAPPING && isActiveScreen && std::string(activeScreen->tag()) != "ControlMapping") {411UpdateUIState(UISTATE_MENU);412manager->push(new ControlMappingScreen(Path()));413} else if (message == UIMessage::SHOW_DISPLAY_LAYOUT_EDITOR && isActiveScreen && std::string(activeScreen->tag()) != "DisplayLayout") {414UpdateUIState(UISTATE_MENU);415manager->push(new DisplayLayoutScreen(Path()));416} else if (message == UIMessage::SHOW_SETTINGS && isActiveScreen && std::string(activeScreen->tag()) != "GameSettings") {417UpdateUIState(UISTATE_MENU);418manager->push(new GameSettingsScreen(Path()));419} else if (message == UIMessage::SHOW_LANGUAGE_SCREEN && isActiveScreen) {420auto sy = GetI18NCategory(I18NCat::SYSTEM);421auto langScreen = new NewLanguageScreen(sy->T("Language"));422langScreen->OnChoice.Add([](UI::EventParams &) {423System_PostUIMessage(UIMessage::RECREATE_VIEWS);424System_Notify(SystemNotification::UI);425return UI::EVENT_DONE;426});427manager->push(langScreen);428} else if (message == UIMessage::WINDOW_MINIMIZED) {429if (!strcmp(value, "true")) {430gstate_c.skipDrawReason |= SKIPDRAW_WINDOW_MINIMIZED;431} else {432gstate_c.skipDrawReason &= ~SKIPDRAW_WINDOW_MINIMIZED;433}434}435}436437ScreenRenderFlags BackgroundScreen::render(ScreenRenderMode mode) {438if (mode & ScreenRenderMode::FIRST) {439SetupViewport();440} else {441_dbg_assert_(false);442}443444UIContext *uiContext = screenManager()->getUIContext();445446uiContext->PushTransform({ translation_, scale_, alpha_ });447448uiContext->Begin();449float x, y, z;450screenManager()->getFocusPosition(x, y, z);451452if (!gamePath_.empty()) {453::DrawGameBackground(*uiContext, gamePath_, x, y, z);454} else {455::DrawBackground(*uiContext, 1.0f, x, y, z);456}457458uiContext->Flush();459460uiContext->PopTransform();461462return ScreenRenderFlags::NONE;463}464465void BackgroundScreen::sendMessage(UIMessage message, const char *value) {466switch (message) {467case UIMessage::GAME_SELECTED:468if (value && strlen(value)) {469gamePath_ = Path(value);470} else {471gamePath_.clear();472}473break;474default:475break;476}477}478479void UIScreenWithGameBackground::sendMessage(UIMessage message, const char *value) {480if (message == UIMessage::SHOW_SETTINGS && screenManager()->topScreen() == this) {481screenManager()->push(new GameSettingsScreen(gamePath_));482} else {483UIScreenWithBackground::sendMessage(message, value);484}485}486487void UIDialogScreenWithGameBackground::sendMessage(UIMessage message, const char *value) {488if (message == UIMessage::SHOW_SETTINGS && screenManager()->topScreen() == this) {489screenManager()->push(new GameSettingsScreen(gamePath_));490} else {491UIDialogScreenWithBackground::sendMessage(message, value);492}493}494495void UIScreenWithBackground::sendMessage(UIMessage message, const char *value) {496HandleCommonMessages(message, value, screenManager(), this);497}498499void UIDialogScreenWithBackground::AddStandardBack(UI::ViewGroup *parent) {500using namespace UI;501auto di = GetI18NCategory(I18NCat::DIALOG);502parent->Add(new Choice(di->T("Back"), "", false, new AnchorLayoutParams(150, 64, 10, NONE, NONE, 10)))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);503}504505void UIDialogScreenWithBackground::sendMessage(UIMessage message, const char *value) {506HandleCommonMessages(message, value, screenManager(), this);507}508509PromptScreen::PromptScreen(const Path &gamePath, std::string_view message, std::string_view yesButtonText, std::string_view noButtonText, std::function<void(bool)> callback)510: UIDialogScreenWithGameBackground(gamePath), message_(message), callback_(callback) {511auto di = GetI18NCategory(I18NCat::DIALOG);512yesButtonText_ = di->T(yesButtonText);513noButtonText_ = di->T(noButtonText);514}515516void PromptScreen::CreateViews() {517// Information in the top left.518// Back button to the bottom left.519// Scrolling action menu to the right.520using namespace UI;521522Margins actionMenuMargins(0, 100, 15, 0);523524root_ = new AnchorLayout();525526root_->Add(new TextView(message_, ALIGN_LEFT | FLAG_WRAP_TEXT, false, new AnchorLayoutParams(WRAP_CONTENT, WRAP_CONTENT, 15, 15, 330, 10)))->SetClip(false);527528ViewGroup *rightColumnItems = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(300, WRAP_CONTENT, NONE, 15, 15, NONE));529root_->Add(rightColumnItems);530531Choice *yesButton = rightColumnItems->Add(new Choice(yesButtonText_));532yesButton->OnClick.Handle(this, &PromptScreen::OnYes);533root_->SetDefaultFocusView(yesButton);534if (!noButtonText_.empty()) {535rightColumnItems->Add(new Choice(noButtonText_))->OnClick.Handle(this, &PromptScreen::OnNo);536} else {537// This is an information screen, not a question.538// Sneak in the version of PPSSPP in the corner, for debug-reporting user screenshots.539std::string version = System_GetProperty(SYSPROP_BUILD_VERSION);540root_->Add(new TextView(version, 0, true, new AnchorLayoutParams(10.0f, NONE, NONE, 10.0f)));541}542}543544UI::EventReturn PromptScreen::OnYes(UI::EventParams &e) {545TriggerFinish(DR_OK);546return UI::EVENT_DONE;547}548549UI::EventReturn PromptScreen::OnNo(UI::EventParams &e) {550TriggerFinish(DR_CANCEL);551return UI::EVENT_DONE;552}553554void PromptScreen::TriggerFinish(DialogResult result) {555if (callback_) {556callback_(result == DR_OK || result == DR_YES);557}558UIDialogScreenWithBackground::TriggerFinish(result);559}560561TextureShaderScreen::TextureShaderScreen(std::string_view title) : ListPopupScreen(title) {}562563void TextureShaderScreen::CreateViews() {564auto ps = GetI18NCategory(I18NCat::TEXTURESHADERS);565ReloadAllPostShaderInfo(screenManager()->getDrawContext());566shaders_ = GetAllTextureShaderInfo();567std::vector<std::string> items;568int selected = -1;569for (int i = 0; i < (int)shaders_.size(); i++) {570if (shaders_[i].section == g_Config.sTextureShaderName)571selected = i;572items.push_back(std::string(ps->T(shaders_[i].section.c_str(), shaders_[i].name.c_str())));573}574adaptor_ = UI::StringVectorListAdaptor(items, selected);575576ListPopupScreen::CreateViews();577}578579void TextureShaderScreen::OnCompleted(DialogResult result) {580if (result != DR_OK)581return;582g_Config.sTextureShaderName = shaders_[listView_->GetSelected()].section;583}584585NewLanguageScreen::NewLanguageScreen(std::string_view title) : ListPopupScreen(title) {586// Disable annoying encoding warning587#ifdef _MSC_VER588#pragma warning(disable:4566)589#endif590auto &langValuesMapping = g_Config.GetLangValuesMapping();591592std::vector<File::FileInfo> tempLangs;593g_VFS.GetFileListing("lang", &tempLangs, "ini");594std::vector<std::string> listing;595int selected = -1;596int counter = 0;597for (size_t i = 0; i < tempLangs.size(); i++) {598// Skip README599if (tempLangs[i].name.find("README") != std::string::npos) {600continue;601}602603// We only support Arabic on platforms where we have support for the native text rendering604// APIs, as proper Arabic support is way too difficult to implement ourselves.605#if !(defined(USING_QT_UI) || PPSSPP_PLATFORM(WINDOWS) || PPSSPP_PLATFORM(ANDROID))606if (tempLangs[i].name.find("ar_AE") != std::string::npos) {607continue;608}609610if (tempLangs[i].name.find("fa_IR") != std::string::npos) {611continue;612}613#endif614615File::FileInfo lang = tempLangs[i];616langs_.push_back(lang);617618std::string code;619size_t dot = lang.name.find('.');620if (dot != std::string::npos)621code = lang.name.substr(0, dot);622623std::string buttonTitle = lang.name;624625if (!code.empty()) {626auto iter = langValuesMapping.find(code);627if (iter == langValuesMapping.end()) {628// No title found, show locale code629buttonTitle = code;630} else {631buttonTitle = iter->second.first;632}633}634if (g_Config.sLanguageIni == code)635selected = counter;636listing.push_back(buttonTitle);637counter++;638}639640adaptor_ = UI::StringVectorListAdaptor(listing, selected);641}642643void NewLanguageScreen::OnCompleted(DialogResult result) {644if (result != DR_OK)645return;646std::string oldLang = g_Config.sLanguageIni;647std::string iniFile = langs_[listView_->GetSelected()].name;648649size_t dot = iniFile.find('.');650std::string code;651if (dot != std::string::npos)652code = iniFile.substr(0, dot);653654if (code.empty())655return;656657g_Config.sLanguageIni = code;658659bool iniLoadedSuccessfully = false;660// Allow the lang directory to be overridden for testing purposes (e.g. Android, where it's hard to661// test new languages without recompiling the entire app, which is a hassle).662const Path langOverridePath = GetSysDirectory(DIRECTORY_SYSTEM) / "lang";663664// If we run into the unlikely case that "lang" is actually a file, just use the built-in translations.665if (!File::Exists(langOverridePath) || !File::IsDirectory(langOverridePath))666iniLoadedSuccessfully = g_i18nrepo.LoadIni(g_Config.sLanguageIni);667else668iniLoadedSuccessfully = g_i18nrepo.LoadIni(g_Config.sLanguageIni, langOverridePath);669670if (iniLoadedSuccessfully) {671RecreateViews();672} else {673// Failed to load the language ini. Shouldn't really happen, but let's just switch back to the old language.674g_Config.sLanguageIni = oldLang;675}676}677678void LogoScreen::Next() {679if (!switched_) {680switched_ = true;681Path gamePath = boot_filename;682683switch (afterLogoScreen_) {684case AfterLogoScreen::TO_GAME_SETTINGS:685if (!gamePath.empty()) {686screenManager()->switchScreen(new EmuScreen(gamePath));687} else {688screenManager()->switchScreen(new MainScreen());689}690screenManager()->push(new GameSettingsScreen(gamePath));691break;692case AfterLogoScreen::MEMSTICK_SCREEN_INITIAL_SETUP:693screenManager()->switchScreen(new MemStickScreen(true));694break;695case AfterLogoScreen::DEFAULT:696default:697if (boot_filename.size()) {698screenManager()->switchScreen(new EmuScreen(gamePath));699} else {700screenManager()->switchScreen(new MainScreen());701}702break;703}704}705}706707const float logoScreenSeconds = 2.5f;708709LogoScreen::LogoScreen(AfterLogoScreen afterLogoScreen)710: afterLogoScreen_(afterLogoScreen) {711}712713void LogoScreen::update() {714UIScreen::update();715double rate = std::max(30.0, (double)System_GetPropertyFloat(SYSPROP_DISPLAY_REFRESH_RATE));716717if ((double)frames_ / rate > logoScreenSeconds) {718Next();719}720frames_++;721sinceStart_ = (double)frames_ / rate;722}723724void LogoScreen::sendMessage(UIMessage message, const char *value) {725if (message == UIMessage::REQUEST_GAME_BOOT && screenManager()->topScreen() == this) {726screenManager()->switchScreen(new EmuScreen(Path(value)));727}728}729730bool LogoScreen::key(const KeyInput &key) {731if (key.deviceId != DEVICE_ID_MOUSE && (key.flags & KEY_DOWN)) {732Next();733return true;734}735return false;736}737738void LogoScreen::touch(const TouchInput &touch) {739if (touch.flags & TOUCH_DOWN) {740Next();741}742}743744void LogoScreen::DrawForeground(UIContext &dc) {745using namespace Draw;746747const Bounds &bounds = dc.GetBounds();748749dc.Begin();750751float t = (float)sinceStart_ / (logoScreenSeconds / 3.0f);752753float alpha = t;754if (t > 1.0f)755alpha = 1.0f;756float alphaText = alpha;757if (t > 2.0f)758alphaText = 3.0f - t;759uint32_t textColor = colorAlpha(dc.theme->infoStyle.fgColor, alphaText);760761auto cr = GetI18NCategory(I18NCat::PSPCREDITS);762auto gr = GetI18NCategory(I18NCat::GRAPHICS);763char temp[256];764// Manually formatting UTF-8 is fun. \xXX doesn't work everywhere.765snprintf(temp, sizeof(temp), "%s Henrik Rydg%c%crd", cr->T_cstr("created", "Created by"), 0xC3, 0xA5);766if (System_GetPropertyBool(SYSPROP_APP_GOLD)) {767dc.Draw()->DrawImage(ImageID("I_ICONGOLD"), bounds.centerX() - 120, bounds.centerY() - 30, 1.2f, 0xFFFFFFFF, ALIGN_CENTER);768} else {769dc.Draw()->DrawImage(ImageID("I_ICON"), bounds.centerX() - 120, bounds.centerY() - 30, 1.2f, 0xFFFFFFFF, ALIGN_CENTER);770}771dc.Draw()->DrawImage(ImageID("I_LOGO"), bounds.centerX() + 40, bounds.centerY() - 30, 1.5f, 0xFFFFFFFF, ALIGN_CENTER);772//dc.Draw()->DrawTextShadow(UBUNTU48, "PPSSPP", bounds.w / 2, bounds.h / 2 - 30, textColor, ALIGN_CENTER);773dc.SetFontScale(1.0f, 1.0f);774dc.SetFontStyle(dc.theme->uiFont);775dc.DrawText(temp, bounds.centerX(), bounds.centerY() + 40, textColor, ALIGN_CENTER);776dc.DrawText(cr->T_cstr("license", "Free Software under GPL 2.0+"), bounds.centerX(), bounds.centerY() + 70, textColor, ALIGN_CENTER);777778int ppsspp_org_y = bounds.h / 2 + 130;779dc.DrawText("www.ppsspp.org", bounds.centerX(), ppsspp_org_y, textColor, ALIGN_CENTER);780781#if !PPSSPP_PLATFORM(UWP) || defined(_DEBUG)782// Draw the graphics API, except on UWP where it's always D3D11783std::string apiName = screenManager()->getDrawContext()->GetInfoString(InfoField::APINAME);784#ifdef _DEBUG785apiName += ", debug build ";786// Add some emoji for testing.787apiName += CodepointToUTF8(0x1F41B) + CodepointToUTF8(0x1F41C) + CodepointToUTF8(0x1F914);788#endif789dc.DrawText(gr->T_cstr(apiName.c_str()), bounds.centerX(), ppsspp_org_y + 50, textColor, ALIGN_CENTER);790#endif791792dc.Flush();793}794795void CreditsScreen::CreateViews() {796using namespace UI;797auto di = GetI18NCategory(I18NCat::DIALOG);798auto cr = GetI18NCategory(I18NCat::PSPCREDITS);799800root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));801Button *back = root_->Add(new Button(di->T("Back"), new AnchorLayoutParams(260, 64, NONE, NONE, 10, 10, false)));802back->OnClick.Handle<UIScreen>(this, &UIScreen::OnOK);803root_->SetDefaultFocusView(back);804805// Really need to redo this whole layout with some linear layouts...806807int rightYOffset = 0;808if (!System_GetPropertyBool(SYSPROP_APP_GOLD)) {809root_->Add(new Button(cr->T("Buy Gold"), new AnchorLayoutParams(260, 64, NONE, NONE, 10, 84, false)))->OnClick.Handle(this, &CreditsScreen::OnSupport);810rightYOffset = 74;811}812root_->Add(new Button(cr->T("PPSSPP Forums"), new AnchorLayoutParams(260, 64, 10, NONE, NONE, 158, false)))->OnClick.Handle(this, &CreditsScreen::OnForums);813root_->Add(new Button(cr->T("Discord"), new AnchorLayoutParams(260, 64, 10, NONE, NONE, 232, false)))->OnClick.Handle(this, &CreditsScreen::OnDiscord);814root_->Add(new Button("www.ppsspp.org", new AnchorLayoutParams(260, 64, 10, NONE, NONE, 10, false)))->OnClick.Handle(this, &CreditsScreen::OnPPSSPPOrg);815root_->Add(new Button(cr->T("Privacy Policy"), new AnchorLayoutParams(260, 64, 10, NONE, NONE, 84, false)))->OnClick.Handle(this, &CreditsScreen::OnPrivacy);816root_->Add(new Button(cr->T("Twitter @PPSSPP_emu"), new AnchorLayoutParams(260, 64, NONE, NONE, 10, rightYOffset + 84, false)))->OnClick.Handle(this, &CreditsScreen::OnTwitter);817#if PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(IOS)818root_->Add(new Button(cr->T("Share PPSSPP"), new AnchorLayoutParams(260, 64, NONE, NONE, 10, rightYOffset + 158, false)))->OnClick.Handle(this, &CreditsScreen::OnShare);819#endif820if (System_GetPropertyBool(SYSPROP_APP_GOLD)) {821root_->Add(new ImageView(ImageID("I_ICONGOLD"), "", IS_DEFAULT, new AnchorLayoutParams(100, 64, 10, 10, NONE, NONE, false)));822} else {823root_->Add(new ImageView(ImageID("I_ICON"), "", IS_DEFAULT, new AnchorLayoutParams(100, 64, 10, 10, NONE, NONE, false)));824}825}826827UI::EventReturn CreditsScreen::OnSupport(UI::EventParams &e) {828#ifdef __ANDROID__829System_LaunchUrl(LaunchUrlType::BROWSER_URL, "market://details?id=org.ppsspp.ppssppgold");830#else831System_LaunchUrl(LaunchUrlType::BROWSER_URL, "https://www.ppsspp.org/buygold");832#endif833return UI::EVENT_DONE;834}835836UI::EventReturn CreditsScreen::OnTwitter(UI::EventParams &e) {837System_LaunchUrl(LaunchUrlType::BROWSER_URL, "https://twitter.com/PPSSPP_emu");838return UI::EVENT_DONE;839}840841UI::EventReturn CreditsScreen::OnPPSSPPOrg(UI::EventParams &e) {842System_LaunchUrl(LaunchUrlType::BROWSER_URL, "https://www.ppsspp.org");843return UI::EVENT_DONE;844}845846UI::EventReturn CreditsScreen::OnPrivacy(UI::EventParams &e) {847System_LaunchUrl(LaunchUrlType::BROWSER_URL, "https://www.ppsspp.org/privacy");848return UI::EVENT_DONE;849}850851UI::EventReturn CreditsScreen::OnForums(UI::EventParams &e) {852System_LaunchUrl(LaunchUrlType::BROWSER_URL, "https://forums.ppsspp.org");853return UI::EVENT_DONE;854}855856UI::EventReturn CreditsScreen::OnDiscord(UI::EventParams &e) {857System_LaunchUrl(LaunchUrlType::BROWSER_URL, "https://discord.gg/5NJB6dD");858return UI::EVENT_DONE;859}860861UI::EventReturn CreditsScreen::OnShare(UI::EventParams &e) {862auto cr = GetI18NCategory(I18NCat::PSPCREDITS);863System_ShareText(cr->T("CheckOutPPSSPP", "Check out PPSSPP, the awesome PSP emulator: https://www.ppsspp.org/"));864return UI::EVENT_DONE;865}866867CreditsScreen::CreditsScreen() {868startTime_ = time_now_d();869}870871void CreditsScreen::update() {872UIScreen::update();873UpdateUIState(UISTATE_MENU);874}875876void CreditsScreen::DrawForeground(UIContext &dc) {877auto cr = GetI18NCategory(I18NCat::PSPCREDITS);878879std::string specialthanksMaxim = "Maxim ";880specialthanksMaxim += cr->T("specialthanksMaxim", "for his amazing Atrac3+ decoder work");881882std::string specialthanksKeithGalocy = "Keith Galocy ";883specialthanksKeithGalocy += cr->T("specialthanksKeithGalocy", "at NVIDIA (hardware, advice)");884885std::string specialthanksOrphis = "Orphis (";886specialthanksOrphis += cr->T("build server");887specialthanksOrphis += ')';888889std::string specialthanksangelxwind = "angelxwind (";890specialthanksangelxwind += cr->T("iOS builds");891specialthanksangelxwind += ')';892893std::string specialthanksW_MS = "W.MS (";894specialthanksW_MS += cr->T("iOS builds");895specialthanksW_MS += ')';896897std::string specialthankssolarmystic = "solarmystic (";898specialthankssolarmystic += cr->T("testing");899specialthankssolarmystic += ')';900901std::string_view credits[] = {902System_GetPropertyBool(SYSPROP_APP_GOLD) ? "PPSSPP Gold" : "PPSSPP",903"",904cr->T("title", "A fast and portable PSP emulator"),905"",906"",907cr->T("created", "Created by"),908"Henrik Rydg\xc3\xa5rd",909"",910"",911cr->T("contributors", "Contributors:"),912"unknownbrackets",913"oioitff",914"xsacha",915"raven02",916"tpunix",917"orphis",918"sum2012",919"mikusp",920"aquanull",921"The Dax",922"bollu",923"tmaul",924"artart78",925"ced2911",926"soywiz",927"kovensky",928"xele",929"chaserhjk",930"evilcorn",931"daniel dressler",932"makotech222",933"CPkmn",934"mgaver",935"jeid3",936"cinaera/BeaR",937"jtraynham",938"Kingcom",939"arnastia",940"lioncash",941"JulianoAmaralChaves",942"vnctdj",943"kaienfr",944"shenweip",945"Danyal Zia",946"Igor Calabria",947"Coldbird",948"Kyhel",949"xebra",950"LunaMoo",951"zminhquanz",952"ANR2ME",953"adenovan",954"iota97",955"Lubos",956"stenzek", // For retroachievements integration957"fp64",958"",959cr->T("specialthanks", "Special thanks to:"),960specialthanksMaxim.c_str(),961specialthanksKeithGalocy.c_str(),962specialthanksOrphis.c_str(),963specialthanksangelxwind.c_str(),964specialthanksW_MS.c_str(),965specialthankssolarmystic.c_str(),966cr->T("all the forum mods"),967"",968cr->T("this translation by", ""), // Empty string as this is the original :)969cr->T("translators1", ""),970cr->T("translators2", ""),971cr->T("translators3", ""),972cr->T("translators4", ""),973cr->T("translators5", ""),974cr->T("translators6", ""),975"",976cr->T("written", "Written in C++ for speed and portability"),977"",978"",979cr->T("tools", "Free tools used:"),980#if PPSSPP_PLATFORM(ANDROID)981"Android SDK + NDK",982#endif983#if defined(USING_QT_UI)984"Qt",985#endif986#if defined(SDL)987"SDL",988#endif989"CMake",990"freetype2",991"zlib",992"rcheevos",993"SPIRV-Cross",994"armips",995"Basis Universal",996"cityhash",997"zstd",998"glew",999"libchdr",1000"minimp3",1001"xxhash",1002"naett-http",1003"PSP SDK",1004"",1005"",1006cr->T("website", "Check out the website:"),1007"www.ppsspp.org",1008cr->T("list", "compatibility lists, forums, and development info"),1009"",1010"",1011cr->T("check", "Also check out Dolphin, the best Wii/GC emu around:"),1012"https://www.dolphin-emu.org",1013"",1014"",1015cr->T("info1", "PPSSPP is only intended to play games you own."),1016cr->T("info2", "Please make sure that you own the rights to any games"),1017cr->T("info3", "you play by owning the UMD or by buying the digital"),1018cr->T("info4", "download from the PSN store on your real PSP."),1019"",1020"",1021cr->T("info5", "PSP is a trademark by Sony, Inc."),1022};10231024// TODO: This is kinda ugly, done on every frame...1025char temp[256];1026if (System_GetPropertyBool(SYSPROP_APP_GOLD)) {1027snprintf(temp, sizeof(temp), "PPSSPP Gold %s", PPSSPP_GIT_VERSION);1028} else {1029snprintf(temp, sizeof(temp), "PPSSPP %s", PPSSPP_GIT_VERSION);1030}1031credits[0] = (const char *)temp;10321033dc.Begin();1034const Bounds &bounds = dc.GetLayoutBounds();10351036const int numItems = ARRAY_SIZE(credits);1037int itemHeight = 36;1038int totalHeight = numItems * itemHeight + bounds.h + 200;10391040float t = (float)(time_now_d() - startTime_) * 60.0;10411042float y = bounds.y2() - fmodf(t, (float)totalHeight);1043for (int i = 0; i < numItems; i++) {1044float alpha = linearInOut(y+32, 64, bounds.y2() - 192, 64);1045uint32_t textColor = colorAlpha(dc.theme->infoStyle.fgColor, alpha);10461047if (alpha > 0.0f) {1048dc.SetFontScale(ease(alpha), ease(alpha));1049dc.DrawText(credits[i], bounds.centerX(), y, textColor, ALIGN_HCENTER);1050dc.SetFontScale(1.0f, 1.0f);1051}1052y += itemHeight;1053}10541055dc.Flush();1056}10571058SettingInfoMessage::SettingInfoMessage(int align, float cutOffY, UI::AnchorLayoutParams *lp)1059: UI::LinearLayout(UI::ORIENT_HORIZONTAL, lp), cutOffY_(cutOffY) {1060using namespace UI;1061SetSpacing(0.0f);1062Add(new UI::Spacer(10.0f));1063text_ = Add(new UI::TextView("", align, false, new LinearLayoutParams(1.0, Margins(0, 10))));1064Add(new UI::Spacer(10.0f));1065}10661067void SettingInfoMessage::Show(std::string_view text, const UI::View *refView) {1068if (refView) {1069Bounds b = refView->GetBounds();1070const UI::AnchorLayoutParams *lp = GetLayoutParams()->As<UI::AnchorLayoutParams>();1071if (lp) {1072if (cutOffY_ != -1.0f && b.y >= cutOffY_) {1073ReplaceLayoutParams(new UI::AnchorLayoutParams(lp->width, lp->height, lp->left, 80.0f, lp->right, lp->bottom, lp->center));1074} else {1075ReplaceLayoutParams(new UI::AnchorLayoutParams(lp->width, lp->height, lp->left, g_display.dp_yres - 80.0f - 40.0f, lp->right, lp->bottom, lp->center));1076}1077}1078}1079text_->SetText(text);1080timeShown_ = time_now_d();1081}10821083void SettingInfoMessage::Draw(UIContext &dc) {1084static const double FADE_TIME = 1.0;1085static const float MAX_ALPHA = 0.9f;10861087// Let's show longer messages for more time (guesstimate at reading speed.)1088// Note: this will give multibyte characters more time, but they often have shorter words anyway.1089double timeToShow = std::max(1.5, text_->GetText().size() * 0.05);10901091double sinceShow = time_now_d() - timeShown_;1092float alpha = MAX_ALPHA;1093if (timeShown_ == 0.0 || sinceShow > timeToShow + FADE_TIME) {1094alpha = 0.0f;1095} else if (sinceShow > timeToShow) {1096alpha = MAX_ALPHA - MAX_ALPHA * (float)((sinceShow - timeToShow) / FADE_TIME);1097}10981099if (alpha >= 0.1f) {1100UI::Style style = dc.theme->popupStyle;1101style.background.color = colorAlpha(style.background.color, alpha - 0.1f);1102dc.FillRect(style.background, bounds_);1103}11041105uint32_t textColor = colorAlpha(dc.GetTheme().itemStyle.fgColor, alpha);1106text_->SetTextColor(textColor);1107ViewGroup::Draw(dc);1108showing_ = sinceShow <= timeToShow; // Don't consider fade time1109}11101111std::string SettingInfoMessage::GetText() const {1112return (showing_ && text_) ? text_->GetText() : "";1113}111411151116