From be70c8ab04923b8ff7b6bc68b29e28df8009eae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 24 Mar 2013 20:03:42 +0100 Subject: [PATCH] Add buttons for recently played games to the empty space on the menu screen. --- Core/Config.cpp | 25 ++++++++++++++++++++----- Core/Config.h | 14 ++++++++++---- Core/System.cpp | 1 + android/jni/MenuScreens.cpp | 13 +++++++++++++ 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index f3bdc009c3..66667a02c6 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -21,17 +21,17 @@ #include "HLE/sceUtility.h" SState g_State; -CConfig g_Config; +Config g_Config; -CConfig::CConfig() +Config::Config() { } -CConfig::~CConfig() +Config::~Config() { } -void CConfig::Load(const char *iniFileName) +void Config::Load(const char *iniFileName) { iniFilename_ = iniFileName; INFO_LOG(LOADER, "Loading config: %s", iniFileName); @@ -56,6 +56,7 @@ void CConfig::Load(const char *iniFileName) general->Get("ShowDebuggerOnLoad", &bShowDebuggerOnLoad, false); // "default" means let emulator decide, "" means disable. general->Get("ReportHost", &sReportHost, "default"); + general->Get("Recent", recentIsos); IniFile::Section *cpu = iniFile.GetOrCreateSection("CPU"); cpu->Get("Jit", &bJit, true); @@ -107,7 +108,7 @@ void CConfig::Load(const char *iniFileName) bDrawWireframe = false; } -void CConfig::Save() +void Config::Save() { if (iniFilename_.size() && g_Config.bSaveSettings) { IniFile iniFile; @@ -125,6 +126,7 @@ void CConfig::Save() general->Set("CurrentDirectory", currentDirectory); general->Set("ShowDebuggerOnLoad", bShowDebuggerOnLoad); general->Set("ReportHost", sReportHost); + general->Set("Recent", recentIsos); IniFile::Section *cpu = iniFile.GetOrCreateSection("CPU"); cpu->Set("Jit", bJit); @@ -171,3 +173,16 @@ void CConfig::Save() INFO_LOG(LOADER, "Not saving config"); } } + +void Config::AddRecent(const std::string &file) { + for (auto str = recentIsos.begin(); str != recentIsos.end(); str++) { + if (*str == file) { + recentIsos.erase(str); + recentIsos.insert(recentIsos.begin(), file); + return; + } + } + recentIsos.insert(recentIsos.begin(), file); + if (recentIsos.size() > 4) + recentIsos.resize(4); +} diff --git a/Core/Config.h b/Core/Config.h index 214addab08..27f1cff5bc 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -18,6 +18,7 @@ #pragma once #include +#include #include extern const char *PPSSPP_GIT_VERSION; @@ -28,11 +29,11 @@ struct SState bool bBooted; }; -struct CConfig +struct Config { public: - CConfig(); - ~CConfig(); + Config(); + ~Config(); // Whether to save the config on close. bool bSaveSettings; @@ -50,6 +51,7 @@ public: bool bFastMemory; bool bJit; std::string sReportHost; + std::vector recentIsos; // GFX bool bDisplayFramebuffer; @@ -95,9 +97,13 @@ public: void Load(const char *iniFileName = "ppsspp.ini"); void Save(); + + // Utility functions for "recent" management + void AddRecent(const std::string &file); + private: std::string iniFilename_; }; extern SState g_State; -extern CConfig g_Config; +extern Config g_Config; diff --git a/Core/System.cpp b/Core/System.cpp index 8a0581b7bf..2f63c1b30b 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -87,6 +87,7 @@ bool PSP_Init(const CoreParameter &coreParam, std::string *error_string) return false; } + g_Config.AddRecent(coreParameter.fileToStart); // Setup JIT here. if (coreParameter.startPaused) coreState = CORE_STEPPING; diff --git a/android/jni/MenuScreens.cpp b/android/jni/MenuScreens.cpp index 046be148d1..051ab7318c 100644 --- a/android/jni/MenuScreens.cpp +++ b/android/jni/MenuScreens.cpp @@ -38,6 +38,7 @@ #include "util/text/utf8.h" #include "UIShader.h" +#include "Common/StringUtil.h" #include "../../GPU/ge_constants.h" #include "../../GPU/GPUState.h" #include "../../GPU/GPUInterface.h" @@ -177,6 +178,7 @@ void MenuScreen::render() { ui_draw2d.DrawTextShadow(UBUNTU24, PPSSPP_GIT_VERSION, dp_xres + xoff, 85, 0xFFFFFFFF, ALIGN_RIGHT | ALIGN_BOTTOM); ui_draw2d.SetFontScale(1.0f, 1.0f); VLinear vlinear(dp_xres + xoff, 100, 20); + VLinear vlinear2(-xoff, 100, 20); if (UIButton(GEN_ID, vlinear, w, "Load...", ALIGN_RIGHT)) { #if defined(USING_QT_UI) @@ -222,6 +224,17 @@ void MenuScreen::render() { LaunchBrowser("http://www.ppsspp.org/"); } + int recentW = 350; + if (g_Config.recentIsos.size()) { + ui_draw2d.DrawText(UBUNTU24, "Recent", -xoff, 80, 0xFFFFFFFF, ALIGN_BOTTOMLEFT); + } + for (size_t i = 0; i < g_Config.recentIsos.size(); i++) { + std::string filename; + SplitPath(g_Config.recentIsos[i], nullptr, &filename, nullptr); + if (UIButton(GEN_ID_LOOP(i), vlinear2, recentW, filename.c_str(), ALIGN_LEFT)) { + screenManager()->switchScreen(new EmuScreen(g_Config.recentIsos[i])); + } + } DrawWatermark(); UIEnd();