blob: d1afad4d7f831ea4825101455b6fa8cd546c7c09 (
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
// TODO: package
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class GameWindow extends JFrame implements ActionListener {
public static final Dimension WINDOW_SIZE = new Dimension(600, 400);
private JPanel menu;
// TODO: remove map editor, start directly on Battle mode
public GameWindow() {
super("Subconscious");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(WINDOW_SIZE);
this.setPreferredSize(WINDOW_SIZE);
this.setLocationRelativeTo(null);
JPanel menu = new JPanel();
menu.setLayout(new GridLayout(3, 1));
JButton editor = new JButton("Editor");
editor.setActionCommand("btn-editor");
JButton battle = new JButton("Battle");
battle.setActionCommand("btn-battle");
JButton exit = new JButton("Exit");
exit.setActionCommand("btn-exit");
editor.addActionListener(this);
battle.addActionListener(this);
exit.addActionListener(this);
menu.add(editor);
menu.add(battle);
menu.add(exit);
this.menu = menu;
this.add(this.menu);
this.pack();
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().startsWith("btn")) {
if (e.getActionCommand().equals("btn-exit")) {
this.setVisible(false);
this.dispose();
return;
}
Scene scene = null;
if (e.getActionCommand().equals("btn-editor")) {
scene = new MapEditorScene();
} else if (e.getActionCommand().equals("btn-battle")) {
scene = new BattleScene();
}
if (scene == null) {
return;
}
this.getContentPane().removeAll();
this.getContentPane().invalidate();
this.getContentPane().add(scene);
this.getContentPane().revalidate();
scene.updateCanvasSize();
Thread sceneThread = new Thread(scene);
sceneThread.start();
}
}
public void backToMenu() {
this.getContentPane().removeAll();
this.getContentPane().invalidate();
this.getContentPane().add(this.menu);
this.getContentPane().revalidate();
}
}
|