Skip to content

Commit

Permalink
Fixed some mac issues where game was unplayable
Browse files Browse the repository at this point in the history
  • Loading branch information
David52920 committed Jan 5, 2021
1 parent 3763cf6 commit 28b98dc
Show file tree
Hide file tree
Showing 12 changed files with 750 additions and 697 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ allprojects {
box2DLightsVersion = '1.5'
ashleyVersion = '1.7.3'
aiVersion = '1.8.2'
visuiVersion = '1.4.8'
}

repositories {
Expand Down Expand Up @@ -53,6 +54,7 @@ project(":client-core") {
compile group: 'io.netty', name: 'netty-all', version: '4.1.40.Final'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'javax.xml.soap', name: 'javax.xml.soap-api', version: '1.4.0'
compile "com.kotcrab.vis:vis-ui:$visuiVersion"
}
}

Expand Down
4 changes: 4 additions & 0 deletions client-core/src/com/benberi/cadesim/BlockadeSimulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.badlogic.gdx.Gdx;
import com.benberi.cadesim.util.ScreenEnum;
import com.benberi.cadesim.util.ScreenManager;
import com.kotcrab.vis.ui.VisUI;
import com.kotcrab.vis.ui.widget.file.FileChooser;

public class BlockadeSimulator extends Game{

Expand All @@ -17,6 +19,8 @@ public class BlockadeSimulator extends Game{
@Override
public void create () {
context = new GameContext(this);
VisUI.load();
FileChooser.setDefaultPrefsName("com.cadesim.mapeditor.filechooser");
ScreenManager.getInstance().initialize(this);
ScreenManager.getInstance().showScreen(ScreenEnum.LOBBY, context);
}
Expand Down
60 changes: 30 additions & 30 deletions client-core/src/com/benberi/cadesim/GameContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,13 @@ public ClientPacketHandler getPacketHandler() {
public void createFurtherScenes(int shipId) {
GameContext context = this;
Gdx.app.postRunnable(new Runnable() {

@Override
public void run() {
ScreenManager.getInstance().showScreen(ScreenEnum.GAME, context);
graphics.setTitle("GC: " + myVessel + " (" + myTeam + ")");
}

});
Gdx.graphics.setTitle("GC: " + myVessel + " (" + myTeam + ")");
}

public void setLobbyScreen(LobbyScreen lobby) {
Expand Down Expand Up @@ -403,7 +402,7 @@ public void onFailure() {
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
graphics.setResizable(false);
graphics.setResizable(true);
}
});
}
Expand All @@ -416,36 +415,23 @@ public void run() {
*
* @param response The response code
*/
public void handleLoginResponse(int response) {
public String handleLoginResponse(int response) {
if (response != LoginResponsePacket.SUCCESS) {
getServerChannel().disconnect();
haveServerResponse = true;

switch (response) {
case LoginResponsePacket.BAD_VERSION:
getLobbyScreen().setPopupMessage("Outdated client.");
getLobbyScreen().showPopup();
break;
return "Outdated client.";
case LoginResponsePacket.NAME_IN_USE:
getLobbyScreen().setPopupMessage("Display name already in use.");
getLobbyScreen().showPopup();
break;
return "Display name already in use.";
case LoginResponsePacket.BAD_SHIP:
getLobbyScreen().setPopupMessage("The selected ship is not allowed.");
getLobbyScreen().showPopup();
break;
return "The selected ship is not allowed.";
case LoginResponsePacket.SERVER_FULL:
getLobbyScreen().setPopupMessage("The server is full.");
getLobbyScreen().showPopup();
break;
return "The server is full.";
case LoginResponsePacket.BAD_NAME:
getLobbyScreen().setPopupMessage("That ship name is not allowed.");
getLobbyScreen().showPopup();
break;
return "That ship name is not allowed.";
default:
getLobbyScreen().setPopupMessage("Unknown login failure.");
getLobbyScreen().showPopup();
break;
return "Unknown login failure.";
}

}
Expand All @@ -458,6 +444,7 @@ public void handleLoginResponse(int response) {
getBattleScreen().battleMenu.audio_slider.setValue(Float.parseFloat(volume));
getBattleScreen().setSound_volume(Float.parseFloat(volume));
}
return null;
}
}

Expand Down Expand Up @@ -595,30 +582,43 @@ public void disconnect() {
* When the client (or user) decides to disconnect
*/
public void exitMapEditor() {
Gdx.graphics.setResizable(true);
setStartedMapEditor(false);
setClientInitiatedDisconnect(true); // wedunnit!
setConnected(false);
setIsInLobby(true);
Gdx.graphics.setTitle("GC: v" + Constants.VERSION);
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
graphics.setResizable(true);
graphics.setTitle("GC: v" + Constants.VERSION);
}

});
}
/*
* When the server decides to disconnect
*/
public void handleServersideDisconnect() {
if(getServerResponse()) {
// inputMultiplexer.clear();
getServerChannel().disconnect();
getLobbyScreen().setPopupMessage("Login error.");
getLobbyScreen().showPopup();
System.out.println("Login error; handling response.");
}else {
// inputMultiplexer.clear();
setConnected(false);
setIsInLobby(true);
getServerChannel().disconnect();
// getConnectScene().setState(ConnectionSceneState.DEFAULT);
// connectScene.setPopupMessage("Server Disconnected.");
// connectScene.showPopup();
getLobbyScreen().setPopupMessage("Server Disconnected.");
getLobbyScreen().showPopup();
}

Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
ScreenManager.getInstance().showScreen(ScreenEnum.LOBBY, context);
graphics.setResizable(true);
}
});
}

