Implemented color changing in game begin panels
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@455 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
fbf5cc3572
commit
626f4bd9ab
4 changed files with 135 additions and 232 deletions
|
@ -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 {
|
||||
|
|
|
@ -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<Connection> connections = new ArrayList<Connection>();
|
||||
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<GameData>() {
|
||||
|
@ -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<Integer, Color>() {
|
||||
@Override
|
||||
public void handle(Integer playerNumber, Color color) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void updateSettingsPanel(GameSettings settings) {
|
||||
view.getSettingsPanel().setGameSettings(settings);
|
||||
|
||||
Set<Color> colors = new HashSet<Color>(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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Connection> connections = new ArrayList<Connection>();
|
||||
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<String>() {
|
||||
|
@ -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<Integer, Color>() {
|
||||
connections.add(connectionControl.getGameLeaveEvent().add(
|
||||
new IListener1<String>() {
|
||||
@Override
|
||||
public void handle(Integer i, Color color) {
|
||||
for (PlayerSettings player : settings.getPlayerList()) {
|
||||
if (player.getColor() == color) {
|
||||
return;
|
||||
public void handle(String sender) {
|
||||
List<PlayerSettings> 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<String>() {
|
||||
@Override
|
||||
public void handle(String sender) {
|
||||
List<PlayerSettings> 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<Color> colors = new HashSet<Color>(
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue