2011-05-27 15:00:28 +02:00
|
|
|
package jrummikub.control;
|
|
|
|
|
2011-05-27 17:54:46 +02:00
|
|
|
import java.awt.Color;
|
|
|
|
|
2011-05-27 15:00:28 +02:00
|
|
|
import jrummikub.model.GameSettings;
|
2011-05-27 17:54:46 +02:00
|
|
|
import jrummikub.model.PlayerSettings;
|
2011-05-27 15:00:28 +02:00
|
|
|
import jrummikub.util.Event1;
|
|
|
|
import jrummikub.util.IEvent1;
|
2011-05-27 17:54:46 +02:00
|
|
|
import jrummikub.util.IListener;
|
2011-05-27 15:00:28 +02:00
|
|
|
import jrummikub.util.IListener1;
|
|
|
|
import jrummikub.view.IView;
|
|
|
|
|
|
|
|
public class SettingsControl {
|
|
|
|
private IView view;
|
|
|
|
private Event1<GameSettings> startGameEvent = new Event1<GameSettings>();
|
|
|
|
|
|
|
|
public SettingsControl(IView view) {
|
|
|
|
this.view = view;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEvent1<GameSettings> getStartGameEvent() {
|
|
|
|
return startGameEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startSettings() {
|
|
|
|
/*
|
|
|
|
* view.getSettingsPanel().getSettingsChangeEvent() .add(new
|
|
|
|
* IListener1<GameSettings>() {
|
|
|
|
*
|
|
|
|
* @Override public void handle(GameSettings settings) {
|
|
|
|
* checkSettings(settings); } });
|
|
|
|
* view.getSettingsPanel().getStartGameEvent() .add(new
|
|
|
|
* IListener1<GameSettings>() {
|
|
|
|
*
|
|
|
|
* @Override public void handle(GameSettings settings) {
|
|
|
|
* startGame(settings); } });
|
|
|
|
*/
|
2011-05-27 17:54:46 +02:00
|
|
|
// TODO vvv this is just a temp. fix
|
|
|
|
view.getSettingsPanel().getStartGameEvent().add(new IListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handle() {
|
|
|
|
GameSettings defaultSettings = new GameSettings();
|
|
|
|
defaultSettings.getPlayerList().add(new PlayerSettings("Foo", new Color(1.0f, 0, 0)));
|
|
|
|
defaultSettings.getPlayerList().add(new PlayerSettings("Bar", new Color(0, 1.0f, 0)));
|
|
|
|
startGame(defaultSettings);
|
|
|
|
}
|
|
|
|
});
|
2011-05-27 15:00:28 +02:00
|
|
|
view.showSettingsPanel(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean checkSettings(GameSettings settings) {
|
|
|
|
// TODO Check
|
|
|
|
// TODO Show error
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void startGame(GameSettings settings) {
|
|
|
|
if (!checkSettings(settings)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
view.showSettingsPanel(false);
|
|
|
|
|
|
|
|
startGameEvent.emit(settings);
|
|
|
|
}
|
|
|
|
}
|