Skip to content

Commit 1ea206a

Browse files
committed
feat: carousel preview VIP
1 parent 13e8321 commit 1ea206a

12 files changed

+339
-34
lines changed
839 KB
Loading

src/main/java/se/lantz/gui/ListPanel.java

+22-3
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ else if (gameListViewId < -1)
275275

276276
}
277277
});
278-
279-
listViewEditButton.setToolTipText("<html>Manage gamelist views</html>" );
278+
279+
listViewEditButton.setToolTipText("<html>Manage gamelist views</html>");
280280
}
281281
return listViewEditButton;
282282
}
@@ -387,6 +387,25 @@ void setSelectedIndexInList(int index)
387387
list.ensureIndexIsVisible(indexToSelect);
388388
}
389389

390+
public void setSelectedGameInGameList(String gameId)
391+
{
392+
List<GameListData> currentGameList = uiModel.getGameListModel().getCurrentGameList();
393+
for (int i = 0; i < currentGameList.size(); i++)
394+
{
395+
if (currentGameList.get(i).getGameId().equals(gameId))
396+
{
397+
int indexToSelect = i;
398+
if (i >= uiModel.getGameListModel().getSize())
399+
{
400+
indexToSelect = uiModel.getGameListModel().getSize() - 1;
401+
}
402+
list.setSelectionInterval(indexToSelect, indexToSelect);
403+
list.ensureIndexIsVisible(indexToSelect);
404+
break;
405+
}
406+
}
407+
}
408+
390409
public void clearGameListSelection()
391410
{
392411
list.clearSelection();
@@ -829,7 +848,7 @@ public void setViewTag(String viewTag)
829848
mainPanel.repaintAfterModifications();
830849
}
831850
}
832-
851+
833852
public void reloadCurrentGameView()
834853
{
835854
GameListData selectedData = getList().getSelectedValue();

src/main/java/se/lantz/gui/MainPanel.java

+5
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,9 @@ public void updateSavedStatesTabTitle()
284284
{
285285
getGameDetailsBackgroundPanel().updateSavedStatesTabTitle();
286286
}
287+
288+
public void setSelectedGameInGameList(String gameId)
289+
{
290+
getListPanel().setSelectedGameInGameList(gameId);
291+
}
287292
}

src/main/java/se/lantz/gui/MainWindow.java

+5
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,9 @@ public void checkForNewPCUAEVersionAtStartup()
145145
{
146146
this.menuManager.checkForNewPCUAEVersionAtStartup();
147147
}
148+
149+
public void setSelectedGameInGameList(String gameId)
150+
{
151+
getMainPanel().setSelectedGameInGameList(gameId);
152+
}
148153
}

src/main/java/se/lantz/gui/carousel/BackgroundPanel.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import javax.swing.JButton;
99
import javax.swing.JPanel;
1010

11+
import se.lantz.gui.MainWindow;
1112
import se.lantz.model.MainViewModel;
1213
import se.lantz.model.carousel.CarouselPreviewModel;
1314
import se.lantz.model.data.GameDetails;
@@ -25,9 +26,11 @@
2526

