fix: add cover images for favorites 1-10 info slots.

Changing the system setting (c64 or Vic-20) changes the cover for an info slot to the generic version for that system.
This commit is contained in:
lantzelot-swe 2022-01-07 09:44:22 +01:00
parent 0990f80b95
commit 72b7c6def5
18 changed files with 121 additions and 25 deletions

View File

@ -296,11 +296,11 @@ public class GameDetailsBackgroundPanel extends JPanel
{ {
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{ {
//Make sure any edits to time for saved states are commited. //Make sure any edits to time for saved states are committed.
savesBackgroundPanel.commitEdits(); savesBackgroundPanel.commitEdits();
if (model.saveData()) if (model.saveData())
{ {
getInfoBackgroundPanel().getScreensPanel().resetWhenSaved(); getInfoBackgroundPanel().getScreensPanel().resetWhenSavedOrNewGameSelected();
} }
} }
}); });

View File

@ -12,6 +12,7 @@ import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.beans.Beans; import java.beans.Beans;
import java.beans.PropertyChangeEvent;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
@ -117,13 +118,15 @@ public class ScreenshotsPanel extends JPanel
add(getGamePanel(), gbc_gamePanel); add(getGamePanel(), gbc_gamePanel);
if (!Beans.isDesignTime()) if (!Beans.isDesignTime())
{ {
infomodel.addPropertyChangeListener((e) -> modelChanged()); infomodel.addPropertyChangeListener(e -> modelChanged());
//React on changes to system, C64 or Vic-20 //React on changes to system, C64 or Vic-20
model.getSystemModel().addPropertyChangeListener((e) -> modelChanged()); model.getSystemModel().addPropertyChangeListener("c64", e -> systemChanged(e));
//React on when a new game is selected
model.addPropertyChangeListener("gameSelected", e -> resetWhenSavedOrNewGameSelected());
} }
} }
public void resetWhenSaved() public void resetWhenSavedOrNewGameSelected()
{ {
currentCoverFile = ""; currentCoverFile = "";
currentScreen1File = ""; currentScreen1File = "";
@ -147,6 +150,16 @@ public class ScreenshotsPanel extends JPanel
reloadScreens(); reloadScreens();
} }
private void systemChanged(PropertyChangeEvent e)
{
//Update cover info slot when the system type changes, but only for custom views and all games (id > -2)
if (infomodel.isInfoSlot() && model.getSelectedGameView().getGameViewId() > -2)
{
infomodel
.setCoverImage((boolean) e.getNewValue() ? FileManager.infoSlotC64Cover : FileManager.infoSlotVic20Cover);
}
}
private String getGameFileName() private String getGameFileName()
{ {
String returnValue = infomodel.getGamesFile(); String returnValue = infomodel.getGamesFile();
@ -159,7 +172,6 @@ public class ScreenshotsPanel extends JPanel
private void reloadScreens() private void reloadScreens()
{ {
// Cover
BufferedImage coverImage = infomodel.getCoverImage(); BufferedImage coverImage = infomodel.getCoverImage();
if (coverImage != null) if (coverImage != null)
{ {
@ -177,7 +189,7 @@ public class ScreenshotsPanel extends JPanel
if (modelCoverFile.isEmpty()) if (modelCoverFile.isEmpty())
{ {
currentCoverFile = ""; currentCoverFile = "";
getCoverImageLabel().setIcon(getMissingCoverImageIcon()); getCoverImageLabel().setIcon(getDefaultCoverImageIcon());
} }
else if (!modelCoverFile.equals(currentCoverFile)) else if (!modelCoverFile.equals(currentCoverFile))
{ {
@ -185,6 +197,7 @@ public class ScreenshotsPanel extends JPanel
currentCoverFile = modelCoverFile; currentCoverFile = modelCoverFile;
} }
} }
// Screen 1 // Screen 1
BufferedImage screen1Image = infomodel.getScreen1Image(); BufferedImage screen1Image = infomodel.getScreen1Image();
if (screen1Image != null) if (screen1Image != null)
@ -269,12 +282,12 @@ public class ScreenshotsPanel extends JPanel
catch (IOException e) catch (IOException e)
{ {
logger.error("can't read file: " + filename, e); logger.error("can't read file: " + filename, e);
getCoverImageLabel().setIcon(getMissingCoverImageIcon()); getCoverImageLabel().setIcon(getDefaultCoverImageIcon());
} }
} }
else else
{ {
getCoverImageLabel().setIcon(getMissingCoverImageIcon()); getCoverImageLabel().setIcon(getDefaultCoverImageIcon());
} }
} }
@ -313,7 +326,7 @@ public class ScreenshotsPanel extends JPanel
return missingSceenshotIcon; return missingSceenshotIcon;
} }
private ImageIcon getMissingCoverImageIcon() private ImageIcon getDefaultCoverImageIcon()
{ {
if (missingC64CoverIcon == null) if (missingC64CoverIcon == null)
{ {
@ -767,12 +780,14 @@ public class ScreenshotsPanel extends JPanel
{ {
//Ask if text shall be added //Ask if text shall be added
int value = JOptionPane.showConfirmDialog(getScreenshotPanel(), int value = JOptionPane.showConfirmDialog(getScreenshotPanel(),
"Do you want to add the gamelist view name to the screenshot?", "Do you want to add the gamelist view name to the screenshot?",
"Screenshot file", "Screenshot file",
JOptionPane.YES_NO_OPTION, JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
if (value == JOptionPane.YES_OPTION) if (value == JOptionPane.YES_OPTION)
{ {
//Make sure the image is of right size vefore adding text to it
returnImage = FileManager.scaleImageTo320x200x32bit(returnImage);
model.writeGameViewTextOnScreen(returnImage, first ? Color.yellow : Color.red); model.writeGameViewTextOnScreen(returnImage, first ? Color.yellow : Color.red);
} }
} }
@ -812,8 +827,18 @@ public class ScreenshotsPanel extends JPanel
} }
fileChooser.setCurrentDirectory(new File(gameDir)); fileChooser.setCurrentDirectory(new File(gameDir));
FileNameExtensionFilter vicefilter = FileNameExtensionFilter vicefilter = new FileNameExtensionFilter("Vice runnable files",
new FileNameExtensionFilter("Vice runnable files", "d64", "t64", "tap", "VSF", "VSZ", "GZ", "crt", "prg", "g64", "d81", "d82"); "d64",
"t64",
"tap",
"VSF",
"VSZ",
"GZ",
"crt",
"prg",
"g64",
"d81",
"d82");
fileChooser.addChoosableFileFilter(vicefilter); fileChooser.addChoosableFileFilter(vicefilter);
fileChooser.setFileFilter(vicefilter); fileChooser.setFileFilter(vicefilter);
int value = fileChooser.showOpenDialog(MainWindow.getInstance()); int value = fileChooser.showOpenDialog(MainWindow.getInstance());
@ -868,11 +893,13 @@ public class ScreenshotsPanel extends JPanel
FileManager.getConfiguredProperties().put(SCREENS_DIR_PROPERTY, selectedFile.toPath().getParent().toString()); FileManager.getConfiguredProperties().put(SCREENS_DIR_PROPERTY, selectedFile.toPath().getParent().toString());
if (first) if (first)
{ {
infomodel.setScreen1Image(handleScreenFileDrop(new File[] { selectedFile }, screen1ImageLabel, edit1Button, true)); infomodel
.setScreen1Image(handleScreenFileDrop(new File[] { selectedFile }, screen1ImageLabel, edit1Button, true));
} }
else else
{ {
infomodel.setScreen2Image(handleScreenFileDrop(new File[] { selectedFile }, screen2ImageLabel, edit2Button, false)); infomodel
.setScreen2Image(handleScreenFileDrop(new File[] { selectedFile }, screen2ImageLabel, edit2Button, false));
} }
} }
} }

