Added missing file
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@458 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
a77a87994f
commit
a61bca2c60
1 changed files with 108 additions and 0 deletions
108
src/jrummikub/control/network/AbstractGameBeginControl.java
Normal file
108
src/jrummikub/control/network/AbstractGameBeginControl.java
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
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 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.IListener2;
|
||||||
|
import jrummikub.view.ISettingsPanel;
|
||||||
|
import jrummikub.view.ISettingsPanel.SettingsMode;
|
||||||
|
import jrummikub.view.IView;
|
||||||
|
|
||||||
|
public abstract class AbstractGameBeginControl {
|
||||||
|
protected List<Connection> connections = new ArrayList<Connection>();
|
||||||
|
protected GameData gameData;
|
||||||
|
protected ConnectionControl connectionControl;
|
||||||
|
protected IView view;
|
||||||
|
protected Event backEvent = new Event();
|
||||||
|
|
||||||
|
public AbstractGameBeginControl(ConnectionControl connection, IView view,
|
||||||
|
final GameData gameData, SettingsMode settingsMode) {
|
||||||
|
this.connectionControl = connection;
|
||||||
|
this.view = view;
|
||||||
|
this.gameData = gameData;
|
||||||
|
|
||||||
|
view.getSettingsPanel().setSettingsMode(settingsMode);
|
||||||
|
view.getSettingsPanel().enableAddPlayerButton(false);
|
||||||
|
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 i, Color color) {
|
||||||
|
for (PlayerSettings player : gameData.getGameSettings()
|
||||||
|
.getPlayerList()) {
|
||||||
|
if (player.getColor() == color) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PlayerSettings player = gameData.getGameSettings()
|
||||||
|
.getPlayerList().get(i);
|
||||||
|
if (player.getType() != Type.HUMAN) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.setColor(color);
|
||||||
|
connectionControl.changeColor(color);
|
||||||
|
updateSettingsPanel();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
connections.add(connectionControl.getChangeColorEvent().add(
|
||||||
|
new IListener2<String, Color>() {
|
||||||
|
@Override
|
||||||
|
public void handle(String sender, Color color) {
|
||||||
|
List<PlayerSettings> players = gameData
|
||||||
|
.getGameSettings().getPlayerList();
|
||||||
|
for (PlayerSettings s : players) {
|
||||||
|
if (s.getName().equals(sender)
|
||||||
|
&& s.getType() == Type.NETWORK) {
|
||||||
|
s.setColor(color);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateSettingsPanel();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void goBack();
|
||||||
|
|
||||||
|
public Event getBackEvent() {
|
||||||
|
return backEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void abort() {
|
||||||
|
view.showSettingsPanel(false);
|
||||||
|
for (Connection c : connections) {
|
||||||
|
c.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateSettingsPanel() {
|
||||||
|
view.getSettingsPanel().setGameSettings(gameData.getGameSettings());
|
||||||
|
|
||||||
|
Set<Color> colors = new HashSet<Color>(
|
||||||
|
Arrays.asList(ISettingsPanel.PLAYER_COLORS));
|
||||||
|
|
||||||
|
for (PlayerSettings player : gameData.getGameSettings().getPlayerList()) {
|
||||||
|
colors.remove(player.getColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
view.getSettingsPanel().setPlayerColors(colors);
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue