From 4879b7b93eaff1f80056d78e19271d6418ec6534 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 14 Jun 2011 02:43:55 +0200 Subject: Display open games correctly git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@433 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/AbstractSettingsControl.java | 2 +- .../control/network/GameOfferControl.java | 15 ++++++++-- src/jrummikub/control/network/NetworkControl.java | 34 +++++++++++++--------- .../control/network/NetworkSettingsControl.java | 6 ++-- src/jrummikub/model/PlayerSettings.java | 4 ++- src/jrummikub/view/impl/GameListPanel.java | 18 +++++++++--- src/jrummikub/view/impl/SettingsPanel.java | 2 ++ 7 files changed, 56 insertions(+), 25 deletions(-) diff --git a/src/jrummikub/control/AbstractSettingsControl.java b/src/jrummikub/control/AbstractSettingsControl.java index 693e0f0..ff43ce2 100644 --- a/src/jrummikub/control/AbstractSettingsControl.java +++ b/src/jrummikub/control/AbstractSettingsControl.java @@ -262,7 +262,7 @@ public abstract class AbstractSettingsControl { String name = player1.getName(); Type type = player1.getType(); - if (type == Type.NETWORK) { + if (type == Type.VACANT) { continue; } diff --git a/src/jrummikub/control/network/GameOfferControl.java b/src/jrummikub/control/network/GameOfferControl.java index 8d3e8c8..0db5110 100644 --- a/src/jrummikub/control/network/GameOfferControl.java +++ b/src/jrummikub/control/network/GameOfferControl.java @@ -1,10 +1,14 @@ package jrummikub.control.network; +import java.util.UUID; + import jrummikub.model.GameSettings; +import jrummikub.util.GameData; import jrummikub.view.ISettingsPanel.SettingsMode; import jrummikub.view.IView; public class GameOfferControl { + private GameData gameData; private ConnectionControl connectionControl; private GameSettings settings; private IView view; @@ -14,15 +18,22 @@ public class GameOfferControl { this.connectionControl = connectionControl; this.settings = settings; this.view = view; - + + gameData = new GameData(UUID.randomUUID(), settings); + view.getSettingsPanel().setSettingsMode(SettingsMode.NETWORK_OFFER); view.getSettingsPanel().enableAddPlayerButton(false); view.getSettingsPanel().setGameSettings(settings); } public void startGameOffer() { + connectionControl.offerGame(gameData); + view.showSettingsPanel(true); - + } + public void abort() { + connectionControl.withdrawGame(gameData.getGameID()); + } } diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java index e09cdc0..7435839 100644 --- a/src/jrummikub/control/network/NetworkControl.java +++ b/src/jrummikub/control/network/NetworkControl.java @@ -34,9 +34,9 @@ public class NetworkControl { * Creates a new network control * * @param loginData - * user's login data + * user's login data * @param view - * for events and handlers + * for events and handlers */ public NetworkControl(final LoginData loginData, final IView view) { this.view = view; @@ -75,21 +75,19 @@ public class NetworkControl { * Adds the listeners for connection control events * * @param loginData - * player's login data + * player's login data * @param view - * view for events + * view for events */ public void addConnectionControlListeners(final LoginData loginData, final IView view) { - connections.add(connectionControl.getConnectedEvent().add( - new IListener() { - @Override - public void handle() { - view.getGameListPanel().setChannelName( - loginData.getChannelName()); - view.showGameListPanel(true); - } - })); + connections.add(connectionControl.getConnectedEvent().add(new IListener() { + @Override + public void handle() { + view.getGameListPanel().setChannelName(loginData.getChannelName()); + view.showGameListPanel(true); + } + })); connections.add(connectionControl.getConnectionFailedEvent().add( new IListener() { @@ -144,8 +142,16 @@ public class NetworkControl { for (Connection c : connections) { c.remove(); } - connectionControl.disconnect(); view.showGameListPanel(false); + + if (settingsControl != null) { + settingsControl.abort(); + } + if (gameOfferControl != null) { + gameOfferControl.abort(); + } + + connectionControl.disconnect(); } /** diff --git a/src/jrummikub/control/network/NetworkSettingsControl.java b/src/jrummikub/control/network/NetworkSettingsControl.java index ca8c74b..447bf08 100644 --- a/src/jrummikub/control/network/NetworkSettingsControl.java +++ b/src/jrummikub/control/network/NetworkSettingsControl.java @@ -99,7 +99,7 @@ public class NetworkSettingsControl extends AbstractSettingsControl { choices.add(Collections.singletonList(Type.HUMAN)); enableRemoveButtons.add(false); } else { - choices.add(Arrays.asList(Type.NETWORK, Type.COMPUTER)); + choices.add(Arrays.asList(Type.VACANT, Type.COMPUTER)); enableRemoveButtons.add(settings.getPlayerList().size() > 2); } @@ -119,7 +119,7 @@ public class NetworkSettingsControl extends AbstractSettingsControl { settings.getPlayerList().get(i).setType(type); - if (type == Type.NETWORK) { + if (type == Type.VACANT) { settings.getPlayerList().get(i).setName("Offen"); } else if (oldType != Type.COMPUTER && type == Type.COMPUTER) { // Find unused player name @@ -158,7 +158,7 @@ public class NetworkSettingsControl extends AbstractSettingsControl { PlayerSettings playerSettings = new PlayerSettings("Offen", findUnusedColor()); - playerSettings.setType(Type.NETWORK); + playerSettings.setType(Type.VACANT); settings.getPlayerList().add(playerSettings); update(); diff --git a/src/jrummikub/model/PlayerSettings.java b/src/jrummikub/model/PlayerSettings.java index 5e9d05a..effd933 100644 --- a/src/jrummikub/model/PlayerSettings.java +++ b/src/jrummikub/model/PlayerSettings.java @@ -16,7 +16,9 @@ public class PlayerSettings implements Serializable { /** */ COMPUTER, /** */ - NETWORK + NETWORK, + /** */ + VACANT } private static final long serialVersionUID = 1963640115089275992L; diff --git a/src/jrummikub/view/impl/GameListPanel.java b/src/jrummikub/view/impl/GameListPanel.java index d22dc02..7324559 100644 --- a/src/jrummikub/view/impl/GameListPanel.java +++ b/src/jrummikub/view/impl/GameListPanel.java @@ -21,6 +21,8 @@ import javax.swing.border.CompoundBorder; import javax.swing.border.EmptyBorder; import javax.swing.border.LineBorder; +import jrummikub.model.PlayerSettings; +import jrummikub.model.PlayerSettings.Type; import jrummikub.util.Event; import jrummikub.util.Event1; import jrummikub.util.GameData; @@ -188,13 +190,21 @@ class GameListPanel extends JPanel implements IGameListPanel { int index, boolean isSelected, boolean cellHasFocus) { String host = "", playerCount = ""; - if (value instanceof GameData && ((GameData)value).getGameSettings() != null) { + if (value instanceof GameData + && ((GameData) value).getGameSettings() != null) { GameData gameData = (GameData) value; host = gameData.getHost(); - /*playerCount = gameData.getCurrentPlayerCount() + "/" - + gameData.getMaxPlayerCount();*/ - playerCount = String.valueOf(gameData.getGameSettings().getPlayerList().size()); + int total = gameData.getGameSettings().getPlayerList().size(); + int occupied = total; + + for (PlayerSettings player : gameData.getGameSettings().getPlayerList()) { + if (player.getType() == Type.VACANT) { + occupied--; + } + } + + playerCount = occupied + "/" + total; } else { host = String.valueOf(value); } diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java index 60fe20c..8ec9d3e 100644 --- a/src/jrummikub/view/impl/SettingsPanel.java +++ b/src/jrummikub/view/impl/SettingsPanel.java @@ -275,6 +275,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel { @Override public void enableStartGameButton(boolean enable) { startButton.setEnabled(enable); + offerButton.setEnabled(enable); } @Override @@ -861,6 +862,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel { case HUMAN: return "Mensch"; case NETWORK: + case VACANT: return "Netzwerk"; } -- cgit v1.2.3