Skip to content

Commit

Permalink
Merge pull request #131 from StenAL/features
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippvK authored Jan 2, 2025
2 parents 77f4aac + 18fa52e commit 4b7c3d6
Show file tree
Hide file tree
Showing 34 changed files with 425 additions and 453 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

# Reformat the codebase with Spotless
6e262ce1d8d66ac83af70b557269f1ed584f7438

# Rename package in client from aapeli.applet to aapeli.frame
3f2ca9710452bdc73cded805b8555634048cc634
6 changes: 3 additions & 3 deletions client/src/main/java/agolf/GameContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class GameContainer { // some kind of a container for everything

public GameApplet gameApplet;
public GolfGameFrame golfGameFrame;
public Parameters params;
public TextManager textManager;
public SoundManager soundManager;
Expand All @@ -33,8 +33,8 @@ public class GameContainer { // some kind of a container for everything
public GamePanel gamePanel;
public int graphicsQualityIndex;

public GameContainer(GameApplet gameApplet, Parameters params) {
this.gameApplet = gameApplet;
public GameContainer(GolfGameFrame golfGameFrame, Parameters params) {
this.golfGameFrame = golfGameFrame;
this.params = params;
this.graphicsQualityIndex = 3;
this.synchronizedTrackTestMode = new SynchronizedBool();
Expand Down
43 changes: 22 additions & 21 deletions client/src/main/java/agolf/GolfConnection.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package agolf;

import com.aapeli.applet.AApplet;
import com.aapeli.connection.SocketConnection;
import com.aapeli.connection.SocketConnectionListener;
import com.aapeli.frame.AbstractGameFrame;
import com.aapeli.tools.Tools;

public class GolfConnection implements SocketConnectionListener {
Expand Down Expand Up @@ -95,7 +95,7 @@ public void dataReceived(String packet) {

try {
this.writeData("error-debug\t"
+ this.gameContainer.gameApplet.getActivePanel()
+ this.gameContainer.golfGameFrame.getActivePanel()
+ "\t"
+ e.toString().trim().replace('\n', '\\')
+ "\t"
Expand All @@ -107,19 +107,19 @@ public void dataReceived(String packet) {
} catch (Exception ex) {
}

this.gameContainer.gameApplet.setEndState(e);
this.gameContainer.golfGameFrame.setEndState(e);
this.socketConnection.closeConnection();
}
}

public void connectionLost(int var1) {
if (var1 != 2 && var1 != 3) {
if (var1 == 4) {
this.gameContainer.gameApplet.setEndState(AApplet.END_ERROR_VERSION);
this.gameContainer.golfGameFrame.setEndState(AbstractGameFrame.END_ERROR_VERSION);
}

} else {
this.gameContainer.gameApplet.setEndState(AApplet.END_ERROR_CONNECTION);
this.gameContainer.golfGameFrame.setEndState(AbstractGameFrame.END_ERROR_CONNECTION);
}
}

Expand All @@ -128,12 +128,12 @@ public void notifyConnectionDown() {}
public void notifyConnectionUp() {}

protected boolean openSocketConnection() {
this.socketConnection = new SocketConnection(this.gameContainer.gameApplet, this, cipherCmds);
this.socketConnection = new SocketConnection(this.gameContainer.golfGameFrame, this, cipherCmds);
return this.socketConnection.openConnection();
}

protected void sendVersion() {
this.gameContainer.gameApplet.setGameState(0);
this.gameContainer.golfGameFrame.setGameState(0);
this.writeData("version\t" + 35);
}

Expand All @@ -153,9 +153,9 @@ private void handlePacket(String cmd) {
switch (args[0]) {
case "error" -> {
if (args[1].equals("vernotok")) {
this.gameContainer.gameApplet.setEndState(AApplet.END_ERROR_VERSION);
this.gameContainer.golfGameFrame.setEndState(AbstractGameFrame.END_ERROR_VERSION);
} else if (args[1].equals("serverfull")) {
this.gameContainer.gameApplet.setEndState(AApplet.END_ERROR_SERVERFULL);
this.gameContainer.golfGameFrame.setEndState(AbstractGameFrame.END_ERROR_SERVERFULL);
}

this.socketConnection.closeConnection();
Expand All @@ -165,9 +165,9 @@ private void handlePacket(String cmd) {
this.writeData("logintype\t"
+ (this.gameContainer.synchronizedTrackTestMode.get()
? "ttm"
: (this.gameContainer.gameApplet.hasSession() ? "reg" : "nr")));
: (this.gameContainer.golfGameFrame.hasSession() ? "reg" : "nr")));
}
case "basicinfo" -> this.gameContainer.gameApplet.setGameSettings(
case "basicinfo" -> this.gameContainer.golfGameFrame.setGameSettings(
args[1].equals("t"), Integer.parseInt(args[2]), args[3].equals("t"), args[4].equals("t"));
case "broadcast" -> {
if (this.gameContainer.lobbyPanel != null) {
Expand All @@ -182,7 +182,7 @@ private void handlePacket(String cmd) {
switch (args[1]) {
case "login" -> {
if (args.length == 2) {
this.gameContainer.gameApplet.setGameState(1);
this.gameContainer.golfGameFrame.setGameState(1);
return;
}

Expand All @@ -203,46 +203,47 @@ private void handlePacket(String cmd) {
var3 = 7;
}

this.gameContainer.gameApplet.setGameState(1, var3);
this.gameContainer.golfGameFrame.setGameState(1, var3);
return;
}
case "lobbyselect" -> {
this.gameContainer.gameApplet.setGameState(2, args.length > 2 ? Integer.parseInt(args[2]) : 0);
this.gameContainer.golfGameFrame.setGameState(
2, args.length > 2 ? Integer.parseInt(args[2]) : 0);
return;
}
case "lobby" -> {
if (args.length == 2) {
this.gameContainer.gameApplet.setGameState(3, Integer.MIN_VALUE);
this.gameContainer.golfGameFrame.setGameState(3, Integer.MIN_VALUE);
return;
}

if (args[2].equals("tt")) {
this.gameContainer.gameApplet.setGameState(3, -1, args[3].equals("t") ? 1 : 0);
this.gameContainer.golfGameFrame.setGameState(3, -1, args[3].equals("t") ? 1 : 0);
return;
}

if (!args[2].equals("1") && !args[2].equals("1h")) {
if (args[2].equals("2")) {
this.gameContainer.gameApplet.setGameState(3, 2);
this.gameContainer.golfGameFrame.setGameState(3, 2);
return;
}

if (args.length == 3) {
this.gameContainer.gameApplet.setGameState(3, 3);
this.gameContainer.golfGameFrame.setGameState(3, 3);
return;
}

this.gameContainer.gameApplet.setGameState(3, 3, Integer.parseInt(args[3]));
this.gameContainer.golfGameFrame.setGameState(3, 3, Integer.parseInt(args[3]));
return;
}

this.gameContainer.gameApplet.setGameState(3, 1, args[2].equals("1") ? 1 : -1);
this.gameContainer.golfGameFrame.setGameState(3, 1, args[2].equals("1") ? 1 : -1);
// enables tracklistadmin this.aGameContainer_2370.gameApplet.setGameState(3, -1,
// 1);
return;
}
case "game" -> {
this.gameContainer.gameApplet.setGameState(4);
this.gameContainer.golfGameFrame.setGameState(4);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import agolf.game.GameBackgroundCanvas;
import agolf.game.GamePanel;
import agolf.lobby.LobbyPanel;
import com.aapeli.applet.AApplet;
import com.aapeli.client.AutoPopups;
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.Locale;

public class GameApplet extends AApplet {
public class GolfGameFrame extends AbstractGameFrame {

public SynchronizedBool syncIsValidSite;
public static final Color colourGameBackground = new Color(153, 255, 153);
Expand All @@ -41,11 +41,11 @@ public class GameApplet extends AApplet {
private Image anImage3774;
private boolean verbose = false;

public GameApplet(Parameters parameters) {
super(parameters);
public GolfGameFrame(String server, int port, Locale locale, String username, boolean verbose, boolean norandom) {
super(server, port, locale, username, verbose, norandom);
}

public void initApplet(Parameters parameters) {
public void initGame(Parameters parameters) {
this.syncIsValidSite = new SynchronizedBool(this.isValidSite());
this.setBackground(colourGameBackground);
this.setForeground(colourTextBlack);
Expand All @@ -54,7 +54,7 @@ public void initApplet(Parameters parameters) {
}

@Override
public String getAppletInfo() {
public String getCopyrightInfo() {
return "-= AGolf =-\nCopyright (c) 2002-2012 Playforia (www.playforia.info)\nProgramming: Pasi Laaksonen\nGraphics: Janne Matilainen";
}

Expand Down Expand Up @@ -103,7 +103,7 @@ public void connectToServer() {
}
}

public void appletReady() {
public void gameReady() {
this.gameContainer.autoPopup = new AutoPopups(this);
// this.setGameSettings(false, 0, false, true); // disabled Bad Word Filter!
this.setGameSettings(false, 0, true, true); // enabled Bad Word Filter!
Expand All @@ -112,7 +112,7 @@ public void appletReady() {
this.gameContainer.connection.sendVersion();
}

public void destroyApplet() {
public void destroyGame() {
this.gameContainer.destroy();
}

Expand Down Expand Up @@ -158,7 +158,7 @@ protected void setGameState(int activePanel, int lobbyId, int lobbyExtra) {
String username = param.getUsername();
if (username == null) {
TrackTestLoginPanel loginPanel =
new TrackTestLoginPanel(this, super.appletWidth, super.appletHeight);
new TrackTestLoginPanel(this, super.contentWidth, super.contentHeight);
loginPanel.setLocation(0, 0);
this.addToContent(loginPanel);
} else {
Expand All @@ -176,7 +176,7 @@ protected void setGameState(int activePanel, int lobbyId, int lobbyExtra) {
if (activePanel == 2) {
if (this.gameContainer.lobbySelectionPanel == null) {
this.gameContainer.lobbySelectionPanel =
new LobbySelectPanel(this.gameContainer, super.appletWidth, super.appletHeight);
new LobbySelectPanel(this.gameContainer, super.contentWidth, super.contentHeight);
this.gameContainer.lobbySelectionPanel.setLocation(0, 0);
}

Expand Down Expand Up @@ -205,7 +205,7 @@ protected void setGameState(int activePanel, int lobbyId, int lobbyExtra) {
this.gameContainer.gamePanel = null;
if (this.gameContainer.lobbyPanel == null) {
this.gameContainer.lobbyPanel =
new LobbyPanel(this.gameContainer, super.appletWidth, super.appletHeight);
new LobbyPanel(this.gameContainer, super.contentWidth, super.contentHeight);
this.gameContainer.lobbyPanel.setLocation(0, 0);
}

Expand All @@ -222,7 +222,7 @@ protected void setGameState(int activePanel, int lobbyId, int lobbyExtra) {

if (activePanel == 4) {
this.gameContainer.gamePanel =
new GamePanel(this.gameContainer, super.appletWidth, super.appletHeight, this.anImage3774);
new GamePanel(this.gameContainer, super.contentWidth, super.contentHeight, this.anImage3774);
this.gameContainer.gamePanel.setLocation(0, 0);
this.addToContent(this.gameContainer.gamePanel);
}
Expand Down
24 changes: 12 additions & 12 deletions client/src/main/java/agolf/LobbySelectPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void paint(Graphics g) {
public void update(Graphics g) {
g.drawImage(this.gameContainer.imageManager.getGameImage("bg-lobbyselect"), 0, 0, this);
g.setColor(Color.black);
g.setFont(GameApplet.fontSerif26b);
g.setFont(GolfGameFrame.fontSerif26b);
if (!this.gameContainer.disableSinglePlayer) {
StringDraw.drawString(
g, this.gameContainer.textManager.getGame("LobbySelect_SinglePlayer"), this.width / 6, 70, 0);
Expand All @@ -70,7 +70,7 @@ public void update(Graphics g) {
g, this.gameContainer.textManager.getGame("LobbySelect_DualPlayer"), this.width * 3 / 6, 70, 0);
StringDraw.drawString(
g, this.gameContainer.textManager.getGame("LobbySelect_MultiPlayer"), this.width * 5 / 6, 70, 0);
g.setFont(GameApplet.fontDialog12);
g.setFont(GolfGameFrame.fontDialog12);
if (!this.gameContainer.disableSinglePlayer) {
this.drawNumPlayers(g, this.width / 6, this.lobbyNumPlayers[0]);
}
Expand Down Expand Up @@ -120,14 +120,14 @@ else if (evtSource == this.buttonDual) {
} else if (evtSource == this.buttonMulti) {
this.selectLobby(3);
} else if (evtSource == this.buttonSingleQuick) {
this.gameContainer.gameApplet.setGameState(0);
this.gameContainer.golfGameFrame.setGameState(0);
this.writeData("cspt\t10\t1\t0");
} else if (evtSource == this.buttonMultiQuick) {
this.gameContainer.gameApplet.setGameState(0);
this.gameContainer.golfGameFrame.setGameState(0);
this.writeData("qmpt");
} else {
if (evtSource == this.buttonQuit) {
this.gameContainer.gameApplet.quit(null);
this.gameContainer.golfGameFrame.quit(null);
}
}
}
Expand Down Expand Up @@ -209,15 +209,15 @@ private void create() {
this.setLayout(null);
this.checkboxPlayHidden = new ColorCheckbox(this.gameContainer.textManager.getGame("LobbySelect_PlayHidden"));
this.checkboxPlayHidden.setBounds(this.width / 6 - 75 - 10, this.height - 124, 220, 18);
this.checkboxPlayHidden.setBackground(GameApplet.colourGameBackground);
this.checkboxPlayHidden.setBackground(GolfGameFrame.colourGameBackground);
if (!this.gameContainer.disableSinglePlayer) {
this.add(this.checkboxPlayHidden);
this.buttonSingle = new ColorButton(this.gameContainer.textManager.getGame("LobbySelect_SinglePlayer"));
this.buttonSingle.setBounds(this.width / 6 - 75, this.height - 150, 150, 25);
this.buttonSingle.addActionListener(this);
this.add(this.buttonSingle);
this.buttonSingleQuick = new ColorButton(this.gameContainer.textManager.getGame("LobbySelect_QuickStart"));
this.buttonSingleQuick.setBackground(GameApplet.colourButtonBlue);
this.buttonSingleQuick.setBackground(GolfGameFrame.colourButtonBlue);
this.buttonSingleQuick.setBounds(this.width / 6 - 50, this.height - 95, 100, 20);
this.buttonSingleQuick.addActionListener(this);
this.add(this.buttonSingleQuick);
Expand All @@ -236,7 +236,7 @@ private void create() {
this.add(this.buttonMulti);

this.buttonMultiQuick = new ColorButton(this.gameContainer.textManager.getGame("LobbySelect_QuickStart"));
this.buttonMultiQuick.setBackground(GameApplet.colourButtonBlue);
this.buttonMultiQuick.setBackground(GolfGameFrame.colourButtonBlue);
this.buttonMultiQuick.setBounds(this.width * 5 / 6 - 50, this.height - 95, 100, 20);
this.buttonMultiQuick.addActionListener(this);
this.add(this.buttonMultiQuick);
Expand Down Expand Up @@ -266,7 +266,7 @@ private void create() {
this.add(this.audioChoicer);

this.buttonQuit = new ColorButton(this.gameContainer.textManager.getGame("LobbySelect_Quit"));
this.buttonQuit.setBackground(GameApplet.colourButtonRed);
this.buttonQuit.setBackground(GolfGameFrame.colourButtonRed);
this.buttonQuit.setBounds(this.width * 2 / 3 - 50, this.height - 10 - 20, 100, 20);
this.buttonQuit.addActionListener(this);
this.add(this.buttonQuit);
Expand All @@ -284,18 +284,18 @@ private void drawNumPlayers(Graphics g, int x, int numPlayers) {
}

StringDraw.drawString(g, text, x, 110, 0);
if (numPlayers >= this.lobbyMaxPlayers && this.gameContainer.gameApplet.getPlayerAccessLevel() == 0) {
if (numPlayers >= this.lobbyMaxPlayers && this.gameContainer.golfGameFrame.getPlayerAccessLevel() == 0) {
StringDraw.drawString(g, this.gameContainer.textManager.getGame("LobbySelect_Full"), x, 130, 0);
}
}
}

private boolean selectLobby(int lobbyId) {
if (this.lobbyNumPlayers[lobbyId - 1] >= this.lobbyMaxPlayers
&& this.gameContainer.gameApplet.getPlayerAccessLevel() == 0) {
&& this.gameContainer.golfGameFrame.getPlayerAccessLevel() == 0) {
return false;
} else {
this.gameContainer.gameApplet.setGameState(0);
this.gameContainer.golfGameFrame.setGameState(0);
this.writeData(getLobbySelectMessage(lobbyId));
return true;
}
Expand Down
Loading

0 comments on commit 4b7c3d6

Please sign in to comment.