summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub')
-rw-r--r--src/jrummikub/control/ApplicationControl.java10
-rw-r--r--src/jrummikub/control/network/ConnectionControl.java4
-rw-r--r--src/jrummikub/control/network/GameJoinControl.java19
-rw-r--r--src/jrummikub/control/network/GameOfferControl.java5
-rw-r--r--src/jrummikub/control/network/NetworkControl.java7
-rw-r--r--src/jrummikub/util/Event1.java2
-rw-r--r--src/jrummikub/util/Event2.java2
-rw-r--r--src/jrummikub/util/Event3.java2
8 files changed, 31 insertions, 20 deletions
diff --git a/src/jrummikub/control/ApplicationControl.java b/src/jrummikub/control/ApplicationControl.java
index 85fb663..3e429d2 100644
--- a/src/jrummikub/control/ApplicationControl.java
+++ b/src/jrummikub/control/ApplicationControl.java
@@ -70,14 +70,8 @@ public class ApplicationControl {
view.getNetworkGameEvent().add(new IListener() {
@Override
public void handle() {
- if (settingsControl != null) {
- settingsControl.abort();
- }
-
- if (gameControl != null) {
- gameControl.abortGame();
- }
-
+ abortControls();
+
loginControl = new LoginControl(view);
loginControl.getLoginEvent().add(new IListener1<LoginData>() {
@Override
diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java
index 6dc1bb5..57e0cc6 100644
--- a/src/jrummikub/control/network/ConnectionControl.java
+++ b/src/jrummikub/control/network/ConnectionControl.java
@@ -125,8 +125,8 @@ class ConnectionControl {
void withdrawGame() {
offeredGame = null;
- currentGame = null;
final UUID uuid = currentGame.getGameID();
+ currentGame = null;
new Thread(new SendRunner() {
@Override
public Message send() {
@@ -137,7 +137,7 @@ class ConnectionControl {
return createMessage(extension);
}
- });
+ }).start();
}
GameData getCurrentGame() {
diff --git a/src/jrummikub/control/network/GameJoinControl.java b/src/jrummikub/control/network/GameJoinControl.java
index 1d29df4..d4a31d3 100644
--- a/src/jrummikub/control/network/GameJoinControl.java
+++ b/src/jrummikub/control/network/GameJoinControl.java
@@ -1,5 +1,7 @@
package jrummikub.control.network;
+import java.util.UUID;
+
import jrummikub.model.GameSettings;
import jrummikub.model.PlayerSettings;
import jrummikub.model.PlayerSettings.Type;
@@ -10,7 +12,6 @@ import jrummikub.view.ISettingsPanel.SettingsMode;
import jrummikub.view.IView;
public class GameJoinControl extends AbstractGameBeginControl {
- private Event backEvent = new Event();
public GameJoinControl(final ConnectionControl connectionControl,
final GameData gameData, final IView view) {
@@ -31,6 +32,16 @@ public class GameJoinControl extends AbstractGameBeginControl {
}
}
}));
+ connections.add(connectionControl.getGameWithdrawalEvent().add(
+ new IListener1<UUID>() {
+ @Override
+ public void handle(UUID uuid) {
+ if (uuid.equals(gameData.getGameID())) {
+ abort();
+ backEvent.emit();
+ }
+ }
+ }));
}
private void fixGameSettings(GameSettings settings) {
@@ -44,10 +55,6 @@ public class GameJoinControl extends AbstractGameBeginControl {
}
}
- public Event getBackEvent() {
- return backEvent;
- }
-
public void startGameJoin() {
view.showSettingsPanel(true);
}
@@ -55,10 +62,10 @@ public class GameJoinControl extends AbstractGameBeginControl {
/**
* Aborts joining and goes back to game list
*/
+ @Override
protected void goBack() {
abort();
connectionControl.leaveGame();
- view.showSettingsPanel(false);
backEvent.emit();
}
diff --git a/src/jrummikub/control/network/GameOfferControl.java b/src/jrummikub/control/network/GameOfferControl.java
index f09eb6e..7e3241f 100644
--- a/src/jrummikub/control/network/GameOfferControl.java
+++ b/src/jrummikub/control/network/GameOfferControl.java
@@ -64,7 +64,10 @@ public class GameOfferControl extends AbstractGameBeginControl {
}
+ @Override
protected void goBack() {
- // TODO
+ abort();
+ connectionControl.withdrawGame();
+ backEvent.emit();
}
}
diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java
index 0e8381b..0a7ea8d 100644
--- a/src/jrummikub/control/network/NetworkControl.java
+++ b/src/jrummikub/control/network/NetworkControl.java
@@ -243,6 +243,13 @@ public class NetworkControl {
return;
}
gameOfferControl = new GameOfferControl(connectionControl, settings, view);
+ gameOfferControl.getBackEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ gameOfferControl=null;
+ view.showGameListPanel(true);
+ }
+ });
gameOfferControl.startGameOffer();
}
diff --git a/src/jrummikub/util/Event1.java b/src/jrummikub/util/Event1.java
index 5e3391c..f93d519 100644
--- a/src/jrummikub/util/Event1.java
+++ b/src/jrummikub/util/Event1.java
@@ -35,7 +35,7 @@ public class Event1<T> implements IEvent1<T> {
* the event parameter
*/
public void emit(T value) {
- for (IListener1<T> listener : listeners) {
+ for (IListener1<T> listener : new HashSet<IListener1<T>>(listeners)) {
listener.handle(value);
}
}
diff --git a/src/jrummikub/util/Event2.java b/src/jrummikub/util/Event2.java
index 9bcee43..139f19f 100644
--- a/src/jrummikub/util/Event2.java
+++ b/src/jrummikub/util/Event2.java
@@ -39,7 +39,7 @@ public class Event2<T1, T2> implements IEvent2<T1, T2> {
* the second event parameter
*/
public void emit(T1 value1, T2 value2) {
- for (IListener2<T1, T2> listener : listeners) {
+ for (IListener2<T1, T2> listener : new HashSet<IListener2<T1, T2>>(listeners)) {
listener.handle(value1, value2);
}
}
diff --git a/src/jrummikub/util/Event3.java b/src/jrummikub/util/Event3.java
index 38cdd07..9510e48 100644
--- a/src/jrummikub/util/Event3.java
+++ b/src/jrummikub/util/Event3.java
@@ -43,7 +43,7 @@ public class Event3<T1, T2, T3> implements IEvent3<T1, T2, T3> {
* the third event parameter
*/
public void emit(T1 value1, T2 value2, T3 value3) {
- for (IListener3<T1, T2, T3> listener : listeners) {
+ for (IListener3<T1, T2, T3> listener : new HashSet<IListener3<T1, T2, T3>>(listeners)) {
listener.handle(value1, value2, value3);
}
}