Compare commits
4 Commits
refactor_m
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| 5f121ad315 | |||
| 93953cc0b3 | |||
| ae1eba3ff6 | |||
| 213dcf3a6a |
@@ -6,20 +6,26 @@ import com.badlogic.gdx.Screen;
|
|||||||
import com.badlogic.gdx.assets.AssetManager;
|
import com.badlogic.gdx.assets.AssetManager;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||||
|
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||||
|
import com.ghost.technic.screen.BattlefieldScreen;
|
||||||
import com.ghost.technic.server.Player;
|
import com.ghost.technic.server.Player;
|
||||||
import com.ghost.technic.server.game.GameActionService;
|
import com.ghost.technic.server.game.GameActionService;
|
||||||
import com.ghost.technic.server.game.GameState;
|
import com.ghost.technic.server.game.GameState;
|
||||||
import com.ghost.technic.server.game.event.EventBus;
|
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. */
|
/** {@link com.badlogic.gdx.ApplicationListener} implementation shared by all platforms. */
|
||||||
public class TechnicClient extends Game {
|
public class TechnicClient extends Game {
|
||||||
|
|
||||||
private Skin skin;
|
private Skin skin;
|
||||||
private Screen currentScreen;
|
|
||||||
private AssetManager assetManager;
|
private AssetManager assetManager;
|
||||||
private GameState gameState;
|
private GameState gameState;
|
||||||
private GameActionService gameActionService;
|
private GameActionService gameActionService;
|
||||||
|
|
||||||
|
private final Map<Class<? extends Screen>, Screen> screenCache = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create() {
|
public void create() {
|
||||||
|
|
||||||
@@ -37,28 +43,31 @@ public class TechnicClient extends Game {
|
|||||||
gameState.setPlayers(playerOne, playerTwo);
|
gameState.setPlayers(playerOne, playerTwo);
|
||||||
gameState.setup();
|
gameState.setup();
|
||||||
|
|
||||||
currentScreen = new BattlefieldScreen(skin); // store reference
|
// screen
|
||||||
currentScreen.show();
|
addScreen(new BattlefieldScreen(skin));
|
||||||
|
setScreen(BattlefieldScreen.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void addScreen(Screen screen) {
|
||||||
public void render() {
|
screenCache.put(screen.getClass(), screen);
|
||||||
if (currentScreen != null) {
|
|
||||||
currentScreen.render(Gdx.graphics.getDeltaTime());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setScreen(Class<? extends Screen> screenClass) {
|
||||||
public void resize(int width, int height) {
|
var screen = screenCache.get(screenClass);
|
||||||
if (currentScreen != null) {
|
if (screen == null) {
|
||||||
currentScreen.resize(width, height);
|
throw new GdxRuntimeException("Screen " + screenClass.getSimpleName() + " not found in cache");
|
||||||
}
|
}
|
||||||
|
super.setScreen(screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeScreen(Screen screen) {
|
||||||
|
screenCache.remove(screen.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
if (currentScreen != null) {
|
for (Screen screen : screenCache.values()) {
|
||||||
currentScreen.dispose();
|
screen.dispose();
|
||||||
}
|
}
|
||||||
skin.dispose();
|
skin.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.ghost.technic;
|
package com.ghost.technic.screen;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Screen;
|
import com.badlogic.gdx.Screen;
|
||||||
@@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.Stage;
|
|||||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||||
import com.badlogic.gdx.utils.ScreenUtils;
|
import com.badlogic.gdx.utils.ScreenUtils;
|
||||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||||
|
import com.ghost.technic.BattlefieldView;
|
||||||
|
|
||||||
public class BattlefieldScreen implements Screen {
|
public class BattlefieldScreen implements Screen {
|
||||||
|
|
||||||
Reference in New Issue
Block a user