mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
A few aesthetic and organizational updates around the Forge initialization process.
This commit is contained in:
@@ -28,6 +28,7 @@ import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor;
|
|||||||
import arcane.util.MultiplexOutputStream;
|
import arcane.util.MultiplexOutputStream;
|
||||||
import forge.Constant;
|
import forge.Constant;
|
||||||
import forge.HttpUtil;
|
import forge.HttpUtil;
|
||||||
|
import forge.ImageCache;
|
||||||
import forge.properties.ForgePreferences;
|
import forge.properties.ForgePreferences;
|
||||||
import forge.properties.ForgeProps;
|
import forge.properties.ForgeProps;
|
||||||
import forge.properties.NewConstants;
|
import forge.properties.NewConstants;
|
||||||
@@ -64,13 +65,7 @@ public class FModel {
|
|||||||
* if we could not find or write to the log file.
|
* if we could not find or write to the log file.
|
||||||
*/
|
*/
|
||||||
public FModel(final BraidsProgressMonitor theMonitor) throws FileNotFoundException {
|
public FModel(final BraidsProgressMonitor theMonitor) throws FileNotFoundException {
|
||||||
/*
|
// Fire up log file
|
||||||
* To be implemented later. -Braids BraidsProgressMonitor monitor; if
|
|
||||||
* (theMonitor == null) { monitor = new
|
|
||||||
* BaseProgressMonitor(NUM_INIT_PHASES, 1); } else { monitor =
|
|
||||||
* theMonitor; }
|
|
||||||
*/
|
|
||||||
|
|
||||||
final File logFile = new File("forge.log");
|
final File logFile = new File("forge.log");
|
||||||
final boolean deleteSucceeded = logFile.delete();
|
final boolean deleteSucceeded = logFile.delete();
|
||||||
|
|
||||||
@@ -85,18 +80,25 @@ public class FModel {
|
|||||||
this.oldSystemErr = System.err;
|
this.oldSystemErr = System.err;
|
||||||
System.setErr(new PrintStream(new MultiplexOutputStream(System.err, this.logFileStream), true));
|
System.setErr(new PrintStream(new MultiplexOutputStream(System.err, this.logFileStream), true));
|
||||||
|
|
||||||
|
// Instantiate preferences
|
||||||
try {
|
try {
|
||||||
this.setPreferences(new ForgePreferences("forge.preferences"));
|
this.setPreferences(new ForgePreferences("forge.preferences"));
|
||||||
} catch (final Exception exn) {
|
} catch (final Exception exn) {
|
||||||
throw new RuntimeException(exn); // NOPMD by Braids on 8/13/11 8:21
|
// NOPMD by Braids on 8/13/11 8:21 PM
|
||||||
// PM
|
// Log.error("Error loading preferences: " + exn);
|
||||||
|
throw new RuntimeException(exn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO these should be set along with others all at the same time, not here
|
||||||
Constant.Runtime.MILL[0] = this.preferences.isMillingLossCondition();
|
Constant.Runtime.MILL[0] = this.preferences.isMillingLossCondition();
|
||||||
Constant.Runtime.DEV_MODE[0] = this.preferences.isDeveloperMode();
|
Constant.Runtime.DEV_MODE[0] = this.preferences.isDeveloperMode();
|
||||||
Constant.Runtime.UPLOAD_DRAFT[0] = this.preferences.isUploadDraftAI();
|
Constant.Runtime.UPLOAD_DRAFT[0] = this.preferences.isUploadDraftAI();
|
||||||
Constant.Runtime.RANDOM_FOIL[0] = this.preferences.isRandCFoil();
|
Constant.Runtime.RANDOM_FOIL[0] = this.preferences.isRandCFoil();
|
||||||
|
ImageCache.setScaleLargerThanOriginal(preferences.isScaleLargerThanOriginal());
|
||||||
|
/////////
|
||||||
|
|
||||||
|
// Instantiate pinger
|
||||||
|
// TODO is this in the right place?
|
||||||
final HttpUtil pinger = new HttpUtil();
|
final HttpUtil pinger = new HttpUtil();
|
||||||
String url = ForgeProps.getProperty(NewConstants.CARDFORGE_URL) + "/draftAI/ping.php";
|
String url = ForgeProps.getProperty(NewConstants.CARDFORGE_URL) + "/draftAI/ping.php";
|
||||||
if (pinger.getURL(url).equals("pong")) {
|
if (pinger.getURL(url).equals("pong")) {
|
||||||
|
|||||||
@@ -17,24 +17,18 @@
|
|||||||
*/
|
*/
|
||||||
package forge.view;
|
package forge.view;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import net.slightlymagic.braids.util.UtilFunctions;
|
import net.slightlymagic.braids.util.UtilFunctions;
|
||||||
import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor;
|
import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor;
|
||||||
|
|
||||||
import com.esotericsoftware.minlog.Log;
|
|
||||||
|
|
||||||
import forge.AllZone;
|
import forge.AllZone;
|
||||||
import forge.ComputerAIGeneral;
|
import forge.ComputerAIGeneral;
|
||||||
import forge.ComputerAIInput;
|
import forge.ComputerAIInput;
|
||||||
import forge.Constant;
|
import forge.Constant;
|
||||||
import forge.ImageCache;
|
|
||||||
import forge.control.ControlAllUI;
|
import forge.control.ControlAllUI;
|
||||||
import forge.error.ErrorViewer;
|
import forge.error.ErrorViewer;
|
||||||
import forge.game.GameType;
|
import forge.game.GameType;
|
||||||
import forge.model.FModel;
|
|
||||||
import forge.properties.ForgePreferences;
|
|
||||||
import forge.view.home.SplashFrame;
|
import forge.view.home.SplashFrame;
|
||||||
import forge.view.toolbox.CardFaceSymbols;
|
import forge.view.toolbox.CardFaceSymbols;
|
||||||
import forge.view.toolbox.FSkin;
|
import forge.view.toolbox.FSkin;
|
||||||
@@ -58,29 +52,20 @@ public class FView {
|
|||||||
this.skin = skin0;
|
this.skin = skin0;
|
||||||
|
|
||||||
// We must use invokeAndWait here to fulfill the constructor's
|
// We must use invokeAndWait here to fulfill the constructor's
|
||||||
// contract.
|
// contract. NOPMD by Braids on 8/18/11 11:37 PM
|
||||||
|
UtilFunctions.invokeInEventDispatchThreadAndWait(new Runnable() {
|
||||||
UtilFunctions.invokeInEventDispatchThreadAndWait(new Runnable() { // NOPMD
|
@Override
|
||||||
// by
|
public void run() {
|
||||||
// Braids
|
FView.this.splashFrame = new SplashFrame(skin);
|
||||||
// on
|
}
|
||||||
// 8/18/11
|
});
|
||||||
// 11:37
|
// NOPMD by Braids on 8/18/11 11:37 PM
|
||||||
// PM
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
FView.this.splashFrame = new SplashFrame(skin);
|
FView.this.splashFrame.setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids on
|
|
||||||
// 8/18/11 11:37 PM
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
FView.this.splashFrame.setVisible(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,22 +98,8 @@ public class FView {
|
|||||||
/**
|
/**
|
||||||
* Tell the view that the model has been bootstrapped, and its data is ready
|
* Tell the view that the model has been bootstrapped, and its data is ready
|
||||||
* for initial display.
|
* for initial display.
|
||||||
*
|
|
||||||
* @param model
|
|
||||||
* the model that has finished bootstrapping
|
|
||||||
*/
|
*/
|
||||||
public final void setModel(final FModel model) {
|
public final void initialize() {
|
||||||
try {
|
|
||||||
|
|
||||||
final ForgePreferences preferences = model.getPreferences();
|
|
||||||
|
|
||||||
// FindBugs doesn't like the next line.
|
|
||||||
ImageCache.setScaleLargerThanOriginal(preferences.isScaleLargerThanOriginal());
|
|
||||||
|
|
||||||
} catch (final Exception exn) {
|
|
||||||
Log.error("Error loading preferences: " + exn);
|
|
||||||
}
|
|
||||||
|
|
||||||
// For the following two blocks, check if user has cancelled
|
// For the following two blocks, check if user has cancelled
|
||||||
// SplashFrame.
|
// SplashFrame.
|
||||||
// Note: Error thrown sometimes because log file cannot be accessed
|
// Note: Error thrown sometimes because log file cannot be accessed
|
||||||
@@ -138,35 +109,33 @@ public class FView {
|
|||||||
|
|
||||||
if (!this.splashFrame.getSplashHasBeenClosed()) {
|
if (!this.splashFrame.getSplashHasBeenClosed()) {
|
||||||
try {
|
try {
|
||||||
CardFaceSymbols.loadImages();
|
// NOPMD by Braids on 8/7/11 1:07
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
AllZone.getInputControl().setComputer(new ComputerAIInput(new ComputerAIGeneral()));
|
||||||
|
skin.loadFontAndImages();
|
||||||
|
|
||||||
Constant.Runtime.setGameType(GameType.Constructed);
|
CardFaceSymbols.loadImages();
|
||||||
SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids
|
|
||||||
// on 8/7/11 1:07
|
|
||||||
// PM: this isn't a
|
|
||||||
// web app
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
AllZone.getInputControl().setComputer(new ComputerAIInput(new ComputerAIGeneral()));
|
|
||||||
|
|
||||||
// Enable only one of the following two lines.
|
Constant.Runtime.setGameType(GameType.Constructed);
|
||||||
// The second
|
|
||||||
// is useful for debugging.
|
|
||||||
|
|
||||||
FView.this.splashFrame.dispose();
|
GuiTopLevel g = new GuiTopLevel();
|
||||||
// splashFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
AllZone.setDisplay(g);
|
||||||
|
g.getController().changeState(ControlAllUI.HOME_SCREEN);
|
||||||
|
g.pack();
|
||||||
|
g.setVisible(true);
|
||||||
|
|
||||||
FView.this.splashFrame = null;
|
FView.this.splashFrame.dispose();
|
||||||
skin.loadFontAndImages();
|
// Enable only one of the following two lines.
|
||||||
GuiTopLevel g = new GuiTopLevel();
|
// The second is useful for debugging.
|
||||||
g.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
FView.this.splashFrame = null;
|
||||||
AllZone.setDisplay(g);
|
// FView.this.splashFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
g.getController().changeState(ControlAllUI.HOME_SCREEN);
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
ErrorViewer.showError(ex);
|
ErrorViewer.showError(ex);
|
||||||
}
|
}
|
||||||
} // End if(splashHasBeenClosed)
|
} // End if(splashHasBeenClosed) */
|
||||||
} // End FView()
|
} // End FView()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,10 +65,9 @@ public class GuiTopLevel extends JFrame implements Display, CardContainer {
|
|||||||
this.lpnContent.setOpaque(true);
|
this.lpnContent.setOpaque(true);
|
||||||
this.setContentPane(this.lpnContent);
|
this.setContentPane(this.lpnContent);
|
||||||
this.addOverlay();
|
this.addOverlay();
|
||||||
|
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
this.setIconImage(Toolkit.getDefaultToolkit().getImage("res/images/symbols-13/favicon.png"));
|
this.setIconImage(Toolkit.getDefaultToolkit().getImage("res/images/symbols-13/favicon.png"));
|
||||||
this.setTitle("Forge");
|
this.setTitle("Forge: " + Singletons.getModel().getBuildInfo().getVersion());
|
||||||
|
|
||||||
this.setVisible(true);
|
|
||||||
|
|
||||||
// Init controller
|
// Init controller
|
||||||
this.control = new ControlAllUI(this);
|
this.control = new ControlAllUI(this);
|
||||||
|
|||||||
@@ -50,10 +50,10 @@ public final class Main {
|
|||||||
ExceptionHandler.registerErrorHandling();
|
ExceptionHandler.registerErrorHandling();
|
||||||
try {
|
try {
|
||||||
final FModel model = new FModel(null);
|
final FModel model = new FModel(null);
|
||||||
Singletons.setModel(model);
|
final FSkin skin = new FSkin(model.getPreferences().getSkin());
|
||||||
|
|
||||||
final FSkin skin = new FSkin(Singletons.getModel().getPreferences().getSkin());
|
|
||||||
final FView view = new FView(skin);
|
final FView view = new FView(skin);
|
||||||
|
|
||||||
|
Singletons.setModel(model);
|
||||||
Singletons.setView(view);
|
Singletons.setView(view);
|
||||||
|
|
||||||
// Need this soon after card factory is loaded
|
// Need this soon after card factory is loaded
|
||||||
@@ -63,11 +63,9 @@ public final class Main {
|
|||||||
// game.
|
// game.
|
||||||
// It is only here to maintain semantic equality with the current
|
// It is only here to maintain semantic equality with the current
|
||||||
// code base.
|
// code base.
|
||||||
|
|
||||||
model.resetGameState();
|
model.resetGameState();
|
||||||
|
|
||||||
view.setModel(model);
|
view.initialize();
|
||||||
|
|
||||||
} catch (final Throwable exn) {
|
} catch (final Throwable exn) {
|
||||||
ErrorViewer.showError(exn);
|
ErrorViewer.showError(exn);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package forge.view.home;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
import java.awt.Toolkit;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
@@ -94,6 +95,8 @@ public class SplashFrame extends JFrame {
|
|||||||
this.setLocationRelativeTo(null);
|
this.setLocationRelativeTo(null);
|
||||||
this.setResizable(false);
|
this.setResizable(false);
|
||||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
this.setIconImage(Toolkit.getDefaultToolkit().getImage("res/images/symbols-13/favicon.png"));
|
||||||
|
this.setTitle("Loading Forge...");
|
||||||
|
|
||||||
// Insert JPanel to hold content above background
|
// Insert JPanel to hold content above background
|
||||||
final JPanel contentPane = new JPanel();
|
final JPanel contentPane = new JPanel();
|
||||||
|
|||||||
Reference in New Issue
Block a user