From 7faff76b3fa8a4b64cf9692b1022b8dc86bb837d Mon Sep 17 00:00:00 2001 From: Doublestrike Date: Sat, 14 Apr 2012 08:29:21 +0000 Subject: [PATCH] Boom - it's landed. Draggable layout for match UI. --- .gitattributes | 75 +- res/layouts/match_default.xml | 30 + src/main/java/forge/GameAction.java | 2 +- src/main/java/forge/GameActionUtil.java | 5 +- .../AbilityFactoryCounters.java | 3 +- .../cardfactory/CardFactoryArtifacts.java | 11 +- .../cardfactory/CardFactoryCreatures.java | 17 +- .../cardfactory/CardFactoryEnchantments.java | 3 +- .../card/cardfactory/CardFactoryLands.java | 17 +- .../cardfactory/CardFactorySorceries.java | 23 +- .../card/cardfactory/CardFactoryUtil.java | 25 +- .../java/forge/card/cost/CostDiscard.java | 4 +- src/main/java/forge/card/cost/CostExile.java | 3 +- src/main/java/forge/card/cost/CostMana.java | 8 +- .../java/forge/card/cost/CostPutCounter.java | 4 +- src/main/java/forge/card/cost/CostReturn.java | 3 +- src/main/java/forge/card/cost/CostReveal.java | 4 +- .../java/forge/card/cost/CostSacrifice.java | 3 +- .../java/forge/card/cost/CostTapType.java | 4 +- .../card/spellability/TargetSelection.java | 6 +- src/main/java/forge/control/FControl.java | 37 +- .../java/forge/control/KeyboardShortcuts.java | 15 +- src/main/java/forge/control/input/Input.java | 3 +- .../java/forge/control/input/InputAttack.java | 9 +- .../java/forge/control/input/InputBlock.java | 9 +- .../forge/control/input/InputCleanup.java | 5 +- .../forge/control/input/InputControl.java | 4 +- .../forge/control/input/InputMulligan.java | 12 +- .../control/input/InputPassPriority.java | 7 +- .../forge/control/input/InputPayManaCost.java | 3 +- .../input/InputPayManaCostAbility.java | 8 +- .../forge/control/match/ControlField.java | 604 ------------ .../java/forge/control/match/ControlHand.java | 281 ------ .../forge/control/match/ControlMessage.java | 136 --- .../forge/control/match/ControlTabber.java | 226 ----- .../forge/control/match/package-info.java | 3 - src/main/java/forge/game/GameNew.java | 50 +- src/main/java/forge/game/phase/Combat.java | 5 +- .../java/forge/game/phase/CombatUtil.java | 8 +- .../java/forge/game/phase/PhaseHandler.java | 10 +- src/main/java/forge/game/phase/PhaseUtil.java | 9 +- src/main/java/forge/game/phase/Untap.java | 7 +- src/main/java/forge/game/phase/Upkeep.java | 15 +- .../java/forge/game/player/HumanPlayer.java | 3 +- src/main/java/forge/game/player/Player.java | 3 +- .../java/forge/game/player/PlayerUtil.java | 11 +- src/main/java/forge/game/zone/MagicStack.java | 7 +- src/main/java/forge/gui/GuiDisplayUtil.java | 2 +- src/main/java/forge/gui/GuiInput.java | 6 +- .../java/forge/gui/GuiMultipleBlockers.java | 4 +- src/main/java/forge/gui/GuiUtils.java | 4 +- .../gui/{layout => framework}/DragCell.java | 72 +- .../gui/{layout => framework}/DragTab.java | 13 +- .../gui/{layout => framework}/EDocID.java | 47 +- .../gui/{layout => framework}/ICDoc.java | 11 +- .../gui/{layout => framework}/IDocIdList.java | 2 +- .../{layout => framework}/ILocalRepaint.java | 2 +- src/main/java/forge/gui/framework/IVDoc.java | 62 ++ .../forge/gui/framework/IVTopLevelUI.java | 23 + .../forge/gui/framework/SDisplayUtil.java | 87 ++ .../java/forge/gui/framework/SIOUtil.java | 173 ++++ .../forge/gui/framework/SLayoutConstants.java | 14 + .../{layout => framework}/SOverflowUtil.java | 18 +- .../SRearrangingUtil.java | 72 +- .../{layout => framework}/SResizingUtil.java | 50 +- src/main/java/forge/gui/home/EMenuGroup.java | 2 + src/main/java/forge/gui/home/EMenuItem.java | 4 +- src/main/java/forge/gui/home/ICSubmenu.java | 12 +- src/main/java/forge/gui/home/IVSubmenu.java | 7 +- .../ViewHomeUI.java => gui/home/VHomeUI.java} | 121 ++- .../gui/home/quest/CSubmenuChallenges.java | 6 +- .../forge/gui/home/quest/CSubmenuDuels.java | 6 +- .../gui/home/quest/CSubmenuQuestDecks.java | 4 +- src/main/java/forge/gui/layout/FViewNew.java | 181 ---- src/main/java/forge/gui/layout/IVDoc.java | 49 - src/main/java/forge/gui/layout/MDragUI.java | 13 - src/main/java/forge/gui/layout/SIOUtil.java | 114 --- .../match/CMatchUI.java} | 157 +-- .../match/ControlWinLose.java | 3 +- .../match/QuestWinLoseCardViewer.java | 2 +- .../match/QuestWinLoseHandler.java | 4 +- src/main/java/forge/gui/match/VMatchUI.java | 168 ++++ .../{view => gui}/match/ViewWinLose.java | 3 +- .../forge/gui/match/controllers/CAntes.java | 38 + .../forge/gui/match/controllers/CCombat.java | 40 + .../match/controllers/CDetail.java} | 46 +- .../forge/gui/match/controllers/CDev.java | 110 +++ .../match/controllers/CDock.java} | 80 +- .../forge/gui/match/controllers/CLog.java | 53 ++ .../forge/gui/match/controllers/CMessage.java | 114 +++ .../match/controllers/CPicture.java} | 57 +- .../forge/gui/match/controllers/CPlayers.java | 42 + .../forge/gui/match/controllers/CStack.java | 52 + .../forge/gui/match/nonsingleton/CField.java | 579 +++++++++++ .../forge/gui/match/nonsingleton/CHand.java | 288 ++++++ .../forge/gui/match/nonsingleton/VField.java | 258 ++--- .../forge/gui/match/nonsingleton/VHand.java | 107 ++- .../java/forge/gui/match/views/VAntes.java | 90 +- .../java/forge/gui/match/views/VCombat.java | 87 +- .../java/forge/gui/match/views/VDetail.java | 75 +- src/main/java/forge/gui/match/views/VDev.java | 351 +++++++ .../java/forge/gui/match/views/VDock.java | 172 +++- src/main/java/forge/gui/match/views/VLog.java | 95 +- .../java/forge/gui/match/views/VMessage.java | 162 +--- .../java/forge/gui/match/views/VPicture.java | 71 +- .../java/forge/gui/match/views/VPlayers.java | 153 ++- .../java/forge/gui/match/views/VStack.java | 257 ++++- src/main/java/forge/gui/toolbox/FPanel.java | 6 - .../forge/gui/toolbox/FVerticalTabPanel.java | 276 ------ src/main/java/forge/model/FModel.java | 15 +- src/main/java/forge/view/ButtonUtil.java | 6 +- src/main/java/forge/view/FView.java | 367 ++++--- src/main/java/forge/view/ViewMatchUI.java | 422 --------- .../forge/view/match/ViewBattlefield.java | 71 -- .../java/forge/view/match/ViewDetail.java | 69 -- src/main/java/forge/view/match/ViewDock.java | 220 ----- src/main/java/forge/view/match/ViewField.java | 632 ------------- src/main/java/forge/view/match/ViewHand.java | 83 -- .../java/forge/view/match/ViewMessage.java | 187 ---- .../java/forge/view/match/ViewPicture.java | 66 -- .../java/forge/view/match/ViewTabber.java | 895 ------------------ .../java/forge/view/match/package-info.java | 3 - 122 files changed, 4161 insertions(+), 5792 deletions(-) create mode 100644 res/layouts/match_default.xml delete mode 100644 src/main/java/forge/control/match/ControlField.java delete mode 100644 src/main/java/forge/control/match/ControlHand.java delete mode 100644 src/main/java/forge/control/match/ControlMessage.java delete mode 100644 src/main/java/forge/control/match/ControlTabber.java delete mode 100644 src/main/java/forge/control/match/package-info.java rename src/main/java/forge/gui/{layout => framework}/DragCell.java (83%) rename src/main/java/forge/gui/{layout => framework}/DragTab.java (84%) rename src/main/java/forge/gui/{layout => framework}/EDocID.java (53%) rename src/main/java/forge/gui/{layout => framework}/ICDoc.java (65%) rename src/main/java/forge/gui/{layout => framework}/IDocIdList.java (85%) rename src/main/java/forge/gui/{layout => framework}/ILocalRepaint.java (88%) create mode 100644 src/main/java/forge/gui/framework/IVDoc.java create mode 100644 src/main/java/forge/gui/framework/IVTopLevelUI.java create mode 100644 src/main/java/forge/gui/framework/SDisplayUtil.java create mode 100644 src/main/java/forge/gui/framework/SIOUtil.java create mode 100644 src/main/java/forge/gui/framework/SLayoutConstants.java rename src/main/java/forge/gui/{layout => framework}/SOverflowUtil.java (85%) rename src/main/java/forge/gui/{layout => framework}/SRearrangingUtil.java (84%) rename src/main/java/forge/gui/{layout => framework}/SResizingUtil.java (87%) rename src/main/java/forge/{view/ViewHomeUI.java => gui/home/VHomeUI.java} (89%) delete mode 100644 src/main/java/forge/gui/layout/FViewNew.java delete mode 100644 src/main/java/forge/gui/layout/IVDoc.java delete mode 100644 src/main/java/forge/gui/layout/MDragUI.java delete mode 100644 src/main/java/forge/gui/layout/SIOUtil.java rename src/main/java/forge/{control/ControlMatchUI.java => gui/match/CMatchUI.java} (56%) rename src/main/java/forge/{control => gui}/match/ControlWinLose.java (95%) rename src/main/java/forge/{view => gui}/match/QuestWinLoseCardViewer.java (96%) rename src/main/java/forge/{view => gui}/match/QuestWinLoseHandler.java (99%) create mode 100644 src/main/java/forge/gui/match/VMatchUI.java rename src/main/java/forge/{view => gui}/match/ViewWinLose.java (96%) create mode 100644 src/main/java/forge/gui/match/controllers/CAntes.java create mode 100644 src/main/java/forge/gui/match/controllers/CCombat.java rename src/main/java/forge/{control/match/ControlDetail.java => gui/match/controllers/CDetail.java} (59%) create mode 100644 src/main/java/forge/gui/match/controllers/CDev.java rename src/main/java/forge/{control/match/ControlDock.java => gui/match/controllers/CDock.java} (69%) create mode 100644 src/main/java/forge/gui/match/controllers/CLog.java create mode 100644 src/main/java/forge/gui/match/controllers/CMessage.java rename src/main/java/forge/{control/match/ControlPicture.java => gui/match/controllers/CPicture.java} (57%) create mode 100644 src/main/java/forge/gui/match/controllers/CPlayers.java create mode 100644 src/main/java/forge/gui/match/controllers/CStack.java create mode 100644 src/main/java/forge/gui/match/nonsingleton/CField.java create mode 100644 src/main/java/forge/gui/match/nonsingleton/CHand.java create mode 100644 src/main/java/forge/gui/match/views/VDev.java delete mode 100644 src/main/java/forge/gui/toolbox/FVerticalTabPanel.java delete mode 100644 src/main/java/forge/view/ViewMatchUI.java delete mode 100644 src/main/java/forge/view/match/ViewBattlefield.java delete mode 100644 src/main/java/forge/view/match/ViewDetail.java delete mode 100644 src/main/java/forge/view/match/ViewDock.java delete mode 100644 src/main/java/forge/view/match/ViewField.java delete mode 100644 src/main/java/forge/view/match/ViewHand.java delete mode 100644 src/main/java/forge/view/match/ViewMessage.java delete mode 100644 src/main/java/forge/view/match/ViewPicture.java delete mode 100644 src/main/java/forge/view/match/ViewTabber.java delete mode 100644 src/main/java/forge/view/match/package-info.java diff --git a/.gitattributes b/.gitattributes index ecb3cc170ca..f89c66ddff2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10603,6 +10603,7 @@ res/lang/en.properties svneol=native#text/plain res/lang/howTo/de.properties svneol=native#text/plain res/lang/howTo/en.properties svneol=native#text/plain res/lang/lang.properties svneol=native#text/plain +res/layouts/match_default.xml -text res/licenses/java-yield-license.txt svneol=native#text/plain res/licenses/log4j-license.txt svneol=native#text/plain res/licenses/multiline-label-license.txt svneol=native#text/plain @@ -11538,7 +11539,6 @@ src/main/java/forge/card/trigger/TriggerUntaps.java svneol=native#text/plain src/main/java/forge/card/trigger/ZCTrigger.java svneol=native#text/plain src/main/java/forge/card/trigger/package-info.java svneol=native#text/plain src/main/java/forge/control/ControlBazaarUI.java -text -src/main/java/forge/control/ControlMatchUI.java -text src/main/java/forge/control/FControl.java -text src/main/java/forge/control/KeyboardShortcuts.java -text src/main/java/forge/control/RestartUtil.java -text @@ -11556,15 +11556,6 @@ src/main/java/forge/control/input/InputPayManaCost.java svneol=native#text/plain src/main/java/forge/control/input/InputPayManaCostAbility.java svneol=native#text/plain src/main/java/forge/control/input/InputPayManaCostUtil.java svneol=native#text/plain src/main/java/forge/control/input/package-info.java svneol=native#text/plain -src/main/java/forge/control/match/ControlDetail.java -text -src/main/java/forge/control/match/ControlDock.java -text -src/main/java/forge/control/match/ControlField.java -text -src/main/java/forge/control/match/ControlHand.java -text -src/main/java/forge/control/match/ControlMessage.java -text -src/main/java/forge/control/match/ControlPicture.java -text -src/main/java/forge/control/match/ControlTabber.java -text -src/main/java/forge/control/match/ControlWinLose.java -text -src/main/java/forge/control/match/package-info.java -text src/main/java/forge/control/package-info.java -text src/main/java/forge/deck/CardCollections.java -text src/main/java/forge/deck/Deck.java svneol=native#text/plain @@ -11690,11 +11681,26 @@ src/main/java/forge/gui/download/GuiDownloadQuestImages.java -text src/main/java/forge/gui/download/GuiDownloadSetPicturesLQ.java svneol=native#text/plain src/main/java/forge/gui/download/GuiDownloader.java -text src/main/java/forge/gui/download/package-info.java -text +src/main/java/forge/gui/framework/DragCell.java -text +src/main/java/forge/gui/framework/DragTab.java -text +src/main/java/forge/gui/framework/EDocID.java -text +src/main/java/forge/gui/framework/ICDoc.java -text +src/main/java/forge/gui/framework/IDocIdList.java -text +src/main/java/forge/gui/framework/ILocalRepaint.java -text +src/main/java/forge/gui/framework/IVDoc.java -text +src/main/java/forge/gui/framework/IVTopLevelUI.java -text +src/main/java/forge/gui/framework/SDisplayUtil.java -text +src/main/java/forge/gui/framework/SIOUtil.java -text +src/main/java/forge/gui/framework/SLayoutConstants.java -text +src/main/java/forge/gui/framework/SOverflowUtil.java -text +src/main/java/forge/gui/framework/SRearrangingUtil.java -text +src/main/java/forge/gui/framework/SResizingUtil.java -text src/main/java/forge/gui/home/EMenuGroup.java -text src/main/java/forge/gui/home/EMenuItem.java -text src/main/java/forge/gui/home/ICSubmenu.java -text src/main/java/forge/gui/home/IVSubmenu.java -text src/main/java/forge/gui/home/StartButton.java -text +src/main/java/forge/gui/home/VHomeUI.java -text src/main/java/forge/gui/home/package-info.java svneol=native#text/plain src/main/java/forge/gui/home/quest/CSubmenuChallenges.java -text src/main/java/forge/gui/home/quest/CSubmenuDuels.java -text @@ -11730,24 +11736,30 @@ src/main/java/forge/gui/home/utilities/VSubmenuDeckEditor.java -text src/main/java/forge/gui/home/utilities/VSubmenuExit.java -text src/main/java/forge/gui/home/utilities/VSubmenuUtilities.java -text src/main/java/forge/gui/home/utilities/package-info.java svneol=native#text/plain -src/main/java/forge/gui/layout/DragCell.java -text -src/main/java/forge/gui/layout/DragTab.java -text -src/main/java/forge/gui/layout/EDocID.java -text -src/main/java/forge/gui/layout/FViewNew.java -text -src/main/java/forge/gui/layout/ICDoc.java -text -src/main/java/forge/gui/layout/IDocIdList.java -text -src/main/java/forge/gui/layout/ILocalRepaint.java -text -src/main/java/forge/gui/layout/IVDoc.java -text -src/main/java/forge/gui/layout/MDragUI.java -text -src/main/java/forge/gui/layout/SIOUtil.java -text -src/main/java/forge/gui/layout/SOverflowUtil.java -text -src/main/java/forge/gui/layout/SRearrangingUtil.java -text -src/main/java/forge/gui/layout/SResizingUtil.java -text +src/main/java/forge/gui/match/CMatchUI.java -text +src/main/java/forge/gui/match/ControlWinLose.java -text +src/main/java/forge/gui/match/QuestWinLoseCardViewer.java -text +src/main/java/forge/gui/match/QuestWinLoseHandler.java -text +src/main/java/forge/gui/match/VMatchUI.java -text +src/main/java/forge/gui/match/ViewWinLose.java -text +src/main/java/forge/gui/match/controllers/CAntes.java -text +src/main/java/forge/gui/match/controllers/CCombat.java -text +src/main/java/forge/gui/match/controllers/CDetail.java -text +src/main/java/forge/gui/match/controllers/CDev.java -text +src/main/java/forge/gui/match/controllers/CDock.java -text +src/main/java/forge/gui/match/controllers/CLog.java -text +src/main/java/forge/gui/match/controllers/CMessage.java -text +src/main/java/forge/gui/match/controllers/CPicture.java -text +src/main/java/forge/gui/match/controllers/CPlayers.java -text +src/main/java/forge/gui/match/controllers/CStack.java -text +src/main/java/forge/gui/match/nonsingleton/CField.java -text +src/main/java/forge/gui/match/nonsingleton/CHand.java -text src/main/java/forge/gui/match/nonsingleton/VField.java -text src/main/java/forge/gui/match/nonsingleton/VHand.java -text src/main/java/forge/gui/match/views/VAntes.java -text src/main/java/forge/gui/match/views/VCombat.java -text src/main/java/forge/gui/match/views/VDetail.java -text +src/main/java/forge/gui/match/views/VDev.java -text src/main/java/forge/gui/match/views/VDock.java -text src/main/java/forge/gui/match/views/VLog.java -text src/main/java/forge/gui/match/views/VMessage.java -text @@ -11769,7 +11781,6 @@ src/main/java/forge/gui/toolbox/FRadioButton.java -text src/main/java/forge/gui/toolbox/FScrollPane.java -text src/main/java/forge/gui/toolbox/FSkin.java -text src/main/java/forge/gui/toolbox/FTextArea.java -text -src/main/java/forge/gui/toolbox/FVerticalTabPanel.java -text src/main/java/forge/gui/toolbox/package-info.java svneol=native#text/plain src/main/java/forge/item/BoosterPack.java -text src/main/java/forge/item/CardDb.java -text @@ -11862,13 +11873,11 @@ src/main/java/forge/util/closures/Predicate.java -text src/main/java/forge/util/closures/PredicateString.java -text src/main/java/forge/util/package-info.java -text src/main/java/forge/view/ButtonUtil.java svneol=native#text/plain -src/main/java/forge/view/FView.java svneol=native#text/plain +src/main/java/forge/view/FView.java -text src/main/java/forge/view/Main.java -text src/main/java/forge/view/SplashFrame.java -text src/main/java/forge/view/ViewBazaarUI.java -text src/main/java/forge/view/ViewEditorUI.java -text -src/main/java/forge/view/ViewHomeUI.java -text -src/main/java/forge/view/ViewMatchUI.java -text src/main/java/forge/view/arcane/CardArea.java svneol=native#text/plain src/main/java/forge/view/arcane/CardPanel.java svneol=native#text/plain src/main/java/forge/view/arcane/CardPanelContainer.java svneol=native#text/plain @@ -11886,18 +11895,6 @@ src/main/java/forge/view/arcane/util/package-info.java svneol=native#text/plain src/main/java/forge/view/bazaar/ViewItem.java -text src/main/java/forge/view/bazaar/ViewStall.java svneol=native#text/plain src/main/java/forge/view/bazaar/package-info.java svneol=native#text/plain -src/main/java/forge/view/match/QuestWinLoseCardViewer.java -text -src/main/java/forge/view/match/QuestWinLoseHandler.java -text -src/main/java/forge/view/match/ViewBattlefield.java -text -src/main/java/forge/view/match/ViewDetail.java -text -src/main/java/forge/view/match/ViewDock.java -text -src/main/java/forge/view/match/ViewField.java -text -src/main/java/forge/view/match/ViewHand.java -text -src/main/java/forge/view/match/ViewMessage.java -text -src/main/java/forge/view/match/ViewPicture.java -text -src/main/java/forge/view/match/ViewTabber.java -text -src/main/java/forge/view/match/ViewWinLose.java -text -src/main/java/forge/view/match/package-info.java svneol=native#text/plain src/main/java/forge/view/package-info.java svneol=native#text/plain src/main/java/net/slightlymagic/braids/BaseProgressMonitor.java svneol=native#text/plain src/main/java/net/slightlymagic/braids/BraidsProgressMonitor.java svneol=native#text/plain diff --git a/res/layouts/match_default.xml b/res/layouts/match_default.xml new file mode 100644 index 00000000000..d35f7bbd47d --- /dev/null +++ b/res/layouts/match_default.xml @@ -0,0 +1,30 @@ + + + + REPORT_STACK + REPORT_COMBAT + REPORT_LOG + REPORT_PLAYERS + + + REPORT_MESSAGE + DEV_MODE + CARD_ANTES + BUTTON_DOCK + + + FIELD_0 + + + HAND_1 + + + CARD_DETAIL + + + FIELD_1 + + + CARD_PICTURE + + \ No newline at end of file diff --git a/src/main/java/forge/GameAction.java b/src/main/java/forge/GameAction.java index a7daf035b03..b804280a92a 100644 --- a/src/main/java/forge/GameAction.java +++ b/src/main/java/forge/GameAction.java @@ -55,7 +55,7 @@ import forge.game.zone.PlayerZone; import forge.game.zone.PlayerZoneComesIntoPlay; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; -import forge.view.match.ViewWinLose; +import forge.gui.match.ViewWinLose; /** * Methods for common actions performed during a game. diff --git a/src/main/java/forge/GameActionUtil.java b/src/main/java/forge/GameActionUtil.java index 522308bf5b3..def706ef8f1 100644 --- a/src/main/java/forge/GameActionUtil.java +++ b/src/main/java/forge/GameActionUtil.java @@ -36,6 +36,7 @@ import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; +import forge.gui.match.CMatchUI; import forge.util.MyRandom; /** @@ -417,7 +418,7 @@ public final class GameActionUtil { * @return a boolean. */ public static boolean showYesNoDialog(final Card c, String question, final boolean defaultNo) { - Singletons.getControl().getControlMatch().setCard(c); + CMatchUI.SINGLETON_INSTANCE.setCard(c); final StringBuilder title = new StringBuilder(); title.append(c.getName()).append(" - Ability"); @@ -503,7 +504,7 @@ public final class GameActionUtil { * @return a boolean. */ private static boolean showLandfallDialog(final Card c) { - Singletons.getControl().getControlMatch().setCard(c); + CMatchUI.SINGLETON_INSTANCE.setCard(c); final String[] choices = { "Yes", "No" }; Object q = null; diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryCounters.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryCounters.java index ae8e7ea3519..39564261949 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryCounters.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryCounters.java @@ -46,6 +46,7 @@ import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; +import forge.gui.match.CMatchUI; import forge.util.MyRandom; import forge.view.ButtonUtil; @@ -1428,7 +1429,7 @@ public class AbilityFactoryCounters { @Override public void showMessage() { ButtonUtil.enableOnlyCancel(); - Singletons.getControl().getControlMatch().showMessage("Proliferate: Choose permanents and/or players"); + CMatchUI.SINGLETON_INSTANCE.showMessage("Proliferate: Choose permanents and/or players"); } @Override diff --git a/src/main/java/forge/card/cardfactory/CardFactoryArtifacts.java b/src/main/java/forge/card/cardfactory/CardFactoryArtifacts.java index 93e0723ba91..c3c1d76dabe 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryArtifacts.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryArtifacts.java @@ -28,6 +28,7 @@ import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; /** @@ -145,7 +146,7 @@ class CardFactoryArtifacts { @Override public void showMessage() { - Singletons.getControl().getControlMatch().showMessage("Discard a land card (or select Mox Diamond to sacrifice it)"); + CMatchUI.SINGLETON_INSTANCE.showMessage("Discard a land card (or select Mox Diamond to sacrifice it)"); ButtonUtil.enableOnlyCancel(); } @@ -493,7 +494,7 @@ class CardFactoryArtifacts { final StringBuilder sb = new StringBuilder(); sb.append(card.getName()).append(" - Exile cards from hand. Currently, "); sb.append(this.exiled.size()).append(" selected. (Press OK when done.)"); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); ButtonUtil.enableOnlyOK(); } @@ -528,7 +529,7 @@ class CardFactoryArtifacts { final StringBuilder sb = new StringBuilder(); sb.append(card.getName()).append(" - Returning cards to top of library."); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); // Then look at the exiled cards and put them on // top of your library in any order. @@ -692,7 +693,7 @@ class CardFactoryArtifacts { if (AllZone.getHumanPlayer().getZone(ZoneType.Hand).size() == 0) { this.stop(); } - Singletons.getControl().getControlMatch().showMessage(prompt); + CMatchUI.SINGLETON_INSTANCE.showMessage(prompt); ButtonUtil.disableAll(); } @@ -809,7 +810,7 @@ class CardFactoryArtifacts { public void showMessage() { final StringBuilder sb = new StringBuilder(); sb.append(cardName).append(" - Select an artifact on the battlefield"); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); ButtonUtil.enableOnlyCancel(); } diff --git a/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java b/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java index 9cbadca2b87..73e3cbd0f27 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java @@ -54,6 +54,7 @@ import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; +import forge.gui.match.CMatchUI; import forge.util.MyRandom; import forge.view.ButtonUtil; @@ -361,7 +362,7 @@ public class CardFactoryCreatures { @Override public void showMessage() { ButtonUtil.disableAll(); - Singletons.getControl().getControlMatch().showMessage("Exile a nonland card from your hand."); + CMatchUI.SINGLETON_INSTANCE.showMessage("Exile a nonland card from your hand."); } @Override @@ -413,9 +414,9 @@ public class CardFactoryCreatures { @Override public void showMessage() { if (index[0] == 0) { - Singletons.getControl().getControlMatch().showMessage("Select target land you control."); + CMatchUI.SINGLETON_INSTANCE.showMessage("Select target land you control."); } else { - Singletons.getControl().getControlMatch().showMessage("Select target land opponent controls."); + CMatchUI.SINGLETON_INSTANCE.showMessage("Select target land opponent controls."); } ButtonUtil.enableOnlyCancel(); @@ -1039,7 +1040,7 @@ public class CardFactoryCreatures { @Override public void showMessage() { - Singletons.getControl().getControlMatch().showMessage(msg); + CMatchUI.SINGLETON_INSTANCE.showMessage(msg); ButtonUtil.enableOnlyOK(); } @@ -1476,7 +1477,7 @@ public class CardFactoryCreatures { final StringBuilder sb = new StringBuilder(); sb.append("Select up to 5 target permanents. Selected ("); sb.append(targetPerms.size()).append(") so far. Click OK when done."); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); ButtonUtil.enableOnlyOK(); } @@ -1518,7 +1519,7 @@ public class CardFactoryCreatures { public void showMessage() { final StringBuilder sb = new StringBuilder(); sb.append(card.getName()).append(" - Select target player"); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); ButtonUtil.enableOnlyCancel(); } @@ -1574,7 +1575,7 @@ public class CardFactoryCreatures { toDisplay += "Currently, (" + toSac.size() + ") selected with a total power of: " + getTotalPower(); toDisplay += " Click OK when Done."; - Singletons.getControl().getControlMatch().showMessage(toDisplay); + CMatchUI.SINGLETON_INSTANCE.showMessage(toDisplay); ButtonUtil.enableAll(); } @@ -1788,7 +1789,7 @@ public class CardFactoryCreatures { message += "or artifact "; } message += "on the battlefield"; - Singletons.getControl().getControlMatch().showMessage(cardName + " - " + message); + CMatchUI.SINGLETON_INSTANCE.showMessage(cardName + " - " + message); ButtonUtil.enableOnlyCancel(); } diff --git a/src/main/java/forge/card/cardfactory/CardFactoryEnchantments.java b/src/main/java/forge/card/cardfactory/CardFactoryEnchantments.java index 08e56b4b471..47a7230c9bd 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryEnchantments.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryEnchantments.java @@ -19,6 +19,7 @@ import forge.game.GameLossReason; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; /** @@ -294,7 +295,7 @@ class CardFactoryEnchantments { public void showMessage() { final StringBuilder sb = new StringBuilder(); sb.append(cardName).append(" - Select an artifact on the battlefield"); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); ButtonUtil.enableOnlyCancel(); } diff --git a/src/main/java/forge/card/cardfactory/CardFactoryLands.java b/src/main/java/forge/card/cardfactory/CardFactoryLands.java index ff1a3f4525d..b0659aacf48 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryLands.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryLands.java @@ -39,6 +39,7 @@ import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; +import forge.gui.match.CMatchUI; import forge.util.MyRandom; import forge.view.ButtonUtil; @@ -206,7 +207,7 @@ class CardFactoryLands { public void showMessage() { final StringBuilder sb = new StringBuilder(); sb.append(cardName).append(" - Select an untapped land to sacrifice"); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); ButtonUtil.enableOnlyCancel(); } @@ -224,7 +225,7 @@ class CardFactoryLands { paid[0]++; final StringBuilder sb = new StringBuilder(); sb.append(cardName).append(" - Select an untapped land to sacrifice"); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); } else { this.stop(); } @@ -295,7 +296,7 @@ class CardFactoryLands { @Override public void showMessage() { - Singletons.getControl().getControlMatch().showMessage( + CMatchUI.SINGLETON_INSTANCE.showMessage( cardName + " - Select one " + type[0] + " to sacrifice"); ButtonUtil.enableOnlyCancel(); } @@ -388,7 +389,7 @@ class CardFactoryLands { @Override public void showMessage() { - Singletons.getControl().getControlMatch().showMessage( + CMatchUI.SINGLETON_INSTANCE.showMessage( "Scorched Ruins - Select an untapped land to sacrifice"); ButtonUtil.enableOnlyCancel(); } @@ -405,7 +406,7 @@ class CardFactoryLands { Singletons.getModel().getGameAction().sacrifice(c); if (paid[0] < 1) { paid[0]++; - Singletons.getControl().getControlMatch().showMessage( + CMatchUI.SINGLETON_INSTANCE.showMessage( "Scorched Ruins - Select an untapped land to sacrifice"); } else { this.stop(); @@ -483,7 +484,7 @@ class CardFactoryLands { public void showMessage() { final StringBuilder sb = new StringBuilder(); sb.append(card.getName()).append(" - Reveal a card."); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); ButtonUtil.enableOnlyCancel(); } @@ -669,7 +670,7 @@ class CardFactoryLands { final StringBuilder sb = new StringBuilder(); sb.append(cardName); sb.append(" - Select one non-Lair land to return to your hand"); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); ButtonUtil.enableOnlyCancel(); } @@ -738,7 +739,7 @@ class CardFactoryLands { final StringBuilder sb = new StringBuilder(); sb.append(card).append(" - Select one untapped "); sb.append(type[0]).append(" to return"); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); ButtonUtil.enableOnlyCancel(); } diff --git a/src/main/java/forge/card/cardfactory/CardFactorySorceries.java b/src/main/java/forge/card/cardfactory/CardFactorySorceries.java index 55ed21a49a0..9eb72bbb201 100644 --- a/src/main/java/forge/card/cardfactory/CardFactorySorceries.java +++ b/src/main/java/forge/card/cardfactory/CardFactorySorceries.java @@ -50,6 +50,7 @@ import forge.game.player.PlayerUtil; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; /** @@ -116,9 +117,9 @@ public class CardFactorySorceries { @Override public void showMessage() { if (index[0] == 0) { - Singletons.getControl().getControlMatch().showMessage("Select target land you control."); + CMatchUI.SINGLETON_INSTANCE.showMessage("Select target land you control."); } else { - Singletons.getControl().getControlMatch().showMessage("Select target land opponent controls."); + CMatchUI.SINGLETON_INSTANCE.showMessage("Select target land opponent controls."); } ButtonUtil.enableOnlyCancel(); @@ -608,7 +609,7 @@ public class CardFactorySorceries { final StringBuilder sb = new StringBuilder(); sb.append("Select target ").append(humanBasic.get(this.count)); sb.append(" land to not sacrifice"); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); ButtonUtil.enableOnlyCancel(); } } @@ -1068,7 +1069,7 @@ public class CardFactorySorceries { final StringBuilder sb = new StringBuilder(); sb.append("Select target creatures and/or players. Currently, "); sb.append(this.getNumTargets()).append(" targets. Click OK when done."); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); } private int getNumTargets() { @@ -1102,11 +1103,11 @@ public class CardFactorySorceries { @Override public void selectCard(final Card c, final PlayerZone zone) { if (!c.canBeTargetedBy(spell)) { - Singletons.getControl().getControlMatch().showMessage("Cannot target this card."); + CMatchUI.SINGLETON_INSTANCE.showMessage("Cannot target this card."); return; // cannot target } if (targets.contains(c)) { - Singletons.getControl().getControlMatch().showMessage("You have already selected this target."); + CMatchUI.SINGLETON_INSTANCE.showMessage("You have already selected this target."); return; // cannot target the same creature twice. } @@ -1119,11 +1120,11 @@ public class CardFactorySorceries { @Override public void selectPlayer(final Player player) { if (!player.canBeTargetedBy(spell)) { - Singletons.getControl().getControlMatch().showMessage("Cannot target this player."); + CMatchUI.SINGLETON_INSTANCE.showMessage("Cannot target this player."); return; // cannot target } if (targetPlayers.contains(player)) { - Singletons.getControl().getControlMatch().showMessage("You have already selected this player."); + CMatchUI.SINGLETON_INSTANCE.showMessage("You have already selected this player."); return; // cannot target the same player twice. } targetPlayers.add(player); @@ -1606,7 +1607,7 @@ public class CardFactorySorceries { final StringBuilder sb = new StringBuilder(); sb.append(cardName).append(" - Select a target creature to gain Fear (up to "); sb.append(this.stop - this.count).append(" more)"); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); ButtonUtil.enableAll(); } @@ -1648,7 +1649,7 @@ public class CardFactorySorceries { public void showMessage() { final StringBuilder sb = new StringBuilder(); sb.append(cardName).append(" - Select target creature to get -X/-X"); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); ButtonUtil.enableOnlyCancel(); } @@ -1729,7 +1730,7 @@ public class CardFactorySorceries { public void showMessage() { final StringBuilder sb = new StringBuilder(); sb.append(cardName).append(" - Select target player to lose life"); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); ButtonUtil.enableOnlyCancel(); } diff --git a/src/main/java/forge/card/cardfactory/CardFactoryUtil.java b/src/main/java/forge/card/cardfactory/CardFactoryUtil.java index 61f47efa981..9bd972371ff 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryUtil.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryUtil.java @@ -67,6 +67,7 @@ import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; +import forge.gui.match.CMatchUI; import forge.util.MyRandom; import forge.view.ButtonUtil; @@ -808,7 +809,7 @@ public class CardFactoryUtil { if (spell.getTargetCard() != null) { this.stop(); } - Singletons.getControl().getControlMatch().showMessage("Select target Spell: "); + CMatchUI.SINGLETON_INSTANCE.showMessage("Select target Spell: "); final Card choice = GuiUtils.chooseOneOrNone("Choose a Spell", choices.toArray()); if (choice != null) { spell.setTargetCard(choice); @@ -856,7 +857,7 @@ public class CardFactoryUtil { @Override public void showMessage() { - Singletons.getControl().getControlMatch().showMessage(message); + CMatchUI.SINGLETON_INSTANCE.showMessage(message); ButtonUtil.disableAll(); } @@ -1752,7 +1753,7 @@ public class CardFactoryUtil { @Override public void showMessage() { - Singletons.getControl().getControlMatch().showMessage(message); + CMatchUI.SINGLETON_INSTANCE.showMessage(message); ButtonUtil.enableOnlyCancel(); } @@ -1764,7 +1765,7 @@ public class CardFactoryUtil { @Override public void selectCard(final Card card, final PlayerZone zone) { if (targeted && !card.canBeTargetedBy(spell)) { - Singletons.getControl().getControlMatch() + CMatchUI.SINGLETON_INSTANCE .showMessage("Cannot target this card (Shroud? Protection?)."); } else if (choices.contains(card)) { spell.setTargetCard(card); @@ -1810,7 +1811,7 @@ public class CardFactoryUtil { @Override public void showMessage() { - Singletons.getControl().getControlMatch().showMessage(message); + CMatchUI.SINGLETON_INSTANCE.showMessage(message); ButtonUtil.enableOnlyCancel(); } @@ -1890,7 +1891,7 @@ public class CardFactoryUtil { * (AllZone.getHumanPlayer().getZone(Zone.Hand).size() == 0) { this.stop(); * } * - * Singletons.getControl().getControlMatch().showMessage( + * CMatchUI.SINGLETON_INSTANCE.showMessage( * "Select a card to discard"); ButtonUtil.disableAll(); } * * @Override public void selectCard(final Card card, final PlayerZone zone) @@ -1901,7 +1902,7 @@ public class CardFactoryUtil { * (AllZone.getHumanPlayer().getZone(Zone.Hand).size() == 0)) { this.done(); * } else { this.showMessage(); } } } * - * void done() { Singletons.getControl().getControlMatch().showMessage( + * void done() { CMatchUI.SINGLETON_INSTANCE.showMessage( * "Returning cards to hand."); * Singletons.getModel().getGameAction().exile(recall); final CardList grave * = AllZone.getHumanPlayer().getCardsIn(Zone.Graveyard); for (int i = 1; i @@ -1934,7 +1935,7 @@ public class CardFactoryUtil { public void showMessage() { final StringBuilder sb = new StringBuilder(); sb.append("Select target wolf to damage for ").append(spell.getSourceCard()); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); ButtonUtil.enableOnlyCancel(); } @@ -1976,7 +1977,7 @@ public class CardFactoryUtil { @Override public void showMessage() { - Singletons.getControl().getControlMatch().showMessage("Select target artifact creature"); + CMatchUI.SINGLETON_INSTANCE.showMessage("Select target artifact creature"); ButtonUtil.enableOnlyCancel(); } @@ -3549,7 +3550,7 @@ public class CardFactoryUtil { public void showMessage() { final StringBuilder sb = new StringBuilder(); sb.append("Select a ").append(type).append(" to untap"); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); ButtonUtil.enableOnlyCancel(); } @@ -4699,7 +4700,7 @@ public class CardFactoryUtil { @Override public void showMessage() { - Singletons.getControl().getControlMatch().showMessage("Choose target creature to haunt."); + CMatchUI.SINGLETON_INSTANCE.showMessage("Choose target creature to haunt."); ButtonUtil.disableAll(); } @@ -4713,7 +4714,7 @@ public class CardFactoryUtil { AllZone.getStack().add(haunterDiesWork); this.stop(); } else { - Singletons.getControl().getControlMatch() + CMatchUI.SINGLETON_INSTANCE .showMessage("Cannot target this card (Shroud? Protection?)."); } } diff --git a/src/main/java/forge/card/cost/CostDiscard.java b/src/main/java/forge/card/cost/CostDiscard.java index 85466301ba1..9307e146c99 100644 --- a/src/main/java/forge/card/cost/CostDiscard.java +++ b/src/main/java/forge/card/cost/CostDiscard.java @@ -21,7 +21,6 @@ import forge.AllZone; import forge.Card; import forge.CardList; import forge.CardListUtil; -import forge.Singletons; import forge.card.abilityfactory.AbilityFactory; import forge.card.spellability.SpellAbility; import forge.control.input.Input; @@ -29,6 +28,7 @@ import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; /** @@ -325,7 +325,7 @@ public class CostDiscard extends CostPartWithList { sb.append(nNeeded - this.nDiscard); sb.append(" remaining."); } - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); ButtonUtil.enableOnlyCancel(); } diff --git a/src/main/java/forge/card/cost/CostExile.java b/src/main/java/forge/card/cost/CostExile.java index abef646a66a..b6dc6796c11 100644 --- a/src/main/java/forge/card/cost/CostExile.java +++ b/src/main/java/forge/card/cost/CostExile.java @@ -34,6 +34,7 @@ import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; /** @@ -408,7 +409,7 @@ public class CostExile extends CostPartWithList { this.typeList = sa.getActivatingPlayer().getCardsIn(part.getFrom()); this.typeList = this.typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(), sa.getSourceCard()); - Singletons.getControl().getControlMatch().showMessage(msg.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(msg.toString()); ButtonUtil.enableOnlyCancel(); } diff --git a/src/main/java/forge/card/cost/CostMana.java b/src/main/java/forge/card/cost/CostMana.java index 2f19a3f6c36..360e1a8f1f0 100644 --- a/src/main/java/forge/card/cost/CostMana.java +++ b/src/main/java/forge/card/cost/CostMana.java @@ -21,7 +21,6 @@ import com.google.common.base.Strings; import forge.AllZone; import forge.Card; -import forge.Singletons; import forge.card.abilityfactory.AbilityFactory; import forge.card.mana.ManaCost; import forge.card.spellability.SpellAbility; @@ -34,6 +33,7 @@ import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; /** @@ -277,7 +277,7 @@ public class CostMana extends CostPart { ButtonUtil.enableOnlyCancel(); } - Singletons.getControl().getControlMatch().showMessage( + CMatchUI.SINGLETON_INSTANCE.showMessage( "Pay X Mana Cost for " + sa.getSourceCard().getName() + "\n" + this.xPaid + " Paid so far."); } @@ -474,7 +474,7 @@ public class CostMana extends CostPart { public void showMessage() { ButtonUtil.enableOnlyCancel(); final String displayMana = this.mana.toString().replace("X", "").trim(); - Singletons.getControl().getControlMatch().showMessage("Pay Mana Cost: " + displayMana); + CMatchUI.SINGLETON_INSTANCE.showMessage("Pay Mana Cost: " + displayMana); final StringBuilder msg = new StringBuilder("Pay Mana Cost: " + displayMana); if (this.phyLifeToLose > 0) { @@ -487,7 +487,7 @@ public class CostMana extends CostPart { msg.append("\n(Click on your life total to pay life for phyrexian mana.)"); } - Singletons.getControl().getControlMatch().showMessage(msg.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(msg.toString()); if (this.mana.isPaid()) { this.done(); } diff --git a/src/main/java/forge/card/cost/CostPutCounter.java b/src/main/java/forge/card/cost/CostPutCounter.java index 610b61c17f0..e4cbfe6dd80 100644 --- a/src/main/java/forge/card/cost/CostPutCounter.java +++ b/src/main/java/forge/card/cost/CostPutCounter.java @@ -20,7 +20,6 @@ package forge.card.cost; import forge.Card; import forge.CardList; import forge.Counters; -import forge.Singletons; import forge.card.abilityfactory.AbilityFactory; import forge.card.cardfactory.CardFactoryUtil; import forge.card.spellability.SpellAbility; @@ -28,6 +27,7 @@ import forge.control.input.Input; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; /** @@ -271,7 +271,7 @@ public class CostPutCounter extends CostPartWithList { this.typeList = sa.getActivatingPlayer().getCardsIn(ZoneType.Battlefield); this.typeList = this.typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(), sa.getSourceCard()); - Singletons.getControl().getControlMatch().showMessage(msg.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(msg.toString()); ButtonUtil.enableOnlyCancel(); } diff --git a/src/main/java/forge/card/cost/CostReturn.java b/src/main/java/forge/card/cost/CostReturn.java index 9d5032f8d01..76a07f48c77 100644 --- a/src/main/java/forge/card/cost/CostReturn.java +++ b/src/main/java/forge/card/cost/CostReturn.java @@ -30,6 +30,7 @@ import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; /** @@ -231,7 +232,7 @@ public class CostReturn extends CostPartWithList { this.typeList = sa.getActivatingPlayer().getCardsIn(ZoneType.Battlefield); this.typeList = this.typeList.getValidCards(type.split(";"), sa.getActivatingPlayer(), sa.getSourceCard()); - Singletons.getControl().getControlMatch().showMessage(msg.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(msg.toString()); ButtonUtil.enableOnlyCancel(); } diff --git a/src/main/java/forge/card/cost/CostReveal.java b/src/main/java/forge/card/cost/CostReveal.java index cd6a079251c..2c490e190a8 100644 --- a/src/main/java/forge/card/cost/CostReveal.java +++ b/src/main/java/forge/card/cost/CostReveal.java @@ -20,7 +20,6 @@ package forge.card.cost; import forge.AllZone; import forge.Card; import forge.CardList; -import forge.Singletons; import forge.card.abilityfactory.AbilityFactory; import forge.card.spellability.SpellAbility; import forge.control.input.Input; @@ -29,6 +28,7 @@ import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; /** @@ -256,7 +256,7 @@ public class CostReveal extends CostPartWithList { sb.append(nNeeded - this.nReveal); sb.append(" remaining."); } - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); ButtonUtil.enableOnlyCancel(); } diff --git a/src/main/java/forge/card/cost/CostSacrifice.java b/src/main/java/forge/card/cost/CostSacrifice.java index c6112eedfbf..e912892e484 100644 --- a/src/main/java/forge/card/cost/CostSacrifice.java +++ b/src/main/java/forge/card/cost/CostSacrifice.java @@ -30,6 +30,7 @@ import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; /** @@ -273,7 +274,7 @@ public class CostSacrifice extends CostPartWithList { msg.append("s"); } - Singletons.getControl().getControlMatch().showMessage(msg.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(msg.toString()); ButtonUtil.enableOnlyCancel(); } diff --git a/src/main/java/forge/card/cost/CostTapType.java b/src/main/java/forge/card/cost/CostTapType.java index b25cb7f89fc..241041a9723 100644 --- a/src/main/java/forge/card/cost/CostTapType.java +++ b/src/main/java/forge/card/cost/CostTapType.java @@ -20,7 +20,6 @@ package forge.card.cost; import forge.Card; import forge.CardList; import forge.CardListFilter; -import forge.Singletons; import forge.card.abilityfactory.AbilityFactory; import forge.card.spellability.SpellAbility; import forge.control.input.Input; @@ -28,6 +27,7 @@ import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; /** @@ -242,7 +242,7 @@ public class CostTapType extends CostPartWithList { } final int left = nCards - this.nTapped; - Singletons.getControl().getControlMatch() + CMatchUI.SINGLETON_INSTANCE .showMessage("Select a " + tapType.getDescription() + " to tap (" + left + " left)"); ButtonUtil.enableOnlyCancel(); } diff --git a/src/main/java/forge/card/spellability/TargetSelection.java b/src/main/java/forge/card/spellability/TargetSelection.java index b4a81fc7870..030c8842c25 100644 --- a/src/main/java/forge/card/spellability/TargetSelection.java +++ b/src/main/java/forge/card/spellability/TargetSelection.java @@ -25,13 +25,13 @@ import forge.AllZone; import forge.AllZoneUtil; import forge.Card; import forge.CardList; -import forge.Singletons; import forge.card.abilityfactory.AbilityFactory; import forge.control.input.Input; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; /** @@ -344,7 +344,7 @@ public class TargetSelection { sb.append("\n"); sb.append(tgt.getVTSelection()); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); // If reached Minimum targets, enable OK button if (!tgt.isMinTargetsChosen(sa.getSourceCard(), sa)) { @@ -376,7 +376,7 @@ public class TargetSelection { // leave this in temporarily, there some seriously wrong things // going on here if (targeted && !card.canBeTargetedBy(sa)) { - Singletons.getControl().getControlMatch().showMessage("Cannot target this card (Shroud? Protection? Restrictions?)."); + CMatchUI.SINGLETON_INSTANCE.showMessage("Cannot target this card (Shroud? Protection? Restrictions?)."); } else if (choices.contains(card)) { tgt.addTarget(card); this.done(); diff --git a/src/main/java/forge/control/FControl.java b/src/main/java/forge/control/FControl.java index 0fc3050d9e5..7a7bad40025 100644 --- a/src/main/java/forge/control/FControl.java +++ b/src/main/java/forge/control/FControl.java @@ -31,10 +31,13 @@ import javax.swing.WindowConstants; import forge.AllZone; import forge.Singletons; import forge.control.KeyboardShortcuts.Shortcut; +import forge.gui.home.VHomeUI; import forge.gui.home.quest.SubmenuQuestUtil; +import forge.gui.match.VMatchUI; +import forge.gui.match.controllers.CDock; import forge.gui.toolbox.CardFaceSymbols; import forge.gui.toolbox.FSkin; -import forge.view.ViewHomeUI; +import forge.view.FView; /** *

@@ -77,7 +80,7 @@ public enum FControl { @Override public void windowClosing(final WindowEvent e) { Singletons.getView().getFrame().setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - Singletons.getControl().getControlMatch().getDockControl().concede(); + CDock.SINGLETON_INSTANCE.concede(); } }; @@ -94,7 +97,7 @@ public enum FControl { // Default action on window close this.waDefault = new WindowAdapter() { @Override - public void windowClosing(WindowEvent e) { + public void windowClosing(final WindowEvent e) { Singletons.getView().getFrame().setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } }; @@ -112,7 +115,7 @@ public enum FControl { CardFaceSymbols.loadImages(); this.shortcuts = KeyboardShortcuts.attachKeyboardShortcuts(); - this.display = Singletons.getView().getLayeredContentPane(); + this.display = FView.SINGLETON_INSTANCE.getLpnDocument(); //Singletons.getView().initialize(); @@ -146,13 +149,14 @@ public enum FControl { // Fire up new state switch (i0) { case HOME_SCREEN: - display.add(ViewHomeUI.SINGLETON_INSTANCE.getPanel(), JLayeredPane.DEFAULT_LAYER); - sizeChildren(); + VHomeUI.SINGLETON_INSTANCE.populate(); + FView.SINGLETON_INSTANCE.getPnlInsets().setVisible(false); + //sizeChildren(); break; case MATCH_SCREEN: - display.add(Singletons.getView().getViewMatch(), JLayeredPane.DEFAULT_LAYER); - sizeChildren(); + VMatchUI.SINGLETON_INSTANCE.populate(); + FView.SINGLETON_INSTANCE.getPnlInsets().setVisible(true); Singletons.getView().getFrame().addWindowListener(waConcede); break; @@ -170,17 +174,6 @@ public enum FControl { } } - /** Gets the match controller. - * @return {@link forge.control.match.ControlMatchUI} - */ - public ControlMatchUI getControlMatch() { - if (getState() != FControl.MATCH_SCREEN) { - throw new IllegalArgumentException("FControl$getControlMatch\n" - + "may only be called while the match UI is showing."); - } - return Singletons.getView().getViewMatch().getControl(); - } - /** * Returns the int reflecting the current state of the top level frame * (see field definitions and class methods for details). @@ -198,10 +191,10 @@ public enum FControl { /** Remove all children from a specified layer. */ private void clearChildren(final int layer0) { - final Component[] children = Singletons.getView() - .getLayeredContentPane().getComponentsInLayer(layer0); + final Component[] children = FView.SINGLETON_INSTANCE.getLpnDocument() + .getComponentsInLayer(layer0); - for (Component c : children) { + for (final Component c : children) { display.remove(c); } } diff --git a/src/main/java/forge/control/KeyboardShortcuts.java b/src/main/java/forge/control/KeyboardShortcuts.java index 5aad94eddae..3402036cd8b 100644 --- a/src/main/java/forge/control/KeyboardShortcuts.java +++ b/src/main/java/forge/control/KeyboardShortcuts.java @@ -16,7 +16,10 @@ import javax.swing.KeyStroke; import org.apache.commons.lang3.StringUtils; import forge.Singletons; +import forge.gui.framework.EDocID; +import forge.gui.framework.SDisplayUtil; import forge.gui.home.settings.VSubmenuPreferences.KeyboardShortcutField; +import forge.gui.match.controllers.CDock; import forge.properties.ForgePreferences.FPref; /** @@ -49,7 +52,7 @@ public class KeyboardShortcuts { @Override public void actionPerformed(final ActionEvent e) { if (Singletons.getControl().getState() != 1) { return; } - Singletons.getControl().getControlMatch().getTabberControl().showPnlStack(); + SDisplayUtil.showTab(EDocID.REPORT_STACK.getDoc()); } }; @@ -58,7 +61,7 @@ public class KeyboardShortcuts { @Override public void actionPerformed(final ActionEvent e) { if (Singletons.getControl().getState() != 1) { return; } - Singletons.getControl().getControlMatch().getTabberControl().showPnlCombat(); + SDisplayUtil.showTab(EDocID.REPORT_COMBAT.getDoc()); } }; @@ -67,7 +70,7 @@ public class KeyboardShortcuts { @Override public void actionPerformed(final ActionEvent e) { if (Singletons.getControl().getState() != 1) { return; } - Singletons.getControl().getControlMatch().getTabberControl().showPnlGameLog(); + SDisplayUtil.showTab(EDocID.REPORT_LOG.getDoc()); } }; @@ -76,7 +79,7 @@ public class KeyboardShortcuts { @Override public void actionPerformed(final ActionEvent e) { if (Singletons.getControl().getState() != 1) { return; } - Singletons.getControl().getControlMatch().getTabberControl().showPnlPlayers(); + SDisplayUtil.showTab(EDocID.REPORT_PLAYERS.getDoc()); } }; @@ -85,7 +88,7 @@ public class KeyboardShortcuts { @Override public void actionPerformed(final ActionEvent e) { if (Singletons.getControl().getState() != 1) { return; } - Singletons.getControl().getControlMatch().getTabberControl().showPnlDev(); + SDisplayUtil.showTab(EDocID.DEV_MODE.getDoc()); } }; @@ -94,7 +97,7 @@ public class KeyboardShortcuts { @Override public void actionPerformed(final ActionEvent e) { if (Singletons.getControl().getState() != 1) { return; } - Singletons.getControl().getControlMatch().getDockControl().concede(); + CDock.SINGLETON_INSTANCE.concede(); } }; diff --git a/src/main/java/forge/control/input/Input.java b/src/main/java/forge/control/input/Input.java index 6432e1bb899..63ef44abca9 100644 --- a/src/main/java/forge/control/input/Input.java +++ b/src/main/java/forge/control/input/Input.java @@ -22,6 +22,7 @@ import forge.Card; import forge.Singletons; import forge.game.player.Player; import forge.game.zone.PlayerZone; +import forge.gui.match.CMatchUI; /** *

@@ -44,7 +45,7 @@ public abstract class Input implements java.io.Serializable { *

*/ public void showMessage() { - Singletons.getControl().getControlMatch().showMessage("Blank Input"); + CMatchUI.SINGLETON_INSTANCE.showMessage("Blank Input"); } /** diff --git a/src/main/java/forge/control/input/InputAttack.java b/src/main/java/forge/control/input/InputAttack.java index 4111e942fce..7c5ac816724 100644 --- a/src/main/java/forge/control/input/InputAttack.java +++ b/src/main/java/forge/control/input/InputAttack.java @@ -20,11 +20,14 @@ package forge.control.input; import forge.AllZone; import forge.Card; import forge.CardList; +import forge.Singletons; import forge.game.phase.CombatUtil; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; +import forge.gui.framework.SDisplayUtil; +import forge.gui.match.CMatchUI; +import forge.gui.match.views.VMessage; import forge.view.ButtonUtil; -import forge.Singletons; /** *

@@ -54,7 +57,7 @@ public class InputAttack extends Input { sb.append("Declare Attackers: Select Creatures to Attack "); sb.append(o.toString()); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); if (AllZone.getCombat().getRemainingDefenders() == 0) { // Nothing left to attack, has to attack this defender @@ -107,7 +110,7 @@ public class InputAttack extends Input { CombatUtil.showCombat(); } else { - Singletons.getControl().getControlMatch().getMessageControl().remind(); + SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE); } } // selectCard() diff --git a/src/main/java/forge/control/input/InputBlock.java b/src/main/java/forge/control/input/InputBlock.java index ab43b660c30..c32b0e2bbc8 100644 --- a/src/main/java/forge/control/input/InputBlock.java +++ b/src/main/java/forge/control/input/InputBlock.java @@ -25,6 +25,9 @@ import forge.Singletons; import forge.game.phase.CombatUtil; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; +import forge.gui.framework.SDisplayUtil; +import forge.gui.match.CMatchUI; +import forge.gui.match.views.VMessage; import forge.view.ButtonUtil; /** @@ -65,14 +68,14 @@ public class InputBlock extends Input { final StringBuilder sb = new StringBuilder(); sb.append("To Block, click on your Opponents attacker first, then your blocker(s). "); sb.append("To cancel a block right-click on your blocker"); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); } else { final String attackerName = this.currentAttacker.isFaceDown() ? "Morph" : this.currentAttacker.getName(); final StringBuilder sb = new StringBuilder(); sb.append("Select a creature to block ").append(attackerName).append(" ("); sb.append(this.currentAttacker.getUniqueNumber()).append("). "); sb.append("To cancel a block right-click on your blocker"); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); } CombatUtil.showCombat(); @@ -102,7 +105,7 @@ public class InputBlock extends Input { this.allBlocking.add(card); AllZone.getCombat().addBlocker(this.currentAttacker, card); } else { - Singletons.getControl().getControlMatch().getMessageControl().remind(); + SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE); } this.showMessage(); } // selectCard() diff --git a/src/main/java/forge/control/input/InputCleanup.java b/src/main/java/forge/control/input/InputCleanup.java index 71d8f005c6d..f2f87b0c3c9 100644 --- a/src/main/java/forge/control/input/InputCleanup.java +++ b/src/main/java/forge/control/input/InputCleanup.java @@ -19,11 +19,12 @@ package forge.control.input; import forge.AllZone; import forge.Card; +import forge.Singletons; import forge.game.phase.CombatUtil; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; -import forge.Singletons; /** *

@@ -63,7 +64,7 @@ public class InputCleanup extends Input { final StringBuffer sb = new StringBuffer(); sb.append("Cleanup Phase: You can only have a maximum of ").append(max); sb.append(" cards, you currently have ").append(n).append(" cards in your hand - select a card to discard"); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); } /** {@inheritDoc} */ diff --git a/src/main/java/forge/control/input/InputControl.java b/src/main/java/forge/control/input/InputControl.java index a9befbe71d1..090db656238 100644 --- a/src/main/java/forge/control/input/InputControl.java +++ b/src/main/java/forge/control/input/InputControl.java @@ -21,11 +21,11 @@ import java.util.LinkedList; import java.util.Stack; import forge.MyObservable; -import forge.Singletons; import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseType; import forge.game.player.ComputerAIInput; import forge.game.player.Player; +import forge.gui.match.CMatchUI; import forge.model.FModel; /** @@ -247,7 +247,7 @@ public class InputControl extends MyObservable implements java.io.Serializable { final boolean skip = this.model.getGameState().getPhaseHandler().doSkipPhase(); this.model.getGameState().getPhaseHandler().setSkipPhase(false); if ((this.model.getGameState().getStack().size() == 0) - && !Singletons.getControl().getControlMatch().stopAtPhase(playerTurn, phase) && skip) { + && !CMatchUI.SINGLETON_INSTANCE.stopAtPhase(playerTurn, phase) && skip) { this.model.getGameState().getPhaseHandler().passPriority(); return null; } else { diff --git a/src/main/java/forge/control/input/InputMulligan.java b/src/main/java/forge/control/input/InputMulligan.java index a2918e38ce6..8ca2ebaec94 100644 --- a/src/main/java/forge/control/input/InputMulligan.java +++ b/src/main/java/forge/control/input/InputMulligan.java @@ -35,6 +35,10 @@ import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; +import forge.gui.framework.SDisplayUtil; +import forge.gui.match.CMatchUI; +import forge.gui.match.VMatchUI; +import forge.gui.match.views.VMessage; import forge.quest.QuestController; import forge.quest.bazaar.QuestItemType; import forge.view.ButtonUtil; @@ -57,9 +61,9 @@ public class InputMulligan extends Input { @Override public final void showMessage() { ButtonUtil.enableAll(); - Singletons.getView().getViewMatch().getBtnOK().setText("No"); - Singletons.getView().getViewMatch().getBtnCancel().setText("Yes"); - Singletons.getControl().getControlMatch().showMessage("Do you want to Mulligan?"); + VMatchUI.SINGLETON_INSTANCE.getBtnOK().setText("No"); + VMatchUI.SINGLETON_INSTANCE.getBtnCancel().setText("Yes"); + CMatchUI.SINGLETON_INSTANCE.showMessage("Do you want to Mulligan?"); } /** {@inheritDoc} */ @@ -224,7 +228,7 @@ public class InputMulligan extends Input { c0.getController().drawCards(hand.size()); } } else { - Singletons.getControl().getControlMatch().getMessageControl().remind(); + SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE); } } } diff --git a/src/main/java/forge/control/input/InputPassPriority.java b/src/main/java/forge/control/input/InputPassPriority.java index e0a4ccbfaa3..e60adeb1929 100644 --- a/src/main/java/forge/control/input/InputPassPriority.java +++ b/src/main/java/forge/control/input/InputPassPriority.java @@ -24,6 +24,9 @@ import forge.game.phase.PhaseType; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.gui.GuiDisplayUtil; +import forge.gui.framework.SDisplayUtil; +import forge.gui.match.CMatchUI; +import forge.gui.match.views.VMessage; import forge.view.ButtonUtil; /** @@ -64,7 +67,7 @@ public class InputPassPriority extends Input implements java.io.Serializable { sb.append("\n"); sb.append("Priority: ").append(player); - Singletons.getControl().getControlMatch().showMessage(sb.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); } /** {@inheritDoc} */ @@ -86,7 +89,7 @@ public class InputPassPriority extends Input implements java.io.Serializable { Singletons.getModel().getGameState().getPhaseHandler().setPriority(AllZone.getHumanPlayer()); } else { - Singletons.getControl().getControlMatch().getMessageControl().remind(); + SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE); } } // selectCard() } diff --git a/src/main/java/forge/control/input/InputPayManaCost.java b/src/main/java/forge/control/input/InputPayManaCost.java index c4b8c98ba31..38269935b4f 100644 --- a/src/main/java/forge/control/input/InputPayManaCost.java +++ b/src/main/java/forge/control/input/InputPayManaCost.java @@ -27,6 +27,7 @@ import forge.game.phase.PhaseHandler; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; //pays the cost of a card played from the player's hand @@ -289,7 +290,7 @@ public class InputPayManaCost extends InputMana { msg.append("\n(Click on your life total to pay life for phyrexian mana.)"); } - Singletons.getControl().getControlMatch().showMessage(msg.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(msg.toString()); if (this.manaCost.isPaid() && !new ManaCost(this.originalManaCost).isPaid()) { this.originalCard.setSunburstValue(this.manaCost.getSunburst()); this.done(); diff --git a/src/main/java/forge/control/input/InputPayManaCostAbility.java b/src/main/java/forge/control/input/InputPayManaCostAbility.java index fd1a55bb6d6..1435d4fbdc2 100644 --- a/src/main/java/forge/control/input/InputPayManaCostAbility.java +++ b/src/main/java/forge/control/input/InputPayManaCostAbility.java @@ -20,11 +20,13 @@ package forge.control.input; import forge.AllZone; import forge.Card; import forge.Command; -import forge.Singletons; import forge.card.mana.ManaCost; import forge.card.spellability.SpellAbility; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; +import forge.gui.framework.SDisplayUtil; +import forge.gui.match.CMatchUI; +import forge.gui.match.views.VMessage; import forge.view.ButtonUtil; //if cost is paid, Command.execute() is called @@ -156,7 +158,7 @@ public class InputPayManaCostAbility extends InputMana { this.manaCost = InputPayManaCostUtil.activateManaAbility(this.fakeAbility, card, this.manaCost); if (card.getManaAbility().isEmpty() || card.isInZone(ZoneType.Hand)) { - Singletons.getControl().getControlMatch().getMessageControl().remind(); + SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE); } if (this.manaCost.isPaid()) { @@ -194,7 +196,7 @@ public class InputPayManaCostAbility extends InputMana { if (this.showOnlyOKButton) { ButtonUtil.enableOnlyOK(); } - Singletons.getControl().getControlMatch().showMessage(this.message + "Pay Mana Cost: \r\n" + this.manaCost.toString()); + CMatchUI.SINGLETON_INSTANCE.showMessage(this.message + "Pay Mana Cost: \r\n" + this.manaCost.toString()); } /* (non-Javadoc) diff --git a/src/main/java/forge/control/match/ControlField.java b/src/main/java/forge/control/match/ControlField.java deleted file mode 100644 index 74aedd9f4f6..00000000000 --- a/src/main/java/forge/control/match/ControlField.java +++ /dev/null @@ -1,604 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.control.match; - -import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionAdapter; -import java.awt.event.MouseMotionListener; -import java.util.ArrayList; -import java.util.Observable; -import java.util.Observer; - -import com.google.code.jyield.Generator; -import com.google.code.jyield.YieldUtils; - -import forge.AllZone; -import forge.Card; -import forge.CardList; -import forge.Constant; -import forge.Singletons; -import forge.card.cardfactory.CardFactoryUtil; -import forge.control.input.Input; -import forge.control.input.InputAttack; -import forge.control.input.InputBlock; -import forge.control.input.InputMana; -import forge.control.input.InputPayManaCost; -import forge.control.input.InputPayManaCostAbility; -import forge.game.player.Player; -import forge.game.zone.PlayerZone; -import forge.game.zone.ZoneType; -import forge.gui.ForgeAction; -import forge.gui.GuiDisplayUtil; -import forge.gui.GuiUtils; -import forge.gui.toolbox.FLabel; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; -import forge.properties.NewConstants.Lang.GuiDisplay.ComputerHand; -import forge.properties.NewConstants.Lang.GuiDisplay.ComputerLibrary; -import forge.properties.NewConstants.Lang.GuiDisplay.HumanHand; -import forge.properties.NewConstants.Lang.GuiDisplay.HumanLibrary; -import forge.view.match.ViewField; - -/** - * Child controller, applied to single field in battlefield. Manages player view - * functions such as card observers, life total changes, graveyard button click, - * etc. - * - */ -public class ControlField { - private final Player player; - private final ViewField view; - - private MouseMotionListener mmlCardOver; - private MouseListener madAvatar, madLibrary, madHand, madExiled, - madGraveyard, madFlashback, madCardClick, madBlack, - madBlue, madGreen, madRed, madWhite, madColorless; - - private Observer observerZones, observerDetails, observerPlay; - - /** - * Child controller, applied to single field in battlefield. Manages player - * view functions such as card observers, life total changes, graveyard - * button click, etc. - * - * @param p - *   The Player this field applies to - * @param v - *   The Swing component for this field - */ - public ControlField(final Player p, final ViewField v) { - this.player = p; - this.view = v; - - initMouseAdapters(); - initObservers(); - - addObservers(); - addListeners(); - } - - /** - * Gets the player. - * - * @return Player - */ - public Player getPlayer() { - return this.player; - } - - /** - * Gets the view. - * - * @return ViewField - */ - public ViewField getView() { - return this.view; - } - - /** - * Adds observers to field components where required: card stats, player - * stats, etc. - */ - public void addObservers() { - this.player.getZone(ZoneType.Hand).addObserver(observerZones); - this.player.addObserver(observerDetails); - this.player.getZone(ZoneType.Battlefield).addObserver(observerPlay); - } - - /** - * Listeners for user actions on the battlefield. - * - */ - public void addListeners() { - // Battlefield card clicks - this.view.getTabletop().removeMouseListener(madCardClick); - this.view.getTabletop().addMouseListener(madCardClick); - - // Battlefield card mouseover - this.view.getTabletop().removeMouseMotionListener(mmlCardOver); - this.view.getTabletop().addMouseMotionListener(mmlCardOver); - - // Player select - this.view.getAvatarArea().removeMouseListener(madAvatar); - this.view.getAvatarArea().addMouseListener(madAvatar); - - // Graveyard card list button - ((FLabel) this.view.getLblGraveyard()).setHoverable(true); - this.view.getLblGraveyard().removeMouseListener(madGraveyard); - this.view.getLblGraveyard().addMouseListener(madGraveyard); - // Exile card list button - ((FLabel) this.view.getLblExile()).setHoverable(true); - this.view.getLblExile().removeMouseListener(madExiled); - this.view.getLblExile().addMouseListener(madExiled); - - // Library card list button - this.view.getLblLibrary().removeMouseListener(madLibrary); - this.view.getLblLibrary().addMouseListener(madLibrary); - - this.view.getLblHand().removeMouseListener(madHand); - this.view.getLblHand().addMouseListener(madHand); - - // Flashback card list button - ((FLabel) this.view.getLblFlashback()).setHoverable(true); - this.view.getLblFlashback().removeMouseListener(madFlashback); - this.view.getLblFlashback().addMouseListener(madFlashback); - - ((FLabel) this.view.getLblBlack()).setHoverable(true); - this.view.getLblBlack().removeMouseListener(madBlack); - this.view.getLblBlack().addMouseListener(madBlack); - - ((FLabel) this.view.getLblBlue()).setHoverable(true); - this.view.getLblBlue().removeMouseListener(madBlue); - this.view.getLblBlue().addMouseListener(madBlue); - - ((FLabel) this.view.getLblGreen()).setHoverable(true); - this.view.getLblGreen().removeMouseListener(madGreen); - this.view.getLblGreen().addMouseListener(madGreen); - - ((FLabel) this.view.getLblRed()).setHoverable(true); - this.view.getLblRed().removeMouseListener(madRed); - this.view.getLblRed().addMouseListener(madRed); - - ((FLabel) this.view.getLblWhite()).setHoverable(true); - this.view.getLblWhite().removeMouseListener(madWhite); - this.view.getLblWhite().addMouseListener(madWhite); - - ((FLabel) this.view.getLblColorless()).setHoverable(true); - this.view.getLblColorless().removeMouseListener(madColorless); - this.view.getLblColorless().addMouseListener(madColorless); - } - - /** - * Resets all phase buttons to "inactive", so highlight won't be drawn on - * them. "Enabled" state remains the same. - */ - public void resetPhaseButtons() { - this.view.getLblUpkeep().setActive(false); - this.view.getLblDraw().setActive(false); - this.view.getLblMain1().setActive(false); - this.view.getLblBeginCombat().setActive(false); - this.view.getLblDeclareAttackers().setActive(false); - this.view.getLblDeclareBlockers().setActive(false); - this.view.getLblFirstStrike().setActive(false); - this.view.getLblCombatDamage().setActive(false); - this.view.getLblEndCombat().setActive(false); - this.view.getLblMain2().setActive(false); - this.view.getLblEndTurn().setActive(false); - this.view.getLblCleanup().setActive(false); - } - - /** - * Receives click and programmatic requests for viewing data stacks in the - * "zones" of a player field: hand, library, etc. - * - */ - private class ZoneAction extends ForgeAction { - private static final long serialVersionUID = -5822976087772388839L; - private final PlayerZone zone; - private final String title; - - /** - * Receives click and programmatic requests for viewing data stacks in - * the "zones" of a player field: hand, graveyard, etc. The library - * "zone" is an exception to the rule; it's handled in DeckListAction. - * - * @param zone - *   PlayerZone obj - * @param property - *   String obj - */ - public ZoneAction(final PlayerZone zone, final String property) { - super(property); - this.title = ForgeProps.getLocalized(property + "/title"); - this.zone = zone; - } - - /** - * @param e - *   ActionEvent obj - */ - @Override - public void actionPerformed(final ActionEvent e) { - Generator c = YieldUtils.toGenerator(this.getCardsAsIterable()); - - if (AllZone.getNameChanger().shouldChangeCardName()) { - c = AllZone.getNameChanger().changeCard(c); - } - - final Iterable myIterable = YieldUtils.toIterable(c); - final ArrayList choices = YieldUtils.toArrayList(myIterable); - - final ArrayList choices2 = new ArrayList(); - - if (choices.isEmpty()) { - GuiUtils.chooseOneOrNone(this.title, new String[] { "no cards" }); - } else { - for (int i = 0; i < choices.size(); i++) { - final Card crd = choices.get(i); - if (crd.isFaceDown()) { - if (crd.getController().isComputer() || !crd.hasKeyword("You may look at this card.")) { - final Card faceDown = new Card(); - faceDown.setName("Face Down"); - choices2.add(faceDown); - } else { - final Card faceDown = AllZone.getCardFactory().copyCard(crd); - faceDown.turnFaceUp(); - choices2.add(faceDown); - } - } else { - choices2.add(crd); - } - } - final Card choice = (Card) GuiUtils.chooseOneOrNone(this.title, choices2.toArray()); - if (choice != null) { - this.doAction(choice); - } - } - } - - protected Iterable getCardsAsIterable() { - return this.zone.getCards(); - } - - protected void doAction(final Card c) { - } - } // End ZoneAction - - private void initObservers() { - // Hand, Graveyard, Library, Flashback, Exile zones, attached to hand. - observerZones = new Observer() { - @Override - public void update(final Observable a, final Object b) { - ControlField.this.view.updateZones(ControlField.this.player); - } - }; - - // Life total, poison total, and keywords, attached directly to Player. - observerDetails = new Observer() { - @Override - public void update(final Observable a, final Object b) { - ControlField.this.view.updateDetails(ControlField.this.player); - } - }; - - // Card play area, attached to battlefield zone. - observerPlay = new Observer() { - @Override - public void update(final Observable a, final Object b) { - final PlayerZone pZone = (PlayerZone) a; - GuiDisplayUtil.setupPlayZone(ControlField.this.view.getTabletop(), pZone.getCards(false)); - } - }; - } - - /** Simple method that inits the mouse adapters for listeners, - * here to simplify life in the constructor. - */ - private void initMouseAdapters() { - // Hand listener - madHand = new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - if (!ControlField.this.player.isComputer()) { - new ZoneAction(ControlField.this.player.getZone(ZoneType.Hand), HumanHand.BASE) - .actionPerformed(null); - } else if (Constant.Runtime.DEV_MODE[0] - || ControlField.this.player.hasKeyword("Play with your hand revealed.")) { - new ZoneAction(ControlField.this.player.getZone(ZoneType.Hand), ComputerHand.BASE) - .actionPerformed(null); - } - } - }; - - // Flashback listener - madFlashback = new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - if (!ControlField.this.player.isComputer()) { - new ZoneAction(AllZone.getHumanPlayer().getZone(ZoneType.Graveyard), - NewConstants.Lang.GuiDisplay.HUMAN_FLASHBACK) { - - private static final long serialVersionUID = 8120331222693706164L; - - @Override - protected Iterable getCardsAsIterable() { - return CardFactoryUtil.getExternalZoneActivationCards(AllZone.getHumanPlayer()); - } - - @Override - protected void doAction(final Card c) { - Singletons.getModel().getGameAction().playCard(c); - } - } .actionPerformed(null); - } else { - new ZoneAction(ControlField.this.player.getZone(ZoneType.Graveyard), - NewConstants.Lang.GuiDisplay.COMPUTER_FLASHBACK) { - - private static final long serialVersionUID = 8120331222693706164L; - - @Override - protected Iterable getCardsAsIterable() { - return CardFactoryUtil.getExternalZoneActivationCards(AllZone.getComputerPlayer()); - } - - @Override - protected void doAction(final Card c) { - Singletons.getModel().getGameAction().playCard(c); - } - } .actionPerformed(null); - } - } - }; - - // Library listener - madLibrary = new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - if (!Constant.Runtime.DEV_MODE[0]) { return; } - - if (!ControlField.this.player.isComputer()) { - new ZoneAction(ControlField.this.player.getZone(ZoneType.Library), HumanLibrary.BASE) - .actionPerformed(null); - } else { - new ZoneAction(ControlField.this.player.getZone(ZoneType.Library), ComputerLibrary.BASE) - .actionPerformed(null); - } - } - }; - - // Exiled adapter - madExiled = new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - if (ControlField.this.player.isComputer()) { - new ZoneAction(ControlField.this.player.getZone(ZoneType.Exile), - NewConstants.Lang.GuiDisplay.COMPUTER_EXILED).actionPerformed(null); - } else { - new ZoneAction(ControlField.this.player.getZone(ZoneType.Exile), - NewConstants.Lang.GuiDisplay.HUMAN_EXILED).actionPerformed(null); - } - } - }; - - // Graveyard adapter - madGraveyard = new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - if (ControlField.this.player.isComputer()) { - new ZoneAction(ControlField.this.player.getZone(ZoneType.Graveyard), - NewConstants.Lang.GuiDisplay.COMPUTER_GRAVEYARD).actionPerformed(null); - } else { - new ZoneAction(ControlField.this.player.getZone(ZoneType.Graveyard), - NewConstants.Lang.GuiDisplay.HUMAN_GRAVEYARD).actionPerformed(null); - } - } - }; - - // Avatar - madAvatar = new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - if (ControlField.this.player.isComputer()) { - Singletons.getControl().getControlMatch().getMessageControl() - .getInputControl().selectPlayer(AllZone.getComputerPlayer()); - } else { - Singletons.getControl().getControlMatch().getMessageControl() - .getInputControl().selectPlayer(AllZone.getHumanPlayer()); - } - } - }; - - // Battlefield card mouse over - mmlCardOver = new MouseMotionAdapter() { - @Override - public void mouseMoved(final MouseEvent me) { - final Card c = ControlField.this.view.getTabletop().getCardFromMouseOverPanel(); - if (c != null) { - Singletons.getControl().getControlMatch().setCard(c); - } - } - }; - - // Battlefield card - madCardClick = new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - - // original version: - // final Card c = t.getDetailController().getCurrentCard(); - // Roujin's bug fix version dated 2-12-2012 - final Card c = ControlField.this.view.getTabletop().getCardFromMouseOverPanel(); - - final Input input = Singletons.getControl().getControlMatch().getMessageControl().getInputControl().getInput(); - - if (c != null && c.isInZone(ZoneType.Battlefield)) { - if (c.isTapped() - && ((input instanceof InputPayManaCost) || (input instanceof InputPayManaCostAbility))) { - final forge.view.arcane.CardPanel cardPanel = ControlField.this.view.getTabletop().getCardPanel( - c.getUniqueNumber()); - for (final forge.view.arcane.CardPanel cp : cardPanel.getAttachedPanels()) { - if (cp.getCard().isUntapped()) { - break; - } - } - } - - final CardList att = AllZone.getCombat().getAttackerList(); - if ((c.isTapped() || c.hasSickness() || ((c.hasKeyword("Vigilance")) && att.contains(c))) - && (input instanceof InputAttack)) { - final forge.view.arcane.CardPanel cardPanel = ControlField.this.view.getTabletop().getCardPanel( - c.getUniqueNumber()); - for (final forge.view.arcane.CardPanel cp : cardPanel.getAttachedPanels()) { - if (cp.getCard().isUntapped() && !cp.getCard().hasSickness()) { - break; - } - } - } - - if (e.isMetaDown()) { - if (att.contains(c) && (input instanceof InputAttack) - && !c.hasKeyword("CARDNAME attacks each turn if able.")) { - c.untap(); - AllZone.getCombat().removeFromCombat(c); - } else if (input instanceof InputBlock) { - if (c.getController().isHuman()) { - AllZone.getCombat().removeFromCombat(c); - } - ((InputBlock) input).removeFromAllBlocking(c); - } - } else { - //Yosei, the Morning Star required cards to be chosen on computer side - //earlier it was enforced that cards must be in player zone - //this can potentially break some other functionality - //(tapping lands works ok but some custom cards may not...) - if (c.getController() != null) { - Singletons.getControl().getControlMatch().getMessageControl() - .getInputControl().selectCard(c, - c.getController().getZone(ZoneType.Battlefield)); - } else { - //in weird case card has no controller revert to default behaviour - Singletons.getControl().getControlMatch().getMessageControl() - .getInputControl().selectCard(c, - AllZone.getHumanPlayer().getZone(ZoneType.Battlefield)); - - } - } - } - } - }; - - madBlack = new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - if (ControlField.this.player.isComputer()) { - System.out.println("Stop trying to spend the AI's mana"); - // TODO: Mindslaver might need to add changes here - } else { - Input in = AllZone.getInputControl().getInput(); - if (in instanceof InputMana) { - // Do something - ((InputMana) in).selectManaPool(Constant.Color.BLACK); - } - } - } - }; - - madBlue = new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - if (ControlField.this.player.isComputer()) { - System.out.println("Stop trying to spend the AI's mana"); - // TODO: Mindslaver might need to add changes here - } else { - Input in = AllZone.getInputControl().getInput(); - if (in instanceof InputMana) { - // Do something - ((InputMana) in).selectManaPool(Constant.Color.BLUE); - } - } - } - }; - - madGreen = new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - if (ControlField.this.player.isComputer()) { - System.out.println("Stop trying to spend the AI's mana"); - // TODO: Mindslaver might need to add changes here - } else { - Input in = AllZone.getInputControl().getInput(); - if (in instanceof InputMana) { - // Do something - ((InputMana) in).selectManaPool(Constant.Color.GREEN); - } - } - } - }; - - madRed = new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - if (ControlField.this.player.isComputer()) { - System.out.println("Stop trying to spend the AI's mana"); - // TODO: Mindslaver might need to add changes here - } else { - Input in = AllZone.getInputControl().getInput(); - if (in instanceof InputMana) { - // Do something - ((InputMana) in).selectManaPool(Constant.Color.RED); - } - } - } - }; - - madWhite = new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - if (ControlField.this.player.isComputer()) { - System.out.println("Stop trying to spend the AI's mana"); - // TODO: Mindslaver might need to add changes here - } else { - Input in = AllZone.getInputControl().getInput(); - if (in instanceof InputMana) { - // Do something - ((InputMana) in).selectManaPool(Constant.Color.WHITE); - } - } - } - }; - - madColorless = new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - if (ControlField.this.player.isComputer()) { - System.out.println("Stop trying to spend the AI's mana"); - // TODO: Mindslaver might need to add changes here - } else { - Input in = AllZone.getInputControl().getInput(); - if (in instanceof InputMana) { - // Do something - ((InputMana) in).selectManaPool(Constant.Color.COLORLESS); - } - } - } - }; - } // End initMouseAdapters() -} // End class ControlField diff --git a/src/main/java/forge/control/match/ControlHand.java b/src/main/java/forge/control/match/ControlHand.java deleted file mode 100644 index 51af83dd872..00000000000 --- a/src/main/java/forge/control/match/ControlHand.java +++ /dev/null @@ -1,281 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.control.match; - -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionAdapter; -import java.awt.event.MouseMotionListener; -import java.util.ArrayList; -import java.util.List; -import java.util.Observable; -import java.util.Observer; - -import javax.swing.JLayeredPane; -import javax.swing.SwingUtilities; - -import forge.AllZone; -import forge.Card; -import forge.Singletons; -import forge.game.zone.PlayerZone; -import forge.game.zone.ZoneType; -import forge.view.arcane.CardPanel; -import forge.view.arcane.HandArea; -import forge.view.arcane.util.Animation; -import forge.view.match.ViewHand; - -/** - * Child controller - handles operations related to cards in user's hand and - * their Swing components, which are assembled in ViewHand. - * - */ -public class ControlHand { - private final List cardsInPanel; - private final ViewHand view; - - private final MouseListener madCardClick; - private final MouseMotionListener madCardMove; - - /** The o1. */ - private Observer o1; - - /** - * Child controller - handles operations related to cards in user's hand and - * their Swing components, which are assembled in ViewHand. - * - * @param v - *   The Swing component for user hand - */ - public ControlHand(final ViewHand v) { - this.view = v; - this.cardsInPanel = new ArrayList(); - - madCardClick = new MouseAdapter() { - // Card click - @Override - public void mousePressed(final MouseEvent e) { - if (e.getButton() != MouseEvent.BUTTON1) { - return; - } - final Card c = view.getHandArea().getCardFromMouseOverPanel(); - if (c != null) { - Singletons.getControl().getControlMatch().getMessageControl().getInputControl().selectCard(c, AllZone.getHumanPlayer().getZone(ZoneType.Hand)); - Singletons.getView().getViewMatch().getBtnOK().requestFocusInWindow(); - } - } - }; - - madCardMove = new MouseMotionAdapter() { - // Card mouseover - @Override - public void mouseMoved(final MouseEvent me) { - final Card c = view.getHandArea().getCardFromMouseOverPanel(); - if (c != null) { - Singletons.getControl().getControlMatch().setCard(c); - } - } - }; - - o1 = new Observer() { - @Override - public void update(final Observable a, final Object b) { - final PlayerZone pZone = (PlayerZone) a; - final HandArea p = view.getHandArea(); - final Rectangle rctLibraryLabel = Singletons.getControl() - .getControlMatch().getFieldControls().get(1) - .getView().getLblLibrary().getBounds(); - final List c = pZone.getCards(); - - // Animation starts from the library label. - // This check prevents animation running if label hasn't been realised yet. - if (rctLibraryLabel.isEmpty()) { - return; - } - - List tmp, diff; - tmp = new ArrayList(); - for (final forge.view.arcane.CardPanel cpa : p.getCardPanels()) { - tmp.add(cpa.getGameCard()); - } - diff = new ArrayList(tmp); - diff.removeAll(c); - if (diff.size() == p.getCardPanels().size()) { - p.clear(); - } else { - for (final Card card : diff) { - p.removeCardPanel(p.getCardPanel(card.getUniqueNumber())); - } - } - diff = new ArrayList(c); - diff.removeAll(tmp); - - JLayeredPane layeredPane = Singletons.getView().getFrame().getLayeredPane(); - int fromZoneX = 0, fromZoneY = 0; - - final Point zoneLocation = SwingUtilities.convertPoint(Singletons - .getControl().getControlMatch().getFieldControls() - .get(1).getView().getLblLibrary(), - Math.round(rctLibraryLabel.width / 2.0f), Math.round(rctLibraryLabel.height / 2.0f), layeredPane); - fromZoneX = zoneLocation.x; - fromZoneY = zoneLocation.y; - int startWidth, startX, startY; - startWidth = 10; - startX = fromZoneX - Math.round(startWidth / 2.0f); - startY = fromZoneY - Math.round(Math.round(startWidth * forge.view.arcane.CardPanel.ASPECT_RATIO) / 2.0f); - - int endWidth, endX, endY; - forge.view.arcane.CardPanel toPanel = null; - - for (final Card card : diff) { - toPanel = p.addCard(card); - endWidth = toPanel.getCardWidth(); - final Point toPos = SwingUtilities.convertPoint(view.getHandArea(), - toPanel.getCardLocation(), layeredPane); - endX = toPos.x; - endY = toPos.y; - final forge.view.arcane.CardPanel animationPanel = new forge.view.arcane.CardPanel(card); - if (Singletons.getView().getFrame().isShowing()) { - Animation.moveCard(startX, startY, startWidth, endX, endY, endWidth, animationPanel, toPanel, - layeredPane, 500); - } else { - Animation.moveCard(toPanel); - } - } - } - }; - - addObservers(); - addListeners(); - } - - /** Adds observers to hand panel. */ - public void addObservers() { - AllZone.getHumanPlayer().getZone(ZoneType.Hand).addObserver(o1); - } - - /** Adds listeners to hand panel: clicks, mouseover, etc. */ - public void addListeners() { - view.getHandArea().removeMouseListener(madCardClick); - view.getHandArea().addMouseListener(madCardClick); - - view.getHandArea().removeMouseMotionListener(madCardMove); - view.getHandArea().addMouseMotionListener(madCardMove); - } - - /** - * Adds various listeners for cards in hand. Uses CardPanel instance from - * ViewHand. - * - * @param c - *   CardPanel object - */ - public void addCardPanelListeners(final CardPanel c) { - // Grab top level controller to facilitate interaction between children - final Card cardobj = c.getCard(); - - // Sidebar pic/detail on card hover - c.addMouseListener(new MouseAdapter() { - @Override - public void mouseEntered(final MouseEvent e) { - Singletons.getControl().getControlMatch().getDetailControl().showCard(cardobj); - Singletons.getControl().getControlMatch().getPictureControl().showCard(cardobj); - } - }); - - // Mouse press - c.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - - if (e.getButton() != MouseEvent.BUTTON1) { - return; - } - - Singletons.getControl().getControlMatch().getMessageControl().getInputControl() - .selectCard(cardobj, AllZone.getHumanPlayer().getZone(ZoneType.Hand)); - } - }); - } - - /** - * Adds the card. - * - * @param c - *   Card object - */ - public void addCard(final Card c) { - this.cardsInPanel.add(c); - //this.view.refreshLayout(); - } - - /** - * Adds the cards. - * - * @param c - *   List of Card objects - */ - public void addCards(final List c) { - this.cardsInPanel.addAll(c); - //this.view.refreshLayout(); - } - - /** - * Gets the cards. - * - * @return List - */ - public List getCards() { - return this.cardsInPanel; - } - - /** - * Removes the card. - * - * @param c - *   Card object - */ - public void removeCard(final Card c) { - this.cardsInPanel.remove(c); - //this.view.refreshLayout(); - } - - /** - * Removes the cards. - * - * @param c - *   List of Card objects - */ - public void removeCards(final List c) { - this.cardsInPanel.removeAll(c); - //this.view.refreshLayout(); - } - - /** - * Reset cards. - * - * @param c - *   List of Card objects - */ - public void resetCards(final List c) { - this.cardsInPanel.clear(); - this.addCards(c); - } -} diff --git a/src/main/java/forge/control/match/ControlMessage.java b/src/main/java/forge/control/match/ControlMessage.java deleted file mode 100644 index d8e191ff119..00000000000 --- a/src/main/java/forge/control/match/ControlMessage.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.control.match; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import forge.Constant; -import forge.Singletons; -import forge.gui.GuiInput; -import forge.view.match.ViewMessage; - -/** - * Child controller - handles operations related to message panel. - * - */ -public class ControlMessage { - private final ViewMessage view; - - private final GuiInput inputControl; - - private final ActionListener actCancel, actOK; - - /** - * Child controller - handles operations related to input panel. - * - * @param v - *   The Swing component for the input area - */ - public ControlMessage(final ViewMessage v) { - this.view = v; - this.inputControl = new GuiInput(); - - this.actOK = new ActionListener() { - @Override - public void actionPerformed(final ActionEvent evt) { - ControlMessage.this.btnOKActionPerformed(evt); - - if (Singletons.getModel().getGameState().getPhaseHandler().isNeedToNextPhase()) { - // moves to next turn - Singletons.getModel().getGameState().getPhaseHandler().setNeedToNextPhase(false); - Singletons.getModel().getGameState().getPhaseHandler().nextPhase(); - } - ControlMessage.this.view.getBtnOK().requestFocusInWindow(); - } - }; - - this.actCancel = new ActionListener() { - @Override - public void actionPerformed(final ActionEvent evt) { - ControlMessage.this.btnCancelActionPerformed(evt); - ControlMessage.this.view.getBtnOK().requestFocusInWindow(); - } - }; - - addListeners(); - } - - /** Adds listeners to input area. */ - public void addListeners() { - this.view.getBtnCancel().removeActionListener(actCancel); - this.view.getBtnCancel().addActionListener(actCancel); - - this.view.getBtnOK().removeActionListener(actOK); - this.view.getBtnOK().addActionListener(actOK); - } - - /** - *

- * btnCancelActionPerformed. - *

- * Triggers current cancel action from whichever input controller is being - * used. - * - * @param evt - * a {@link java.awt.event.ActionEvent} object. - */ - private void btnCancelActionPerformed(final ActionEvent evt) { - this.inputControl.selectButtonCancel(); - } - - /** - *

- * btnOKActionPerformed. - *

- * Triggers current OK action from whichever input controller is being used. - * - * @param evt - * a {@link java.awt.event.ActionEvent} object. - */ - private void btnOKActionPerformed(final ActionEvent evt) { - this.inputControl.selectButtonOK(); - } - - /** - * Gets the input control. - * - * @return GuiInput - */ - public GuiInput getInputControl() { - return this.inputControl; - } - - /** @param s0   {@link java.lang.String} */ - public void setMessage(String s0) { - view.getTarMessage().setText(s0); - } - - /** Updates count label in input area. */ - public void updateGameCount() { - view.getLblGames().setText("Game #" - + (Singletons.getModel().getMatchState().getGamesPlayedCount() + 1) - + " of " + Singletons.getModel().getMatchState().getGamesPerMatch() - + "
" + Constant.Runtime.getGameType().toString() + " mode"); - } - - /** Flashes animation on input panel if play is currently waiting on input. */ - public void remind() { - view.remind(); - } -} diff --git a/src/main/java/forge/control/match/ControlTabber.java b/src/main/java/forge/control/match/ControlTabber.java deleted file mode 100644 index 870d8ae7818..00000000000 --- a/src/main/java/forge/control/match/ControlTabber.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.control.match; - -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.util.Observable; -import java.util.Observer; - -import forge.AllZone; -import forge.MyObservable; -import forge.Singletons; -import forge.gui.GuiDisplayUtil; -import forge.properties.ForgePreferences.FPref; -import forge.view.match.ViewTabber; - -/** - * Controls the vertical tabber in sidebar used for viewing gameplay data: - * stack, combat, etc. - * - */ -public class ControlTabber extends MyObservable { - private final ViewTabber view; - private final MouseListener madMilling, madUnlimited, madAddAnyCard, - madMana, madSetup, madTutor, madCounter, madTap, madUntap, madLife; - - private Observer obsStack, obsLog; - - /** */ - public static final int STACK_PANEL = 0; - /** */ - public static final int COMBAT_PANEL = 1; - /** */ - public static final int LOG_PANEL = 2; - /** */ - public static final int PLAYERS_PANEL = 3; - /** */ - public static final int DEV_PANEL = 4; - - /** - * Controls the vertical tabber in sidebar used for viewing gameplay data: - * stack, combat, etc. - * - * @param v - *   The tabber Swing component - */ - public ControlTabber(final ViewTabber v) { - this.view = v; - - if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.DEV_MILLING_LOSS)) { - this.view.getLblMilling().setEnabled(true); - } else { - this.view.getLblMilling().setEnabled(false); - } - - if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.DEV_UNLIMITED_LAND)) { - this.view.getLblUnlimitedLands().setEnabled(true); - } else { - this.view.getLblUnlimitedLands().setEnabled(false); - } - - // Observers and listeners - obsStack = new Observer() { @Override - public void update(final Observable a, final Object b) { - ControlTabber.this.view.updateStack(); } }; - - obsLog = new Observer() { @Override - public void update(final Observable a, final Object b) { - ControlTabber.this.view.updateConsole(); } }; - - madMilling = new MouseAdapter() { @Override - public void mousePressed(final MouseEvent e) { - ControlTabber.this.view.getLblMilling().toggleEnabled(); } }; - - madUnlimited = new MouseAdapter() { @Override - public void mousePressed(final MouseEvent e) { - ControlTabber.this.view.getLblUnlimitedLands().toggleEnabled(); } }; - - madMana = new MouseAdapter() { @Override - public void mousePressed(final MouseEvent e) { - GuiDisplayUtil.devModeGenerateMana(); } }; - - madSetup = new MouseAdapter() { @Override - public void mousePressed(final MouseEvent e) { - GuiDisplayUtil.devSetupGameState(); } }; - - madTutor = new MouseAdapter() { @Override - public void mousePressed(final MouseEvent e) { - GuiDisplayUtil.devModeTutor(); } }; - - madAddAnyCard = new MouseAdapter() { @Override - public void mousePressed(final MouseEvent e) { - GuiDisplayUtil.devModeAddAnyCard(); } }; - - madCounter = new MouseAdapter() { @Override - public void mousePressed(final MouseEvent e) { - GuiDisplayUtil.devModeAddCounter(); } }; - - madTap = new MouseAdapter() { @Override - public void mousePressed(final MouseEvent e) { - GuiDisplayUtil.devModeTapPerm(); } }; - - madUntap = new MouseAdapter() { @Override - public void mousePressed(final MouseEvent e) { - GuiDisplayUtil.devModeUntapPerm(); } }; - - madLife = new MouseAdapter() { @Override - public void mousePressed(final MouseEvent e) { - GuiDisplayUtil.devModeSetLife(); } }; - - addListeners(); - addObservers(); - } - - /** Adds observers to tabber. */ - public void addObservers() { - AllZone.getStack().addObserver(obsStack); - AllZone.getGameLog().addObserver(obsLog); - } - - /** Adds listeners to various components in tabber. */ - public void addListeners() { - // Milling enable toggle - this.view.getLblMilling().removeMouseListener(madMilling); - this.view.getLblMilling().addMouseListener(madMilling); - - // DevMode: Play unlimited land this turn toggle - this.view.getLblUnlimitedLands().removeMouseListener(madUnlimited); - this.view.getLblUnlimitedLands().addMouseListener(madUnlimited); - - // DevMode: Generate mana - this.view.getLblGenerateMana().removeMouseListener(madMana); - this.view.getLblGenerateMana().addMouseListener(madMana); - - // DevMode: Battlefield setup - this.view.getLblSetupGame().removeMouseListener(madSetup); - this.view.getLblSetupGame().addMouseListener(madSetup); - - // DevMode: Tutor for card - this.view.getLblTutor().removeMouseListener(madTutor); - this.view.getLblTutor().addMouseListener(madTutor); - - this.view.getAnyCard().removeMouseListener(madAddAnyCard); - this.view.getAnyCard().addMouseListener(madAddAnyCard); - - // DevMode: Add counter to permanent - this.view.getLblCounterPermanent().removeMouseListener(madCounter); - this.view.getLblCounterPermanent().addMouseListener(madCounter); - - // DevMode: Tap permanent - this.view.getLblTapPermanent().removeMouseListener(madTap); - this.view.getLblTapPermanent().addMouseListener(madTap); - - // DevMode: Untap permanent - this.view.getLblUntapPermanent().removeMouseListener(madUntap); - this.view.getLblUntapPermanent().addMouseListener(madUntap); - - // DevMode: Set life - this.view.getLblSetLife().removeMouseListener(madLife); - this.view.getLblSetLife().addMouseListener(madLife); - } - - /** - * Gets the view. - * - * @return ViewTabber - */ - public ViewTabber getView() { - return this.view; - } - - /** - * Programatically forces card layout of sidebar tabber to show "Dev" panel. - */ - public void showPnlDev() { - this.view.getVtpTabber().showTab(DEV_PANEL); - } - - /** - * Programatically forces card layout of sidebar tabber to show "Players" - * panel. - */ - public void showPnlPlayers() { - this.view.getVtpTabber().showTab(PLAYERS_PANEL); - } - - /** - * Programatically forces card layout of sidebar tabber to show "Log" - * panel. - */ - public void showPnlGameLog() { - this.view.getVtpTabber().showTab(LOG_PANEL); - } - - /** - * Programatically forces card layout of sidebar tabber to show "Combat" - * panel. - */ - public void showPnlCombat() { - this.view.getVtpTabber().showTab(COMBAT_PANEL); - } - - /** - * Programatically forces card layout of sidebar tabber to show "Stack" - * panel. - */ - public void showPnlStack() { - this.view.getVtpTabber().showTab(STACK_PANEL); - } -} diff --git a/src/main/java/forge/control/match/package-info.java b/src/main/java/forge/control/match/package-info.java deleted file mode 100644 index ba6acc3b070..00000000000 --- a/src/main/java/forge/control/match/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -/** Child controllers used in match UI. */ -package forge.control.match; - diff --git a/src/main/java/forge/game/GameNew.java b/src/main/java/forge/game/GameNew.java index 26c8d49e6b0..d91646061c8 100644 --- a/src/main/java/forge/game/GameNew.java +++ b/src/main/java/forge/game/GameNew.java @@ -20,15 +20,20 @@ import forge.card.trigger.TriggerType; import forge.control.FControl; import forge.control.input.InputMulligan; import forge.deck.Deck; +import forge.game.phase.PhaseHandler; import forge.game.player.Player; import forge.game.zone.ZoneType; +import forge.gui.match.CMatchUI; +import forge.gui.match.VMatchUI; +import forge.gui.match.controllers.CMessage; +import forge.gui.match.nonsingleton.VField; +import forge.gui.match.views.VAntes; import forge.gui.toolbox.FLabel; import forge.item.CardPrinted; import forge.properties.ForgePreferences.FPref; import forge.properties.ForgeProps; import forge.properties.NewConstants.Lang.GameAction.GameActionText; import forge.util.MyRandom; -import forge.view.match.ViewField; /** * Methods for all things related to starting a new game. @@ -40,24 +45,24 @@ public class GameNew { * immediately, and life totals to be adjusted, for computer and human. * * @param humanDeck - *   {@link forge.deck.Deck} object. + *   {@link forge.deck.Deck} object. * @param computerDeck - *   {@link forge.deck.Deck} object. + *   {@link forge.deck.Deck} object. * @param human - *   {@link forge.CardList} object. + *   {@link forge.CardList} object. * @param computer - *   {@link forge.CardList} object. + *   {@link forge.CardList} object. * @param humanLife - *   int. + *   int. * @param computerLife - *   int. + *   int. * @param iconEnemy - *   String. + *   {@link java.lang.String} */ public static void newGame(final Deck humanDeck, final Deck computerDeck, final CardList human, final CardList computer, final int humanLife, final int computerLife, String iconEnemy) { Singletons.getControl().changeState(FControl.MATCH_SCREEN); - Singletons.getControl().getControlMatch().initMatch(iconEnemy); + CMatchUI.SINGLETON_INSTANCE.initMatch(iconEnemy); GameNew.newGameCleanup(); GameNew.newMatchCleanup(); @@ -89,7 +94,7 @@ public class GameNew { */ public static void newGame(final Deck humanDeck, final Deck computerDeck) { Singletons.getControl().changeState(FControl.MATCH_SCREEN); - Singletons.getControl().getControlMatch().initMatch(null); + CMatchUI.SINGLETON_INSTANCE.initMatch(null); GameNew.newGameCleanup(); GameNew.newMatchCleanup(); @@ -111,7 +116,7 @@ public class GameNew { forge.card.trigger.Trigger.resetIDs(); AllZone.getTriggerHandler().clearTriggerSettings(); AllZone.getTriggerHandler().clearDelayedTrigger(); - Singletons.getControl().getControlMatch().getMessageControl().updateGameCount(); + CMessage.SINGLETON_INSTANCE.updateGameCount(); // friendliness Card.resetUniqueNumber(); @@ -270,6 +275,7 @@ public class GameNew { throw new RuntimeException(p + " library is empty."); } AllZone.getGameLog().add("Ante", p + " anted " + ante, 0); + VAntes.SINGLETON_INSTANCE.setAnteCard(p, ante); Singletons.getModel().getGameAction().moveTo(ZoneType.Ante, ante); msg.append(p.getName()).append(" ante: ").append(ante).append(nl); } @@ -281,10 +287,10 @@ public class GameNew { AllZone.getComputerPlayer().drawCard(); } - Singletons.getControl().getControlMatch().setCard(AllZone.getHumanPlayer().getCardsIn(ZoneType.Hand).get(0)); + CMatchUI.SINGLETON_INSTANCE.setCard(AllZone.getHumanPlayer().getCardsIn(ZoneType.Hand).get(0)); AllZone.getInputControl().setInput(new InputMulligan()); - // PhaseHandler.setGameBegins(1); // is this needed? It's already in InputMulligan... + PhaseHandler.setGameBegins(1); // is this needed? It's already in InputMulligan... AllZone.getGameLog().add("Turn", "Turn " + Singletons.getModel().getGameState().getPhaseHandler().getTurn() @@ -323,26 +329,28 @@ public class GameNew { // Update mouse events in case of dev mode toggle if (Constant.Runtime.DEV_MODE[0]) { - Singletons.getView().getViewMatch() - .getViewTabber().getVtpTabber().getAllVTabs().get(4).setVisible(true); - final List allFields = Singletons.getView().getViewMatch().getFieldViews(); + // TODO restore this functionality!!! + //VMatchUI.SINGLETON_INSTANCE.getViewDevMode().getDocument().setVisible(true); + final List allFields = VMatchUI.SINGLETON_INSTANCE.getFieldViews(); - for (final ViewField field : allFields) { + for (final VField field : allFields) { ((FLabel) field.getLblHand()).setHoverable(true); ((FLabel) field.getLblLibrary()).setHoverable(true); } } else { - Singletons.getView().getViewMatch() - .getViewTabber().getVtpTabber().getAllVTabs().get(4).setVisible(false); - final List allFields = Singletons.getView().getViewMatch().getFieldViews(); + // TODO restore this functionality!!! + //VMatchUI.SINGLETON_INSTANCE.getViewDevMode().getDocument().setVisible(false); + final List allFields = VMatchUI.SINGLETON_INSTANCE.getFieldViews(); - for (final ViewField field : allFields) { + for (final VField field : allFields) { ((FLabel) field.getLblHand()).setHoverable(false); ((FLabel) field.getLblLibrary()).setHoverable(false); } } + VAntes.SINGLETON_INSTANCE.setAnteCard(AllZone.getComputerPlayer(), null); + VAntes.SINGLETON_INSTANCE.setAnteCard(AllZone.getHumanPlayer(), null); AllZone.getInputControl().resetInput(); Singletons.getModel().getMatchState().reset(); Singletons.getModel().loadPrefs(); diff --git a/src/main/java/forge/game/phase/Combat.java b/src/main/java/forge/game/phase/Combat.java index 71099789414..f935201c1de 100644 --- a/src/main/java/forge/game/phase/Combat.java +++ b/src/main/java/forge/game/phase/Combat.java @@ -39,6 +39,7 @@ import forge.Singletons; import forge.card.trigger.TriggerType; import forge.game.player.Player; import forge.game.zone.ZoneType; +import forge.gui.match.CMatchUI; /** *

@@ -729,7 +730,7 @@ public class Combat { this.addDefendingDamage(damageDealt, attacker); } else { if (attacker.hasKeyword("Trample") || (block.size() > 1)) { - Singletons.getControl().getControlMatch().assignDamage(attacker, block, damageDealt); + CMatchUI.SINGLETON_INSTANCE.assignDamage(attacker, block, damageDealt); } else { block.get(0).addAssignedDamage(damageDealt, attacking.get(i)); } @@ -782,7 +783,7 @@ public class Combat { this.addDefendingDamage(damageDealt, attacker); } else { if (attacker.hasKeyword("Trample") || (block.size() > 1)) { - Singletons.getControl().getControlMatch().assignDamage(attacker, block, damageDealt); + CMatchUI.SINGLETON_INSTANCE.assignDamage(attacker, block, damageDealt); } else { block.get(0).addAssignedDamage(damageDealt, attacking.get(i)); } diff --git a/src/main/java/forge/game/phase/CombatUtil.java b/src/main/java/forge/game/phase/CombatUtil.java index 2835e68045f..1be8f32fdff 100644 --- a/src/main/java/forge/game/phase/CombatUtil.java +++ b/src/main/java/forge/game/phase/CombatUtil.java @@ -52,6 +52,9 @@ import forge.game.player.PlayerUtil; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; +import forge.gui.framework.EDocID; +import forge.gui.framework.SDisplayUtil; +import forge.gui.match.views.VCombat; /** *

@@ -2431,8 +2434,6 @@ public class CombatUtil { *

*/ public static void showCombat() { - Singletons.getControl().getControlMatch().showCombat(""); - Card[] defend = null; final StringBuilder display = new StringBuilder(); @@ -2471,8 +2472,9 @@ public class CombatUtil { } } // loop through attackers } - Singletons.getControl().getControlMatch().showCombat(display.toString().trim()); + SDisplayUtil.showTab(EDocID.REPORT_COMBAT.getDoc()); + VCombat.SINGLETON_INSTANCE.updateCombat(display.toString().trim()); } // showBlockers() /** diff --git a/src/main/java/forge/game/phase/PhaseHandler.java b/src/main/java/forge/game/phase/PhaseHandler.java index 9b30ca30bd8..6fbec0e41cc 100644 --- a/src/main/java/forge/game/phase/PhaseHandler.java +++ b/src/main/java/forge/game/phase/PhaseHandler.java @@ -34,6 +34,8 @@ import forge.Singletons; import forge.card.trigger.TriggerType; import forge.game.player.Player; import forge.game.zone.ZoneType; +import forge.gui.framework.EDocID; +import forge.gui.framework.SDisplayUtil; import forge.properties.ForgePreferences.FPref; /** @@ -321,7 +323,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable { switch(phase) { case UNTAP: - Singletons.getControl().getControlMatch().showStack(); + SDisplayUtil.showTab(EDocID.REPORT_STACK.getDoc()); PhaseUtil.handleUntap(); break; @@ -406,12 +408,12 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable { AllZone.getEndOfCombat().executeUntil(); AllZone.getEndOfCombat().executeAt(); CombatUtil.showCombat(); - Singletons.getControl().getControlMatch().showStack(); + SDisplayUtil.showTab(EDocID.REPORT_STACK.getDoc()); break; case MAIN2: CombatUtil.showCombat(); - Singletons.getControl().getControlMatch().showStack(); + SDisplayUtil.showTab(EDocID.REPORT_STACK.getDoc()); break; case END_OF_TURN: @@ -526,7 +528,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable { } if (this.getPhase() == PhaseType.COMBAT_END) { - Singletons.getControl().getControlMatch().showStack(); + SDisplayUtil.showTab(EDocID.REPORT_STACK.getDoc()); AllZone.getCombat().reset(); this.resetAttackedThisCombat(this.getPlayerTurn()); this.bCombat = false; diff --git a/src/main/java/forge/game/phase/PhaseUtil.java b/src/main/java/forge/game/phase/PhaseUtil.java index 26615fa7eea..6f995942870 100644 --- a/src/main/java/forge/game/phase/PhaseUtil.java +++ b/src/main/java/forge/game/phase/PhaseUtil.java @@ -26,11 +26,10 @@ import forge.CardList; import forge.CardListFilter; import forge.Singletons; import forge.card.trigger.TriggerType; -import forge.control.ControlMatchUI; -import forge.game.phase.PhaseType; import forge.game.player.Player; import forge.game.zone.ZoneType; -import forge.view.match.ViewField.PhaseLabel; +import forge.gui.match.CMatchUI; +import forge.gui.match.nonsingleton.VField.PhaseLabel; /** *

@@ -386,13 +385,12 @@ public class PhaseUtil { public static void visuallyActivatePhase(final PhaseType s) { PhaseLabel lbl = null; final Player p = Singletons.getModel().getGameState().getPhaseHandler().getPlayerTurn(); - final ControlMatchUI t = Singletons.getControl().getControlMatch(); + final CMatchUI t = CMatchUI.SINGLETON_INSTANCE; // Index of field; computer is 0, human is 1 int i = p.isComputer() ? 0 : 1; switch(s) { - case UPKEEP: lbl = t.getFieldControls().get(i).getView().getLblUpkeep(); break; @@ -434,7 +432,6 @@ public class PhaseUtil { } t.resetAllPhaseButtons(); - Singletons.getView().getViewMatch().repaint(); lbl.setActive(true); } } diff --git a/src/main/java/forge/game/phase/Untap.java b/src/main/java/forge/game/phase/Untap.java index ae4b8c7c8f1..2858ff77fdf 100644 --- a/src/main/java/forge/game/phase/Untap.java +++ b/src/main/java/forge/game/phase/Untap.java @@ -33,6 +33,7 @@ import forge.control.input.Input; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; /** @@ -208,7 +209,7 @@ public class Untap extends Phase implements java.io.Serializable { @Override public void showMessage() { - Singletons.getControl().getControlMatch().showMessage("Select one tapped land to untap"); + CMatchUI.SINGLETON_INSTANCE.showMessage("Select one tapped land to untap"); ButtonUtil.enableOnlyCancel(); } @@ -256,7 +257,7 @@ public class Untap extends Phase implements java.io.Serializable { @Override public void showMessage() { - Singletons.getControl().getControlMatch().showMessage("Select one tapped artifact to untap"); + CMatchUI.SINGLETON_INSTANCE.showMessage("Select one tapped artifact to untap"); ButtonUtil.enableOnlyCancel(); } @@ -305,7 +306,7 @@ public class Untap extends Phase implements java.io.Serializable { @Override public void showMessage() { - Singletons.getControl().getControlMatch().showMessage("Select one creature to untap"); + CMatchUI.SINGLETON_INSTANCE.showMessage("Select one creature to untap"); ButtonUtil.enableOnlyCancel(); } diff --git a/src/main/java/forge/game/phase/Upkeep.java b/src/main/java/forge/game/phase/Upkeep.java index 4f36aa02d3a..84065b862a4 100644 --- a/src/main/java/forge/game/phase/Upkeep.java +++ b/src/main/java/forge/game/phase/Upkeep.java @@ -44,6 +44,7 @@ import forge.game.player.PlayerUtil; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; /** @@ -495,9 +496,7 @@ public class Upkeep extends Phase implements java.io.Serializable { @Override public void showMessage() { - Singletons - .getControl() - .getControlMatch() + CMatchUI.SINGLETON_INSTANCE .showMessage( abyss.getName() + " - Select one nonartifact creature to destroy"); ButtonUtil.disableAll(); @@ -566,9 +565,7 @@ public class Upkeep extends Phase implements java.io.Serializable { @Override public void showMessage() { - Singletons - .getControl() - .getControlMatch() + CMatchUI.SINGLETON_INSTANCE .showMessage( "Yawgmoth Demon - Select one artifact to sacrifice or be dealt 2 damage"); ButtonUtil.enableOnlyCancel(); @@ -2285,7 +2282,7 @@ public class Upkeep extends Phase implements java.io.Serializable { @Override public void showMessage() { - Singletons.getControl().getControlMatch() + CMatchUI.SINGLETON_INSTANCE .showMessage(c.getName() + " - Select target creature."); ButtonUtil.enableOnlyCancel(); } @@ -2359,9 +2356,7 @@ public class Upkeep extends Phase implements java.io.Serializable { this.stop(); return; } - Singletons - .getControl() - .getControlMatch() + CMatchUI.SINGLETON_INSTANCE .showMessage( source.getName() + " - Select " diff --git a/src/main/java/forge/game/player/HumanPlayer.java b/src/main/java/forge/game/player/HumanPlayer.java index 1501e75aa26..86c1087af20 100644 --- a/src/main/java/forge/game/player/HumanPlayer.java +++ b/src/main/java/forge/game/player/HumanPlayer.java @@ -26,6 +26,7 @@ import forge.card.spellability.SpellAbility; import forge.control.input.Input; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; +import forge.gui.match.CMatchUI; /** *

@@ -250,7 +251,7 @@ public class HumanPlayer extends Player { protected final void clashMoveToTopOrBottom(final Card c) { String choice = ""; final String[] choices = { "top", "bottom" }; - Singletons.getControl().getControlMatch().setCard(c); + CMatchUI.SINGLETON_INSTANCE.setCard(c); choice = GuiUtils.chooseOne(c.getName() + " - Top or bottom of Library", choices); if (choice.equals("bottom")) { diff --git a/src/main/java/forge/game/player/Player.java b/src/main/java/forge/game/player/Player.java index d5ed0c64c51..674f0e90397 100644 --- a/src/main/java/forge/game/player/Player.java +++ b/src/main/java/forge/game/player/Player.java @@ -51,6 +51,7 @@ import forge.game.zone.PlayerZone; import forge.game.zone.PlayerZoneComesIntoPlay; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; +import forge.gui.match.VMatchUI; import forge.util.MyRandom; /** @@ -1854,7 +1855,7 @@ public abstract class Player extends GameEntity { * @return a boolean. */ public final boolean canPlayLand() { - if (Singletons.getView().getViewMatch().getViewTabber().getLblUnlimitedLands().getEnabled() && this.isHuman() + if (VMatchUI.SINGLETON_INSTANCE.getViewDevMode().getLblUnlimitedLands().getEnabled() && this.isHuman() && Constant.Runtime.DEV_MODE[0]) { return PhaseHandler.canCastSorcery(this); } diff --git a/src/main/java/forge/game/player/PlayerUtil.java b/src/main/java/forge/game/player/PlayerUtil.java index 0ded70beeac..0c8fd73d8b5 100644 --- a/src/main/java/forge/game/player/PlayerUtil.java +++ b/src/main/java/forge/game/player/PlayerUtil.java @@ -26,6 +26,7 @@ import forge.card.spellability.SpellAbility; import forge.control.input.Input; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; /** @@ -91,7 +92,7 @@ public final class PlayerUtil { if (AllZone.getHumanPlayer().getZone(ZoneType.Hand).size() == 0) { this.stop(); } - Singletons.getControl().getControlMatch().showMessage( + CMatchUI.SINGLETON_INSTANCE.showMessage( "Select " + (nCards - this.n) + " cards to discard, unless you discard a " + uType + "."); ButtonUtil.disableAll(); } @@ -151,7 +152,7 @@ public final class PlayerUtil { this.stop(); } - Singletons.getControl().getControlMatch().showMessage("Select a card to discard"); + CMatchUI.SINGLETON_INSTANCE.showMessage("Select a card to discard"); ButtonUtil.disableAll(); } @@ -190,7 +191,7 @@ public final class PlayerUtil { this.stop(); } - Singletons.getControl().getControlMatch().showMessage("Chains of Mephistopheles:\n" + "Select a card to discard"); + CMatchUI.SINGLETON_INSTANCE.showMessage("Chains of Mephistopheles:\n" + "Select a card to discard"); ButtonUtil.disableAll(); } @@ -288,7 +289,7 @@ public final class PlayerUtil { return; } - Singletons.getControl().getControlMatch().showMessage(message + " (" + (nCards - this.n) + " left)"); + CMatchUI.SINGLETON_INSTANCE.showMessage(message + " (" + (nCards - this.n) + " left)"); ButtonUtil.disableAll(); } @@ -331,7 +332,7 @@ public final class PlayerUtil { @Override public void showMessage() { - Singletons.getControl().getControlMatch().showMessage("Select a card to put on the " + topOrBottom + " of your library."); + CMatchUI.SINGLETON_INSTANCE.showMessage("Select a card to put on the " + topOrBottom + " of your library."); ButtonUtil.disableAll(); if ((this.n == num) || (AllZone.getHumanPlayer().getZone(ZoneType.Hand).size() == 0)) { diff --git a/src/main/java/forge/game/zone/MagicStack.java b/src/main/java/forge/game/zone/MagicStack.java index a25bbc26e01..c2e7632f7e3 100644 --- a/src/main/java/forge/game/zone/MagicStack.java +++ b/src/main/java/forge/game/zone/MagicStack.java @@ -57,6 +57,7 @@ import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.gui.GuiDisplayUtil; import forge.gui.GuiUtils; +import forge.gui.match.CMatchUI; import forge.view.ButtonUtil; /** @@ -761,7 +762,7 @@ public class MagicStack extends MyObservable { @Override public void showMessage() { - Singletons.getControl().getControlMatch().showMessage("Mana Vortex - select a land to sacrifice"); + CMatchUI.SINGLETON_INSTANCE.showMessage("Mana Vortex - select a land to sacrifice"); ButtonUtil.enableOnlyCancel(); } @@ -953,7 +954,7 @@ public class MagicStack extends MyObservable { @Override public void showMessage() { - Singletons.getControl().getControlMatch().showMessage("Choose target creature to haunt."); + CMatchUI.SINGLETON_INSTANCE.showMessage("Choose target creature to haunt."); ButtonUtil.disableAll(); } @@ -967,7 +968,7 @@ public class MagicStack extends MyObservable { MagicStack.this.add(haunterDiesWork); this.stop(); } else { - Singletons.getControl().getControlMatch().showMessage("Cannot target this card (Shroud? Protection?)."); + CMatchUI.SINGLETON_INSTANCE.showMessage("Cannot target this card (Shroud? Protection?)."); } } }; diff --git a/src/main/java/forge/gui/GuiDisplayUtil.java b/src/main/java/forge/gui/GuiDisplayUtil.java index 78a2f97f10a..ef9a66cb55e 100644 --- a/src/main/java/forge/gui/GuiDisplayUtil.java +++ b/src/main/java/forge/gui/GuiDisplayUtil.java @@ -327,7 +327,7 @@ public final class GuiDisplayUtil { public static void updateGUI() { AllZone.getComputerPlayer().getZone(ZoneType.Battlefield).updateObservers(); AllZone.getHumanPlayer().getZone(ZoneType.Battlefield).updateObservers(); - //AllZone.getHumanPlayer().getZone(Zone.Hand).updateObservers(); + //AllZone.getHumanPlayer().getZone(ZoneType.Hand).updateObservers(); AllZone.getComputerPlayer().updateObservers(); AllZone.getHumanPlayer().updateObservers(); } diff --git a/src/main/java/forge/gui/GuiInput.java b/src/main/java/forge/gui/GuiInput.java index 82020709aae..c4a19cc149b 100644 --- a/src/main/java/forge/gui/GuiInput.java +++ b/src/main/java/forge/gui/GuiInput.java @@ -133,11 +133,7 @@ public class GuiInput extends MyObservable implements Observer { return this.getInput().toString(); } - /** - * Gets the input. - * - * @return the input - */ + /** @return {@link forge.gui.GuiInput.Input} */ public Input getInput() { return this.input; } diff --git a/src/main/java/forge/gui/GuiMultipleBlockers.java b/src/main/java/forge/gui/GuiMultipleBlockers.java index 3bc4938242a..cc838035423 100644 --- a/src/main/java/forge/gui/GuiMultipleBlockers.java +++ b/src/main/java/forge/gui/GuiMultipleBlockers.java @@ -32,8 +32,8 @@ import javax.swing.SwingConstants; import forge.AllZone; import forge.Card; import forge.CardList; -import forge.Singletons; import forge.error.ErrorViewer; +import forge.gui.match.CMatchUI; /** *

Constructor for Gui_MultipleBlockers4.

@@ -241,7 +241,7 @@ public class GuiMultipleBlockers extends JFrame { final CardContainer cardPanel = (CardContainer) o; final Card c = cardPanel.getCard(); - Singletons.getControl().getControlMatch().setCard(c); + CMatchUI.SINGLETON_INSTANCE.setCard(c); } } } diff --git a/src/main/java/forge/gui/GuiUtils.java b/src/main/java/forge/gui/GuiUtils.java index 68312c69e0a..5fc5433d070 100644 --- a/src/main/java/forge/gui/GuiUtils.java +++ b/src/main/java/forge/gui/GuiUtils.java @@ -39,7 +39,7 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import forge.Card; -import forge.Singletons; +import forge.gui.match.CMatchUI; import forge.properties.ForgeProps; import forge.properties.NewConstants; @@ -343,7 +343,7 @@ public final class GuiUtils { @Override public void valueChanged(final ListSelectionEvent ev) { if (list.getSelectedValue() instanceof Card) { - Singletons.getControl().getControlMatch().setCard((Card) list.getSelectedValue()); + CMatchUI.SINGLETON_INSTANCE.setCard((Card) list.getSelectedValue()); } } }); diff --git a/src/main/java/forge/gui/layout/DragCell.java b/src/main/java/forge/gui/framework/DragCell.java similarity index 83% rename from src/main/java/forge/gui/layout/DragCell.java rename to src/main/java/forge/gui/framework/DragCell.java index 3b2b9cf5f7f..71a67da3d6a 100644 --- a/src/main/java/forge/gui/layout/DragCell.java +++ b/src/main/java/forge/gui/framework/DragCell.java @@ -1,6 +1,5 @@ -package forge.gui.layout; +package forge.gui.framework; -import java.awt.CardLayout; import java.awt.Color; import java.awt.Cursor; import java.awt.Dimension; @@ -17,6 +16,7 @@ import javax.swing.JPanel; import javax.swing.SwingConstants; import net.miginfocom.swing.MigLayout; +import forge.gui.toolbox.FPanel; import forge.gui.toolbox.FSkin; /** @@ -26,7 +26,7 @@ import forge.gui.toolbox.FSkin; * for resizing. */ @SuppressWarnings("serial") -final class DragCell extends JPanel implements ILocalRepaint { +public final class DragCell extends JPanel implements ILocalRepaint { // Layout creation worker vars private double roughX = 0; private double roughY = 0; @@ -38,9 +38,8 @@ final class DragCell extends JPanel implements ILocalRepaint { private int smoothH = 0; // Core layout stuff - private final CardLayout cards = new CardLayout(); private final JPanel pnlHead = new JPanel(new MigLayout("insets 0, gap 0, hidemode 3")); - private final JPanel pnlBody = new JPanel(cards); + private final JPanel pnlBody = new FPanel(); private final JPanel pnlBorderRight = new JPanel(); private final JPanel pnlBorderBottom = new JPanel(); private final int tabPaddingPx = 2; @@ -58,18 +57,19 @@ final class DragCell extends JPanel implements ILocalRepaint { public DragCell() { super(new MigLayout("insets 0, gap 0, wrap 2")); - this.add(pnlHead, "w 100% - " + FViewNew.BORDER_T + "px!, " - + "h " + FViewNew.HEAD_H + "px!"); - this.add(pnlBorderRight, "w " + FViewNew.BORDER_T + "px!, " - + "h 100% - " + FViewNew.BORDER_T + "px!, span 1 2"); - this.add(pnlBody, "w 100% - " + FViewNew.BORDER_T + "px!, " - + "h 100% - " + (FViewNew.HEAD_H + FViewNew.BORDER_T) + "px!"); - this.add(pnlBorderBottom, "w 100% - " + FViewNew.BORDER_T + "px!, " - + "h " + FViewNew.BORDER_T + "px!"); + this.add(pnlHead, "w 100% - " + SLayoutConstants.BORDER_T + "px!, " + + "h " + SLayoutConstants.HEAD_H + "px!"); + this.add(pnlBorderRight, "w " + SLayoutConstants.BORDER_T + "px!, " + + "h 100% - " + SLayoutConstants.BORDER_T + "px!, span 1 2"); + this.add(pnlBody, "w 100% - " + SLayoutConstants.BORDER_T + "px!, " + + "h 100% - " + (SLayoutConstants.HEAD_H + SLayoutConstants.BORDER_T) + "px!"); + this.add(pnlBorderBottom, "w 100% - " + SLayoutConstants.BORDER_T + "px!, " + + "h " + SLayoutConstants.BORDER_T + "px!"); + + this.setOpaque(false); + pnlHead.setOpaque(false); - this.setBackground(Color.black); pnlHead.setBackground(Color.DARK_GRAY); - pnlBody.setBackground(Color.LIGHT_GRAY); lblOverflow.setForeground(Color.white); lblOverflow.setHorizontalAlignment(SwingConstants.CENTER); @@ -117,7 +117,7 @@ final class DragCell extends JPanel implements ILocalRepaint { /** * Returns a defensive copy list of all documents in this cell. - * @return {@link java.util.List}<{@link forge.gui.layout.IVDoc}> + * @return {@link java.util.List}<{@link forge.gui.framework.IVDoc}> */ public List getDocs() { final List clone = new ArrayList(); @@ -237,11 +237,11 @@ final class DragCell extends JPanel implements ILocalRepaint { this.smoothH = h0; } - /** Adds a document to the layout and tabs. - * @param doc0   {@link forge.gui.layout.IVDoc} */ + /** Adds a document to the tabs. + * @param doc0   {@link forge.gui.framework.IVDoc} */ public void addDoc(final IVDoc doc0) { - pnlBody.add(doc0.getDocumentID().toString(), doc0.getDocument()); allDocs.add(doc0); + doc0.setParentCell(this); pnlHead.add(doc0.getTabLabel(), "h 100%!, gap " + tabPaddingPx + "px " + tabPaddingPx + "px 0 0", allDocs.size() - 1); // Ensure that a tab is selected @@ -249,44 +249,52 @@ final class DragCell extends JPanel implements ILocalRepaint { } /** Removes a document from the layout and tabs. - * @param doc0   {@link forge.gui.layout.IVDoc} */ + * @param doc0   {@link forge.gui.framework.IVDoc} */ public void removeDoc(final IVDoc doc0) { - pnlBody.remove(doc0.getDocument()); allDocs.remove(doc0); pnlHead.remove(doc0.getTabLabel()); } - /** Deselects previous selection, if exists, and then - * selects a tab in the title bar.

null will reset + /** - Deselects previous selection, if there is one
+ * - Decrements the priorities of all other tabs
+ * - Sets selected as priority 1
+ * + *
null will reset * (deselect all tabs, and then select the first in the group). + * *

Unless there are no tab docs in this cell, there * will always be a selection. * - * @param doc0   {@link forge.gui.layout.IVDoc} tab document. + * @param doc0   {@link forge.gui.framework.IVDoc} tab document. */ public void setSelected(final IVDoc doc0) { docSelected = null; + pnlBody.removeAll(); // Priorities are used to "remember" tab selection history. - for (final IVDoc t : allDocs) { - if (t.equals(doc0)) { + for (final IVDoc doc : allDocs) { + if (doc.equals(doc0)) { docSelected = doc0; - t.getTabLabel().priorityOne(); - docSelected.getTabLabel().setSelected(true); - cards.show(pnlBody, docSelected.getDocumentID().toString()); + doc.getTabLabel().priorityOne(); + doc.getTabLabel().setSelected(true); + doc.populate(); + doc.getControl().update(); } else { - t.getTabLabel().setSelected(false); - t.getTabLabel().priorityDecrease(); + doc.getTabLabel().setSelected(false); + doc.getTabLabel().priorityDecrease(); } } + pnlBody.revalidate(); + pnlBody.repaint(); + // Reached the end without a selection? Select the first in the group. if (docSelected == null && allDocs.size() > 0) { setSelected(allDocs.get(0)); } } /** Returns currently selected document in this cell. - * @return {@link forge.gui.layout.IVDoc} */ + * @return {@link forge.gui.framework.IVDoc} */ public IVDoc getSelected() { return docSelected; } diff --git a/src/main/java/forge/gui/layout/DragTab.java b/src/main/java/forge/gui/framework/DragTab.java similarity index 84% rename from src/main/java/forge/gui/layout/DragTab.java rename to src/main/java/forge/gui/framework/DragTab.java index 48679043210..0691bc84b4c 100644 --- a/src/main/java/forge/gui/layout/DragTab.java +++ b/src/main/java/forge/gui/framework/DragTab.java @@ -1,12 +1,13 @@ -package forge.gui.layout; +package forge.gui.framework; -import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import javax.swing.JLabel; import javax.swing.border.EmptyBorder; +import forge.gui.toolbox.FSkin; + /** * The tab label object in drag layout. * No modification should be necessary to this object. @@ -68,15 +69,15 @@ public final class DragTab extends JLabel implements ILocalRepaint { @Override public void paintComponent(final Graphics g) { if (!selected) { - g.setColor(Color.white); + g.setColor(FSkin.getColor(FSkin.Colors.CLR_BORDERS)); g.fillRoundRect(0, 0, getWidth() - 1, getHeight() * 2, 6, 6); - g.setColor(Color.LIGHT_GRAY); + g.setColor(FSkin.getColor(FSkin.Colors.CLR_INACTIVE)); g.drawRoundRect(0, 0, getWidth() - 1, getHeight() * 2, 6, 6); } else { - g.setColor(Color.orange); + g.setColor(FSkin.getColor(FSkin.Colors.CLR_ACTIVE)); g.fillRoundRect(0, 0, getWidth() - 1, getHeight() * 2, 6, 6); - g.setColor(Color.red); + g.setColor(FSkin.getColor(FSkin.Colors.CLR_BORDERS)); g.drawRoundRect(0, 0, getWidth() - 1, getHeight() * 2, 6, 6); } diff --git a/src/main/java/forge/gui/layout/EDocID.java b/src/main/java/forge/gui/framework/EDocID.java similarity index 53% rename from src/main/java/forge/gui/layout/EDocID.java rename to src/main/java/forge/gui/framework/EDocID.java index 8f6f5b9cb6e..3e68ad6de2e 100644 --- a/src/main/java/forge/gui/layout/EDocID.java +++ b/src/main/java/forge/gui/framework/EDocID.java @@ -1,13 +1,12 @@ /** * */ -package forge.gui.layout; +package forge.gui.framework; -import forge.gui.match.nonsingleton.VField; -import forge.gui.match.nonsingleton.VHand; import forge.gui.match.views.VAntes; import forge.gui.match.views.VCombat; import forge.gui.match.views.VDetail; +import forge.gui.match.views.VDev; import forge.gui.match.views.VDock; import forge.gui.match.views.VLog; import forge.gui.match.views.VMessage; @@ -15,10 +14,8 @@ import forge.gui.match.views.VPicture; import forge.gui.match.views.VPlayers; import forge.gui.match.views.VStack; - - /** - * These are the identifiers for tabs found in the Drag3 layout. + * These are the identifiers for tabs found in the drag layout. * These IDs are used in the save XML and card layouts. * *

(E at beginning of class name denotes an enum.) @@ -34,17 +31,17 @@ public enum EDocID { /** */ REPORT_LOG (VLog.SINGLETON_INSTANCE), /** */ REPORT_PLAYERS (VPlayers.SINGLETON_INSTANCE), /** */ - // Current user's panels - YOUR_HAND (VHand.SINGLETON_INSTANCE), /** */ - YOUR_BATTLEFIELD (VField.SINGLETON_INSTANCE), /** */ - YOUR_DOCK (VDock.SINGLETON_INSTANCE), /** */ + DEV_MODE (VDev.SINGLETON_INSTANCE), /** */ + BUTTON_DOCK (VDock.SINGLETON_INSTANCE), /** */ - // Non-user battlefields (AI or teammate), use setDoc to activate. - BATTLEFIELD_1 (null), /** */ - BATTLEFIELD_2 (null), /** */ - BATTLEFIELD_3 (null), /** */ + // Non-user battlefields (AI or teammate), use setDoc to register. + FIELD_0 (null), /** */ + FIELD_1 (null), /** */ + FIELD_2 (null), /** */ + FIELD_3 (null), /** */ - // Non-user hands (AI or teammate), use setDoc to activate. + // Non-user hands (AI or teammate), use setDoc to register. + HAND_0 (null), /** */ HAND_1 (null), /** */ HAND_2 (null), /** */ HAND_3 (null); /** */ @@ -52,23 +49,19 @@ public enum EDocID { /** */ // End enum declarations, start enum methods. private IVDoc vDoc; - /** @param doc0   {@link forge.gui.layout.IVDoc} */ + /** @param doc0   {@link forge.gui.framework.IVDoc} */ EDocID(final IVDoc doc0) { this.vDoc = doc0; } - /** @return {@link forge.gui.layout.IVDoc} */ - public IVDoc getDoc() { - return vDoc; + /** @param doc0   {@link forge.gui.framework.IVDoc} */ + public void setDoc(final IVDoc doc0) { + this.vDoc = doc0; } - /** - * Register non-singleton tab instances using this method. - * - * @param id0   {@link forge.gui.layout.EDocID} - * @param doc0   {@link forge.gui.layout.IVDoc} - */ - public void setDoc(EDocID id0, IVDoc doc0) { - id0.vDoc = doc0; + /** @return {@link forge.gui.framework.IVDoc} */ + public IVDoc getDoc() { + if (vDoc == null) { throw new NullPointerException("No document found!"); } + return vDoc; } } diff --git a/src/main/java/forge/gui/layout/ICDoc.java b/src/main/java/forge/gui/framework/ICDoc.java similarity index 65% rename from src/main/java/forge/gui/layout/ICDoc.java rename to src/main/java/forge/gui/framework/ICDoc.java index 67580d1b863..9dc42a9c282 100644 --- a/src/main/java/forge/gui/layout/ICDoc.java +++ b/src/main/java/forge/gui/framework/ICDoc.java @@ -1,10 +1,10 @@ -package forge.gui.layout; +package forge.gui.framework; import forge.Command; /** * Dictates methods required for any controller - * of an {@link forge.gui.layout.IVDoc}. + * of an {@link forge.gui.framework.IVDoc}. * *

(I at beginning of class name denotes an interface.) *
(C at beginning of class name denotes a controller class.) @@ -14,14 +14,17 @@ public interface ICDoc { * Fires when this controller's view tab is selected. * Since this method is fired when all tabs are first * initialized, be wary of NPEs created by referring to - * non-existing components. + * non-existent components. * * @return {@link forge.Command} */ Command getCommandOnSelect(); /** * Call this method after the view singleton has been fully realized - * for the first time. This method should ideally only be called once. + * for the first time. It should execute operations which should only + * be done once, but require non-null view components.

+ * + * This method should only be called once, in FView, after singletons are populated. */ void initialize(); diff --git a/src/main/java/forge/gui/layout/IDocIdList.java b/src/main/java/forge/gui/framework/IDocIdList.java similarity index 85% rename from src/main/java/forge/gui/layout/IDocIdList.java rename to src/main/java/forge/gui/framework/IDocIdList.java index 91785bd3035..80f862d0461 100644 --- a/src/main/java/forge/gui/layout/IDocIdList.java +++ b/src/main/java/forge/gui/framework/IDocIdList.java @@ -1,7 +1,7 @@ /** * */ -package forge.gui.layout; +package forge.gui.framework; /** * This interface provides a unifying type to all enums diff --git a/src/main/java/forge/gui/layout/ILocalRepaint.java b/src/main/java/forge/gui/framework/ILocalRepaint.java similarity index 88% rename from src/main/java/forge/gui/layout/ILocalRepaint.java rename to src/main/java/forge/gui/framework/ILocalRepaint.java index 6355f746f86..e58103602fe 100644 --- a/src/main/java/forge/gui/layout/ILocalRepaint.java +++ b/src/main/java/forge/gui/framework/ILocalRepaint.java @@ -1,4 +1,4 @@ -package forge.gui.layout; +package forge.gui.framework; /** * This interface requires a repaintThis() method, which diff --git a/src/main/java/forge/gui/framework/IVDoc.java b/src/main/java/forge/gui/framework/IVDoc.java new file mode 100644 index 00000000000..fec4ee85f2b --- /dev/null +++ b/src/main/java/forge/gui/framework/IVDoc.java @@ -0,0 +1,62 @@ +package forge.gui.framework; + + + +/** + * This interface provides a unifying type to any component + * (usually JPanels or JScrollPanes) which could be used as + * a tab. A single one of these components is referred to as + * a "document" throughout the codebase. The tabs and their + * documents are contained in "cells" for resizing and dragging. + * + *

(I at beginning of class name denotes an interface.) + *
(V at beginning of class name denotes a view class.) + */ +public interface IVDoc { + /** + * Returns the ID used to identify this tab in save XML and card layouts. + * + * @return {@link forge.gui.framework.EDocID} + */ + EDocID getDocumentID(); + + /** + * Returns tab label object used in title bars. + * + * @return {@link forge.gui.framework.DragTab} + */ + DragTab getTabLabel(); + + /** Retrieves control object associated with this document. + * @return {@link forge.gui.home.ICSubmenu} + */ + ICDoc getControl(); + + /** Sets the current parent cell of this view, + * allowing access to its body and head sections. + * + * @param cell0   {@link forge.gui.framework.DragCell} + */ + void setParentCell(DragCell cell0); + + /** + * Gets parent cell for this view. + * + * @return {@link forge.gui.framework.DragCell} + */ + DragCell getParentCell(); + + /** + * Targets the drag cell body (use parentCell.getBody()). + * Populates panel components, independent of constructor. + * Expected to provide a completely fresh layout to the body panel. + *

+ * Styling and adding of lower-level components for this view + * should happen once, in constructor. This method is + * only for removing / adding top-level components. + *

+ * The body panel will be empty when this method is called. + * However, its layout may need to be redefined as required. + */ + void populate(); +} diff --git a/src/main/java/forge/gui/framework/IVTopLevelUI.java b/src/main/java/forge/gui/framework/IVTopLevelUI.java new file mode 100644 index 00000000000..651de1ef11b --- /dev/null +++ b/src/main/java/forge/gui/framework/IVTopLevelUI.java @@ -0,0 +1,23 @@ +package forge.gui.framework; + +/** + * This interface provides a unifying type for all top-level + * UI components. + * + *

(I at beginning of class name denotes an interface.) + *
(V at beginning of class name denotes a view class.) + * + */ +public interface IVTopLevelUI { + /** Called during the preload sequence, this method caches + * all of the children singletons and instances. */ + void instantiate(); + + /** + * Removes all children and (re)populates top level content, + * independent of constructor. Expected to provide + * a completely fresh layout on the component. + * + */ + void populate(); +} diff --git a/src/main/java/forge/gui/framework/SDisplayUtil.java b/src/main/java/forge/gui/framework/SDisplayUtil.java new file mode 100644 index 00000000000..5d54fbf8282 --- /dev/null +++ b/src/main/java/forge/gui/framework/SDisplayUtil.java @@ -0,0 +1,87 @@ +package forge.gui.framework; + +import java.awt.Color; +import java.util.Timer; +import java.util.TimerTask; + +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +/** + * Experimental static factory for generic operations carried out + * onto specific members of the framework. Doublestrike 11-04-12 + * + *

(S at beginning of class name denotes a static factory.) + */ +public class SDisplayUtil { + private static boolean remindIsRunning = false; + private static int counter = 0; + private static int[] newA = null, newR = null, newG = null, newB = null; + private static Timer timer1 = null; + + /** Flashes animation on input panel if play is currently waiting on input. + * + * @param tab0   {@link java.gui.framework.IVDoc} + */ + public static void remind(final IVDoc tab0) { + showTab(tab0); + final JPanel pnl = tab0.getParentCell().getBody(); + + // To adjust, only touch these two values. + final int steps = 5; // Number of delays + final int delay = 80; // Milliseconds between steps + + if (remindIsRunning) { return; } + if (pnl.equals(null)) { return; } + + remindIsRunning = true; + final int oldR = pnl.getBackground().getRed(); + final int oldG = pnl.getBackground().getGreen(); + final int oldB = pnl.getBackground().getBlue(); + final int oldA = pnl.getBackground().getAlpha(); + counter = 0; + newR = new int[steps]; + newG = new int[steps]; + newB = new int[steps]; + newA = new int[steps]; + + for (int i = 0; i < steps; i++) { + newR[i] = (int) ((255 - oldR) / steps * i); + newG[i] = (int) (oldG / steps * i); + newB[i] = (int) (oldB / steps * i); + newA[i] = (int) ((255 - oldA) / steps * i); + } + + final TimerTask tt = new TimerTask() { + @Override + public void run() { + counter++; + if (counter != (steps - 1)) { + SwingUtilities.invokeLater(new Runnable() { @Override + public void run() { + pnl.setBackground(new Color(newR[counter], oldG, oldB, newA[counter])); + } + }); + } + else { + SwingUtilities.invokeLater(new Runnable() { @Override + public void run() { pnl.setBackground(new Color(oldR, oldG, oldB, oldA)); } }); + remindIsRunning = false; + timer1.cancel(); + newR = null; + newG = null; + newB = null; + newA = null; + } + } + }; + + timer1 = new Timer(); + timer1.scheduleAtFixedRate(tt, 0, delay); + } + + /** @param tab0   {@link java.gui.framework.IVDoc} */ + public static void showTab(final IVDoc tab0) { + tab0.getParentCell().setSelected(tab0); + } +} diff --git a/src/main/java/forge/gui/framework/SIOUtil.java b/src/main/java/forge/gui/framework/SIOUtil.java new file mode 100644 index 00000000000..0a392a19b85 --- /dev/null +++ b/src/main/java/forge/gui/framework/SIOUtil.java @@ -0,0 +1,173 @@ +package forge.gui.framework; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.util.Iterator; +import java.util.List; + +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +import javax.xml.stream.XMLEventFactory; +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.XMLEventWriter; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.events.Attribute; +import javax.xml.stream.events.StartElement; +import javax.xml.stream.events.XMLEvent; + +import forge.view.FView; + + +/** Package-private class for handling layout saving and loading. */ +public final class SIOUtil { + /** Each cell must save these elements of its display. */ + private enum Property { + x, + y, + w, + h, + doc + }; + + private static final String FILE_DEFAULT = "res/layouts/match_default.xml"; + private static final String FILE_PREFERRED = "res/layouts/match_preferred.xml"; + private static final XMLEventFactory EF = XMLEventFactory.newInstance(); + private static final XMLEvent NEWLINE = EF.createDTD("\n"); + private static final XMLEvent TAB = EF.createDTD("\t"); + + /** Publicly-accessible save method, to neatly handle exception handling. */ + public static void saveLayout() { + if (SwingUtilities.isEventDispatchThread()) { + throw new IllegalThreadStateException("This operation should be independent of the EDT."); + } + + try { save(); } + catch (final Exception e) { e.printStackTrace(); } + } + + /** Publicly-accessible load method, to neatly handle exception handling. */ + public static void loadLayout() { + if (SwingUtilities.isEventDispatchThread()) { + throw new IllegalThreadStateException("This operation should be independent of the EDT."); + } + + try { load(); } + catch (final Exception e) { e.printStackTrace(); } + } + + private static void save() throws Exception { + final XMLOutputFactory out = XMLOutputFactory.newInstance(); + final XMLEventWriter writer = out.createXMLEventWriter(new FileOutputStream(FILE_PREFERRED)); + final List cells = FView.SINGLETON_INSTANCE.getDragCells(); + final JPanel pnl = FView.SINGLETON_INSTANCE.getPnlContent(); + double x0, y0, w0, h0; + + writer.add(EF.createStartDocument()); + writer.add(NEWLINE); + writer.add(EF.createStartElement("", "", "layout")); + writer.add(NEWLINE); + + for (final DragCell cell : cells) { + x0 = ((double) Math.round(((double) cell.getX() / (double) pnl.getWidth()) * 1000)) / 1000; + y0 = ((double) Math.round(((double) cell.getY() / (double) pnl.getHeight()) * 1000)) / 1000; + w0 = ((double) Math.round(((double) cell.getW() / (double) pnl.getWidth()) * 1000)) / 1000; + h0 = ((double) Math.round(((double) cell.getH() / (double) pnl.getHeight()) * 1000)) / 1000; + + //cell.setRoughBounds(x, y, w, h); + + writer.add(TAB); + writer.add(EF.createStartElement("", "", "cell")); + writer.add(EF.createAttribute(Property.x.toString(), String.valueOf(x0))); + writer.add(EF.createAttribute(Property.y.toString(), String.valueOf(y0))); + writer.add(EF.createAttribute(Property.w.toString(), String.valueOf(w0))); + writer.add(EF.createAttribute(Property.h.toString(), String.valueOf(h0))); + writer.add(NEWLINE); + + for (final IVDoc vDoc : cell.getDocs()) { + createNode(writer, Property.doc, vDoc.getDocumentID().toString()); + } + + writer.add(TAB); + writer.add(EF.createEndElement("", "", "cell")); + writer.add(NEWLINE); + } + + writer.add(EF.createEndDocument()); + writer.flush(); + writer.close(); + } + + private static void load() throws Exception { + final FView view = FView.SINGLETON_INSTANCE; + final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + + final XMLEventReader reader; + if (new File(FILE_PREFERRED).exists()) { + reader = inputFactory.createXMLEventReader(new FileInputStream(FILE_PREFERRED)); + } + else { + reader = inputFactory.createXMLEventReader(new FileInputStream(FILE_DEFAULT)); + } + + view.removeAllDragCells(); + XMLEvent event; + StartElement element; + Iterator attributes; + Attribute attribute; + DragCell cell = null; + double x0 = 0, y0 = 0, w0 = 0, h0 = 0; + + while (reader.hasNext()) { + event = reader.nextEvent(); + + if (event.isStartElement()) { + //&& event.asStartElement().getName().getLocalPart().equals("cell")) { + element = event.asStartElement(); + + if (element.getName().getLocalPart().equals("cell")) { + attributes = element.getAttributes(); + while (attributes.hasNext()) { + attribute = (Attribute) attributes.next(); + if (attribute.getName().toString().equals(Property.x.toString())) { + x0 = Double.valueOf(attribute.getValue()); + } + else if (attribute.getName().toString().equals(Property.y.toString())) { + y0 = Double.valueOf(attribute.getValue()); + } + else if (attribute.getName().toString().equals(Property.w.toString())) { + w0 = Double.valueOf(attribute.getValue()); + } + else if (attribute.getName().toString().equals(Property.h.toString())) { + h0 = Double.valueOf(attribute.getValue()); + } + } + + cell = new DragCell(); + cell.setRoughBounds(x0, y0, w0, h0); + FView.SINGLETON_INSTANCE.addDragCell(cell); + } + else if (element.getName().getLocalPart().equals("doc")) { + event = reader.nextEvent(); + cell.addDoc(EDocID.valueOf(event.asCharacters().getData()).getDoc()); + } + } + } + + // Rough bounds are all in place; resize the window. + SResizingUtil.resizeWindow(); + } + + private static void createNode(final XMLEventWriter writer0, final Property name0, + final String val0) throws XMLStreamException { + + writer0.add(TAB); + writer0.add(TAB); + writer0.add(EF.createStartElement("", "", name0.toString())); + writer0.add(EF.createCharacters(val0)); + writer0.add(EF.createEndElement("", "", name0.toString())); + writer0.add(NEWLINE); + } +} diff --git a/src/main/java/forge/gui/framework/SLayoutConstants.java b/src/main/java/forge/gui/framework/SLayoutConstants.java new file mode 100644 index 00000000000..32c2c99835c --- /dev/null +++ b/src/main/java/forge/gui/framework/SLayoutConstants.java @@ -0,0 +1,14 @@ +package forge.gui.framework; + +/** + * Holds static constants used throughout layout. + * + *

(S at beginning of class name denotes a static factory.) + */ +public class SLayoutConstants { + /** Height of head area in drag panel. */ + public static final int HEAD_H = 20; + + /** Thickness of resize border in drag panel. */ + public static final int BORDER_T = 5; +} diff --git a/src/main/java/forge/gui/layout/SOverflowUtil.java b/src/main/java/forge/gui/framework/SOverflowUtil.java similarity index 85% rename from src/main/java/forge/gui/layout/SOverflowUtil.java rename to src/main/java/forge/gui/framework/SOverflowUtil.java index 6a8c3bb1bc8..7f3c1f98254 100644 --- a/src/main/java/forge/gui/layout/SOverflowUtil.java +++ b/src/main/java/forge/gui/framework/SOverflowUtil.java @@ -1,4 +1,4 @@ -package forge.gui.layout; +package forge.gui.framework; import java.awt.Color; import java.awt.Dimension; @@ -9,19 +9,21 @@ import java.awt.event.MouseListener; import javax.swing.JLabel; import javax.swing.JPanel; +import forge.view.FView; + /** * Package-private utilities for generic overflow behavior * in title bar for any cell in layout. * *

(S at beginning of class name denotes a static factory.) */ -final class SOverflowUtil { +public final class SOverflowUtil { private static final MouseListener MAD_OVERFLOW_SELECT = new MouseAdapter() { @Override public void mouseReleased(final MouseEvent e) { final JLabel src = ((JLabel) e.getSource()); final DragCell pnlParent = ((DragCell) src.getParent().getParent()); - final JPanel pnlOverflow = FViewNew.SINGLETON_INSTANCE.getPnlTabOverflow(); + final JPanel pnlOverflow = FView.SINGLETON_INSTANCE.getPnlTabOverflow(); final String constraints = "w 150px!, h 20px!, gap 5px 5px 2px 2px"; final int w = 160; int h = 0; @@ -36,11 +38,11 @@ final class SOverflowUtil { pnlOverflow.revalidate(); pnlOverflow.setVisible(true); - int x = src.getParent().getParent().getX() + src.getX() + FViewNew.BORDER_T; - final int y = src.getParent().getParent().getY() + src.getY() + FViewNew.BORDER_T + src.getHeight() + 3; + int x = src.getParent().getParent().getX() + src.getX() + SLayoutConstants.BORDER_T; + final int y = src.getParent().getParent().getY() + src.getY() + SLayoutConstants.BORDER_T + src.getHeight() + 3; // If overflow will appear offscreen, offset. - if (x + w > FViewNew.SINGLETON_INSTANCE.getPnlContent().getWidth()) { + if (x + w > FView.SINGLETON_INSTANCE.getPnlContent().getWidth()) { x += src.getWidth() - w; } @@ -64,7 +66,7 @@ final class SOverflowUtil { private static final MouseListener MAD_HIDE_OVERFLOW = new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { - final JPanel pnl = FViewNew.SINGLETON_INSTANCE.getPnlTabOverflow(); + final JPanel pnl = FView.SINGLETON_INSTANCE.getPnlTabOverflow(); if (pnl != null) { pnl.setVisible(pnl.isVisible() ? false : true); } @@ -103,7 +105,7 @@ final class SOverflowUtil { @Override public void mousePressed(final MouseEvent e) { - FViewNew.SINGLETON_INSTANCE.getPnlTabOverflow().setVisible(false); + FView.SINGLETON_INSTANCE.getPnlTabOverflow().setVisible(false); parent0.setSelected(tab0); parent0.refresh(); } diff --git a/src/main/java/forge/gui/layout/SRearrangingUtil.java b/src/main/java/forge/gui/framework/SRearrangingUtil.java similarity index 84% rename from src/main/java/forge/gui/layout/SRearrangingUtil.java rename to src/main/java/forge/gui/framework/SRearrangingUtil.java index c53c6c0a528..66305543eef 100644 --- a/src/main/java/forge/gui/layout/SRearrangingUtil.java +++ b/src/main/java/forge/gui/framework/SRearrangingUtil.java @@ -1,4 +1,4 @@ -package forge.gui.layout; +package forge.gui.framework; import java.awt.Container; import java.awt.Cursor; @@ -16,14 +16,15 @@ import javax.swing.JLayeredPane; import javax.swing.JPanel; import forge.gui.toolbox.FSkin; +import forge.view.FView; /** * Package-private utilities for rearranging drag behavior using - * the draggable panels registered in FViewNew. + * the draggable panels registered in FView. * *

(S at beginning of class name denotes a static factory.) */ -final class SRearrangingUtil { +public final class SRearrangingUtil { private enum Dropzone { BODY, @@ -42,8 +43,8 @@ final class SRearrangingUtil { private static int tempW; private static int tempH; - private static JPanel pnlPreview = FViewNew.SINGLETON_INSTANCE.getPnlPreview(); - private static JLayeredPane pnlDocument = FViewNew.SINGLETON_INSTANCE.getLpnDocument(); + private static JPanel pnlPreview = FView.SINGLETON_INSTANCE.getPnlPreview(); + private static JLayeredPane pnlDocument = FView.SINGLETON_INSTANCE.getLpnDocument(); private static DragCell cellTarget = null; private static DragCell cellSrc = null; private static DragCell cellNew = null; @@ -134,7 +135,7 @@ final class SRearrangingUtil { evtY = (int) e.getLocationOnScreen().getY(); // Find out over which panel the event occurred. - for (final DragCell t : FViewNew.SINGLETON_INSTANCE.getDragCells()) { + for (final DragCell t : FView.SINGLETON_INSTANCE.getDragCells()) { tempX = t.getAbsX(); tempY = t.getAbsY(); tempW = t.getW(); @@ -154,10 +155,10 @@ final class SRearrangingUtil { dropzone = Dropzone.LEFT; pnlDocument.setCursor(CUR_L); pnlPreview.setBounds( - cellTarget.getX() + FViewNew.BORDER_T, - cellTarget.getY() + FViewNew.BORDER_T, - (int) ((tempW - FViewNew.BORDER_T) / 2), - tempH - FViewNew.BORDER_T + cellTarget.getX() + SLayoutConstants.BORDER_T, + cellTarget.getY() + SLayoutConstants.BORDER_T, + (int) ((tempW - SLayoutConstants.BORDER_T) / 2), + tempH - SLayoutConstants.BORDER_T ); } @@ -169,20 +170,20 @@ final class SRearrangingUtil { pnlPreview.setBounds( cellTarget.getX() + cellTarget.getW() - tempW, - cellTarget.getY() + FViewNew.BORDER_T, + cellTarget.getY() + SLayoutConstants.BORDER_T, tempW, - tempH - FViewNew.BORDER_T + tempH - SLayoutConstants.BORDER_T ); } - else if (evtY < (tempY + nestingMargin + FViewNew.HEAD_H) && evtY > tempY + FViewNew.HEAD_H + else if (evtY < (tempY + nestingMargin + SLayoutConstants.HEAD_H) && evtY > tempY + SLayoutConstants.HEAD_H && (cellTarget.getH() / 2) > SResizingUtil.H_MIN) { dropzone = Dropzone.TOP; pnlDocument.setCursor(CUR_T); pnlPreview.setBounds( - cellTarget.getX() + FViewNew.BORDER_T, - cellTarget.getY() + FViewNew.BORDER_T, - tempW - FViewNew.BORDER_T, + cellTarget.getX() + SLayoutConstants.BORDER_T, + cellTarget.getY() + SLayoutConstants.BORDER_T, + tempW - SLayoutConstants.BORDER_T, (int) (tempH / 2) ); } @@ -193,9 +194,9 @@ final class SRearrangingUtil { tempH = (int) Math.round(cellTarget.getH() / 2); pnlPreview.setBounds( - cellTarget.getX() + FViewNew.BORDER_T, + cellTarget.getX() + SLayoutConstants.BORDER_T, cellTarget.getY() + cellTarget.getH() - tempH, - tempW - FViewNew.BORDER_T, + tempW - SLayoutConstants.BORDER_T, tempH ); } @@ -209,10 +210,10 @@ final class SRearrangingUtil { pnlDocument.setCursor(CUR_TAB); pnlPreview.setBounds( - cellTarget.getX() + FViewNew.BORDER_T, - cellTarget.getY() + FViewNew.BORDER_T, - tempW - FViewNew.BORDER_T, - tempH - FViewNew.BORDER_T + cellTarget.getX() + SLayoutConstants.BORDER_T, + cellTarget.getY() + SLayoutConstants.BORDER_T, + tempW - SLayoutConstants.BORDER_T, + tempH - SLayoutConstants.BORDER_T ); } } @@ -247,7 +248,7 @@ final class SRearrangingUtil { cellTarget.setBounds( tempX + cellNew.getW(), tempY, tempW - cellNew.getW(), tempH); - FViewNew.SINGLETON_INSTANCE.addDragCell(cellNew); + FView.SINGLETON_INSTANCE.addDragCell(cellNew); break; case RIGHT: cellTarget.setBounds( @@ -256,7 +257,7 @@ final class SRearrangingUtil { cellNew.setBounds( cellTarget.getX() + cellTarget.getW(), tempY , tempW - cellTarget.getW(), tempH); - FViewNew.SINGLETON_INSTANCE.addDragCell(cellNew); + FView.SINGLETON_INSTANCE.addDragCell(cellNew); break; case TOP: cellNew.setBounds( @@ -265,7 +266,7 @@ final class SRearrangingUtil { cellTarget.setBounds( tempX, tempY + cellNew.getH(), tempW, tempH - cellNew.getH()); - FViewNew.SINGLETON_INSTANCE.addDragCell(cellNew); + FView.SINGLETON_INSTANCE.addDragCell(cellNew); break; case BOTTOM: cellTarget.setBounds( @@ -275,7 +276,7 @@ final class SRearrangingUtil { cellNew.setBounds( tempX, cellTarget.getY() + cellTarget.getH(), tempW, tempH - cellTarget.getH()); - FViewNew.SINGLETON_INSTANCE.addDragCell(cellNew); + FView.SINGLETON_INSTANCE.addDragCell(cellNew); break; case BODY: cellNew = cellTarget; @@ -292,7 +293,7 @@ final class SRearrangingUtil { // Remove old cell if necessary if (cellSrc.getDocs().size() == 0) { fillGap(); - FViewNew.SINGLETON_INSTANCE.removeDragCell(cellSrc); + FView.SINGLETON_INSTANCE.removeDragCell(cellSrc); } cellSrc.setSelected(srcSelectedDoc); @@ -301,7 +302,10 @@ final class SRearrangingUtil { cellNew.validate(); cellNew.refresh(); updateBorders(); - SIOUtil.saveLayout(); + + final Thread t = new Thread() { @Override + public void run() { SIOUtil.saveLayout(); } }; + t.start(); } /** The gap created by displaced panels must be filled. @@ -324,7 +328,7 @@ final class SRearrangingUtil { foundT = false; foundB = false; // Look for matching panels to left of source, expand them to the right. - for (final DragCell cell : FViewNew.SINGLETON_INSTANCE.getDragCells()) { + for (final DragCell cell : FView.SINGLETON_INSTANCE.getDragCells()) { if (cell.getAbsX2() != srcX) { continue; } if (cell.getAbsY() == srcY) { @@ -349,7 +353,7 @@ final class SRearrangingUtil { foundT = false; foundB = false; // Look for matching panels to right of source, expand them to the left. - for (final DragCell cell : FViewNew.SINGLETON_INSTANCE.getDragCells()) { + for (final DragCell cell : FView.SINGLETON_INSTANCE.getDragCells()) { if (cell.getAbsX() != srcX2) { continue; } if (cell.getAbsY() == srcY) { @@ -374,7 +378,7 @@ final class SRearrangingUtil { foundL = false; foundR = false; // Look for matching panels below source, expand them upwards. - for (final DragCell cell : FViewNew.SINGLETON_INSTANCE.getDragCells()) { + for (final DragCell cell : FView.SINGLETON_INSTANCE.getDragCells()) { if (cell.getAbsY() != srcY2) { continue; } if (cell.getAbsX() == srcX) { @@ -399,7 +403,7 @@ final class SRearrangingUtil { foundL = false; foundR = false; // Look for matching panels above source, expand them downwards. - for (final DragCell cell : FViewNew.SINGLETON_INSTANCE.getDragCells()) { + for (final DragCell cell : FView.SINGLETON_INSTANCE.getDragCells()) { if (cell.getAbsY2() != srcY) { continue; } if (cell.getAbsX() == srcX) { @@ -426,8 +430,8 @@ final class SRearrangingUtil { /** Hides outer borders for components on edges, * preventing illegal resizing (and misleading cursor). */ public static void updateBorders() { - final List cells = FViewNew.SINGLETON_INSTANCE.getDragCells(); - final JPanel pnlContent = FViewNew.SINGLETON_INSTANCE.getPnlContent(); + final List cells = FView.SINGLETON_INSTANCE.getDragCells(); + final JPanel pnlContent = FView.SINGLETON_INSTANCE.getPnlContent(); for (final DragCell t : cells) { if (t.getAbsX2() == (pnlContent.getLocationOnScreen().getX() + pnlContent.getWidth())) { diff --git a/src/main/java/forge/gui/layout/SResizingUtil.java b/src/main/java/forge/gui/framework/SResizingUtil.java similarity index 87% rename from src/main/java/forge/gui/layout/SResizingUtil.java rename to src/main/java/forge/gui/framework/SResizingUtil.java index bbcf1cd7683..1ff77fa20d2 100644 --- a/src/main/java/forge/gui/layout/SResizingUtil.java +++ b/src/main/java/forge/gui/framework/SResizingUtil.java @@ -1,4 +1,4 @@ -package forge.gui.layout; +package forge.gui.framework; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; @@ -13,15 +13,16 @@ import java.util.Iterator; import java.util.List; import javax.swing.JPanel; -import javax.swing.SwingWorker; + +import forge.view.FView; /** * Package-private utilities for resizing drag behavior using - * the draggable panels registered in FViewNew. + * the draggable panels registered in FView. * *

(S at beginning of class name denotes a static factory.) */ -final class SResizingUtil { +public final class SResizingUtil { private static final List LEFT_PANELS = new ArrayList(); private static final List RIGHT_PANELS = new ArrayList(); private static final List TOP_PANELS = new ArrayList(); @@ -45,7 +46,7 @@ final class SResizingUtil { @Override public void mouseReleased(final MouseEvent e) { - SResizingUtil.endResizeX(); + SResizingUtil.endResize(); } }; @@ -57,7 +58,7 @@ final class SResizingUtil { @Override public void mouseReleased(final MouseEvent e) { - SResizingUtil.endResizeY(); + SResizingUtil.endResize(); } }; @@ -85,11 +86,11 @@ final class SResizingUtil { /** */ public static void resizeWindow() { - final List cells = FViewNew.SINGLETON_INSTANCE.getDragCells(); - final JPanel pnlContent = FViewNew.SINGLETON_INSTANCE.getPnlContent(); - final JPanel pnlInsets = FViewNew.SINGLETON_INSTANCE.getPnlInsets(); + final List cells = FView.SINGLETON_INSTANCE.getDragCells(); + final JPanel pnlContent = FView.SINGLETON_INSTANCE.getPnlContent(); + final JPanel pnlInsets = FView.SINGLETON_INSTANCE.getPnlInsets(); - pnlInsets.setBounds(FViewNew.SINGLETON_INSTANCE.getFrame().getContentPane().getBounds()); + pnlInsets.setBounds(FView.SINGLETON_INSTANCE.getFrame().getContentPane().getBounds()); pnlInsets.validate(); final int w = pnlContent.getWidth(); @@ -218,7 +219,7 @@ final class SResizingUtil { // Add all panels who share a left or right edge with the // same coordinate as the right edge of the source panel. - for (final DragCell t : FViewNew.SINGLETON_INSTANCE.getDragCells()) { + for (final DragCell t : FView.SINGLETON_INSTANCE.getDragCells()) { tempX = t.getAbsX(); tempX2 = t.getAbsX2(); @@ -283,7 +284,7 @@ final class SResizingUtil { // Add all panels who share a top or bottom edge with the // same coordinate as the bottom edge of the source panel. - for (final DragCell t : FViewNew.SINGLETON_INSTANCE.getDragCells()) { + for (final DragCell t : FView.SINGLETON_INSTANCE.getDragCells()) { tempY = t.getAbsY(); tempY2 = t.getAbsY2(); @@ -329,27 +330,10 @@ final class SResizingUtil { } /** */ - public static void endResizeX() { - final SwingWorker w = new SwingWorker() { - @Override - public Object doInBackground() { - SIOUtil.saveLayout(); - return null; - } - }; - w.execute(); - } - - /** */ - public static void endResizeY() { - final SwingWorker w = new SwingWorker() { - @Override - public Object doInBackground() { - SIOUtil.saveLayout(); - return null; - } - }; - w.execute(); + public static void endResize() { + final Thread t = new Thread() { @Override + public void run() { SIOUtil.saveLayout(); } }; + t.start(); } /** @return {@link java.awt.event.MouseListener} */ diff --git a/src/main/java/forge/gui/home/EMenuGroup.java b/src/main/java/forge/gui/home/EMenuGroup.java index 4b2c8f1d59c..0eb93acc806 100644 --- a/src/main/java/forge/gui/home/EMenuGroup.java +++ b/src/main/java/forge/gui/home/EMenuGroup.java @@ -4,6 +4,8 @@ package forge.gui.home; * Submenus each belong to a menu group, which * is used for several functions, such as expanding * and collapsing in the menu. + * + *

(E at beginning of class name denotes an enum.) */ public enum EMenuGroup { /** */ SANCTIONED ("Sanctioned Game Formats"), /** */ diff --git a/src/main/java/forge/gui/home/EMenuItem.java b/src/main/java/forge/gui/home/EMenuItem.java index 72b2d55acf8..c58250de5e5 100644 --- a/src/main/java/forge/gui/home/EMenuItem.java +++ b/src/main/java/forge/gui/home/EMenuItem.java @@ -1,7 +1,9 @@ package forge.gui.home; /** - * TODO: Write javadoc for this type. + * These are the identifiers for topics found in home screen submenus. + * + *

(E at beginning of class name denotes an enum.) * */ public enum EMenuItem { /** */ diff --git a/src/main/java/forge/gui/home/ICSubmenu.java b/src/main/java/forge/gui/home/ICSubmenu.java index c55fc64ca89..96fe1f6d5ec 100644 --- a/src/main/java/forge/gui/home/ICSubmenu.java +++ b/src/main/java/forge/gui/home/ICSubmenu.java @@ -2,12 +2,16 @@ package forge.gui.home; import forge.Command; - -/** Dictates methods required for a submenu controller. */ +/** + * Dictates methods required for a submenu controller. + * + *

(I at beginning of class name denotes an interface.) + *
(C at beginning of class name denotes a controller class.) + */ public interface ICSubmenu { /** Fires when a menu is selected. Avoid any reference - * referring to ViewHomeUI in this method, because - * it is triggered when ViewHomeUI is initialized, which + * referring to VHomeUI in this method, because + * it is triggered when VHomeUI is initialized, which * will create an NPE. * * @return {@link forge.Command} */ diff --git a/src/main/java/forge/gui/home/IVSubmenu.java b/src/main/java/forge/gui/home/IVSubmenu.java index dea1c9748e0..cb879155bc7 100644 --- a/src/main/java/forge/gui/home/IVSubmenu.java +++ b/src/main/java/forge/gui/home/IVSubmenu.java @@ -2,7 +2,12 @@ package forge.gui.home; import javax.swing.JPanel; -/** Dictates methods required for a submenu view. */ +/** + * Dictates methods required for a submenu view. + * + *

(I at beginning of class name denotes an interface.) + *
(V at beginning of class name denotes a view class.) + */ public interface IVSubmenu { /** Allows static factory creation by decoupling UI components. * @return {@link javax.swing.JPanel} */ diff --git a/src/main/java/forge/view/ViewHomeUI.java b/src/main/java/forge/gui/home/VHomeUI.java similarity index 89% rename from src/main/java/forge/view/ViewHomeUI.java rename to src/main/java/forge/gui/home/VHomeUI.java index 8db3a24f9b2..c4cabd8eca0 100644 --- a/src/main/java/forge/view/ViewHomeUI.java +++ b/src/main/java/forge/gui/home/VHomeUI.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package forge.view; +package forge.gui.home; import java.awt.CardLayout; import java.awt.Component; @@ -32,6 +32,7 @@ import java.util.TreeMap; import javax.swing.BorderFactory; import javax.swing.JLabel; +import javax.swing.JLayeredPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingConstants; @@ -43,9 +44,7 @@ import net.miginfocom.swing.MigLayout; import forge.AllZone; import forge.Command; import forge.Singletons; -import forge.gui.home.EMenuGroup; -import forge.gui.home.EMenuItem; -import forge.gui.home.IVSubmenu; +import forge.gui.framework.IVTopLevelUI; import forge.gui.home.quest.VSubmenuChallenges; import forge.gui.home.quest.VSubmenuDuels; import forge.gui.home.quest.VSubmenuQuestData; @@ -69,6 +68,7 @@ import forge.properties.ForgeProps; import forge.properties.NewConstants; import forge.quest.data.QuestPreferences.QPref; import forge.quest.io.QuestDataIO; +import forge.view.FView; /** Singleton instance of home screen UI. * Use "getPanel()" to work with the main container. @@ -79,9 +79,11 @@ import forge.quest.io.QuestDataIO; * - Build a view implementing IVSubmenu
* - Build a controller impelementing ICSubmenu
* - Add its singleton instance to the map storing the views for the card layout. + * + *

(V at beginning of class name denotes a view class.) */ -public enum ViewHomeUI { +public enum VHomeUI implements IVTopLevelUI { /** */ SINGLETON_INSTANCE; @@ -90,6 +92,9 @@ public enum ViewHomeUI { private final FPanel pnlLeft = new FPanel(); private final FPanel pnlRight = new FPanel(cards); private final JPanel pnlMenu = new JPanel(); + private final FScrollPane scrMenu = new FScrollPane(pnlMenu, + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); private final int insets = 10; private final int leftWidthPx = 250; @@ -97,20 +102,15 @@ public enum ViewHomeUI { private final Map allSubmenuLabels = new HashMap(); private FLabel lblPreviousSelected; - /** Mostly, assembles child singletons for the home screen UI. */ - public void initialize() { - // There's d a better home for this (model?) + @Override + public void instantiate() { + // There'd a better home for this (model?) final File dirQuests = ForgeProps.getFile(NewConstants.Quest.DATA_DIR); final String questname = Singletons.getModel().getQuestPreferences().getPreference(QPref.CURRENT_QUEST); final File data = new File(dirQuests.getPath(), questname); - - if (data.exists()) { - AllZone.getQuest().load(QuestDataIO.loadData(data)); - } ////////////////////////////// - + if (data.exists()) { AllZone.getQuest().load(QuestDataIO.loadData(data)); } // Add new menu items here (order doesn't matter). - allSubmenus.clear(); allSubmenus.add(VSubmenuConstructed.SINGLETON_INSTANCE); allSubmenus.add(VSubmenuDraft.SINGLETON_INSTANCE); allSubmenus.add(VSubmenuSealed.SINGLETON_INSTANCE); @@ -133,13 +133,12 @@ public enum ViewHomeUI { pnlParent.setBorderToggle(false); pnlParent.setBackgroundTexture(FSkin.getIcon(FSkin.Backgrounds.BG_TEXTURE)); pnlParent.setLayout(null); - pnlParent.add(pnlLeft); - pnlParent.add(pnlRight); + pnlParent.add(pnlRight); // Left pane holds scroller with menu panel. - final FScrollPane scrMenu = new FScrollPane(pnlMenu, - JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + pnlMenu.setLayout(new MigLayout("insets 0, gap 0, wrap, hidemode 3")); + pnlMenu.setOpaque(false); scrMenu.setBorder(null); pnlLeft.setLayout(new MigLayout("insets 0, gap 0, align center, wrap")); @@ -148,8 +147,43 @@ public enum ViewHomeUI { pnlLeft.add(scrMenu, "pushy, growy, w 98%!, gap 1% 0 1% 0"); - populateMenu(); + final Map allGroupLabels = new HashMap(); + final String strTitleConstraints = "w 90%!, gap 5% 0 5px 10px"; + final String strGroupConstraints = "w 85%!, gap 10% 0 0 0"; + final String strItemConstraints = "w 100%!, h 26px!, gap 0 0 1px 1px"; + + // For each group: init its panel + final SortedMap allGroupPanels = new TreeMap(); + for (final EMenuGroup e : EMenuGroup.values()) { + allGroupPanels.put(e, new JPanel()); + allGroupPanels.get(e).setOpaque(false); + allGroupPanels.get(e).setVisible(false); + allGroupPanels.get(e).setLayout(new MigLayout("insets 0, gap 0, wrap")); + allGroupPanels.get(e).setName(e.toString()); + } + + // For each item: Add to its group, and add to the card layout in right panel. + for (final IVSubmenu item : allSubmenus) { + allSubmenuLabels.put(EMenuItem.valueOf(item.getItemEnum()), makeItemLabel(item)); + pnlRight.add(item.getItemEnum(), item.getPanel()); + allGroupPanels.get(item.getGroupEnum()).add( + allSubmenuLabels.get(EMenuItem.valueOf(item.getItemEnum())), strItemConstraints); + item.getControl().initialize(); + } + + // For each group: add its title, then its panel, then "click" if necessary. + for (final EMenuGroup e : allGroupPanels.keySet()) { + allGroupLabels.put(e, makeTitleLabel(e)); + pnlMenu.add(allGroupLabels.get(e), strTitleConstraints); + pnlMenu.add(allGroupPanels.get(e), strGroupConstraints); + + // Expand groups expanded from previous session + if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.valueOf("SUBMENU_" + e.toString()))) { + groupClick(e, allGroupLabels.get(e)); + } + } + // Select previous EMenuItem selected = null; try { @@ -164,6 +198,7 @@ public enum ViewHomeUI { itemClick(EMenuItem.CONSTRUCTED); } + // TODO this shouldn't be here; should perhaps be an interface method in controller. pnlParent.addComponentListener(new ComponentAdapter() { @Override public void componentResized(final ComponentEvent e) { @@ -181,51 +216,9 @@ public enum ViewHomeUI { }); } - /** Generates expand/collapse menu using cards in layout, and EMenuGroup enum. - * No further hardcoding should be required in this method. */ - private void populateMenu() { - final SortedMap allGroupPanels = new TreeMap(); - final Map allGroupLabels = new HashMap(); - - final ForgePreferences prefs = Singletons.getModel().getPreferences(); - final String strTitleConstraints = "w 90%!, gap 5% 0 5px 10px"; - final String strGroupConstraints = "w 85%!, gap 10% 0 0 0"; - final String strItemConstraints = "w 100%!, h 26px!, gap 0 0 1px 1px"; - - pnlMenu.removeAll(); - pnlMenu.setLayout(new MigLayout("insets 0, gap 0, wrap, hidemode 3")); - pnlMenu.setOpaque(false); - - // For each group: init its panel - for (final EMenuGroup e : EMenuGroup.values()) { - allGroupPanels.put(e, new JPanel()); - allGroupPanels.get(e).setOpaque(false); - allGroupPanels.get(e).setVisible(false); - allGroupPanels.get(e).setLayout(new MigLayout("insets 0, gap 0, wrap")); - allGroupPanels.get(e).setName(e.toString()); - } - - // For each item: Add to its group, and add to the card layout in right panel. - allSubmenuLabels.clear(); - for (final IVSubmenu item : allSubmenus) { - allSubmenuLabels.put(EMenuItem.valueOf(item.getItemEnum()), makeItemLabel(item)); - pnlRight.add(item.getItemEnum(), item.getPanel()); - allGroupPanels.get(item.getGroupEnum()).add( - allSubmenuLabels.get(EMenuItem.valueOf(item.getItemEnum())), strItemConstraints); - item.getControl().initialize(); - } - - // For each group: add its title, then its panel, then "click" if necessary. - for (final EMenuGroup e : allGroupPanels.keySet()) { - allGroupLabels.put(e, makeTitleLabel(e)); - pnlMenu.add(allGroupLabels.get(e), strTitleConstraints); - pnlMenu.add(allGroupPanels.get(e), strGroupConstraints); - - // Expand groups expanded from previous session - if (prefs.getPrefBoolean(FPref.valueOf("SUBMENU_" + e.toString()))) { - groupClick(e, allGroupLabels.get(e)); - } - } + @Override + public void populate() { + FView.SINGLETON_INSTANCE.getLpnDocument().add(pnlParent, JLayeredPane.DEFAULT_LAYER); } private void groupClick(final EMenuGroup e0, final JLabel lbl0) { diff --git a/src/main/java/forge/gui/home/quest/CSubmenuChallenges.java b/src/main/java/forge/gui/home/quest/CSubmenuChallenges.java index fa1a97a3a6b..cc3129c122d 100644 --- a/src/main/java/forge/gui/home/quest/CSubmenuChallenges.java +++ b/src/main/java/forge/gui/home/quest/CSubmenuChallenges.java @@ -12,13 +12,13 @@ import forge.AllZone; import forge.Command; import forge.gui.home.EMenuItem; import forge.gui.home.ICSubmenu; +import forge.gui.home.VHomeUI; import forge.gui.home.quest.SubmenuQuestUtil.SelectablePanel; import forge.gui.toolbox.FLabel; import forge.quest.QuestController; import forge.quest.QuestEventChallenge; import forge.quest.bazaar.QuestItemType; import forge.quest.bazaar.QuestPetController; -import forge.view.ViewHomeUI; /** * TODO: Write javadoc for this type. @@ -39,7 +39,7 @@ public enum CSubmenuChallenges implements ICSubmenu { @Override public void execute() { if (qc.getAchievements() == null) { - ViewHomeUI.SINGLETON_INSTANCE.itemClick(EMenuItem.QUEST_DATA); + VHomeUI.SINGLETON_INSTANCE.itemClick(EMenuItem.QUEST_DATA); } } }; @@ -80,7 +80,7 @@ public enum CSubmenuChallenges implements ICSubmenu { view.getBtnCurrentDeck().setCommand( new Command() { @Override public void execute() { - ViewHomeUI.SINGLETON_INSTANCE.itemClick(EMenuItem.QUEST_DECKS); + VHomeUI.SINGLETON_INSTANCE.itemClick(EMenuItem.QUEST_DECKS); } }); diff --git a/src/main/java/forge/gui/home/quest/CSubmenuDuels.java b/src/main/java/forge/gui/home/quest/CSubmenuDuels.java index 64d3e2a7523..afea7af5c68 100644 --- a/src/main/java/forge/gui/home/quest/CSubmenuDuels.java +++ b/src/main/java/forge/gui/home/quest/CSubmenuDuels.java @@ -8,11 +8,11 @@ import forge.AllZone; import forge.Command; import forge.gui.home.EMenuItem; import forge.gui.home.ICSubmenu; +import forge.gui.home.VHomeUI; import forge.gui.home.quest.SubmenuQuestUtil.SelectablePanel; import forge.quest.QuestController; import forge.quest.QuestEventDuel; import forge.quest.bazaar.QuestPetController; -import forge.view.ViewHomeUI; /** * TODO: Write javadoc for this type. @@ -32,7 +32,7 @@ public enum CSubmenuDuels implements ICSubmenu { return new Command() { public void execute() { if (qc.getAchievements() == null) { - ViewHomeUI.SINGLETON_INSTANCE.itemClick(EMenuItem.QUEST_DATA); + VHomeUI.SINGLETON_INSTANCE.itemClick(EMenuItem.QUEST_DATA); } } }; @@ -63,7 +63,7 @@ public enum CSubmenuDuels implements ICSubmenu { view.getBtnCurrentDeck().setCommand( new Command() { @Override public void execute() { - ViewHomeUI.SINGLETON_INSTANCE.itemClick(EMenuItem.QUEST_DECKS); + VHomeUI.SINGLETON_INSTANCE.itemClick(EMenuItem.QUEST_DECKS); } }); diff --git a/src/main/java/forge/gui/home/quest/CSubmenuQuestDecks.java b/src/main/java/forge/gui/home/quest/CSubmenuQuestDecks.java index 1932eaee8d8..ddfb0981573 100644 --- a/src/main/java/forge/gui/home/quest/CSubmenuQuestDecks.java +++ b/src/main/java/forge/gui/home/quest/CSubmenuQuestDecks.java @@ -10,9 +10,9 @@ import forge.gui.OverlayUtils; import forge.gui.deckeditor.DeckEditorQuest; import forge.gui.home.EMenuItem; import forge.gui.home.ICSubmenu; +import forge.gui.home.VHomeUI; import forge.quest.QuestController; import forge.quest.data.QuestPreferences.QPref; -import forge.view.ViewHomeUI; /** * TODO: Write javadoc for this type. @@ -57,7 +57,7 @@ public enum CSubmenuQuestDecks implements ICSubmenu { @Override public void execute() { if (qc.getAchievements() == null) { - ViewHomeUI.SINGLETON_INSTANCE.itemClick(EMenuItem.QUEST_DATA); + VHomeUI.SINGLETON_INSTANCE.itemClick(EMenuItem.QUEST_DATA); } } }; diff --git a/src/main/java/forge/gui/layout/FViewNew.java b/src/main/java/forge/gui/layout/FViewNew.java deleted file mode 100644 index 992a711f773..00000000000 --- a/src/main/java/forge/gui/layout/FViewNew.java +++ /dev/null @@ -1,181 +0,0 @@ -package forge.gui.layout; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JFrame; -import javax.swing.JLayeredPane; -import javax.swing.JPanel; -import javax.swing.border.EmptyBorder; -import javax.swing.border.LineBorder; - -import net.miginfocom.swing.MigLayout; -import forge.Singletons; - -/** */ -public enum FViewNew { - /** */ - SINGLETON_INSTANCE; - - // Layout vars - private final JFrame frmDocument = new JFrame(); - private final JPanel pnlContent = new JPanel(); - private final JPanel pnlInsets = new JPanel(new BorderLayout()); - private final JPanel pnlPreview = new PreviewPanel(); - private final JPanel pnlTabOverflow = new JPanel(new MigLayout("insets 0, gap 0, wrap")); - private final JLayeredPane lpnDocument = new JLayeredPane(); - private static final List CELLS = new ArrayList(); - - /** Height of head area in drag panel. */ - public static final int HEAD_H = 20; - /** Thickness of resize border in drag panel. */ - public static final int BORDER_T = 5; - - private FViewNew() { - frmDocument.setMinimumSize(new Dimension(800, 600)); - frmDocument.setLocationRelativeTo(null); - frmDocument.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frmDocument.setContentPane(lpnDocument); - frmDocument.setTitle("Forge: " + Singletons.getModel().getBuildInfo().getVersion()); - - pnlInsets.add(pnlContent, BorderLayout.CENTER); - pnlInsets.setBackground(Color.black); - pnlInsets.setBorder(new EmptyBorder( - FViewNew.BORDER_T, FViewNew.BORDER_T, 0, 0)); - - pnlContent.setBackground(Color.black); - pnlContent.setLayout(null); - - lpnDocument.addMouseListener(SOverflowUtil.getHideOverflowListener()); - lpnDocument.addComponentListener(SResizingUtil.getWindowResizeListener()); - - lpnDocument.add(pnlInsets, (Integer) 0); - lpnDocument.add(pnlPreview, (Integer) 1); - lpnDocument.add(pnlTabOverflow, (Integer) 2); - - frmDocument.setVisible(true); - pnlInsets.setBounds(lpnDocument.getBounds()); - } - - /** */ - public void populate() { - DragCell cell0 = new DragCell(); - DragCell cell1 = new DragCell(); - DragCell cell2 = new DragCell(); - DragCell cell3 = new DragCell(); - DragCell cell4 = new DragCell(); - DragCell cell5 = new DragCell(); - - cell0.addDoc(EDocID.REPORT_STACK.getDoc()); - cell0.addDoc(EDocID.REPORT_COMBAT.getDoc()); - cell0.addDoc(EDocID.REPORT_LOG.getDoc()); - cell0.addDoc(EDocID.REPORT_PLAYERS.getDoc()); - cell1.addDoc(EDocID.REPORT_MESSAGE.getDoc()); - cell2.addDoc(EDocID.YOUR_BATTLEFIELD.getDoc()); - cell3.addDoc(EDocID.YOUR_HAND.getDoc()); - cell4.addDoc(EDocID.YOUR_DOCK.getDoc()); - cell5.addDoc(EDocID.CARD_DETAIL.getDoc()); - cell5.addDoc(EDocID.CARD_PICTURE.getDoc()); - cell5.addDoc(EDocID.CARD_ANTES.getDoc()); - - addDragCell(cell0); - addDragCell(cell1); - addDragCell(cell2); - addDragCell(cell3); - addDragCell(cell4); - addDragCell(cell5); - - cell0.setRoughBounds(0, 0, 0.2, 0.7); - cell1.setRoughBounds(0, 0.7, 0.2, 0.3); - cell2.setRoughBounds(0.2, 0, 0.6, 0.5); - cell3.setRoughBounds(0.2, 0.5, 0.6, 0.5); - cell4.setRoughBounds(0.8, 0, 0.2, 0.25); - cell5.setRoughBounds(0.8, 0.25, 0.2, 0.75); - - // TODO save a default layout, and then remove these lines and load it every time. - //SIOUtil.saveLayout(); - //SIOUtil.loadLayout(); - } - - /** @return {@link javax.swing.JFrame} */ - public JFrame getFrame() { - return frmDocument; - } - - /** @return {@link javax.swing.JLayeredPane} */ - public JLayeredPane getLpnDocument() { - return lpnDocument; - } - - /** @return {@link javax.swing.JPanel} */ - public JPanel getPnlInsets() { - return pnlInsets; - } - - /** @return {@link javax.swing.JPanel} */ - public JPanel getPnlContent() { - return pnlContent; - } - - /** @return {@link javax.swing.JPanel} */ - public JPanel getPnlPreview() { - return pnlPreview; - } - - /** @return {@link javax.swing.JPanel} */ - public JPanel getPnlTabOverflow() { - return pnlTabOverflow; - } - - /** @return {@link java.util.List}<{@link forge.gui.layout.DragCell}> */ - public List getDragCells() { - final List clone = new ArrayList(); - clone.addAll(CELLS); - return clone; - } - - /** @param pnl0   {@link forge.gui.layout.DragCell} */ - public void addDragCell(final DragCell pnl0) { - CELLS.add(pnl0); - pnlContent.add(pnl0); - } - - /** @param pnl0   {@link forge.gui.layout.DragCell} */ - public void removeDragCell(final DragCell pnl0) { - CELLS.remove(pnl0); - pnlContent.remove(pnl0); - } - - /** */ - public void removeAllDragCells() { - CELLS.clear(); - pnlContent.removeAll(); - } - - /** PreviewPanel shows where a dragged component could - * come to rest when the mouse is released.
- * This class is an unfortunate necessity to overcome - * translucency issues for preview panel. */ - @SuppressWarnings("serial") - class PreviewPanel extends JPanel { - /** PreviewPanel shows where a dragged component could - * come to rest when the mouse is released. */ - public PreviewPanel() { - super(); - setOpaque(false); - setVisible(false); - setBorder(new LineBorder(Color.DARK_GRAY, 2)); - } - - @Override - public void paintComponent(final Graphics g) { - super.paintComponent(g); - g.setColor(new Color(0, 0, 0, 50)); - g.fillRect(0, 0, getWidth(), getHeight()); - } - } -} diff --git a/src/main/java/forge/gui/layout/IVDoc.java b/src/main/java/forge/gui/layout/IVDoc.java deleted file mode 100644 index 97a1b40b353..00000000000 --- a/src/main/java/forge/gui/layout/IVDoc.java +++ /dev/null @@ -1,49 +0,0 @@ -package forge.gui.layout; - -import java.awt.Component; - -/** - * This interface provides a unifying type to any component - * (usually JPanels or JScrollPanes) which could be used as - * a tab. A single one of these components is referred to as - * a "document" throughout the codebase. The tabs and their - * documents are contained in "cells" for resizing and dragging. - * - *

(I at beginning of class name denotes an interface.) - *
(V at beginning of class name denotes a view class.) - */ -public interface IVDoc { - /** - * Returns the ID used to identify this tab in save XML and card layouts. - * - * @return {@link forge.gui.layout.EDocID} - */ - EDocID getDocumentID(); - - /** - * Returns top-level component containing all of the content in this tab. - * This is used to attach the component to the card layout of its parent. - * - * @return {@link java.awt.Component} - */ - Component getDocument(); - - /** - * Returns tab label object used in title bars. - * - * @return {@link forge.gui.layout.DragTab} - */ - DragTab getTabLabel(); - - /** Retrieves control object associated with this document. - * @return {@link forge.gui.home.ICSubmenu} - */ - ICDoc getControl(); - - /** - * Removes all children and (re)populates panel components, - * independent of constructor. Expected to provide - * a completely fresh layout on the component. - */ - void populate(); -} diff --git a/src/main/java/forge/gui/layout/MDragUI.java b/src/main/java/forge/gui/layout/MDragUI.java deleted file mode 100644 index 9c75e55e402..00000000000 --- a/src/main/java/forge/gui/layout/MDragUI.java +++ /dev/null @@ -1,13 +0,0 @@ -package forge.gui.layout; - -/** - *

(M at beginning of class name denotes a class - * containing the main method). - */ -final class MDragUI { - /** @param args   {@link java.lang.String}[] */ - public static void main(String[] args) { - FViewNew.SINGLETON_INSTANCE.populate(); - } -} - diff --git a/src/main/java/forge/gui/layout/SIOUtil.java b/src/main/java/forge/gui/layout/SIOUtil.java deleted file mode 100644 index 62627651e30..00000000000 --- a/src/main/java/forge/gui/layout/SIOUtil.java +++ /dev/null @@ -1,114 +0,0 @@ -package forge.gui.layout; - -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.util.List; - -import javax.swing.SwingUtilities; -import javax.xml.stream.XMLEventFactory; -import javax.xml.stream.XMLEventReader; -import javax.xml.stream.XMLEventWriter; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.events.XMLEvent; - - -/** Package-private class for handling layout saving and loading. */ -final class SIOUtil { - /** Each cell must save these elements of its display. */ - private enum Element { - x, - y, - w, - h, - doc - }; - - private static final String FILE = "layout_default.xml"; - private static final XMLEventFactory EF = XMLEventFactory.newInstance(); - private static final XMLEvent NEWLINE = EF.createDTD("\n"); - private static final XMLEvent TAB = EF.createDTD("\t"); - - /** Publicly-accessible save method, to neatly handle exception handling. */ - public static void saveLayout() { - if (SwingUtilities.isEventDispatchThread()) { - throw new IllegalThreadStateException("This operation should be independent of the EDT."); - } - - // try { save(); } - // catch (final Exception e) { e.printStackTrace(); } - } - - /** Publicly-accessible load method, to neatly handle exception handling. */ - public static void loadLayout() { - if (SwingUtilities.isEventDispatchThread()) { - throw new IllegalThreadStateException("This operation should be independent of the EDT."); - } - - // try { load(); } - // catch (final Exception e) { e.printStackTrace(); } - // TODO save layout after resize / rearrange - // TODO layout save - int todo = 5; - } - - private static void save() throws Exception { - final XMLOutputFactory out = XMLOutputFactory.newInstance(); - final XMLEventWriter writer = out.createXMLEventWriter(new FileOutputStream(FILE)); - final List cells = FViewNew.SINGLETON_INSTANCE.getDragCells(); - - writer.add(EF.createStartDocument()); - writer.add(EF.createStartElement("", "", "layout")); - - for (final DragCell cell : cells) { - writer.add(EF.createStartElement("", "", "cell")); - - createNode(writer, Element.x, String.valueOf(cell.getRoughX())); - createNode(writer, Element.y, String.valueOf(cell.getRoughY())); - createNode(writer, Element.w, String.valueOf(cell.getRoughW())); - createNode(writer, Element.h, String.valueOf(cell.getRoughH())); - - for (final IVDoc vDoc : cell.getDocs()) { - createNode(writer, Element.doc, vDoc.getDocumentID().toString()); - } - - writer.add(EF.createEndElement("", "", "cell")); - } - - writer.add(EF.createEndDocument()); - writer.flush(); - writer.close(); - } - - private static void load() throws Exception { - final FViewNew view = FViewNew.SINGLETON_INSTANCE; - final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); - final XMLEventReader reader = inputFactory.createXMLEventReader(new FileInputStream(FILE)); - - view.removeAllDragCells(); - /*while (reader.hasNext()) { - XMLEvent event = reader.nextEvent(); - - if (event.isStartElement()) { - /*StartElement startElement = event.asStartElement(); - - if (startElement.getName().getLocalPart() == (ITEM)) { - - }* - - //System.err.println(event.isStartElement()); - } - }*/ - } - - private static void createNode(final XMLEventWriter writer0, final Element name0, - final String val0) throws XMLStreamException { - - writer0.add(TAB); - writer0.add(EF.createStartElement("", "", name0.toString())); - writer0.add(EF.createCharacters(val0)); - writer0.add(EF.createEndElement("", "", name0.toString())); - writer0.add(NEWLINE); - } -} diff --git a/src/main/java/forge/control/ControlMatchUI.java b/src/main/java/forge/gui/match/CMatchUI.java similarity index 56% rename from src/main/java/forge/control/ControlMatchUI.java rename to src/main/java/forge/gui/match/CMatchUI.java index 56ea45b33af..2063701dfe2 100644 --- a/src/main/java/forge/control/ControlMatchUI.java +++ b/src/main/java/forge/gui/match/CMatchUI.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package forge.control; +package forge.gui.match; import java.awt.Image; import java.io.File; @@ -29,57 +29,36 @@ import forge.Card; import forge.CardList; import forge.Constant; import forge.Singletons; -import forge.control.match.ControlDetail; -import forge.control.match.ControlDock; -import forge.control.match.ControlField; -import forge.control.match.ControlHand; -import forge.control.match.ControlMessage; -import forge.control.match.ControlPicture; -import forge.control.match.ControlTabber; import forge.game.GameType; import forge.game.phase.PhaseType; import forge.game.player.Player; import forge.game.zone.ZoneType; import forge.gui.CardContainer; import forge.gui.GuiMultipleBlockers; +import forge.gui.framework.EDocID; +import forge.gui.framework.SDisplayUtil; +import forge.gui.match.controllers.CDetail; +import forge.gui.match.controllers.CMessage; +import forge.gui.match.controllers.CPicture; +import forge.gui.match.nonsingleton.CField; +import forge.gui.match.nonsingleton.VField; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FSkin; import forge.properties.ForgePreferences.FPref; import forge.properties.ForgeProps; import forge.properties.NewConstants; -import forge.view.ViewMatchUI; -import forge.view.match.ViewField; /** - *

- * ControlMatchUI - *

- * Top-level controller for matches. + * Constructs instance of match UI controller, used as a single point of + * top-level control for child UIs. Tasks targeting the view of individual + * components are found in a separate controller for that component and + * should not be included here. * + *

(C at beginning of class name denotes a control class.) */ -public class ControlMatchUI implements CardContainer { - private final ViewMatchUI view; - - /** - *

- * ControlMatchUI - *

- * Constructs instance of match UI controller, used as a single point of - * top-level control for child UIs - in other words, this class controls the - * controllers. Tasks targeting the view of individual components are found - * in a separate controller for that component and should not be included - * here. - * - * This constructor is called after child components have been instantiated. - * When children are instantiated, they also instantiate their controller. - * So, this class must be called after everything is already in place. - * - * @param v - *   A ViewMatchUI object - */ - public ControlMatchUI(final ViewMatchUI v) { - this.view = v; - } +public enum CMatchUI implements CardContainer { + /** */ + SINGLETON_INSTANCE; /** * Fires up controllers for each component of UI. @@ -88,12 +67,11 @@ public class ControlMatchUI implements CardContainer { * */ public void initMatch(final String strAvatarIcon) { - ControlMatchUI.this.showCombat(""); - ControlMatchUI.this.showStack(); + SDisplayUtil.showTab(EDocID.REPORT_LOG.getDoc()); // Update avatars final String[] indices = Singletons.getModel().getPreferences().getPref(FPref.UI_AVATARS).split(","); - final Object[] views = Singletons.getView().getViewMatch().getFieldViews().toArray(); + final Object[] views = VMatchUI.SINGLETON_INSTANCE.getFieldViews().toArray(); for (int i = 0; i < views.length; i++) { final Image img; // Update AI quest icon @@ -115,8 +93,8 @@ public class ControlMatchUI implements CardContainer { img = FSkin.getAvatars().get(Integer.parseInt(indices[i])); } - ((ViewField) views[i]).getLblAvatar().setIcon(new ImageIcon(img)); - ((FLabel) ((ViewField) views[i]).getLblAvatar()).getResizeTimer().start(); + ((VField) views[i]).getLblAvatar().setIcon(new ImageIcon(img)); + ((FLabel) ((VField) views[i]).getLblAvatar()).getResizeTimer().start(); } // Update observers @@ -126,11 +104,11 @@ public class ControlMatchUI implements CardContainer { AllZone.getComputerPlayer().updateObservers(); AllZone.getComputerPlayer().getZone(ZoneType.Hand).updateObservers(); - AllZone.getHumanPlayer().getZone(ZoneType.Battlefield).updateObservers(); + AllZone.getComputerPlayer().getZone(ZoneType.Battlefield).updateObservers(); AllZone.getStack().updateObservers(); AllZone.getInputControl().updateObservers(); - ControlMatchUI.this.getTabberControl().updateObservers(); + AllZone.getGameLog().updateObservers(); } /** @@ -140,91 +118,27 @@ public class ControlMatchUI implements CardContainer { // This method is in the top-level controller because it affects ALL fields // (not just one). public void resetAllPhaseButtons() { - for (final ControlField c : ControlMatchUI.this.getFieldControls()) { + for (final CField c : CMatchUI.this.getFieldControls()) { c.resetPhaseButtons(); } } /** @param s0   {@link java.lang.String} */ public void showMessage(final String s0) { - getMessageControl().setMessage(s0); - } - - /** */ - public void showStack() { - ControlMatchUI.this.getTabberControl().showPnlStack(); - } - - /** @param s0   {@link java.lang.String} */ - public void showCombat(final String s0) { - ControlMatchUI.this.getTabberControl().getView().updateCombat(s0); - } - - /** - * Gets the detail controller. - * - * @return ControlDetail - */ - public ControlDetail getDetailControl() { - return view.getViewDetail().getControl(); - } - - /** - * Gets the picture controller. - * - * @return ControlPicture - */ - public ControlPicture getPictureControl() { - return view.getViewPicture().getControl(); - } - - /** - * Gets the tabber controller. - * - * @return ControlTabber - */ - public ControlTabber getTabberControl() { - return view.getViewTabber().getControl(); - } - - /** - * Gets the input controller. - * - * @return ControlMessage - */ - public ControlMessage getMessageControl() { - return view.getViewMessage().getControl(); - } - - /** - * Gets the hand controller. - * - * @return ControlHand - */ - public ControlHand getHandControl() { - return view.getViewHand().getControl(); - } - - /** - * Gets the dock controller. - * - * @return ControlDock - */ - public ControlDock getDockControl() { - return view.getDockView().getControl(); + CMessage.SINGLETON_INSTANCE.setMessage(s0); } /** * Gets the field controllers. * - * @return List + * @return List */ - public List getFieldControls() { - final List fields = view.getViewBattlefield().getFields(); - final List controllers = new ArrayList(); + public List getFieldControls() { + final List fields = VMatchUI.SINGLETON_INSTANCE.getFieldViews(); + final List controllers = new ArrayList(); - for (final ViewField f : fields) { - controllers.add(f.getControl()); + for (final VField f : fields) { + controllers.add((CField) f.getControl()); } return controllers; @@ -255,11 +169,11 @@ public class ControlMatchUI implements CardContainer { * @return boolean */ public final boolean stopAtPhase(final Player turn, final PhaseType phase) { - final List fieldControllers = ControlMatchUI.this.getFieldControls(); + final List fieldControllers = CMatchUI.this.getFieldControls(); // AI field is at index [0] int index = turn.isComputer() ? 0 : 1; - ViewField vf = fieldControllers.get(index).getView(); + VField vf = fieldControllers.get(index).getView(); switch (phase) { case UPKEEP: return vf.getLblUpkeep().getEnabled(); @@ -273,6 +187,7 @@ public class ControlMatchUI implements CardContainer { case COMBAT_END: return vf.getLblEndCombat().getEnabled(); case MAIN2: return vf.getLblMain2().getEnabled(); case END_OF_TURN: return vf.getLblEndTurn().getEnabled(); + default: } return true; @@ -280,12 +195,12 @@ public class ControlMatchUI implements CardContainer { @Override public void setCard(final Card c) { - Singletons.getControl().getControlMatch().getDetailControl().showCard(c); - Singletons.getControl().getControlMatch().getPictureControl().showCard(c); + CDetail.SINGLETON_INSTANCE.showCard(c); + CPicture.SINGLETON_INSTANCE.showCard(c); } @Override public Card getCard() { - return Singletons.getControl().getControlMatch().getDetailControl().getCurrentCard(); + return CDetail.SINGLETON_INSTANCE.getCurrentCard(); } } diff --git a/src/main/java/forge/control/match/ControlWinLose.java b/src/main/java/forge/gui/match/ControlWinLose.java similarity index 95% rename from src/main/java/forge/control/match/ControlWinLose.java rename to src/main/java/forge/gui/match/ControlWinLose.java index 0e98e4580a0..81b6aa737bc 100644 --- a/src/main/java/forge/control/match/ControlWinLose.java +++ b/src/main/java/forge/gui/match/ControlWinLose.java @@ -1,4 +1,4 @@ -package forge.control.match; +package forge.gui.match; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -19,7 +19,6 @@ import forge.gui.OverlayUtils; import forge.item.CardDb; import forge.item.CardPrinted; import forge.properties.ForgePreferences.FPref; -import forge.view.match.ViewWinLose; /** * Default controller for a ViewWinLose object. This class can diff --git a/src/main/java/forge/view/match/QuestWinLoseCardViewer.java b/src/main/java/forge/gui/match/QuestWinLoseCardViewer.java similarity index 96% rename from src/main/java/forge/view/match/QuestWinLoseCardViewer.java rename to src/main/java/forge/gui/match/QuestWinLoseCardViewer.java index ceec4de198a..c8b6c74d743 100644 --- a/src/main/java/forge/view/match/QuestWinLoseCardViewer.java +++ b/src/main/java/forge/gui/match/QuestWinLoseCardViewer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package forge.view.match; +package forge.gui.match; import java.util.Collections; import java.util.List; diff --git a/src/main/java/forge/view/match/QuestWinLoseHandler.java b/src/main/java/forge/gui/match/QuestWinLoseHandler.java similarity index 99% rename from src/main/java/forge/view/match/QuestWinLoseHandler.java rename to src/main/java/forge/gui/match/QuestWinLoseHandler.java index a269d89f007..ed5bcf9c3e4 100644 --- a/src/main/java/forge/view/match/QuestWinLoseHandler.java +++ b/src/main/java/forge/gui/match/QuestWinLoseHandler.java @@ -14,14 +14,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package forge.view.match; +package forge.gui.match; import forge.AllZone; import forge.CardList; import forge.Constant; import forge.Singletons; import forge.control.FControl; -import forge.control.match.ControlWinLose; import forge.game.GameEndReason; import forge.game.GameFormat; @@ -49,6 +48,7 @@ import forge.quest.bazaar.QuestItemType; import forge.quest.data.QuestAssets; import forge.quest.data.QuestPreferences.QPref; import forge.util.MyRandom; + import java.awt.Color; import java.awt.Dimension; import java.util.ArrayList; diff --git a/src/main/java/forge/gui/match/VMatchUI.java b/src/main/java/forge/gui/match/VMatchUI.java new file mode 100644 index 00000000000..11ca01bdfab --- /dev/null +++ b/src/main/java/forge/gui/match/VMatchUI.java @@ -0,0 +1,168 @@ +package forge.gui.match; + +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JButton; + +import forge.AllZone; +import forge.gui.framework.DragCell; +import forge.gui.framework.EDocID; +import forge.gui.framework.IVDoc; +import forge.gui.framework.IVTopLevelUI; +import forge.gui.framework.SIOUtil; +import forge.gui.framework.SResizingUtil; +import forge.gui.match.nonsingleton.VField; +import forge.gui.match.nonsingleton.VHand; +import forge.gui.match.views.VDetail; +import forge.gui.match.views.VDev; +import forge.gui.match.views.VMessage; +import forge.gui.match.views.VPicture; +import forge.view.FView; + +/** + * Top level view class for match UI drag layout.
+ * Has access methods for all draggable documents.
+ * Uses singleton pattern.
+ * + *

(V at beginning of class name denotes a view class.) + */ +public enum VMatchUI implements IVTopLevelUI { + /** */ + SINGLETON_INSTANCE; + + // Instantiate non-singleton tab instances + private final IVDoc field0 = new VField(EDocID.FIELD_0, AllZone.getComputerPlayer()); + private final IVDoc field1 = new VField(EDocID.FIELD_1, AllZone.getHumanPlayer()); + private final IVDoc field2 = new VField(EDocID.FIELD_2, AllZone.getComputerPlayer()); + private final IVDoc field3 = new VField(EDocID.FIELD_3, AllZone.getComputerPlayer()); + + private final IVDoc hand0 = new VHand(EDocID.HAND_0, AllZone.getComputerPlayer()); + private final IVDoc hand1 = new VHand(EDocID.HAND_1, AllZone.getHumanPlayer()); + private final IVDoc hand2 = new VHand(EDocID.HAND_2, AllZone.getComputerPlayer()); + private final IVDoc hand3 = new VHand(EDocID.HAND_3, AllZone.getComputerPlayer()); + + // Instantiate singleton tab instances + private final IVDoc stack = EDocID.REPORT_STACK.getDoc(); + private final IVDoc combat = EDocID.REPORT_COMBAT.getDoc(); + private final IVDoc log = EDocID.REPORT_LOG.getDoc(); + private final IVDoc players = EDocID.REPORT_PLAYERS.getDoc(); + private final IVDoc message = EDocID.REPORT_MESSAGE.getDoc(); + + private final IVDoc dock = EDocID.BUTTON_DOCK.getDoc(); + private final IVDoc detail = EDocID.CARD_DETAIL.getDoc(); + private final IVDoc picture = EDocID.CARD_PICTURE.getDoc(); + private final IVDoc antes = EDocID.CARD_ANTES.getDoc(); + private final IVDoc devmode = EDocID.DEV_MODE.getDoc(); + + // Other instantiations + private final CMatchUI control = null; + private boolean isPopulated = false; + + /** */ + public void instantiate() { + + } + + /** */ + public void populate() { + if (isPopulated) { return; } + else { isPopulated = true; } + + SIOUtil.loadLayout(); + } + + /** */ + public void defaultLayout() { + final DragCell cell0 = new DragCell(); + final DragCell cell1 = new DragCell(); + final DragCell cell2 = new DragCell(); + final DragCell cell3 = new DragCell(); + final DragCell cell4 = new DragCell(); + final DragCell cell5 = new DragCell(); + final DragCell cell6 = new DragCell(); + + cell0.addDoc(stack); + cell0.addDoc(combat); + cell0.addDoc(log); + cell0.addDoc(players); + + cell1.addDoc(message); + cell1.addDoc(devmode); + + cell2.addDoc(field0); + cell6.addDoc(field1); + if (AllZone.getPlayersInGame().size() > 2) { cell2.addDoc(field2); } + if (AllZone.getPlayersInGame().size() > 3) { cell2.addDoc(field3); } + + if (AllZone.getPlayersInGame().size() > 1000) { cell3.addDoc(hand0); } + cell3.addDoc(hand1); + if (AllZone.getPlayersInGame().size() > 2) { cell2.addDoc(hand2); } + if (AllZone.getPlayersInGame().size() > 3) { cell2.addDoc(hand3); } + + cell4.addDoc(dock); + cell5.addDoc(detail); + cell5.addDoc(picture); + cell5.addDoc(antes); + + FView.SINGLETON_INSTANCE.addDragCell(cell0); + FView.SINGLETON_INSTANCE.addDragCell(cell1); + FView.SINGLETON_INSTANCE.addDragCell(cell2); + FView.SINGLETON_INSTANCE.addDragCell(cell3); + FView.SINGLETON_INSTANCE.addDragCell(cell4); + FView.SINGLETON_INSTANCE.addDragCell(cell5); + FView.SINGLETON_INSTANCE.addDragCell(cell6); + + cell0.setRoughBounds(0, 0, 0.2, 0.7); + cell1.setRoughBounds(0, 0.7, 0.2, 0.3); + cell2.setRoughBounds(0.2, 0, 0.6, 0.33); + cell3.setRoughBounds(0.2, 0.66, 0.6, 0.34); + cell4.setRoughBounds(0.8, 0, 0.2, 0.25); + cell5.setRoughBounds(0.8, 0.25, 0.2, 0.75); + cell6.setRoughBounds(0.2, 0.33, 0.6, 0.33); + + SResizingUtil.resizeWindow(); + } + + //========== Retrieval methods + + /** @return {@link forge.gui.match.CMatchUI} */ + public CMatchUI getControl() { + return this.control; + } + + /** @return {@link forge.gui.match.views.VDetail} */ + public VDetail getViewDetail() { + return ((VDetail) this.detail); + } + + /** @return {@link forge.gui.match.views.VPicture} */ + public VPicture getViewPicture() { + return ((VPicture) this.picture); + } + + /** @return {@link forge.gui.match.views.VDev} */ + public VDev getViewDevMode() { + return ((VDev) this.devmode); + } + + /** @return {@link java.util.List}<{@link forge.gui.match.nonsigleton.VField}> */ + public List getFieldViews() { + final List lst = new ArrayList(); + lst.add((VField) field0); + lst.add((VField) field1); + //lst.add((VField) field2); + //lst.add((VField) field3); + return lst; + } + + /** @return {@link javax.swing.JButton} */ + public JButton getBtnCancel() { + return ((VMessage) this.message).getBtnCancel(); + } + + /** @return {@link javax.swing.JButton} */ + public JButton getBtnOK() { + return ((VMessage) this.message).getBtnOK(); + } +} diff --git a/src/main/java/forge/view/match/ViewWinLose.java b/src/main/java/forge/gui/match/ViewWinLose.java similarity index 96% rename from src/main/java/forge/view/match/ViewWinLose.java rename to src/main/java/forge/gui/match/ViewWinLose.java index c535d824778..393e3eb4341 100644 --- a/src/main/java/forge/view/match/ViewWinLose.java +++ b/src/main/java/forge/gui/match/ViewWinLose.java @@ -1,4 +1,4 @@ -package forge.view.match; +package forge.gui.match; import java.awt.Color; import java.awt.Font; @@ -13,7 +13,6 @@ import net.miginfocom.swing.MigLayout; import forge.AllZone; import forge.Constant; import forge.Singletons; -import forge.control.match.ControlWinLose; import forge.game.GameType; import forge.game.phase.PhaseHandler; import forge.game.player.Player; diff --git a/src/main/java/forge/gui/match/controllers/CAntes.java b/src/main/java/forge/gui/match/controllers/CAntes.java new file mode 100644 index 00000000000..317c8532b22 --- /dev/null +++ b/src/main/java/forge/gui/match/controllers/CAntes.java @@ -0,0 +1,38 @@ +package forge.gui.match.controllers; + +import forge.Command; +import forge.gui.framework.ICDoc; + +/** + * Controls the ante panel in the match UI. + * + *

(C at beginning of class name denotes a control class.) + * + */ +public enum CAntes implements ICDoc { + /** */ + SINGLETON_INSTANCE; + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#initialize() + */ + @Override + public void initialize() { + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + } + +} diff --git a/src/main/java/forge/gui/match/controllers/CCombat.java b/src/main/java/forge/gui/match/controllers/CCombat.java new file mode 100644 index 00000000000..cd11686b3a0 --- /dev/null +++ b/src/main/java/forge/gui/match/controllers/CCombat.java @@ -0,0 +1,40 @@ +package forge.gui.match.controllers; + +import forge.Command; +import forge.gui.framework.ICDoc; +import forge.gui.match.views.VCombat; + +/** + * Controls the combat panel in the match UI. + * + *

(C at beginning of class name denotes a control class.) + * + */ +public enum CCombat implements ICDoc { + /** */ + SINGLETON_INSTANCE; + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#initialize() + */ + @Override + public void initialize() { + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + VCombat.SINGLETON_INSTANCE.updateCombat(""); + } + +} diff --git a/src/main/java/forge/control/match/ControlDetail.java b/src/main/java/forge/gui/match/controllers/CDetail.java similarity index 59% rename from src/main/java/forge/control/match/ControlDetail.java rename to src/main/java/forge/gui/match/controllers/CDetail.java index 5c97bb35a1e..f136ff32976 100644 --- a/src/main/java/forge/control/match/ControlDetail.java +++ b/src/main/java/forge/gui/match/controllers/CDetail.java @@ -15,28 +15,24 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package forge.control.match; +package forge.gui.match.controllers; import forge.Card; -import forge.view.match.ViewDetail; +import forge.Command; +import forge.gui.framework.ICDoc; +import forge.gui.match.views.VDetail; /** * * Controls the card detail area in the match UI. * + *

(C at beginning of class name denotes a control class.) */ -public class ControlDetail { - private final ViewDetail view; - private Card currentCard = null; +public enum CDetail implements ICDoc { + /** */ + SINGLETON_INSTANCE; - /** - * Controls the card detail area in the match UI. - * - * @param v   The CardViewer Swing component. - */ - public ControlDetail(final ViewDetail v) { - this.view = v; - } + private Card currentCard = null; /** * Shows card details and/or picture in sidebar cardview tabber. @@ -45,7 +41,7 @@ public class ControlDetail { */ public void showCard(final Card c) { this.currentCard = c; - this.view.getPnlDetail().setCard(c); + VDetail.SINGLETON_INSTANCE.getPnlDetail().setCard(c); } /** @@ -56,4 +52,26 @@ public class ControlDetail { public Card getCurrentCard() { return this.currentCard; } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#initialize() + */ + @Override + public void initialize() { + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + } } diff --git a/src/main/java/forge/gui/match/controllers/CDev.java b/src/main/java/forge/gui/match/controllers/CDev.java new file mode 100644 index 00000000000..90874b2bae9 --- /dev/null +++ b/src/main/java/forge/gui/match/controllers/CDev.java @@ -0,0 +1,110 @@ +package forge.gui.match.controllers; + +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + +import forge.Command; +import forge.Singletons; +import forge.gui.GuiDisplayUtil; +import forge.gui.framework.ICDoc; +import forge.gui.match.views.VDev; +import forge.properties.ForgePreferences.FPref; + +/** + * Controls the combat panel in the match UI. + * + *

(C at beginning of class name denotes a control class.) + * + */ +public enum CDev implements ICDoc { + /** */ + SINGLETON_INSTANCE; + + //========= Start mouse listener inits + private final MouseListener madMilling = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + VDev.SINGLETON_INSTANCE.getLblMilling().toggleEnabled(); } }; + + private final MouseListener madUnlimited = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + VDev.SINGLETON_INSTANCE.getLblUnlimitedLands().toggleEnabled(); } }; + + private final MouseListener madMana = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + GuiDisplayUtil.devModeGenerateMana(); } }; + + private final MouseListener madSetup = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + GuiDisplayUtil.devSetupGameState(); } }; + + private final MouseListener madTutor = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + GuiDisplayUtil.devModeTutor(); } }; + + private final MouseListener madAddAnyCard = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + GuiDisplayUtil.devModeAddAnyCard(); } }; + + private final MouseListener madCounter = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + GuiDisplayUtil.devModeAddCounter(); } }; + + private final MouseListener madTap = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + GuiDisplayUtil.devModeTapPerm(); } }; + + private final MouseListener madUntap = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + GuiDisplayUtil.devModeUntapPerm(); } }; + + private final MouseListener madLife = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + GuiDisplayUtil.devModeSetLife(); } }; + + //========== End mouse listener inits + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#initialize() + */ + @Override + public void initialize() { + VDev.SINGLETON_INSTANCE.getLblMilling().addMouseListener(madMilling); + VDev.SINGLETON_INSTANCE.getLblUnlimitedLands().addMouseListener(madUnlimited); + VDev.SINGLETON_INSTANCE.getLblGenerateMana().addMouseListener(madMana); + VDev.SINGLETON_INSTANCE.getLblSetupGame().addMouseListener(madSetup); + VDev.SINGLETON_INSTANCE.getLblTutor().addMouseListener(madTutor); + VDev.SINGLETON_INSTANCE.getAnyCard().addMouseListener(madAddAnyCard); + VDev.SINGLETON_INSTANCE.getLblCounterPermanent().addMouseListener(madCounter); + VDev.SINGLETON_INSTANCE.getLblTapPermanent().addMouseListener(madTap); + VDev.SINGLETON_INSTANCE.getLblUntapPermanent().addMouseListener(madUntap); + VDev.SINGLETON_INSTANCE.getLblSetLife().addMouseListener(madLife); + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.DEV_MILLING_LOSS)) { + VDev.SINGLETON_INSTANCE.getLblMilling().setEnabled(true); + } else { + VDev.SINGLETON_INSTANCE.getLblMilling().setEnabled(false); + } + + if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.DEV_UNLIMITED_LAND)) { + VDev.SINGLETON_INSTANCE.getLblUnlimitedLands().setEnabled(true); + } else { + VDev.SINGLETON_INSTANCE.getLblUnlimitedLands().setEnabled(false); + } + } + +} diff --git a/src/main/java/forge/control/match/ControlDock.java b/src/main/java/forge/gui/match/controllers/CDock.java similarity index 69% rename from src/main/java/forge/control/match/ControlDock.java rename to src/main/java/forge/gui/match/controllers/CDock.java index 4d70131a6af..2c4faaa37fe 100644 --- a/src/main/java/forge/control/match/ControlDock.java +++ b/src/main/java/forge/gui/match/controllers/CDock.java @@ -15,11 +15,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package forge.control.match; +package forge.gui.match.controllers; import java.awt.Toolkit; import java.awt.datatransfer.StringSelection; import java.awt.event.ActionEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -28,30 +30,25 @@ import java.util.Map.Entry; import javax.swing.JOptionPane; import forge.AllZone; +import forge.Command; import forge.Constant; import forge.Singletons; import forge.deck.Deck; import forge.gui.ForgeAction; +import forge.gui.OverlayUtils; +import forge.gui.framework.ICDoc; +import forge.gui.match.views.VDock; import forge.item.CardPrinted; import forge.properties.NewConstants; -import forge.view.match.ViewDock; /** - * Child controller, handles dock button operations. + * Controls the dock panel in the match UI. * + *

(C at beginning of class name denotes a control class.) */ -public class ControlDock { - private final ViewDock view; - - /** - * Child controller, handles dock button operations. - * - * @param v - *   ViewDock obj - */ - public ControlDock(final ViewDock v) { - this.view = v; - } +public enum CDock implements ICDoc { + /** */ + SINGLETON_INSTANCE; /** Concede game, bring up WinLose UI. */ public void concede() { @@ -59,22 +56,14 @@ public class ControlDock { Singletons.getModel().getGameAction().checkStateEffects(); } - /** - * Gets the view. - * - * @return ViewDock - */ - public ViewDock getView() { - return this.view; - } - /** * End turn. */ public void endTurn() { // Big thanks to you, Gameplay Guru, since I was too lazy to figure this // out before release. Doublestrike 24-11-11 - System.err.println("forge.control.match > ControlDock > endTurn()"); + // + System.err.println("forge.control.match > CDock > endTurn()"); System.out.println("Should skip to the end of turn, or entire turn."); System.err.println("If some gameplay guru could implement this, that would be great..."); } @@ -160,4 +149,45 @@ public class ControlDock { } } } // End DeckListAction + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#initialize() + */ + @Override + public void initialize() { + VDock.SINGLETON_INSTANCE.getBtnConcede() + .addMouseListener(new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + concede(); } }); + + VDock.SINGLETON_INSTANCE.getBtnSettings() + .addMouseListener(new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + OverlayUtils.showOverlay(); } }); + + VDock.SINGLETON_INSTANCE.getBtnEndTurn() + .addMouseListener(new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + endTurn(); } }); + + VDock.SINGLETON_INSTANCE.getBtnViewDeckList() + .addMouseListener(new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + viewDeckList(); } }); + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + } } diff --git a/src/main/java/forge/gui/match/controllers/CLog.java b/src/main/java/forge/gui/match/controllers/CLog.java new file mode 100644 index 00000000000..328351be8d9 --- /dev/null +++ b/src/main/java/forge/gui/match/controllers/CLog.java @@ -0,0 +1,53 @@ +package forge.gui.match.controllers; + +import java.util.Observable; +import java.util.Observer; + +import forge.AllZone; +import forge.Command; +import forge.gui.framework.ICDoc; +import forge.gui.match.views.VLog; + +/** + * Controls the combat panel in the match UI. + * + *

(C at beginning of class name denotes a control class.) + * + */ +public enum CLog implements ICDoc, Observer { + /** */ + SINGLETON_INSTANCE; + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#initialize() + */ + @Override + public void initialize() { + AllZone.getGameLog().addObserver(this); + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + VLog.SINGLETON_INSTANCE.updateConsole(); + } + + /* (non-Javadoc) + * @see java.util.Observer#update(java.util.Observable, java.lang.Object) + */ + @Override + public void update(Observable arg0, Object arg1) { + update(); + } + +} diff --git a/src/main/java/forge/gui/match/controllers/CMessage.java b/src/main/java/forge/gui/match/controllers/CMessage.java new file mode 100644 index 00000000000..5cc2917b4e3 --- /dev/null +++ b/src/main/java/forge/gui/match/controllers/CMessage.java @@ -0,0 +1,114 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.gui.match.controllers; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import forge.Command; +import forge.Constant; +import forge.Singletons; +import forge.gui.GuiInput; +import forge.gui.framework.ICDoc; +import forge.gui.framework.SDisplayUtil; +import forge.gui.match.views.VMessage; + +/** + * Controls the message panel in the match UI. + * + *

(C at beginning of class name denotes a control class.) + */ +public enum CMessage implements ICDoc { + /** */ + SINGLETON_INSTANCE; + + private final GuiInput inputControl = new GuiInput(); + private final ActionListener actCancel = new ActionListener() { + @Override + public void actionPerformed(final ActionEvent evt) { + inputControl.selectButtonCancel(); + VMessage.SINGLETON_INSTANCE.getBtnOK().requestFocusInWindow(); + } + }; + + private final ActionListener actOK = new ActionListener() { + @Override + public void actionPerformed(final ActionEvent evt) { + inputControl.selectButtonOK(); + + if (Singletons.getModel().getGameState().getPhaseHandler().isNeedToNextPhase()) { + // moves to next turn + Singletons.getModel().getGameState().getPhaseHandler().setNeedToNextPhase(false); + Singletons.getModel().getGameState().getPhaseHandler().nextPhase(); + } + VMessage.SINGLETON_INSTANCE.getBtnOK().requestFocusInWindow(); + } + }; + + @Override + public void initialize() { + VMessage.SINGLETON_INSTANCE.getBtnCancel().removeActionListener(actCancel); + VMessage.SINGLETON_INSTANCE.getBtnCancel().addActionListener(actCancel); + + VMessage.SINGLETON_INSTANCE.getBtnOK().removeActionListener(actOK); + VMessage.SINGLETON_INSTANCE.getBtnOK().addActionListener(actOK); + } + + /** + * Gets the input control. + * + * @return GuiInput + */ + public GuiInput getInputControl() { + return this.inputControl; + } + + /** @param s0   {@link java.lang.String} */ + public void setMessage(String s0) { + VMessage.SINGLETON_INSTANCE.getTarMessage().setText(s0); + } + + /** Updates count label in input area. */ + public void updateGameCount() { + VMessage.SINGLETON_INSTANCE.getLblGames().setText("Game #" + + (Singletons.getModel().getMatchState().getGamesPlayedCount() + 1) + + " of " + Singletons.getModel().getMatchState().getGamesPerMatch() + + "
" + Constant.Runtime.getGameType().toString() + " mode"); + } + + /** Flashes animation on input panel if play is currently waiting on input. */ + public void remind() { + SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE); + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + + } +} diff --git a/src/main/java/forge/control/match/ControlPicture.java b/src/main/java/forge/gui/match/controllers/CPicture.java similarity index 57% rename from src/main/java/forge/control/match/ControlPicture.java rename to src/main/java/forge/gui/match/controllers/CPicture.java index 8e8822ed2f1..b1b2d82c4d1 100644 --- a/src/main/java/forge/control/match/ControlPicture.java +++ b/src/main/java/forge/gui/match/controllers/CPicture.java @@ -15,36 +15,23 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package forge.control.match; +package forge.gui.match.controllers; import forge.Card; -import forge.view.match.ViewPicture; +import forge.Command; +import forge.gui.framework.ICDoc; +import forge.gui.match.views.VPicture; /** + * Controls the card picture panel in the match UI. * - * Controls the vertical tabber in sidebar used for viewing card details and - * picture. - * + *

(C at beginning of class name denotes a control class.) */ -public class ControlPicture { - private final ViewPicture view; +public enum CPicture implements ICDoc { + /** */ + SINGLETON_INSTANCE; + private Card currentCard = null; - /** - * Controls the vertical tabber in sidebar used for viewing card details and - * picture. - * - * @param v - *   The CardViewer Swing component. - */ - public ControlPicture(final ViewPicture v) { - this.view = v; - } - - /** @return ViewPicture */ - public ViewPicture getView() { - return view; - } - /** * Shows card details and/or picture in sidebar cardview tabber. * @@ -53,7 +40,7 @@ public class ControlPicture { */ public void showCard(final Card c) { this.currentCard = c; - this.view.getPnlPicture().setCard(c); + VPicture.SINGLETON_INSTANCE.getPnlPicture().setCard(c); } /** @@ -64,4 +51,26 @@ public class ControlPicture { public Card getCurrentCard() { return this.currentCard; } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#initialize() + */ + @Override + public void initialize() { + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + } } diff --git a/src/main/java/forge/gui/match/controllers/CPlayers.java b/src/main/java/forge/gui/match/controllers/CPlayers.java new file mode 100644 index 00000000000..bbde10ba063 --- /dev/null +++ b/src/main/java/forge/gui/match/controllers/CPlayers.java @@ -0,0 +1,42 @@ +package forge.gui.match.controllers; + +import forge.AllZone; +import forge.Command; +import forge.gui.framework.ICDoc; +import forge.gui.match.views.VPlayers; + +/** + * Controls the combat panel in the match UI. + * + *

(C at beginning of class name denotes a control class.) + * + */ +public enum CPlayers implements ICDoc { + /** */ + SINGLETON_INSTANCE; + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#initialize() + */ + @Override + public void initialize() { + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + VPlayers.SINGLETON_INSTANCE.updatePlayerLabels(AllZone.getComputerPlayer()); + VPlayers.SINGLETON_INSTANCE.updatePlayerLabels(AllZone.getHumanPlayer()); + } + +} diff --git a/src/main/java/forge/gui/match/controllers/CStack.java b/src/main/java/forge/gui/match/controllers/CStack.java new file mode 100644 index 00000000000..338aebfd647 --- /dev/null +++ b/src/main/java/forge/gui/match/controllers/CStack.java @@ -0,0 +1,52 @@ +package forge.gui.match.controllers; + +import java.util.Observable; +import java.util.Observer; + +import forge.AllZone; +import forge.Command; +import forge.gui.framework.ICDoc; +import forge.gui.match.views.VStack; + +/** + * Controls the combat panel in the match UI. + * + *

(C at beginning of class name denotes a control class.) + * + */ +public enum CStack implements ICDoc, Observer { + /** */ + SINGLETON_INSTANCE; + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#initialize() + */ + @Override + public void initialize() { + AllZone.getStack().addObserver(this); + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + VStack.SINGLETON_INSTANCE.updateStack(); + } + + /* (non-Javadoc) + * @see java.util.Observer#update(java.util.Observable, java.lang.Object) + */ + @Override + public void update(Observable arg0, Object arg1) { + update(); + } +} diff --git a/src/main/java/forge/gui/match/nonsingleton/CField.java b/src/main/java/forge/gui/match/nonsingleton/CField.java new file mode 100644 index 00000000000..96b11d2f72a --- /dev/null +++ b/src/main/java/forge/gui/match/nonsingleton/CField.java @@ -0,0 +1,579 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.gui.match.nonsingleton; + +import java.awt.event.ActionEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionAdapter; +import java.awt.event.MouseMotionListener; +import java.util.ArrayList; +import java.util.Observable; +import java.util.Observer; + +import com.google.code.jyield.Generator; +import com.google.code.jyield.YieldUtils; + +import forge.AllZone; +import forge.Card; +import forge.CardList; +import forge.Command; +import forge.Constant; +import forge.Singletons; +import forge.card.cardfactory.CardFactoryUtil; +import forge.control.input.Input; +import forge.control.input.InputAttack; +import forge.control.input.InputBlock; +import forge.control.input.InputMana; +import forge.control.input.InputPayManaCost; +import forge.control.input.InputPayManaCostAbility; +import forge.game.player.Player; +import forge.game.zone.PlayerZone; +import forge.game.zone.ZoneType; +import forge.gui.ForgeAction; +import forge.gui.GuiDisplayUtil; +import forge.gui.GuiUtils; +import forge.gui.framework.ICDoc; +import forge.gui.match.CMatchUI; +import forge.gui.match.controllers.CMessage; +import forge.gui.toolbox.FLabel; +import forge.properties.ForgeProps; +import forge.properties.NewConstants; +import forge.properties.NewConstants.Lang.GuiDisplay.ComputerHand; +import forge.properties.NewConstants.Lang.GuiDisplay.ComputerLibrary; +import forge.properties.NewConstants.Lang.GuiDisplay.HumanHand; +import forge.properties.NewConstants.Lang.GuiDisplay.HumanLibrary; + +/** + * Controls Swing components of a player's field instance. + */ +public class CField implements ICDoc { + private final Player player; + private final VField view; + private boolean initializedAlready = false; + + private MouseMotionListener mmlCardOver = new MouseMotionAdapter() { @Override + public void mouseMoved(final MouseEvent e) { + cardoverAction(); } }; + + private final MouseListener madHand = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + handAction(); } }; + + private final MouseListener madAvatar = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + avatarAction(); } }; + + private final MouseListener madExiled = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + exiledAction(); } }; + + private final MouseListener madLibrary = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + libraryAction(); } }; + + private final MouseListener madGraveyard = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + graveyardAction(); } }; + + private final MouseListener madFlashback = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + flashbackAction(); } }; + + private final MouseListener madCardClick = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + cardclickAction(e); } }; + + private final MouseListener madBlack = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + blackAction(); } }; + + private final MouseListener madBlue = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + blueAction(); } }; + + private final MouseListener madGreen = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + greenAction(); } }; + + private final MouseListener madRed = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + redAction(); } }; + + private final MouseListener madWhite = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + whiteAction(); } }; + + private final MouseListener madColorless = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + colorlessAction(); } }; + + // Hand, Graveyard, Library, Flashback, Exile zones, attached to hand. + private final Observer observerZones = new Observer() { + @Override + public void update(final Observable a, final Object b) { + CField.this.view.updateZones(CField.this.player); + } + }; + + // Life total, poison total, and keywords, attached directly to Player. + private final Observer observerDetails = new Observer() { + @Override + public void update(final Observable a, final Object b) { + CField.this.view.updateDetails(CField.this.player); + } + }; + + // Card play area, attached to battlefield zone. + private final Observer observerPlay = new Observer() { + @Override + public void update(final Observable a, final Object b) { + final PlayerZone pZone = (PlayerZone) a; + GuiDisplayUtil.setupPlayZone(CField.this.view.getTabletop(), pZone.getCards(false)); + } + }; + + /** + * Controls Swing components of a player's field instance. + * + * @param p0   {@link forge.game.player.Player} + * @param v0   {@link forge.gui.match.nonsingleton.VField} + */ + public CField(final Player p0, final VField v0) { + this.player = p0; + this.view = v0; + } + + @Override + public void initialize() { + if (initializedAlready) { return; } + else { initializedAlready = true; } + + // Observers + CField.this.player.getZone(ZoneType.Hand).addObserver(observerZones); + CField.this.player.getZone(ZoneType.Battlefield).addObserver(observerPlay); + CField.this.player.addObserver(observerDetails); + + // Listeners + // Battlefield card clicks + this.view.getTabletop().addMouseListener(madCardClick); + + // Battlefield card mouseover + this.view.getTabletop().addMouseMotionListener(mmlCardOver); + + // Player select + this.view.getAvatarArea().addMouseListener(madAvatar); + + // Detail label listeners + ((FLabel) this.view.getLblGraveyard()).setHoverable(true); + this.view.getLblGraveyard().addMouseListener(madGraveyard); + + ((FLabel) this.view.getLblExile()).setHoverable(true); + this.view.getLblExile().addMouseListener(madExiled); + + this.view.getLblLibrary().addMouseListener(madLibrary); + this.view.getLblHand().addMouseListener(madHand); + + ((FLabel) this.view.getLblFlashback()).setHoverable(true); + this.view.getLblFlashback().addMouseListener(madFlashback); + + ((FLabel) this.view.getLblBlack()).setHoverable(true); + this.view.getLblBlack().addMouseListener(madBlack); + + ((FLabel) this.view.getLblBlue()).setHoverable(true); + this.view.getLblBlue().addMouseListener(madBlue); + + ((FLabel) this.view.getLblGreen()).setHoverable(true); + this.view.getLblGreen().addMouseListener(madGreen); + + ((FLabel) this.view.getLblRed()).setHoverable(true); + this.view.getLblRed().removeMouseListener(madRed); + this.view.getLblRed().addMouseListener(madRed); + + ((FLabel) this.view.getLblWhite()).setHoverable(true); + this.view.getLblWhite().removeMouseListener(madWhite); + this.view.getLblWhite().addMouseListener(madWhite); + + ((FLabel) this.view.getLblColorless()).setHoverable(true); + this.view.getLblColorless().addMouseListener(madColorless); + } + + @Override + public void update() { + } + + /** @return {@link forge.game.player.Player} */ + public Player getPlayer() { + return this.player; + } + + /** @return {@link forge.gui.nonsingleton.VField} */ + public VField getView() { + return this.view; + } + + /** + * Resets all phase buttons to "inactive", so highlight won't be drawn on + * them. "Enabled" state remains the same. + */ + public void resetPhaseButtons() { + this.view.getLblUpkeep().setActive(false); + this.view.getLblDraw().setActive(false); + this.view.getLblMain1().setActive(false); + this.view.getLblBeginCombat().setActive(false); + this.view.getLblDeclareAttackers().setActive(false); + this.view.getLblDeclareBlockers().setActive(false); + this.view.getLblFirstStrike().setActive(false); + this.view.getLblCombatDamage().setActive(false); + this.view.getLblEndCombat().setActive(false); + this.view.getLblMain2().setActive(false); + this.view.getLblEndTurn().setActive(false); + this.view.getLblCleanup().setActive(false); + } + + /** + * Receives click and programmatic requests for viewing data stacks in the + * "zones" of a player field: hand, library, etc. + * + */ + private class ZoneAction extends ForgeAction { + private static final long serialVersionUID = -5822976087772388839L; + private final PlayerZone zone; + private final String title; + + /** + * Receives click and programmatic requests for viewing data stacks in + * the "zones" of a player field: hand, graveyard, etc. The library + * "zone" is an exception to the rule; it's handled in DeckListAction. + * + * @param zone + *   PlayerZone obj + * @param property + *   String obj + */ + public ZoneAction(final PlayerZone zone, final String property) { + super(property); + this.title = ForgeProps.getLocalized(property + "/title"); + this.zone = zone; + } + + /** + * @param e + *   ActionEvent obj + */ + @Override + public void actionPerformed(final ActionEvent e) { + Generator c = YieldUtils.toGenerator(this.getCardsAsIterable()); + + if (AllZone.getNameChanger().shouldChangeCardName()) { + c = AllZone.getNameChanger().changeCard(c); + } + + final Iterable myIterable = YieldUtils.toIterable(c); + final ArrayList choices = YieldUtils.toArrayList(myIterable); + + final ArrayList choices2 = new ArrayList(); + + if (choices.isEmpty()) { + GuiUtils.chooseOneOrNone(this.title, new String[] { "no cards" }); + } else { + for (int i = 0; i < choices.size(); i++) { + final Card crd = choices.get(i); + if (crd.isFaceDown()) { + if (crd.getController().isComputer() || !crd.hasKeyword("You may look at this card.")) { + final Card faceDown = new Card(); + faceDown.setName("Face Down"); + choices2.add(faceDown); + } else { + final Card faceDown = AllZone.getCardFactory().copyCard(crd); + faceDown.turnFaceUp(); + choices2.add(faceDown); + } + } else { + choices2.add(crd); + } + } + final Card choice = (Card) GuiUtils.chooseOneOrNone(this.title, choices2.toArray()); + if (choice != null) { + this.doAction(choice); + } + } + } + + protected Iterable getCardsAsIterable() { + return this.zone.getCards(); + } + + protected void doAction(final Card c) { + } + } // End ZoneAction + + /** */ + private void handAction() { + if (!CField.this.player.isComputer()) { + new ZoneAction(CField.this.player.getZone(ZoneType.Hand), HumanHand.BASE) + .actionPerformed(null); + } else if (Constant.Runtime.DEV_MODE[0] + || CField.this.player.hasKeyword("Play with your hand revealed.")) { + new ZoneAction(CField.this.player.getZone(ZoneType.Hand), ComputerHand.BASE) + .actionPerformed(null); + } + } + + /** */ + private void flashbackAction() { + if (!CField.this.player.isComputer()) { + new ZoneAction(AllZone.getHumanPlayer().getZone(ZoneType.Graveyard), + NewConstants.Lang.GuiDisplay.HUMAN_FLASHBACK) { + + private static final long serialVersionUID = 8120331222693706164L; + + @Override + protected Iterable getCardsAsIterable() { + return CardFactoryUtil.getExternalZoneActivationCards(AllZone.getHumanPlayer()); + } + + @Override + protected void doAction(final Card c) { + Singletons.getModel().getGameAction().playCard(c); + } + } .actionPerformed(null); + } + else { + new ZoneAction(CField.this.player.getZone(ZoneType.Graveyard), + NewConstants.Lang.GuiDisplay.COMPUTER_FLASHBACK) { + + private static final long serialVersionUID = 8120331222693706164L; + + @Override + protected Iterable getCardsAsIterable() { + return CardFactoryUtil.getExternalZoneActivationCards(AllZone.getComputerPlayer()); + } + + @Override + protected void doAction(final Card c) { + Singletons.getModel().getGameAction().playCard(c); + } + } .actionPerformed(null); + } + } + + /** */ + private void libraryAction() { + if (!Constant.Runtime.DEV_MODE[0]) { return; } + + if (!CField.this.player.isComputer()) { + new ZoneAction(CField.this.player.getZone(ZoneType.Library), HumanLibrary.BASE) + .actionPerformed(null); + } else { + new ZoneAction(CField.this.player.getZone(ZoneType.Library), ComputerLibrary.BASE) + .actionPerformed(null); + } + } + + /** */ + private void exiledAction() { + if (CField.this.player.isComputer()) { + new ZoneAction(CField.this.player.getZone(ZoneType.Exile), + NewConstants.Lang.GuiDisplay.COMPUTER_EXILED).actionPerformed(null); + } else { + new ZoneAction(CField.this.player.getZone(ZoneType.Exile), + NewConstants.Lang.GuiDisplay.HUMAN_EXILED).actionPerformed(null); + } + } + + private void graveyardAction() { + if (CField.this.player.isComputer()) { + new ZoneAction(CField.this.player.getZone(ZoneType.Graveyard), + NewConstants.Lang.GuiDisplay.COMPUTER_GRAVEYARD).actionPerformed(null); + } else { + new ZoneAction(CField.this.player.getZone(ZoneType.Graveyard), + NewConstants.Lang.GuiDisplay.HUMAN_GRAVEYARD).actionPerformed(null); + } + } + + private void avatarAction() { + if (CField.this.player.isComputer()) { + CMessage.SINGLETON_INSTANCE + .getInputControl().selectPlayer(AllZone.getComputerPlayer()); + } else { + CMessage.SINGLETON_INSTANCE + .getInputControl().selectPlayer(AllZone.getHumanPlayer()); + } + } + + /** */ + private void cardoverAction() { + final Card c = CField.this.view.getTabletop().getCardFromMouseOverPanel(); + if (c != null) { + CMatchUI.SINGLETON_INSTANCE.setCard(c); + } + } + + /** */ + private void cardclickAction(final MouseEvent e) { + // original version: + // final Card c = t.getDetailController().getCurrentCard(); + // Roujin's bug fix version dated 2-12-2012 + final Card c = CField.this.view.getTabletop().getCardFromMouseOverPanel(); + + final Input input = CMessage.SINGLETON_INSTANCE.getInputControl().getInput(); + + if (c != null && c.isInZone(ZoneType.Battlefield)) { + if (c.isTapped() + && ((input instanceof InputPayManaCost) || (input instanceof InputPayManaCostAbility))) { + final forge.view.arcane.CardPanel cardPanel = CField.this.view.getTabletop().getCardPanel( + c.getUniqueNumber()); + for (final forge.view.arcane.CardPanel cp : cardPanel.getAttachedPanels()) { + if (cp.getCard().isUntapped()) { + break; + } + } + } + + final CardList att = AllZone.getCombat().getAttackerList(); + if ((c.isTapped() || c.hasSickness() || ((c.hasKeyword("Vigilance")) && att.contains(c))) + && (input instanceof InputAttack)) { + final forge.view.arcane.CardPanel cardPanel = CField.this.view.getTabletop().getCardPanel( + c.getUniqueNumber()); + for (final forge.view.arcane.CardPanel cp : cardPanel.getAttachedPanels()) { + if (cp.getCard().isUntapped() && !cp.getCard().hasSickness()) { + break; + } + } + } + + if (e.isMetaDown()) { + if (att.contains(c) && (input instanceof InputAttack) + && !c.hasKeyword("CARDNAME attacks each turn if able.")) { + c.untap(); + AllZone.getCombat().removeFromCombat(c); + } else if (input instanceof InputBlock) { + if (c.getController().isHuman()) { + AllZone.getCombat().removeFromCombat(c); + } + ((InputBlock) input).removeFromAllBlocking(c); + } + } else { + //Yosei, the Morning Star required cards to be chosen on computer side + //earlier it was enforced that cards must be in player zone + //this can potentially break some other functionality + //(tapping lands works ok but some custom cards may not...) + if (c.getController() != null) { + input.selectCard(c, c.getController().getZone(ZoneType.Battlefield)); + } else { + //in weird case card has no controller revert to default behaviour + input.selectCard(c, AllZone.getHumanPlayer().getZone(ZoneType.Battlefield)); + } + } + } + } + + /** */ + private void blackAction() { + if (CField.this.player.isComputer()) { + System.out.println("Stop trying to spend the AI's mana"); + // TODO: Mindslaver might need to add changes here + } else { + final Input in = AllZone.getInputControl().getInput(); + if (in instanceof InputMana) { + // Do something + ((InputMana) in).selectManaPool(Constant.Color.BLACK); + } + } + } + + /** */ + private void blueAction() { + if (CField.this.player.isComputer()) { + System.out.println("Stop trying to spend the AI's mana"); + // TODO: Mindslaver might need to add changes here + } else { + final Input in = AllZone.getInputControl().getInput(); + if (in instanceof InputMana) { + // Do something + ((InputMana) in).selectManaPool(Constant.Color.BLUE); + } + } + } + + /** */ + private void greenAction() { + if (CField.this.player.isComputer()) { + System.out.println("Stop trying to spend the AI's mana"); + // TODO: Mindslaver might need to add changes here + } else { + final Input in = AllZone.getInputControl().getInput(); + if (in instanceof InputMana) { + // Do something + ((InputMana) in).selectManaPool(Constant.Color.GREEN); + } + } + } + + /** */ + private void redAction() { + if (CField.this.player.isComputer()) { + System.out.println("Stop trying to spend the AI's mana"); + // TODO: Mindslaver might need to add changes here + } else { + final Input in = AllZone.getInputControl().getInput(); + if (in instanceof InputMana) { + // Do something + ((InputMana) in).selectManaPool(Constant.Color.RED); + } + } + } + + /** */ + private void whiteAction() { + if (CField.this.player.isComputer()) { + System.out.println("Stop trying to spend the AI's mana"); + // TODO: Mindslaver might need to add changes here + } else { + final Input in = AllZone.getInputControl().getInput(); + if (in instanceof InputMana) { + // Do something + ((InputMana) in).selectManaPool(Constant.Color.WHITE); + } + } + } + + /** */ + private void colorlessAction() { + if (CField.this.player.isComputer()) { + System.out.println("Stop trying to spend the AI's mana"); + // TODO: Mindslaver might need to add changes here + } else { + final Input in = AllZone.getInputControl().getInput(); + if (in instanceof InputMana) { + // Do something + ((InputMana) in).selectManaPool(Constant.Color.COLORLESS); + } + } + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } +} // End class CField diff --git a/src/main/java/forge/gui/match/nonsingleton/CHand.java b/src/main/java/forge/gui/match/nonsingleton/CHand.java new file mode 100644 index 00000000000..de7571bb1d8 --- /dev/null +++ b/src/main/java/forge/gui/match/nonsingleton/CHand.java @@ -0,0 +1,288 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.gui.match.nonsingleton; + +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionAdapter; +import java.awt.event.MouseMotionListener; +import java.util.ArrayList; +import java.util.List; +import java.util.Observable; +import java.util.Observer; + +import javax.swing.JLayeredPane; +import javax.swing.SwingUtilities; + +import forge.AllZone; +import forge.Card; +import forge.Command; +import forge.Singletons; +import forge.game.player.Player; +import forge.game.zone.PlayerZone; +import forge.game.zone.ZoneType; +import forge.gui.framework.ICDoc; +import forge.gui.match.CMatchUI; +import forge.gui.match.VMatchUI; +import forge.gui.match.controllers.CMessage; +import forge.view.arcane.CardPanel; +import forge.view.arcane.HandArea; +import forge.view.arcane.util.Animation; + +/** + * Controls Swing components of a player's hand instance. + * + */ +public class CHand implements ICDoc { + private final Player player; + private final VHand view; + private boolean initializedAlready = false; + + private final List cardsInPanel = new ArrayList();; + + private final MouseListener madCardClick = new MouseAdapter() { @Override + public void mousePressed(final MouseEvent e) { + cardclickAction(e); } }; + + private final MouseMotionListener madCardMove = new MouseMotionAdapter() { @Override + public void mouseMoved(final MouseEvent me) { + cardmoveAction(); } }; + + private final Observer o1 = new Observer() { @Override + public void update(final Observable a, final Object b) { + observerAction(a); } }; + + /** + * Controls Swing components of a player's hand instance. + * + * @param p0   {@link forge.game.player.Player} + * @param v0   {@link forge.gui.match.nonsingleton.VHand} + */ + public CHand(final Player p0, final VHand v0) { + this.player = p0; + this.view = v0; + } + + @Override + public void initialize() { + if (initializedAlready) { return; } + else { initializedAlready = true; } + + player.getZone(ZoneType.Hand).addObserver(o1); + + view.getHandArea().addMouseListener(madCardClick); + view.getHandArea().addMouseMotionListener(madCardMove); + } + + /** + * Adds various listeners for cards in hand. Uses CardPanel instance from + * ViewHand. + * + * @param c + *   CardPanel object + */ + public void addCardPanelListeners(final CardPanel c) { + // Grab top level controller to facilitate interaction between children + final Card cardobj = c.getCard(); + + // Sidebar pic/detail on card hover + c.addMouseListener(new MouseAdapter() { + @Override + public void mouseEntered(final MouseEvent e) { + CMatchUI.SINGLETON_INSTANCE.setCard(cardobj); + } + }); + + // Mouse press + c.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(final MouseEvent e) { + if (e.getButton() != MouseEvent.BUTTON1) { return; } + + CMessage.SINGLETON_INSTANCE.getInputControl() + .selectCard(cardobj, AllZone.getHumanPlayer().getZone(ZoneType.Hand)); + } + }); + } + + /** + * Adds the card. + * + * @param c + *   Card object + */ + public void addCard(final Card c) { + this.cardsInPanel.add(c); + //this.view.refreshLayout(); + } + + /** + * Adds the cards. + * + * @param c + *   List of Card objects + */ + public void addCards(final List c) { + this.cardsInPanel.addAll(c); + //this.view.refreshLayout(); + } + + /** + * Gets the cards. + * + * @return List + */ + public List getCards() { + return this.cardsInPanel; + } + + /** + * Removes the card. + * + * @param c + *   Card object + */ + public void removeCard(final Card c) { + this.cardsInPanel.remove(c); + //this.view.refreshLayout(); + } + + /** + * Removes the cards. + * + * @param c + *   List of Card objects + */ + public void removeCards(final List c) { + this.cardsInPanel.removeAll(c); + //this.view.refreshLayout(); + } + + /** + * Reset cards. + * + * @param c + *   List of Card objects + */ + public void resetCards(final List c) { + this.cardsInPanel.clear(); + this.addCards(c); + } + + private void cardmoveAction() { + final Card c = view.getHandArea().getCardFromMouseOverPanel(); + if (c != null) { + CMatchUI.SINGLETON_INSTANCE.setCard(c); + } + } + + private void cardclickAction(final MouseEvent e) { + if (e.getButton() != MouseEvent.BUTTON1) { + return; + } + final Card c = view.getHandArea().getCardFromMouseOverPanel(); + if (c != null) { + CMessage.SINGLETON_INSTANCE.getInputControl().selectCard(c, AllZone.getHumanPlayer().getZone(ZoneType.Hand)); + VMatchUI.SINGLETON_INSTANCE.getBtnOK().requestFocusInWindow(); + } + } + + private void observerAction(final Observable a) { + final PlayerZone pZone = (PlayerZone) a; + final HandArea p = view.getHandArea(); + final Rectangle rctLibraryLabel = CMatchUI.SINGLETON_INSTANCE + .getFieldControls().get(1) + .getView().getLblLibrary().getBounds(); + final List c = pZone.getCards(); + + // Animation starts from the library label and runs to the hand panel. + // This check prevents animation running if label hasn't been realized yet. + if (rctLibraryLabel.isEmpty() || p.getWidth() <= 0) { + return; + } + + List tmp, diff; + tmp = new ArrayList(); + for (final forge.view.arcane.CardPanel cpa : p.getCardPanels()) { + tmp.add(cpa.getGameCard()); + } + diff = new ArrayList(tmp); + diff.removeAll(c); + if (diff.size() == p.getCardPanels().size()) { + p.clear(); + } else { + for (final Card card : diff) { + p.removeCardPanel(p.getCardPanel(card.getUniqueNumber())); + } + } + diff = new ArrayList(c); + diff.removeAll(tmp); + + JLayeredPane layeredPane = Singletons.getView().getFrame().getLayeredPane(); + int fromZoneX = 0, fromZoneY = 0; + + final Point zoneLocation = SwingUtilities.convertPoint(CMatchUI.SINGLETON_INSTANCE + .getFieldControls() + .get(1).getView().getLblLibrary(), + Math.round(rctLibraryLabel.width / 2.0f), Math.round(rctLibraryLabel.height / 2.0f), layeredPane); + fromZoneX = zoneLocation.x; + fromZoneY = zoneLocation.y; + int startWidth, startX, startY; + startWidth = 10; + startX = fromZoneX - Math.round(startWidth / 2.0f); + startY = fromZoneY - Math.round(Math.round(startWidth * forge.view.arcane.CardPanel.ASPECT_RATIO) / 2.0f); + + int endWidth, endX, endY; + forge.view.arcane.CardPanel toPanel = null; + + for (final Card card : diff) { + toPanel = p.addCard(card); + endWidth = toPanel.getCardWidth(); + final Point toPos = SwingUtilities.convertPoint(view.getHandArea(), + toPanel.getCardLocation(), layeredPane); + endX = toPos.x; + endY = toPos.y; + + final forge.view.arcane.CardPanel animationPanel = new forge.view.arcane.CardPanel(card); + if (Singletons.getView().getFrame().isShowing()) { + Animation.moveCard(startX, startY, startWidth, endX, endY, endWidth, animationPanel, toPanel, + layeredPane, 500); + } else { + Animation.moveCard(toPanel); + } + } + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + } +} diff --git a/src/main/java/forge/gui/match/nonsingleton/VField.java b/src/main/java/forge/gui/match/nonsingleton/VField.java index 3f0db6337c2..345638fd53b 100644 --- a/src/main/java/forge/gui/match/nonsingleton/VField.java +++ b/src/main/java/forge/gui/match/nonsingleton/VField.java @@ -18,7 +18,6 @@ package forge.gui.match.nonsingleton; import java.awt.Color; -import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; @@ -30,15 +29,21 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingConstants; -import javax.swing.border.Border; import javax.swing.border.LineBorder; import javax.swing.border.MatteBorder; import net.miginfocom.swing.MigLayout; -import forge.gui.layout.DragTab; -import forge.gui.layout.EDocID; -import forge.gui.layout.ICDoc; -import forge.gui.layout.IVDoc; +import forge.AllZone; +import forge.card.cardfactory.CardFactoryUtil; +import forge.card.mana.ManaPool; +import forge.game.player.Player; +import forge.game.zone.ZoneType; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.match.controllers.CPlayers; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FSkin; import forge.gui.toolbox.FSkin.SkinProp; @@ -49,18 +54,30 @@ import forge.view.arcane.PlayArea; * *

(V at beginning of class name denotes a view class.) */ -public enum VField implements IVDoc { - /** */ - SINGLETON_INSTANCE; +public class VField implements IVDoc { + // Fields used with interface IVDoc + private final CField control; + private DragCell parentCell; + private final EDocID docID; + private final DragTab tab = new DragTab("Field"); - private final JPanel pnl = new JPanel(); - private final DragTab tab = new DragTab("Your Battlefield"); + // Other fields + private Player player = null; + + // Top-level containers private final JScrollPane scroller = new JScrollPane(); - private final PlayArea tabletop = new PlayArea(scroller, true); + private final PlayArea tabletop; + private final JPanel avatarArea = new JPanel(); + private final JPanel phaseArea = new JPanel(); + private final JPanel pnlDetails = new JPanel(); - private final Border inactiveBorder = new LineBorder(new Color(0, 0, 0, 0), 1); - private final Border hoverBorder = new LineBorder(FSkin.getColor(FSkin.Colors.CLR_BORDERS), 1); + // Avatar area + private final JLabel lblAvatar = new FLabel.Builder().fontAlign(SwingConstants.CENTER) + .iconScaleFactor(1.0f).build(); + private final JLabel lblLife = new FLabel.Builder().fontAlign(SwingConstants.CENTER) + .fontStyle(Font.BOLD).build(); + // Info labels private FLabel lblHand = getBuiltFLabel(FSkin.ZoneImages.ICO_HAND, "99", "Cards in hand"); private FLabel lblGraveyard = getBuiltFLabel(FSkin.ZoneImages.ICO_GRAVEYARD, "99", "Cards in graveyard"); private FLabel lblLibrary = getBuiltFLabel(FSkin.ZoneImages.ICO_LIBRARY, "99", "Cards in library"); @@ -74,6 +91,7 @@ public enum VField implements IVDoc { private FLabel lblWhite = getBuiltFLabel(FSkin.ManaImages.IMG_WHITE, "99", "White mana"); private FLabel lblColorless = getBuiltFLabel(FSkin.ManaImages.IMG_COLORLESS, "99", "Colorless mana"); + // Phase labels private PhaseLabel lblUpkeep = new PhaseLabel("UP"); private PhaseLabel lblDraw = new PhaseLabel("DR"); private PhaseLabel lblMain1 = new PhaseLabel("M1"); @@ -87,44 +105,55 @@ public enum VField implements IVDoc { private PhaseLabel lblEndTurn = new PhaseLabel("ET"); private PhaseLabel lblCleanup = new PhaseLabel("CL"); - private final JPanel avatarArea = new JPanel(); - private final JPanel phaseArea = new JPanel(); - private final JPanel pnlDetails = new JPanel(); - private final JLabel lblAvatar = new FLabel.Builder().fontAlign(SwingConstants.CENTER) - .iconScaleFactor(1.0f).build(); - private final JLabel lblLife = new FLabel.Builder().fontAlign(SwingConstants.CENTER) - .fontStyle(Font.BOLD).build(); - - private final Color clrHover - = FSkin.getColor(FSkin.Colors.CLR_HOVER); - private final Color clrPhaseActiveEnabled - = FSkin.getColor(FSkin.Colors.CLR_PHASE_ACTIVE_ENABLED); - private final Color clrPhaseActiveDisabled - = FSkin.getColor(FSkin.Colors.CLR_PHASE_ACTIVE_DISABLED); - private final Color clrPhaseInactiveEnabled - = FSkin.getColor(FSkin.Colors.CLR_PHASE_INACTIVE_ENABLED); - private final Color clrPhaseInactiveDisabled - = FSkin.getColor(FSkin.Colors.CLR_PHASE_INACTIVE_DISABLED); - - /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#populate() + //========= Constructor + /** + * Assembles Swing components of a player field instance. + * + * @param player0   {@link forge.game.player.Player} + * @param id0   {@link forge.gui.framework.EDocID} */ - @Override - public void populate() { - // Avatar and life + public VField(final EDocID id0, final Player player0) { + this.docID = id0; + id0.setDoc(this); + + this.player = player0; + if (player0 != null) { tab.setText(player0.getName() + " Field"); } + else { tab.setText("NO PLAYER FOR " + docID.toString()); } + + // TODO player is hard-coded into tabletop...should be dynamic + // (haven't looked into it too deeply). Doublestrike 12-04-12 + tabletop = new PlayArea(scroller, + player.equals(AllZone.getComputerPlayer()) ? true : false); + + control = new CField(player, this); + avatarArea.setOpaque(false); avatarArea.setBackground(FSkin.getColor(FSkin.Colors.CLR_HOVER)); avatarArea.setLayout(new MigLayout("insets 0, gap 0")); avatarArea.add(lblAvatar, "w 100%!, h 70%!, wrap, gaptop 4%"); avatarArea.add(lblLife, "w 100%!, h 30%!, gaptop 4%"); - // Phases + // Player area hover effect + avatarArea.addMouseListener(new MouseAdapter() { + @Override + public void mouseEntered(final MouseEvent e) { + avatarArea.setOpaque(true); + avatarArea.setBorder(new LineBorder(FSkin.getColor(FSkin.Colors.CLR_BORDERS), 1)); + } + + @Override + public void mouseExited(final MouseEvent e) { + avatarArea.setOpaque(false); + avatarArea.setBorder(new LineBorder(new Color(0, 0, 0, 0), 1)); + } + }); + phaseArea.setOpaque(false); phaseArea.setLayout(new MigLayout("insets 0 0 1% 0, gap 0, wrap")); populatePhase(); - // Play area - tabletop.setBorder(new MatteBorder(0, 1, 0, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + tabletop.setBorder(new MatteBorder(0, 1, 0, 0, + FSkin.getColor(FSkin.Colors.CLR_BORDERS))); tabletop.setOpaque(false); scroller.setViewportView(this.tabletop); @@ -132,56 +161,37 @@ public enum VField implements IVDoc { scroller.getViewport().setOpaque(false); scroller.setBorder(null); - // Pool info pnlDetails.setOpaque(false); pnlDetails.setLayout(new MigLayout("insets 0, gap 0, wrap")); populateDetails(); + } - // Final layout - pnl.removeAll(); + //========= Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#populate() + */ + @Override + public void populate() { + final JPanel pnl = parentCell.getBody(); pnl.setLayout(new MigLayout("insets 0, gap 0")); + pnl.add(avatarArea, "w 10%!, h 30%!"); pnl.add(phaseArea, "w 5%!, h 100%!, span 1 2"); pnl.add(scroller, "w 85%!, h 100%!, span 1 2, wrap"); pnl.add(pnlDetails, "w 10%!, h 69%!, gapleft 1px"); - - // TODO Player hover effect - /* - avatarArea.addMouseListener(new MouseAdapter() { - @Override - public void mouseEntered(final MouseEvent e) { - VField.this.avatarArea.setOpaque(true); - VField.this.avatarArea.setBorder(VField.this.hoverBorder); - } - - @Override - public void mouseExited(final MouseEvent e) { - VField.this.avatarArea.setOpaque(false); - VField.this.avatarArea.setBorder(VField.this.inactiveBorder); - } - }); - */ } - /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocumentID() + * @see forge.gui.framework.IVDoc#getDocumentID() */ @Override public EDocID getDocumentID() { - return EDocID.YOUR_BATTLEFIELD; + return docID; } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocument() - */ - @Override - public Component getDocument() { - return pnl; - } - - /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getTabLabel() + * @see forge.gui.framework.IVDoc#getTabLabel() */ @Override public DragTab getTabLabel() { @@ -189,13 +199,31 @@ public enum VField implements IVDoc { } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getControl() + * @see forge.gui.framework.IVDoc#getControl() */ @Override public ICDoc getControl() { - return null; + return control; } + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#setParentCell() + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + //========= Populate helper methods + /** Adds phase indicator labels to phase area JPanel container. */ private void populatePhase() { // Constraints string, set once @@ -284,32 +312,39 @@ public enum VField implements IVDoc { pnlDetails.add(row6, constraintsRow); } + private FLabel getBuiltFLabel(SkinProp p0, String s0, String s1) { + return new FLabel.Builder().icon(new ImageIcon(FSkin.getImage(p0))) + .opaque(false).fontScaleAuto(false).fontSize(14) + .fontStyle(Font.BOLD).iconAlpha(0.6f).iconInBackground(true) + .text(s0).tooltip(s1).fontAlign(SwingConstants.RIGHT).build(); + } + // ========== Observer update methods /** * Handles observer update of player Zones - hand, graveyard, etc. * - * @p aram p0 - *   Player obj - * + * @param p0   {@link forge.game.player.Player} + */ public void updateZones(final Player p0) { - this.getLblHand().setText("" + p0.getZone(Zone.Hand).size()); - this.getLblGraveyard().setText("" + p0.getZone(Zone.Graveyard).size()); - this.getLblLibrary().setText("" + p0.getZone(Zone.Library).size()); + this.getLblHand().setText("" + p0.getZone(ZoneType.Hand).size()); + this.getLblGraveyard().setText("" + p0.getZone(ZoneType.Graveyard).size()); + this.getLblLibrary().setText("" + p0.getZone(ZoneType.Library).size()); this.getLblFlashback().setText("" + CardFactoryUtil.getExternalZoneActivationCards(p0).size()); - this.getLblExile().setText("" + p0.getZone(Zone.Exile).size()); + this.getLblExile().setText("" + p0.getZone(ZoneType.Exile).size()); } /** * Handles observer update of non-Zone details - life, poison, etc. Also * updates "players" panel in tabber for this player. * - * @p aram p0 - *   Player obj - * + * @param p0   {@link forge.game.player.Player} + */ public void updateDetails(final Player p0) { // "Players" panel update - Singletons.getControl().getControlMatch() - .getTabberControl().getView().updatePlayerLabels(p0); + CPlayers.SINGLETON_INSTANCE.update(); + + // Mana pool update + updateManaPool(p0); // Poison/life this.getLblLife().setText("" + p0.getLife()); @@ -328,28 +363,32 @@ public enum VField implements IVDoc { else { this.getLblPoison().setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); } - - //mana pool - updateManaPool(p0); } /** * Handles observer update of the mana pool. * - * @p aram p0 - *   Player obj - * + * @param p0   {@link forge.game.player.Player} + */ public void updateManaPool(final Player p0) { ManaPool m = p0.getManaPool(); - getLblBlack().setText("" + m.getAmountOfColor(forge.Constant.Color.BLACK)); - getLblBlue().setText("" + m.getAmountOfColor(forge.Constant.Color.BLUE)); - getLblGreen().setText("" + m.getAmountOfColor(forge.Constant.Color.GREEN)); - getLblRed().setText("" + m.getAmountOfColor(forge.Constant.Color.RED)); - getLblWhite().setText("" + m.getAmountOfColor(forge.Constant.Color.WHITE)); - getLblColorless().setText("" + m.getAmountOfColor(forge.Constant.Color.COLORLESS)); + this.lblBlack.setText("" + m.getAmountOfColor(forge.Constant.Color.BLACK)); + this.lblBlue.setText("" + m.getAmountOfColor(forge.Constant.Color.BLUE)); + this.lblGreen.setText("" + m.getAmountOfColor(forge.Constant.Color.GREEN)); + this.lblRed.setText("" + m.getAmountOfColor(forge.Constant.Color.RED)); + this.lblWhite.setText("" + m.getAmountOfColor(forge.Constant.Color.WHITE)); + this.lblColorless.setText("" + m.getAmountOfColor(forge.Constant.Color.COLORLESS)); + } + + //========= Retrieval methods + /** + * Gets the player currently associated with this field. + * @return {@link forge.game.player.Player} + */ + public Player getPlayer() { + return this.player; } - // ========= Retrieval methods /** * Gets the tabletop. * @@ -499,19 +538,14 @@ public enum VField implements IVDoc { return this.lblCleanup; } - // ========== Custom class handling - - private FLabel getBuiltFLabel(SkinProp p0, String s0, String s1) { - return new FLabel.Builder().icon(new ImageIcon(FSkin.getImage(p0))) - .opaque(false).fontScaleFactor(0.5).iconAlpha(0.6f).iconInBackground(true) - .text(s0).tooltip(s1).fontAlign(SwingConstants.RIGHT).build(); - } + //========== Custom class handling /** * Shows phase labels, handles repainting and on/off states. A PhaseLabel * has "skip" and "active" states, meaning "this phase is (not) skipped" and * "this is the current phase". */ + @SuppressWarnings("serial") public class PhaseLabel extends JLabel { private boolean enabled = true; private boolean active = false; @@ -613,15 +647,15 @@ public enum VField implements IVDoc { // Set color according to skip or active or hover state of label if (this.hover) { - c = clrHover; + c = FSkin.getColor(FSkin.Colors.CLR_HOVER); } else if (this.active && this.enabled) { - c = clrPhaseActiveEnabled; + c = FSkin.getColor(FSkin.Colors.CLR_PHASE_ACTIVE_ENABLED); } else if (!this.active && this.enabled) { - c = clrPhaseInactiveEnabled; + c = FSkin.getColor(FSkin.Colors.CLR_PHASE_INACTIVE_ENABLED); } else if (this.active && !this.enabled) { - c = clrPhaseActiveDisabled; + c = FSkin.getColor(FSkin.Colors.CLR_PHASE_ACTIVE_DISABLED); } else { - c = clrPhaseInactiveDisabled; + c = FSkin.getColor(FSkin.Colors.CLR_PHASE_INACTIVE_DISABLED); } // Center vertically and horizontally. Show border if active. diff --git a/src/main/java/forge/gui/match/nonsingleton/VHand.java b/src/main/java/forge/gui/match/nonsingleton/VHand.java index d923dab2449..d11fc2138ee 100644 --- a/src/main/java/forge/gui/match/nonsingleton/VHand.java +++ b/src/main/java/forge/gui/match/nonsingleton/VHand.java @@ -17,16 +17,16 @@ */ package forge.gui.match.nonsingleton; -import java.awt.Component; - import javax.swing.JPanel; import javax.swing.JScrollPane; import net.miginfocom.swing.MigLayout; -import forge.gui.layout.DragTab; -import forge.gui.layout.EDocID; -import forge.gui.layout.ICDoc; -import forge.gui.layout.IVDoc; +import forge.game.player.Player; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; import forge.view.arcane.HandArea; /** @@ -34,56 +34,98 @@ import forge.view.arcane.HandArea; * *

(V at beginning of class name denotes a view class.) */ -public enum VHand implements IVDoc { - /** */ - SINGLETON_INSTANCE; - - private final JPanel pnl = new JPanel(); +public class VHand implements IVDoc { + // Fields used with interface IVDoc + private final CHand control; + private DragCell parentCell; + private final EDocID docID; private final DragTab tab = new DragTab("Your Hand"); + // Other fields + private Player player = null; + + // Top-level containers private final JScrollPane scroller = new JScrollPane(); private final HandArea hand = new HandArea(scroller); - /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#populate() + //========= Constructor + /** + * Assembles Swing components of a player hand instance. + * + * @param id0   {@link forge.gui.framework.EDocID} + * @param player0   {@link forge.game.player.Player} */ - @Override - public void populate() { + public VHand(final EDocID id0, final Player player0) { + docID = id0; + id0.setDoc(this); + tab.setText(player0.getName() + " Hand"); + + player = player0; + + scroller.setBorder(null); scroller.setViewportView(VHand.this.hand); scroller.setOpaque(false); scroller.getViewport().setOpaque(false); - scroller.setBorder(null); + hand.setOpaque(false); - pnl.removeAll(); + control = new CHand(player, this); + } + + //========= Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#populate() + */ + @Override + public void populate() { + final JPanel pnl = parentCell.getBody(); pnl.setLayout(new MigLayout("insets 0, gap 0")); + pnl.add(scroller, "w 100%, h 100%!"); } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocumentID() + * @see forge.gui.framework.IVDoc#getDocumentID() */ @Override public EDocID getDocumentID() { - return EDocID.YOUR_HAND; + return docID; } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocument() + * @see forge.gui.framework.IVDoc#setParentCell() */ @Override - public Component getDocument() { - return pnl; + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getTabLabel() + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getTabLabel() */ @Override public DragTab getTabLabel() { return tab; } + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getControl() + */ + @Override + public ICDoc getControl() { + return control; + } + + //========= Retrieval methods /** * Gets the hand area. * @@ -93,11 +135,20 @@ public enum VHand implements IVDoc { return VHand.this.hand; } - /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getControl() + /** + * Gets the player currently associated with this hand. + * @return {@link forge.game.player.Player} */ - @Override - public ICDoc getControl() { - return null; + public Player getPlayer() { + return this.player; + } + + /** + * Sets the player currently associated with this field. + * @param player0   {@link forge.game.player.Player} + */ + public void setPlayer(final Player player0) { + this.player = player0; + if (player0 != null) { tab.setText(player0.getName() + " Field"); } } } diff --git a/src/main/java/forge/gui/match/views/VAntes.java b/src/main/java/forge/gui/match/views/VAntes.java index cadf8103146..9164e1a03e1 100644 --- a/src/main/java/forge/gui/match/views/VAntes.java +++ b/src/main/java/forge/gui/match/views/VAntes.java @@ -17,15 +17,17 @@ */ package forge.gui.match.views; -import java.awt.Component; - -import javax.swing.JPanel; - -import forge.gui.layout.DragTab; -import forge.gui.layout.EDocID; -import forge.gui.layout.ICDoc; -import forge.gui.layout.IVDoc; -import forge.gui.toolbox.FSkin; +import net.miginfocom.swing.MigLayout; +import forge.AllZone; +import forge.Card; +import forge.game.player.Player; +import forge.gui.CardPicturePanel; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.match.controllers.CAntes; /** * Assembles Swing components of card ante area. @@ -36,36 +38,56 @@ public enum VAntes implements IVDoc { /** */ SINGLETON_INSTANCE; - private final JPanel pnl = new JPanel(); + // Fields used with interface IVDoc + private DragCell parentCell; private final DragTab tab = new DragTab("Ante"); + private CardPicturePanel humanAnte = new CardPicturePanel(null); + private CardPicturePanel computerAnte = new CardPicturePanel(null); + + //========== Constructor + private VAntes() { + humanAnte.setOpaque(false); + computerAnte.setOpaque(false); + } + + //========== Overridden methods /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#populate() + * @see forge.gui.framework.IVDoc#populate() */ @Override public void populate() { - pnl.removeAll(); - pnl.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); + parentCell.getBody().setLayout(new MigLayout("insets 1%, gap 1%")); + parentCell.getBody().add(humanAnte, "w 47%!, h 100%!"); + parentCell.getBody().add(computerAnte, "w 47%!, h 100%!"); } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocumentID() + * @see forge.gui.framework.IVDoc#setParentCell() + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() */ @Override public EDocID getDocumentID() { - return EDocID.REPORT_STACK; + return EDocID.CARD_ANTES; } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocument() - */ - @Override - public Component getDocument() { - return pnl; - } - - /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getTabLabel() + * @see forge.gui.framework.IVDoc#getTabLabel() */ @Override public DragTab getTabLabel() { @@ -73,10 +95,26 @@ public enum VAntes implements IVDoc { } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getControl() + * @see forge.gui.framework.IVDoc#getControl() */ @Override public ICDoc getControl() { - return null; + return CAntes.SINGLETON_INSTANCE; + } + + //========== Setters / getters + /** + * @param p0   {@link forge.game.player.Player} + * @param c0   {@link forge.Card} + */ + public void setAnteCard(final Player p0, final Card c0) { + if (p0.equals(AllZone.getComputerPlayer())) { + computerAnte.setCard(c0); + computerAnte.revalidate(); + } + else if (p0.equals(AllZone.getHumanPlayer())) { + humanAnte.setCard(c0); + humanAnte.revalidate(); + } } } diff --git a/src/main/java/forge/gui/match/views/VCombat.java b/src/main/java/forge/gui/match/views/VCombat.java index 4128c6eb851..a0aaacf44ea 100644 --- a/src/main/java/forge/gui/match/views/VCombat.java +++ b/src/main/java/forge/gui/match/views/VCombat.java @@ -17,14 +17,18 @@ */ package forge.gui.match.views; -import java.awt.Component; +import javax.swing.JTextArea; +import javax.swing.border.Border; +import javax.swing.border.MatteBorder; -import javax.swing.JPanel; - -import forge.gui.layout.DragTab; -import forge.gui.layout.EDocID; -import forge.gui.layout.ICDoc; -import forge.gui.layout.IVDoc; +import net.miginfocom.swing.MigLayout; +import forge.AllZone; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.match.controllers.CCombat; import forge.gui.toolbox.FSkin; /** @@ -36,36 +40,46 @@ public enum VCombat implements IVDoc { /** */ SINGLETON_INSTANCE; - private final JPanel pnl = new JPanel(); - private final DragTab tab = new DragTab("Combat Report"); + // Fields used with interface IVDoc + private DragCell parentCell; + private final DragTab tab = new DragTab("Combat"); + + //========== Overridden methods /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#populate() + * @see forge.gui.framework.IVDoc#populate() */ @Override public void populate() { - pnl.removeAll(); - pnl.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); + // (Panel uses observers to update, no permanent components here.) } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocumentID() + * @see forge.gui.framework.IVDoc#setParentCell() + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() */ @Override public EDocID getDocumentID() { - return EDocID.REPORT_STACK; + return EDocID.REPORT_COMBAT; } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocument() - */ - @Override - public Component getDocument() { - return pnl; - } - - /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getTabLabel() + * @see forge.gui.framework.IVDoc#getTabLabel() */ @Override public DragTab getTabLabel() { @@ -73,10 +87,33 @@ public enum VCombat implements IVDoc { } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getControl() + * @see forge.gui.framework.IVDoc#getControl() */ @Override public ICDoc getControl() { - return null; + return CCombat.SINGLETON_INSTANCE; + } + + //========= Observer update methods + + /** @param s0   {@link java.lang.String} */ + public void updateCombat(final String s0) { + // No need to update this unless it's showing + if (!parentCell.getSelected().equals(this)) { return; } + + parentCell.getBody().removeAll(); + parentCell.getBody().setLayout(new MigLayout("insets 0, gap 0, wrap")); + + final Border border = new MatteBorder(0, 0, 0, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS)); + + tab.setText("Combat : " + AllZone.getCombat().getAttackers().size()); + + final JTextArea tar = new JTextArea(s0); + tar.setOpaque(false); + tar.setBorder(border); + tar.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + tar.setFocusable(false); + tar.setLineWrap(true); + parentCell.getBody().add(tar, "w 95%!, gapleft 3%, gaptop 1%, h 95%"); } } diff --git a/src/main/java/forge/gui/match/views/VDetail.java b/src/main/java/forge/gui/match/views/VDetail.java index c21239f6436..d9f1ec8f615 100644 --- a/src/main/java/forge/gui/match/views/VDetail.java +++ b/src/main/java/forge/gui/match/views/VDetail.java @@ -17,17 +17,14 @@ */ package forge.gui.match.views; -import java.awt.Component; - -import javax.swing.JPanel; - import net.miginfocom.swing.MigLayout; import forge.gui.CardDetailPanel; -import forge.gui.layout.DragTab; -import forge.gui.layout.EDocID; -import forge.gui.layout.ICDoc; -import forge.gui.layout.IVDoc; -import forge.gui.toolbox.FSkin; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.match.controllers.CDetail; /** * Assembles Swing components of card detail area. @@ -38,32 +35,41 @@ public enum VDetail implements IVDoc { /** */ SINGLETON_INSTANCE; - private final JPanel pnl = new JPanel(); + // Fields used with interface IVDoc + private DragCell parentCell; private final DragTab tab = new DragTab("Card Detail"); + // Top-level containers private final CardDetailPanel pnlDetail = new CardDetailPanel(null); + //========= Overridden methods /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#populate() + * @see forge.gui.framework.IVDoc#populate() */ @Override public void populate() { - pnlDetail.setOpaque(false); - - pnl.removeAll(); - pnl.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); - pnl.setLayout(new MigLayout("insets 0, gap 0")); - - pnl.add(pnlDetail, "w 100%!, h 100%!"); - } - - /** @return {@link forge.gui.CardDetailPanel} */ - public CardDetailPanel getPnlDetail() { - return pnlDetail; + parentCell.getBody().setLayout(new MigLayout("insets 0, gap 0")); + parentCell.getBody().add(pnlDetail, "w 100%!, h 100%!"); } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocumentID() + * @see forge.gui.framework.IVDoc#setParentCell() + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() */ @Override public EDocID getDocumentID() { @@ -71,15 +77,7 @@ public enum VDetail implements IVDoc { } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocument() - */ - @Override - public Component getDocument() { - return pnl; - } - - /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getTabLabel() + * @see forge.gui.framework.IVDoc#getTabLabel() */ @Override public DragTab getTabLabel() { @@ -87,10 +85,17 @@ public enum VDetail implements IVDoc { } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getControl() + * @see forge.gui.framework.IVDoc#getControl() */ @Override public ICDoc getControl() { - return null; + return CDetail.SINGLETON_INSTANCE; + } + + //========= Retrieval methods + + /** @return {@link forge.gui.CardDetailPanel} */ + public CardDetailPanel getPnlDetail() { + return pnlDetail; } } diff --git a/src/main/java/forge/gui/match/views/VDev.java b/src/main/java/forge/gui/match/views/VDev.java new file mode 100644 index 00000000000..966ed9d93c5 --- /dev/null +++ b/src/main/java/forge/gui/match/views/VDev.java @@ -0,0 +1,351 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Nate + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.gui.match.views; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.ScrollPaneConstants; +import javax.swing.border.EmptyBorder; + +import net.miginfocom.swing.MigLayout; +import forge.gui.MultiLineLabelUI; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.match.controllers.CDev; +import forge.gui.toolbox.FSkin; + +/** + * Assembles Swing components of players report. + * + *

(V at beginning of class name denotes a view class.) + */ +public enum VDev implements IVDoc { + /** */ + SINGLETON_INSTANCE; + + // Fields used with interface IVDoc + private DragCell parentCell; + private final DragTab tab = new DragTab("Dev Mode"); + + // Other fields + private List devLBLs = new ArrayList(); + + // Top-level containers + private final JPanel viewport = new JPanel(new MigLayout("wrap, insets 0")); + private final JScrollPane scroller = new JScrollPane(viewport, + ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, + ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + + // Dev labels + private final DevLabel lblMilling = new DevLabel("Loss by Milling: Enabled", "Loss by Milling: Disabled"); + private final DevLabel lblUnlimitedLands = new DevLabel("Play Unlimited Lands This Turn: Enabled", + "Play Unlimited Lands This Turn: Disabled"); + private final DevLabel lblGenerateMana = new DevLabel("Generate Mana"); + private final DevLabel lblSetupGame = new DevLabel("Setup Game State"); + private final DevLabel lblTutor = new DevLabel("Tutor for Card"); + private final DevLabel lblCounterPermanent = new DevLabel("Add Counter to Permanent"); + private final DevLabel lblTapPermanent = new DevLabel("Tap Permanent"); + private final DevLabel lblUntapPermanent = new DevLabel("Untap Permanent"); + private final DevLabel lblSetLife = new DevLabel("Set Player Life"); + private final DevLabel lblAddCard = new DevLabel("Add any card"); + + //========= Constructor + + private VDev() { + devLBLs.add(lblMilling); + devLBLs.add(lblUnlimitedLands); + devLBLs.add(lblGenerateMana); + devLBLs.add(lblSetupGame); + devLBLs.add(lblTutor); + devLBLs.add(lblAddCard); + devLBLs.add(lblCounterPermanent); + devLBLs.add(lblTapPermanent); + devLBLs.add(lblUntapPermanent); + devLBLs.add(lblSetLife); + + scroller.setBorder(null); + scroller.setOpaque(false); + scroller.getViewport().setOpaque(false); + viewport.setOpaque(false); + + final String constraints = "w 95%!, gap 0 0 5px 0"; + viewport.add(this.lblMilling, constraints); + viewport.add(this.lblUnlimitedLands, constraints); + viewport.add(this.lblGenerateMana, constraints); + viewport.add(this.lblSetupGame, constraints); + viewport.add(this.lblTutor, constraints); + viewport.add(this.lblAddCard, constraints); + viewport.add(this.lblCounterPermanent, constraints); + viewport.add(this.lblTapPermanent, constraints); + viewport.add(this.lblUntapPermanent, constraints); + viewport.add(this.lblSetLife, constraints); + } + + //========= Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#populate() + */ + @Override + public void populate() { + parentCell.getBody().setLayout(new MigLayout("insets 0, gap 0")); + parentCell.getBody().add(scroller, "w 100%, h 100%!"); + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#setParentCell() + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() + */ + @Override + public EDocID getDocumentID() { + return EDocID.DEV_MODE; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getTabLabel() + */ + @Override + public DragTab getTabLabel() { + return tab; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getControl() + */ + @Override + public ICDoc getControl() { + return CDev.SINGLETON_INSTANCE; + } + + //========= Retrieval methods + + /** @return {@link forge.gui.match.views.VDev.DevLabel} */ + public DevLabel getLblMilling() { + return this.lblMilling; + } + + /** @return {@link forge.gui.match.views.VDev.DevLabel} */ + public DevLabel getLblGenerateMana() { + return this.lblGenerateMana; + } + + /** @return {@link forge.gui.match.views.VDev.DevLabel} */ + public DevLabel getLblSetupGame() { + return this.lblSetupGame; + } + + /** @return {@link forge.gui.match.views.VDev.DevLabel} */ + public DevLabel getLblTutor() { + return this.lblTutor; + } + + /** @return {@link forge.gui.match.views.VDev.DevLabel} */ + public DevLabel getAnyCard() { + return this.lblAddCard; + } + + /** @return {@link forge.gui.match.views.VDev.DevLabel} */ + public DevLabel getLblCounterPermanent() { + return this.lblCounterPermanent; + } + + /** @return {@link forge.gui.match.views.VDev.DevLabel} */ + public DevLabel getLblTapPermanent() { + return this.lblTapPermanent; + } + + /** @return {@link forge.gui.match.views.VDev.DevLabel} */ + public DevLabel getLblUntapPermanent() { + return this.lblUntapPermanent; + } + + /** @return {@link forge.gui.match.views.VDev.DevLabel} */ + public DevLabel getLblUnlimitedLands() { + return this.lblUnlimitedLands; + } + + /** @return {@link forge.gui.match.views.VDev.DevLabel} */ + public DevLabel getLblSetLife() { + return this.lblSetLife; + } + + /** + * Labels that act as buttons which control dev mode functions. Labels are + * used to support multiline text. + */ + public class DevLabel extends JLabel { + private static final long serialVersionUID = 7917311680519060700L; + + private Color defaultBG = FSkin.getColor(FSkin.Colors.CLR_ACTIVE);; + private final Color hoverBG = FSkin.getColor(FSkin.Colors.CLR_HOVER); + private final Color pressedBG = FSkin.getColor(FSkin.Colors.CLR_INACTIVE);; + private boolean enabled; + private final String enabledText, disabledText; + private int w, h; // Width, height, radius, insets (for paintComponent) + + private final int r; + + private final int i; + + /** + * Labels that act as buttons which control dev mode functions. Labels + * are used (instead of buttons) to support multiline text. + * + * Constructor for DevLabel which doesn't use enabled/disabled states; + * only single text string required. + * + * @param s0 + *   String text/tooltip of label + */ + public DevLabel(final String s0) { + this(s0, s0); + } + + /** + * Labels that act as buttons which control dev mode functions. Labels + * are used (instead of buttons) to support multiline text. + * + * This constructor for DevLabels empowers an "enable" state that + * displays them as green (enabled) or red (disabled). + * + * @param en0 + *   String text/tooltip of label, in "enabled" state + * @param dis0 + *   String text/tooltip of label, in "disabled" state + */ + public DevLabel(final String en0, final String dis0) { + super(); + this.setUI(MultiLineLabelUI.getLabelUI()); + this.setBorder(new EmptyBorder(5, 5, 5, 5)); + this.enabledText = en0; + this.disabledText = dis0; + this.r = 6; // Radius (for paintComponent) + this.i = 2; // Insets (for paintComponent) + this.setEnabled(true); + this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + + this.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(final MouseEvent e) { + DevLabel.this.setBackground(DevLabel.this.pressedBG); + } + + @Override + public void mouseReleased(final MouseEvent e) { + DevLabel.this.setBackground(DevLabel.this.defaultBG); + } + + @Override + public void mouseEntered(final MouseEvent e) { + DevLabel.this.setBackground(DevLabel.this.hoverBG); + } + + @Override + public void mouseExited(final MouseEvent e) { + DevLabel.this.setBackground(DevLabel.this.defaultBG); + } + }); + } + + /** + * Changes enabled state per boolean parameter, automatically updating + * text string and background color. + * + * @param b + *   boolean + */ + @Override + public void setEnabled(final boolean b) { + String s; + if (b) { + this.defaultBG = FSkin.getColor(FSkin.Colors.CLR_ACTIVE); + s = this.enabledText; + } else { + this.defaultBG = FSkin.getColor(FSkin.Colors.CLR_INACTIVE); + s = this.disabledText; + } + this.enabled = b; + this.setText(s); + this.setToolTipText(s); + this.setBackground(this.defaultBG); + } + + /** + * Gets the enabled. + * + * @return boolean + */ + public boolean getEnabled() { + return this.enabled; + } + + /** + * In many cases, a DevLabel state will just be toggling a boolean. This + * method sets up and evaluates the condition and toggles as + * appropriate. + * + */ + public void toggleEnabled() { + if (this.enabled) { + this.setEnabled(false); + } else { + this.setEnabled(true); + } + } + + /* + * (non-Javadoc) + * + * @see javax.swing.JComponent#paintComponent(java.awt.Graphics) + */ + @Override + protected void paintComponent(final Graphics g) { + this.w = this.getWidth(); + this.h = this.getHeight(); + g.setColor(this.getBackground()); + g.fillRoundRect(this.i, this.i, this.w - (2 * this.i), this.h - this.i, this.r, this.r); + super.paintComponent(g); + } + } +} diff --git a/src/main/java/forge/gui/match/views/VDock.java b/src/main/java/forge/gui/match/views/VDock.java index 6fd23631b86..21487caf083 100644 --- a/src/main/java/forge/gui/match/views/VDock.java +++ b/src/main/java/forge/gui/match/views/VDock.java @@ -17,15 +17,25 @@ */ package forge.gui.match.views; -import java.awt.Component; +import java.awt.Color; +import java.awt.Dimension; import java.awt.FlowLayout; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.ImageIcon; +import javax.swing.JLabel; import javax.swing.JPanel; -import forge.gui.layout.DragTab; -import forge.gui.layout.EDocID; -import forge.gui.layout.ICDoc; -import forge.gui.layout.IVDoc; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.match.controllers.CDock; +import forge.gui.toolbox.FSkin; /** * Assembles Swing components of button dock area. @@ -36,43 +46,64 @@ public enum VDock implements IVDoc { /** */ SINGLETON_INSTANCE; - private final JPanel pnl = new JPanel(); - private final DragTab tab = new DragTab("Button Dock"); + // Fields used with interface IVDoc + private DragCell parentCell; + private final DragTab tab = new DragTab("Dock"); + + // Dock button instances + private final JLabel btnConcede = + new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_CONCEDE), "Concede Game"); + private final JLabel btnSettings = + new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_SETTINGS), "Game Settings"); + private final JLabel btnEndTurn = + new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_ENDTURN), "End Turn"); + private final JLabel btnViewDeckList = + new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_DECKLIST), "View Deck List"); + + //========= Overridden methods /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#populate() + * @see forge.gui.framework.IVDoc#populate() */ @Override public void populate() { + final JPanel pnl = parentCell.getBody(); // Mig layout does not support wrapping! // http://stackoverflow.com/questions/5715833/how-do-you-make-miglayout-behave-like-wrap-layout - final FlowLayout layFlow = new FlowLayout(); - layFlow.setHgap(10); - layFlow.setVgap(10); + pnl.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10)); - pnl.removeAll(); - pnl.setOpaque(false); - pnl.setLayout(layFlow); + pnl.add(btnConcede); + pnl.add(btnSettings); + pnl.add(btnEndTurn); + pnl.add(btnViewDeckList); } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocumentID() + * @see forge.gui.framework.IVDoc#setParentCell() + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() */ @Override public EDocID getDocumentID() { - return EDocID.YOUR_DOCK; + return EDocID.BUTTON_DOCK; } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocument() - */ - @Override - public Component getDocument() { - return pnl; - } - - /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getTabLabel() + * @see forge.gui.framework.IVDoc#getTabLabel() */ @Override public DragTab getTabLabel() { @@ -80,10 +111,97 @@ public enum VDock implements IVDoc { } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getControl() + * @see forge.gui.framework.IVDoc#getControl() */ @Override public ICDoc getControl() { - return null; + return CDock.SINGLETON_INSTANCE; + } + + //========= Retrieval methods + + /** @return {@link javax.swing.JLabel} */ + public JLabel getBtnConcede() { + return btnConcede; + } + + /** @return {@link javax.swing.JLabel} */ + public JLabel getBtnSettings() { + return btnSettings; + } + + /** @return {@link javax.swing.JLabel} */ + public JLabel getBtnEndTurn() { + return btnEndTurn; + } + + /** @return {@link javax.swing.JLabel} */ + public JLabel getBtnViewDeckList() { + return btnViewDeckList; + } + + //========= Custom class handling + /** + * Buttons in Dock. JLabels are used to allow hover effects. + */ + @SuppressWarnings("serial") + private class DockButton extends JLabel { + private final Image img; + private final Color hoverBG = FSkin.getColor(FSkin.Colors.CLR_HOVER); + private final Color defaultBG = new Color(0, 0, 0, 0); + private Color clrBorders = new Color(0, 0, 0, 0); + private int w, h; + + /** + * Buttons in Dock. JLabels are used to allow hover effects. + * + * @param i0 + *   ImageIcon to show in button + * @param s0 + *   Tooltip string + */ + public DockButton(final ImageIcon i0, final String s0) { + super(); + this.setToolTipText(s0); + this.setOpaque(false); + this.setBackground(this.defaultBG); + this.img = i0.getImage(); + + Dimension size = new Dimension(30, 30); + this.setMinimumSize(size); + this.setMaximumSize(size); + this.setPreferredSize(size); + + this.addMouseListener(new MouseAdapter() { + @Override + public void mouseEntered(final MouseEvent e) { + DockButton.this.clrBorders = FSkin.getColor(FSkin.Colors.CLR_BORDERS); + DockButton.this.setBackground(DockButton.this.hoverBG); + } + + @Override + public void mouseExited(final MouseEvent e) { + DockButton.this.clrBorders = new Color(0, 0, 0, 0); + DockButton.this.setBackground(DockButton.this.defaultBG); + } + }); + } + + /* + * (non-Javadoc) + * + * @see javax.swing.JComponent#paintComponent(java.awt.Graphics) + */ + @Override + public void paintComponent(final Graphics g) { + this.w = this.getWidth(); + this.h = this.getHeight(); + g.setColor(this.getBackground()); + g.fillRect(0, 0, this.w, this.h); + g.setColor(this.clrBorders); + g.drawRect(0, 0, this.w - 1, this.h - 1); + g.drawImage(this.img, 0, 0, this.w, this.h, null); + super.paintComponent(g); + } } } diff --git a/src/main/java/forge/gui/match/views/VLog.java b/src/main/java/forge/gui/match/views/VLog.java index 0cfdb6fb949..f9e69a653b6 100644 --- a/src/main/java/forge/gui/match/views/VLog.java +++ b/src/main/java/forge/gui/match/views/VLog.java @@ -17,14 +17,18 @@ */ package forge.gui.match.views; -import java.awt.Component; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; -import javax.swing.JPanel; - -import forge.gui.layout.DragTab; -import forge.gui.layout.EDocID; -import forge.gui.layout.ICDoc; -import forge.gui.layout.IVDoc; +import net.miginfocom.swing.MigLayout; +import forge.AllZone; +import forge.GameLog; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.match.controllers.CLog; import forge.gui.toolbox.FSkin; /** @@ -36,36 +40,45 @@ public enum VLog implements IVDoc { /** */ SINGLETON_INSTANCE; - private final JPanel pnl = new JPanel(); - private final DragTab tab = new DragTab("Game Log"); + // Fields used with interface IVDoc + private DragCell parentCell; + private final DragTab tab = new DragTab("Log"); + //========== Overridden methods /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#populate() + * @see forge.gui.framework.IVDoc#populate() */ @Override public void populate() { - pnl.removeAll(); - pnl.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); + // (Panel uses observers to update, no permanent components here.) } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocumentID() + * @see forge.gui.framework.IVDoc#setParentCell() + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() */ @Override public EDocID getDocumentID() { - return EDocID.REPORT_STACK; + return EDocID.REPORT_LOG; } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocument() - */ - @Override - public Component getDocument() { - return pnl; - } - - /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getTabLabel() + * @see forge.gui.framework.IVDoc#getTabLabel() */ @Override public DragTab getTabLabel() { @@ -73,10 +86,42 @@ public enum VLog implements IVDoc { } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getControl() + * @see forge.gui.framework.IVDoc#getControl() */ @Override public ICDoc getControl() { - return null; + return CLog.SINGLETON_INSTANCE; + } + + //========== Observer update methods + /** */ + public void updateConsole() { + // No need to update this unless it's showing + if (!parentCell.getSelected().equals(this)) { return; } + + final GameLog gl = AllZone.getGameLog(); + + parentCell.getBody().setLayout(new MigLayout("insets 1%, gap 1%, wrap")); + parentCell.getBody().removeAll(); + + // by default, grab everything logging level 3 or less + // TODO - some option to make this configurable is probably desirable + // TODO - add these components to resize adapter in constructor + JTextArea tar = new JTextArea(gl.getLogText(3)); + tar.setOpaque(false); + tar.setBorder(null); + tar.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + + tar.setFocusable(false); + tar.setEditable(false); + tar.setLineWrap(true); + tar.setWrapStyleWord(true); + + JScrollPane jsp = new JScrollPane(tar); + jsp.setOpaque(false); + jsp.setBorder(null); + jsp.getViewport().setOpaque(false); + + parentCell.getBody().add(jsp, "w 98%!"); } } diff --git a/src/main/java/forge/gui/match/views/VMessage.java b/src/main/java/forge/gui/match/views/VMessage.java index 10090829710..08c48af2585 100644 --- a/src/main/java/forge/gui/match/views/VMessage.java +++ b/src/main/java/forge/gui/match/views/VMessage.java @@ -17,21 +17,21 @@ */ package forge.gui.match.views; -import java.awt.Component; import java.awt.Font; import javax.swing.JButton; import javax.swing.JLabel; -import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.SwingConstants; import javax.swing.border.MatteBorder; import net.miginfocom.swing.MigLayout; -import forge.gui.layout.DragTab; -import forge.gui.layout.EDocID; -import forge.gui.layout.ICDoc; -import forge.gui.layout.IVDoc; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.match.controllers.CMessage; import forge.gui.toolbox.FButton; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FSkin; @@ -45,24 +45,19 @@ public enum VMessage implements IVDoc { /** */ SINGLETON_INSTANCE; - private final JPanel pnl = new JPanel(); + // Fields used with interface IVDoc + private DragCell parentCell; private final DragTab tab = new DragTab("Message Report"); + // Various components private final JButton btnOK = new FButton("OK"); private final JButton btnCancel = new FButton("Cancel"); private final JTextArea tarMessage = new JTextArea(); private final JLabel lblGames = new FLabel.Builder().fontScaleAuto(false) .fontSize(12).fontStyle(Font.BOLD).fontAlign(SwingConstants.CENTER).build(); - /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#populate() - */ - @Override - public void populate() { - pnl.removeAll(); - pnl.setToolTipText("Input Area"); - pnl.setLayout(new MigLayout("wrap 2, fill, insets 0, gap 0")); - + //========= Constructor + private VMessage() { lblGames.setBorder(new MatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); tarMessage.setOpaque(false); @@ -71,16 +66,42 @@ public enum VMessage implements IVDoc { tarMessage.setLineWrap(true); tarMessage.setWrapStyleWord(true); tarMessage.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - tarMessage.setFont(FSkin.getFont(16)); + tarMessage.setFont(FSkin.getFont(12)); + } - pnl.add(lblGames, "span 2 1, w 96%!, gapleft 2%, h 10%, wrap"); - pnl.add(tarMessage, "span 2 1, h 70%!, w 96%!, gapleft 2%, gaptop 1%"); - pnl.add(btnOK, "w 47%!, gapright 2%, gapleft 1%"); - pnl.add(btnCancel, "w 47%!, gapright 1%"); + //========== Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#populate() + */ + @Override + public void populate() { + parentCell.getBody().setLayout(new MigLayout("wrap 2, fill, insets 0, gap 0")); + + parentCell.getBody().add(lblGames, "span 2 1, w 96%!, gapleft 2%, h 30px, wrap"); + parentCell.getBody().add(tarMessage, "span 2 1, h 70%!, w 96%!, gap 2% 0 1% 0"); + parentCell.getBody().add(btnOK, "w 47%!, gap 2% 1% 0 5px"); + parentCell.getBody().add(btnCancel, "w 47%!, gap 0 1% 0 5px"); } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocumentID() + * @see forge.gui.framework.IVDoc#setParentCell() + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() */ @Override public EDocID getDocumentID() { @@ -88,119 +109,38 @@ public enum VMessage implements IVDoc { } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getControl() + * @see forge.gui.framework.IVDoc#getControl() */ @Override public ICDoc getControl() { - return null; + return CMessage.SINGLETON_INSTANCE; } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocument() - */ - @Override - public Component getDocument() { - return pnl; - } - - /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getTabLabel() + * @see forge.gui.framework.IVDoc#getTabLabel() */ @Override public DragTab getTabLabel() { return tab; } - /** Flashes animation on input panel if play is currently waiting on input. */ - public void remind() { - /* - * THIS SHOULD COMPLETELY AND TOTALLY BE IN A - * UTIL LIBRARY THAT CAN FLASH IT ON ANY COMPONENT - * IN THE LAYOUT. - */ - - /* - * THESE VALUES WERE PREVIOUSLY CLASS VARIABLES; SHOULD BE METHOD-SPECIFIC SOMEHOW. - * private Timer timer1 = null; - private static int counter = 0; - private int[] newA = null, newR = null, newG = null, newB = null; - private boolean remindIsRunning = false; - */ - - - // To adjust, only touch these two values. - /* final int steps = 5; // Number of delays - final int delay = 80; // Milliseconds between steps - - if (remindIsRunning) { return; } - - remindIsRunning = true; - final int oldR = getBackground().getRed(); - final int oldG = getBackground().getGreen(); - final int oldB = getBackground().getBlue(); - final int oldA = getBackground().getAlpha(); - counter = 0; - newR = new int[steps]; - newG = new int[steps]; - newB = new int[steps]; - newA = new int[steps]; - - for (int i = 0; i < steps; i++) { - newR[i] = (int) ((255 - oldR) / steps * i); - newG[i] = (int) (oldG / steps * i); - newB[i] = (int) (oldB / steps * i); - newA[i] = (int) ((255 - oldA) / steps * i); - } - - final TimerTask tt = new TimerTask() { - @Override - public void run() { - counter++; - if (counter != (steps - 1)) { - SwingUtilities.invokeLater(new Runnable() { @Override - public void run() { setBackground(new Color(newR[counter], oldG, oldB, newA[counter])); } }); - } - else { - SwingUtilities.invokeLater(new Runnable() { @Override - public void run() { setBackground(new Color(oldR, oldG, oldB, oldA)); } }); - remindIsRunning = false; - timer1.cancel(); - newR = null; - newG = null; - newB = null; - newA = null; - } - } - }; - - timer1 = new Timer(); - timer1.scheduleAtFixedRate(tt, 0, delay);*/ - } - - /** - * Gets the btn ok. - * - * @return JButton - */ + //========= Retrieval methods + /** @return {@link javax.swing.JButton} */ public JButton getBtnOK() { return this.btnOK; } - /** - * Gets the btn cancel. - * - * @return JButton - */ + /** @return {@link javax.swing.JButton} */ public JButton getBtnCancel() { return this.btnCancel; } - /** @return JTextArea */ + /** @return {@link javax.swing.JTextArea} */ public JTextArea getTarMessage() { return this.tarMessage; } - /** @return JLabel */ + /** @return {@link javax.swing.JLabel} */ public JLabel getLblGames() { return this.lblGames; } diff --git a/src/main/java/forge/gui/match/views/VPicture.java b/src/main/java/forge/gui/match/views/VPicture.java index c7bdd5da4f3..1e0d7401b24 100644 --- a/src/main/java/forge/gui/match/views/VPicture.java +++ b/src/main/java/forge/gui/match/views/VPicture.java @@ -17,16 +17,14 @@ */ package forge.gui.match.views; -import java.awt.Component; - -import javax.swing.JPanel; - import net.miginfocom.swing.MigLayout; import forge.gui.CardPicturePanel; -import forge.gui.layout.DragTab; -import forge.gui.layout.EDocID; -import forge.gui.layout.ICDoc; -import forge.gui.layout.IVDoc; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.match.controllers.CPicture; /** * Assembles Swing components of card picture area. @@ -37,24 +35,47 @@ public enum VPicture implements IVDoc { /** */ SINGLETON_INSTANCE; - private final JPanel pnl = new JPanel(); + // Fields used with interface IVDoc + private DragCell parentCell; private final DragTab tab = new DragTab("Card Picture"); - private final CardPicturePanel pnlPicture = new CardPicturePanel(null);; + + // Top-level containers + private final CardPicturePanel pnlPicture = new CardPicturePanel(null); + + //========= Constructor + private VPicture() { + pnlPicture.setOpaque(false); + } + + //========== Overridden methods /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#populate() + * @see forge.gui.framework.IVDoc#populate() */ @Override public void populate() { - pnl.removeAll(); - - pnlPicture.setOpaque(false); - pnl.setLayout(new MigLayout("insets 0, gap 0, center")); - pnl.add(pnlPicture, "w 100%!, h 100%!"); + parentCell.getBody().setLayout(new MigLayout("insets 0, gap 0, center")); + parentCell.getBody().add(pnlPicture, "w 100%!, h 100%!"); } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocumentID() + * @see forge.gui.framework.IVDoc#setParentCell() + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() */ @Override public EDocID getDocumentID() { @@ -62,15 +83,7 @@ public enum VPicture implements IVDoc { } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocument() - */ - @Override - public Component getDocument() { - return pnl; - } - - /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getTabLabel() + * @see forge.gui.framework.IVDoc#getTabLabel() */ @Override public DragTab getTabLabel() { @@ -78,13 +91,15 @@ public enum VPicture implements IVDoc { } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getControl() + * @see forge.gui.framework.IVDoc#getControl() */ @Override public ICDoc getControl() { - return null; + return CPicture.SINGLETON_INSTANCE; } + //========== Retrieval methods + /** @return {@link forge.gui.CardPicturePanel} */ public CardPicturePanel getPnlPicture() { return pnlPicture; diff --git a/src/main/java/forge/gui/match/views/VPlayers.java b/src/main/java/forge/gui/match/views/VPlayers.java index 1e75a7c8d82..970708a3f6f 100644 --- a/src/main/java/forge/gui/match/views/VPlayers.java +++ b/src/main/java/forge/gui/match/views/VPlayers.java @@ -17,15 +17,28 @@ */ package forge.gui.match.views; -import java.awt.Component; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.border.MatteBorder; -import forge.gui.layout.DragTab; -import forge.gui.layout.EDocID; -import forge.gui.layout.ICDoc; -import forge.gui.layout.IVDoc; +import net.miginfocom.swing.MigLayout; +import forge.AllZone; +import forge.CardList; +import forge.Singletons; +import forge.game.player.Player; +import forge.game.zone.ZoneType; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.match.controllers.CPlayers; import forge.gui.toolbox.FSkin; +import forge.properties.ForgePreferences.FPref; /** * Assembles Swing components of players report. @@ -36,36 +49,85 @@ public enum VPlayers implements IVDoc { /** */ SINGLETON_INSTANCE; - private final JPanel pnl = new JPanel(); - private final DragTab tab = new DragTab("Players Report"); + // Fields used with interface IVDoc + private DragCell parentCell; + private final DragTab tab = new DragTab("Players"); + + // Other fields + private Map infoLBLs; + private JLabel stormLabel; + + //========= Overridden methods /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#populate() + * @see forge.gui.framework.IVDoc#populate() */ @Override public void populate() { - pnl.removeAll(); - pnl.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); + final JPanel pnl = parentCell.getBody(); + pnl.setLayout(new MigLayout("insets 0, gap 0, wrap")); + + final List players = AllZone.getPlayersInGame(); + this.infoLBLs = new HashMap(); + + final String constraints = "w 97%!, gapleft 2%, gapbottom 1%"; + + for (final Player p : players) { + // Create and store labels detailing various non-critical player + // info. + final InfoLabel name = new InfoLabel(); + final InfoLabel life = new InfoLabel(); + final InfoLabel hand = new InfoLabel(); + final InfoLabel draw = new InfoLabel(); + final InfoLabel prevention = new InfoLabel(); + final InfoLabel keywords = new InfoLabel(); + final InfoLabel antes = new InfoLabel(); + this.infoLBLs.put(p, new JLabel[] { name, life, hand, draw, prevention, keywords, antes }); + + // Set border on bottom label, and larger font on player name + antes.setBorder(new MatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + name.setText(p.getName()); + + // Add to "players" tab panel + pnl.add(name, constraints); + pnl.add(life, constraints); + pnl.add(hand, constraints); + pnl.add(draw, constraints); + pnl.add(prevention, constraints); + pnl.add(keywords, constraints); + pnl.add(antes, constraints); + } + + stormLabel = new InfoLabel(); + pnl.add(stormLabel, constraints); } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocumentID() + * @see forge.gui.framework.IVDoc#setParentCell() + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() */ @Override public EDocID getDocumentID() { - return EDocID.REPORT_STACK; + return EDocID.REPORT_PLAYERS; } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocument() - */ - @Override - public Component getDocument() { - return pnl; - } - - /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getTabLabel() + * @see forge.gui.framework.IVDoc#getTabLabel() */ @Override public DragTab getTabLabel() { @@ -73,10 +135,55 @@ public enum VPlayers implements IVDoc { } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getControl() + * @see forge.gui.framework.IVDoc#getControl() */ @Override public ICDoc getControl() { - return null; + return CPlayers.SINGLETON_INSTANCE; + } + + //========== Observer update methods + + /** @param p0 {@link forge.game.player.Player} */ + public void updatePlayerLabels(final Player p0) { + // No need to update if this panel isn't showing + if (!parentCell.getSelected().equals(this)) { return; } + + final JLabel[] temp = this.infoLBLs.get(p0); + temp[1].setText("Life: " + String.valueOf(p0.getLife()) + " | Poison counters: " + + String.valueOf(p0.getPoisonCounters())); + temp[2].setText("Maximum hand size: " + String.valueOf(p0.getMaxHandSize())); + temp[3].setText("Cards drawn this turn: " + String.valueOf(p0.getNumDrawnThisTurn())); + temp[4].setText("Damage Prevention: " + String.valueOf(p0.getPreventNextDamage())); + if (!p0.getKeywords().isEmpty()) { + temp[5].setText(p0.getKeywords().toString()); + } else { + temp[5].setText(""); + } + if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_ANTE)) { + CardList list = p0.getCardsIn(ZoneType.Ante); + StringBuilder sb = new StringBuilder(); + sb.append("Ante'd: "); + for (int i = 0; i < list.size(); i++) { + sb.append(list.get(i)); + if (i < (list.size() - 1)) { + sb.append(", "); + } + } + temp[6].setText(sb.toString()); + } + + stormLabel.setText("Storm count: " + AllZone.getStack().getCardsCastThisTurn().size()); + } + + //========= Custom class handling + + /** A quick JLabel for info in "players" panel, to consolidate styling. */ + @SuppressWarnings("serial") + private class InfoLabel extends JLabel { + public InfoLabel() { + super(); + this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + } } } diff --git a/src/main/java/forge/gui/match/views/VStack.java b/src/main/java/forge/gui/match/views/VStack.java index f7035522be3..bbae8bb9bbf 100644 --- a/src/main/java/forge/gui/match/views/VStack.java +++ b/src/main/java/forge/gui/match/views/VStack.java @@ -17,15 +17,35 @@ */ package forge.gui.match.views; -import java.awt.Component; +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.List; -import javax.swing.JPanel; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JPopupMenu; +import javax.swing.JTextArea; +import javax.swing.border.Border; +import javax.swing.border.EmptyBorder; -import forge.gui.layout.DragTab; -import forge.gui.layout.EDocID; -import forge.gui.layout.ICDoc; -import forge.gui.layout.IVDoc; +import net.miginfocom.swing.MigLayout; +import forge.AllZone; +import forge.CardUtil; +import forge.card.spellability.SpellAbilityStackInstance; +import forge.game.zone.MagicStack; +import forge.gui.ForgeAction; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.match.CMatchUI; +import forge.gui.match.VMatchUI; +import forge.gui.match.controllers.CStack; import forge.gui.toolbox.FSkin; +import forge.properties.NewConstants; /** * Assembles Swing components of stack report. @@ -36,20 +56,42 @@ public enum VStack implements IVDoc { /** */ SINGLETON_INSTANCE; - private final JPanel pnl = new JPanel(); - private final DragTab tab = new DragTab("Stack Report"); + // Fields used with interface IVDoc + private DragCell parentCell; + private final DragTab tab = new DragTab("Stack"); + + // Other fields + private List stackTARs = new ArrayList(); + private TriggerReactionMenu triggerMenu = new TriggerReactionMenu(); + + //========= Overridden methods /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#populate() + * @see forge.gui.framework.IVDoc#populate() */ @Override public void populate() { - pnl.removeAll(); - pnl.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); + // (Panel uses observers to update, no permanent components here.) } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocumentID() + * @see forge.gui.framework.IVDoc#setParentCell() + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() */ @Override public EDocID getDocumentID() { @@ -57,15 +99,7 @@ public enum VStack implements IVDoc { } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getDocument() - */ - @Override - public Component getDocument() { - return pnl; - } - - /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getTabLabel() + * @see forge.gui.framework.IVDoc#getTabLabel() */ @Override public DragTab getTabLabel() { @@ -73,10 +107,187 @@ public enum VStack implements IVDoc { } /* (non-Javadoc) - * @see forge.gui.layout.IVDoc#getControl() + * @see forge.gui.framework.IVDoc#getControl() */ @Override public ICDoc getControl() { - return null; + return CStack.SINGLETON_INSTANCE; + } + + //========== Observer update methods + + /** */ + public void updateStack() { + // No need to update this unless it's showing + if (!parentCell.getSelected().equals(this)) { return; } + + final MagicStack stack = AllZone.getStack(); + + int count = 1; + JTextArea tar; + String txt, isOptional; + + parentCell.getBody().removeAll(); + parentCell.getBody().setLayout(new MigLayout("insets 1%, gap 1%, wrap")); + + tab.setText("Stack : " + stack.size()); + + final Border border = new EmptyBorder(5, 5, 5, 5); + Color[] scheme; + + stackTARs.clear(); + for (int i = stack.size() - 1; 0 <= i; i--) { + final SpellAbilityStackInstance spell = stack.peekInstance(i); + final int index = i; + + scheme = getSpellColor(spell); + + isOptional = stack.peekAbility(i).isOptionalTrigger() + && stack.peekAbility(i).getSourceCard().getController().isHuman() ? "(OPTIONAL) " : ""; + txt = (count++) + ". " + isOptional + spell.getStackDescription(); + tar = new JTextArea(txt); + tar.setToolTipText(txt); + tar.setOpaque(true); + tar.setBorder(border); + tar.setForeground(scheme[1]); + tar.setBackground(scheme[0]); + + tar.setFocusable(false); + tar.setEditable(false); + tar.setLineWrap(true); + tar.setWrapStyleWord(true); + + /* + * TODO - we should figure out how to display cards on the stack in + * the Picture/Detail panel The problem not is that when a computer + * casts a Morph, the real card shows because Picture/Detail checks + * isFaceDown() which will be false on for spell.getSourceCard() on + * the stack. + */ + + // this functionality was present in v 1.1.8 + tar.addMouseListener(new MouseAdapter() { + @Override + public void mouseEntered(final MouseEvent e) { + CMatchUI.SINGLETON_INSTANCE.setCard(spell.getSpellAbility().getSourceCard()); + } + }); + + /* + * This updates the Card Picture/Detail when the spell is added to + * the stack. This funcaitonality was not present in v 1.1.8. + * + * Problem is described in TODO right above this. + */ + /* + * if (i == 0) { + * AllZone.getDisplay().setCard(spell.getSourceCard()); } + */ + + parentCell.getBody().add(tar, "w 98%!"); + stackTARs.add(tar); + + if (stack.peekInstance(i).isOptionalTrigger()) { + tar.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(final MouseEvent e) { + + if (e.getButton() != MouseEvent.BUTTON3) { + return; + } + + triggerMenu.setTrigger(stack.peekAbility(index).getSourceTrigger()); + triggerMenu.show(e.getComponent(), e.getX(), e.getY()); + } + }); + } + } + + VMatchUI.SINGLETON_INSTANCE.getBtnOK().requestFocusInWindow(); + } + + /** Returns array with [background, foreground] colors. */ + private Color[] getSpellColor(SpellAbilityStackInstance s0) { + if (CardUtil.getColors(s0.getSourceCard()).size() > 1) { + return new Color[] { new Color(253, 175, 63), Color.black }; + } else if (s0.getSourceCard().isBlack()) { + return new Color[] { Color.black, Color.white }; + } else if (s0.getSourceCard().isBlue()) { + return new Color[] { new Color(71, 108, 191), Color.white }; + } else if (s0.getSourceCard().isGreen()) { + return new Color[] { new Color(23, 95, 30), Color.white }; + } else if (s0.getSourceCard().isRed()) { + return new Color[] { new Color(214, 8, 8), Color.white }; + } else if (s0.getSourceCard().isWhite()) { + return new Color[] { Color.white, Color.black }; + } else if (s0.getSourceCard().isArtifact() || s0.getSourceCard().isLand()) { + return new Color[] { new Color(111, 75, 43), Color.white }; + } + + return new Color[] { new Color(0, 0, 0, 0), FSkin.getColor(FSkin.Colors.CLR_TEXT) }; + } + + //========= Custom class handling + + private class TriggerReactionMenu extends JPopupMenu { + private static final long serialVersionUID = 6665085414634139984L; + private int workTrigID; + + public TriggerReactionMenu() { + super(); + + final ForgeAction actAccept = new ForgeAction(NewConstants.Lang.GuiDisplay.Trigger.ALWAYSACCEPT) { + private static final long serialVersionUID = -3734674058185367612L; + + @Override + public final void actionPerformed(final ActionEvent e) { + AllZone.getTriggerHandler().setAlwaysAcceptTrigger(TriggerReactionMenu.this.workTrigID); + } + }; + + final ForgeAction actDecline = new ForgeAction(NewConstants.Lang.GuiDisplay.Trigger.ALWAYSDECLINE) { + private static final long serialVersionUID = -1983295769159971502L; + + @Override + public final void actionPerformed(final ActionEvent e) { + AllZone.getTriggerHandler().setAlwaysDeclineTrigger(TriggerReactionMenu.this.workTrigID); + } + }; + + final ForgeAction actAsk = new ForgeAction(NewConstants.Lang.GuiDisplay.Trigger.ALWAYSASK) { + private static final long serialVersionUID = 5045255351332940821L; + + @Override + public final void actionPerformed(final ActionEvent e) { + AllZone.getTriggerHandler().setAlwaysAskTrigger(TriggerReactionMenu.this.workTrigID); + } + }; + + final JCheckBoxMenuItem jcbmiAccept = new JCheckBoxMenuItem(actAccept); + final JCheckBoxMenuItem jcbmiDecline = new JCheckBoxMenuItem(actDecline); + final JCheckBoxMenuItem jcbmiAsk = new JCheckBoxMenuItem(actAsk); + + this.add(jcbmiAccept); + this.add(jcbmiDecline); + this.add(jcbmiAsk); + } + + public void setTrigger(final int trigID) { + this.workTrigID = trigID; + + if (AllZone.getTriggerHandler().isAlwaysAccepted(trigID)) { + ((JCheckBoxMenuItem) this.getComponent(0)).setState(true); + ((JCheckBoxMenuItem) this.getComponent(1)).setState(false); + ((JCheckBoxMenuItem) this.getComponent(2)).setState(false); + } else if (AllZone.getTriggerHandler().isAlwaysDeclined(trigID)) { + ((JCheckBoxMenuItem) this.getComponent(0)).setState(false); + ((JCheckBoxMenuItem) this.getComponent(1)).setState(true); + ((JCheckBoxMenuItem) this.getComponent(2)).setState(false); + } else { + ((JCheckBoxMenuItem) this.getComponent(0)).setState(false); + ((JCheckBoxMenuItem) this.getComponent(1)).setState(false); + ((JCheckBoxMenuItem) this.getComponent(2)).setState(true); + } + } } } diff --git a/src/main/java/forge/gui/toolbox/FPanel.java b/src/main/java/forge/gui/toolbox/FPanel.java index 0d22abadfc3..cf267c02dc8 100644 --- a/src/main/java/forge/gui/toolbox/FPanel.java +++ b/src/main/java/forge/gui/toolbox/FPanel.java @@ -32,7 +32,6 @@ import java.util.List; import javax.swing.ImageIcon; import javax.swing.JPanel; import javax.swing.SwingConstants; -import javax.swing.border.Border; import forge.Command; @@ -209,11 +208,6 @@ public class FPanel extends JPanel { this.hovered = b0; } - @Override - public void setBorder(final Border bord0) { - // Intentionally empty - } - /* * (non-Javadoc) * diff --git a/src/main/java/forge/gui/toolbox/FVerticalTabPanel.java b/src/main/java/forge/gui/toolbox/FVerticalTabPanel.java deleted file mode 100644 index 9f42e47b444..00000000000 --- a/src/main/java/forge/gui/toolbox/FVerticalTabPanel.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.toolbox; - -import java.awt.CardLayout; -import java.awt.Color; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.geom.AffineTransform; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JPanel; -import javax.swing.border.MatteBorder; - -import net.miginfocom.swing.MigLayout; - -/** - * TODO: Write javadoc for this type. - * - */ -@SuppressWarnings("serial") -public class FVerticalTabPanel extends JPanel { - private final CardLayout cards; - private final JPanel pnlContent; - private final List allVTabs; - private int w, h, active; - private final Color activeColor, inactiveColor, hoverColor; - - private boolean tabsOnRightSide; - - /** - * Constructor, will automatically place tabs on left side. - * - * @param childPanels - *   JPanels to be placed in tabber - * @wbp.parser.constructor - */ - public FVerticalTabPanel(final List childPanels) { - this(childPanels, false); - } - - /** - * Assembles vertical tab panel from list of child panels. Tooltip on tab is - * same as tooltip on child panel. Title of tab is same as name of child - * panel. - * - * @param childPanels - *   JPanels to be placed in tabber - * @param b - *   boolean, true if tabs are on right side, false for left - * side. - */ - public FVerticalTabPanel(final List childPanels, boolean b) { - // General inits and skin settings - super(); - tabsOnRightSide = b; - this.setLayout(new MigLayout("insets 0, gap 0, wrap 2")); - this.setOpaque(false); - final int size = childPanels.size(); - this.hoverColor = FSkin.getColor(FSkin.Colors.CLR_HOVER); - this.activeColor = FSkin.getColor(FSkin.Colors.CLR_ACTIVE); - this.inactiveColor = FSkin.getColor(FSkin.Colors.CLR_INACTIVE); - - // Width of tabs, in percent width of container - final int pctTabW = 11; - // Spacing above and below each tab - final double pctSpacing = 0.5; - // - final int pctTabH = (int) ((100 - size * pctSpacing * 2) / size); - - // Content panel and card layout inits - this.cards = new CardLayout(); - this.pnlContent = new FPanel(); - ((FPanel) pnlContent).setCornerDiameter(0); - this.pnlContent.setLayout(this.cards); - - // If tabs are on the left side, content panel is added - // immediately to define grid. - if (tabsOnRightSide) { - this.add(this.pnlContent, "span 1 " + (size + 1) + ", w " + (100 - pctTabW) + "%!, h 100%!"); - this.pnlContent.setBorder(new MatteBorder(0, 0, 0, 1, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); - } - - this.add(new JPanel(), "w 0, h 0!"); - - // If tabs are on right side, content panel - // must be added after spacer, which then defines the grid. - if (!tabsOnRightSide) { - this.add(this.pnlContent, "span 1 " + (size + 1) + ", w " + (100 - pctTabW) + "%!, h 100%!"); - this.pnlContent.setBorder(new MatteBorder(0, 1, 0, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); - } - - // Add all tabs - VTab tab; - this.allVTabs = new ArrayList(); - - for (int i = 0; i < size; i++) { - tab = new VTab(childPanels.get(i).getName(), i); - tab.setToolTipText(childPanels.get(i).getToolTipText()); - - if (i == 0) { - tab.setBackground(this.activeColor); - this.active = 0; - } else { - tab.setBackground(this.inactiveColor); - } - - this.add(tab, "w " + pctTabW + "%!, h " + pctTabH + "%!," - + " gap 0 0 " + pctSpacing + " " + pctSpacing + "%!, ay center"); - this.allVTabs.add(tab); - - // Add card to content panel - this.pnlContent.add(childPanels.get(i), "CARD" + i); - } - } - - /** - * Programatically flips tab layout to specified number (without needing a - * mouse event). - * - * @param index - *   Tab number, starting from 0 - */ - public void showTab(final int index) { - if (index >= this.allVTabs.size()) { - return; - } - - this.allVTabs.get(this.active).setBackground(this.inactiveColor); - this.active = index; - this.cards.show(this.pnlContent, "CARD" + index); - this.allVTabs.get(this.active).setBackground(this.activeColor); - } - - /** - * Gets the content panel. - * - * @return JPanel - */ - public JPanel getContentPanel() { - return this.pnlContent; - } - - /** - * A single instance of a vertical tab, with paintComponent overridden to - * provide vertical-ness. Also manages root level hover and click effects. - * - */ - public class VTab extends JPanel { - private String msg; - private int id; - - // ID is used to retrieve this tab from the list of allVTabs. - /** - * Creates the actual clickable tab. - * - * @param txt - *   String text in tab - * @param i - *   int index - */ - VTab(final String txt, final int i) { - super(); - this.setLayout(new MigLayout("insets 0, gap 0")); - this.setOpaque(false); - this.msg = txt; - this.id = i; - - this.addMouseListener(new MouseAdapter() { - @Override - public void mouseEntered(final MouseEvent e) { - if (VTab.this.id != FVerticalTabPanel.this.active) { - VTab.this.setBackground(FVerticalTabPanel.this.hoverColor); - } - } - - @Override - public void mouseExited(final MouseEvent e) { - if (VTab.this.id != FVerticalTabPanel.this.active) { - VTab.this.setBackground(FVerticalTabPanel.this.inactiveColor); - } - } - - @Override - public void mousePressed(final MouseEvent e) { - FVerticalTabPanel.this.allVTabs.get(FVerticalTabPanel.this.active).setBackground( - FVerticalTabPanel.this.inactiveColor); - FVerticalTabPanel.this.active = VTab.this.id; - FVerticalTabPanel.this.cards.show(FVerticalTabPanel.this.pnlContent, "CARD" + VTab.this.id); - VTab.this.setBackground(FVerticalTabPanel.this.activeColor); - } - }); - - // Resize adapter - this.addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - // Careful with this font scale factor; the vertical tabs will be - // unreadable - // if small window, too big if large window. - setFont(FSkin.getFont((int) (h * 0.16))); - } - }); - } - - @Override - protected void paintComponent(final Graphics g) { - //super.paintComponent(g); - w = this.getWidth(); - h = this.getHeight(); - - g.setColor(this.getBackground()); - g.fillRoundRect(0, 0, w, h, 10, 10); - g.fillRect(11, 0, w, h); - - // Rotate, draw string, rotate back (to allow hover border to be - // painted properly) - final Graphics2D g2d = (Graphics2D) g; - final AffineTransform at = g2d.getTransform(); - - if (tabsOnRightSide) { - at.rotate(Math.toRadians(90), 0, 0); - g2d.setTransform(at); - g2d.setColor(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - g2d.drawString(this.msg, 5, -4); - } else { - at.rotate(Math.toRadians(-90), 0, 0); - g2d.setTransform(at); - g2d.setColor(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - // Rotated, so follows: (this.msg, vertical coord, horizontal coord) - g2d.drawString(this.msg, 8 - h, w - 6); - } - - if (tabsOnRightSide) { - at.rotate(Math.toRadians(-90), 0, 0); - } else { - at.rotate(Math.toRadians(90), 0, 0); - } - - g2d.setTransform(at); - } - - /** - * @param txt0 - *   String - */ - public void setText(String txt0) { - this.msg = txt0; - } - } - - /** @return List */ - public List getAllVTabs() { - return allVTabs; - } -} diff --git a/src/main/java/forge/model/FModel.java b/src/main/java/forge/model/FModel.java index 2fb9b4c9a58..f3a8cc81e53 100644 --- a/src/main/java/forge/model/FModel.java +++ b/src/main/java/forge/model/FModel.java @@ -40,6 +40,9 @@ 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; @@ -51,8 +54,6 @@ import forge.util.HttpUtil; import forge.util.IStorageView; import forge.util.MultiplexOutputStream; import forge.util.StorageView; -import forge.view.match.ViewField; -import forge.view.match.ViewTabber; /** * The default Model implementation for Forge. @@ -392,7 +393,7 @@ public enum FModel { */ public final boolean savePrefs() { final ForgePreferences fp = this.preferences; - final List fieldViews = Singletons.getView().getViewMatch().getFieldViews(); + final List fieldViews = VMatchUI.SINGLETON_INSTANCE.getFieldViews(); // AI field is at index [0] fp.setPref(FPref.PHASE_AI_UPKEEP, String.valueOf(fieldViews.get(0).getLblUpkeep().getEnabled())); @@ -426,11 +427,11 @@ public enum FModel { 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 ViewTabber v = Singletons.getView().getViewMatch().getViewTabber(); + final VDev v = VMatchUI.SINGLETON_INSTANCE.getViewDevMode(); Constant.Runtime.MILL[0] = v.getLblMilling().getEnabled(); fp.setPref(FPref.DEV_MILLING_LOSS, String.valueOf(Constant.Runtime.MILL[0])); - fp.setPref(FPref.UI_LAYOUT_PARAMS, String.valueOf(Singletons.getView().getViewMatch().getLayoutParams())); + //fp.setPref(FPref.UI_LAYOUT_PARAMS, String.valueOf(Singletons.getView().getViewMatch().getLayoutParams())); fp.setPref(FPref.DEV_UNLIMITED_LAND, String.valueOf(v.getLblUnlimitedLands().getEnabled())); fp.save(); @@ -445,7 +446,7 @@ public enum FModel { */ public final boolean loadPrefs() { final ForgePreferences fp = Singletons.getModel().getPreferences(); - final List fieldViews = Singletons.getView().getViewMatch().getFieldViews(); + final List 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); @@ -482,7 +483,7 @@ public enum FModel { 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)); + //Singletons.getView().getViewMatch().setLayoutParams(fp.getPref(FPref.UI_LAYOUT_PARAMS)); return true; } diff --git a/src/main/java/forge/view/ButtonUtil.java b/src/main/java/forge/view/ButtonUtil.java index 6ce6193732f..db49126363a 100644 --- a/src/main/java/forge/view/ButtonUtil.java +++ b/src/main/java/forge/view/ButtonUtil.java @@ -19,7 +19,7 @@ package forge.view; import javax.swing.JButton; -import forge.Singletons; +import forge.gui.match.VMatchUI; /** *

@@ -109,7 +109,7 @@ public class ButtonUtil { * @return a {@link forge.MyButton} object. */ private static JButton getOK() { - return Singletons.getView().getViewMatch().getBtnOK(); + return VMatchUI.SINGLETON_INSTANCE.getBtnOK(); } /** @@ -120,6 +120,6 @@ public class ButtonUtil { * @return a {@link forge.MyButton} object. */ private static JButton getCancel() { - return Singletons.getView().getViewMatch().getBtnCancel(); + return VMatchUI.SINGLETON_INSTANCE.getBtnCancel(); } } diff --git a/src/main/java/forge/view/FView.java b/src/main/java/forge/view/FView.java index 633a70dbc26..030d0a5e5dd 100644 --- a/src/main/java/forge/view/FView.java +++ b/src/main/java/forge/view/FView.java @@ -1,143 +1,224 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.view; - -import java.awt.Dimension; -import java.awt.Frame; - -import javax.swing.JFrame; -import javax.swing.JLayeredPane; -import javax.swing.SwingUtilities; - -import forge.AllZone; -import forge.Singletons; -import forge.control.FControl; -import forge.gui.toolbox.FOverlay; -import forge.gui.toolbox.FSkin; - -/** - * The main view for Forge: a java swing application. All view class instances - * should be accessible from here. - */ -public enum FView { - /** */ - SINGLETON_INSTANCE; - - private final JFrame frame = new JFrame(); - private final JLayeredPane lpnContent = new JLayeredPane(); - private final FOverlay overlay = new FOverlay(); - - private SplashFrame splash; - private ViewMatchUI match = null; - private ViewEditorUI editor = null; - private ViewBazaarUI bazaar = null; - - /** The splash frame is guaranteed to exist when this constructor exits. */ - private FView() { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - try { splash = new SplashFrame(); } - catch (Exception e) { e.printStackTrace(); } - } - }); - } - - /** Transitions between splash and main UI. Called after everything is initialized. */ - public void initialize() { - SplashFrame.PROGRESS_BAR.setDescription("Creating display components."); - - // After events and shortcuts are assembled, instantiate all different state screens - Singletons.getView().instantiateCachedUIStates(); - - // Frame styling - frame.setMinimumSize(new Dimension(800, 600)); - frame.setLocationRelativeTo(null); - frame.setExtendedState(frame.getExtendedState() | Frame.MAXIMIZED_BOTH); - frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - frame.setIconImage(FSkin.getIcon(FSkin.ForgeIcons.ICO_FAVICON).getImage()); - frame.setTitle("Forge: " + Singletons.getModel().getBuildInfo().getVersion()); - - // Content pane - FView.this.lpnContent.setOpaque(true); - frame.setContentPane(FView.this.lpnContent); - - // Overlay - overlay.setBounds(0, 0, frame.getWidth(), frame.getHeight()); - overlay.setBackground(FSkin.getColor(FSkin.Colors.CLR_OVERLAY)); - FView.this.lpnContent.add(overlay, JLayeredPane.MODAL_LAYER); - - // All is ready to go - fire up home screen and discard splash frame. - Singletons.getControl().changeState(FControl.HOME_SCREEN); - - FView.this.splash.dispose(); - FView.this.splash = null; - - frame.setVisible(true); - } - - /** @return {@link javax.swing.JLayeredPane} */ - public JLayeredPane getLayeredContentPane() { - return FView.this.lpnContent; - } - - /** @return {@link javax.swing.JFrame} */ - public JFrame getFrame() { - return this.frame; - } - - /** @return {@link forge.gui.toolbox.FOverlay} */ - public FOverlay getOverlay() { - return FView.this.overlay; - } - - /** @return {@link forge.view.ViewMatchUI} */ - public ViewMatchUI getViewMatch() { - if (Singletons.getControl().getState() != FControl.MATCH_SCREEN) { - throw new IllegalArgumentException("FView$getVIewMatch\n" - + "may only be called while the match UI is showing."); - } - return FView.this.match; - } - - /** @return {@link forge.view.ViewEditorUI} */ - public ViewEditorUI getViewEditor() { - if (Singletons.getControl().getState() != FControl.DEFAULT_EDITOR) { - throw new IllegalArgumentException("FView$getViewEditor\n" - + "may only be called while the editor UI is showing."); - } - return FView.this.editor; - } - - /** @return {@link forge.view.ViewBazaarUI} */ - public ViewBazaarUI getViewBazaar() { - if (Singletons.getControl().getState() != FControl.QUEST_BAZAAR) { - throw new IllegalArgumentException("FView$getViewBazaar\n" - + "may only be called while the bazaar UI is showing."); - } - return FView.this.bazaar; - } - - /** Like it says. */ - public void instantiateCachedUIStates() { - FView.this.match = new ViewMatchUI(); - FView.this.editor = new ViewEditorUI(); - FView.this.bazaar = new ViewBazaarUI(AllZone.getQuest().getBazaar()); - ViewHomeUI.SINGLETON_INSTANCE.initialize(); - } -} +package forge.view; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.Graphics; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JFrame; +import javax.swing.JLayeredPane; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +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; +import forge.gui.framework.DragCell; +import forge.gui.framework.EDocID; +import forge.gui.framework.SLayoutConstants; +import forge.gui.framework.SOverflowUtil; +import forge.gui.framework.SResizingUtil; +import forge.gui.home.VHomeUI; +import forge.gui.match.VMatchUI; +import forge.gui.toolbox.FOverlay; +import forge.gui.toolbox.FPanel; +import forge.gui.toolbox.FSkin; + +/** */ +public enum FView { + /** */ + SINGLETON_INSTANCE; + private final List allCells = new ArrayList(); + private SplashFrame splash; + + // Non-singleton instances (deprecated, but not updated yet) + private ViewEditorUI editor = null; + private ViewBazaarUI bazaar = null; + + // Top-level UI components; all have getters. + private final JFrame frmDocument = new JFrame(); + private final JPanel pnlContent = new JPanel(); + private final FPanel pnlInsets = new FPanel(new BorderLayout()); + private final JPanel pnlPreview = new PreviewPanel(); + private final JPanel pnlTabOverflow = new JPanel(new MigLayout("insets 0, gap 0, wrap")); + private final JLayeredPane lpnDocument = new JLayeredPane(); + private final FOverlay pnlOverlay = new FOverlay(); + + // + private FView() { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + try { splash = new SplashFrame(); } + catch (Exception e) { e.printStackTrace(); } + } + }); + } + + /** */ + public void initialize() { + SplashFrame.PROGRESS_BAR.setDescription("Creating display components."); + Singletons.getView().cacheUIStates(); + + // Frame styling + frmDocument.setMinimumSize(new Dimension(800, 600)); + frmDocument.setLocationRelativeTo(null); + frmDocument.setExtendedState(frmDocument.getExtendedState() | Frame.MAXIMIZED_BOTH); + frmDocument.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + frmDocument.setIconImage(FSkin.getIcon(FSkin.ForgeIcons.ICO_FAVICON).getImage()); + frmDocument.setTitle("Forge: " + Singletons.getModel().getBuildInfo().getVersion()); + + // Frame components + frmDocument.setContentPane(lpnDocument); + lpnDocument.add(pnlInsets, (Integer) 1); + lpnDocument.add(pnlPreview, (Integer) 2); + lpnDocument.add(pnlTabOverflow, (Integer) 3); + lpnDocument.add(pnlOverlay, JLayeredPane.MODAL_LAYER); + + pnlInsets.add(pnlContent, BorderLayout.CENTER); + pnlInsets.setBackgroundTexture(FSkin.getIcon(FSkin.Backgrounds.BG_TEXTURE)); + pnlInsets.setForegroundImage(FSkin.getIcon(FSkin.Backgrounds.BG_MATCH)); + pnlInsets.setBorder(new EmptyBorder( + SLayoutConstants.BORDER_T, SLayoutConstants.BORDER_T, 0, 0)); + + pnlContent.setOpaque(false); + pnlContent.setLayout(null); + + pnlOverlay.setBackground(FSkin.getColor(FSkin.Colors.CLR_OVERLAY)); + + // Populate all drag tabs. After they are realized, + // their controller can initialize actions on their components. + for (EDocID doc : EDocID.values()) { + if (doc.getDoc().getControl() == null) { continue; } + doc.getDoc().getControl().initialize(); + } + + // All is ready to go - fire up home screen and discard splash frame. + Singletons.getControl().changeState(FControl.HOME_SCREEN); + + FView.this.splash.dispose(); + FView.this.splash = null; + + frmDocument.setVisible(true); + + // TODO MOVE TO CONTROL! + // TODO delete FViewOld + lpnDocument.addMouseListener(SOverflowUtil.getHideOverflowListener()); + lpnDocument.addComponentListener(SResizingUtil.getWindowResizeListener()); + } + + /** @return {@link javax.swing.JFrame} */ + public JFrame getFrame() { + return frmDocument; + } + + /** @return {@link javax.swing.JLayeredPane} */ + public JLayeredPane getLpnDocument() { + return lpnDocument; + } + + /** @return {@link javax.swing.JPanel} */ + public JPanel getPnlInsets() { + return pnlInsets; + } + + /** @return {@link javax.swing.JPanel} */ + public JPanel getPnlContent() { + return pnlContent; + } + + /** @return {@link javax.swing.JPanel} */ + public JPanel getPnlPreview() { + return pnlPreview; + } + + /** @return {@link javax.swing.JPanel} */ + public JPanel getPnlTabOverflow() { + return pnlTabOverflow; + } + + /** @return {@link forge.gui.toolbox.FOverlay} */ + public FOverlay getOverlay() { + return FView.this.pnlOverlay; + } + + /** @return {@link java.util.List}<{@link forge.gui.framework.DragCell}> */ + public List getDragCells() { + final List clone = new ArrayList(); + clone.addAll(allCells); + return clone; + } + + /** @param pnl0   {@link forge.gui.framework.DragCell} */ + public void addDragCell(final DragCell pnl0) { + allCells.add(pnl0); + pnlContent.add(pnl0); + } + + /** @param pnl0   {@link forge.gui.framework.DragCell} */ + public void removeDragCell(final DragCell pnl0) { + allCells.remove(pnl0); + pnlContent.remove(pnl0); + } + + /** */ + public void removeAllDragCells() { + allCells.clear(); + pnlContent.removeAll(); + } + + /** PreviewPanel shows where a dragged component could + * come to rest when the mouse is released.
+ * This class is an unfortunate necessity to overcome + * translucency issues for preview panel. */ + @SuppressWarnings("serial") + class PreviewPanel extends JPanel { + /** PreviewPanel shows where a dragged component could + * come to rest when the mouse is released. */ + public PreviewPanel() { + super(); + setOpaque(false); + setVisible(false); + setBorder(new LineBorder(Color.DARK_GRAY, 2)); + } + + @Override + public void paintComponent(final Graphics g) { + super.paintComponent(g); + g.setColor(new Color(0, 0, 0, 50)); + g.fillRect(0, 0, getWidth(), getHeight()); + } + } + + /** @return {@link forge.view.ViewEditorUI} */ + public ViewEditorUI getViewEditor() { + if (Singletons.getControl().getState() != FControl.DEFAULT_EDITOR) { + throw new IllegalArgumentException("FView$getViewEditor\n" + + "may only be called while the editor UI is showing."); + } + return FView.this.editor; + } + + /** @return {@link forge.view.ViewBazaarUI} */ + public ViewBazaarUI getViewBazaar() { + if (Singletons.getControl().getState() != FControl.QUEST_BAZAAR) { + throw new IllegalArgumentException("FView$getViewBazaar\n" + + "may only be called while the bazaar UI is showing."); + } + return FView.this.bazaar; + } + + /** */ + private void cacheUIStates() { + FView.this.editor = new ViewEditorUI(); + FView.this.bazaar = new ViewBazaarUI(AllZone.getQuest().getBazaar()); + VMatchUI.SINGLETON_INSTANCE.instantiate(); + VHomeUI.SINGLETON_INSTANCE.instantiate(); + } +} diff --git a/src/main/java/forge/view/ViewMatchUI.java b/src/main/java/forge/view/ViewMatchUI.java deleted file mode 100644 index 49fb4e176cf..00000000000 --- a/src/main/java/forge/view/ViewMatchUI.java +++ /dev/null @@ -1,422 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.view; - -import java.awt.Color; -import java.awt.Cursor; -import java.awt.Graphics; -import java.awt.Rectangle; -import java.awt.event.MouseEvent; -import java.awt.event.MouseMotionAdapter; -import java.util.List; - -import javax.swing.JButton; -import javax.swing.JPanel; - -import net.miginfocom.swing.MigLayout; -import forge.control.ControlMatchUI; -import forge.gui.toolbox.FPanel; -import forge.gui.toolbox.FSkin; -import forge.view.match.ViewBattlefield; -import forge.view.match.ViewDetail; -import forge.view.match.ViewDock; -import forge.view.match.ViewField; -import forge.view.match.ViewHand; -import forge.view.match.ViewMessage; -import forge.view.match.ViewPicture; -import forge.view.match.ViewTabber; - -/** - * - Lays out containers and borders for resizeable layout.
- * - Instantiates top-level controller for match UI.
- * - Has access methods for all child controllers
- * - Implements Display interface used in singleton pattern - * - */ - -@SuppressWarnings("serial") -public class ViewMatchUI extends FPanel { - private final ControlMatchUI control; - private final ViewBattlefield battlefield; - private final ViewDetail detail; - private final ViewDock dock; - private final ViewHand hand; - private final ViewMessage message; - private final ViewPicture picture; - private final ViewTabber tabber; - private int w, h, b; - private double delta; - - // Default layout parameters (all in percent!) - private double tabberWpct = 0.15; - private double tabberHpct = 0.55; - private double battleWpct = 0.68; - private double battleHpct = 0.73; - private double pictureHpct = 0.4; - private double detailHpct = 0.45; - - private static final int BOUNDARY_THICKNESS_PX = 6; - - // Boundary rectangles for all components, and boundary panel objects. - private Rectangle pictureBounds, detailBounds, battleBounds, handBounds, tabberBounds, dockBounds, inputBounds; - - private BoundaryPanel pnlB1, pnlB2, pnlB3, pnlB4, pnlB5, pnlB6; - - private RegionPanel pnlPicture, pnlDetail, pnlBattlefield, pnlHand, pnlTabber, pnlDock, pnlInput; - - /** - * - Lays out battle, sidebar, user areas in locked % vals and repaints as - * necessary.
- * - Instantiates top-level controller for match UI.
- * - Has access methods for all child controllers
- * - Implements Display interface used in singleton pattern - * - */ - public ViewMatchUI() { - super(); - - // Set properties - this.setOpaque(false); - this.setBackgroundTexture(FSkin.getIcon(FSkin.Backgrounds.BG_TEXTURE)); - this.setForegroundImage(FSkin.getIcon(FSkin.Backgrounds.BG_MATCH).getImage()); - this.setCornerDiameter(0); - this.setBorderToggle(false); - this.setLayout(null); - b = (int) Math.ceil(BOUNDARY_THICKNESS_PX / 2); - - // Declare and add containers and resizers for various regions in layout - pnlPicture = new RegionPanel(); - pnlDetail = new RegionPanel(); - pnlBattlefield = new RegionPanel(); - pnlHand = new RegionPanel(); - pnlDock = new RegionPanel(); - pnlInput = new RegionPanel(); - pnlTabber = new RegionPanel(); - - pnlB1 = new BoundaryPanel(true); - pnlB2 = new BoundaryPanel(); - pnlB3 = new BoundaryPanel(true); - pnlB4 = new BoundaryPanel(); - pnlB5 = new BoundaryPanel(true); - pnlB6 = new BoundaryPanel(true); - - add(pnlPicture); - add(pnlDetail); - add(pnlBattlefield); - add(pnlHand); - add(pnlDock); - add(pnlInput); - add(pnlTabber); - - add(pnlB1); - add(pnlB2); - add(pnlB3); - add(pnlB4); - add(pnlB5); - add(pnlB6); - - // Declare and add various view components - message = new ViewMessage(); - hand = new ViewHand(this); - dock = new ViewDock(); - battlefield = new ViewBattlefield(); - tabber = new ViewTabber(); - detail = new ViewDetail(); - picture = new ViewPicture(); - - String constraints = "w 100%!, h 100%!"; - pnlInput.add(message, constraints); - pnlHand.add(hand, constraints); - pnlBattlefield.add(battlefield, constraints); - pnlDock.add(dock, constraints); - pnlTabber.add(tabber, constraints); - pnlDetail.add(detail, constraints); - pnlPicture.add(picture, constraints); - - // After all components are in place, instantiate controller. - addDragListeners(); - control = new ControlMatchUI(this); - } - - /** - * Panel resizing algorithms. Basically, find the change in % per drag - * event, then add that to an appropriate parameter. In some cases, also - * remove the delta from an appropriate parameter. - * - */ - - // Formulas here SHOULD NOT BE VERY COMPLICATED at all. If they're - // complicated, you're doing it wrong. The complicated part should - // be in calculateBounds(). - private void addDragListeners() { - pnlB1.addMouseMotionListener(new MouseMotionAdapter() { - @Override - public void mouseDragged(final MouseEvent e) { - delta = e.getY() / (double) h; - tabberHpct += delta; - repaint(); - } - }); - - pnlB2.addMouseMotionListener(new MouseMotionAdapter() { - @Override - public void mouseDragged(final MouseEvent e) { - delta = e.getX() / (double) w; - tabberWpct += delta; - battleWpct -= delta; - repaint(); - } - }); - - pnlB3.addMouseMotionListener(new MouseMotionAdapter() { - @Override - public void mouseDragged(final MouseEvent e) { - delta = e.getY() / (double) h; - battleHpct += delta; - repaint(); - } - }); - - pnlB4.addMouseMotionListener(new MouseMotionAdapter() { - @Override - public void mouseDragged(final MouseEvent e) { - delta = e.getX() / (double) w; - battleWpct += delta; - repaint(); - } - }); - - pnlB5.addMouseMotionListener(new MouseMotionAdapter() { - @Override - public void mouseDragged(final MouseEvent e) { - delta = e.getY() / (double) h; - pictureHpct += delta; - detailHpct -= delta; - repaint(); - } - }); - - pnlB6.addMouseMotionListener(new MouseMotionAdapter() { - @Override - public void mouseDragged(final MouseEvent e) { - delta = e.getY() / (double) h; - detailHpct += delta; - repaint(); - } - }); - } - - /** - * Put together default layout; most values are dependent on sibling - * component dimensions. The whole layout can be defined from six - * parameters. - * - */ - private void calculateBounds() { - tabberBounds = new Rectangle(b, b, (int) (tabberWpct * w), (int) (tabberHpct * h)); - - inputBounds = new Rectangle(tabberBounds.x, tabberBounds.height + 3 * b, tabberBounds.width, h - - tabberBounds.height - 4 * b); - - battleBounds = new Rectangle(tabberBounds.width + 3 * b, b, (int) (w * battleWpct), (int) (h * battleHpct)); - - handBounds = new Rectangle(battleBounds.x, battleBounds.height + 3 * b, battleBounds.width, h - - battleBounds.height - 4 * b); - - pictureBounds = new Rectangle(battleBounds.x + battleBounds.width + 2 * b, b, w - battleBounds.x - - battleBounds.width - 3 * b, (int) (h * pictureHpct)); - - detailBounds = new Rectangle(pictureBounds.x, pictureBounds.height + 3 * b, pictureBounds.width, - (int) (h * detailHpct)); - - dockBounds = new Rectangle(pictureBounds.x, detailBounds.y + detailBounds.height + 2 * b, pictureBounds.width, - h - detailBounds.y - detailBounds.height - 3 * b); - - // Apply bounds to regions. - pnlPicture.setBounds(pictureBounds); - pnlDetail.setBounds(detailBounds); - pnlBattlefield.setBounds(battleBounds); - pnlHand.setBounds(handBounds); - pnlDock.setBounds(dockBounds); - pnlInput.setBounds(inputBounds); - pnlTabber.setBounds(tabberBounds); - - // Apply bounds to boundaries. - pnlB1.setBounds(new Rectangle(b, tabberBounds.height + b, tabberBounds.width, 2 * b)); - - pnlB2.setBounds(new Rectangle(tabberBounds.width + b, b, 2 * b, h - 2 * b)); - - pnlB3.setBounds(new Rectangle(battleBounds.x, battleBounds.height + b, battleBounds.width, 2 * b)); - - pnlB4.setBounds(new Rectangle(battleBounds.x + battleBounds.width, b, 2 * b, h - 2 * b)); - - pnlB5.setBounds(new Rectangle(pictureBounds.x, pictureBounds.height + b, pictureBounds.width, 2 * b)); - - pnlB6.setBounds(new Rectangle(pictureBounds.x, detailBounds.y + detailBounds.height, detailBounds.width, 2 * b)); - - this.revalidate(); - } // End calculateBounds() - - /** @return String, comma delimited layout parameters. */ - public String getLayoutParams() { - String s = ""; - s += Double.toString(tabberWpct) + ","; - s += Double.toString(tabberHpct) + ","; - s += Double.toString(battleWpct) + ","; - s += Double.toString(battleHpct) + ","; - s += Double.toString(pictureHpct) + ","; - s += Double.toString(detailHpct); - - return s; - } - - /** - * Takes a string of comma-delimited layout parameters and applies to layout. - * @param s0   String - */ - public void setLayoutParams(String s0) { - if (s0 == null || s0.isEmpty()) { - return; - } - - String[] vals = s0.split(","); - - tabberWpct = Double.parseDouble(vals[0]); - tabberHpct = Double.parseDouble(vals[1]); - battleWpct = Double.parseDouble(vals[2]); - battleHpct = Double.parseDouble(vals[3]); - pictureHpct = Double.parseDouble(vals[4]); - detailHpct = Double.parseDouble(vals[5]); - } - - /** Consolidates cursor and opacity settings in one place. */ - private class BoundaryPanel extends JPanel { - public BoundaryPanel() { - this(false); - } - - public BoundaryPanel(boolean movesNorthSouth) { - super(); - // For testing, comment this opaque setter. - setOpaque(false); - - if (movesNorthSouth) { - setBackground(Color.red); - setCursor(new Cursor(Cursor.N_RESIZE_CURSOR)); - } else { - setBackground(Color.blue); - setCursor(new Cursor(Cursor.E_RESIZE_CURSOR)); - } - } - } - - /** Consolidates opacity settings in one place. */ - private class RegionPanel extends JPanel { - public RegionPanel() { - super(); - // For testing, comment this opaque setter, uncomment the border. - // setBorder(new LineBorder(Color.green, 1)); - setOpaque(false); - setLayout(new MigLayout("insets 0, gap 0")); - } - } - - /** - * The null layout used in MatchFrame has zones split into percentage values - * to prevent child components pushing around the parent layout. A single - * instance of BodyPanel holds these zones, and handles the percentage - * resizing. - * - * @param g - * Graphics object - */ - @Override - public void paintComponent(final Graphics g) { - h = getHeight(); - w = getWidth(); - - calculateBounds(); - super.paintComponent(g); - } - - //========== Retrieval methods - - /** @return {@link forge.control.ControlMatchUI} */ - public ControlMatchUI getControl() { - return this.control; - } - - /** - * Gets the field views. - * - * @return List - */ - public List getFieldViews() { - return ViewMatchUI.this.battlefield.getFields(); - } - - /** @return {@link forge.view.match.ViewDock} */ - public ViewDock getDockView() { - return this.dock; - } - - /** @return {@link forge.view.match.ViewTabber} */ - public ViewTabber getViewTabber() { - return this.tabber; - } - - /** @return {@link forge.view.match.ViewDetail} */ - public ViewDetail getViewDetail() { - return this.detail; - } - - /** @return {@link forge.view.match.ViewPicture} */ - public ViewPicture getViewPicture() { - return this.picture; - } - - /** @return {@link forge.view.match.ViewHand} */ - public ViewHand getViewHand() { - return this.hand; - } - - /** @return {@link forge.view.match.ViewMessage} */ - public ViewMessage getViewMessage() { - return this.message; - } - - /** @return {@link forge.view.match.ViewBattlefield} */ - public ViewBattlefield getViewBattlefield() { - return this.battlefield; - } - - /** @return {@link javax.swing.JButton} */ - public JButton getBtnCancel() { - return this.message.getBtnCancel(); - } - - /** @return {@link javax.swing.JButton} */ - public JButton getBtnOK() { - return this.message.getBtnOK(); - } - - /** @return {@link javax.swing.JPanel} */ - public JPanel getPnlBattlefield() { - return this.pnlBattlefield; - } -} diff --git a/src/main/java/forge/view/match/ViewBattlefield.java b/src/main/java/forge/view/match/ViewBattlefield.java deleted file mode 100644 index a45781643c3..00000000000 --- a/src/main/java/forge/view/match/ViewBattlefield.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.view.match; - -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JPanel; - -import net.miginfocom.swing.MigLayout; -import forge.AllZone; - -/** - * Battlefield, assembles and contains instances of MatchPlayer. SHOULD PROBABLY - * COLLAPSE INTO TOP LEVEL. - * - */ -@SuppressWarnings("serial") -public class ViewBattlefield extends JPanel { - private final List fields; - - /** - * An FPanel that adds instances of ViewField fields from player name list. - * - */ - public ViewBattlefield() { - super(); - this.setOpaque(false); - this.setLayout(new MigLayout("wrap, insets 0, gap 0")); - - // When future codebase upgrades allow, as many fields as - // necessary can be instantiated here. Doublestrike 29-10-11 - - this.fields = new ArrayList(); - - ViewField temp; - String constraints = "h 49.5%!, w 100%!"; - - temp = new ViewField(AllZone.getComputerPlayer()); - this.add(temp, constraints); - this.fields.add(temp); - - temp = new ViewField(AllZone.getHumanPlayer()); - this.add(temp, constraints + ", gaptop 1%"); - this.fields.add(temp); - } - - /** - * Returns a list of field components in battlefield. - * - * @return List - */ - public List getFields() { - return this.fields; - } -} diff --git a/src/main/java/forge/view/match/ViewDetail.java b/src/main/java/forge/view/match/ViewDetail.java deleted file mode 100644 index 82df234d781..00000000000 --- a/src/main/java/forge/view/match/ViewDetail.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.view.match; - -import net.miginfocom.swing.MigLayout; -import forge.control.match.ControlDetail; -import forge.gui.CardDetailPanel; -import forge.gui.toolbox.FPanel; -import forge.gui.toolbox.FSkin; - -/** - * TODO: Write javadoc for this type. - * - */ -@SuppressWarnings("serial") -public class ViewDetail extends FPanel { - private ControlDetail control; - private CardDetailPanel pnlDetail; - - /** - * Instantiates a new view detail. - */ - public ViewDetail() { - super(); - pnlDetail = new CardDetailPanel(null); - pnlDetail.setOpaque(false); - - this.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); - this.setLayout(new MigLayout("insets 0, gap 0")); - - add(pnlDetail, "w 100%!, h 100%!"); - control = new ControlDetail(this); - - setFont(FSkin.getFont(12)); - } - - /** - * Gets the controller. - * - * @return ControlDetail - */ - public ControlDetail getControl() { - return control; - } - - /** - * Gets the pnl detail. - * - * @return CardDetailPanel - */ - public CardDetailPanel getPnlDetail() { - return pnlDetail; - } -} diff --git a/src/main/java/forge/view/match/ViewDock.java b/src/main/java/forge/view/match/ViewDock.java deleted file mode 100644 index ef9193b6930..00000000000 --- a/src/main/java/forge/view/match/ViewDock.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.view.match; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.Graphics; -import java.awt.Image; -import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ImageIcon; -import javax.swing.JLabel; -import javax.swing.JPanel; - -import net.miginfocom.swing.MigLayout; -import forge.Singletons; -import forge.control.match.ControlDock; -import forge.gui.OverlayUtils; -import forge.gui.toolbox.FButton; -import forge.gui.toolbox.FOverlay; -import forge.gui.toolbox.FPanel; -import forge.gui.toolbox.FSkin; - -/** - * Swing component for button dock. - * - */ -@SuppressWarnings("serial") -public class ViewDock extends FPanel { - private final ControlDock control; - private final Action actClose; - - /** - * Swing component for button dock. - * - */ - public ViewDock() { - super(); - this.setToolTipText("Shortcut Button Dock"); - //this.setLayout(new MigLayout("insets 0, gap 0, ay center, ax center")); - - // Mig layout does not support wrapping! - // http://stackoverflow.com/questions/5715833/how-do-you-make-miglayout-behave-like-wrap-layout - FlowLayout layFlow = new FlowLayout(); - layFlow.setHgap(10); - layFlow.setVgap(10); - this.setLayout(layFlow); - - this.actClose = new AbstractAction() { - @Override - public void actionPerformed(final ActionEvent e) { - OverlayUtils.hideOverlay(); - } - }; - - final JLabel btnConcede = new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_CONCEDE), "Concede Game"); - btnConcede.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - ViewDock.this.control.concede(); - } - }); - - final JLabel btnSettings = new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_SETTINGS), "Game Settings"); - btnSettings.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - ViewDock.this.overlaySettings(); - } - }); - - final JLabel btnEndTurn = new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_ENDTURN), "End Turn"); - btnEndTurn.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - ViewDock.this.control.endTurn(); - } - }); - - final JLabel btnViewDeckList = new DockButton(FSkin.getIcon(FSkin.DockIcons.ICO_DECKLIST), "View Deck List"); - btnViewDeckList.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - ViewDock.this.control.viewDeckList(); - } - }); - - this.add(btnConcede); - //this.add(btnShortcuts); - this.add(btnSettings); - this.add(btnEndTurn); - this.add(btnViewDeckList); - - // After all components are in place, instantiate controller. - this.control = new ControlDock(this); - } - - /** - * Gets the controller. - * - * @return ControlDock - */ - public ControlDock getControl() { - return this.control; - } - - /** - * Buttons in Dock. JLabels are used to allow hover effects. - */ - public class DockButton extends JLabel { - private final Image img; - private final Color hoverBG = FSkin.getColor(FSkin.Colors.CLR_HOVER); - private final Color defaultBG = new Color(0, 0, 0, 0); - private Color clrBorders = new Color(0, 0, 0, 0); - private int w, h; - - /** - * Buttons in Dock. JLabels are used to allow hover effects. - * - * @param i0 - *   ImageIcon to show in button - * @param s0 - *   Tooltip string - */ - public DockButton(final ImageIcon i0, final String s0) { - super(); - this.setToolTipText(s0); - this.setOpaque(false); - this.setBackground(this.defaultBG); - this.img = i0.getImage(); - - Dimension size = new Dimension(30, 30); - this.setMinimumSize(size); - this.setMaximumSize(size); - this.setPreferredSize(size); - - this.addMouseListener(new MouseAdapter() { - @Override - public void mouseEntered(final MouseEvent e) { - DockButton.this.clrBorders = FSkin.getColor(FSkin.Colors.CLR_BORDERS); - DockButton.this.setBackground(DockButton.this.hoverBG); - } - - @Override - public void mouseExited(final MouseEvent e) { - DockButton.this.clrBorders = new Color(0, 0, 0, 0); - DockButton.this.setBackground(DockButton.this.defaultBG); - } - }); - } - - /* - * (non-Javadoc) - * - * @see javax.swing.JComponent#paintComponent(java.awt.Graphics) - */ - @Override - public void paintComponent(final Graphics g) { - this.w = this.getWidth(); - this.h = this.getHeight(); - g.setColor(this.getBackground()); - g.fillRect(0, 0, this.w, this.h); - g.setColor(this.clrBorders); - g.drawRect(0, 0, this.w - 1, this.h - 1); - g.drawImage(this.img, 0, 0, this.w, this.h, null); - super.paintComponent(g); - } - } - - /** */ - private void overlaySettings() { - final FOverlay overlay = Singletons.getView().getOverlay(); - overlay.setLayout(new MigLayout("insets 0")); - OverlayUtils.showOverlay(); - - final JPanel parent = new JPanel(); - parent.setBackground(Color.red.darker()); - overlay.add(parent, "w 80%!, h 80%!, gaptop 10%, gapleft 10%, span 2 1"); - - final FButton btnOK = new FButton("Save and Exit"); - final FButton btnCancel = new FButton("Exit Without Save"); - - overlay.add(btnOK, "width 30%, newline, gapright 10%, gapleft 15%, gaptop 10px"); - overlay.add(btnCancel, "width 30%!"); - - btnOK.setAction(this.actClose); - btnOK.setText("Save and Exit"); - - btnCancel.setAction(this.actClose); - btnCancel.setText("Exit Without Save"); - - final JLabel test = new JLabel(); - test.setForeground(Color.white); - test.setText("

'Settings' does not do anything yet.
" - + "This button is just here to demonstrate the dock feature.
" - + "'Settings' can be removed or developed further.
"); - - parent.add(test); - } -} diff --git a/src/main/java/forge/view/match/ViewField.java b/src/main/java/forge/view/match/ViewField.java deleted file mode 100644 index 1f235b150ea..00000000000 --- a/src/main/java/forge/view/match/ViewField.java +++ /dev/null @@ -1,632 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.view.match; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -import javax.swing.ImageIcon; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.SwingConstants; -import javax.swing.border.Border; -import javax.swing.border.LineBorder; -import javax.swing.border.MatteBorder; - -import net.miginfocom.swing.MigLayout; -import forge.AllZone; -import forge.Singletons; -import forge.card.cardfactory.CardFactoryUtil; -import forge.card.mana.ManaPool; -import forge.control.match.ControlField; -import forge.game.player.Player; -import forge.game.zone.ZoneType; -import forge.gui.toolbox.FLabel; -import forge.gui.toolbox.FPanel; -import forge.gui.toolbox.FSkin; -import forge.gui.toolbox.FSkin.SkinProp; -import forge.view.arcane.PlayArea; - -/** - * Assembles Swing components of player field instance. - * - */ -@SuppressWarnings("serial") -public class ViewField extends FPanel { - private final ControlField control; - private final PlayArea tabletop; - - private final Border hoverBorder, inactiveBorder; - - private FLabel lblHand, lblGraveyard, lblLibrary, lblExile, - lblFlashback, lblPoison, lblBlack, lblBlue, - lblGreen, lblRed, lblWhite, lblColorless; - - private PhaseLabel lblUpkeep, lblDraw, lblMain1, lblBeginCombat, - lblDeclareAttackers, lblDeclareBlockers, lblFirstStrike, lblCombatDamage, - lblEndCombat, lblMain2, lblEndTurn, lblCleanup; - - private final JPanel avatarArea, phaseArea, pnlDetails; - private final JLabel lblAvatar, lblLife; - private final Color clrHover, clrPhaseActiveEnabled, clrPhaseActiveDisabled, - clrPhaseInactiveEnabled, clrPhaseInactiveDisabled; - /** - * Assembles Swing components of player field instance. - * - * @param player - *   a Player object. - */ - public ViewField(final Player player) { - super(); - this.setLayout(new MigLayout("insets 0, gap 0")); - this.setToolTipText(player.getName() + " Gameboard"); - - this.inactiveBorder = new LineBorder(new Color(0, 0, 0, 0), 1); - this.hoverBorder = new LineBorder(FSkin.getColor(FSkin.Colors.CLR_BORDERS), 1); - - this.clrHover = FSkin.getColor(FSkin.Colors.CLR_HOVER); - this.clrPhaseActiveEnabled = FSkin.getColor(FSkin.Colors.CLR_PHASE_ACTIVE_ENABLED); - this.clrPhaseInactiveEnabled = FSkin.getColor(FSkin.Colors.CLR_PHASE_INACTIVE_ENABLED); - this.clrPhaseActiveDisabled = FSkin.getColor(FSkin.Colors.CLR_PHASE_ACTIVE_DISABLED); - this.clrPhaseInactiveDisabled = FSkin.getColor(FSkin.Colors.CLR_PHASE_INACTIVE_DISABLED); - - // Avatar and life - avatarArea = new JPanel(); - avatarArea.setOpaque(false); - avatarArea.setBackground(FSkin.getColor(FSkin.Colors.CLR_HOVER)); - avatarArea.setLayout(new MigLayout("insets 0, gap 0")); - - lblAvatar = new FLabel.Builder().fontAlign(SwingConstants.CENTER) - .iconScaleFactor(1.0f).build(); - avatarArea.add(lblAvatar, "w 100%!, h 70%!, wrap, gaptop 4%"); - - lblLife = new FLabel.Builder().fontAlign(SwingConstants.CENTER) - .fontStyle(Font.BOLD).build(); - avatarArea.add(lblLife, "w 100%!, h 30%!, gaptop 4%"); - - this.add(avatarArea, "w 10%!, h 30%!"); - - // Phases - phaseArea = new JPanel(); - phaseArea.setOpaque(false); - phaseArea.setLayout(new MigLayout("insets 0 0 1% 0, gap 0, wrap")); - populatePhase(); - this.add(phaseArea, "w 5%!, h 100%!, span 1 2"); - - // Play area - final JScrollPane scroller = new JScrollPane(); - - this.tabletop = new PlayArea(scroller, player.equals(AllZone.getComputerPlayer()) ? true : false); - this.tabletop.setBorder(new MatteBorder(0, 1, 0, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); - this.tabletop.setOpaque(false); - - scroller.setViewportView(this.tabletop); - scroller.setOpaque(false); - scroller.getViewport().setOpaque(false); - scroller.setBorder(null); - - this.add(scroller, "w 85%!, h 100%!, span 1 2, wrap"); - - // Pool info - pnlDetails = new JPanel(); - pnlDetails.setOpaque(false); - pnlDetails.setLayout(new MigLayout("insets 0, gap 0, wrap")); - populateDetails(); - this.add(pnlDetails, "w 10%!, h 69%!, gapleft 1px"); - - // Player hover effect - avatarArea.addMouseListener(new MouseAdapter() { - @Override - public void mouseEntered(final MouseEvent e) { - ViewField.this.avatarArea.setOpaque(true); - ViewField.this.avatarArea.setBorder(ViewField.this.hoverBorder); - } - - @Override - public void mouseExited(final MouseEvent e) { - ViewField.this.avatarArea.setOpaque(false); - ViewField.this.avatarArea.setBorder(ViewField.this.inactiveBorder); - } - }); - - //============ - - // After all components are in place, instantiate controller. - this.control = new ControlField(player, this); - } - - /** - * Gets the controller. - * - * @return ControlField - */ - public ControlField getControl() { - return this.control; - } - - /** Adds phase indicator labels to phase area JPanel container. */ - private void populatePhase() { - // Constraints string, set once - final String constraints = "w 94%!, h 7.2%, gaptop 1%, gapleft 3%"; - - ViewField.this.lblUpkeep = new PhaseLabel("UP"); - ViewField.this.lblUpkeep.setToolTipText("Phase: Upkeep
Click to toggle."); - phaseArea.add(ViewField.this.lblUpkeep, constraints); - - ViewField.this.lblDraw = new PhaseLabel("DR"); - ViewField.this.lblDraw.setToolTipText("Phase: Draw
Click to toggle."); - phaseArea.add(ViewField.this.lblDraw, constraints); - - ViewField.this.lblMain1 = new PhaseLabel("M1"); - ViewField.this.lblMain1.setToolTipText("Phase: Main 1
Click to toggle."); - phaseArea.add(ViewField.this.lblMain1, constraints); - - ViewField.this.lblBeginCombat = new PhaseLabel("BC"); - ViewField.this.lblBeginCombat.setToolTipText("Phase: Begin Combat
Click to toggle."); - phaseArea.add(ViewField.this.lblBeginCombat, constraints); - - ViewField.this.lblDeclareAttackers = new PhaseLabel("DA"); - ViewField.this.lblDeclareAttackers.setToolTipText("Phase: Declare Attackers
Click to toggle."); - phaseArea.add(ViewField.this.lblDeclareAttackers, constraints); - - ViewField.this.lblDeclareBlockers = new PhaseLabel("DB"); - ViewField.this.lblDeclareBlockers.setToolTipText("Phase: Declare Blockers
Click to toggle."); - phaseArea.add(ViewField.this.lblDeclareBlockers, constraints); - - ViewField.this.lblFirstStrike = new PhaseLabel("FS"); - ViewField.this.lblFirstStrike.setToolTipText("Phase: First Strike Damage
Click to toggle."); - phaseArea.add(ViewField.this.lblFirstStrike, constraints); - - ViewField.this.lblCombatDamage = new PhaseLabel("CD"); - ViewField.this.lblCombatDamage.setToolTipText("Phase: Combat Damage
Click to toggle."); - phaseArea.add(ViewField.this.lblCombatDamage, constraints); - - ViewField.this.lblEndCombat = new PhaseLabel("EC"); - ViewField.this.lblEndCombat.setToolTipText("Phase: End Combat
Click to toggle."); - phaseArea.add(ViewField.this.lblEndCombat, constraints); - - ViewField.this.lblMain2 = new PhaseLabel("M2"); - ViewField.this.lblMain2.setToolTipText("Phase: Main 2
Click to toggle."); - phaseArea.add(ViewField.this.lblMain2, constraints); - - ViewField.this.lblEndTurn = new PhaseLabel("ET"); - ViewField.this.lblEndTurn.setToolTipText("Phase: End Turn
Click to toggle."); - phaseArea.add(ViewField.this.lblEndTurn, constraints); - - ViewField.this.lblCleanup = new PhaseLabel("CL"); - ViewField.this.lblCleanup.setToolTipText("Phase: Cleanup
Click to toggle."); - phaseArea.add(ViewField.this.lblCleanup, constraints); - } - - /** Adds various labels to pool area JPanel container. */ - private void populateDetails() { - final JPanel row1 = new JPanel(new MigLayout("insets 0, gap 0")); - final JPanel row2 = new JPanel(new MigLayout("insets 0, gap 0")); - final JPanel row3 = new JPanel(new MigLayout("insets 0, gap 0")); - final JPanel row4 = new JPanel(new MigLayout("insets 0, gap 0")); - final JPanel row5 = new JPanel(new MigLayout("insets 0, gap 0")); - final JPanel row6 = new JPanel(new MigLayout("insets 0, gap 0")); - - row1.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); - row2.setOpaque(false); - row3.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); - row4.setOpaque(false); - row5.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); - row6.setOpaque(false); - - // Hand, library, graveyard, exile, flashback, poison labels - final String constraintsCell = "w 45%!, h 100%!, gap 0 5% 2px 2px"; - - lblHand = getBuiltFLabel(FSkin.ZoneImages.ICO_HAND, "99", "Cards in hand"); - lblLibrary = getBuiltFLabel(FSkin.ZoneImages.ICO_LIBRARY, "99", "Cards in library"); - - row1.add(lblHand, constraintsCell); - row1.add(lblLibrary, constraintsCell); - - lblGraveyard = getBuiltFLabel(FSkin.ZoneImages.ICO_GRAVEYARD, "99", "Cards in graveyard"); - lblExile = getBuiltFLabel(FSkin.ZoneImages.ICO_EXILE, "99", "Exiled cards"); - - row2.add(lblGraveyard, constraintsCell); - row2.add(lblExile, constraintsCell); - - lblFlashback = getBuiltFLabel(FSkin.ZoneImages.ICO_FLASHBACK, "99", "Flashback cards"); - lblPoison = getBuiltFLabel(FSkin.ZoneImages.ICO_POISON, "99", "Poison counters"); - - row3.add(lblFlashback, constraintsCell); - row3.add(lblPoison, constraintsCell); - - // Black, Blue, Colorless, Green, Red, White mana labels - lblBlack = getBuiltFLabel(FSkin.ManaImages.IMG_BLACK, "99", "Black mana"); - lblBlue = getBuiltFLabel(FSkin.ManaImages.IMG_BLUE, "99", "Blue mana"); - - row4.add(lblBlack, constraintsCell); - row4.add(lblBlue, constraintsCell); - - lblGreen = getBuiltFLabel(FSkin.ManaImages.IMG_GREEN, "99", "Green mana"); - lblRed = getBuiltFLabel(FSkin.ManaImages.IMG_RED, "99", "Red mana"); - - row5.add(lblGreen, constraintsCell); - row5.add(lblRed, constraintsCell); - - lblWhite = getBuiltFLabel(FSkin.ManaImages.IMG_WHITE, "99", "White mana"); - lblColorless = getBuiltFLabel(FSkin.ManaImages.IMG_COLORLESS, "99", "Colorless mana"); - - row6.add(lblWhite, constraintsCell); - row6.add(lblColorless, constraintsCell); - - final String constraintsRow = "w 100%!, h 16%!"; - pnlDetails.add(row1, constraintsRow + ", gap 0 0 4% 0"); - pnlDetails.add(row2, constraintsRow); - pnlDetails.add(row3, constraintsRow); - pnlDetails.add(row4, constraintsRow); - pnlDetails.add(row5, constraintsRow); - pnlDetails.add(row6, constraintsRow); - } - - // ========== Observer update methods - /** - * Handles observer update of player Zones - hand, graveyard, etc. - * - * @param p0 - *   Player obj - */ - public void updateZones(final Player p0) { - this.getLblHand().setText("" + p0.getZone(ZoneType.Hand).size()); - this.getLblGraveyard().setText("" + p0.getZone(ZoneType.Graveyard).size()); - this.getLblLibrary().setText("" + p0.getZone(ZoneType.Library).size()); - this.getLblFlashback().setText("" + CardFactoryUtil.getExternalZoneActivationCards(p0).size()); - this.getLblExile().setText("" + p0.getZone(ZoneType.Exile).size()); - } - - /** - * Handles observer update of non-Zone details - life, poison, etc. Also - * updates "players" panel in tabber for this player. - * - * @param p0 - *   Player obj - */ - public void updateDetails(final Player p0) { - // "Players" panel update - Singletons.getControl().getControlMatch() - .getTabberControl().getView().updatePlayerLabels(p0); - - // Poison/life - this.getLblLife().setText("" + p0.getLife()); - this.getLblPoison().setText("" + p0.getPoisonCounters()); - - if (p0.getLife() <= 5) { - this.getLblLife().setForeground(Color.red); - } - else { - this.getLblLife().setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - } - - if (p0.getPoisonCounters() >= 8) { - this.getLblPoison().setForeground(Color.red); - } - else { - this.getLblPoison().setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - } - - //mana pool - updateManaPool(p0); - } - - /** - * Handles observer update of the mana pool. - * - * @param p0 - *   Player obj - */ - public void updateManaPool(final Player p0) { - ManaPool m = p0.getManaPool(); - getLblBlack().setText("" + m.getAmountOfColor(forge.Constant.Color.BLACK)); - getLblBlue().setText("" + m.getAmountOfColor(forge.Constant.Color.BLUE)); - getLblGreen().setText("" + m.getAmountOfColor(forge.Constant.Color.GREEN)); - getLblRed().setText("" + m.getAmountOfColor(forge.Constant.Color.RED)); - getLblWhite().setText("" + m.getAmountOfColor(forge.Constant.Color.WHITE)); - getLblColorless().setText("" + m.getAmountOfColor(forge.Constant.Color.COLORLESS)); - } - - // ========= Retrieval methods - /** - * Gets the tabletop. - * - * @return PlayArea where cards for this field are in play - */ - public PlayArea getTabletop() { - return this.tabletop; - } - - /** - * Gets the avatar area. - * - * @return JPanel containing avatar pic and life label - */ - public JPanel getAvatarArea() { - return this.avatarArea; - } - - /** @return {@link javax.swing.JLabel} */ - public JLabel getLblAvatar() { - return this.lblAvatar; - } - - /** @return {@link javax.swing.JLabel} */ - public JLabel getLblLife() { - return this.lblLife; - } - - /** @return {@link javax.swing.JLabel} */ - public JLabel getLblHand() { - return this.lblHand; - } - - /** @return {@link javax.swing.JLabel} */ - public JLabel getLblLibrary() { - return this.lblLibrary; - } - - /** @return {@link javax.swing.JLabel} */ - public JLabel getLblGraveyard() { - return this.lblGraveyard; - } - - /** @return {@link javax.swing.JLabel} */ - public JLabel getLblExile() { - return this.lblExile; - } - - /** @return {@link javax.swing.JLabel} */ - public JLabel getLblFlashback() { - return this.lblFlashback; - } - - /** @return {@link javax.swing.JLabel} */ - public JLabel getLblPoison() { - return this.lblPoison; - } - - /** @return {@link javax.swing.JLabel} */ - public JLabel getLblColorless() { - return this.lblColorless; - } - - /** @return {@link javax.swing.JLabel} */ - public JLabel getLblBlack() { - return this.lblBlack; - } - - /** @return {@link javax.swing.JLabel} */ - public JLabel getLblBlue() { - return this.lblBlue; - } - - /** @return {@link javax.swing.JLabel} */ - public JLabel getLblGreen() { - return this.lblGreen; - } - - /** @return {@link javax.swing.JLabel} */ - public JLabel getLblRed() { - return this.lblRed; - } - - /** @return {@link javax.swing.JLabel} */ - public JLabel getLblWhite() { - return this.lblWhite; - } - - // Phases - /** @return {@link javax.swing.JLabel} */ - public PhaseLabel getLblUpkeep() { - return this.lblUpkeep; - } - - /** @return {@link javax.swing.JLabel} */ - public PhaseLabel getLblDraw() { - return this.lblDraw; - } - - /** @return {@link javax.swing.JLabel} */ - public PhaseLabel getLblMain1() { - return this.lblMain1; - } - - /** @return {@link javax.swing.JLabel} */ - public PhaseLabel getLblBeginCombat() { - return this.lblBeginCombat; - } - - /** @return {@link javax.swing.JLabel} */ - public PhaseLabel getLblDeclareAttackers() { - return this.lblDeclareAttackers; - } - - /** @return {@link javax.swing.JLabel} */ - public PhaseLabel getLblDeclareBlockers() { - return this.lblDeclareBlockers; - } - - /** @return {@link javax.swing.JLabel} */ - public PhaseLabel getLblCombatDamage() { - return this.lblCombatDamage; - } - - /** @return {@link javax.swing.JLabel} */ - public PhaseLabel getLblFirstStrike() { - return this.lblFirstStrike; - } - - /** @return {@link javax.swing.JLabel} */ - public PhaseLabel getLblEndCombat() { - return this.lblEndCombat; - } - - /** @return {@link javax.swing.JLabel} */ - public PhaseLabel getLblMain2() { - return this.lblMain2; - } - - /** @return {@link javax.swing.JLabel} */ - public PhaseLabel getLblEndTurn() { - return this.lblEndTurn; - } - - /** @return {@link javax.swing.JLabel} */ - public PhaseLabel getLblCleanup() { - return this.lblCleanup; - } - - // ========== Custom class handling - - private FLabel getBuiltFLabel(SkinProp p0, String s0, String s1) { - return new FLabel.Builder().icon(new ImageIcon(FSkin.getImage(p0))) - .opaque(false).fontScaleFactor(0.5).iconAlpha(0.6f).iconInBackground(true) - .text(s0).tooltip(s1).fontAlign(SwingConstants.RIGHT).build(); - } - - /** - * Shows phase labels, handles repainting and on/off states. A PhaseLabel - * has "skip" and "active" states, meaning "this phase is (not) skipped" and - * "this is the current phase". - */ - public class PhaseLabel extends JLabel { - private boolean enabled = true; - private boolean active = false; - private boolean hover = false; - - - /** - * Shows phase labels, handles repainting and on/off states. A - * PhaseLabel has "skip" and "active" states, meaning - * "this phase is (not) skipped" and "this is the current phase". - * - * @param txt - *   Label text - */ - public PhaseLabel(final String txt) { - super(txt); - this.setHorizontalTextPosition(SwingConstants.CENTER); - this.setHorizontalAlignment(SwingConstants.CENTER); - - this.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - if (PhaseLabel.this.enabled) { - PhaseLabel.this.enabled = false; - } else { - PhaseLabel.this.enabled = true; - } - } - - @Override - public void mouseEntered(final MouseEvent e) { - PhaseLabel.this.hover = true; - PhaseLabel.this.repaintOnlyThisLabel(); - } - - @Override - public void mouseExited(final MouseEvent e) { - PhaseLabel.this.hover = false; - PhaseLabel.this.repaintOnlyThisLabel(); - } - }); - } - - /** - * Determines whether play pauses at this phase or not. - * - * @param b - *   boolean, true if play pauses - */ - @Override - public void setEnabled(final boolean b) { - this.enabled = b; - } - - /** - * Determines whether play pauses at this phase or not. - * - * @return boolean - */ - public boolean getEnabled() { - return this.enabled; - } - - /** - * Determines if this phase is the current phase (or not). - * - * @param b - *   boolean, true if phase is current - */ - public void setActive(final boolean b) { - this.active = b; - } - - /** - * Determines if this phase is the current phase (or not). - * - * @return boolean - */ - public boolean getActive() { - return this.active; - } - - /** Prevent label from repainting the whole screen. */ - public void repaintOnlyThisLabel() { - final Dimension d = PhaseLabel.this.getSize(); - repaint(0, 0, d.width, d.height); - } - - /* - * (non-Javadoc) - * - * @see javax.swing.JComponent#paintComponent(java.awt.Graphics) - */ - @Override - public void paintComponent(final Graphics g) { - final int w = this.getWidth(); - final int h = this.getHeight(); - Color c; - - // Set color according to skip or active or hover state of label - if (this.hover) { - c = clrHover; - } else if (this.active && this.enabled) { - c = clrPhaseActiveEnabled; - } else if (!this.active && this.enabled) { - c = clrPhaseInactiveEnabled; - } else if (this.active && !this.enabled) { - c = clrPhaseActiveDisabled; - } else { - c = clrPhaseInactiveDisabled; - } - - // Center vertically and horizontally. Show border if active. - g.setColor(c); - g.fillRoundRect(1, 1, w - 2, h - 2, 5, 5); - super.paintComponent(g); - } - } -} diff --git a/src/main/java/forge/view/match/ViewHand.java b/src/main/java/forge/view/match/ViewHand.java deleted file mode 100644 index 57f1e9df14e..00000000000 --- a/src/main/java/forge/view/match/ViewHand.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.view.match; - -import javax.swing.JScrollPane; - -import net.miginfocom.swing.MigLayout; -import forge.control.match.ControlHand; -import forge.gui.toolbox.FPanel; -import forge.view.ViewMatchUI; -import forge.view.arcane.HandArea; - -/** - * VIEW - Swing components for user hand. - * - */ -@SuppressWarnings("serial") -public class ViewHand extends FPanel { - private ControlHand control; - private HandArea hand; - private ViewMatchUI topLevel; - - /** - * Swing components for user hand. - * - * @param v0   The ViewMatchUI parent. - */ - public ViewHand(ViewMatchUI v0) { - final JScrollPane scroller = new JScrollPane(); - ViewHand.this.hand = new HandArea(scroller); - topLevel = v0; - - scroller.setViewportView(ViewHand.this.hand); - scroller.setOpaque(false); - scroller.getViewport().setOpaque(false); - scroller.setBorder(null); - ViewHand.this.hand.setOpaque(false); - - setLayout(new MigLayout("insets 0, gap 0")); - add(scroller, "w 100%, h 100%!"); - - // After all components are in place, instantiate controller. - ViewHand.this.control = new ControlHand(this); - } - - /** - * Gets the controller. - * - * @return ControlHand - */ - public ControlHand getControl() { - return ViewHand.this.control; - } - - /** - * Gets the hand area. - * - * @return HandArea - */ - public HandArea getHandArea() { - return ViewHand.this.hand; - } - - /** @return ViewMatchUI */ - public ViewMatchUI getTopLevel() { - return this.topLevel; - } -} diff --git a/src/main/java/forge/view/match/ViewMessage.java b/src/main/java/forge/view/match/ViewMessage.java deleted file mode 100644 index 5aecabcc393..00000000000 --- a/src/main/java/forge/view/match/ViewMessage.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.view.match; - -import java.awt.Color; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.util.Timer; -import java.util.TimerTask; - -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JTextArea; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; -import javax.swing.border.MatteBorder; - -import net.miginfocom.swing.MigLayout; -import forge.control.match.ControlMessage; -import forge.gui.toolbox.FButton; -import forge.gui.toolbox.FPanel; -import forge.gui.toolbox.FSkin; - -/** - * Assembles Swing components of input area. - * - */ -@SuppressWarnings("serial") -public class ViewMessage extends FPanel { - private final ControlMessage control; - private final JButton btnOK, btnCancel; - private final JTextArea tarMessage; - private final JLabel lblGames; - private Timer timer1 = null; - private static int counter = 0; - private int[] newA = null, newR = null, newG = null, newB = null; - private boolean remindIsRunning = false; - - /** - * Assembles UI for input area (buttons and message panel). - * - */ - public ViewMessage() { - super(); - this.setToolTipText("Input Area"); - this.setLayout(new MigLayout("wrap 2, fill, insets 0, gap 0")); - - // Cancel button - this.btnCancel = new FButton("Cancel"); - this.btnOK = new FButton("OK"); - - // Game counter - lblGames = new JLabel(); - lblGames.setFont(FSkin.getBoldFont(12)); - lblGames.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - lblGames.setHorizontalAlignment(SwingConstants.CENTER); - lblGames.setBorder(new MatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); - - this.tarMessage = new JTextArea(); - this.tarMessage.setOpaque(false); - this.tarMessage.setFocusable(false); - this.tarMessage.setEditable(false); - this.tarMessage.setLineWrap(true); - this.tarMessage.setWrapStyleWord(true); - this.tarMessage.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - this.tarMessage.setFont(FSkin.getFont(16)); - this.add(this.lblGames, "span 2 1, w 96%!, gapleft 2%, h 10%, wrap"); - this.add(this.tarMessage, "span 2 1, h 70%!, w 96%!, gapleft 2%, gaptop 1%"); - this.add(this.btnOK, "w 47%!, gapright 2%, gapleft 1%"); - this.add(this.btnCancel, "w 47%!, gapright 1%"); - - // Resize adapter - this.addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - int px = (int) (ViewMessage.this.getWidth() / 17); - px = (px < 11 ? 11 : px); - tarMessage.setFont(FSkin.getFont(px)); - } - }); - // After all components are in place, instantiate controller. - this.control = new ControlMessage(this); - } - - /** - * Gets the controller. - * - * @return ControlMessage - */ - public ControlMessage getControl() { - return this.control; - } - - /** - * Gets the btn ok. - * - * @return JButton - */ - public JButton getBtnOK() { - return this.btnOK; - } - - /** - * Gets the btn cancel. - * - * @return JButton - */ - public JButton getBtnCancel() { - return this.btnCancel; - } - - /** @return JTextArea */ - public JTextArea getTarMessage() { - return this.tarMessage; - } - - /** @return JLabel */ - public JLabel getLblGames() { - return this.lblGames; - } - - /** Flashes animation on input panel if play is currently waiting on input. */ - public void remind() { - // To adjust, only touch these two values. - final int steps = 5; // Number of delays - final int delay = 80; // Milliseconds between steps - - if (remindIsRunning) { return; } - - remindIsRunning = true; - final int oldR = getBackground().getRed(); - final int oldG = getBackground().getGreen(); - final int oldB = getBackground().getBlue(); - final int oldA = getBackground().getAlpha(); - counter = 0; - newR = new int[steps]; - newG = new int[steps]; - newB = new int[steps]; - newA = new int[steps]; - - for (int i = 0; i < steps; i++) { - newR[i] = (int) ((255 - oldR) / steps * i); - newG[i] = (int) (oldG / steps * i); - newB[i] = (int) (oldB / steps * i); - newA[i] = (int) ((255 - oldA) / steps * i); - } - - final TimerTask tt = new TimerTask() { - @Override - public void run() { - counter++; - if (counter != (steps - 1)) { - SwingUtilities.invokeLater(new Runnable() { @Override - public void run() { setBackground(new Color(newR[counter], oldG, oldB, newA[counter])); } }); - } - else { - SwingUtilities.invokeLater(new Runnable() { @Override - public void run() { setBackground(new Color(oldR, oldG, oldB, oldA)); } }); - remindIsRunning = false; - timer1.cancel(); - newR = null; - newG = null; - newB = null; - newA = null; - } - } - }; - - timer1 = new Timer(); - timer1.scheduleAtFixedRate(tt, 0, delay); - } -} diff --git a/src/main/java/forge/view/match/ViewPicture.java b/src/main/java/forge/view/match/ViewPicture.java deleted file mode 100644 index db9ccc645a2..00000000000 --- a/src/main/java/forge/view/match/ViewPicture.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.view.match; - -import net.miginfocom.swing.MigLayout; -import forge.control.match.ControlPicture; -import forge.gui.CardPicturePanel; -import forge.gui.toolbox.FPanel; - -/** - * TODO: Write javadoc for this type. - * - */ -@SuppressWarnings("serial") -public class ViewPicture extends FPanel { - private ControlPicture control; - - private CardPicturePanel pnlPicture; - - /** - * Instantiates a new view picture. - */ - public ViewPicture() { - super(); - pnlPicture = new CardPicturePanel(null); - pnlPicture.setOpaque(false); - - this.setLayout(new MigLayout("insets 0, gap 0, center")); - - add(pnlPicture, "w 100%!, h 100%!"); - control = new ControlPicture(this); - } - - /** - * Gets the controller. - * - * @return ControlPicture - */ - public ControlPicture getControl() { - return control; - } - - /** - * Gets the pnl picture. - * - * @return CardPicturePanel - */ - public CardPicturePanel getPnlPicture() { - return pnlPicture; - } -} diff --git a/src/main/java/forge/view/match/ViewTabber.java b/src/main/java/forge/view/match/ViewTabber.java deleted file mode 100644 index 47762b7e521..00000000000 --- a/src/main/java/forge/view/match/ViewTabber.java +++ /dev/null @@ -1,895 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.view.match; - -import java.awt.Color; -import java.awt.Graphics; -import java.awt.event.ActionEvent; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import javax.swing.BorderFactory; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JPopupMenu; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.ScrollPaneConstants; -import javax.swing.border.Border; -import javax.swing.border.EmptyBorder; -import javax.swing.border.MatteBorder; - -import net.miginfocom.swing.MigLayout; -import forge.AllZone; -import forge.CardList; -import forge.CardUtil; -import forge.GameLog; -import forge.Singletons; -import forge.card.spellability.SpellAbilityStackInstance; -import forge.control.match.ControlTabber; -import forge.game.player.Player; -import forge.game.zone.MagicStack; -import forge.game.zone.ZoneType; -import forge.gui.ForgeAction; -import forge.gui.MultiLineLabelUI; -import forge.gui.toolbox.FSkin; -import forge.gui.toolbox.FVerticalTabPanel; -import forge.properties.ForgePreferences.FPref; -import forge.properties.NewConstants; - -/** - * Vertical tab panel for viewing stack, combat, etc. Unfortunately, cannot - * extend a Swing component, since vertical tabs are generated dynamically in - * the constructor. - * - */ -@SuppressWarnings("serial") -public class ViewTabber extends JPanel { - private final List panelList; - private Map infoLBLs; - private JLabel stormLabel; - private List stackTARs; - private List combatTARs; - private List consoleTARs; - private List devLBLs; - - private final ControlTabber control; - private TriggerReactionMenu triggerMenu; - private final JPanel pnlStack, pnlCombat, pnlConsole, pnlPlayers, pnlDev; - - private DevLabel lblMilling, lblGenerateMana, lblSetupGame, lblTutor, lblAddCard, - lblCounterPermanent, lblTapPermanent, lblUntapPermanent, lblUnlimitedLands, lblSetLife; - - private final FVerticalTabPanel vtpTabber; - - private final Color activeColor, inactiveColor, hoverColor; - - /** - * Assembles Swing components for tabber area in sidebar. - */ - public ViewTabber() { - this.hoverColor = FSkin.getColor(FSkin.Colors.CLR_HOVER); - this.activeColor = FSkin.getColor(FSkin.Colors.CLR_ACTIVE); - this.inactiveColor = FSkin.getColor(FSkin.Colors.CLR_INACTIVE); - this.setOpaque(false); - - // Assemble card pic viewer - this.panelList = new ArrayList(); - final String constraints = "wrap, insets 0 3% 0 0, gap 0"; - stackTARs = new ArrayList(); - combatTARs = new ArrayList(); - consoleTARs = new ArrayList(); - devLBLs = new ArrayList(); - - // Trigger Context Menu creation - this.triggerMenu = new TriggerReactionMenu(); - - this.pnlStack = new JPanel(); - this.pnlStack.setName("Stack"); - this.pnlStack.setOpaque(false); - this.pnlStack.setLayout(new MigLayout(constraints)); - this.pnlStack.setToolTipText("View Stack"); - this.panelList.add(this.pnlStack); - - this.pnlCombat = new JPanel(); - this.pnlCombat.setName("Combat"); - this.pnlCombat.setOpaque(false); - this.pnlCombat.setLayout(new MigLayout(constraints)); - this.pnlCombat.setToolTipText("View Combat"); - this.panelList.add(this.pnlCombat); - - this.pnlConsole = new JPanel(); - this.pnlConsole.setName("Log"); - this.pnlConsole.setOpaque(false); - this.pnlConsole.setLayout(new MigLayout(constraints)); - this.pnlConsole.setToolTipText("View Console"); - this.panelList.add(this.pnlConsole); - - this.pnlPlayers = new JPanel(); - this.pnlPlayers.setName("Players"); - this.pnlPlayers.setOpaque(false); - this.pnlPlayers.setLayout(new MigLayout(constraints)); - this.pnlPlayers.setToolTipText("Player List"); - this.panelList.add(this.pnlPlayers); - - this.pnlDev = new JPanel(); - this.pnlDev.setName("Dev"); - this.pnlDev.setOpaque(false); - this.pnlDev.setLayout(new MigLayout(constraints)); - this.pnlDev.setToolTipText("Developer Mode"); - this.panelList.add(this.pnlDev); - - // Populate the various panels in the tabber. - this.populatePnlDev(); - this.populatePnlPlayers(); - this.populatePnlConsole(); - - this.vtpTabber = new FVerticalTabPanel(this.panelList); - this.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); - this.setLayout(new MigLayout("insets 0, gap 0")); - - this.add(vtpTabber, "w 97%!, h 100%!, gapleft 2%"); - - // Resize adapter - this.addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - int big = getWidth() / 15, regular, x; - big = (big < 13 ? 13 : big); - regular = big - 2; - - // Player panel info - Iterator> it = infoLBLs.entrySet().iterator(); - while (it.hasNext()) { - JLabel[] labels = (JLabel[]) it.next().getValue(); - for (x = 0; x < labels.length; x++) { - if (x > 0) { - labels[x].setFont(FSkin.getFont(regular)); - } else { - labels[x].setFont(FSkin.getFont(big)); - } - } - } - - // Storm label - stormLabel.setFont(FSkin.getFont(big)); - - // Stack text areas - for (JTextArea tar : stackTARs) { - tar.setFont(FSkin.getFont(big)); - } - - // Combat text areas - for (JTextArea tar : combatTARs) { - tar.setFont(FSkin.getFont(big)); - } - - // Console text areas - for (JTextArea tar : consoleTARs) { - tar.setFont(FSkin.getFont(big)); - } - - // Devmode Labels - for (JLabel lbl : devLBLs) { - lbl.setFont(FSkin.getFont(regular)); - } - } - }); - - // After all components are in place, instantiate controller. - this.control = new ControlTabber(this); - } - - /** - * Gets the controller. - * - * @return ControlTabber - */ - public ControlTabber getControl() { - return this.control; - } - - /** - * Removes and adds JTextAreas to stack panel, which briefly summarize the - * spell and allow mouseover. - * - */ - public void updateStack() { - final MagicStack stack = AllZone.getStack(); - - int count = 1; - JTextArea tar; - String txt, isOptional; - - this.pnlStack.removeAll(); - this.control.showPnlStack(); - - this.vtpTabber.getAllVTabs().get(ControlTabber.STACK_PANEL).setText("Stack : " + stack.size()); - - // final Border border = new LineBorder(FSkin.getClrBorders(), 1); - final Border border = new EmptyBorder(5, 5, 5, 5); - Color[] scheme; - - stackTARs.clear(); - for (int i = stack.size() - 1; 0 <= i; i--) { - final SpellAbilityStackInstance spell = stack.peekInstance(i); - final int index = i; - - scheme = getSpellColor(spell); - - isOptional = stack.peekAbility(i).isOptionalTrigger() - && stack.peekAbility(i).getSourceCard().getController().isHuman() ? "(OPTIONAL) " : ""; - txt = (count++) + ". " + isOptional + spell.getStackDescription(); - tar = new JTextArea(txt); - tar.setToolTipText(txt); - tar.setOpaque(true); - tar.setBorder(border); - tar.setForeground(scheme[1]); - tar.setBackground(scheme[0]); - - tar.setFocusable(false); - tar.setEditable(false); - tar.setLineWrap(true); - tar.setWrapStyleWord(true); - - /* - * TODO - we should figure out how to display cards on the stack in - * the Picture/Detail panel The problem not is that when a computer - * casts a Morph, the real card shows because Picture/Detail checks - * isFaceDown() which will be false on for spell.getSourceCard() on - * the stack. - */ - - // this functionality was present in v 1.1.8 - tar.addMouseListener(new MouseAdapter() { - @Override - public void mouseEntered(final MouseEvent e) { - Singletons.getControl().getControlMatch().setCard(spell.getSpellAbility().getSourceCard()); - } - }); - - /* - * This updates the Card Picture/Detail when the spell is added to - * the stack. This funcaitonality was not present in v 1.1.8. - * - * Problem is described in TODO right above this. - */ - /* - * if (i == 0) { - * AllZone.getDisplay().setCard(spell.getSourceCard()); } - */ - - this.pnlStack.add(tar, "w 98%!, gapright 1%, gaptop 1%"); - stackTARs.add(tar); - - if (stack.peekInstance(i).isOptionalTrigger()) { - tar.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - - if (e.getButton() != MouseEvent.BUTTON3) { - return; - } - - ViewTabber.this.triggerMenu.setTrigger(stack.peekAbility(index).getSourceTrigger()); - ViewTabber.this.triggerMenu.show(e.getComponent(), e.getX(), e.getY()); - } - }); - } - } - - Singletons.getView().getViewMatch().getBtnOK().requestFocusInWindow(); - } - - /** Returns array with [background, foreground] colors. */ - private Color[] getSpellColor(SpellAbilityStackInstance s0) { - if (CardUtil.getColors(s0.getSourceCard()).size() > 1) { - return new Color[] { new Color(253, 175, 63), Color.black }; - } else if (s0.getSourceCard().isBlack()) { - return new Color[] { Color.black, Color.white }; - } else if (s0.getSourceCard().isBlue()) { - return new Color[] { new Color(71, 108, 191), Color.white }; - } else if (s0.getSourceCard().isGreen()) { - return new Color[] { new Color(23, 95, 30), Color.white }; - } else if (s0.getSourceCard().isRed()) { - return new Color[] { new Color(214, 8, 8), Color.white }; - } else if (s0.getSourceCard().isWhite()) { - return new Color[] { Color.white, Color.black }; - } else if (s0.getSourceCard().isArtifact() || s0.getSourceCard().isLand()) { - return new Color[] { new Color(111, 75, 43), Color.white }; - } - - return new Color[] { new Color(0, 0, 0, 0), FSkin.getColor(FSkin.Colors.CLR_TEXT) }; - } - - /** - * Removes and adds JTextAreas to combat panel, which briefly summarize the - * current combat situation. - * - * @param s - *   String message - */ - - // Note: Can (should?) be easily retrofitted to fit stack-style reporting: - // multiple text areas, with mouseovers highlighting combat cards. - // Doublestrike 06-11-11 - public void updateCombat(final String s) { - this.pnlCombat.removeAll(); - - // if this is not cleared every time, we keep a history of combat - // strings. Not very useful. - // probably will never be useful, even if we have multiple text areas to - // display combat... - this.combatTARs.clear(); - this.control.showPnlCombat(); - - final Border border = new MatteBorder(0, 0, 0, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS)); - - this.vtpTabber.getAllVTabs().get(ControlTabber.COMBAT_PANEL) - .setText("Combat : " + AllZone.getCombat().getAttackers().size()); - - final JTextArea tar = new JTextArea(s); - tar.setOpaque(false); - tar.setBorder(border); - tar.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - tar.setFocusable(false); - tar.setLineWrap(true); - this.pnlCombat.add(tar, "w 95%!, gapleft 3%, gaptop 1%, h 95%"); - combatTARs.add(tar); - } - - /** - * Sets the text for the GameLog. - * - */ - public void updateConsole() { - final GameLog gl = AllZone.getGameLog(); - - this.pnlConsole.removeAll(); - // final Border border = new MatteBorder(0, 0, 0, 0, - // FSkin.getClrBorders()); - - // by default, grab everything logging level 3 or less - // TODO - some option to make this configurable is probably desirable - // TODO - add these components to resize adapter in constructor - JTextArea tar = new JTextArea(gl.getLogText(3)); - tar.setOpaque(false); - // tar.setBorder(border); - tar.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - - tar.setFocusable(false); - tar.setEditable(false); - tar.setLineWrap(true); - tar.setWrapStyleWord(true); - - JScrollPane jsp = new JScrollPane(tar); - jsp.setOpaque(false); - jsp.getViewport().setOpaque(false); - - this.pnlConsole.add(jsp, "w 95%!, gapleft 3%, gaptop 1%"); - } - - /** - * Updates labels in the "player" panel, which display non-critical details - * about each player in the game. - * - * @param p0 - *   Player obj - */ - public void updatePlayerLabels(final Player p0) { - final JLabel[] temp = this.infoLBLs.get(p0); - temp[1].setText("Life: " + String.valueOf(p0.getLife()) + " | Poison counters: " - + String.valueOf(p0.getPoisonCounters())); - temp[2].setText("Maximum hand size: " + String.valueOf(p0.getMaxHandSize())); - temp[3].setText("Cards drawn this turn: " + String.valueOf(p0.getNumDrawnThisTurn())); - temp[4].setText("Damage Prevention: " + String.valueOf(p0.getPreventNextDamage())); - if (!p0.getKeywords().isEmpty()) { - temp[5].setText(p0.getKeywords().toString()); - } else { - temp[5].setText(""); - } - if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_ANTE)) { - CardList list = p0.getCardsIn(ZoneType.Ante); - StringBuilder sb = new StringBuilder(); - sb.append("Ante'd: "); - for (int i = 0; i < list.size(); i++) { - sb.append(list.get(i)); - if (i < (list.size() - 1)) { - sb.append(", "); - } - } - temp[6].setText(sb.toString()); - } - - stormLabel.setText("Storm count: " + AllZone.getStack().getCardsCastThisTurn().size()); - } - - /** - * Gets the vtp tabber. - * - * @return FVerticalTabPanel - */ - public FVerticalTabPanel getVtpTabber() { - return this.vtpTabber; - } - - /** - * Gets the pnl stack. - * - * @return {@link javax.swing.JPanel} - */ - public JPanel getPnlStack() { - return this.pnlStack; - } - - /** - * Gets the pnl combat. - * - * @return {@link javax.swing.JPanel} - */ - public JPanel getPnlCombat() { - return this.pnlCombat; - } - - /** - * Gets the pnl console. - * - * @return {@link javax.swing.JPanel} - */ - public JPanel getPnlConsole() { - return this.pnlConsole; - } - - /** - * Gets the pnl players. - * - * @return {@link javax.swing.JPanel} - */ - public JPanel getPnlPlayers() { - return this.pnlPlayers; - } - - /** - * Gets the pnl dev. - * - * @return {@link javax.swing.JPanel} - */ - public JPanel getPnlDev() { - return this.pnlDev; - } - - /** - * Gets the lbl milling. - * - * @return DevLabel - */ - public DevLabel getLblMilling() { - return this.lblMilling; - } - - /** - * Gets the lbl generate mana. - * - * @return DevLabel - */ - public DevLabel getLblGenerateMana() { - return this.lblGenerateMana; - } - - /** - * Gets the lbl setup game. - * - * @return DevLabel - */ - public DevLabel getLblSetupGame() { - return this.lblSetupGame; - } - - /** - * Gets the lbl tutor. - * - * @return DevLabel - */ - public DevLabel getLblTutor() { - return this.lblTutor; - } - - public DevLabel getAnyCard() { - return this.lblAddCard; - } - - /** - * Gets the lbl counter permanent. - * - * @return DevLabel - */ - public DevLabel getLblCounterPermanent() { - return this.lblCounterPermanent; - } - - /** - * Gets the lbl tap permanent. - * - * @return DevLabel - */ - public DevLabel getLblTapPermanent() { - return this.lblTapPermanent; - } - - /** - * Gets the lbl untap permanent. - * - * @return DevLabel - */ - public DevLabel getLblUntapPermanent() { - return this.lblUntapPermanent; - } - - /** - * Gets the lbl unlimited lands. - * - * @return DevLabel - */ - public DevLabel getLblUnlimitedLands() { - return this.lblUnlimitedLands; - } - - /** - * Gets the lbl human life. - * - * @return DevLabel - */ - public DevLabel getLblSetLife() { - return this.lblSetLife; - } - - /** Assembles Swing components for "players" panel. */ - private void populatePnlPlayers() { - final List players = AllZone.getPlayersInGame(); - this.infoLBLs = new HashMap(); - - final String constraints = "w 97%!, gapleft 2%, gapbottom 1%"; - - for (final Player p : players) { - // Create and store labels detailing various non-critical player - // info. - final InfoLabel name = new InfoLabel(); - final InfoLabel life = new InfoLabel(); - final InfoLabel hand = new InfoLabel(); - final InfoLabel draw = new InfoLabel(); - final InfoLabel prevention = new InfoLabel(); - final InfoLabel keywords = new InfoLabel(); - final InfoLabel antes = new InfoLabel(); - this.infoLBLs.put(p, new JLabel[] { name, life, hand, draw, prevention, keywords, antes }); - - // Set border on bottom label, and larger font on player name - antes.setBorder(new MatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); - name.setText(p.getName()); - - // Add to "players" tab panel - this.pnlPlayers.add(name, constraints); - this.pnlPlayers.add(life, constraints); - this.pnlPlayers.add(hand, constraints); - this.pnlPlayers.add(draw, constraints); - this.pnlPlayers.add(prevention, constraints); - this.pnlPlayers.add(keywords, constraints); - this.pnlPlayers.add(antes, constraints); - } - - stormLabel = new InfoLabel(); - this.pnlPlayers.add(stormLabel, constraints); - } - - /** Assembles Swing components for "dev mode" panel. */ - private void populatePnlDev() { - final JPanel viewport = new JPanel(); - viewport.setLayout(new MigLayout("wrap, insets 0")); - viewport.setOpaque(false); - - final JScrollPane jsp = new JScrollPane(viewport, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, - ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - jsp.setBorder(BorderFactory.createEmptyBorder()); - jsp.setOpaque(false); - jsp.getViewport().setOpaque(false); - - this.pnlDev.add(jsp, "w 98%!, h 98%!"); - - lblMilling = new DevLabel("Loss by Milling: Enabled", "Loss by Milling: Disabled"); - lblUnlimitedLands = new DevLabel("Play Unlimited Lands This Turn: Enabled", - "Play Unlimited Lands This Turn: Disabled"); - lblGenerateMana = new DevLabel("Generate Mana"); - lblSetupGame = new DevLabel("Setup Game State"); - lblTutor = new DevLabel("Tutor for Card"); - lblCounterPermanent = new DevLabel("Add Counter to Permanent"); - lblTapPermanent = new DevLabel("Tap Permanent"); - lblUntapPermanent = new DevLabel("Untap Permanent"); - lblSetLife = new DevLabel("Set Player Life"); - lblAddCard = new DevLabel("Add any card"); - - devLBLs.add(lblMilling); - // devLBLs.add(lblHandView); - // devLBLs.add(lblLibraryView); - devLBLs.add(lblUnlimitedLands); - devLBLs.add(lblGenerateMana); - devLBLs.add(lblSetupGame); - devLBLs.add(lblTutor); - devLBLs.add(lblAddCard); - devLBLs.add(lblCounterPermanent); - devLBLs.add(lblTapPermanent); - devLBLs.add(lblUntapPermanent); - devLBLs.add(lblSetLife); - - final String constraints = "w 95%!, gap 0 0 5px 0"; - viewport.add(this.lblMilling, constraints); - // viewport.add(this.lblHandView, constraints); - // viewport.add(this.lblLibraryView, constraints); - viewport.add(this.lblUnlimitedLands, constraints); - viewport.add(this.lblGenerateMana, constraints); - viewport.add(this.lblSetupGame, constraints); - viewport.add(this.lblTutor, constraints); - viewport.add(this.lblAddCard, constraints); - viewport.add(this.lblCounterPermanent, constraints); - viewport.add(this.lblTapPermanent, constraints); - viewport.add(this.lblUntapPermanent, constraints); - viewport.add(this.lblSetLife, constraints); - } - - /** Assembles swing components for "console" panel. */ - private void populatePnlConsole() { - final JLabel prompt = new JLabel("IN > "); - final JTextField input = new JTextField(); - - final JTextArea log = new JTextArea(); - log.setBackground(new Color(0, 0, 0, 20)); - log.setWrapStyleWord(true); - log.setLineWrap(true); - log.setWrapStyleWord(true); - log.setEditable(false); - log.setFocusable(false); - log.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - log.setBorder(new MatteBorder(1, 0, 0, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); - - log.setText("No log information yet. Input codes entered above. " + "Output data recorded below."); - - this.pnlConsole.setLayout(new MigLayout("insets 0, gap 0, wrap 2")); - - this.pnlConsole.add(prompt, "w 28%!, h 10%!, gapleft 2%, gaptop 2%, gapbottom 2%"); - this.pnlConsole.add(input, "w 68%!, gapright 2%, gaptop 2%, gapbottom 2%"); - this.pnlConsole.add(log, "w 94%!, h 80%!, gapleft 4%, span 2 1"); - } - - /** - * Labels that act as buttons which control dev mode functions. Labels are - * used to support multiline text. - * - */ - public class DevLabel extends JLabel { - private static final long serialVersionUID = 7917311680519060700L; - - private Color defaultBG = ViewTabber.this.activeColor; - private final Color hoverBG = ViewTabber.this.hoverColor; - private final Color pressedBG = ViewTabber.this.inactiveColor; - private boolean enabled; - private final String enabledText, disabledText; - private int w, h; // Width, height, radius, insets (for paintComponent) - - private final int r; - - private final int i; - - /** - * Labels that act as buttons which control dev mode functions. Labels - * are used (instead of buttons) to support multiline text. - * - * Constructor for DevLabel which doesn't use enabled/disabled states; - * only single text string required. - * - * @param s0 - *   String text/tooltip of label - */ - public DevLabel(final String s0) { - this(s0, s0); - } - - /** - * Labels that act as buttons which control dev mode functions. Labels - * are used (instead of buttons) to support multiline text. - * - * This constructor for DevLabels empowers an "enable" state that - * displays them as green (enabled) or red (disabled). - * - * @param en0 - *   String text/tooltip of label, in "enabled" state - * @param dis0 - *   String text/tooltip of label, in "disabled" state - */ - public DevLabel(final String en0, final String dis0) { - super(); - this.setUI(MultiLineLabelUI.getLabelUI()); - this.setBorder(new EmptyBorder(5, 5, 5, 5)); - this.enabledText = en0; - this.disabledText = dis0; - this.r = 6; // Radius (for paintComponent) - this.i = 2; // Insets (for paintComponent) - this.setEnabled(true); - this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - - this.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - DevLabel.this.setBackground(DevLabel.this.pressedBG); - } - - @Override - public void mouseReleased(final MouseEvent e) { - DevLabel.this.setBackground(DevLabel.this.defaultBG); - } - - @Override - public void mouseEntered(final MouseEvent e) { - DevLabel.this.setBackground(DevLabel.this.hoverBG); - } - - @Override - public void mouseExited(final MouseEvent e) { - DevLabel.this.setBackground(DevLabel.this.defaultBG); - } - }); - } - - /** - * Changes enabled state per boolean parameter, automatically updating - * text string and background color. - * - * @param b - *   boolean - */ - @Override - public void setEnabled(final boolean b) { - String s; - if (b) { - this.defaultBG = ViewTabber.this.activeColor; - s = this.enabledText; - } else { - this.defaultBG = ViewTabber.this.inactiveColor; - s = this.disabledText; - } - this.enabled = b; - this.setText(s); - this.setToolTipText(s); - this.setBackground(this.defaultBG); - } - - /** - * Gets the enabled. - * - * @return boolean - */ - public boolean getEnabled() { - return this.enabled; - } - - /** - * In many cases, a DevLabel state will just be toggling a boolean. This - * method sets up and evaluates the condition and toggles as - * appropriate. - * - */ - public void toggleEnabled() { - if (this.enabled) { - this.setEnabled(false); - } else { - this.setEnabled(true); - } - } - - /* - * (non-Javadoc) - * - * @see javax.swing.JComponent#paintComponent(java.awt.Graphics) - */ - @Override - protected void paintComponent(final Graphics g) { - this.w = this.getWidth(); - this.h = this.getHeight(); - g.setColor(this.getBackground()); - g.fillRoundRect(this.i, this.i, this.w - (2 * this.i), this.h - this.i, this.r, this.r); - super.paintComponent(g); - } - } - - /** A quick JLabel for info in "players" panel, to consolidate styling. */ - private class InfoLabel extends JLabel { - public InfoLabel() { - super(); - this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - } - } - - private class TriggerReactionMenu extends JPopupMenu { - private static final long serialVersionUID = 6665085414634139984L; - private int workTrigID; - - public TriggerReactionMenu() { - super(); - - final ForgeAction actAccept = new ForgeAction(NewConstants.Lang.GuiDisplay.Trigger.ALWAYSACCEPT) { - private static final long serialVersionUID = -3734674058185367612L; - - @Override - public final void actionPerformed(final ActionEvent e) { - AllZone.getTriggerHandler().setAlwaysAcceptTrigger(TriggerReactionMenu.this.workTrigID); - } - }; - - final ForgeAction actDecline = new ForgeAction(NewConstants.Lang.GuiDisplay.Trigger.ALWAYSDECLINE) { - private static final long serialVersionUID = -1983295769159971502L; - - @Override - public final void actionPerformed(final ActionEvent e) { - AllZone.getTriggerHandler().setAlwaysDeclineTrigger(TriggerReactionMenu.this.workTrigID); - } - }; - - final ForgeAction actAsk = new ForgeAction(NewConstants.Lang.GuiDisplay.Trigger.ALWAYSASK) { - private static final long serialVersionUID = 5045255351332940821L; - - @Override - public final void actionPerformed(final ActionEvent e) { - AllZone.getTriggerHandler().setAlwaysAskTrigger(TriggerReactionMenu.this.workTrigID); - } - }; - - final JCheckBoxMenuItem jcbmiAccept = new JCheckBoxMenuItem(actAccept); - final JCheckBoxMenuItem jcbmiDecline = new JCheckBoxMenuItem(actDecline); - final JCheckBoxMenuItem jcbmiAsk = new JCheckBoxMenuItem(actAsk); - - this.add(jcbmiAccept); - this.add(jcbmiDecline); - this.add(jcbmiAsk); - } - - public void setTrigger(final int trigID) { - this.workTrigID = trigID; - - if (AllZone.getTriggerHandler().isAlwaysAccepted(trigID)) { - ((JCheckBoxMenuItem) this.getComponent(0)).setState(true); - ((JCheckBoxMenuItem) this.getComponent(1)).setState(false); - ((JCheckBoxMenuItem) this.getComponent(2)).setState(false); - } else if (AllZone.getTriggerHandler().isAlwaysDeclined(trigID)) { - ((JCheckBoxMenuItem) this.getComponent(0)).setState(false); - ((JCheckBoxMenuItem) this.getComponent(1)).setState(true); - ((JCheckBoxMenuItem) this.getComponent(2)).setState(false); - } else { - ((JCheckBoxMenuItem) this.getComponent(0)).setState(false); - ((JCheckBoxMenuItem) this.getComponent(1)).setState(false); - ((JCheckBoxMenuItem) this.getComponent(2)).setState(true); - } - } - } -} diff --git a/src/main/java/forge/view/match/package-info.java b/src/main/java/forge/view/match/package-info.java deleted file mode 100644 index db876fb8d97..00000000000 --- a/src/main/java/forge/view/match/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -/** Views (as in model-view-controller) for Forge. */ -package forge.view.match; -