From 49847028036fe7abdb8afc07d5dddc4dae442c5c Mon Sep 17 00:00:00 2001 From: drdev Date: Sat, 13 Jun 2015 17:20:49 +0000 Subject: [PATCH] Tweak how mobile user sets that they're ready --- .../screens/constructed/LobbyScreen.java | 3 - .../screens/constructed/PlayerPanel.java | 57 +++++++++---------- .../src/main/java/forge/match/GameLobby.java | 2 +- .../src/main/java/forge/net/OfflineLobby.java | 4 +- 4 files changed, 29 insertions(+), 37 deletions(-) diff --git a/forge-gui-mobile/src/forge/screens/constructed/LobbyScreen.java b/forge-gui-mobile/src/forge/screens/constructed/LobbyScreen.java index 87bf9be3184..34c9c6b2719 100644 --- a/forge-gui-mobile/src/forge/screens/constructed/LobbyScreen.java +++ b/forge-gui-mobile/src/forge/screens/constructed/LobbyScreen.java @@ -245,9 +245,6 @@ public abstract class LobbyScreen extends LaunchScreen implements ILobbyView { @Override protected void startMatch() { - if (lobby.isAllowNetworking()) { //flag that player 1 is ready when Start button tapped - lobby.getSlot(0).setIsReady(true); - } for (int i = 0; i < getNumPlayers(); i++) { updateDeck(i); } diff --git a/forge-gui-mobile/src/forge/screens/constructed/PlayerPanel.java b/forge-gui-mobile/src/forge/screens/constructed/PlayerPanel.java index ae2f1baabe8..a1b8b5e83cd 100644 --- a/forge-gui-mobile/src/forge/screens/constructed/PlayerPanel.java +++ b/forge-gui-mobile/src/forge/screens/constructed/PlayerPanel.java @@ -62,7 +62,7 @@ public class PlayerPanel extends FContainer { private int avatarIndex; private final FTextField txtPlayerName = new FTextField("Player name"); - private final FToggleSwitch humanAiSwitch = new FToggleSwitch("Human", "AI"); + private final FToggleSwitch humanAiSwitch; private FComboBox cbTeam = new FComboBox(); private FComboBox cbArchenemyTeam = new FComboBox(); @@ -80,6 +80,12 @@ public class PlayerPanel extends FContainer { super(); screen = screen0; allowNetworking = allowNetworking0; + if (allowNetworking) { + humanAiSwitch = new FToggleSwitch("Not Ready", "Ready"); + } + else { + humanAiSwitch = new FToggleSwitch("Human", "AI"); + } index = index0; populateTeamsComboBoxes(); setTeam(slot.getTeam()); @@ -284,30 +290,22 @@ public class PlayerPanel extends FContainer { private final FEventHandler humanAiSwitched = new FEventHandler() { @Override public void handleEvent(FEvent e) { - boolean wasAi = isAi(); - boolean isAi = humanAiSwitch.isToggled(); - if (isAi) { - type = LobbySlotType.AI; - } - else if (allowNetworking && index > 0) { - type = isReady ? LobbySlotType.REMOTE : LobbySlotType.OPEN; - humanAiSwitch.setOffText(isReady ? "Ready" : "Open"); + boolean toggled = humanAiSwitch.isToggled(); + if (allowNetworking) { + setIsReady(toggled); } else { - type = LobbySlotType.LOCAL; + type = toggled ? LobbySlotType.AI : LobbySlotType.LOCAL; + onIsAiChanged(toggled); + + LobbySlot slot = screen.getLobby().getSlot(index); + slot.setType(type); + + //update may edit in-case it changed as a result of the AI change + setMayEdit(screen.getLobby().mayEdit(index)); + setAvatarIndex(slot.getAvatarIndex()); + setPlayerName(slot.getName()); } - - if (wasAi != isAi) { - onIsAiChanged(isAi); - } - - LobbySlot slot = screen.getLobby().getSlot(index); - slot.setType(type); - - //update may edit in-case it changed as a result of the AI change - setMayEdit(screen.getLobby().mayEdit(index)); - setAvatarIndex(slot.getAvatarIndex()); - setPlayerName(slot.getName()); } }; @@ -552,12 +550,11 @@ public class PlayerPanel extends FContainer { humanAiSwitch.setToggled(true); break; case OPEN: - humanAiSwitch.setOffText("Open"); + isReady = false; humanAiSwitch.setToggled(false); break; case REMOTE: - humanAiSwitch.setOffText("Ready"); - humanAiSwitch.setToggled(false); + humanAiSwitch.setToggled(isReady); break; } @@ -597,11 +594,8 @@ public class PlayerPanel extends FContainer { return isReady; } public void setIsReady(boolean isReady0) { - if (isReady == isReady0) { return; } - - if (type == LobbySlotType.LOCAL) { - humanAiSwitch.setOffText(isReady ? "Ready" : "Human"); - } + isReady = isReady0; + humanAiSwitch.setToggled(isReady); } public void setMayEdit(boolean mayEdit0) { @@ -610,6 +604,7 @@ public class PlayerPanel extends FContainer { avatarLabel.setEnabled(mayEdit); txtPlayerName.setEnabled(mayEdit); nameRandomiser.setEnabled(mayEdit); + humanAiSwitch.setEnabled(mayEdit && mayControl); updateVariantControlsVisibility(); //if panel has height already, ensure height updated to account for button visibility changes @@ -621,7 +616,7 @@ public class PlayerPanel extends FContainer { public void setMayControl(boolean mayControl0) { if (mayControl == mayControl0) { return; } mayControl = mayControl0; - humanAiSwitch.setEnabled(mayControl); + humanAiSwitch.setEnabled(mayEdit && mayControl); } public void setMayRemove(boolean mayRemove0) { diff --git a/forge-gui/src/main/java/forge/match/GameLobby.java b/forge-gui/src/main/java/forge/match/GameLobby.java index b1ab9244218..384ef3b7204 100644 --- a/forge-gui/src/main/java/forge/match/GameLobby.java +++ b/forge-gui/src/main/java/forge/match/GameLobby.java @@ -154,7 +154,7 @@ public abstract class GameLobby { } data.slots.add(slot); - if (StringUtils.isEmpty(slot.getName())) { + if (StringUtils.isEmpty(slot.getName()) && slot.getType() != LobbySlotType.OPEN) { slot.setName(randomName()); } if (data.slots.size() == 1) { diff --git a/forge-gui/src/main/java/forge/net/OfflineLobby.java b/forge-gui/src/main/java/forge/net/OfflineLobby.java index a5762fa776d..de2dca14b53 100644 --- a/forge-gui/src/main/java/forge/net/OfflineLobby.java +++ b/forge-gui/src/main/java/forge/net/OfflineLobby.java @@ -16,10 +16,10 @@ public final class OfflineLobby extends GameLobby { final String humanName = localName(); final int[] avatarIndices = localAvatarIndices(); - final LobbySlot slot0 = new LobbySlot(LobbySlotType.LOCAL, humanName, avatarIndices[0], 0, true, true, Collections.emptySet()); + final LobbySlot slot0 = new LobbySlot(LobbySlotType.LOCAL, humanName, avatarIndices[0], 0, true, false, Collections.emptySet()); addSlot(slot0); - final LobbySlot slot1 = new LobbySlot(LobbySlotType.OPEN, "Open", avatarIndices[1], 1, false, false, Collections.emptySet()); + final LobbySlot slot1 = new LobbySlot(LobbySlotType.OPEN, null, -1, -1, false, false, Collections.emptySet()); addSlot(slot1); }