View File

@ -22,6 +22,11 @@ public abstract class AbstractModel
{ {
propertyChangeSupport.addPropertyChangeListener(listener); propertyChangeSupport.addPropertyChangeListener(listener);
} }
public void addPropertyChangeListener(String property, PropertyChangeListener listener)
{
propertyChangeSupport.addPropertyChangeListener(property, listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) public void removePropertyChangeListener(PropertyChangeListener listener)
{ {
@ -36,6 +41,24 @@ public abstract class AbstractModel
propertyChangeSupport.firePropertyChange("notify", null, ""); propertyChangeSupport.firePropertyChange("notify", null, "");
} }
} }
protected void notifyChange(String property, boolean oldValue, boolean newValue)
{
if (!disable)
{
dataChanged = true;
propertyChangeSupport.firePropertyChange(property, oldValue, newValue);
}
}
protected void notifyChange(String property, String oldValue, String newValue)
{
if (!disable)
{
dataChanged = true;
propertyChangeSupport.firePropertyChange(property, oldValue, newValue);
}
}
public boolean isDataChanged() public boolean isDataChanged()
{ {

View File

@ -278,6 +278,8 @@ public class MainViewModel extends AbstractModel
//Trigger a save directly when adding a info slot //Trigger a save directly when adding a info slot
saveData(); saveData();
} }
//Notify that a new game has been selected
notifyChange("gameSelected", null, "");
} }
public StringBuilder importGameInfo(List<String> rowValues, public StringBuilder importGameInfo(List<String> rowValues,
@ -910,7 +912,7 @@ public class MainViewModel extends AbstractModel
infoModel.resetOldFileNames(); infoModel.resetOldFileNames();
//Cover image //Cover image
infoModel.setCoverImage(FileManager.getInfoSlotCoverImage()); infoModel.setCoverImage(FileManager.getInfoSlotCover(this.selectedGameView.getGameViewId()));
//Screen images //Screen images
BufferedImage screenImage1 = FileManager.getInfoSlotScreenImage(true); BufferedImage screenImage1 = FileManager.getInfoSlotScreenImage(true);
writeGameViewTextOnScreen(screenImage1, Color.yellow); writeGameViewTextOnScreen(screenImage1, Color.yellow);
@ -920,7 +922,7 @@ public class MainViewModel extends AbstractModel
writeGameViewTextOnScreen(screenImage2, Color.red); writeGameViewTextOnScreen(screenImage2, Color.red);
infoModel.setScreen2Image(screenImage2); infoModel.setScreen2Image(screenImage2);
} }
public void writeGameViewTextOnScreen(BufferedImage image, Color color) public void writeGameViewTextOnScreen(BufferedImage image, Color color)
{ {
String title = this.selectedGameView.getName().toUpperCase(); String title = this.selectedGameView.getName().toUpperCase();

View File

@ -319,7 +319,8 @@ public class SystemModel extends AbstractModel
} }
if ((Boolean.compare(old, c64) != 0)) if ((Boolean.compare(old, c64) != 0))
{ {
notifyChange(); //Notify with explicit values to be able to react on this in ScreenshotsPanel.
notifyChange("c64", old, c64);
} }
} }
@ -338,7 +339,8 @@ public class SystemModel extends AbstractModel
} }
if ((Boolean.compare(old, vic) != 0)) if ((Boolean.compare(old, vic) != 0))
{ {
notifyChange(); //Notify with explicit values to be able to react on this in ScreenshotsPanel.
notifyChange("c64", !old, !vic);
} }
} }

