forked from PhilippvK/playforia-minigolf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGolfGameFrame.java
More file actions
295 lines (252 loc) · 11.7 KB
/
GolfGameFrame.java
File metadata and controls
295 lines (252 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
package agolf;
import agolf.game.GamePanel;
import agolf.lobby.LobbyPanel;
import com.aapeli.client.BadWordFilter;
import com.aapeli.client.ImageManager;
import com.aapeli.client.Parameters;
import com.aapeli.client.SoundManager;
import com.aapeli.client.TextManager;
import com.aapeli.frame.AbstractGameFrame;
import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import org.moparforia.client.Launcher;
import org.moparforia.shared.Language;
public class GolfGameFrame extends AbstractGameFrame {
public SynchronizedBool syncIsValidSite;
public static final Color colourGameBackground = new Color(153, 255, 153);
public static final Color colourTextBlack = new Color(0, 0, 0);
public static final Color colourTextDarkGreen = new Color(64, 128, 64);
public static final Color colourTextRed = new Color(128, 0, 0);
public static final Color colourButtonGreen = new Color(144, 224, 144);
public static final Color colourButtonYellow = new Color(224, 224, 144);
public static final Color colourButtonRed = new Color(224, 144, 144);
public static final Color colourButtonBlue = new Color(144, 144, 224);
public static final Font fontSerif26b = new Font("Serif", Font.BOLD, 26);
public static final Font fontSerif20 = new Font("Serif", Font.PLAIN, 20);
public static final Font fontDialog14b = new Font("Dialog", Font.BOLD, 14);
public static final Font fontDialog12 = new Font("Dialog", Font.PLAIN, 12);
public static final Font fontDialog11 = new Font("Dialog", Font.PLAIN, 11);
private GameContainer gameContainer;
private int activePanel;
private SynchronizedBool syncUnknownBool;
private SynchronizedInteger syncPlayerAccessLevel;
private boolean disableGuestChat;
private boolean aBoolean3773;
private Image anImage3774;
private boolean verbose = false;
public GolfGameFrame(
String server, int port, Language language, String username, boolean verbose, boolean norandom) {
super(server, port, language, username, verbose, norandom);
}
public void initGame(Parameters parameters) {
this.syncIsValidSite = new SynchronizedBool(this.isValidSite());
this.setBackground(colourGameBackground);
this.setForeground(colourTextBlack);
this.gameContainer = new GameContainer(this, parameters);
this.aBoolean3773 = false;
}
@Override
public String getCopyrightInfo() {
return "-= AGolf =-\nCopyright (c) 2002-2012 Playforia (www.playforia.info)\nProgramming: Pasi Laaksonen\nGraphics: Janne Matilainen";
}
public void textsLoadedNotify(TextManager textManager) {
this.gameContainer.textManager = textManager;
}
public void defineSounds(SoundManager soundManager) {
this.gameContainer.soundManager = soundManager;
}
public void defineImages(ImageManager imageManager) {
this.gameContainer.imageManager = imageManager;
imageManager.defineImage("bg-lobbyselect.gif");
imageManager.defineImage("bg-lobby-single.gif");
imageManager.defineImage("bg-lobby-single-fade.jpg");
imageManager.defineImage("bg-lobby-dual.gif");
imageManager.defineImage("bg-lobby-multi.gif");
imageManager.defineImage("bg-lobby-multi-fade.jpg");
imageManager.defineImage("bg-lobby-password.gif");
imageManager.defineImage("shapes.gif");
imageManager.defineImage("elements.gif");
imageManager.defineImage("special.gif");
imageManager.defineImage("balls.gif");
imageManager.defineImage("ranking-icons.gif");
imageManager.defineImage("language-flags.png");
imageManager.defineImage("credit-background.jpg");
imageManager.defineImage("tf-background.gif");
}
public void createImages() {
this.gameContainer.spriteManager = new SpriteManager(super.imageManager);
this.gameContainer.spriteManager.loadSprites();
}
public void connectToServer() {
this.gameContainer.connection = new GolfConnection(this.gameContainer);
if (!this.gameContainer.connection.openSocketConnection()) {
this.setEndState(END_ERROR_CONNECTION);
}
}
public void gameReady() {
// this.setGameSettings(false, 0, false, true); // disabled Bad Word Filter!
this.setGameSettings(false, 0, true, true); // enabled Bad Word Filter!
this.gameContainer.trackCollection = new TrackCollection();
this.anImage3774 = this.createImage(735, 375);
this.gameContainer.connection.sendVersion();
}
public void destroyGame() {
this.gameContainer.destroy();
}
public boolean isDebug() {
return verbose;
}
protected int getActivePanel() {
return this.activePanel;
}
public void setGameState(int state) {
this.setGameState(state, 0, 0);
}
protected void setGameState(int state, int lobbyId) {
this.setGameState(state, lobbyId, 0);
}
/**
* @param activePanel 0 == ?, 1 == login, 2 == lobby selection panel, 3 == in lobby, 4 == in
* game
* @param lobbyId game type, single player == 1, dual player == 2, multiplayer == 3
*/
protected void setGameState(int activePanel, int lobbyId, int lobbyExtra) {
if (activePanel != this.activePanel && this.syncIsValidSite.get()) {
this.activePanel = activePanel;
if (this.gameContainer.lobbySelectionPanel != null) {
this.gameContainer.lobbySelectionPanel.destroyNumberOfPlayersFetcher();
}
this.clearContent();
if (activePanel == 1) {
if (this.aBoolean3773) {
super.param.removeSession();
} else {
this.aBoolean3773 = true;
}
// System.out.println(hasSession() + " " +
// gameContainer.synchronizedTrackTestMode.get());
if (Launcher.isUsingCustomServer()) {
String username = param.getUsername();
if (username == null) {
TrackTestLoginPanel loginPanel =
new TrackTestLoginPanel(this, super.contentWidth, super.contentHeight);
loginPanel.setLocation(0, 0);
this.addToContent(loginPanel);
} else {
this.trackTestLogin(username, "");
}
} else if (this.hasSession()) {
this.gameContainer.connection.writeData("login\t" + super.param.getSession());
this.activePanel = 0;
} else if (!this.gameContainer.synchronizedTrackTestMode.get()) {
this.gameContainer.connection.writeData("login");
this.activePanel = 0;
}
}
if (activePanel == 2) {
if (this.gameContainer.lobbySelectionPanel == null) {
this.gameContainer.lobbySelectionPanel =
new LobbySelectPanel(this.gameContainer, super.contentWidth, super.contentHeight);
this.gameContainer.lobbySelectionPanel.setLocation(0, 0);
}
boolean var5 = false;
if (this.gameContainer.defaultLobby != null) {
if (this.gameContainer.defaultLobby.equalsIgnoreCase("singlehidden")) {
var5 = this.gameContainer.lobbySelectionPanel.selectLobby(1, true);
} else if (this.gameContainer.defaultLobby.equalsIgnoreCase("single")) {
var5 = this.gameContainer.lobbySelectionPanel.selectLobby(1, false);
} else if (this.gameContainer.defaultLobby.equalsIgnoreCase("dual")) {
var5 = this.gameContainer.lobbySelectionPanel.selectLobby(2, false);
} else if (this.gameContainer.defaultLobby.equalsIgnoreCase("multi")) {
var5 = this.gameContainer.lobbySelectionPanel.selectLobby(3, false);
}
this.gameContainer.defaultLobby = null;
}
if (!var5) {
this.addToContent(this.gameContainer.lobbySelectionPanel);
this.gameContainer.lobbySelectionPanel.resetNumberOfPlayersFetcher();
}
}
if (activePanel == 3) {
this.gameContainer.gamePanel = null;
if (this.gameContainer.lobbyPanel == null) {
this.gameContainer.lobbyPanel =
new LobbyPanel(this.gameContainer, super.contentWidth, super.contentHeight);
this.gameContainer.lobbyPanel.setLocation(0, 0);
}
if (lobbyId == -1 || lobbyId >= 1) {
this.gameContainer.lobbyPanel.selectLobby(lobbyId, lobbyExtra);
if (lobbyId == 3 && lobbyExtra >= 0) {
this.gameContainer.lobbyPanel.setJoinError(lobbyExtra);
}
}
this.gameContainer.lobbyPanel.init();
this.addToContent(this.gameContainer.lobbyPanel);
}
if (activePanel == 4) {
this.gameContainer.gamePanel =
new GamePanel(this.gameContainer, super.contentWidth, super.contentHeight, this.anImage3774);
this.gameContainer.gamePanel.setLocation(0, 0);
this.addToContent(this.gameContainer.gamePanel);
}
if (activePanel == 5) {
// super.param.showQuitPage();
System.exit(0);
} else {
this.contentReady();
}
}
}
protected void setGameSettings(
boolean emailUnconfirmed, int playerElevationLevel, boolean useBadWordFilter, boolean disableGuestChat) {
this.syncUnknownBool = new SynchronizedBool(emailUnconfirmed);
this.syncPlayerAccessLevel = new SynchronizedInteger(playerElevationLevel);
this.gameContainer.badWordFilter = useBadWordFilter ? new BadWordFilter(super.textManager) : null;
this.disableGuestChat = disableGuestChat;
}
protected void trackTestLogin(String username, String password) {
this.setGameState(0);
this.gameContainer.connection.writeData("ttlogin\t" + username + "\t" + password);
}
protected void trackTestLogin(String username, String password, Language language) {
this.textManager.setLanguage(language);
this.gameContainer.connection.writeData("language\t" + language);
this.trackTestLogin(username, password);
}
public boolean isEmailVerified() {
return this.syncUnknownBool.get();
}
public int getPlayerAccessLevel() {
return this.syncPlayerAccessLevel.get();
}
public boolean isGuestChatDisabled() {
return this.disableGuestChat;
}
protected boolean hasSession() {
return super.param.getSession() != null;
}
public boolean showPlayerCard(String name) {
return super.param.showPlayerCard(name);
}
public void showPlayerList(String[] names) {
super.param.showPlayerList(names);
}
public void showPlayerListWinners(boolean[] var1) {
super.param.showPlayerListWinners(var1);
}
public void removePlayerListWinnders() {
super.param.removePlayerListWinners();
}
public void removePlayerList() {
super.param.removePlayerList();
}
public void quit(String from) {
this.setEndState(END_QUIT);
this.gameContainer.connection.writeData((from != null ? from + "\t" : "") + "quit");
this.setGameState(5);
}
private boolean isValidSite() {
return true;
}
}