Add buttons for recently played games to the empty space on the menu screen.

This commit is contained in:
Henrik Rydgård 2013-03-24 20:03:42 +01:00
parent d1af119c6f
commit be70c8ab04
4 changed files with 44 additions and 9 deletions

View file

@ -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);
}

View file

@ -18,6 +18,7 @@
#pragma once
#include <string>
#include <vector>
#include <map>
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<std::string> 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;

View file

@ -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;

View file

@ -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();