A few aesthetic and organizational updates around the Forge initialization process.

This commit is contained in:
Doublestrike
2012-01-17 13:43:59 +00:00
parent 2b034da809
commit f6778e2e3a
5 changed files with 56 additions and 85 deletions

View File

@@ -28,6 +28,7 @@ import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor;
import arcane.util.MultiplexOutputStream;
import forge.Constant;
import forge.HttpUtil;
import forge.ImageCache;
import forge.properties.ForgePreferences;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
@@ -64,13 +65,7 @@ public class FModel {
* if we could not find or write to the log file.
*/
public FModel(final BraidsProgressMonitor theMonitor) throws FileNotFoundException {
/*
* To be implemented later. -Braids BraidsProgressMonitor monitor; if
* (theMonitor == null) { monitor = new
* BaseProgressMonitor(NUM_INIT_PHASES, 1); } else { monitor =
* theMonitor; }
*/
// Fire up log file
final File logFile = new File("forge.log");
final boolean deleteSucceeded = logFile.delete();
@@ -85,18 +80,25 @@ public class FModel {
this.oldSystemErr = System.err;
System.setErr(new PrintStream(new MultiplexOutputStream(System.err, this.logFileStream), true));
// Instantiate preferences
try {
this.setPreferences(new ForgePreferences("forge.preferences"));
} catch (final Exception exn) {
throw new RuntimeException(exn); // NOPMD by Braids on 8/13/11 8:21
// PM
// NOPMD by Braids on 8/13/11 8:21 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.DEV_MODE[0] = this.preferences.isDeveloperMode();
Constant.Runtime.UPLOAD_DRAFT[0] = this.preferences.isUploadDraftAI();
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();
String url = ForgeProps.getProperty(NewConstants.CARDFORGE_URL) + "/draftAI/ping.php";
if (pinger.getURL(url).equals("pong")) {

View File

@@ -17,24 +17,18 @@
*/
package forge.view;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import net.slightlymagic.braids.util.UtilFunctions;
import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor;
import com.esotericsoftware.minlog.Log;
import forge.AllZone;
import forge.ComputerAIGeneral;
import forge.ComputerAIInput;
import forge.Constant;
import forge.ImageCache;
import forge.control.ControlAllUI;
import forge.error.ErrorViewer;
import forge.game.GameType;
import forge.model.FModel;
import forge.properties.ForgePreferences;
import forge.view.home.SplashFrame;
import forge.view.toolbox.CardFaceSymbols;
import forge.view.toolbox.FSkin;
@@ -58,29 +52,20 @@ public class FView {
this.skin = skin0;
// We must use invokeAndWait here to fulfill the constructor's
// contract.
UtilFunctions.invokeInEventDispatchThreadAndWait(new Runnable() { // NOPMD
// by
// Braids
// on
// 8/18/11
// 11:37
// PM
// contract. NOPMD by Braids on 8/18/11 11:37 PM
UtilFunctions.invokeInEventDispatchThreadAndWait(new Runnable() {
@Override
public void run() {
FView.this.splashFrame = new SplashFrame(skin);
}
});
SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids on
// 8/18/11 11:37 PM
// NOPMD by Braids on 8/18/11 11:37 PM
SwingUtilities.invokeLater(new Runnable() {
@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
* for initial display.
*
* @param model
* the model that has finished bootstrapping
*/
public final void setModel(final FModel model) {
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);
}
public final void initialize() {
// For the following two blocks, check if user has cancelled
// SplashFrame.
// Note: Error thrown sometimes because log file cannot be accessed
@@ -138,35 +109,33 @@ public class FView {
if (!this.splashFrame.getSplashHasBeenClosed()) {
try {
CardFaceSymbols.loadImages();
Constant.Runtime.setGameType(GameType.Constructed);
SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids
// on 8/7/11 1:07
// PM: this isn't a
// web app
// NOPMD by Braids on 8/7/11 1:07
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
AllZone.getInputControl().setComputer(new ComputerAIInput(new ComputerAIGeneral()));
// Enable only one of the following two lines.
// The second
// is useful for debugging.
FView.this.splashFrame.dispose();
// splashFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
FView.this.splashFrame = null;
skin.loadFontAndImages();
CardFaceSymbols.loadImages();
Constant.Runtime.setGameType(GameType.Constructed);
GuiTopLevel g = new GuiTopLevel();
g.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
AllZone.setDisplay(g);
g.getController().changeState(ControlAllUI.HOME_SCREEN);
g.pack();
g.setVisible(true);
FView.this.splashFrame.dispose();
// Enable only one of the following two lines.
// The second is useful for debugging.
FView.this.splashFrame = null;
// FView.this.splashFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
});
} catch (final Exception ex) {
ErrorViewer.showError(ex);
}
} // End if(splashHasBeenClosed)
} // End if(splashHasBeenClosed) */
} // End FView()
}

View File

@@ -65,10 +65,9 @@ public class GuiTopLevel extends JFrame implements Display, CardContainer {
this.lpnContent.setOpaque(true);
this.setContentPane(this.lpnContent);
this.addOverlay();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setIconImage(Toolkit.getDefaultToolkit().getImage("res/images/symbols-13/favicon.png"));
this.setTitle("Forge");
this.setVisible(true);
this.setTitle("Forge: " + Singletons.getModel().getBuildInfo().getVersion());
// Init controller
this.control = new ControlAllUI(this);

View File

@@ -50,10 +50,10 @@ public final class Main {
ExceptionHandler.registerErrorHandling();
try {
final FModel model = new FModel(null);
Singletons.setModel(model);
final FSkin skin = new FSkin(Singletons.getModel().getPreferences().getSkin());
final FSkin skin = new FSkin(model.getPreferences().getSkin());
final FView view = new FView(skin);
Singletons.setModel(model);
Singletons.setView(view);
// Need this soon after card factory is loaded
@@ -63,11 +63,9 @@ public final class Main {
// game.
// It is only here to maintain semantic equality with the current
// code base.
model.resetGameState();
view.setModel(model);
view.initialize();
} catch (final Throwable exn) {
ErrorViewer.showError(exn);
}

View File

@@ -20,6 +20,7 @@ package forge.view.home;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
@@ -94,6 +95,8 @@ public class SplashFrame extends JFrame {
this.setLocationRelativeTo(null);
this.setResizable(false);
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
final JPanel contentPane = new JPanel();