View File

@ -54,6 +54,7 @@ import se.lantz.model.SavedStatesModel.SAVESTATE;
import se.lantz.model.SystemModel; import se.lantz.model.SystemModel;
import se.lantz.model.data.GameDetails; import se.lantz.model.data.GameDetails;
import se.lantz.model.data.GameValidationDetails; import se.lantz.model.data.GameValidationDetails;
import se.lantz.model.data.GameView;
public class FileManager public class FileManager
{ {
@ -62,6 +63,9 @@ public class FileManager
public static BufferedImage emptyC64Screenshot; public static BufferedImage emptyC64Screenshot;
public static BufferedImage emptyVic20Screenshot; public static BufferedImage emptyVic20Screenshot;
public static BufferedImage infoSlotC64Cover;
public static BufferedImage infoSlotVic20Cover;
public static final String GAMES = "./games/"; public static final String GAMES = "./games/";
private static final String SCREENS = "./screens/"; private static final String SCREENS = "./screens/";
private static final String COVERS = "./covers/"; private static final String COVERS = "./covers/";
@ -90,6 +94,8 @@ public class FileManager
emptyVic20Cover = ImageIO.read(FileManager.class.getResource("/se/lantz/CoverMissing-VIC20.png")); emptyVic20Cover = ImageIO.read(FileManager.class.getResource("/se/lantz/CoverMissing-VIC20.png"));
emptyC64Screenshot = ImageIO.read(FileManager.class.getResource("/se/lantz/MissingScreenshot-C64.png")); emptyC64Screenshot = ImageIO.read(FileManager.class.getResource("/se/lantz/MissingScreenshot-C64.png"));
emptyVic20Screenshot = ImageIO.read(FileManager.class.getResource("/se/lantz/MissingScreenshot-VIC20.png")); emptyVic20Screenshot = ImageIO.read(FileManager.class.getResource("/se/lantz/MissingScreenshot-VIC20.png"));
infoSlotC64Cover = ImageIO.read(FileManager.class.getResource("/se/lantz/InfoSlotC64Cover.png"));
infoSlotVic20Cover = ImageIO.read(FileManager.class.getResource("/se/lantz/InfoSlotVic20Cover.png"));
} }
catch (IOException e) catch (IOException e)
{ {
@ -115,16 +121,52 @@ public class FileManager
return FileManager.class.getResourceAsStream("/se/lantz/MissingGame-Vic20.vsf.gz"); return FileManager.class.getResourceAsStream("/se/lantz/MissingGame-Vic20.vsf.gz");
} }
public static BufferedImage getInfoSlotCoverImage() public static BufferedImage getInfoSlotCover(int gameViewId)
{ {
BufferedImage coverImage = null; BufferedImage coverImage = null;
String coverName = "InfoSlotC64Cover.png";
switch (gameViewId)
{
case GameView.FAVORITES_ID:
coverName = "InfoSlotF1Cover.png";
break;
case GameView.FAVORITES_2_ID:
coverName = "InfoSlotF2Cover.png";
break;
case GameView.FAVORITES_3_ID:
coverName = "InfoSlotF3Cover.png";
break;
case GameView.FAVORITES_4_ID:
coverName = "InfoSlotF4Cover.png";
break;
case GameView.FAVORITES_5_ID:
coverName = "InfoSlotF5Cover.png";
break;
case GameView.FAVORITES_6_ID:
coverName = "InfoSlotF6Cover.png";
break;
case GameView.FAVORITES_7_ID:
coverName = "InfoSlotF7Cover.png";
break;
case GameView.FAVORITES_8_ID:
coverName = "InfoSlotF8Cover.png";
break;
case GameView.FAVORITES_9_ID:
coverName = "InfoSlotF9Cover.png";
break;
case GameView.FAVORITES_10_ID:
coverName = "InfoSlotF10Cover.png";
break;
default:
break;
}
try try
{ {
coverImage = ImageIO.read(FileManager.class.getResource("/se/lantz/InfoSlotCover.png")); coverImage = ImageIO.read(FileManager.class.getResource("/se/lantz/" + coverName));
} }
catch (IOException e) catch (IOException e)
{ {
ExceptionHandler.handleException(e, "Could not read cover image."); ExceptionHandler.handleException(e, "Could not read info slot cover image.");
} }
return coverImage; return coverImage;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB