Skip to content

Commit

Permalink
Fix for issue where navigation by first letter didn't work for some l…
Browse files Browse the repository at this point in the history
…etters. Two separate contributing causes.
  • Loading branch information
lanceewing committed Apr 4, 2024
1 parent 352c25b commit a5c8e04
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
33 changes: 23 additions & 10 deletions core/src/main/java/com/agifans/agile/HomeScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -836,14 +836,25 @@ public void inputTextResult(boolean success, String text) {
}

private int getIndexOfFirstGameStartingWithChar(char letter) {
// Ignore the original Sierra AGI games, as they're all on the first page.
int gameIndex = 14;
for (String gameName : appConfigMap.keySet()) {
gameIndex++;
if (gameName.toUpperCase().startsWith("" + letter)) {
return gameIndex;
int gameIndex = 0;

for (int loopCount=0; loopCount < 2; loopCount++) {
for (AppConfigItem appConfigItem : appConfigMap.values()) {
String gameId = appConfigItem.getGameId().toLowerCase();
if (((loopCount == 0) && (SIERRA_GAMES.contains(gameId))) ||
((loopCount == 1) && (!SIERRA_GAMES.contains(gameId)))) {
gameIndex++;
// Ignore the original Sierra AGI games, as they're all on the first page.
if (loopCount == 1) {
String gameName = appConfigItem.getName();
if (gameName.toUpperCase().startsWith("" + letter)) {
return gameIndex;
}
}
}
}
}

return -1;
}

Expand Down Expand Up @@ -871,15 +882,17 @@ private void showGamePage(AppConfigItem appConfigItem) {
}

private void showGamePage(int gameIndex, boolean skipScroll) {
// Work out how far to move from far left to get to game's page.
float pageWidth = viewportManager.isPortrait()? 1130.0f : 1970.0f;
float newScrollX = pageWidth * (gameIndex / 15);

// Apply scroll X without animating, i.e. move immediately to the page.
Stage currentStage = viewportManager.isPortrait()? portraitStage : landscapeStage;
PagedScrollPane pagedScrollPane = (PagedScrollPane)
((Table)currentStage.getActors().get(0)).getChild(0);
currentStage.act(0f);

// Work out how far to move from far left to get to game's page.
int gamesPerPage = pagedScrollPane.getGamesPerPage();
float pageWidth = viewportManager.isPortrait()? 1130.0f : 1970.0f;
float newScrollX = pageWidth * (gameIndex / gamesPerPage);

pagedScrollPane.setScrollX(newScrollX);
pagedScrollPane.setLastScrollX(newScrollX);
if (skipScroll) {
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/com/agifans/agile/ui/PagedScrollPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ public void reset() {
setScrollX(0);
}

public int getGamesPerPage() {
int gamesPerPage = 0;
if (content.getChildren().notEmpty()) {
Table firstPage = (Table)content.getChild(0);
gamesPerPage = firstPage.getColumns() * firstPage.getRows();
}
return gamesPerPage;
}

public int getNumOfPages() {
return content.getChildren().size;
}
Expand Down

0 comments on commit a5c8e04

Please sign in to comment.