void editDeck(final Deck d0) {
ACEditorBase extends InventoryItem, ? extends DeckBase> editorCtrl = null;
- FControl.Screens newState = null;
+ FScreen screen = null;
switch (this.gametype) {
case Quest:
+ screen = FScreen.DECK_EDITOR_QUEST;
editorCtrl = new CEditorQuest(Singletons.getModel().getQuest());
- newState = FControl.Screens.DECK_EDITOR_QUEST;
break;
case Constructed:
- newState = FControl.Screens.DECK_EDITOR_CONSTRUCTED;
- editorCtrl = new CEditorConstructed();
+ screen = FScreen.DECK_EDITOR_CONSTRUCTED;
+ //re-use constructed controller
break;
case Sealed:
- editorCtrl = new CEditorLimited(Singletons.getModel().getDecks().getSealed());
- newState = FControl.Screens.DECK_EDITOR_LIMITED;
+ screen = FScreen.DECK_EDITOR_SEALED;
+ editorCtrl = new CEditorLimited(Singletons.getModel().getDecks().getSealed(), screen);
break;
case Draft:
- editorCtrl = new CEditorLimited(Singletons.getModel().getDecks().getDraft());
- newState = FControl.Screens.DECK_EDITOR_LIMITED;
+ screen = FScreen.DECK_EDITOR_DRAFT;
+ editorCtrl = new CEditorLimited(Singletons.getModel().getDecks().getDraft(), screen);
break;
default:
return;
}
- Singletons.getControl().changeStateAutoFixLayout(newState, "deck editor");
- CDeckEditorUI.SINGLETON_INSTANCE.setCurrentEditorController(editorCtrl);
- editorCtrl.getDeckController().load(d0.getName());
+ Singletons.getControl().setCurrentScreen(screen);
+ if (editorCtrl != null) {
+ CDeckEditorUI.SINGLETON_INSTANCE.setCurrentEditorController(editorCtrl);
+ }
+ CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().getDeckController().load(d0.getName());
}
private void deleteDeck(final RowPanel r0) {
diff --git a/src/main/java/forge/properties/NewConstants.java b/src/main/java/forge/properties/NewConstants.java
index f3a1abdeddc..124ec2e4496 100644
--- a/src/main/java/forge/properties/NewConstants.java
+++ b/src/main/java/forge/properties/NewConstants.java
@@ -87,7 +87,6 @@ public final class NewConstants {
private static final String _DEFAULTS_DIR = _RES_ROOT + "defaults/";
public static final FileLocation EDITOR_PREFERENCES_FILE = new FileLocation(_DEFAULTS_DIR, USER_PREFS_DIR, "editor.preferences");
public static final FileLocation WINDOW_LAYOUT_FILE = new FileLocation(_DEFAULTS_DIR, USER_PREFS_DIR, "window.xml");
- public static final FileLocation HOME_LAYOUT_FILE = new FileLocation(_DEFAULTS_DIR, USER_PREFS_DIR, "home.xml");
public static final FileLocation MATCH_LAYOUT_FILE = new FileLocation(_DEFAULTS_DIR, USER_PREFS_DIR, "match.xml");
public static final FileLocation EDITOR_LAYOUT_FILE = new FileLocation(_DEFAULTS_DIR, USER_PREFS_DIR, "editor.xml");
public static final FileLocation GAUNTLET_DIR = new FileLocation(_DEFAULTS_DIR, USER_DIR, "gauntlet/");
diff --git a/src/main/java/forge/quest/gui/ViewStall.java b/src/main/java/forge/quest/gui/ViewStall.java
index a069c7ee4d2..bbae21aea3a 100644
--- a/src/main/java/forge/quest/gui/ViewStall.java
+++ b/src/main/java/forge/quest/gui/ViewStall.java
@@ -31,6 +31,7 @@ import javax.swing.text.StyledDocument;
import net.miginfocom.swing.MigLayout;
import forge.Singletons;
+import forge.gui.bazaar.VBazaarUI;
import forge.gui.toolbox.FLabel;
import forge.gui.toolbox.FScrollPane;
import forge.gui.toolbox.FSkin;
@@ -39,7 +40,6 @@ import forge.quest.QuestController;
import forge.quest.bazaar.IQuestBazaarItem;
import forge.quest.bazaar.QuestStallDefinition;
import forge.quest.data.QuestAssets;
-import forge.view.ViewBazaarUI;
/**
*
@@ -55,15 +55,15 @@ public class ViewStall extends JPanel {
private final JTextPane tpnFluff;
private final JPanel pnlInventory;
private final FScrollPane scrInventory;
- private final ViewBazaarUI parentView;
+ private final VBazaarUI parentView;
private final List lstItemPanels;
private QuestStallDefinition stall;
/**
* @param v0
- * {@link forge.view.ViewBazaarUI}
+ * {@link forge.gui.bazaar.VBazaarUI}
*/
- public ViewStall(final ViewBazaarUI v0) {
+ public ViewStall(final VBazaarUI v0) {
// Final/component inits
this.lblStallName = new FLabel.Builder().text("").fontAlign(SwingConstants.CENTER).build();
this.lblEmpty = new FLabel.Builder().text("The merchant does not have anything useful for sale.")
@@ -179,8 +179,8 @@ public class ViewStall extends JPanel {
}
}
- /** @return {@link forge.view.ViewBazaarUI} */
- public ViewBazaarUI getParentView() {
+ /** @return {@link forge.gui.bazaar.VBazaarUI} */
+ public VBazaarUI getParentView() {
return this.parentView;
}
}
diff --git a/src/main/java/forge/view/FNavigationBar.java b/src/main/java/forge/view/FNavigationBar.java
index c83a3a1d2d5..93e1dbf7a7b 100644
--- a/src/main/java/forge/view/FNavigationBar.java
+++ b/src/main/java/forge/view/FNavigationBar.java
@@ -24,10 +24,8 @@ import javax.swing.Timer;
import javax.swing.border.EmptyBorder;
import forge.Singletons;
-import forge.control.FControl.Screens;
-import forge.gui.deckeditor.CDeckEditorUI;
+import forge.gui.framework.FScreen;
import forge.gui.framework.ILocalRepaint;
-import forge.gui.home.CHomeUI;
import forge.gui.menus.ForgeMenu;
import forge.gui.menus.LayoutMenu;
import forge.gui.toolbox.FButton;
@@ -35,7 +33,6 @@ import forge.gui.toolbox.FDigitalClock;
import forge.gui.toolbox.FSkin;
import forge.gui.toolbox.FSkin.JLabelSkin;
import forge.gui.toolbox.FSkin.SkinColor;
-import forge.gui.toolbox.FSkin.SkinImage;
import forge.util.TypeUtil;
@SuppressWarnings("serial")
@@ -75,7 +72,7 @@ public class FNavigationBar extends FTitleBarBase {
btnClose.setToolTipText("Close");
break;
case CLOSE_SCREEN:
- btnClose.setToolTipText(this.selectedTab.data.getCloseButtonTooltip());
+ btnClose.setToolTipText(this.selectedTab.screen.getCloseButtonTooltip());
break;
case EXIT_FORGE:
btnClose.setToolTipText("Exit Forge");
@@ -90,8 +87,8 @@ public class FNavigationBar extends FTitleBarBase {
layout.putConstraint(SpringLayout.SOUTH, btnForge, -1, SpringLayout.SOUTH, this);
addForgeButtonListeners();
- addNavigationTab(CHomeUI.SINGLETON_INSTANCE);
- addNavigationTab(CDeckEditorUI.SINGLETON_INSTANCE);
+ addNavigationTab(FScreen.HOME_SCREEN);
+ addNavigationTab(FScreen.DECK_EDITOR_CONSTRUCTED);
super.addControls();
@@ -101,8 +98,8 @@ public class FNavigationBar extends FTitleBarBase {
updateClockVisibility();
}
- private NavigationTab addNavigationTab(INavigationTabData data) {
- NavigationTab tab = new NavigationTab(data);
+ private NavigationTab addNavigationTab(FScreen screen) {
+ NavigationTab tab = new NavigationTab(screen);
if (tabs.size() == 0) {
tab.setSelected(true);
selectedTab = tab;
@@ -117,48 +114,41 @@ public class FNavigationBar extends FTitleBarBase {
return tab;
}
- private NavigationTab getTab(INavigationTabData data) {
+ private NavigationTab getTab(FScreen screen) {
for (NavigationTab tab : tabs) {
- if (tab.data == data) {
+ if (tab.screen == screen) {
return tab;
}
}
return null;
}
-
- public void ensureTabActive(INavigationTabData data) {
- NavigationTab tab = getTab(data);
- if (tab != null && !tab.selected) {
- setSelectedTab(tab);
- Singletons.getControl().changeStateAutoFixLayout(data.getTabDestScreen(), tab.getText());
- }
+
+ public boolean canSwitchAway() {
+ return (selectedTab == null || selectedTab.screen.onSwitching());
}
- public void setSelectedTab(INavigationTabData data) {
- NavigationTab tab = getTab(data);
+ public void updateSelectedTab() {
+ FScreen screen = Singletons.getControl().getCurrentScreen();
+ NavigationTab tab = getTab(screen);
if (tab == null) {
- tab = addNavigationTab(data); //if tab not found, add and select it
+ tab = addNavigationTab(screen); //if tab not found, add and select it
}
- setSelectedTab(tab);
- }
-
- private void setSelectedTab(NavigationTab tab) {
- if (tab != null && tab != selectedTab) {
- if (selectedTab != null) {
- selectedTab.setSelected(false);
- }
- tab.setSelected(true);
- selectedTab = tab;
- updateBtnCloseTooltip();
+ else if (tab == selectedTab) { return; }
+
+ if (selectedTab != null) {
+ selectedTab.setSelected(false);
}
+ tab.setSelected(true);
+ selectedTab = tab;
+ updateBtnCloseTooltip();
}
public void closeSelectedTab() {
closeTab(selectedTab);
}
- public void closeTab(INavigationTabData data) {
- NavigationTab tab = getTab(data);
+ public void closeTab(FScreen screen) {
+ NavigationTab tab = getTab(screen);
if (tab != null) {
closeTab(tab);
}
@@ -166,10 +156,13 @@ public class FNavigationBar extends FTitleBarBase {
private void closeTab(NavigationTab tab) {
if (tab == null) { return; }
- if (!tab.data.onClosing()) { return; } //give data a chance to perform special close handling and/or cancel closing tab
+ if (!tab.screen.onClosing()) { return; } //give screen a chance to perform special close handling and/or cancel closing tab
if (tab.selected) {
- setSelectedTab(tabs.get(0)); //select home tab if selected tab closed (TODO: support navigation history and go to previous tab instead)
+ //return to Home screen if selected tab closed
+ //TODO: support navigation history and go to previous tab instead
+ this.selectedTab = null; //prevent raising onSwitching for tab being closed
+ Singletons.getControl().setCurrentScreen(FScreen.HOME_SCREEN);
}
int index = tabs.indexOf(tab);
if (index != -1) {
@@ -350,39 +343,30 @@ public class FNavigationBar extends FTitleBarBase {
@Override
public void setIconImage(Image image) {
}
-
- public interface INavigationTabData {
- public String getTabCaption();
- public SkinImage getTabIcon();
- public Screens getTabDestScreen();
- public boolean allowTabClose();
- public String getCloseButtonTooltip();
- public boolean onClosing();
- }
private final class NavigationTab extends JLabel implements ILocalRepaint {
private static final int fontSize = 14;
private static final int unhoveredAlpha = 150;
private final FSkin.JLabelSkin skin;
- private final INavigationTabData data;
+ private final FScreen screen;
private final CloseButton btnClose;
private SkinColor backColor;
private boolean selected = false;
private boolean hovered = false;
- private NavigationTab(final INavigationTabData data0) {
- super(data0.getTabCaption());
- this.data = data0;
+ private NavigationTab(final FScreen screen0) {
+ super(screen0.getTabCaption());
+ this.screen = screen0;
setOpaque(false);
skin = FSkin.get(this);
- skin.setIcon(data0.getTabIcon());
+ skin.setIcon(screen0.getTabIcon());
skin.setForeground(foreColor.alphaColor(unhoveredAlpha));
skin.setFont(FSkin.getFont(fontSize));
int closeButtonOffset;
- if (data.allowTabClose()) {
+ if (screen.allowTabClose()) {
btnClose = new CloseButton();
- btnClose.setToolTipText(data.getCloseButtonTooltip());
+ btnClose.setToolTipText(screen.getCloseButtonTooltip());
closeButtonOffset = btnClose.getPreferredSize().width;
SpringLayout tabLayout = new SpringLayout();
setLayout(tabLayout);
@@ -402,11 +386,10 @@ public class FNavigationBar extends FTitleBarBase {
if (!NavigationTab.this.isEnabled()) { return; }
if (SwingUtilities.isLeftMouseButton(e)) {
if (!selected) {
- FNavigationBar.this.setSelectedTab(NavigationTab.this);
- Singletons.getControl().changeStateAutoFixLayout(data.getTabDestScreen(), NavigationTab.this.getText());
+ Singletons.getControl().setCurrentScreen(screen);
}
}
- else if (SwingUtilities.isMiddleMouseButton(e) && data.allowTabClose()) {
+ else if (SwingUtilities.isMiddleMouseButton(e) && screen.allowTabClose()) {
FNavigationBar.this.closeTab(NavigationTab.this);
}
}
diff --git a/src/main/java/forge/view/FView.java b/src/main/java/forge/view/FView.java
index b009a1a183f..6ad8e133847 100644
--- a/src/main/java/forge/view/FView.java
+++ b/src/main/java/forge/view/FView.java
@@ -33,14 +33,15 @@ import org.apache.commons.lang3.StringUtils;
import com.google.common.collect.Lists;
import forge.Singletons;
-import forge.control.FControl;
import forge.control.RestartUtil;
import forge.gui.FNetOverlay;
import forge.gui.ImportDialog;
import forge.gui.SOverlayUtils;
+import forge.gui.bazaar.VBazaarUI;
import forge.gui.deckeditor.VDeckEditorUI;
import forge.gui.framework.DragCell;
import forge.gui.framework.EDocID;
+import forge.gui.framework.FScreen;
import forge.gui.framework.SLayoutConstants;
import forge.gui.framework.SLayoutIO;
import forge.gui.home.VHomeUI;
@@ -74,7 +75,7 @@ public enum FView {
private SplashFrame frmSplash;
// Non-singleton instances (deprecated, but not updated yet)
- private ViewBazaarUI bazaar = null;
+ private VBazaarUI bazaar = null;
// Top-level UI components; all have getters.
private final FFrame frmDocument = new FFrame();
@@ -152,7 +153,7 @@ public enum FView {
}
// All is ready to go - fire up home screen and discard splash frame.
- Singletons.getControl().changeState(FControl.Screens.HOME_SCREEN);
+ Singletons.getControl().setCurrentScreen(FScreen.HOME_SCREEN);
FView.this.frmSplash.dispose();
FView.this.frmSplash = null;
@@ -408,9 +409,9 @@ public enum FView {
}
}
- /** @return {@link forge.view.ViewBazaarUI} */
- public ViewBazaarUI getViewBazaar() {
- if (Singletons.getControl().getState() != FControl.Screens.QUEST_BAZAAR) {
+ /** @return {@link forge.gui.bazaar.VBazaarUI} */
+ public VBazaarUI getViewBazaar() {
+ if (Singletons.getControl().getCurrentScreen() != FScreen.QUEST_BAZAAR) {
throw new IllegalArgumentException("FView$getViewBazaar\n"
+ "may only be called while the bazaar UI is showing.");
}
@@ -420,10 +421,10 @@ public enum FView {
/** */
private void cacheUIStates() {
- FView.this.bazaar = new ViewBazaarUI(Singletons.getModel().getQuest().getBazaar());
VMatchUI.SINGLETON_INSTANCE.instantiate();
VHomeUI.SINGLETON_INSTANCE.instantiate();
VDeckEditorUI.SINGLETON_INSTANCE.instantiate();
+ VBazaarUI.SINGLETON_INSTANCE.instantiate();
}
public void incrementSplashProgessBar() {