public GameAssetManager getAssetObject() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.ObjectInputStream;
import java.util.ArrayList;

import com.badlogic.gdx.Gdx;
import com.benberi.cadesim.GameContext;
import com.benberi.cadesim.client.codec.util.Packet;
import com.benberi.cadesim.client.packet.ClientPacketExecutor;
Expand All @@ -26,7 +27,7 @@ public LoginResponsePacket(GameContext ctx) {
@Override
public void execute(Packet p) {
int response = p.readByte();
getContext().handleLoginResponse(response);
String string = getContext().handleLoginResponse(response);
int length = p.readInt();
ObjectInputStream ois;
try {
Expand All @@ -42,6 +43,15 @@ public void execute(Packet p) {
} catch (IOException e) {
e.printStackTrace();
}
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
if(string != null) {
getContext().getLobbyScreen().setPopupMessage(string);
getContext().getLobbyScreen().showPopup();
}
}
});
}

@Override
Expand Down
23 changes: 4 additions & 19 deletions client-core/src/com/benberi/cadesim/game/screen/LobbyScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
Expand Down Expand Up @@ -60,10 +59,6 @@ public class LobbyScreen extends AbstractScreen implements InputProcessor {
* Batch for opening screen
*/

/**
* The shape renderer
*/
public ShapeRenderer renderer;

private BitmapFont font;
private BitmapFont titleFont;
Expand Down Expand Up @@ -136,8 +131,6 @@ public class LobbyScreen extends AbstractScreen implements InputProcessor {

public int screenWidth;
public int screenHeight;

private Skin skin;

private Random random = new Random();
private HashMap<String,String> userProperties;
Expand All @@ -160,11 +153,9 @@ public void buildStage() {
room_names.clear();
server_codes.clear();
greetings.clear();
renderer = new ShapeRenderer();
loginButtonStyle = new ImageButtonStyle();
mapEditorButtonStyle = new ImageButtonStyle();
url = null;
skin = new Skin(Gdx.files.internal("uiskin.json"));

//styles
style = new TextField.TextFieldStyle();
Expand Down Expand Up @@ -566,12 +557,12 @@ public void fillInfo() {
public void initListeners() {
buttonMapEditor.addListener(new ClickListener() {//runs update if there is one before logging in
public void clicked(InputEvent event, float x, float y){
stage.clear();
ScreenManager.getInstance().showScreen(ScreenEnum.MAPEDITOR,context);
context.setStartedMapEditor(true);
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
stage.clear();
ScreenManager.getInstance().showScreen(ScreenEnum.MAPEDITOR,context);
context.setStartedMapEditor(true);
graphics.setResizable(false);
}
});
Expand All @@ -581,22 +572,16 @@ public void run() {
buttonConn.addListener(new ClickListener() {//runs update if there is one before logging in
public void clicked(InputEvent event, float x, float y){
Gdx.app.postRunnable(new Runnable() {

@Override
public void run() {
ScreenManager.getInstance().showScreen(ScreenEnum.LOADING,context,"Connecting, please wait...");
graphics.setResizable(false);
}

});
try {
performUpdateCheck();
buttonConn.toggle();
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
graphics.setResizable(false);
}
});
} catch (UnknownHostException e) {
return;
}
Expand Down
Loading

0 comments on commit 28b98dc

Please sign in to comment.