Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cursor position when sorting by recently played upon reboot #2430

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions romsel_aktheme/arm9/source/fileBrowse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -171,6 +172,7 @@ void getDirectoryContents(std::vector<DirEntry> &dirContents, const std::vector<
dirContents.clear();

file_count = 0;
fileStartPos = 0;

DIR *pdir = opendir(".");

Expand Down Expand Up @@ -246,6 +248,9 @@ void getDirectoryContents(std::vector<DirEntry> &dirContents, const std::vector<

iconsToDisplay++;
if (iconsToDisplay > 4) iconsToDisplay = 4;

if (pent->d_type == DT_DIR)
fileStartPos++;
}
}

Expand Down Expand Up @@ -1923,6 +1928,13 @@ std::string browseForFile(const std::vector<std::string_view> 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);
}

Expand Down
11 changes: 11 additions & 0 deletions romsel_dsimenutheme/arm9/source/fileBrowse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -267,6 +268,7 @@ void getDirectoryContents(std::vector<DirEntry> &dirContents, const std::vector<
dirContents.clear();

file_count = 0;
fileStartPos = 0;

if (access("dirInfo.twlm.ini", F_OK) == 0) {
dirInfoIniFound = true;
Expand Down Expand Up @@ -354,6 +356,9 @@ void getDirectoryContents(std::vector<DirEntry> &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();
Expand Down Expand Up @@ -3967,6 +3972,12 @@ std::string browseForFile(const std::vector<std::string_view> 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) {
Expand Down
13 changes: 13 additions & 0 deletions romsel_r4theme/arm9/source/fileBrowse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -174,6 +176,8 @@ void getDirectoryContents(std::vector<DirEntry> &dirContents, const std::vector<
iprintf("Unable to open the directory.\n");
} else {
int file_count = 0;
fileStartPos = 0;

while (1) {
bgOperations(false);

Expand Down Expand Up @@ -240,6 +244,9 @@ void getDirectoryContents(std::vector<DirEntry> &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++;
}
}

Expand Down Expand Up @@ -1497,6 +1504,12 @@ std::string browseForFile(const std::vector<std::string_view> 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
Expand Down
Loading