Improve Android zone restoration

This commit is contained in:
friarsol
2020-02-13 23:17:26 -05:00
parent ddc531c5f2
commit ec79434759
3 changed files with 32 additions and 10 deletions

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -14,11 +14,15 @@ public class PlayerZoneUpdate implements Serializable {
private final Set<ZoneType> zones;
public PlayerZoneUpdate(final PlayerView player, final ZoneType zone) {
if (player == null || zone == null) {
if (player == null ) {
throw new NullPointerException();
}
this.player = player;
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());
}