Skip to content

Commit

Permalink
fixed some things to allow running the server from startup + added er…
Browse files Browse the repository at this point in the history
…ror screen
  • Loading branch information
chrisj42 committed Mar 27, 2018
1 parent 77ed2c1 commit 934ed29
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ allprojects {
apply plugin: "java"
apply plugin: "idea"

version = '1.3.2'
version = '1.3.3'
ext {
appName = "miniventure"
gdxVersion = '1.9.8'
Expand Down
2 changes: 1 addition & 1 deletion core/client/src/miniventure/game/client/ClientCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void create () {
gameScreen = new GameScreen();
clientWorld = new ClientWorld(serverStarter, gameScreen);

setScreen(new MainMenu(clientWorld));
setScreen(new MainMenu());
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion core/client/src/miniventure/game/client/ClientWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void exitWorld(boolean save) { // returns to title screen
// set menu to main menu, and dispose of level/world resources
mainPlayer = null;
clearLevels();
ClientCore.setScreen(new MainMenu(this));
ClientCore.setScreen(new MainMenu());
}


Expand Down
21 changes: 13 additions & 8 deletions core/client/src/miniventure/game/client/GameClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import miniventure.game.GameCore;
import miniventure.game.GameProtocol;
import miniventure.game.screen.ErrorScreen;
import miniventure.game.screen.MainMenu;
import miniventure.game.util.ProgressLogger;
import miniventure.game.world.Chunk;
Expand Down Expand Up @@ -163,17 +164,21 @@ public void received (Connection connection, Object object) {
public void disconnected(Connection connection) {
System.err.println("client disconnected from server.");
// TODO make ErrorScreen, which accepts a string to display and has a "back to title screen" button.
Gdx.app.postRunnable(() -> ClientCore.setScreen(new MainMenu(ClientCore.getWorld())));
Gdx.app.postRunnable(() -> ClientCore.setScreen(new MainMenu()));
//GameCore.setScreen(new ErrorScreen("Lost connection with server."));
}
});

client.start();
client.getUpdateThread().setUncaughtExceptionHandler((t, e) -> {
ClientCore.exceptionHandler.uncaughtException(t, e);
t.getThreadGroup().uncaughtException(t, e);
client.stop();
});
new Thread(client) {
public void start() {
client.start();
client.getUpdateThread().setUncaughtExceptionHandler((t, e) -> {
ClientCore.exceptionHandler.uncaughtException(t, e);
t.getThreadGroup().uncaughtException(t, e);
client.close();
});
}
}.start();
}

public void send(Object obj) { client.sendTCP(obj); }
Expand All @@ -188,7 +193,7 @@ public boolean connectToServer(@NotNull ProgressLogger logger, String host, int
} catch(IOException e) {
e.printStackTrace();
// error screen
logger.editMessage("failed to connect to server.");
Gdx.app.postRunnable(() -> ClientCore.setScreen(new ErrorScreen("failed to connect to server.")));
return false;
}

Expand Down
29 changes: 29 additions & 0 deletions core/client/src/miniventure/game/screen/ErrorScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package miniventure.game.screen;

import miniventure.game.client.ClientCore;

import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.kotcrab.vis.ui.widget.VisLabel;
import com.kotcrab.vis.ui.widget.VisTextButton;

public class ErrorScreen extends MenuScreen {

public ErrorScreen(String error) {

vGroup.addActor(new VisLabel(error));

vGroup.space(50);


VisTextButton returnBtn = new VisTextButton("Back to main menu");
returnBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent e, float x, float y) {
ClientCore.setScreen(new MainMenu());
}
});
vGroup.addActor(returnBtn);
}

}
7 changes: 5 additions & 2 deletions core/client/src/miniventure/game/screen/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javax.swing.JOptionPane;

import miniventure.game.GameCore;
import miniventure.game.client.ClientCore;
import miniventure.game.client.ClientWorld;

import com.badlogic.gdx.scenes.scene2d.InputEvent;
Expand All @@ -13,9 +14,11 @@

public class MainMenu extends MenuScreen {

public MainMenu(ClientWorld world) {
public MainMenu() {
super();

ClientWorld world = ClientCore.getWorld();

addLabel("Miniventure", 20);
addLabel("You are playing version " + GameCore.VERSION, 15);

Expand All @@ -39,7 +42,7 @@ public void clicked(InputEvent e, float x, float y) {
addActor(table);
table.add(button);

VisTextButton joinBtn = new VisTextButton("Join Local Server");
VisTextButton joinBtn = new VisTextButton("Join Server");
joinBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent e, float x, float y) {
Expand Down
11 changes: 9 additions & 2 deletions core/game/src/miniventure/game/world/entity/EntityRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,21 @@ protected String[] save() {

public String getName() { return animationName; }

private TextureRegion getSprite() {
if(animation.getKeyFrames().length == 0)
return new TextureRegion();
else
return animation.getKeyFrame(super.elapsedTime, loopAnimation);
}

@Override
public void render(float x, float y, Batch batch) {
batch.draw(animation.getKeyFrame(super.elapsedTime, loopAnimation), x, y);
batch.draw(getSprite(), x, y);
}

@Override
public Vector2 getSize() {
TextureRegion frame = animation.getKeyFrame(super.elapsedTime, loopAnimation);
TextureRegion frame = getSprite();
return new Vector2(frame.getRegionWidth(), frame.getRegionHeight());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void progressAnimation(float delta) {
state = requestedAnimations.poll();
if(state == null) state = AnimationState.IDLE;
if(state != prevState) {
animationChanged = true; // if we're going to render a new animation, we should start it from the beginning, I think. Though, I could see this not ending up being a good idea... NOTE: this is not just set to zero because it seems this causes a divide by zero error when fetching the keyframe.
animationChanged = true;

String textureName = mobSpriteName + "/" + state.name().toLowerCase() + "-";
renderer = new DirectionalAnimationRenderer(mob.getDirection(), dir -> textureName+dir.name().toLowerCase(), state.frameDuration);
Expand Down
2 changes: 2 additions & 0 deletions core/game/src/miniventure/game/world/entity/mob/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ enum Stat {

if(icon.length() > 0) {
TextureRegion fullIcon = GameCore.icons.get(icon);
if(fullIcon == null) fullIcon = new TextureRegion();
TextureRegion emptyIcon = GameCore.icons.get(outlineIcon);
if(emptyIcon == null) emptyIcon = new TextureRegion();
iconWidth = Math.max(fullIcon.getRegionWidth(), emptyIcon.getRegionWidth());
iconHeight = Math.max(fullIcon.getRegionHeight(), emptyIcon.getRegionHeight());
} else
Expand Down

0 comments on commit 934ed29

Please sign in to comment.