summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/SettingsControl.java
blob: adcc369e0cc959ab9b0339351261e9146eed322d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package jrummikub.control;

import java.awt.Color;

import jrummikub.model.GameSettings;
import jrummikub.model.PlayerSettings;
import jrummikub.util.Event1;
import jrummikub.util.IEvent1;
import jrummikub.util.IListener;
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); } });
		 */
		// 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);
			}
		});
		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);
	}
}