Skip to content

Commit

Permalink
splash screen
Browse files Browse the repository at this point in the history
  • Loading branch information
syd711 committed Sep 20, 2022
1 parent d5c1f06 commit 0d1b77b
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 74 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ which are generated everytime a highscore changes.
* Configure Highscore Cards
* Configure DOF Rules
* Table Overview
* Service Status

## Overview

Expand Down
8 changes: 8 additions & 0 deletions install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ ECHO Writing VPinExtensions-Config.bat
echo cd /D %cd%
echo start jdk/bin/javaw -jar vpin-extensions.jar config
) > VPinExtensions-Config.bat


ECHO Writing startService.bat

(
echo cd /D %cd%
echo start jdk/bin/javaw -jar vpin-extensions.jar
) > startService.bat
2 changes: 1 addition & 1 deletion resources/card-generator.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Tue Sep 20 17:54:01 CEST 2022
#Tue Sep 20 19:57:04 CEST 2022
card.alphacomposite.black=28
card.alphacomposite.white=10
card.background=highscore-card-background-2.jpg
Expand Down
3 changes: 2 additions & 1 deletion resources/overlay-generator.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Tue Sep 20 17:54:00 CEST 2022
#Tue Sep 20 19:57:04 CEST 2022
overlay.alphacomposite.black=36
overlay.alphacomposite.white=0
overlay.background=background4k.jpg
Expand All @@ -17,6 +17,7 @@ overlay.table.font.font.style=0
overlay.table.font.name=SF Comic Script
overlay.table.font.size=100
overlay.table.font.style=0
overlay.title.font.font.style=0
overlay.title.font.name=Star Jedi
overlay.title.font.size=110
overlay.title.font.style=0
Expand Down
86 changes: 15 additions & 71 deletions src/main/java/de/mephisto/vpin/extensions/ConfigWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,27 @@ public static ConfigWindow getInstance() {
return instance;
}

