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
This commit is contained in:
parent
4860867fe8
commit
9fe061f21c
3 changed files with 65 additions and 20 deletions
|
@ -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<Integer, Color>() {
|
||||
@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<Integer, Color>() {
|
||||
@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();
|
||||
}
|
||||
|
|
|
@ -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<UUID, String>() {
|
||||
@Override
|
||||
public void handle(UUID value1, String value2) {
|
||||
List<PlayerSettings> 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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue