|
|
|
|
@@ -1,34 +1,31 @@
|
|
|
|
|
package com.ghost.technic;
|
|
|
|
|
|
|
|
|
|
import com.badlogic.gdx.ApplicationAdapter;
|
|
|
|
|
import com.badlogic.gdx.Game;
|
|
|
|
|
import com.badlogic.gdx.Gdx;
|
|
|
|
|
import com.badlogic.gdx.Screen;
|
|
|
|
|
import com.badlogic.gdx.assets.AssetManager;
|
|
|
|
|
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
|
|
|
|
import com.badlogic.gdx.math.MathUtils;
|
|
|
|
|
import com.badlogic.gdx.scenes.scene2d.Actor;
|
|
|
|
|
import com.badlogic.gdx.scenes.scene2d.Stage;
|
|
|
|
|
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
|
|
|
|
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
|
|
|
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
|
|
|
|
import com.badlogic.gdx.scenes.scene2d.ui.Window;
|
|
|
|
|
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
|
|
|
|
import com.badlogic.gdx.utils.ScreenUtils;
|
|
|
|
|
import com.badlogic.gdx.utils.viewport.FitViewport;
|
|
|
|
|
import com.badlogic.gdx.utils.GdxRuntimeException;
|
|
|
|
|
import com.ghost.technic.screen.BattlefieldScreen;
|
|
|
|
|
import com.ghost.technic.server.Player;
|
|
|
|
|
import com.ghost.technic.server.game.GameActionService;
|
|
|
|
|
import com.ghost.technic.server.game.GameState;
|
|
|
|
|
import com.ghost.technic.server.game.event.EventBus;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/** {@link com.badlogic.gdx.ApplicationListener} implementation shared by all platforms. */
|
|
|
|
|
public class TechnicClient extends ApplicationAdapter {
|
|
|
|
|
public class TechnicClient extends Game {
|
|
|
|
|
|
|
|
|
|
private Skin skin;
|
|
|
|
|
private Screen currentScreen;
|
|
|
|
|
private AssetManager assetManager;
|
|
|
|
|
private GameState gameState;
|
|
|
|
|
private GameActionService gameActionService;
|
|
|
|
|
|
|
|
|
|
private final Map<Class<? extends Screen>, Screen> screenCache = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void create() {
|
|
|
|
|
|
|
|
|
|
@@ -46,28 +43,31 @@ public class TechnicClient extends ApplicationAdapter {
|
|
|
|
|
gameState.setPlayers(playerOne, playerTwo);
|
|
|
|
|
gameState.setup();
|
|
|
|
|
|
|
|
|
|
currentScreen = new BattlefieldScreen(skin); // store reference
|
|
|
|
|
currentScreen.show();
|
|
|
|
|
// screen
|
|
|
|
|
addScreen(new BattlefieldScreen(skin));
|
|
|
|
|
setScreen(BattlefieldScreen.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void render() {
|
|
|
|
|
if (currentScreen != null) {
|
|
|
|
|
currentScreen.render(Gdx.graphics.getDeltaTime());
|
|
|
|
|
}
|
|
|
|
|
public void addScreen(Screen screen) {
|
|
|
|
|
screenCache.put(screen.getClass(), screen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void resize(int width, int height) {
|
|
|
|
|
if (currentScreen != null) {
|
|
|
|
|
currentScreen.resize(width, height);
|
|
|
|
|
public void setScreen(Class<? extends Screen> screenClass) {
|
|
|
|
|
var screen = screenCache.get(screenClass);
|
|
|
|
|
if (screen == null) {
|
|
|
|
|
throw new GdxRuntimeException("Screen " + screenClass.getSimpleName() + " not found in cache");
|
|
|
|
|
}
|
|
|
|
|
super.setScreen(screen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removeScreen(Screen screen) {
|
|
|
|
|
screenCache.remove(screen.getClass());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void dispose() {
|
|
|
|
|
if (currentScreen != null) {
|
|
|
|
|
currentScreen.dispose();
|
|
|
|
|
for (Screen screen : screenCache.values()) {
|
|
|
|
|
screen.dispose();
|
|
|
|
|
}
|
|
|
|
|
skin.dispose();
|
|
|
|
|
}
|
|
|
|
|
|