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