Skip to content

Commit

Permalink
Fixed cursor behavior when sorting by recently played (#2430)
Browse files Browse the repository at this point in the history
  • Loading branch information
mentusfentus committed Jun 10, 2024
1 parent ccab1ab commit 62458dd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
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

0 comments on commit 62458dd

Please sign in to comment.