From 97d1c0aa6f9d7a30d9885b3b858cc9c2fb5847ac Mon Sep 17 00:00:00 2001
From: lantzelot-swe <75668734+lantzelot-swe@users.noreply.github.com>
Date: Wed, 22 Jun 2022 22:51:31 +0200
Subject: [PATCH] feat: add support for saved states for games exported to file
loader
-Add option in preferences to show saved states for file loader
-Add tool to copy saved states for the 1.5.2 Carousel to File Loader
fix: trim and remove any " character from the title, author and composer fileds when saving a game.
---
.../lantz/gui/GameDetailsBackgroundPanel.java | 8 +-
.../se/lantz/gui/GameListDataRenderer.java | 2 +-
src/main/java/se/lantz/gui/MenuManager.java | 60 +++++++
.../java/se/lantz/gui/SaveStatePanel.java | 2 +-
.../gui/preferences/PreferencesDialog.java | 2 +-
.../gui/preferences/SaveStatePrefPanel.java | 39 ++++-
.../se/lantz/manager/SavedStatesManager.java | 154 ++++++++++++++++--
src/main/java/se/lantz/model/InfoModel.java | 9 +-
.../java/se/lantz/model/PreferencesModel.java | 1 +
src/main/java/se/lantz/util/FileManager.java | 29 +++-
10 files changed, 279 insertions(+), 27 deletions(-)
diff --git a/src/main/java/se/lantz/gui/GameDetailsBackgroundPanel.java b/src/main/java/se/lantz/gui/GameDetailsBackgroundPanel.java
index e3b609d..21d5807 100644
--- a/src/main/java/se/lantz/gui/GameDetailsBackgroundPanel.java
+++ b/src/main/java/se/lantz/gui/GameDetailsBackgroundPanel.java
@@ -42,6 +42,7 @@ import se.lantz.gui.translation.TranslationProgressDialog;
import se.lantz.gui.translation.TranslationWorker;
import se.lantz.manager.ScraperManager;
import se.lantz.model.MainViewModel;
+import se.lantz.model.PreferencesModel;
import se.lantz.model.data.GameListData;
import se.lantz.model.data.ScraperFields;
import se.lantz.util.FileManager;
@@ -506,7 +507,12 @@ public class GameDetailsBackgroundPanel extends JPanel
public void updateSavedStatesTabTitle()
{
String carouselVersion = FileManager.getConfiguredSavedStatesCarouselVersion();
- getSystemSavesTabbedPane().setTitleAt(1, "Saved States (Carousel " + carouselVersion + ")");
+ String title = "Saved States (Carousel " + carouselVersion + ")";
+ if (carouselVersion.equals(PreferencesModel.FILE_LOADER))
+ {
+ title = "Saved States (File Loader)";
+ }
+ getSystemSavesTabbedPane().setTitleAt(1, title);
getSavesBackgroundPanel().resetCurrentGameReference();
}
}
diff --git a/src/main/java/se/lantz/gui/GameListDataRenderer.java b/src/main/java/se/lantz/gui/GameListDataRenderer.java
index 9bac1d0..cd55310 100644
--- a/src/main/java/se/lantz/gui/GameListDataRenderer.java
+++ b/src/main/java/se/lantz/gui/GameListDataRenderer.java
@@ -131,7 +131,7 @@ public class GameListDataRenderer extends DefaultListCellRenderer
}
else
{
- int numberOfSavedStates = savedStatesManager.getNumberOfSavedStatesForGame(listData.getGameFileName());
+ int numberOfSavedStates = savedStatesManager.getNumberOfSavedStatesForGame(listData.getGameFileName(), listData.getTitle());
if (numberOfSavedStates == 1)
{
this.setIcon(saves1Icon);
diff --git a/src/main/java/se/lantz/gui/MenuManager.java b/src/main/java/se/lantz/gui/MenuManager.java
index 7802327..d3b8c81 100644
--- a/src/main/java/se/lantz/gui/MenuManager.java
+++ b/src/main/java/se/lantz/gui/MenuManager.java
@@ -114,6 +114,7 @@ public class MenuManager
private JMenuItem validateDbItem;
private JMenuItem palNtscFixItem;
private JMenuItem convertSavedStatesItem;
+ private JMenuItem copySavedStatesItem;
private JMenuItem resetJoystickConfigItem;
private JMenuItem installPCUAEItem;
@@ -209,6 +210,7 @@ public class MenuManager
toolsMenu.add(getDeleteGamesForViewMenuItem());
toolsMenu.addSeparator();
toolsMenu.add(getConvertSavedStatesItem());
+ toolsMenu.add(getCopySavedStatesToFileLoaderItem());
toolsMenu.add(getResetJoystickConfigItem());
toolsMenu.addSeparator();
toolsMenu.add(getPalNtscFixMenuItem());
@@ -815,6 +817,18 @@ public class MenuManager
}
return convertSavedStatesItem;
}
+
+ private JMenuItem getCopySavedStatesToFileLoaderItem()
+ {
+
+ if (copySavedStatesItem == null)
+ {
+ copySavedStatesItem = new JMenuItem("Copy Saved states to File Loader...");
+ copySavedStatesItem.setMnemonic('f');
+ copySavedStatesItem.addActionListener(e -> copySavedStatesFromCarouselToFileLoader());
+ }
+ return copySavedStatesItem;
+ }
private JMenuItem getResetJoystickConfigItem()
{
@@ -1289,6 +1303,52 @@ public class MenuManager
}
}
}
+
+ private void copySavedStatesFromCarouselToFileLoader()
+ {
+
+ JOptionPane.showMessageDialog(MainWindow.getInstance().getMainPanel(),
+ "A Carousel saves the saved states for a game in a folder named after the game file name.
When exporting games to File Loader the " +
+ "file name will be based on the title for the game, so the carousel saved states
will not be available for exported games.
With this " +
+ "function you can copy existing saved states for the games in the carousel to a new folder that the File loader will find.
It will check all " +
+ "imported saved states and match them towards available games in the manager and create a new folder in the saves directory.
You can then export the saved states to your USB stick to use them in the File Loader.
Press OK to check for saved states that can be copied.",
+ "Copy saved states to File Loader",
+ JOptionPane.INFORMATION_MESSAGE);
+
+
+ int numberOfSavesNotAvailableForFileLoader = savedStatesManager.checkForSavedStatesToCopyToFileLoader();
+
+ if (numberOfSavesNotAvailableForFileLoader == 0)
+ {
+ JOptionPane.showMessageDialog(MainWindow.getInstance().getMainPanel(),
+ "No carousel saved states exists that are not available for File Loader. All is up to date.",
+ "Copy saved states to File Loader",
+ JOptionPane.INFORMATION_MESSAGE);
+ }
+ else
+ {
+ String message = String
+ .format("There are %s games that have saved states used by the Carousel version 1.5.2 or later.
Do you want to copy them to the File Loader format so that they are accessible from the File Loader?",
+ Integer.valueOf(numberOfSavesNotAvailableForFileLoader));
+ int option = JOptionPane.showConfirmDialog(MainWindow.getInstance().getMainPanel(),
+ message,
+ "Copy saved states to File Loader",
+ JOptionPane.YES_NO_OPTION,
+ JOptionPane.QUESTION_MESSAGE);
+ if (option == JOptionPane.YES_OPTION)
+ {
+ savedStatesManager.copyFromCarouselToFileLoader();
+ //Refresh after converting
+ MainWindow.getInstance().refreshMenuAndUI();
+ //Refresh game views
+ uiModel.reloadGameViews();
+ //Set all games as selected
+ uiModel.setSelectedGameView(null);
+ }
+ }
+
+
+ }
private void resetJoystickConfigs()
{
diff --git a/src/main/java/se/lantz/gui/SaveStatePanel.java b/src/main/java/se/lantz/gui/SaveStatePanel.java
index 37816c7..a5b5778 100644
--- a/src/main/java/se/lantz/gui/SaveStatePanel.java
+++ b/src/main/java/se/lantz/gui/SaveStatePanel.java
@@ -311,7 +311,7 @@ public class SaveStatePanel extends JPanel
BufferedImage image = null;
if (!filename.isEmpty())
{
- String fileName = SavedStatesManager.getGameFolderName(model.getInfoModel().getGamesFile());
+ String fileName = SavedStatesManager.getGameFolderName(model.getInfoModel().getGamesFile(), model.getInfoModel().getTitle());
logger.debug(fileName.toString());
Path saveFolderPath = new File("./saves/" + fileName).toPath();
diff --git a/src/main/java/se/lantz/gui/preferences/PreferencesDialog.java b/src/main/java/se/lantz/gui/preferences/PreferencesDialog.java
index b8d7367..ba6a206 100644
--- a/src/main/java/se/lantz/gui/preferences/PreferencesDialog.java
+++ b/src/main/java/se/lantz/gui/preferences/PreferencesDialog.java
@@ -16,7 +16,7 @@ public class PreferencesDialog extends BaseDialog
addContent(getPreferencesTabPanel());
getOkButton().setText("Save");
getOkButton().setPreferredSize(null);
- this.setPreferredSize(new Dimension(366, 580));
+ this.setPreferredSize(new Dimension(366, 630));
this.setResizable(false);
}
diff --git a/src/main/java/se/lantz/gui/preferences/SaveStatePrefPanel.java b/src/main/java/se/lantz/gui/preferences/SaveStatePrefPanel.java
index 9e1a619..364f802 100644
--- a/src/main/java/se/lantz/gui/preferences/SaveStatePrefPanel.java
+++ b/src/main/java/se/lantz/gui/preferences/SaveStatePrefPanel.java
@@ -21,6 +21,7 @@ public class SaveStatePrefPanel extends JPanel
private JRadioButton v152RadioButton;
private final ButtonGroup buttonGroup = new ButtonGroup();
private PreferencesModel model;
+ private JRadioButton fileLoaderRadioButton;
public SaveStatePrefPanel(PreferencesModel model)
{
@@ -43,13 +44,21 @@ public class SaveStatePrefPanel extends JPanel
gbc_v132RadioButton.gridy = 1;
add(getV132RadioButton(), gbc_v132RadioButton);
GridBagConstraints gbc_v152RadioButton = new GridBagConstraints();
- gbc_v152RadioButton.weighty = 1.0;
- gbc_v152RadioButton.insets = new Insets(0, 40, 10, 0);
+ gbc_v152RadioButton.weighty = 0.0;
+ gbc_v152RadioButton.insets = new Insets(0, 40, 0, 0);
gbc_v152RadioButton.anchor = GridBagConstraints.NORTHWEST;
gbc_v152RadioButton.weightx = 1.0;
gbc_v152RadioButton.gridx = 0;
gbc_v152RadioButton.gridy = 2;
add(getV152RadioButton(), gbc_v152RadioButton);
+ GridBagConstraints gbc_fileLoaderRadioButton = new GridBagConstraints();
+ gbc_fileLoaderRadioButton.insets = new Insets(0, 40, 10, 0);
+ gbc_fileLoaderRadioButton.anchor = GridBagConstraints.NORTHWEST;
+ gbc_fileLoaderRadioButton.gridx = 0;
+ gbc_fileLoaderRadioButton.gridy = 3;
+ gbc_fileLoaderRadioButton.weightx = 1.0;
+ gbc_fileLoaderRadioButton.weighty = 1.0;
+ add(getFileLoaderRadioButton(), gbc_fileLoaderRadioButton);
if (!Beans.isDesignTime())
{
model.addPropertyChangeListener(e -> modelChanged());
@@ -63,8 +72,8 @@ public class SaveStatePrefPanel extends JPanel
if (infoLabel == null)
{
String info = "Different versions of the Carousel adds the saved states in different folders. " +
- "You have to choose which version of the Carousel you want the manager to read the saved states for. " +
- "Only saved states for one carousel version at a time is shown for the games in the gamelist views.";
+ "You have to choose which version of the Carousel (or the File Loader) you want the manager to read the saved states for. " +
+ "Only saved states for one option at a time is shown for the games in the gamelist views. Saved states for the File loader is located in a folder mathching the game title.