public ConfigWindow() throws Exception {
ConfigWindow.instance = this;

setUIFont(new javax.swing.plaf.FontUIResource("Tahoma", Font.PLAIN, 14));
// UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

public ConfigWindow(VPinService service) {
this.service = service;
try {
ConfigWindow.instance = this;

service = VPinService.create(false);
setSize(1346, 990);
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
int x = (int) ((dimension.getWidth() - this.getWidth()) / 2);
int y = (int) ((dimension.getHeight() - this.getHeight()) / 2);
setLocation(x, y);
setResizable(false);

// setting the title of Frame
setTitle("VPin Extensions (" + Updater.getCurrentVersion() + ")");
setIconImage(ResourceLoader.getResource("logo.png"));

setSize(1346, 990);
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
int x = (int) ((dimension.getWidth() - this.getWidth()) / 2);
int y = (int) ((dimension.getHeight() - this.getHeight()) / 2);
setLocation(x, y);
setResizable(false);
setUIFont(new javax.swing.plaf.FontUIResource("Tahoma", Font.PLAIN, 14));
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

// setting the title of Frame
setTitle("VPin Extensions (" + Updater.getCurrentVersion() + ")");
setIconImage(ResourceLoader.getResource("logo.png"));

checkForUpdates();
runInitialCheck();

try {
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

JTabbedPane tabbedPane = new JTabbedPane();
Expand Down Expand Up @@ -89,8 +84,6 @@ public ConfigWindow() throws Exception {
tabbedPane.setBackgroundAt(4, DEFAULT_BG_COLOR);
add(tabbedPane);

setVisible(true);

Action escapeAction = new AbstractAction() {
private static final long serialVersionUID = 5572504000935312338L;

Expand All @@ -109,51 +102,6 @@ public void actionPerformed(ActionEvent e) {
}
}

private void checkForUpdates() {
try {
String nextVersion = Updater.checkForUpdate();
if(!StringUtils.isEmpty(nextVersion)) {
int option = JOptionPane.showConfirmDialog(this, "New version " + nextVersion + " found. Download and install update?", "New Update Found", JOptionPane.YES_NO_OPTION);
if(option == JOptionPane.YES_OPTION) {
try {
Updater.update(nextVersion);
JOptionPane.showMessageDialog(null, "Update downloaded successfully. Please restart application.", "Information", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Update Failed: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error checking for updates: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}

private void runInitialCheck() {
List<GameInfo> gameInfos = service.getGameInfos();
boolean romFound = false;
for (GameInfo gameInfo : gameInfos) {
if (!StringUtils.isEmpty(gameInfo.getRom())) {
romFound = true;
break;
}
}
if (!romFound) {
int option = JOptionPane.showConfirmDialog(this, "It seems that no ROM scan has been performed yet.\n" +
"The ROM name of each table is required in order to scan the highscore information.\n\nScan for ROM names? (This may take a while)", "Table Scan", JOptionPane.YES_NO_OPTION);
if(option == JOptionPane.YES_OPTION) {
ProgressDialog d = new ProgressDialog(this, new TableScanProgressModel(service, "Resolving ROM Names"));
ProgressResultModel progressResultModel = d.showDialog();

JOptionPane.showMessageDialog(this, "Finished ROM scan, found ROM names of "
+ (progressResultModel.getProcessed()-progressResultModel.getSkipped()) + " from " + progressResultModel.getProcessed() + " tables.",
"Generation Finished", JOptionPane.INFORMATION_MESSAGE);
LOG.info("Finished global ROM scan.");
service.refreshGameInfos();
}
}
}

public static void setUIFont(javax.swing.plaf.FontUIResource f) {
java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Expand All @@ -163,8 +111,4 @@ public static void setUIFont(javax.swing.plaf.FontUIResource f) {
UIManager.put(key, f);
}
}

public static void main(String[] args) throws Exception {
new ConfigWindow();
}
}
134 changes: 134 additions & 0 deletions src/main/java/de/mephisto/vpin/extensions/Splash.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package de.mephisto.vpin.extensions;

import de.mephisto.vpin.GameInfo;
import de.mephisto.vpin.VPinService;
import de.mephisto.vpin.extensions.cardsettings.CardSettingsTabActionListener;
import de.mephisto.vpin.extensions.resources.ResourceLoader;
import de.mephisto.vpin.extensions.table.TableScanProgressModel;
import de.mephisto.vpin.extensions.util.ProgressDialog;
import de.mephisto.vpin.extensions.util.ProgressResultModel;
import de.mephisto.vpin.extensions.util.Updater;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory;

import javax.swing.*;
import java.awt.*;
import java.util.List;

import static de.mephisto.vpin.extensions.ConfigWindow.setUIFont;

class Splash extends JWindow {
private final static org.slf4j.Logger LOG = LoggerFactory.getLogger(Splash.class);

static JProgressBar progressBar = new JProgressBar();
private VPinService vPinService;

public Splash() {
try {
Container container = getContentPane();
setUIFont(new javax.swing.plaf.FontUIResource("Tahoma", Font.PLAIN, 14));
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

setIconImage(ResourceLoader.getResource("logo.png"));

this.setSize(new Dimension(700, 450));

Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
int x = (int) ((dimension.getWidth() - this.getWidth()) / 2);
int y = (int) ((dimension.getHeight() - this.getHeight()) / 2);
setLocation(x, y);

JPanel panel = new SplashCenter();
panel.setLayout(null);

container.add(panel, BorderLayout.CENTER);

JLabel label = new JLabel("VPin Extensions");
label.setBounds(30, 50, 600, 200);
Font font = new Font("Tahoma", Font.PLAIN, 34);
label.setFont(font);
label.setForeground(Color.WHITE);
panel.add(label);

label = new JLabel("Version "+ Updater.getCurrentVersion());
label.setBounds(30, 80, 600, 200);
font = new Font("Tahoma", Font.PLAIN, 14);
label.setFont(font);
label.setForeground(Color.WHITE);
panel.add(label);

progressBar.setIndeterminate(true);
progressBar.setMaximum(100);
container.add(progressBar, BorderLayout.SOUTH);
setVisible(true);

new Thread(() -> {
checkForUpdates();

vPinService = VPinService.create(false);
runInitialCheck();
startMain();
}).start();
} catch (Exception e) {
LOG.error("Failed to launch: " + e.getMessage(), e);
JOptionPane.showMessageDialog(this.getContentPane(), "Failed to start VPin Extension configuration window: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
}



private void runInitialCheck() {
List<GameInfo> gameInfos = vPinService.getGameInfos();
boolean romFound = false;
for (GameInfo gameInfo : gameInfos) {
if (!StringUtils.isEmpty(gameInfo.getRom())) {
romFound = true;
break;
}
}
if (!romFound) {
Splash.this.setVisible(false);
int option = JOptionPane.showConfirmDialog(this, "It seems that no ROM scan has been performed yet.\n" +
"The ROM name of each table is required in order to scan the highscore information.\n\nScan for ROM names? (This may take a while)", "Table Scan", JOptionPane.YES_NO_OPTION);
if(option == JOptionPane.YES_OPTION) {
ProgressDialog d = new ProgressDialog(null, new TableScanProgressModel(vPinService, "Resolving ROM Names"));
ProgressResultModel progressResultModel = d.showDialog();

JOptionPane.showMessageDialog(this, "Finished ROM scan, found ROM names of "
+ (progressResultModel.getProcessed()-progressResultModel.getSkipped()) + " from " + progressResultModel.getProcessed() + " tables.",
"Generation Finished", JOptionPane.INFORMATION_MESSAGE);
LOG.info("Finished global ROM scan.");
Splash.this.setVisible(true);
vPinService.refreshGameInfos();
}
}
}

private void checkForUpdates() {
try {
String nextVersion = Updater.checkForUpdate();
if(!StringUtils.isEmpty(nextVersion)) {
Splash.this.setVisible(false);
int option = JOptionPane.showConfirmDialog(this, "New version " + nextVersion + " found. Download and install update?", "New Update Found", JOptionPane.YES_NO_OPTION);
if(option == JOptionPane.YES_OPTION) {
try {
Updater.update(nextVersion);
JOptionPane.showMessageDialog(null, "Update downloaded successfully. Please restart application.", "Information", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Update Failed: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error checking for updates: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}

private void startMain() {
ConfigWindow configWindow = new ConfigWindow(vPinService);
Splash.this.setVisible(false);
configWindow.setVisible(true);
}
}
16 changes: 16 additions & 0 deletions src/main/java/de/mephisto/vpin/extensions/SplashCenter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.mephisto.vpin.extensions;

import de.mephisto.vpin.extensions.resources.ResourceLoader;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

public class SplashCenter extends JPanel {

public void paintComponent(Graphics g) {
super.paintComponent(g);
BufferedImage bufferedImage = ResourceLoader.getResource("splash.jpg");
g.drawImage(bufferedImage, 0, 0, this);
}
}
2 changes: 1 addition & 1 deletion src/main/java/de/mephisto/vpin/extensions/SuperMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class SuperMain {
public static void main(String[] args) throws Exception {
if(args != null && args.length > 0 && args[0].contains("config")) {
ConfigWindow.main(args);
new Splash();
}
else if(args != null && args.length > 0 && args[0].contains("overlay")) {
OverlayGenerator.main(args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.mephisto.vpin.extensions.util;

import de.mephisto.vpin.extensions.ConfigWindow;
import de.mephisto.vpin.extensions.resources.ResourceLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -24,6 +25,7 @@ public class ProgressDialog extends JDialog implements ActionListener {
public ProgressDialog(ConfigWindow parent, ProgressModel model) {
super(parent, model.getTitle(), true);
setSize(500, 200);
setIconImage(ResourceLoader.getResource("logo.png"));
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(4, 4, 4, 4);
Expand Down

0 comments on commit 0d1b77b

Please sign in to comment.