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