summaryrefslogtreecommitdiffstats
path: root/src/GameWindow.java
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-11-19 10:27:15 +0100
committerNao Pross <naopross@thearcway.org>2018-11-19 10:27:15 +0100
commit7a7007571699eb57bc96cef4cd053a5bd50468b3 (patch)
tree14b879b399417a59a340c6fda9daf4719a3dbebf /src/GameWindow.java
parentAdd Actor.SkillSet, remove useless members in various strucutres (diff)
downloadSubconscious-java-7a7007571699eb57bc96cef4cd053a5bd50468b3.tar.gz
Subconscious-java-7a7007571699eb57bc96cef4cd053a5bd50468b3.zip
Update Scene class (and some derivates) to be abstract
Diffstat (limited to 'src/GameWindow.java')
-rw-r--r--src/GameWindow.java89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/GameWindow.java b/src/GameWindow.java
new file mode 100644
index 0000000..540d75b
--- /dev/null
+++ b/src/GameWindow.java
@@ -0,0 +1,89 @@
+// 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 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");
+
+ this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ this.frame.setSize(WINDOW_SIZE);
+ this.frame.setPreferredSize(WINDOW_SIZE);
+ this.frame.setLocationRelativeTo(null);
+
+ JPanel menu = new JPanel();
+ menu.setLayout(new GridLayout(3, 1));
+ JButton editor = new JButton("Editor");
+ editor.setActionCommand("editor");
+ JButton battle = new JButton("Battle");
+ battle.setActionCommand("battle");
+ JButton exit = new JButton("Exit");
+ exit.setActionCommand("exit");
+
+ editor.addActionListener(this);
+ battle.addActionListener(this);
+ exit.addActionListener(this);
+
+ menu.add(editor);
+ menu.add(battle);
+ menu.add(exit);
+
+ this.menu = menu;
+
+ this.frame.add(this.menu);
+ this.frame.pack();
+
+ this.frame.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();
+ }
+ }
+
+ public void backToMenu() {
+ this.frame.getContentPane().removeAll();
+ this.frame.getContentPane().invalidate();
+ this.frame.getContentPane().add(this.menu);
+ this.frame.getContentPane().revalidate();
+ }
+}