aboutsummaryrefslogtreecommitdiff
path: root/src/esieequest/ui/rich
diff options
context:
space:
mode:
Diffstat (limited to 'src/esieequest/ui/rich')
-rw-r--r--src/esieequest/ui/rich/Applet.java28
-rw-r--r--src/esieequest/ui/rich/UserInterface.java698
-rw-r--r--src/esieequest/ui/rich/Window.java32
-rw-r--r--src/esieequest/ui/rich/package-info.java5
4 files changed, 763 insertions, 0 deletions
diff --git a/src/esieequest/ui/rich/Applet.java b/src/esieequest/ui/rich/Applet.java
new file mode 100644
index 0000000..1137182
--- /dev/null
+++ b/src/esieequest/ui/rich/Applet.java
@@ -0,0 +1,28 @@
1package esieequest.ui.rich;
2
3import javax.swing.JApplet;
4
5/**
6 * The applet view.
7 *
8 * @author Pacien TRAN-GIRARD
9 */
10public class Applet extends UserInterface {
11
12 private final JApplet applet;
13
14 /**
15 * The constructor.
16 *
17 * @param applet
18 * the JApplet
19 */
20 public Applet(final JApplet applet) {
21 this.applet = applet;
22 }
23
24 @Override
25 public void show() {
26 this.applet.add(this.getLayout());
27 }
28}
diff --git a/src/esieequest/ui/rich/UserInterface.java b/src/esieequest/ui/rich/UserInterface.java
new file mode 100644
index 0000000..6d4c3d4
--- /dev/null
+++ b/src/esieequest/ui/rich/UserInterface.java
@@ -0,0 +1,698 @@
1package esieequest.ui.rich;
2
3import java.awt.BorderLayout;
4import java.awt.Dimension;
5import java.awt.Font;
6import java.awt.Graphics;
7import java.awt.GridLayout;
8import java.awt.Image;
9import java.awt.event.ActionEvent;
10import java.awt.event.ActionListener;
11import java.awt.event.FocusEvent;
12import java.awt.event.FocusListener;
13import java.awt.event.KeyEvent;
14import java.awt.image.BufferedImage;
15import java.io.FileWriter;
16import java.io.IOException;
17import java.net.URL;
18import java.nio.file.Files;
19import java.nio.file.Path;
20import java.nio.file.Paths;
21import java.util.HashMap;
22import java.util.Map.Entry;
23import java.util.Timer;
24import java.util.TimerTask;
25
26import javax.swing.AbstractAction;
27import javax.swing.JButton;
28import javax.swing.JComponent;
29import javax.swing.JFileChooser;
30import javax.swing.JLabel;
31import javax.swing.JPanel;
32import javax.swing.JTextField;
33import javax.swing.JTextPane;
34import javax.swing.KeyStroke;
35import javax.swing.border.EmptyBorder;
36import javax.swing.filechooser.FileNameExtensionFilter;
37
38import lombok.Getter;
39
40import org.newdawn.easyogg.OggClip;
41
42import com.wordpress.tipsforjava.swing.StretchIcon;
43
44import esieequest.engine.GameEngine;
45import esieequest.engine.commands.Command;
46import esieequest.game.Text;
47import esieequest.game.items.Inventory;
48import esieequest.game.items.Item;
49import esieequest.game.map.Direction;
50import esieequest.game.map.Orientation;
51import esieequest.game.map.Room;
52import esieequest.game.map.Side;
53import esieequest.game.states.Quest;
54import esieequest.game.states.Scene;
55import esieequest.ui.Viewable;
56
57/**
58 * The Swing based graphical user interface.
59 *
60 * @author Pacien TRAN-GIRARD
61 * @author BenoƮt LUBRANO DI SBARAGLIONE
62 */
63abstract class UserInterface implements Viewable, ActionListener {
64
65 private static final String ILLUSTRATION_DIR = "resources/images/";
66 private static final String ILLUSTRATION_EXT = ".png";
67
68 private static final String SOUND_DIR = "resources/audio/";
69 private static final String SOUND_EXT = ".ogg";
70
71 private static final String SAVE_LABEL = "ESIEEquest Game";
72 private static final String SAVE_EXT = "eqg";
73
74 private GameEngine gameEngine;
75
76 @Getter
77 private JPanel layout;
78
79 private JTextPane questTextPane;
80
81 private JLabel imageLabel;
82
83 private JPanel menuPanel;
84 private JPanel questPanel;
85 private JPanel gamePanel;
86
87 private JButton newButton;
88 private JButton soundButton;
89 private JPanel filePanel;
90 private JButton loadButton;
91 private JButton saveButton;
92
93 private JPanel imagePanel;
94
95 private JPanel userPanel;
96 private JPanel dispPanel;
97
98 private JPanel consolePanel;
99 private JPanel inventoryPanel;
100
101 private JPanel controlPanel;
102 private JPanel topControlPanel;
103 private JPanel bottomControlPanel;
104
105 private JTextPane infoTextPane;
106 private JTextField inputField;
107
108 private JButton forwardButton;
109 private JButton inventoryButton;
110 private JButton actionButton;
111 private JButton backButton;
112 private JButton leftButton;
113 private JButton rightButton;
114
115 private Timer timer;
116 private TimerTask timerTask;
117 private boolean scenePlaying;
118
119 private OggClip audio;
120 private boolean muted;
121
122 /**
123 * The default constructor.
124 */
125 public UserInterface() {
126 this.buildUI();
127 this.setActionListener(this);
128 this.bindKeys();
129 this.bindFocus();
130 this.setControlsState(false);
131 this.muted = false;
132 }
133
134 /**
135 * Creates the interface widgets.
136 */
137 private void buildUI() {
138
139 // main window
140 this.layout = new JPanel();
141 this.layout.setLayout(new BorderLayout(0, 0));
142
143 // top bar
144 this.menuPanel = new JPanel();
145 this.layout.add(this.menuPanel, BorderLayout.NORTH);
146 this.menuPanel.setLayout(new BorderLayout(0, 0));
147
148 this.questPanel = new JPanel();
149 this.menuPanel.add(this.questPanel, BorderLayout.CENTER);
150
151 this.questTextPane = new JTextPane();
152 this.questTextPane.setEditable(false);
153 this.questTextPane.setText(Text.DEFAULT_QUEST_TITLE.toString());
154 this.questPanel.add(this.questTextPane);
155
156 this.gamePanel = new JPanel();
157 this.menuPanel.add(this.gamePanel, BorderLayout.WEST);
158
159 this.newButton = new JButton(Text.NEW_GAME_BUTTON.toString());
160 this.newButton.setToolTipText(Text.NEW_GAME_TOOLTIP.toString());
161 this.newButton.setActionCommand(Command.NEW.name());
162 this.gamePanel.add(this.newButton);
163
164 this.soundButton = new JButton(Text.TOGGLE_SOUND_BUTTON.toString());
165 this.soundButton.setToolTipText(Text.TOGGLE_SOUND_TOOLTIP.toString());
166 this.soundButton.setActionCommand(Command.SOUND.name());
167 this.gamePanel.add(this.soundButton);
168
169 this.filePanel = new JPanel();
170 this.menuPanel.add(this.filePanel, BorderLayout.EAST);
171
172 this.loadButton = new JButton(Text.LOAD_GAME_BUTTON.toString());
173 this.loadButton.setToolTipText(Text.LOAD_GAME_TOOLTIP.toString());
174 this.loadButton.setActionCommand(Command.LOAD.name());
175 this.filePanel.add(this.loadButton);
176
177 this.saveButton = new JButton(Text.SAVE_GAME_BUTTON.toString());
178 this.saveButton.setToolTipText(Text.SAVE_GAME_TOOLTIP.toString());
179 this.saveButton.setActionCommand(Command.SAVE.name());
180 this.filePanel.add(this.saveButton);
181
182 // central illustration panel
183 this.imagePanel = new JPanel();
184 this.layout.add(this.imagePanel, BorderLayout.CENTER);
185 this.imagePanel.setLayout(new BorderLayout(0, 0));
186
187 this.imageLabel = new JLabel();
188 this.imagePanel.add(this.imageLabel);
189
190 // bottom panel
191 this.userPanel = new JPanel();
192 this.layout.add(this.userPanel, BorderLayout.SOUTH);
193 this.userPanel.setLayout(new BorderLayout(0, 0));