From 62458dd11e11c95e93eedee4f3161af9033d6e36 Mon Sep 17 00:00:00 2001 From: Mentfent <167481805+mentusfentus@users.noreply.github.com> Date: Mon, 10 Jun 2024 18:04:45 -0300 Subject: [PATCH] Fixed cursor behavior when sorting by recently played (#2430) --- romsel_aktheme/arm9/source/fileBrowse.cpp | 12 ++++++++++++ romsel_dsimenutheme/arm9/source/fileBrowse.cpp | 11 +++++++++++ romsel_r4theme/arm9/source/fileBrowse.cpp | 13 +++++++++++++ 3 files changed, 36 insertions(+) diff --git a/romsel_aktheme/arm9/source/fileBrowse.cpp b/romsel_aktheme/arm9/source/fileBrowse.cpp index 073880dd3a..56d4d63fe7 100644 --- a/romsel_aktheme/arm9/source/fileBrowse.cpp +++ b/romsel_aktheme/arm9/source/fileBrowse.cpp @@ -105,6 +105,7 @@ extern touchPosition touch; extern void bgOperations(bool waitFrame); int file_count = 0; +static int fileStartPos = 0; // The position of the first thing that is not a directory. std::string gameOrderIniPath, recentlyPlayedIniPath, timesPlayedIniPath; @@ -171,6 +172,7 @@ void getDirectoryContents(std::vector &dirContents, const std::vector< dirContents.clear(); file_count = 0; + fileStartPos = 0; DIR *pdir = opendir("."); @@ -246,6 +248,9 @@ void getDirectoryContents(std::vector &dirContents, const std::vector< iconsToDisplay++; if (iconsToDisplay > 4) iconsToDisplay = 4; + + if (pent->d_type == DT_DIR) + fileStartPos++; } } @@ -1923,6 +1928,13 @@ std::string browseForFile(const std::vector extensionList) { CIniFile timesPlayedIni(timesPlayedIniPath); timesPlayedIni.SetInt(path, entry->name, (timesPlayedIni.GetInt(path, entry->name, 0) + 1)); timesPlayedIni.SaveIniFile(timesPlayedIniPath); + + if (ms().sortMethod == TWLSettings::ESortRecent) { + // Set cursor pos to the first slot that isn't a directory so it won't be misplaced with recent sort + PAGENUM = fileStartPos / 40; + CURPOS = fileStartPos - PAGENUM * 40; + } + displayDiskIcon(false); } diff --git a/romsel_dsimenutheme/arm9/source/fileBrowse.cpp b/romsel_dsimenutheme/arm9/source/fileBrowse.cpp index 2972442062..82a6464e6f 100644 --- a/romsel_dsimenutheme/arm9/source/fileBrowse.cpp +++ b/romsel_dsimenutheme/arm9/source/fileBrowse.cpp @@ -87,6 +87,7 @@ extern int vblankRefreshCounter; int file_count = 0; int last_used_box = 0; +static int fileStartPos = 0; // The position of the first thing that is not a directory. extern int spawnedtitleboxes; @@ -267,6 +268,7 @@ void getDirectoryContents(std::vector &dirContents, const std::vector< dirContents.clear(); file_count = 0; + fileStartPos = 0; if (access("dirInfo.twlm.ini", F_OK) == 0) { dirInfoIniFound = true; @@ -354,6 +356,9 @@ void getDirectoryContents(std::vector &dirContents, const std::vector< dirContents.emplace_back(pent->d_name, ms().showDirectories ? (pent->d_type == DT_DIR) : false, file_count, false); logPrint("%s listed: %s\n", (pent->d_type == DT_DIR) ? "Directory" : "File", pent->d_name); file_count++; + + if (pent->d_type == DT_DIR) + fileStartPos++; } } recalculateBoxesCount(); @@ -3967,6 +3972,12 @@ std::string browseForFile(const std::vector extensionList) { timesPlayedIni.SetInt(path, entry->name, (timesPlayedIni.GetInt(path, entry->name, 0) + 1)); timesPlayedIni.SaveIniFile(timesPlayedIniPath); + if (ms().sortMethod == TWLSettings::ESortRecent) { + // Set cursor pos to the first slot that isn't a directory so it won't be misplaced with recent sort + PAGENUM = fileStartPos / 40; + CURPOS = fileStartPos - PAGENUM * 40; + } + if (ms().theme == TWLSettings::EThemeHBL) { displayGameIcons = true; } else if (ms().theme != TWLSettings::EThemeSaturn) { diff --git a/romsel_r4theme/arm9/source/fileBrowse.cpp b/romsel_r4theme/arm9/source/fileBrowse.cpp index 0a2246ce99..8eec2cadfd 100644 --- a/romsel_r4theme/arm9/source/fileBrowse.cpp +++ b/romsel_r4theme/arm9/source/fileBrowse.cpp @@ -88,6 +88,8 @@ extern void bgOperations(bool waitFrame); std::string gameOrderIniPath, recentlyPlayedIniPath, timesPlayedIniPath; +static int fileStartPos = 0; // The position of the first thing that is not a directory. + char path[PATH_MAX] = {0}; static void gbnpBottomInfo(void) { @@ -174,6 +176,8 @@ void getDirectoryContents(std::vector &dirContents, const std::vector< iprintf("Unable to open the directory.\n"); } else { int file_count = 0; + fileStartPos = 0; + while (1) { bgOperations(false); @@ -240,6 +244,9 @@ void getDirectoryContents(std::vector &dirContents, const std::vector< dirContents.emplace_back(pent->d_name, ms().showDirectories ? (pent->d_type == DT_DIR) : false, file_count, false); logPrint("%s listed: %s\n", (pent->d_type == DT_DIR) ? "Directory" : "File", pent->d_name); file_count++; + + if (pent->d_type == DT_DIR) + fileStartPos++; } } @@ -1497,6 +1504,12 @@ std::string browseForFile(const std::vector extensionList) { CIniFile timesPlayedIni(timesPlayedIniPath); timesPlayedIni.SetInt(path, entry->name, (timesPlayedIni.GetInt(path, entry->name, 0) + 1)); timesPlayedIni.SaveIniFile(timesPlayedIniPath); + + if (ms().sortMethod == TWLSettings::ESortRecent) { + // Set cursor pos to the first slot that isn't a directory so it won't be misplaced with recent sort + ms().pagenum[ms().secondaryDevice] = fileStartPos / 40; + ms().cursorPosition[ms().secondaryDevice] = fileStartPos - ms().pagenum[ms().secondaryDevice] * 40; + } } // Return the chosen file