Code cleanup - main, FControl, FView, FModel core.

Should fix occasional "long wait before splash" bug.
This commit is contained in:
Doublestrike
2012-09-28 05:56:12 +00:00
parent c04c9ab030
commit 005a087b53
9 changed files with 196 additions and 216 deletions

View File

@@ -35,7 +35,6 @@ import java.util.zip.ZipFile;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import forge.Card; import forge.Card;
import forge.CardCharacteristicName; import forge.CardCharacteristicName;
import forge.CardColor; import forge.CardColor;
@@ -50,7 +49,7 @@ import forge.card.trigger.TriggerHandler;
import forge.error.ErrorViewer; import forge.error.ErrorViewer;
import forge.gui.toolbox.FProgressBar; import forge.gui.toolbox.FProgressBar;
import forge.util.FileUtil; import forge.util.FileUtil;
import forge.view.SplashFrame; import forge.view.FView;
/** /**
* <p> * <p>
@@ -127,12 +126,6 @@ public class CardReader {
* *
* @param theCardsFolder * @param theCardsFolder
* indicates location of the cardsFolder * indicates location of the cardsFolder
*
* @param theMapToFill
* maps card names to Card instances; this is where we place the
* cards once read
* @param listRules2Fill
* List<CardRules>
* @param useZip * @param useZip
* if true, attempts to load cards from a zip file, if one * if true, attempts to load cards from a zip file, if one
* exists. * exists.
@@ -186,15 +179,12 @@ public class CardReader {
* After that, we save our place in the list of cards (on disk) in case we * After that, we save our place in the list of cards (on disk) in case we
* need to load more. * need to load more.
* *
* @param cardName
* the name to find; if null, load all cards.
*
* @return the Card or null if it was not found. * @return the Card or null if it was not found.
*/ */
public final List<CardRules> loadCards() { public final List<CardRules> loadCards() {
List<CardRules> result = new ArrayList<CardRules>(); List<CardRules> result = new ArrayList<CardRules>();
final FProgressBar barProgress = SplashFrame.PROGRESS_BAR; final FProgressBar barProgress = FView.SINGLETON_INSTANCE.getSplash().getProgressBar();
// Iterate through txt files or zip archive. // Iterate through txt files or zip archive.
// Report relevant numbers to progress monitor model. // Report relevant numbers to progress monitor model.

View File

@@ -28,6 +28,7 @@ import java.util.List;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JLayeredPane; import javax.swing.JLayeredPane;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants; import javax.swing.WindowConstants;
import forge.AllZone; import forge.AllZone;
@@ -136,9 +137,6 @@ public enum FControl {
} }
} }
}; };
FView.SINGLETON_INSTANCE.getLpnDocument().addMouseListener(SOverflowUtil.getHideOverflowListener());
FView.SINGLETON_INSTANCE.getLpnDocument().addComponentListener(SResizingUtil.getWindowResizeListener());
} }
/** After view and model have been initialized, control can start. */ /** After view and model have been initialized, control can start. */
@@ -152,6 +150,7 @@ public enum FControl {
// Does not use progress bar, due to be deprecated with battlefield refactoring. // Does not use progress bar, due to be deprecated with battlefield refactoring.
CardFaceSymbols.loadImages(); CardFaceSymbols.loadImages();
this.shortcuts = KeyboardShortcuts.attachKeyboardShortcuts(); this.shortcuts = KeyboardShortcuts.attachKeyboardShortcuts();
this.display = FView.SINGLETON_INSTANCE.getLpnDocument(); this.display = FView.SINGLETON_INSTANCE.getLpnDocument();
@@ -170,6 +169,12 @@ public enum FControl {
sizeChildren(); sizeChildren();
} }
}); });
FView.SINGLETON_INSTANCE.getLpnDocument().addMouseListener(SOverflowUtil.getHideOverflowListener());
FView.SINGLETON_INSTANCE.getLpnDocument().addComponentListener(SResizingUtil.getWindowResizeListener());
SwingUtilities.invokeLater(new Runnable() { @Override
public void run() { Singletons.getView().initialize(); } });
} }
/** /**

View File

@@ -37,7 +37,6 @@ import forge.model.FModel;
import forge.properties.ForgePreferences.FPref; import forge.properties.ForgePreferences.FPref;
import forge.view.FView; import forge.view.FView;
import forge.view.arcane.CardPanel; import forge.view.arcane.CardPanel;
import forge.view.arcane.PlayArea;
/** /**
* Semi-transparent overlay panel. Should be used with layered panes. * Semi-transparent overlay panel. Should be used with layered panes.
@@ -50,21 +49,13 @@ public enum TargetingOverlay {
SINGLETON_INSTANCE; SINGLETON_INSTANCE;
private final JPanel pnl = new OverlayPanel(); private final JPanel pnl = new OverlayPanel();
private final List<PlayArea> playAreas; private final List<CardPanel> cardPanels = new ArrayList<CardPanel>();
private List<CardPanel> cardPanels;
private final List<Point[]> arcs = new ArrayList<Point[]>(); private final List<Point[]> arcs = new ArrayList<Point[]>();
/** /**
* Semi-transparent overlay panel. Should be used with layered panes. * Semi-transparent overlay panel. Should be used with layered panes.
*/ */
private TargetingOverlay() { private TargetingOverlay() {
playAreas = new ArrayList<PlayArea>();
cardPanels = new ArrayList<CardPanel>();
for (CField f : CMatchUI.SINGLETON_INSTANCE.getFieldControls()) {
playAreas.add(f.getView().getTabletop());
}
pnl.setOpaque(false); pnl.setOpaque(false);
pnl.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); pnl.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA));
} }
@@ -80,8 +71,10 @@ public enum TargetingOverlay {
private void assembleArcs() { private void assembleArcs() {
arcs.clear(); arcs.clear();
cardPanels.clear(); cardPanels.clear();
cardPanels.addAll(playAreas.get(0).getCardPanels());
cardPanels.addAll(playAreas.get(1).getCardPanels()); for (CField f : CMatchUI.SINGLETON_INSTANCE.getFieldControls()) {
cardPanels.addAll(f.getView().getTabletop().getCardPanels());
}
final Point docOffsets = FView.SINGLETON_INSTANCE.getLpnDocument().getLocationOnScreen(); final Point docOffsets = FView.SINGLETON_INSTANCE.getLpnDocument().getLocationOnScreen();
// Locations of arc endpoint, per card, with ID as primary key. // Locations of arc endpoint, per card, with ID as primary key.

View File

@@ -38,7 +38,7 @@ import javax.swing.UIManager;
import javax.swing.border.LineBorder; import javax.swing.border.LineBorder;
import forge.gui.GuiUtils; import forge.gui.GuiUtils;
import forge.view.SplashFrame; import forge.view.FView;
/** /**
* Assembles settings from selected or default theme as appropriate. Saves in a * Assembles settings from selected or default theme as appropriate. Saves in a
@@ -483,7 +483,7 @@ public enum FSkin {
if (FSkin.preferredName.isEmpty()) { FSkin.loadLight("default"); } if (FSkin.preferredName.isEmpty()) { FSkin.loadLight("default"); }
// Everything OK? // Everything OK?
final FProgressBar barProgress = SplashFrame.PROGRESS_BAR; final FProgressBar barProgress = FView.SINGLETON_INSTANCE.getSplash().getProgressBar();
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override

View File

@@ -36,14 +36,11 @@ import forge.card.FatPackData;
import forge.card.FormatCollection; import forge.card.FormatCollection;
import forge.control.input.InputControl; import forge.control.input.InputControl;
import forge.deck.CardCollections; import forge.deck.CardCollections;
import forge.error.ExceptionHandler;
import forge.game.GameState; import forge.game.GameState;
import forge.game.GameSummary; import forge.game.GameSummary;
import forge.game.player.ComputerAIGeneral; import forge.game.player.ComputerAIGeneral;
import forge.game.player.ComputerAIInput; import forge.game.player.ComputerAIInput;
import forge.gui.match.VMatchUI;
import forge.gui.match.nonsingleton.VField;
import forge.gui.match.views.VDev;
import forge.gui.toolbox.FSkin;
import forge.properties.ForgePreferences; import forge.properties.ForgePreferences;
import forge.properties.ForgePreferences.FPref; import forge.properties.ForgePreferences.FPref;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
@@ -93,7 +90,6 @@ public enum FModel {
// CardDb is not ready yet. // CardDb is not ready yet.
private CardCollections decks; private CardCollections decks;
/** /**
* Constructor. * Constructor.
* *
@@ -101,7 +97,9 @@ public enum FModel {
* if we could not find or write to the log file. * if we could not find or write to the log file.
*/ */
private FModel() { private FModel() {
// Fire up log file // Fire up log file and exception handling
ExceptionHandler.registerErrorHandling();
final File logFile = new File("forge.log"); final File logFile = new File("forge.log");
final boolean deleteSucceeded = logFile.delete(); final boolean deleteSucceeded = logFile.delete();
@@ -140,21 +138,8 @@ public enum FModel {
this.blocks = new StorageView<CardBlock>(new CardBlock.Reader("res/blockdata/blocks.txt", editions)); this.blocks = new StorageView<CardBlock>(new CardBlock.Reader("res/blockdata/blocks.txt", editions));
this.fantasyBlocks = new StorageView<CardBlock>(new CardBlock.Reader("res/blockdata/fantasyblocks.txt", editions)); this.fantasyBlocks = new StorageView<CardBlock>(new CardBlock.Reader("res/blockdata/fantasyblocks.txt", editions));
// TODO this single setting from preferences should not be here, or, // TODO - there's got to be a better place for this...oblivion?
// it should be here with all the other settings at the same time.
// Unfortunately, they're tied up in legacy code in the Display
// interface,
// currently in GuiTopLevel. When that code is updated, this TODO should
// be resolved.
// Doublestrike 24-01-12
// ==
// It's looking like all the settings at the same time, here only.
// Doublestrike 06-02-12
Constant.Runtime.DEV_MODE[0] = this.preferences.getPrefBoolean(FPref.DEV_MODE_ENABLED); Constant.Runtime.DEV_MODE[0] = this.preferences.getPrefBoolean(FPref.DEV_MODE_ENABLED);
Constant.Runtime.setSkinName(this.preferences.getPref(FPref.UI_SKIN));
// Load splash image and preloader swatches for skin
FSkin.loadLight(Constant.Runtime.getSkinName());
// Instantiate AI // Instantiate AI
AllZone.setInputControl(new InputControl(FModel.this)); AllZone.setInputControl(new InputControl(FModel.this));
@@ -380,103 +365,23 @@ public enum FModel {
} }
/** /**
* TODO: Needs to be reworked for efficiency with rest of prefs saves in * TODO: Remove this method completely.
* codebase.
*
* @return true, if successful * @return true, if successful
*/ */
public final boolean savePrefs() { public final boolean savePrefs() {
final ForgePreferences fp = this.preferences; this.preferences.writeMatchPreferences();
final List<VField> fieldViews = VMatchUI.SINGLETON_INSTANCE.getFieldViews(); this.preferences.save();
// AI field is at index [0]
fp.setPref(FPref.PHASE_AI_UPKEEP, String.valueOf(fieldViews.get(0).getLblUpkeep().getEnabled()));
fp.setPref(FPref.PHASE_AI_DRAW, String.valueOf(fieldViews.get(0).getLblDraw().getEnabled()));
fp.setPref(FPref.PHASE_AI_MAIN1, String.valueOf(fieldViews.get(0).getLblMain1().getEnabled()));
fp.setPref(FPref.PHASE_AI_BEGINCOMBAT, String.valueOf(fieldViews.get(0).getLblBeginCombat().getEnabled()));
fp.setPref(FPref.PHASE_AI_DECLAREATTACKERS,
String.valueOf(fieldViews.get(0).getLblDeclareAttackers().getEnabled()));
fp.setPref(FPref.PHASE_AI_DECLAREBLOCKERS,
String.valueOf(fieldViews.get(0).getLblDeclareBlockers().getEnabled()));
fp.setPref(FPref.PHASE_AI_FIRSTSTRIKE, String.valueOf(fieldViews.get(0).getLblFirstStrike().getEnabled()));
fp.setPref(FPref.PHASE_AI_COMBATDAMAGE, String.valueOf(fieldViews.get(0).getLblCombatDamage().getEnabled()));
fp.setPref(FPref.PHASE_AI_ENDCOMBAT, String.valueOf(fieldViews.get(0).getLblEndCombat().getEnabled()));
fp.setPref(FPref.PHASE_AI_MAIN2, String.valueOf(fieldViews.get(0).getLblMain2().getEnabled()));
fp.setPref(FPref.PHASE_AI_EOT, String.valueOf(fieldViews.get(0).getLblEndTurn().getEnabled()));
fp.setPref(FPref.PHASE_AI_CLEANUP, String.valueOf(fieldViews.get(0).getLblCleanup().getEnabled()));
// Human field is at index [1]
fp.setPref(FPref.PHASE_HUMAN_UPKEEP, String.valueOf(fieldViews.get(1).getLblUpkeep().getEnabled()));
fp.setPref(FPref.PHASE_HUMAN_DRAW, String.valueOf(fieldViews.get(1).getLblDraw().getEnabled()));
fp.setPref(FPref.PHASE_HUMAN_MAIN1, String.valueOf(fieldViews.get(1).getLblMain1().getEnabled()));
fp.setPref(FPref.PHASE_HUMAN_BEGINCOMBAT, String.valueOf(fieldViews.get(1).getLblBeginCombat().getEnabled()));
fp.setPref(FPref.PHASE_HUMAN_DECLAREATTACKERS,
String.valueOf(fieldViews.get(1).getLblDeclareAttackers().getEnabled()));
fp.setPref(FPref.PHASE_HUMAN_DECLAREBLOCKERS,
String.valueOf(fieldViews.get(1).getLblDeclareBlockers().getEnabled()));
fp.setPref(FPref.PHASE_HUMAN_FIRSTSTRIKE, String.valueOf(fieldViews.get(1).getLblFirstStrike().getEnabled()));
fp.setPref(FPref.PHASE_HUMAN_COMBATDAMAGE, String.valueOf(fieldViews.get(1).getLblCombatDamage().getEnabled()));
fp.setPref(FPref.PHASE_HUMAN_ENDCOMBAT, String.valueOf(fieldViews.get(1).getLblEndCombat().getEnabled()));
fp.setPref(FPref.PHASE_HUMAN_MAIN2, String.valueOf(fieldViews.get(1).getLblMain2().getEnabled()));
fp.setPref(FPref.PHASE_HUMAN_EOT, String.valueOf(fieldViews.get(1).getLblEndTurn().getEnabled()));
fp.setPref(FPref.PHASE_HUMAN_CLEANUP, String.valueOf(fieldViews.get(1).getLblCleanup().getEnabled()));
final VDev v = VDev.SINGLETON_INSTANCE;
Constant.Runtime.MILL[0] = v.getLblMilling().getEnabled();
fp.setPref(FPref.DEV_MILLING_LOSS, String.valueOf(Constant.Runtime.MILL[0]));
fp.setPref(FPref.DEV_UNLIMITED_LAND, String.valueOf(v.getLblUnlimitedLands().getEnabled()));
fp.save();
return true; return true;
} }
/** /**
* TODO: Needs to be reworked for efficiency with rest of prefs loads in * TODO: Remove this method completely.
* codebase.
* *
* @return true, if successful * @return true, if successful
*/ */
public final boolean loadPrefs() { public final boolean loadPrefs() {
final ForgePreferences fp = Singletons.getModel().getPreferences(); final ForgePreferences fp = Singletons.getModel().getPreferences();
final List<VField> fieldViews = VMatchUI.SINGLETON_INSTANCE.getFieldViews(); fp.actuateMatchPreferences();
Constant.Runtime.MILL[0] = fp.getPrefBoolean(FPref.DEV_MILLING_LOSS);
Constant.Runtime.DEV_MODE[0] = fp.getPrefBoolean(FPref.DEV_MODE_ENABLED);
Constant.Runtime.UPLOAD_DRAFT[0] = fp.getPrefBoolean(FPref.UI_UPLOAD_DRAFT);
Constant.Runtime.RANDOM_FOIL[0] = fp.getPrefBoolean(FPref.UI_RANDOM_FOIL);
Constant.Runtime.UPLOAD_DRAFT[0] = (Constant.Runtime.NET_CONN[0] ? fp.getPrefBoolean(FPref.UI_UPLOAD_DRAFT)
: false);
// AI field is at index [0]
fieldViews.get(0).getLblUpkeep().setEnabled(fp.getPrefBoolean(FPref.PHASE_AI_UPKEEP));
fieldViews.get(0).getLblDraw().setEnabled(fp.getPrefBoolean(FPref.PHASE_AI_DRAW));
fieldViews.get(0).getLblMain1().setEnabled(fp.getPrefBoolean(FPref.PHASE_AI_MAIN1));
fieldViews.get(0).getLblBeginCombat().setEnabled(fp.getPrefBoolean(FPref.PHASE_AI_BEGINCOMBAT));
fieldViews.get(0).getLblDeclareAttackers().setEnabled(fp.getPrefBoolean(FPref.PHASE_AI_DECLAREATTACKERS));
fieldViews.get(0).getLblDeclareBlockers().setEnabled(fp.getPrefBoolean(FPref.PHASE_AI_DECLAREBLOCKERS));
fieldViews.get(0).getLblFirstStrike().setEnabled(fp.getPrefBoolean(FPref.PHASE_AI_FIRSTSTRIKE));
fieldViews.get(0).getLblCombatDamage().setEnabled(fp.getPrefBoolean(FPref.PHASE_AI_COMBATDAMAGE));
fieldViews.get(0).getLblEndCombat().setEnabled(fp.getPrefBoolean(FPref.PHASE_AI_ENDCOMBAT));
fieldViews.get(0).getLblMain2().setEnabled(fp.getPrefBoolean(FPref.PHASE_AI_MAIN2));
fieldViews.get(0).getLblEndTurn().setEnabled(fp.getPrefBoolean(FPref.PHASE_AI_EOT));
fieldViews.get(0).getLblCleanup().setEnabled(fp.getPrefBoolean(FPref.PHASE_AI_CLEANUP));
// Human field is at index [1]
fieldViews.get(1).getLblUpkeep().setEnabled(fp.getPrefBoolean(FPref.PHASE_HUMAN_UPKEEP));
fieldViews.get(1).getLblDraw().setEnabled(fp.getPrefBoolean(FPref.PHASE_HUMAN_DRAW));
fieldViews.get(1).getLblMain1().setEnabled(fp.getPrefBoolean(FPref.PHASE_HUMAN_MAIN1));
fieldViews.get(1).getLblBeginCombat().setEnabled(fp.getPrefBoolean(FPref.PHASE_HUMAN_BEGINCOMBAT));
fieldViews.get(1).getLblDeclareAttackers().setEnabled(fp.getPrefBoolean(FPref.PHASE_HUMAN_DECLAREATTACKERS));
fieldViews.get(1).getLblDeclareBlockers().setEnabled(fp.getPrefBoolean(FPref.PHASE_HUMAN_DECLAREBLOCKERS));
fieldViews.get(1).getLblFirstStrike().setEnabled(fp.getPrefBoolean(FPref.PHASE_HUMAN_FIRSTSTRIKE));
fieldViews.get(1).getLblCombatDamage().setEnabled(fp.getPrefBoolean(FPref.PHASE_HUMAN_COMBATDAMAGE));
fieldViews.get(1).getLblEndCombat().setEnabled(fp.getPrefBoolean(FPref.PHASE_HUMAN_ENDCOMBAT));
fieldViews.get(1).getLblMain2().setEnabled(fp.getPrefBoolean(FPref.PHASE_HUMAN_MAIN2));
fieldViews.get(1).getLblEndTurn().setEnabled(fp.getPrefBoolean(FPref.PHASE_HUMAN_EOT));
fieldViews.get(1).getLblCleanup().setEnabled(fp.getPrefBoolean(FPref.PHASE_HUMAN_CLEANUP));
//Singletons.getView().getViewMatch().setLayoutParams(fp.getPref(FPref.UI_LAYOUT_PARAMS));
return true; return true;
} }

View File

@@ -29,9 +29,14 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import forge.Constant;
import forge.gui.home.EMenuItem; import forge.gui.home.EMenuItem;
import forge.gui.match.VMatchUI;
import forge.gui.match.nonsingleton.VField;
import forge.gui.match.views.VDev;
/** /**
* Holds default preference values in an enum. * Holds default preference values in an enum.
@@ -192,6 +197,97 @@ public class ForgePreferences {
} }
} }
/**
* TODO: Needs to be reworked for efficiency with rest of prefs saves in
* codebase.
*/
public void writeMatchPreferences() {
final List<VField> fieldViews = VMatchUI.SINGLETON_INSTANCE.getFieldViews();
// AI field is at index [0]
this.setPref(FPref.PHASE_AI_UPKEEP, String.valueOf(fieldViews.get(0).getLblUpkeep().getEnabled()));
this.setPref(FPref.PHASE_AI_DRAW, String.valueOf(fieldViews.get(0).getLblDraw().getEnabled()));
this.setPref(FPref.PHASE_AI_MAIN1, String.valueOf(fieldViews.get(0).getLblMain1().getEnabled()));
this.setPref(FPref.PHASE_AI_BEGINCOMBAT, String.valueOf(fieldViews.get(0).getLblBeginCombat().getEnabled()));
this.setPref(FPref.PHASE_AI_DECLAREATTACKERS,
String.valueOf(fieldViews.get(0).getLblDeclareAttackers().getEnabled()));
this.setPref(FPref.PHASE_AI_DECLAREBLOCKERS,
String.valueOf(fieldViews.get(0).getLblDeclareBlockers().getEnabled()));
this.setPref(FPref.PHASE_AI_FIRSTSTRIKE, String.valueOf(fieldViews.get(0).getLblFirstStrike().getEnabled()));
this.setPref(FPref.PHASE_AI_COMBATDAMAGE, String.valueOf(fieldViews.get(0).getLblCombatDamage().getEnabled()));
this.setPref(FPref.PHASE_AI_ENDCOMBAT, String.valueOf(fieldViews.get(0).getLblEndCombat().getEnabled()));
this.setPref(FPref.PHASE_AI_MAIN2, String.valueOf(fieldViews.get(0).getLblMain2().getEnabled()));
this.setPref(FPref.PHASE_AI_EOT, String.valueOf(fieldViews.get(0).getLblEndTurn().getEnabled()));
this.setPref(FPref.PHASE_AI_CLEANUP, String.valueOf(fieldViews.get(0).getLblCleanup().getEnabled()));
// Human field is at index [1]
this.setPref(FPref.PHASE_HUMAN_UPKEEP, String.valueOf(fieldViews.get(1).getLblUpkeep().getEnabled()));
this.setPref(FPref.PHASE_HUMAN_DRAW, String.valueOf(fieldViews.get(1).getLblDraw().getEnabled()));
this.setPref(FPref.PHASE_HUMAN_MAIN1, String.valueOf(fieldViews.get(1).getLblMain1().getEnabled()));
this.setPref(FPref.PHASE_HUMAN_BEGINCOMBAT, String.valueOf(fieldViews.get(1).getLblBeginCombat().getEnabled()));
this.setPref(FPref.PHASE_HUMAN_DECLAREATTACKERS,
String.valueOf(fieldViews.get(1).getLblDeclareAttackers().getEnabled()));
this.setPref(FPref.PHASE_HUMAN_DECLAREBLOCKERS,
String.valueOf(fieldViews.get(1).getLblDeclareBlockers().getEnabled()));
this.setPref(FPref.PHASE_HUMAN_FIRSTSTRIKE, String.valueOf(fieldViews.get(1).getLblFirstStrike().getEnabled()));
this.setPref(FPref.PHASE_HUMAN_COMBATDAMAGE, String.valueOf(fieldViews.get(1).getLblCombatDamage().getEnabled()));
this.setPref(FPref.PHASE_HUMAN_ENDCOMBAT, String.valueOf(fieldViews.get(1).getLblEndCombat().getEnabled()));
this.setPref(FPref.PHASE_HUMAN_MAIN2, String.valueOf(fieldViews.get(1).getLblMain2().getEnabled()));
this.setPref(FPref.PHASE_HUMAN_EOT, String.valueOf(fieldViews.get(1).getLblEndTurn().getEnabled()));
this.setPref(FPref.PHASE_HUMAN_CLEANUP, String.valueOf(fieldViews.get(1).getLblCleanup().getEnabled()));
final VDev v = VDev.SINGLETON_INSTANCE;
Constant.Runtime.MILL[0] = v.getLblMilling().getEnabled();
this.setPref(FPref.DEV_MILLING_LOSS, String.valueOf(Constant.Runtime.MILL[0]));
this.setPref(FPref.DEV_UNLIMITED_LAND, String.valueOf(v.getLblUnlimitedLands().getEnabled()));
}
/**
* TODO: Needs to be reworked for efficiency with rest of prefs saves in
* codebase.
*/
public void actuateMatchPreferences() {
final List<VField> fieldViews = VMatchUI.SINGLETON_INSTANCE.getFieldViews();
Constant.Runtime.MILL[0] = this.getPrefBoolean(FPref.DEV_MILLING_LOSS);
Constant.Runtime.DEV_MODE[0] = this.getPrefBoolean(FPref.DEV_MODE_ENABLED);
Constant.Runtime.UPLOAD_DRAFT[0] = this.getPrefBoolean(FPref.UI_UPLOAD_DRAFT);
Constant.Runtime.RANDOM_FOIL[0] = this.getPrefBoolean(FPref.UI_RANDOM_FOIL);
Constant.Runtime.UPLOAD_DRAFT[0] = (Constant.Runtime.NET_CONN[0] ? this.getPrefBoolean(FPref.UI_UPLOAD_DRAFT)
: false);
// AI field is at index [0]
fieldViews.get(0).getLblUpkeep().setEnabled(this.getPrefBoolean(FPref.PHASE_AI_UPKEEP));
fieldViews.get(0).getLblDraw().setEnabled(this.getPrefBoolean(FPref.PHASE_AI_DRAW));
fieldViews.get(0).getLblMain1().setEnabled(this.getPrefBoolean(FPref.PHASE_AI_MAIN1));
fieldViews.get(0).getLblBeginCombat().setEnabled(this.getPrefBoolean(FPref.PHASE_AI_BEGINCOMBAT));
fieldViews.get(0).getLblDeclareAttackers().setEnabled(this.getPrefBoolean(FPref.PHASE_AI_DECLAREATTACKERS));
fieldViews.get(0).getLblDeclareBlockers().setEnabled(this.getPrefBoolean(FPref.PHASE_AI_DECLAREBLOCKERS));
fieldViews.get(0).getLblFirstStrike().setEnabled(this.getPrefBoolean(FPref.PHASE_AI_FIRSTSTRIKE));
fieldViews.get(0).getLblCombatDamage().setEnabled(this.getPrefBoolean(FPref.PHASE_AI_COMBATDAMAGE));
fieldViews.get(0).getLblEndCombat().setEnabled(this.getPrefBoolean(FPref.PHASE_AI_ENDCOMBAT));
fieldViews.get(0).getLblMain2().setEnabled(this.getPrefBoolean(FPref.PHASE_AI_MAIN2));
fieldViews.get(0).getLblEndTurn().setEnabled(this.getPrefBoolean(FPref.PHASE_AI_EOT));
fieldViews.get(0).getLblCleanup().setEnabled(this.getPrefBoolean(FPref.PHASE_AI_CLEANUP));
// Human field is at index [1]
fieldViews.get(1).getLblUpkeep().setEnabled(this.getPrefBoolean(FPref.PHASE_HUMAN_UPKEEP));
fieldViews.get(1).getLblDraw().setEnabled(this.getPrefBoolean(FPref.PHASE_HUMAN_DRAW));
fieldViews.get(1).getLblMain1().setEnabled(this.getPrefBoolean(FPref.PHASE_HUMAN_MAIN1));
fieldViews.get(1).getLblBeginCombat().setEnabled(this.getPrefBoolean(FPref.PHASE_HUMAN_BEGINCOMBAT));
fieldViews.get(1).getLblDeclareAttackers().setEnabled(this.getPrefBoolean(FPref.PHASE_HUMAN_DECLAREATTACKERS));
fieldViews.get(1).getLblDeclareBlockers().setEnabled(this.getPrefBoolean(FPref.PHASE_HUMAN_DECLAREBLOCKERS));
fieldViews.get(1).getLblFirstStrike().setEnabled(this.getPrefBoolean(FPref.PHASE_HUMAN_FIRSTSTRIKE));
fieldViews.get(1).getLblCombatDamage().setEnabled(this.getPrefBoolean(FPref.PHASE_HUMAN_COMBATDAMAGE));
fieldViews.get(1).getLblEndCombat().setEnabled(this.getPrefBoolean(FPref.PHASE_HUMAN_ENDCOMBAT));
fieldViews.get(1).getLblMain2().setEnabled(this.getPrefBoolean(FPref.PHASE_HUMAN_MAIN2));
fieldViews.get(1).getLblEndTurn().setEnabled(this.getPrefBoolean(FPref.PHASE_HUMAN_EOT));
fieldViews.get(1).getLblCleanup().setEnabled(this.getPrefBoolean(FPref.PHASE_HUMAN_CLEANUP));
//Singletons.getView().getViewMatch().setLayoutParams(this.getPref(FPref.UI_LAYOUT_PARAMS));
}
/** Saves prefs map to file. */ /** Saves prefs map to file. */
public void save() { public void save() {
BufferedWriter writer = null; BufferedWriter writer = null;

View File

@@ -15,6 +15,7 @@ import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder; import javax.swing.border.LineBorder;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import forge.AllZone; import forge.AllZone;
import forge.Singletons; import forge.Singletons;
import forge.control.FControl; import forge.control.FControl;
@@ -38,7 +39,7 @@ public enum FView {
/** */ /** */
public static final Integer TARGETING_LAYER = JLayeredPane.MODAL_LAYER - 1; public static final Integer TARGETING_LAYER = JLayeredPane.MODAL_LAYER - 1;
private final List<DragCell> allCells = new ArrayList<DragCell>(); private final List<DragCell> allCells = new ArrayList<DragCell>();
private SplashFrame splash; private SplashFrame frmSplash;
// Non-singleton instances (deprecated, but not updated yet) // Non-singleton instances (deprecated, but not updated yet)
private ViewBazaarUI bazaar = null; private ViewBazaarUI bazaar = null;
@@ -51,14 +52,18 @@ public enum FView {
private final JPanel pnlContent = new JPanel(); private final JPanel pnlContent = new JPanel();
// An insets panel neatly maintains a space from the edges of the window and // An insets panel neatly maintains a space from the edges of the window and
// whatever layout is happening, without having to explicitly define a margin each time. // whatever layout is happening, without having to explicitly define a margin each time.
private final FPanel pnlInsets = new FPanel(new BorderLayout()); private FPanel pnlInsets;
// Preview panel is what is shown when a drag cell is being moved around // Preview panel is what is shown when a drag cell is being moved around
private final JPanel pnlPreview = new PreviewPanel(); private final JPanel pnlPreview = new PreviewPanel();
// Tab overflow is for the +X display for extra tabs. // Tab overflow is for the +X display for extra tabs.
private final JPanel pnlTabOverflow = new JPanel(new MigLayout("insets 0, gap 0, wrap")); private final JPanel pnlTabOverflow = new JPanel(new MigLayout("insets 0, gap 0, wrap"));
private FView() { private FView() {
splash = new SplashFrame(); frmSplash = new SplashFrame();
// Insets panel has background image / texture, which
// must be instantiated after the skin is loaded.
pnlInsets = new FPanel(new BorderLayout());
} }
/** */ /** */
@@ -78,7 +83,7 @@ public enum FView {
lpnDocument.add(pnlTabOverflow, (Integer) 3); lpnDocument.add(pnlTabOverflow, (Integer) 3);
lpnDocument.add(FOverlay.SINGLETON_INSTANCE.getPanel(), JLayeredPane.MODAL_LAYER); lpnDocument.add(FOverlay.SINGLETON_INSTANCE.getPanel(), JLayeredPane.MODAL_LAYER);
// Note: when adding new panels here, keep in mind that the layered pane // Note: when adding new panels here, keep in mind that the layered pane
// has a null layout, so new components will be (0,0) - gotcha! // has a null layout, so new components will be W0 x H0 pixels - gotcha!
// FControl has a method called "sizeComponents" which will fix this. // FControl has a method called "sizeComponents" which will fix this.
lpnDocument.add(TargetingOverlay.SINGLETON_INSTANCE.getPanel(), TARGETING_LAYER); lpnDocument.add(TargetingOverlay.SINGLETON_INSTANCE.getPanel(), TARGETING_LAYER);
@@ -106,12 +111,17 @@ public enum FView {
Singletons.getControl().changeState(FControl.HOME_SCREEN); Singletons.getControl().changeState(FControl.HOME_SCREEN);
CMainMenu.SINGLETON_INSTANCE.selectPrevious(); CMainMenu.SINGLETON_INSTANCE.selectPrevious();
FView.this.splash.dispose(); FView.this.frmSplash.dispose();
FView.this.splash = null; FView.this.frmSplash = null;
frmDocument.setVisible(true); frmDocument.setVisible(true);
} }
/** @return {@link forge.view.SplashFrame} */
public SplashFrame getSplash() {
return frmSplash;
}
/** @return {@link javax.swing.JFrame} */ /** @return {@link javax.swing.JFrame} */
public JFrame getFrame() { public JFrame getFrame() {
return frmDocument; return frmDocument;

View File

@@ -17,11 +17,8 @@
*/ */
package forge.view; package forge.view;
import javax.swing.SwingUtilities;
import forge.Singletons; import forge.Singletons;
import forge.control.FControl; import forge.control.FControl;
import forge.error.ExceptionHandler;
import forge.model.FModel; import forge.model.FModel;
/** /**
@@ -33,7 +30,7 @@ public final class Main {
* Do not instantiate. * Do not instantiate.
*/ */
private Main() { private Main() {
// intentionally blank // Intentionally blank.
} }
/** /**
@@ -43,31 +40,16 @@ public final class Main {
* an array of {@link java.lang.String} objects. * an array of {@link java.lang.String} objects.
*/ */
public static void main(final String[] args) { public static void main(final String[] args) {
//Possible solution to "Comparison method violates it's general contract!" crash // HACK - temporary solution to "Comparison method violates it's general contract!" crash
System.setProperty("java.util.Arrays.useLegacyMergeSort", "true"); System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
ExceptionHandler.registerErrorHandling(); // Start splash screen first, then data models, then controller.
Singletons.setModel(FModel.SINGLETON_INSTANCE);
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
Singletons.setView(FView.SINGLETON_INSTANCE); Singletons.setView(FView.SINGLETON_INSTANCE);
} Singletons.setModel(FModel.SINGLETON_INSTANCE);
});
} catch (Exception e) {
e.printStackTrace();
}
Singletons.setControl(FControl.SINGLETON_INSTANCE); Singletons.setControl(FControl.SINGLETON_INSTANCE);
// Use splash frame to initialize everything, then transition to core UI. // Controller can now step in and take over.
Singletons.getControl().initialize(); Singletons.getControl().initialize();
SwingUtilities.invokeLater(new Runnable() { @Override
public void run() { Singletons.getView().initialize(); } });
} }
/** @throws Throwable */ /** @throws Throwable */

View File

@@ -38,26 +38,36 @@ import javax.swing.UIManager;
import forge.gui.toolbox.FProgressBar; import forge.gui.toolbox.FProgressBar;
import forge.gui.toolbox.FSkin; import forge.gui.toolbox.FSkin;
import forge.properties.ForgePreferences;
import forge.properties.ForgePreferences.FPref;
/** /**
* Shows the splash frame as the application starts. * Shows the splash frame as the application starts.
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class SplashFrame extends JFrame { public class SplashFrame extends JFrame {
private static final int BAR_PADDING_X = 20; private FProgressBar barProgress;
private static final int BAR_PADDING_Y = 20;
private static final int BAR_HEIGHT = 57;
private static final int DISCLAIMER_HEIGHT = 20; private final MouseAdapter madClose = new MouseAdapter() {
private static final int DISCLAIMER_TOP = 300; @Override
private static final int DISCLAIMER_FONT_SIZE = 9; public void mouseEntered(final java.awt.event.MouseEvent evt) {
((JButton) evt.getSource()).setBorder(BorderFactory.createLineBorder(Color.white));
((JButton) evt.getSource()).setForeground(Color.white);
}
private static final int CLOSEBTN_PADDING_Y = 15; @Override
private static final int CLOSEBTN_SIDELENGTH = 15; public void mouseExited(final java.awt.event.MouseEvent evt) {
private static final Color CLOSEBTN_COLOR = new Color(215, 208, 188); ((JButton) evt.getSource()).setBorder(BorderFactory.createLineBorder(new Color(215, 208, 188)));
((JButton) evt.getSource()).setForeground(new Color(215, 208, 188));
}
};
/** Preload bar, static accessible. */ private final Action actClose = new AbstractAction() {
public static final FProgressBar PROGRESS_BAR = new FProgressBar(); @Override
public void actionPerformed(final ActionEvent e) {
System.exit(0);
}
};
/** /**
* Create the frame; this <strong>must</strong> be called from an event * Create the frame; this <strong>must</strong> be called from an event
@@ -66,18 +76,27 @@ public class SplashFrame extends JFrame {
*/ */
public SplashFrame() { public SplashFrame() {
super(); super();
final ForgePreferences prefs = new ForgePreferences();
FSkin.loadLight(prefs.getPref(FPref.UI_SKIN));
if (!SwingUtilities.isEventDispatchThread()) { try {
throw new IllegalStateException( SwingUtilities.invokeAndWait(new Runnable() {
"SplashFrame() must be called from an event dispatch thread."); @Override
public void run() {
SplashFrame.this.init();
}
});
}
catch (Exception e) {
}
} }
private void init() {
final ImageIcon bgIcon = FSkin.getIcon(FSkin.Backgrounds.BG_SPLASH); final ImageIcon bgIcon = FSkin.getIcon(FSkin.Backgrounds.BG_SPLASH);
final int splashWidthPx = bgIcon.getIconWidth(); barProgress = new FProgressBar();
final int splashHeightPx = bgIcon.getIconHeight();
this.setUndecorated(true); this.setUndecorated(true);
this.setMinimumSize(new Dimension(splashWidthPx, splashHeightPx)); this.setMinimumSize(new Dimension(450, 450));
this.setLocationRelativeTo(null); this.setLocationRelativeTo(null);
this.setResizable(false); this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -88,67 +107,47 @@ public class SplashFrame extends JFrame {
this.setContentPane(pnlContent); this.setContentPane(pnlContent);
pnlContent.setLayout(null); pnlContent.setLayout(null);
// Add disclaimer // Disclaimer
final JLabel lblDisclaimer = new JLabel("<html><center>" final JLabel lblDisclaimer = new JLabel("<html><center>"
+ "Forge is not affiliated in any way with Wizards of the Coast." + "Forge is not affiliated in any way with Wizards of the Coast."
+ "<br>Forge is open source software, released under " + "<br>Forge is open source software, released under "
+ "the GNU Public License.</center></html>"); + "the GNU Public License.</center></html>");
lblDisclaimer.setBounds(0, SplashFrame.DISCLAIMER_TOP, splashWidthPx, SplashFrame.DISCLAIMER_HEIGHT); lblDisclaimer.setBounds(0, 300, 450, 20);
lblDisclaimer.setFont(new Font("Tahoma", Font.PLAIN, 9));
lblDisclaimer.setFont(new Font("Tahoma", Font.PLAIN, SplashFrame.DISCLAIMER_FONT_SIZE));
lblDisclaimer.setHorizontalAlignment(SwingConstants.CENTER); lblDisclaimer.setHorizontalAlignment(SwingConstants.CENTER);
lblDisclaimer.setForeground(UIManager.getColor("ProgressBar.selectionForeground")); lblDisclaimer.setForeground(UIManager.getColor("ProgressBar.selectionForeground"));
pnlContent.add(lblDisclaimer); pnlContent.add(lblDisclaimer);
// Add close button // Close button
final JButton btnClose = new JButton("X"); final JButton btnClose = new JButton("X");
btnClose.setBounds(splashWidthPx - (2 * SplashFrame.CLOSEBTN_PADDING_Y), SplashFrame.CLOSEBTN_PADDING_Y, btnClose.setBounds(420, 15, 15, 15);
SplashFrame.CLOSEBTN_SIDELENGTH, SplashFrame.CLOSEBTN_SIDELENGTH); btnClose.setForeground(new Color(215, 208, 188));
btnClose.setForeground(SplashFrame.CLOSEBTN_COLOR); btnClose.setBorder(BorderFactory.createLineBorder(new Color(215, 208, 188)));
btnClose.setBorder(BorderFactory.createLineBorder(SplashFrame.CLOSEBTN_COLOR));
btnClose.setOpaque(false); btnClose.setOpaque(false);
btnClose.setBackground(new Color(0, 0, 0)); btnClose.setBackground(new Color(0, 0, 0));
btnClose.setFocusPainted(false); btnClose.setFocusPainted(false);
pnlContent.add(btnClose); pnlContent.add(btnClose);
// Actions and listeners for close button (also mapped to ESC)
final MouseAdapter madClose = new MouseAdapter() {
@Override
public void mouseEntered(final java.awt.event.MouseEvent evt) {
btnClose.setBorder(BorderFactory.createLineBorder(Color.white));
btnClose.setForeground(Color.white);
}
@Override
public void mouseExited(final java.awt.event.MouseEvent evt) {
btnClose.setBorder(BorderFactory.createLineBorder(SplashFrame.CLOSEBTN_COLOR));
btnClose.setForeground(SplashFrame.CLOSEBTN_COLOR);
}
};
final Action actClose = new AbstractAction() {
@Override
public void actionPerformed(final ActionEvent e) {
System.exit(0);
}
};
btnClose.addMouseListener(madClose); btnClose.addMouseListener(madClose);
btnClose.addActionListener(actClose); btnClose.addActionListener(actClose);
pnlContent.getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"), "escAction"); pnlContent.getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"), "escAction");
pnlContent.getActionMap().put("escAction", actClose); pnlContent.getActionMap().put("escAction", actClose);
PROGRESS_BAR.setString("Welcome to Forge."); barProgress.setString("Welcome to Forge.");
PROGRESS_BAR.setBounds(SplashFrame.BAR_PADDING_X, splashHeightPx - SplashFrame.BAR_PADDING_Y barProgress.setBounds(20, 373, 410, 57);
- SplashFrame.BAR_HEIGHT, splashWidthPx - (2 * SplashFrame.BAR_PADDING_X), SplashFrame.BAR_HEIGHT); pnlContent.add(barProgress);
pnlContent.add(PROGRESS_BAR);
final JLabel bgLabel = new JLabel(bgIcon); final JLabel bgLabel = new JLabel(bgIcon);
bgLabel.setBounds(0, 0, splashWidthPx, splashHeightPx); bgLabel.setBounds(0, 0, 450, 450);
pnlContent.add(bgLabel); pnlContent.add(bgLabel);
this.pack(); this.pack();
this.setVisible(true); this.setVisible(true);
} }
/** @return {@link forge.gui.toolbox.FProgressBar} */
public FProgressBar getProgressBar() {
return this.barProgress;
}
} }