From 82d69635a890c0147804132434a0fc7d45e8425b Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 21 Jun 2011 21:24:26 +0200 Subject: Add "Waiting for players" message to GameOfferControl git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@557 72836036-5685-4462-b002-a69064685172 --- .../control/network/GameOfferControl.java | 33 +++++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'src/jrummikub/control/network') diff --git a/src/jrummikub/control/network/GameOfferControl.java b/src/jrummikub/control/network/GameOfferControl.java index b513170..c697647 100644 --- a/src/jrummikub/control/network/GameOfferControl.java +++ b/src/jrummikub/control/network/GameOfferControl.java @@ -12,6 +12,7 @@ import jrummikub.util.GameData; import jrummikub.util.IEvent1; import jrummikub.util.IListener; import jrummikub.util.IListener1; +import jrummikub.view.ISettingsPanel.SettingsError; import jrummikub.view.ISettingsPanel.SettingsMode; import jrummikub.view.IView; @@ -44,19 +45,31 @@ public class GameOfferControl extends AbstractGameBeginControl { public void handle() { List players = gameData.getGameSettings() .getPlayerList(); - for (PlayerSettings s : players) { - if (s.getType() == Type.NETWORK) { - startGame(); - return; - } + if (checkPlayers()) { + startGame(); } } })); + + checkPlayers(); + } + + private boolean checkPlayers() { + for (PlayerSettings s : gameData.getGameSettings().getPlayerList()) { + if (s.getType() == Type.NETWORK) { + view.getSettingsPanel().setError(SettingsError.NO_ERROR); + view.getSettingsPanel().enableStartGameButton(true); + return true; + } + } + + view.getSettingsPanel().setError(SettingsError.WAITING_FOR_PLAYERS); + view.getSettingsPanel().enableStartGameButton(false); + return false; } private void addConnectionControlListeners( - final IConnectionControl connectionControl, - final GameSettings settings) { + final IConnectionControl connectionControl, final GameSettings settings) { connections.add(connectionControl.getGameJoinEvent().add( new IListener1() { @Override @@ -65,7 +78,10 @@ public class GameOfferControl extends AbstractGameBeginControl { if (player.getType() == Type.VACANT) { player.setName(sender); player.setType(Type.NETWORK); + updateSettingsPanel(); + checkPlayers(); + connectionControl.ackJoinGame(sender, true); connectionControl.offerGame(gameData); return; @@ -88,7 +104,10 @@ public class GameOfferControl extends AbstractGameBeginControl { break; } } + updateSettingsPanel(); + checkPlayers(); + connectionControl.offerGame(gameData); } })); -- cgit v1.2.3