diff --git a/forge-gui-desktop/src/main/java/forge/GuiDesktop.java b/forge-gui-desktop/src/main/java/forge/GuiDesktop.java index 53d0f022f53..a886fad3ec6 100644 --- a/forge-gui-desktop/src/main/java/forge/GuiDesktop.java +++ b/forge-gui-desktop/src/main/java/forge/GuiDesktop.java @@ -395,14 +395,21 @@ public class GuiDesktop implements IGuiBase { } @Override - public boolean openZone(ZoneType zoneType, Set players) { - switch (zoneType) { - case Battlefield: - case Hand: - return true; //don't actually need to open anything, but indicate that zone can be opened - default: - return false; + public boolean openZones(List zones, Map players) { + if (zones.size() == 1) { + switch (zones.get(0)) { + case Battlefield: + case Hand: + return true; //don't actually need to open anything, but indicate that zone can be opened + default: + return false; + } } + return false; + } + + @Override + public void restoreOldZones(Map playersToRestoreZonesFor) { } @Override diff --git a/forge-gui-mobile/src/forge/GuiMobile.java b/forge-gui-mobile/src/forge/GuiMobile.java index c9204dd391c..c56ebce20ad 100644 --- a/forge-gui-mobile/src/forge/GuiMobile.java +++ b/forge-gui-mobile/src/forge/GuiMobile.java @@ -4,6 +4,7 @@ import java.io.File; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import org.apache.commons.lang3.tuple.Pair; @@ -327,24 +328,37 @@ public class GuiMobile implements IGuiBase { } @Override - public boolean openZone(ZoneType zoneType, Set players) { - switch (zoneType) { - case Battlefield: - return true; //Battlefield is always open - default: - //open zone tab for given zone if needed - boolean result = true; - for (Player player : players) { - VPlayerPanel playerPanel = FControl.getPlayerPanel(player); - InfoTab zoneTab = playerPanel.getZoneTab(zoneType); - if (zoneTab == null) { - result = false; - } - else { - playerPanel.setSelectedTab(zoneTab); + public boolean openZones(List zones, Map players) { + if (zones.size() == 1) { + ZoneType zoneType = zones.get(0); + switch (zoneType) { + case Battlefield: + return true; //Battlefield is always open + default: + //open zone tab for given zone if needed + boolean result = true; + for (Player player : players.keySet()) { + VPlayerPanel playerPanel = FControl.getPlayerPanel(player); + players.put(player, playerPanel.getSelectedTab()); //backup selected tab before changing it + InfoTab zoneTab = playerPanel.getZoneTab(zoneType); + if (zoneTab == null) { + result = false; + } + else { + playerPanel.setSelectedTab(zoneTab); + } } + return result; } - return result; + } + return false; + } + + @Override + public void restoreOldZones(Map playersToRestoreZonesFor) { + for (Entry player : playersToRestoreZonesFor.entrySet()) { + VPlayerPanel playerPanel = FControl.getPlayerPanel(player.getKey()); + playerPanel.setSelectedTab((InfoTab)player.getValue()); } } diff --git a/forge-gui/src/main/java/forge/interfaces/IGuiBase.java b/forge-gui/src/main/java/forge/interfaces/IGuiBase.java index 5e24d94627b..129cdef9f67 100644 --- a/forge-gui/src/main/java/forge/interfaces/IGuiBase.java +++ b/forge-gui/src/main/java/forge/interfaces/IGuiBase.java @@ -73,7 +73,8 @@ public interface IGuiBase { void enableOverlay(); void disableOverlay(); void finishGame(); - boolean openZone(ZoneType zoneType, Set players); + boolean openZones(List zones, Map players); + void restoreOldZones(Map playersToRestoreZonesFor); void updateStack(); void updateZones(List> zonesToUpdate); void updateCards(Set cardsToUpdate); diff --git a/forge-gui/src/main/java/forge/player/TargetSelection.java b/forge-gui/src/main/java/forge/player/TargetSelection.java index e99f11a70f8..a15ef2b1b4c 100644 --- a/forge-gui/src/main/java/forge/player/TargetSelection.java +++ b/forge-gui/src/main/java/forge/player/TargetSelection.java @@ -36,9 +36,9 @@ import forge.util.Aggregates; import forge.util.gui.SGuiChoose; import java.util.ArrayList; -import java.util.HashSet; +import java.util.HashMap; import java.util.List; -import java.util.Set; +import java.util.Map; /** *

@@ -113,12 +113,17 @@ public class TargetSelection { return this.chooseCardFromStack(mandatory); } else { - List validTargets = this.getValidCardsToTarget(); - if (zone.size() == 1 && GuiBase.getInterface().openZone(zone.get(0), getPlayersWithValidTargets(validTargets))) { + final List validTargets = this.getValidCardsToTarget(); + final Map playersWithValidTargets = new HashMap(); + for (Card card : validTargets) { + playersWithValidTargets.put(card.getController(), null); + } + if (GuiBase.getInterface().openZones(zone, playersWithValidTargets)) { InputSelectTargets inp = new InputSelectTargets(validTargets, ability, mandatory); inp.showAndWait(); choiceResult = !inp.hasCancelled(); bTargetingDone = inp.hasPressedOk(); + GuiBase.getInterface().restoreOldZones(playersWithValidTargets); } else { // for every other case an all-purpose GuiChoose @@ -129,14 +134,6 @@ public class TargetSelection { return choiceResult && chooseTargets(numTargets); } - private Set getPlayersWithValidTargets(List validTargets) { - Set players = new HashSet(); - for (Card card : validTargets) { - players.add(card.getController()); - } - return players; - } - // these have been copied over from CardFactoryUtil as they need two extra // parameters for target selection. // however, due to the changes necessary for SA_Requirements this is much