Add NetworkSettingsControl

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@409 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-06-11 03:15:12 +02:00
parent 630cdea1d9
commit dbd57d4218
4 changed files with 58 additions and 8 deletions

View file

@ -24,11 +24,11 @@ import jrummikub.view.IView;
* The settings control controls the settings panel * The settings control controls the settings panel
*/ */
public class SettingsControl { public class SettingsControl {
private IView view; protected IView view;
private Event1<GameSettings> startGameEvent = new Event1<GameSettings>(); protected Event1<GameSettings> startGameEvent = new Event1<GameSettings>();
private List<Connection> connections = new ArrayList<Connection>(); private List<Connection> connections = new ArrayList<Connection>();
private GameSettings settings; protected GameSettings settings;
/** /**
* Create a new settings control * Create a new settings control
@ -41,8 +41,6 @@ public class SettingsControl {
public SettingsControl(IView view, GameSettings settings) { public SettingsControl(IView view, GameSettings settings) {
this.view = view; this.view = view;
this.settings = settings; this.settings = settings;
addPlayer();
addPlayer();
} }
/** /**
@ -59,6 +57,9 @@ public class SettingsControl {
* Start the operation of the settings control * Start the operation of the settings control
*/ */
public void startSettings() { public void startSettings() {
addPlayer();
addPlayer();
addPlayerSettingsListeners(); addPlayerSettingsListeners();
addOptionListeners1(); addOptionListeners1();
@ -247,7 +248,7 @@ public class SettingsControl {
update(); update();
} }
private void update() { protected void update() {
view.getSettingsPanel().enableRemovePlayerButtons( view.getSettingsPanel().enableRemovePlayerButtons(
settings.getPlayerList().size() > 2); settings.getPlayerList().size() > 2);
view.getSettingsPanel().enableAddPlayerButton( view.getSettingsPanel().enableAddPlayerButton(

View file

@ -6,6 +6,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import jrummikub.model.GameSettings;
import jrummikub.util.Connection; import jrummikub.util.Connection;
import jrummikub.util.Event; import jrummikub.util.Event;
import jrummikub.util.IEvent; import jrummikub.util.IEvent;
@ -22,6 +23,8 @@ public class NetworkControl {
private List<Connection> connections = new ArrayList<Connection>(); private List<Connection> connections = new ArrayList<Connection>();
private Event stopNetworkEvent = new Event(); private Event stopNetworkEvent = new Event();
private NetworkSettingsControl settingsControl;
private Map<UUID, GameData> gameMap = new HashMap<UUID, GameData>(); private Map<UUID, GameData> gameMap = new HashMap<UUID, GameData>();
public NetworkControl(final LoginData loginData, final IView view) { public NetworkControl(final LoginData loginData, final IView view) {
@ -38,7 +41,6 @@ public class NetworkControl {
testData.setCurrentPlayerCount(2); testData.setCurrentPlayerCount(2);
testData.setMaxPlayerCount(4); testData.setMaxPlayerCount(4);
connectionControl.offerGame(testData);
} }
})); }));
@ -94,8 +96,13 @@ public class NetworkControl {
.add(new IListener() { .add(new IListener() {
@Override @Override
public void handle() { public void handle() {
// TODO Auto-generated method stub if (settingsControl == null) {
view.showGameListPanel(false);
settingsControl = new NetworkSettingsControl(connectionControl,
view, new GameSettings());
settingsControl.startSettings();
}
} }
})); }));

View file

@ -0,0 +1,38 @@
package jrummikub.control.network;
import java.util.UUID;
import jrummikub.control.SettingsControl;
import jrummikub.model.GameSettings;
import jrummikub.view.IGameListPanel.GameData;
import jrummikub.view.IView;
public class NetworkSettingsControl extends SettingsControl {
private GameData gameData = new GameData(UUID.randomUUID());
private ConnectionControl connectionControl;
public NetworkSettingsControl(ConnectionControl connectionControl, IView view, GameSettings settings) {
super(view, settings);
this.connectionControl = connectionControl;
}
@Override
public void startSettings() {
super.startSettings();
}
@Override
protected void update() {
super.update();
gameData.setMaxPlayerCount(settings.getPlayerList().size());
connectionControl.offerGame(gameData);
}
@Override
public void abort() {
super.abort();
connectionControl.withdrawGame(gameData.getGameID());
}
}

View file

@ -12,6 +12,10 @@ public interface IGameListPanel {
private int currentPlayerCount = 0; private int currentPlayerCount = 0;
private int maxPlayerCount = 0; private int maxPlayerCount = 0;
public GameData(UUID gameID) {
this.gameID = gameID;
}
public GameData(UUID gameID, String host) { public GameData(UUID gameID, String host) {
this.gameID = gameID; this.gameID = gameID;
this.host = host; this.host = host;