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