From 9fe061f21c0ed880efed860b95610b66114f68e1 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Sat, 18 Jun 2011 00:22:11 +0200 Subject: Man kann ein Spiel joinen und auch wieder verlassen git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@451 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/network/GameJoinControl.java | 48 +++++++++++++--------- .../control/network/GameOfferControl.java | 29 +++++++++++++ src/jrummikub/control/network/NetworkControl.java | 8 +++- 3 files changed, 65 insertions(+), 20 deletions(-) diff --git a/src/jrummikub/control/network/GameJoinControl.java b/src/jrummikub/control/network/GameJoinControl.java index fbc18c6..83df0ed 100644 --- a/src/jrummikub/control/network/GameJoinControl.java +++ b/src/jrummikub/control/network/GameJoinControl.java @@ -35,7 +35,6 @@ public class GameJoinControl { this.gameData = gameData; this.view = view; - view.getSettingsPanel().setSettingsMode(SettingsMode.NETWORK_JOIN); view.getSettingsPanel().enableAddPlayerButton(false); view.getSettingsPanel().setGameSettings(gameData.getGameSettings()); @@ -55,22 +54,21 @@ public class GameJoinControl { } } })); - connections.add(view.getSettingsPanel().getBackEvent().add(new IListener() { - @Override - public void handle() { - //TODO mit game offer control und game data reden (spieler werden nich wieder entfernt) - - abort(); - } - })); - connections.add(view.getSettingsPanel().getChangePlayerColorEvent().add(new IListener2() { - @Override - public void handle(Integer playerNumber, Color color) { - // TODO Auto-generated method stub - - - } - })); + connections.add(view.getSettingsPanel().getBackEvent().add( + new IListener() { + @Override + public void handle() { + goBack(); + } + })); + connections.add(view.getSettingsPanel().getChangePlayerColorEvent() + .add(new IListener2() { + @Override + public void handle(Integer playerNumber, Color color) { + // TODO Auto-generated method stub + + } + })); } private void updateSettingsPanel(GameSettings settings) { @@ -96,6 +94,10 @@ public class GameJoinControl { } } } + + public Event getBackEvent(){ + return backEvent; + } public void startGameJoin() { view.showSettingsPanel(true); @@ -104,9 +106,17 @@ public class GameJoinControl { /** * Aborts joining and goes back to game list */ - public void abort() { + private void goBack() { + abort(); + connectionControl.leaveGame(gameData.getGameID()); view.showSettingsPanel(false); - view.showGameListPanel(true); + backEvent.emit(); + } + + /** + * Aborts joining + */ + public void abort() { for (Connection c : connections) { c.remove(); } diff --git a/src/jrummikub/control/network/GameOfferControl.java b/src/jrummikub/control/network/GameOfferControl.java index 247cd18..fd55fc1 100644 --- a/src/jrummikub/control/network/GameOfferControl.java +++ b/src/jrummikub/control/network/GameOfferControl.java @@ -13,6 +13,7 @@ import jrummikub.model.PlayerSettings; import jrummikub.model.PlayerSettings.Type; import jrummikub.util.Connection; import jrummikub.util.GameData; +import jrummikub.util.IListener; import jrummikub.util.IListener2; import jrummikub.view.ISettingsPanel; import jrummikub.view.ISettingsPanel.SettingsMode; @@ -70,6 +71,34 @@ public class GameOfferControl { updateSettingsPanel(settings); } })); + connections.add(connectionControl.getGameLeaveEvent().add(new IListener2() { + @Override + public void handle(UUID value1, String value2) { + List players = gameData.getGameSettings().getPlayerList(); + int index=0; + for(PlayerSettings s:players){ + if (s.getName().equals(value2)){ + break; + } + index++; + } + //Only remove network players + if(gameData.getGameSettings().getPlayerList().get(index).getType() == Type.NETWORK){ + gameData.getGameSettings().getPlayerList().get(index).setType(Type.VACANT); + gameData.getGameSettings().getPlayerList().get(index).setName("Offen"); + } + updateSettingsPanel(gameData.getGameSettings()); + connectionControl.offerGame(gameData); + + } + })); + connections.add(view.getSettingsPanel().getBackEvent().add(new IListener() { + @Override + public void handle() { + // TODO Auto-generated method stub + + } + })); } private void updateSettingsPanel(GameSettings settings) { diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java index a89e77d..0ae3808 100644 --- a/src/jrummikub/control/network/NetworkControl.java +++ b/src/jrummikub/control/network/NetworkControl.java @@ -142,7 +142,6 @@ public class NetworkControl { createGameJoinControl(uuid); } else { // TODO Error message - System.err.println("Join NACKed"); view.showGameListPanel(true); } } @@ -166,6 +165,13 @@ public class NetworkControl { GameData gameData = gameMap.get(uuid); gameJoinControl = new GameJoinControl(connectionControl, gameData, view); + gameJoinControl.getBackEvent().add(new IListener() { + @Override + public void handle() { + gameJoinControl=null; + view.showGameListPanel(true); + } + }); gameJoinControl.startGameJoin(); } -- cgit v1.2.3