mGUI: Remmeber name and position of last loaded game

This commit is contained in:
Vicki Pfau 2019-06-07 12:26:40 -07:00
parent 1928d2b5fc
commit 7d821d4f11
5 changed files with 25 additions and 13 deletions

View File

@ -54,6 +54,7 @@ Misc:
- Switch: Dynamic display resizing
- Qt: Make mute menu option also toggle fast-forward mute (fixes mgba.io/i/1424)
- Vita: L2/R2 and L3/R3 can now be mapped on PSTV (fixes mgba.io/i/1292)
- mGUI: Remember name and position of last loaded game
0.7.2: (2019-05-25)
Emulation fixes:

View File

@ -14,7 +14,7 @@ CXX_GUARD_START
struct VFile;
bool GUISelectFile(struct GUIParams*, char* outPath, size_t outLen, bool (*filterName)(const char* name), bool (*filterContents)(struct VFile*));
bool GUISelectFile(struct GUIParams*, char* outPath, size_t outLen, bool (*filterName)(const char* name), bool (*filterContents)(struct VFile*), const char* preselect);
CXX_GUARD_END

View File

@ -303,7 +303,7 @@ void mGUIShowConfig(struct mGUIRunner* runner, struct GUIMenuItem* extra, size_t
}
if (!strcmp(item->data, "gba.bios")) {
// TODO: show box if failed
if (!GUISelectFile(&runner->params, gbaBiosPath, sizeof(gbaBiosPath), _biosNamed, GBAIsBIOS)) {
if (!GUISelectFile(&runner->params, gbaBiosPath, sizeof(gbaBiosPath), _biosNamed, GBAIsBIOS, NULL)) {
gbaBiosPath[0] = '\0';
}
continue;
@ -311,21 +311,21 @@ void mGUIShowConfig(struct mGUIRunner* runner, struct GUIMenuItem* extra, size_t
#ifdef M_CORE_GB
if (!strcmp(item->data, "gb.bios")) {
// TODO: show box if failed
if (!GUISelectFile(&runner->params, gbBiosPath, sizeof(gbBiosPath), _biosNamed, GBIsBIOS)) {
if (!GUISelectFile(&runner->params, gbBiosPath, sizeof(gbBiosPath), _biosNamed, GBIsBIOS, NULL)) {
gbBiosPath[0] = '\0';
}
continue;
}
if (!strcmp(item->data, "gbc.bios")) {
// TODO: show box if failed
if (!GUISelectFile(&runner->params, gbcBiosPath, sizeof(gbcBiosPath), _biosNamed, GBIsBIOS)) {
if (!GUISelectFile(&runner->params, gbcBiosPath, sizeof(gbcBiosPath), _biosNamed, GBIsBIOS, NULL)) {
gbcBiosPath[0] = '\0';
}
continue;
}
if (!strcmp(item->data, "sgb.bios")) {
// TODO: show box if failed
if (!GUISelectFile(&runner->params, sgbBiosPath, sizeof(sgbBiosPath), _biosNamed, GBIsBIOS)) {
if (!GUISelectFile(&runner->params, sgbBiosPath, sizeof(sgbBiosPath), _biosNamed, GBIsBIOS, NULL)) {
sgbBiosPath[0] = '\0';
}
continue;

View File

@ -628,10 +628,18 @@ void mGUIRunloop(struct mGUIRunner* runner) {
}
while (true) {
char path[PATH_MAX];
if (!GUISelectFile(&runner->params, path, sizeof(path), _testExtensions, NULL)) {
const char* preselect = mCoreConfigGetValue(&runner->config, "lastGame");
if (preselect) {
preselect = strrchr(preselect, '/');
}
if (preselect) {
++preselect;
}
if (!GUISelectFile(&runner->params, path, sizeof(path), _testExtensions, NULL, preselect)) {
break;
}
mCoreConfigSetValue(&runner->config, "lastDirectory", runner->params.currentPath);
mCoreConfigSetValue(&runner->config, "lastGame", path);
mCoreConfigSave(&runner->config);
mGUIRun(runner, path);
}

View File

@ -47,7 +47,7 @@ static int _strpcmp(const void* a, const void* b) {
return strcasecmp(((const struct GUIMenuItem*) a)->title, ((const struct GUIMenuItem*) b)->title);
}
static bool _refreshDirectory(struct GUIParams* params, const char* currentPath, struct GUIMenuItemList* currentFiles, bool (*filterName)(const char* name), bool (*filterContents)(struct VFile*)) {
static bool _refreshDirectory(struct GUIParams* params, const char* currentPath, struct GUIMenuItemList* currentFiles, bool (*filterName)(const char* name), bool (*filterContents)(struct VFile*), const char* preselect) {
_cleanFiles(currentFiles);
struct VDir* dir = VDirOpen(currentPath);
@ -144,6 +144,9 @@ static bool _refreshDirectory(struct GUIParams* params, const char* currentPath,
free((char*) testItem->title);
GUIMenuItemListShift(currentFiles, item, 1);
} else {
if (preselect && strncmp(testItem->title, preselect, PATH_MAX) == 0) {
params->fileIndex = item;
}
++item;
}
}
@ -152,14 +155,14 @@ static bool _refreshDirectory(struct GUIParams* params, const char* currentPath,
return true;
}
bool GUISelectFile(struct GUIParams* params, char* outPath, size_t outLen, bool (*filterName)(const char* name), bool (*filterContents)(struct VFile*)) {
bool GUISelectFile(struct GUIParams* params, char* outPath, size_t outLen, bool (*filterName)(const char* name), bool (*filterContents)(struct VFile*), const char* preselect) {
struct GUIMenu menu = {
.title = "Select file",
.subtitle = params->currentPath,
.index = params->fileIndex,
};
GUIMenuItemListInit(&menu.items, 0);
_refreshDirectory(params, params->currentPath, &menu.items, filterName, filterContents);
_refreshDirectory(params, params->currentPath, &menu.items, filterName, filterContents, preselect);
menu.index = params->fileIndex;
while (true) {
struct GUIMenuItem* item;
@ -174,7 +177,7 @@ bool GUISelectFile(struct GUIParams* params, char* outPath, size_t outLen, bool
continue;
}
_upDirectory(params->currentPath);
if (!_refreshDirectory(params, params->currentPath, &menu.items, filterName, filterContents)) {
if (!_refreshDirectory(params, params->currentPath, &menu.items, filterName, filterContents, NULL)) {
break;
}
} else {
@ -187,7 +190,7 @@ bool GUISelectFile(struct GUIParams* params, char* outPath, size_t outLen, bool
struct GUIMenuItemList newFiles;
GUIMenuItemListInit(&newFiles, 0);
if (!_refreshDirectory(params, outPath, &newFiles, filterName, filterContents)) {
if (!_refreshDirectory(params, outPath, &newFiles, filterName, filterContents, NULL)) {
_cleanFiles(&newFiles);
GUIMenuItemListDeinit(&newFiles);
_cleanFiles(&menu.items);
@ -208,7 +211,7 @@ bool GUISelectFile(struct GUIParams* params, char* outPath, size_t outLen, bool
break;
}
_upDirectory(params->currentPath);
if (!_refreshDirectory(params, params->currentPath, &menu.items, filterName, filterContents)) {
if (!_refreshDirectory(params, params->currentPath, &menu.items, filterName, filterContents, NULL)) {
break;
}
params->fileIndex = 0;