mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Code cleanup - main, FControl, FView, FModel core.
Should fix occasional "long wait before splash" bug.
This commit is contained in:
@@ -35,7 +35,6 @@ import java.util.zip.ZipFile;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
|
||||
import forge.Card;
|
||||
import forge.CardCharacteristicName;
|
||||
import forge.CardColor;
|
||||
@@ -50,7 +49,7 @@ import forge.card.trigger.TriggerHandler;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.gui.toolbox.FProgressBar;
|
||||
import forge.util.FileUtil;
|
||||
import forge.view.SplashFrame;
|
||||
import forge.view.FView;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -127,12 +126,6 @@ public class CardReader {
|
||||
*
|
||||
* @param theCardsFolder
|
||||
* 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
|
||||
* if true, attempts to load cards from a zip file, if one
|
||||
* exists.
|
||||
@@ -186,15 +179,12 @@ public class CardReader {
|
||||
* After that, we save our place in the list of cards (on disk) in case we
|
||||
* 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.
|
||||
*/
|
||||
public final List<CardRules> loadCards() {
|
||||
|
||||
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.
|
||||
// Report relevant numbers to progress monitor model.
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.util.List;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JLayeredPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
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. */
|
||||
@@ -152,6 +150,7 @@ public enum FControl {
|
||||
// Does not use progress bar, due to be deprecated with battlefield refactoring.
|
||||
CardFaceSymbols.loadImages();
|
||||
|
||||
|
||||
this.shortcuts = KeyboardShortcuts.attachKeyboardShortcuts();
|
||||
this.display = FView.SINGLETON_INSTANCE.getLpnDocument();
|
||||
|
||||
@@ -170,6 +169,12 @@ public enum FControl {
|
||||
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(); } });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,7 +37,6 @@ import forge.model.FModel;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.view.FView;
|
||||
import forge.view.arcane.CardPanel;
|
||||
import forge.view.arcane.PlayArea;
|
||||
|
||||
/**
|
||||
* Semi-transparent overlay panel. Should be used with layered panes.
|
||||
@@ -50,21 +49,13 @@ public enum TargetingOverlay {
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
private final JPanel pnl = new OverlayPanel();
|
||||
private final List<PlayArea> playAreas;
|
||||
private List<CardPanel> cardPanels;
|
||||
private final List<CardPanel> cardPanels = new ArrayList<CardPanel>();
|
||||
private final List<Point[]> arcs = new ArrayList<Point[]>();
|
||||
|
||||
/**
|
||||
* Semi-transparent overlay panel. Should be used with layered panes.
|
||||
*/
|
||||
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.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA));
|
||||
}
|
||||
@@ -80,8 +71,10 @@ public enum TargetingOverlay {
|
||||
private void assembleArcs() {
|
||||
arcs.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();
|
||||
// Locations of arc endpoint, per card, with ID as primary key.
|
||||
|
||||
@@ -38,7 +38,7 @@ import javax.swing.UIManager;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.view.SplashFrame;
|
||||
import forge.view.FView;
|
||||
|
||||
/**
|
||||
* 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"); }
|
||||
|
||||
// Everything OK?
|
||||
final FProgressBar barProgress = SplashFrame.PROGRESS_BAR;
|
||||
final FProgressBar barProgress = FView.SINGLETON_INSTANCE.getSplash().getProgressBar();
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
|
||||
@@ -36,14 +36,11 @@ import forge.card.FatPackData;
|
||||
import forge.card.FormatCollection;
|
||||
import forge.control.input.InputControl;
|
||||
import forge.deck.CardCollections;
|
||||
import forge.error.ExceptionHandler;
|
||||
import forge.game.GameState;
|
||||
import forge.game.GameSummary;
|
||||
import forge.game.player.ComputerAIGeneral;
|
||||
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.FPref;
|
||||
import forge.properties.ForgeProps;
|
||||
@@ -93,7 +90,6 @@ public enum FModel {
|
||||
// CardDb is not ready yet.
|
||||
private CardCollections decks;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -101,7 +97,9 @@ public enum FModel {
|
||||
* if we could not find or write to the log file.
|
||||
*/
|
||||
private FModel() {
|
||||
// Fire up log file
|
||||
// Fire up log file and exception handling
|
||||
ExceptionHandler.registerErrorHandling();
|
||||
|
||||
final File logFile = new File("forge.log");
|
||||
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.fantasyBlocks = new StorageView<CardBlock>(new CardBlock.Reader("res/blockdata/fantasyblocks.txt", editions));
|
||||
|
||||
// TODO this single setting from preferences should not be here, or,
|
||||
// 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
|
||||
// TODO - there's got to be a better place for this...oblivion?
|
||||
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
|
||||
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
|
||||
* codebase.
|
||||
*
|
||||
* TODO: Remove this method completely.
|
||||
* @return true, if successful
|
||||
*/
|
||||
public final boolean savePrefs() {
|
||||
final ForgePreferences fp = this.preferences;
|
||||
final List<VField> fieldViews = VMatchUI.SINGLETON_INSTANCE.getFieldViews();
|
||||
|
||||
// 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();
|
||||
this.preferences.writeMatchPreferences();
|
||||
this.preferences.save();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Needs to be reworked for efficiency with rest of prefs loads in
|
||||
* codebase.
|
||||
* TODO: Remove this method completely.
|
||||
*
|
||||
* @return true, if successful
|
||||
*/
|
||||
public final boolean loadPrefs() {
|
||||
final ForgePreferences fp = Singletons.getModel().getPreferences();
|
||||
final List<VField> fieldViews = VMatchUI.SINGLETON_INSTANCE.getFieldViews();
|
||||
|
||||
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));
|
||||
fp.actuateMatchPreferences();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,9 +29,14 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import forge.Constant;
|
||||
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.
|
||||
@@ -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. */
|
||||
public void save() {
|
||||
BufferedWriter writer = null;
|
||||
|
||||
@@ -15,6 +15,7 @@ import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Singletons;
|
||||
import forge.control.FControl;
|
||||
@@ -38,7 +39,7 @@ public enum FView {
|
||||
/** */
|
||||
public static final Integer TARGETING_LAYER = JLayeredPane.MODAL_LAYER - 1;
|
||||
private final List<DragCell> allCells = new ArrayList<DragCell>();
|
||||
private SplashFrame splash;
|
||||
private SplashFrame frmSplash;
|
||||
|
||||
// Non-singleton instances (deprecated, but not updated yet)
|
||||
private ViewBazaarUI bazaar = null;
|
||||
@@ -51,14 +52,18 @@ public enum FView {
|
||||
private final JPanel pnlContent = new JPanel();
|
||||
// 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.
|
||||
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
|
||||
private final JPanel pnlPreview = new PreviewPanel();
|
||||
// Tab overflow is for the +X display for extra tabs.
|
||||
private final JPanel pnlTabOverflow = new JPanel(new MigLayout("insets 0, gap 0, wrap"));
|
||||
|
||||
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(FOverlay.SINGLETON_INSTANCE.getPanel(), JLayeredPane.MODAL_LAYER);
|
||||
// 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.
|
||||
lpnDocument.add(TargetingOverlay.SINGLETON_INSTANCE.getPanel(), TARGETING_LAYER);
|
||||
|
||||
@@ -106,12 +111,17 @@ public enum FView {
|
||||
Singletons.getControl().changeState(FControl.HOME_SCREEN);
|
||||
CMainMenu.SINGLETON_INSTANCE.selectPrevious();
|
||||
|
||||
FView.this.splash.dispose();
|
||||
FView.this.splash = null;
|
||||
FView.this.frmSplash.dispose();
|
||||
FView.this.frmSplash = null;
|
||||
|
||||
frmDocument.setVisible(true);
|
||||
}
|
||||
|
||||
/** @return {@link forge.view.SplashFrame} */
|
||||
public SplashFrame getSplash() {
|
||||
return frmSplash;
|
||||
}
|
||||
|
||||
/** @return {@link javax.swing.JFrame} */
|
||||
public JFrame getFrame() {
|
||||
return frmDocument;
|
||||
|
||||
@@ -17,11 +17,8 @@
|
||||
*/
|
||||
package forge.view;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.control.FControl;
|
||||
import forge.error.ExceptionHandler;
|
||||
import forge.model.FModel;
|
||||
|
||||
/**
|
||||
@@ -33,7 +30,7 @@ public final class Main {
|
||||
* Do not instantiate.
|
||||
*/
|
||||
private Main() {
|
||||
// intentionally blank
|
||||
// Intentionally blank.
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,31 +40,16 @@ public final class Main {
|
||||
* an array of {@link java.lang.String} objects.
|
||||
*/
|
||||
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");
|
||||
|
||||
ExceptionHandler.registerErrorHandling();
|
||||
|
||||
// Start splash screen first, then data models, then controller.
|
||||
Singletons.setView(FView.SINGLETON_INSTANCE);
|
||||
Singletons.setModel(FModel.SINGLETON_INSTANCE);
|
||||
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Singletons.setView(FView.SINGLETON_INSTANCE);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() { @Override
|
||||
public void run() { Singletons.getView().initialize(); } });
|
||||
}
|
||||
|
||||
/** @throws Throwable */
|
||||
|
||||
@@ -38,26 +38,36 @@ import javax.swing.UIManager;
|
||||
|
||||
import forge.gui.toolbox.FProgressBar;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
|
||||
/**
|
||||
* Shows the splash frame as the application starts.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class SplashFrame extends JFrame {
|
||||
private static final int BAR_PADDING_X = 20;
|
||||
private static final int BAR_PADDING_Y = 20;
|
||||
private static final int BAR_HEIGHT = 57;
|
||||
private FProgressBar barProgress;
|
||||
|
||||
private static final int DISCLAIMER_HEIGHT = 20;
|
||||
private static final int DISCLAIMER_TOP = 300;
|
||||
private static final int DISCLAIMER_FONT_SIZE = 9;
|
||||
private final MouseAdapter madClose = new MouseAdapter() {
|
||||
@Override
|
||||
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;
|
||||
private static final int CLOSEBTN_SIDELENGTH = 15;
|
||||
private static final Color CLOSEBTN_COLOR = new Color(215, 208, 188);
|
||||
@Override
|
||||
public void mouseExited(final java.awt.event.MouseEvent evt) {
|
||||
((JButton) evt.getSource()).setBorder(BorderFactory.createLineBorder(new Color(215, 208, 188)));
|
||||
((JButton) evt.getSource()).setForeground(new Color(215, 208, 188));
|
||||
}
|
||||
};
|
||||
|
||||
/** Preload bar, static accessible. */
|
||||
public static final FProgressBar PROGRESS_BAR = new FProgressBar();
|
||||
private final Action actClose = new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create the frame; this <strong>must</strong> be called from an event
|
||||
@@ -66,18 +76,27 @@ public class SplashFrame extends JFrame {
|
||||
*/
|
||||
public SplashFrame() {
|
||||
super();
|
||||
final ForgePreferences prefs = new ForgePreferences();
|
||||
FSkin.loadLight(prefs.getPref(FPref.UI_SKIN));
|
||||
|
||||
if (!SwingUtilities.isEventDispatchThread()) {
|
||||
throw new IllegalStateException(
|
||||
"SplashFrame() must be called from an event dispatch thread.");
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SplashFrame.this.init();
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
private void init() {
|
||||
final ImageIcon bgIcon = FSkin.getIcon(FSkin.Backgrounds.BG_SPLASH);
|
||||
final int splashWidthPx = bgIcon.getIconWidth();
|
||||
final int splashHeightPx = bgIcon.getIconHeight();
|
||||
barProgress = new FProgressBar();
|
||||
|
||||
this.setUndecorated(true);
|
||||
this.setMinimumSize(new Dimension(splashWidthPx, splashHeightPx));
|
||||
this.setMinimumSize(new Dimension(450, 450));
|
||||
this.setLocationRelativeTo(null);
|
||||
this.setResizable(false);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
@@ -88,67 +107,47 @@ public class SplashFrame extends JFrame {
|
||||
this.setContentPane(pnlContent);
|
||||
pnlContent.setLayout(null);
|
||||
|
||||
// Add disclaimer
|
||||
// Disclaimer
|
||||
final JLabel lblDisclaimer = new JLabel("<html><center>"
|
||||
+ "Forge is not affiliated in any way with Wizards of the Coast."
|
||||
+ "<br>Forge is open source software, released under "
|
||||
+ "the GNU Public License.</center></html>");
|
||||
|
||||
lblDisclaimer.setBounds(0, SplashFrame.DISCLAIMER_TOP, splashWidthPx, SplashFrame.DISCLAIMER_HEIGHT);
|
||||
|
||||
lblDisclaimer.setFont(new Font("Tahoma", Font.PLAIN, SplashFrame.DISCLAIMER_FONT_SIZE));
|
||||
lblDisclaimer.setBounds(0, 300, 450, 20);
|
||||
lblDisclaimer.setFont(new Font("Tahoma", Font.PLAIN, 9));
|
||||
lblDisclaimer.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
lblDisclaimer.setForeground(UIManager.getColor("ProgressBar.selectionForeground"));
|
||||
pnlContent.add(lblDisclaimer);
|
||||
|
||||
// Add close button
|
||||
// Close button
|
||||
final JButton btnClose = new JButton("X");
|
||||
btnClose.setBounds(splashWidthPx - (2 * SplashFrame.CLOSEBTN_PADDING_Y), SplashFrame.CLOSEBTN_PADDING_Y,
|
||||
SplashFrame.CLOSEBTN_SIDELENGTH, SplashFrame.CLOSEBTN_SIDELENGTH);
|
||||
btnClose.setForeground(SplashFrame.CLOSEBTN_COLOR);
|
||||
btnClose.setBorder(BorderFactory.createLineBorder(SplashFrame.CLOSEBTN_COLOR));
|
||||
btnClose.setBounds(420, 15, 15, 15);
|
||||
btnClose.setForeground(new Color(215, 208, 188));
|
||||
btnClose.setBorder(BorderFactory.createLineBorder(new Color(215, 208, 188)));
|
||||
btnClose.setOpaque(false);
|
||||
btnClose.setBackground(new Color(0, 0, 0));
|
||||
btnClose.setFocusPainted(false);
|
||||
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.addActionListener(actClose);
|
||||
pnlContent.getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"), "escAction");
|
||||
pnlContent.getActionMap().put("escAction", actClose);
|
||||
|
||||
PROGRESS_BAR.setString("Welcome to Forge.");
|
||||
PROGRESS_BAR.setBounds(SplashFrame.BAR_PADDING_X, splashHeightPx - SplashFrame.BAR_PADDING_Y
|
||||
- SplashFrame.BAR_HEIGHT, splashWidthPx - (2 * SplashFrame.BAR_PADDING_X), SplashFrame.BAR_HEIGHT);
|
||||
pnlContent.add(PROGRESS_BAR);
|
||||
barProgress.setString("Welcome to Forge.");
|
||||
barProgress.setBounds(20, 373, 410, 57);
|
||||
pnlContent.add(barProgress);
|
||||
|
||||
final JLabel bgLabel = new JLabel(bgIcon);
|
||||
bgLabel.setBounds(0, 0, splashWidthPx, splashHeightPx);
|
||||
bgLabel.setBounds(0, 0, 450, 450);
|
||||
pnlContent.add(bgLabel);
|
||||
|
||||
this.pack();
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
/** @return {@link forge.gui.toolbox.FProgressBar} */
|
||||
public FProgressBar getProgressBar() {
|
||||
return this.barProgress;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user