1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package nl.tudelft.goal.visualizer.gui;
18
19 import java.awt.BorderLayout;
20 import java.awt.FlowLayout;
21 import java.awt.GridLayout;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.awt.event.KeyEvent;
25
26 import javax.swing.JFrame;
27 import javax.swing.JMenu;
28 import javax.swing.JMenuBar;
29 import javax.swing.JMenuItem;
30 import javax.swing.JOptionPane;
31 import javax.swing.JPanel;
32 import javax.swing.SwingUtilities;
33
34 import nl.tudelft.goal.unreal.util.vecmathcheck.VecmathCheck;
35 import nl.tudelft.goal.ut2004.visualizer.controller.ServerController;
36 import nl.tudelft.goal.ut2004.visualizer.gui.action.PauseResumeAction;
37 import nl.tudelft.goal.ut2004.visualizer.gui.action.ShowDialogueAction;
38 import nl.tudelft.goal.ut2004.visualizer.gui.action.ShowServerDependentDialogueAction;
39 import nl.tudelft.goal.ut2004.visualizer.gui.action.ShowServerEnvironmentDependentDialogueAction;
40 import nl.tudelft.goal.ut2004.visualizer.gui.dialogs.AddNativeBotDialog;
41 import nl.tudelft.goal.ut2004.visualizer.gui.dialogs.AddUnrealGoalBotDialog;
42 import nl.tudelft.goal.ut2004.visualizer.gui.dialogs.ChangeGameSpeedDialog;
43 import nl.tudelft.goal.ut2004.visualizer.gui.dialogs.ChangeMapDialog;
44 import nl.tudelft.goal.ut2004.visualizer.gui.dialogs.ListEnvironmentsDialog;
45 import nl.tudelft.goal.ut2004.visualizer.gui.dialogs.ListPlayerDialog;
46 import nl.tudelft.goal.ut2004.visualizer.gui.dialogs.ServerConnectionDialog;
47 import nl.tudelft.goal.ut2004.visualizer.gui.dialogs.SettingsDialog;
48 import nl.tudelft.goal.visualizer.gui.panels.MapPanel;
49 import nl.tudelft.goal.ut2004.visualizer.util.WindowPersistenceHelper;
50 import nl.tudelft.pogamut.base.server.ReconnectingServerDefinition;
51 import nl.tudelft.pogamut.base.server.ServerDefinition;
52 import cz.cuni.amis.pogamut.ut2004.server.IUT2004Server;
53 import java.awt.Dimension;
54 import java.awt.event.ComponentEvent;
55 import java.net.URI;
56 import java.net.URISyntaxException;
57 import java.util.logging.Level;
58 import java.util.logging.Logger;
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 public class UnrealVisualizerGUI extends JFrame {
74
75
76
77
78 private static final int WINDOW_WIDTH = 800;
79
80
81
82 private static final int WINDOW_HEIGHT = 600;
83
84
85
86
87 private final MapPanel mapPanel;
88
89
90
91
92 private WindowPersistenceHelper persistenceHelper;
93
94 public UnrealVisualizerGUI() {
95 super();
96
97
98 ServerController.createNewController();
99 ServerController controller = ServerController.getInstance();
100 ServerDefinition<IUT2004Server> serverDefinition = controller
101 .getServerDefinition();
102
103
104 setTitle("Unreal Tournament Visualizer for GOAL");
105 setResizable(true);
106 setLayout(new BorderLayout());
107 setDefaultCloseOperation(EXIT_ON_CLOSE);
108
109
110 persistenceHelper = new WindowPersistenceHelper(this);
111 persistenceHelper.load();
112
113
114 setupMenuBar();
115
116
117 mapPanel = new MapPanel();
118
119
120 JPanel mainPanel = new JPanel(new GridLayout(1, 1));
121 mainPanel.add(mapPanel);
122 add(mainPanel);
123 }
124
125 @Override
126 public Dimension getPreferredSize() {
127 return new Dimension(WINDOW_WIDTH, WINDOW_HEIGHT);
128 }
129
130
131
132
133
134 private void setupMenuBar() {
135
136 JMenuBar menuBar = new JMenuBar();
137 menuBar.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
138 setJMenuBar(menuBar);
139
140
141
142 JMenu applicationMenu = new JMenu("Visualizer");
143 {
144
145 SettingsDialog settingsDialogue = new SettingsDialog(this);
146 String name = "Settings";
147 String description = "Change the settings of the visualizer.";
148 ShowDialogueAction showSettings = new ShowDialogueAction(settingsDialogue, name, description);
149 JMenuItem settings = new JMenuItem(showSettings);
150 applicationMenu.add(settings);
151
152
153 JMenuItem exitVis = new JMenuItem("Exit", KeyEvent.VK_E);
154 exitVis.setToolTipText("Exit the Visualizer");
155 exitVis.addActionListener(new ActionListener() {
156 @Override
157 public void actionPerformed(ActionEvent e) {
158
159 dispose();
160 System.exit(0);
161 }
162 });
163 applicationMenu.add(exitVis);
164
165
166 }
167 menuBar.add(applicationMenu);
168
169
170 JMenu server = new JMenu("Server");
171 {
172 {
173 ServerController controller = ServerController.getInstance();
174 ServerDefinition<IUT2004Server> serverDefinition = controller
175 .getServerDefinition();
176 ServerConnectionDialog connectionDialog = new ServerConnectionDialog(
177 this, (ReconnectingServerDefinition) serverDefinition);
178 String name = "Connection";
179 String description = "Connect to an Unreal Tournament Server.";
180 ShowDialogueAction action = new ShowDialogueAction(
181 connectionDialog, name, description);
182 JMenuItem connect = new JMenuItem(action);
183 server.add(connect);
184 }
185
186 JMenuItem pauseResume = new JMenuItem(new PauseResumeAction());
187 server.add(pauseResume);
188 {
189 ChangeGameSpeedDialog gameSpeedDialog = new ChangeGameSpeedDialog(
190 this);
191 String name = "Game Speed";
192 String description = "Change the speed of the game.";
193 ShowServerDependentDialogueAction action = new ShowServerDependentDialogueAction(
194 gameSpeedDialog, name, description);
195 JMenuItem speed = new JMenuItem(action);
196 server.add(speed);
197 }
198
199 {
200 ChangeMapDialog changeMapDialog = new ChangeMapDialog(this);
201 String name = "Change Map";
202 String description = "Change the current map.";
203 ShowServerDependentDialogueAction action = new ShowServerDependentDialogueAction(
204 changeMapDialog, name, description);
205 JMenuItem change = new JMenuItem(action);
206 server.add(change);
207 }
208 {
209 AddNativeBotDialog addNativeBotDialog = new AddNativeBotDialog(
210 this, null);
211 String name = "Add Native Bot";
212 String description = "Adds a native unreal bot to the game.";
213 ShowServerDependentDialogueAction action = new ShowServerDependentDialogueAction(
214 addNativeBotDialog, name, description);
215 JMenuItem add = new JMenuItem(action);
216 server.add(add);
217 }
218 {
219 AddUnrealGoalBotDialog addUnrealGoalBotDialog = new AddUnrealGoalBotDialog(
220 this, null);
221 String name = "Add UnrealGoal Bot";
222 String description = "Adds an UnrealGoal bot to the game.";
223 ShowServerEnvironmentDependentDialogueAction action = new ShowServerEnvironmentDependentDialogueAction(
224 addUnrealGoalBotDialog, name, description);
225 JMenuItem add = new JMenuItem(action);
226 server.add(add);
227 }
228 {
229 ListPlayerDialog listPlayerDialog = new ListPlayerDialog(this);
230 String name = "List Players";
231 String description = "Lists all player in the game.";
232 ShowServerDependentDialogueAction action = new ShowServerDependentDialogueAction(
233 listPlayerDialog, name, description);
234 JMenuItem add = new JMenuItem(action);
235 server.add(add);
236 }
237 }
238
239 menuBar.add(server);
240
241 JMenu environments = new JMenu("Environments");
242 {
243 String name = "List Environments";
244 String description = "List Goal Environments connected to the visualizier.";
245 ListEnvironmentsDialog listDialog = new ListEnvironmentsDialog(this);
246 ShowDialogueAction action = new ShowDialogueAction(listDialog,
247 name, description);
248 JMenuItem list = new JMenuItem(action);
249
250 environments.add(list);
251 }
252 menuBar.add(environments);
253
254 }
255
256
257
258
259
260 @Override
261 public void dispose() {
262 super.dispose();
263
264
265
266 ServerController.disposeController();
267 }
268
269
270
271
272
273
274
275 public static void main(String[] args) {
276
277 if (!VecmathCheck.check()) {
278 JOptionPane.showMessageDialog(null, VecmathCheck.getErrorMessage(),"Version Conflict",JOptionPane.ERROR_MESSAGE);
279
280 return;
281 }
282
283
284 SwingUtilities.invokeLater(new Runnable() {
285
286 @Override
287 public void run() {
288 UnrealVisualizerGUI vizualiser = new UnrealVisualizerGUI();
289 vizualiser.setVisible(true);
290 }
291 });
292 }
293
294 }