From ec79434759747348375389794cffdcd58801e40e Mon Sep 17 00:00:00 2001 From: friarsol Date: Thu, 13 Feb 2020 23:17:26 -0500 Subject: [PATCH] Improve Android zone restoration --- .../forge/screens/match/MatchController.java | 10 +++++++--- .../screens/match/views/VPlayerPanel.java | 20 ++++++++++++++++--- .../java/forge/player/PlayerZoneUpdate.java | 12 +++++++---- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/forge-gui-mobile/src/forge/screens/match/MatchController.java b/forge-gui-mobile/src/forge/screens/match/MatchController.java index 4dd665a72a3..8cc153d9ac4 100644 --- a/forge-gui-mobile/src/forge/screens/match/MatchController.java +++ b/forge-gui-mobile/src/forge/screens/match/MatchController.java @@ -322,8 +322,9 @@ public class MatchController extends AbstractGuiGame { final VPlayerPanel playerPanel = view.getPlayerPanel(player); playersWithTargetables.put(player, playerPanel.getSelectedTab()); //backup selected tab before changing it final InfoTab zoneTab = playerPanel.getZoneTab(zoneType); + ZoneType previousZone = playerPanel.getZoneByInfoTab(playerPanel.getSelectedTab()); + updates.add(new PlayerZoneUpdate(player, previousZone)); if (zoneTab != null) { - updates.add(new PlayerZoneUpdate(player, zoneType)); playerPanel.setSelectedTab(zoneTab); } } @@ -343,9 +344,12 @@ public class MatchController extends AbstractGuiGame { break; } - if (zone == null) { return; } - final VPlayerPanel playerPanel = view.getPlayerPanel(player); + if (zone == null) { + playerPanel.hideSelectedTab(); + continue; + } + final InfoTab zoneTab = playerPanel.getZoneTab(zone); playerPanel.setSelectedTab(zoneTab); } diff --git a/forge-gui-mobile/src/forge/screens/match/views/VPlayerPanel.java b/forge-gui-mobile/src/forge/screens/match/views/VPlayerPanel.java index ee7e4c40967..3d24cc4d8e8 100644 --- a/forge-gui-mobile/src/forge/screens/match/views/VPlayerPanel.java +++ b/forge-gui-mobile/src/forge/screens/match/views/VPlayerPanel.java @@ -102,18 +102,32 @@ public class VPlayerPanel extends FContainer { return zoneTabs.get(zoneType); } + public ZoneType getZoneByInfoTab(InfoTab tab) { + for(ZoneType zone : zoneTabs.keySet()) { + if (zoneTabs.get(zone).equals(tab)) { + return zone; + } + } + + return null; + } + public void setSelectedZone(ZoneType zoneType) { setSelectedTab(zoneTabs.get(zoneType)); } + public void hideSelectedTab() { + if (selectedTab != null) { + selectedTab.displayArea.setVisible(false); + } + } + public void setSelectedTab(InfoTab selectedTab0) { if (selectedTab == selectedTab0) { return; } - if (selectedTab != null) { - selectedTab.displayArea.setVisible(false); - } + hideSelectedTab(); selectedTab = selectedTab0; diff --git a/forge-gui/src/main/java/forge/player/PlayerZoneUpdate.java b/forge-gui/src/main/java/forge/player/PlayerZoneUpdate.java index 5408941ffe5..7ed01f9f469 100644 --- a/forge-gui/src/main/java/forge/player/PlayerZoneUpdate.java +++ b/forge-gui/src/main/java/forge/player/PlayerZoneUpdate.java @@ -14,11 +14,15 @@ public class PlayerZoneUpdate implements Serializable { private final Set zones; public PlayerZoneUpdate(final PlayerView player, final ZoneType zone) { - if (player == null || zone == null) { + if (player == null ) { throw new NullPointerException(); } this.player = player; - this.zones = EnumSet.of(zone); + if (zone != null) { + this.zones = EnumSet.of(zone); + } else { + this.zones = EnumSet.noneOf(ZoneType.class); + } } public PlayerView getPlayer() { @@ -30,13 +34,13 @@ public class PlayerZoneUpdate implements Serializable { void addZone(final ZoneType zone) { if (zone == null) { - throw new NullPointerException(); + return; } zones.add(zone); } void add(final PlayerZoneUpdate other) { if (other == null) { - throw new NullPointerException(); + return; } zones.addAll(other.getZones()); }