summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jrummikub/control/network/GameJoinControl.java48
-rw-r--r--src/jrummikub/control/network/GameOfferControl.java29
-rw-r--r--src/jrummikub/control/network/NetworkControl.java8
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<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();
}
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<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) {
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();
}