2627
public class BackgroundPanel extends JPanel {
2728
private CarouselPreviewModel model;
29+
private MainWindow mainWindow;
2830

29-
public BackgroundPanel(final MainViewModel uiModel) {
30-
model = new CarouselPreviewModel(uiModel);
31+
public BackgroundPanel(final CarouselPreviewModel model, final MainWindow mainWindow) {
32+
this.mainWindow = mainWindow;
33+
this.model = model;
3134

3235
GridBagLayout gridBagLayout = new GridBagLayout();
3336
setLayout(gridBagLayout);
@@ -67,6 +70,10 @@ public BackgroundPanel(final MainViewModel uiModel) {
6770

6871
private void reloadScreens()
6972
{
73+
if (model.getSelectedGame() == null)
74+
{
75+
return;
76+
}
7077
String filename = model.getSelectedGame().getScreen1();
7178
BufferedImage image = null;
7279
if (!filename.isEmpty())
@@ -135,8 +142,14 @@ private TextPanel getTextPanel() {
135142
}
136143
private CoverPanel getCoverPanel() {
137144
if (coverPanel == null) {
138-
coverPanel = new CoverPanel();
145+
coverPanel = new CoverPanel(model, this.mainWindow);
139146
}
140147
return coverPanel;
141148
}
149+
150+
public void initialScroll()
151+
{
152+
//Scroll one game
153+
getCoverPanel().scrollToPosition();
154+
}
142155
}

src/main/java/se/lantz/gui/carousel/CarouselPreviewDialog.java

+19-2
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@
55
import java.beans.Beans;
66

77
import se.lantz.gui.BaseDialog;
8+
import se.lantz.gui.MainWindow;
89
import se.lantz.model.MainViewModel;
10+
import se.lantz.model.carousel.CarouselPreviewModel;
911

1012
public class CarouselPreviewDialog extends BaseDialog
1113
{
1214
private BackgroundPanel panel;
1315
private MainViewModel uiModel;
16+
private MainWindow mainWindow;
17+
private CarouselPreviewModel model;
1418

15-
public CarouselPreviewDialog(final Frame owner, final MainViewModel uiModel)
19+
public CarouselPreviewDialog(final MainWindow owner, final MainViewModel uiModel)
1620
{
1721
super(owner);
22+
this.model = new CarouselPreviewModel(uiModel);
1823
this.uiModel = uiModel;
24+
this.mainWindow = owner;
1925
addContent(getBackgroundPanel());
2026
getOkButton().setPreferredSize(null);
2127
getOkButton().setText("Close");
@@ -26,6 +32,7 @@ public CarouselPreviewDialog(final Frame owner, final MainViewModel uiModel)
2632
if (!Beans.isDesignTime())
2733
{
2834
uiModel.addPropertyChangeListener("selectedGamelistView", e -> modelChanged());
35+
model.addPropertyChangeListener(CarouselPreviewModel.CLOSE_PREVIEW, e -> getOkButton().doClick());
2936
//trigger once at startup
3037
modelChanged();
3138
}
@@ -41,8 +48,18 @@ private BackgroundPanel getBackgroundPanel()
4148
{
4249
if (panel == null)
4350
{
44-
panel = new BackgroundPanel(uiModel);
51+
panel = new BackgroundPanel(model, mainWindow);
4552
}
4653
return panel;
4754
}
55+
56+
@Override
57+
public void setVisible(boolean visible)
58+
{
59+
super.setVisible(visible);
60+
if (visible)
61+
{
62+
getBackgroundPanel().initialScroll();
63+
}
64+
}
4865
}

src/main/java/se/lantz/gui/carousel/CoverPanel.java

+122-11
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,40 @@
44
import java.awt.Dimension;
55
import java.awt.GridBagConstraints;
66
import java.awt.GridBagLayout;
7+
import java.awt.Image;
78
import java.awt.Insets;
89
import java.awt.event.ActionEvent;
910
import java.awt.event.ActionListener;
1011
import java.awt.event.KeyEvent;
1112
import java.awt.event.MouseWheelListener;
13+
import java.awt.image.BufferedImage;
14+
import java.beans.Beans;
15+
import java.io.File;
16+
import java.io.IOException;
17+
import java.util.List;
1218

19+
import javax.imageio.ImageIO;
1320
import javax.swing.AbstractAction;
21+
import javax.swing.BorderFactory;
22+
import javax.swing.ImageIcon;
1423
import javax.swing.JComponent;
1524
import javax.swing.JLabel;
1625
import javax.swing.JPanel;
1726
import javax.swing.JScrollPane;
1827
import javax.swing.KeyStroke;
1928
import javax.swing.Timer;
20-
import javax.swing.border.LineBorder;
29+
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
32+
33+
import se.lantz.gui.MainWindow;
34+
import se.lantz.model.carousel.CarouselPreviewModel;
35+
import se.lantz.model.data.GameDetails;
2136

2237
public class CoverPanel extends JPanel
2338
{
39+
private static final Logger logger = LoggerFactory.getLogger(CarouselPreviewModel.class);
40+
2441
private JPanel panel;
2542
private JScrollPane scrollPane;
2643

@@ -30,11 +47,14 @@ public class CoverPanel extends JPanel
3047

3148
private ActionListener timerListener = e -> scrollFromTimer();
3249

33-
private Timer scrolingTimer = new Timer(10, timerListener);
50+
private Timer scrolingTimer = new Timer(7, timerListener);
51+
private CarouselPreviewModel model;
52+
private MainWindow mainWindow;
3453

35-
public CoverPanel()
54+
public CoverPanel(CarouselPreviewModel model, final MainWindow mainWindow)
3655
{
37-
// setBorder(new LineBorder(new Color(0, 0, 0)));
56+
this.model = model;
57+
this.mainWindow = mainWindow;
3858
GridBagLayout gridBagLayout = new GridBagLayout();
3959
gridBagLayout.rowWeights = new double[] { 1.0 };
4060
gridBagLayout.columnWeights = new double[] { 1.0 };
@@ -47,7 +67,17 @@ public CoverPanel()
4767
gbc_scrollPane.gridx = 0;
4868
gbc_scrollPane.gridy = 0;
4969
add(getScrollPane(), gbc_scrollPane);
50-
addCovers(100);
70+
addCovers(10);
71+
72+
if (!Beans.isDesignTime())
73+
{
74+
model.addPropertyChangeListener(CarouselPreviewModel.SELECTED_GAME, e -> {
75+
reloadScreens();
76+
updateSelectedBorder();
77+
});
78+
//trigger once at startup
79+
reloadScreens();
80+
}
5181
}
5282

5383
private JPanel getPanel()
@@ -99,6 +129,18 @@ private void scrollFromTimer()
99129
scrollingTimerIndex = 0;
100130
scrolingTimer.stop();
101131
scrolingStopped = true;
132+
//Select the next game in the list
133+
String gameId = "";
134+
135+
if (scrollDirectionRight)
136+
{
137+
gameId = model.getNextGameToSelectWhenScrollingRight().getGameId();
138+
}
139+
else
140+
{
141+
gameId = model.getNextGameToSelectWhenScrollingLeft().getGameId();
142+
}
143+
this.mainWindow.setSelectedGameInGameList(gameId);
102144
}
103145
}
104146

@@ -125,12 +167,22 @@ private JScrollPane getScrollPane()
125167

126168
private void addCovers(int converCount)
127169
{
128-
129170
for (int i = 0; i < converCount; i++)
130171
{
131172
GridBagConstraints gbc_label = new GridBagConstraints();
132173
gbc_label.fill = GridBagConstraints.BOTH;
133-
gbc_label.insets = new Insets(5, 22, 5, 23);
174+
if (i == 0)
175+
{
176+
gbc_label.insets = new Insets(5, 100, 5, 23);
177+
}
178+
else if (i == converCount - 1)
179+
{
180+
gbc_label.insets = new Insets(5, 22, 5, 100);
181+
}
182+
else
183+
{
184+
gbc_label.insets = new Insets(5, 22, 5, 23);
185+
}
134186
gbc_label.weighty = 1.0;
135187
gbc_label.gridx = i;
136188
gbc_label.gridy = 0;
@@ -140,11 +192,12 @@ private void addCovers(int converCount)
140192

141193
private JLabel getLabel(int index)
142194
{
143-
JLabel label = new JLabel("Label");
144-
label.setBorder(new LineBorder(new Color(0, 0, 0)));
195+
JLabel label = new JLabel();
145196
label.setPreferredSize(new Dimension(125, 175));
146-
// label.setBackground(Color.red);
147-
// label.setOpaque(true);
197+
if (index == 4)
198+
{
199+
label.setBorder(BorderFactory.createLineBorder(Color.YELLOW, 5));
200+
}
148201
return label;
149202
}
150203

@@ -157,4 +210,62 @@ private void scrollOneGame(boolean right)
157210
scrolingTimer.start();
158211
}
159212
}
213+
214+
private void reloadScreens()
215+
{
216+
panel.setVisible(false);
217+
//Remove all existing
218+
panel.removeAll();
219+
addCovers(10);
220+
List<GameDetails> games = model.getGameDetails();
221+
222+
for (int i = 0; i < games.size(); i++)
223+
{
224+
GameDetails game = games.get(i);
225+
loadScreen((JLabel) panel.getComponent(i), game);
226+
}
227+
scrollToPosition();
228+
panel.setVisible(true);
229+
}
230+
231+
private void updateSelectedBorder()
232+
{
233+
for (int i = 0; i < panel.getComponentCount(); i++)
234+
{
235+
((JLabel) panel.getComponent(i)).setBorder(null);
236+
}
237+
238+
List<GameDetails> games = model.getGameDetails();
239+
240+
for (int i = 0; i < games.size(); i++)
241+
{
242+
if (games.indexOf(model.getSelectedGame()) == i)
243+
{
244+
// logger.debug("Setting selected border to cover nr " + i);
245+
((JLabel) panel.getComponent(i)).setBorder(BorderFactory.createLineBorder(Color.YELLOW, 5));
246+
}
247+
}
248+
}
249+
250+
private void loadScreen(JLabel label, GameDetails game)
251+
{
252+
String filename = game.getCover();
253+
File imagefile = new File("./covers/" + filename);
254+
try
255+
{
256+
BufferedImage image = ImageIO.read(imagefile);
257+
Image newImage = image.getScaledInstance(125, 175, Image.SCALE_SMOOTH);
258+
label.setIcon(new ImageIcon(newImage));
259+
}
260+
catch (IOException e)
261+
{
262+
(label).setIcon(null);
263+
}
264+
}
265+
266+
public void scrollToPosition()
267+
{
268+
//Scroll one game
269+
scrollPane.getHorizontalScrollBar().setValue(200);
270+
}
160271
}

src/main/java/se/lantz/model/AbstractModel.java

+9
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ protected void notifyChange(String property, String oldValue, String newValue)
5959
propertyChangeSupport.firePropertyChange(property, oldValue, newValue);
6060
}
6161
}
62+
63+
protected void notifyChange(String property)
64+
{
65+
if (!disable)
66+
{
67+
dataChanged = true;
68+
propertyChangeSupport.firePropertyChange(property, null, null);
69+
}
70+
}
6271

6372
public boolean isDataChanged()
6473
{

0 commit comments

Comments
 (0)