Skip to content
This repository has been archived by the owner on Aug 20, 2022. It is now read-only.

Commit

Permalink
When a game is moved to a different game menu, ti gets sorted alphabe…
Browse files Browse the repository at this point in the history
…tically in its new menu.
  • Loading branch information
mpaterakis committed Jul 6, 2019
1 parent 9fe3b0b commit ecbc1dd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/UI/GameSettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,19 +359,33 @@ private void doMoveToGameMenu(int newMenuIndex) {
yesButton.setBackground(new Color(209, 209, 209));
yesButton.setFocusPainted(false);
yesButton.addActionListener((ActionEvent actionEvent) -> {
// Get array index of previous (alphabetically) game
ArrayList<String> gameNames = new ArrayList<>();
mainFrame.getGameLabelLists().get(newMenuIndex).forEach((currentGameLabel) -> {
gameNames.add(currentGameLabel.getGame().getGameName());
});

// Compare game names
int previousGameIndex = -1;
for (int i = 0; i < gameNames.size(); i++) {
if (gameNames.get(i).compareTo(game.getGameName()) <= 0) {
previousGameIndex = i;
}
}

// Get gameLabels, remove this instance and move it to the new gameLabels list
mainFrame.getActiveGameLabels().remove(gameLabel);
mainFrame.getGameLabelLists().get(newMenuIndex).add(gameLabel);
mainFrame.getGameLabelLists().get(newMenuIndex).add(previousGameIndex + 1, gameLabel);

// If the gameLabels list is empty, remove it
if (mainFrame.getActiveGameLabels().isEmpty()) {
mainFrame.getGameLabelLists().remove(mainFrame.getActiveGameLabels());
mainFrame.goToGameMenu(newMenuIndex);
}

// Reload GameLabels
mainFrame.redrawGameGridPanel(mainFrame.getActiveGameLabels());

// Close the dialogs
SwingUtilities.getWindowAncestor(yesButton).dispose();
dispose();
Expand Down
3 changes: 2 additions & 1 deletion src/UI/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -939,12 +939,13 @@ private void doDropFile(java.io.File[] files) {
// Create new GameLabel object
GameLabel gameLabel = new GameLabel(new Game(iconFile, files[0].getAbsoluteFile().getAbsolutePath(), this.gameName, frameScale), this);

// Get array index of previous (alphabetically) game
ArrayList<String> gameNames = new ArrayList<>();
activeGameLabels.forEach((currentGameLabel) -> {
gameNames.add(currentGameLabel.getGame().getGameName());
});

// Get array index of previous (alphabetically) game
// Compare game names
int previousGameIndex = -1;
for (int i = 0; i < gameNames.size(); i++) {
if (gameNames.get(i).compareTo(this.gameName) <= 0) {
Expand Down

0 comments on commit ecbc1dd

Please sign in to comment.