Skip to content

Commit

Permalink
Update client to use screens instead of adding them to list
Browse files Browse the repository at this point in the history
  • Loading branch information
David52920 committed Dec 16, 2020
1 parent 3f9f6e7 commit 79897ee
Show file tree
Hide file tree
Showing 62 changed files with 2,604 additions and 2,955 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ project(":client-launcher") {

dependencies {
compile project(":client-core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
compile ("com.badlogicgames.gdx:gdx-tools:$gdxVersion") {
exclude group: 'com.badlogicgames.gdx', module: 'gdx-backend-lwjgl'
}
compile "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-desktop"
Expand Down
77 changes: 12 additions & 65 deletions client-core/src/com/benberi/cadesim/BlockadeSimulator.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.benberi.cadesim;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.benberi.cadesim.game.scene.GameScene;
import com.benberi.cadesim.util.ScreenEnum;
import com.benberi.cadesim.util.ScreenManager;



public class BlockadeSimulator extends ApplicationAdapter{
public class BlockadeSimulator extends Game{

/**
* The game context
Expand All @@ -19,67 +15,18 @@ public class BlockadeSimulator extends ApplicationAdapter{
@Override
public void create () {
context = new GameContext(this);
context.create();
}

@Override
public void render () {
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

// always tick packet queue
context.getPacketHandler().tickQueue();

if (!context.isConnected()) {
// Just update lobby
context.getConnectScene().update();
context.getConnectScene().render();
}
else
{
// Render and update all scenes
for (GameScene scene : context.getScenes()) {
scene.update();
scene.render();
}
}
// render only for map editor
if(context.isInMapEditor()) {
// Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
for (GameScene scene : context.getScenes()) {
scene.update();
scene.render();
}
}

ScreenManager.getInstance().initialize(this);
ScreenManager.getInstance().showScreen(ScreenEnum.LOBBY, context);
}

@Override
public void dispose () {
}

public void setScreenRect (int width, int height){
context.getConnectScene().screenWidth = width;
context.getConnectScene().screenHeight = height;
}

@Override
public void resize (int width, int height) {
if(!context.isConnected() && !context.isStartedMapEditor()) {
if(context.gameStage == null) {
context.gameStage = new Stage(new FitViewport(width, height));
}
context.gameStage.getViewport().update(width, height, true);
context.getConnectScene().stage = new Stage(new FitViewport(width, height));
context.getConnectScene().stage.getViewport().update(width, height, true);
context.getConnectScene().setActorPositions(width);
setScreenRect(width,height);
context.getConnectScene().addStage();
context.getConnectScene().setup();
}
else {
Gdx.graphics.setResizable(false);
try {
context.getService().shutdownNow();
context.getConnectTask().dispose();
}catch(NullPointerException e) {
//throws null pointer if not connected; but cleanup anyway if user logs in then returns to lobby
}
Gdx.app.exit();
}
}
Loading

0 comments on commit 79897ee

Please sign in to comment.