summaryrefslogtreecommitdiffstats
path: root/src/GameWindow.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/GameWindow.java')
-rw-r--r--src/GameWindow.java87
1 files changed, 44 insertions, 43 deletions
diff --git a/src/GameWindow.java b/src/GameWindow.java
index 540d75b..d1afad4 100644
--- a/src/GameWindow.java
+++ b/src/GameWindow.java
@@ -10,29 +10,28 @@ import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-public class GameWindow implements ActionListener {
+public class GameWindow extends JFrame implements ActionListener {
public static final Dimension WINDOW_SIZE = new Dimension(600, 400);
- private JFrame frame;
private JPanel menu;
// TODO: remove map editor, start directly on Battle mode
public GameWindow() {
- this.frame = new JFrame("Subconscious");
+ super("Subconscious");
- this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.frame.setSize(WINDOW_SIZE);
- this.frame.setPreferredSize(WINDOW_SIZE);
- this.frame.setLocationRelativeTo(null);
+ 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("editor");
+ editor.setActionCommand("btn-editor");
JButton battle = new JButton("Battle");
- battle.setActionCommand("battle");
+ battle.setActionCommand("btn-battle");
JButton exit = new JButton("Exit");
- exit.setActionCommand("exit");
+ exit.setActionCommand("btn-exit");
editor.addActionListener(this);
battle.addActionListener(this);
@@ -44,46 +43,48 @@ public class GameWindow implements ActionListener {
this.menu = menu;
- this.frame.add(this.menu);
- this.frame.pack();
-
- this.frame.setVisible(true);
+ this.add(this.menu);
+ this.pack();
+ this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
- if ("editor".equals(e.getActionCommand())) {
- MapEditor mapEditor = new MapEditor(frame);
-
- this.frame.getContentPane().removeAll();
- this.frame.getContentPane().invalidate();
- this.frame.getContentPane().add(mapEditor);
- this.frame.getContentPane().revalidate();
-
- Thread mapEditorThread = new Thread(mapEditor);
- mapEditorThread.start();
-
- } else if ("battle".equals(e.getActionCommand())) {
- BattleScene battleScene = new BattleScene(frame);
-
- this.frame.getContentPane().removeAll();
- this.frame.getContentPane().invalidate();
- this.frame.getContentPane().add(battleScene);
- this.frame.getContentPane().revalidate();
-
- Thread battleThread = new Thread(battleScene);
- battleThread.start();
-
- } else if ("exit".equals(e.getActionCommand())) {
- this.frame.setVisible(false);
- this.frame.dispose();
+ 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.frame.getContentPane().removeAll();
- this.frame.getContentPane().invalidate();
- this.frame.getContentPane().add(this.menu);
- this.frame.getContentPane().revalidate();
+ this.getContentPane().removeAll();
+ this.getContentPane().invalidate();
+ this.getContentPane().add(this.menu);
+ this.getContentPane().revalidate();
}
}