From 626f4bd9ab6f9143851768b3b2f0a756a9d45f01 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Sat, 18 Jun 2011 02:34:07 +0200 Subject: Implemented color changing in game begin panels git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@455 72836036-5685-4462-b002-a69064685172 --- .../control/network/ConnectionControl.java | 4 +- src/jrummikub/control/network/GameJoinControl.java | 74 ++--------------- .../control/network/GameOfferControl.java | 94 +++++----------------- 3 files changed, 28 insertions(+), 144 deletions(-) (limited to 'src/jrummikub/control') diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java index 21d2c8b..6dc1bb5 100644 --- a/src/jrummikub/control/network/ConnectionControl.java +++ b/src/jrummikub/control/network/ConnectionControl.java @@ -9,12 +9,10 @@ import jrummikub.model.GameSettings; import jrummikub.util.Event; import jrummikub.util.Event1; import jrummikub.util.Event2; -import jrummikub.util.Event3; import jrummikub.util.GameData; import jrummikub.util.IEvent; import jrummikub.util.IEvent1; import jrummikub.util.IEvent2; -import jrummikub.util.IEvent3; import jrummikub.util.LoginData; import org.jivesoftware.smack.Connection; @@ -307,7 +305,7 @@ class ConnectionControl { } else if (messageType.equals("game_join_ack")) { gameJoinAckEvent .emit(Boolean.valueOf(extension.getValue("ack"))); - } else if (messageType.equals("changeColor")) { + } else if (messageType.equals("change_color")) { changeColorEvent.emit(sender, (Color) Base64 .decodeToObject(extension.getValue("color"))); } else { diff --git a/src/jrummikub/control/network/GameJoinControl.java b/src/jrummikub/control/network/GameJoinControl.java index afb78d4..1d29df4 100644 --- a/src/jrummikub/control/network/GameJoinControl.java +++ b/src/jrummikub/control/network/GameJoinControl.java @@ -1,43 +1,20 @@ package jrummikub.control.network; -import java.awt.Color; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; - import jrummikub.model.GameSettings; import jrummikub.model.PlayerSettings; import jrummikub.model.PlayerSettings.Type; -import jrummikub.util.Connection; import jrummikub.util.Event; import jrummikub.util.GameData; -import jrummikub.util.IListener; import jrummikub.util.IListener1; -import jrummikub.util.IListener2; -import jrummikub.util.IListener3; -import jrummikub.view.ISettingsPanel; -import jrummikub.view.IView; import jrummikub.view.ISettingsPanel.SettingsMode; +import jrummikub.view.IView; -public class GameJoinControl { - private List connections = new ArrayList(); - private GameData gameData; - private ConnectionControl connectionControl; - private IView view; +public class GameJoinControl extends AbstractGameBeginControl { private Event backEvent = new Event(); public GameJoinControl(final ConnectionControl connectionControl, final GameData gameData, final IView view) { - this.connectionControl = connectionControl; - this.gameData = gameData; - this.view = view; - - view.getSettingsPanel().setSettingsMode(SettingsMode.NETWORK_JOIN); - view.getSettingsPanel().enableAddPlayerButton(false); - view.getSettingsPanel().setGameSettings(gameData.getGameSettings()); + super(connectionControl, view, gameData, SettingsMode.NETWORK_JOIN); connections.add(connectionControl.getGameOfferEvent().add( new IListener1() { @@ -50,38 +27,10 @@ public class GameJoinControl { gameData.setGameSettings(settings); - updateSettingsPanel(settings); + updateSettingsPanel(); } } })); - 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) { - view.getSettingsPanel().setGameSettings(settings); - - Set colors = new HashSet(Arrays - .asList(ISettingsPanel.PLAYER_COLORS)); - - for (PlayerSettings player : settings.getPlayerList()) { - colors.remove(player.getColor()); - } - - view.getSettingsPanel().setPlayerColors(colors); } private void fixGameSettings(GameSettings settings) { @@ -94,8 +43,8 @@ public class GameJoinControl { } } } - - public Event getBackEvent(){ + + public Event getBackEvent() { return backEvent; } @@ -106,20 +55,11 @@ public class GameJoinControl { /** * Aborts joining and goes back to game list */ - private void goBack() { + protected void goBack() { abort(); connectionControl.leaveGame(); view.showSettingsPanel(false); 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 f0dc526..f09eb6e 100644 --- a/src/jrummikub/control/network/GameOfferControl.java +++ b/src/jrummikub/control/network/GameOfferControl.java @@ -1,41 +1,23 @@ package jrummikub.control.network; -import java.awt.Color; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.UUID; import jrummikub.model.GameSettings; import jrummikub.model.PlayerSettings; import jrummikub.model.PlayerSettings.Type; -import jrummikub.util.Connection; import jrummikub.util.GameData; -import jrummikub.util.IListener; import jrummikub.util.IListener1; -import jrummikub.util.IListener2; -import jrummikub.view.ISettingsPanel; import jrummikub.view.ISettingsPanel.SettingsMode; import jrummikub.view.IView; -public class GameOfferControl { - private List connections = new ArrayList(); - private GameData gameData; - private ConnectionControl connectionControl; - private IView view; +public class GameOfferControl extends AbstractGameBeginControl { public GameOfferControl(final ConnectionControl connectionControl, final GameSettings settings, final IView view) { - this.connectionControl = connectionControl; - this.view = view; - - gameData = new GameData(UUID.randomUUID(), settings); - - view.getSettingsPanel().setSettingsMode(SettingsMode.NETWORK_OFFER); - view.getSettingsPanel().enableAddPlayerButton(false); - updateSettingsPanel(settings); + super(connectionControl, view, + new GameData(UUID.randomUUID(), settings), + SettingsMode.NETWORK_OFFER); connections.add(connectionControl.getGameJoinEvent().add( new IListener1() { @@ -45,7 +27,7 @@ public class GameOfferControl { if (player.getType() == Type.VACANT) { player.setName(sender); player.setType(Type.NETWORK); - updateSettingsPanel(settings); + updateSettingsPanel(); connectionControl.ackJoinGame(sender, true); connectionControl.offerGame(gameData); return; @@ -55,60 +37,24 @@ public class GameOfferControl { connectionControl.ackJoinGame(sender, false); } })); - connections.add(view.getSettingsPanel().getChangePlayerColorEvent() - .add(new IListener2() { + connections.add(connectionControl.getGameLeaveEvent().add( + new IListener1() { @Override - public void handle(Integer i, Color color) { - for (PlayerSettings player : settings.getPlayerList()) { - if (player.getColor() == color) { - return; + public void handle(String sender) { + List players = gameData + .getGameSettings().getPlayerList(); + for (PlayerSettings s : players) { + if (s.getName().equals(sender) + && s.getType() == Type.NETWORK) { + s.setType(Type.VACANT); + s.setName("Offen"); + break; } } - settings.getPlayerList().get(i).setColor(color); - updateSettingsPanel(settings); + updateSettingsPanel(); + connectionControl.offerGame(gameData); } })); - connections.add(connectionControl.getGameLeaveEvent().add(new IListener1() { - @Override - public void handle(String sender) { - List players = gameData.getGameSettings().getPlayerList(); - int index=0; - for(PlayerSettings s:players){ - if (s.getName().equals(sender)){ - 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) { - view.getSettingsPanel().setGameSettings(settings); - - Set colors = new HashSet( - Arrays.asList(ISettingsPanel.PLAYER_COLORS)); - - for (PlayerSettings player : settings.getPlayerList()) { - colors.remove(player.getColor()); - } - - view.getSettingsPanel().setPlayerColors(colors); } public void startGameOffer() { @@ -118,7 +64,7 @@ public class GameOfferControl { } - public void abort() { - connectionControl.withdrawGame(); + protected void goBack() { + // TODO } } -- cgit v1.2.3