diff options
Diffstat (limited to 'src/esieequest/ui/rich')
-rw-r--r-- | src/esieequest/ui/rich/Applet.java | 28 | ||||
-rw-r--r-- | src/esieequest/ui/rich/UserInterface.java | 698 | ||||
-rw-r--r-- | src/esieequest/ui/rich/Window.java | 32 | ||||
-rw-r--r-- | src/esieequest/ui/rich/package-info.java | 5 |
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 @@ | |||
1 | package esieequest.ui.rich; | ||
2 | |||
3 | import javax.swing.JApplet; | ||
4 | |||
5 | /** | ||
6 | * The applet view. | ||
7 | * | ||
8 | * @author Pacien TRAN-GIRARD | ||
9 | */ | ||
10 | public 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 @@ | |||
1 | package esieequest.ui.rich; | ||
2 | |||
3 | import java.awt.BorderLayout; | ||
4 | import java.awt.Dimension; | ||
5 | import java.awt.Font; | ||
6 | import java.awt.Graphics; | ||
7 | import java.awt.GridLayout; | ||
8 | import java.awt.Image; | ||
9 | import java.awt.event.ActionEvent; | ||
10 | import java.awt.event.ActionListener; | ||
11 | import java.awt.event.FocusEvent; | ||
12 | import java.awt.event.FocusListener; | ||
13 | import java.awt.event.KeyEvent; | ||
14 | import java.awt.image.BufferedImage; | ||
15 | import java.io.FileWriter; | ||
16 | import java.io.IOException; | ||
17 | import java.net.URL; | ||
18 | import java.nio.file.Files; | ||
19 | import java.nio.file.Path; | ||
20 | import java.nio.file.Paths; | ||
21 | import java.util.HashMap; | ||
22 | import java.util.Map.Entry; | ||
23 | import java.util.Timer; | ||
24 | import java.util.TimerTask; | ||
25 | |||
26 | import javax.swing.AbstractAction; | ||
27 | import javax.swing.JButton; | ||
28 | import javax.swing.JComponent; | ||
29 | import javax.swing.JFileChooser; | ||
30 | import javax.swing.JLabel; | ||
31 | import javax.swing.JPanel; | ||
32 | import javax.swing.JTextField; | ||
33 | import javax.swing.JTextPane; | ||
34 | import javax.swing.KeyStroke; | ||
35 | import javax.swing.border.EmptyBorder; | ||
36 | import javax.swing.filechooser.FileNameExtensionFilter; | ||
37 | |||
38 | import lombok.Getter; | ||
39 | |||
40 | import org.newdawn.easyogg.OggClip; | ||
41 | |||
42 | import com.wordpress.tipsforjava.swing.StretchIcon; | ||
43 | |||
44 | import esieequest.engine.GameEngine; | ||
45 | import esieequest.engine.commands.Command; | ||
46 | import esieequest.game.Text; | ||
47 | import esieequest.game.items.Inventory; | ||
48 | import esieequest.game.items.Item; | ||
49 | import esieequest.game.map.Direction; | ||
50 | import esieequest.game.map.Orientation; | ||
51 | import esieequest.game.map.Room; | ||
52 | import esieequest.game.map.Side; | ||
53 | import esieequest.game.states.Quest; | ||
54 | import esieequest.game.states.Scene; | ||
55 | import 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 | */ | ||
63 | abstract 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)); | ||