mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Merge branch 'master' of https://github.com/inf112-v20/Fiasko
This commit is contained in:
commit
db8364eb46
@ -0,0 +1,75 @@
|
||||
package inf112.fiasko.roborally.game_wrapper;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Screen;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.utils.viewport.ExtendViewport;
|
||||
import com.badlogic.gdx.utils.viewport.Viewport;
|
||||
|
||||
public class LoadingScreen implements Screen {
|
||||
private final RoboRallyWrapper roboRallyWrapper;
|
||||
|
||||
private final OrthographicCamera camera;
|
||||
private final Viewport viewport;
|
||||
|
||||
private long startTime;
|
||||
private final int applicationWidth = 600;
|
||||
private final int applicationHeight = 800;
|
||||
|
||||
public LoadingScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||
this.roboRallyWrapper = roboRallyWrapper;
|
||||
camera = new OrthographicCamera();
|
||||
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
||||
viewport = new ExtendViewport(applicationWidth, applicationHeight, camera);
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
//Nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
Gdx.gl.glClearColor(0f, 0f, 0f, 0f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
camera.update();
|
||||
roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
|
||||
|
||||
roboRallyWrapper.batch.begin();
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Loading...", applicationWidth/2f-380/2f,
|
||||
applicationHeight/2f,380, 1, true);
|
||||
roboRallyWrapper.batch.end();
|
||||
long time = System.currentTimeMillis();
|
||||
if (time-startTime>10000){
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getMainMenuScreen(this.roboRallyWrapper));
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
viewport.update(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
//Nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
//Nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
//Nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
//Nothing to do
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package inf112.fiasko.roborally.game_wrapper;
|
||||
|
||||
import com.badlogic.gdx.Input;
|
||||
|
||||
public class MyTextInputListener implements Input.TextInputListener {
|
||||
@Override
|
||||
public void input (String text) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void canceled () {
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ public class PowerDownScreen implements Screen {
|
||||
private long startTime;
|
||||
private final int applicationWidth = 600;
|
||||
private final int applicationHeight = 800;
|
||||
private Boolean press = false;
|
||||
public PowerDownScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||
camera = new OrthographicCamera();
|
||||
viewport = new FitViewport(applicationWidth, applicationHeight, camera);
|
||||
@ -35,7 +36,8 @@ public class PowerDownScreen implements Screen {
|
||||
powerDownButton.addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
return true;
|
||||
press = true;
|
||||
return true;//her we do stuff
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -63,6 +65,10 @@ public class PowerDownScreen implements Screen {
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getMainMenuScreen(this.roboRallyWrapper));
|
||||
dispose();
|
||||
}
|
||||
else if (press){
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,7 +22,7 @@ public class RoboRallyWrapper extends Game {
|
||||
batch = new SpriteBatch();
|
||||
font = new BitmapFont(Gdx.files.internal("assets/Montserrat-Regular.fnt"));
|
||||
this.screenManager = new ScreenManager();
|
||||
this.setScreen(screenManager.getMainMenuScreen(this));
|
||||
this.setScreen(screenManager.getStartMenuScreen(this));
|
||||
try {
|
||||
RoboRallyServer server = new RoboRallyServer();
|
||||
RoboRallyClient client = new RoboRallyClient();
|
||||
|
@ -8,6 +8,8 @@ public class ScreenManager {
|
||||
private BoardActiveScreen boardActiveScreen;
|
||||
private CardChoiceScreen cardChoiceScreen;
|
||||
private PowerDownScreen powerDownScreen;
|
||||
private LoadingScreen loadingScreen;
|
||||
private StartMenuScreen startMenuScreen;
|
||||
|
||||
/**
|
||||
* Gets an instance of the main menu screen
|
||||
@ -21,6 +23,20 @@ public class ScreenManager {
|
||||
return powerDownScreen;
|
||||
}
|
||||
|
||||
public synchronized StartMenuScreen getStartMenuScreen(RoboRallyWrapper roboRallyWrapper) {
|
||||
if (this.startMenuScreen == null) {
|
||||
this.startMenuScreen = new StartMenuScreen(roboRallyWrapper);
|
||||
}
|
||||
return startMenuScreen;
|
||||
}
|
||||
|
||||
public synchronized LoadingScreen getLoadingScreen(RoboRallyWrapper roboRallyWrapper) {
|
||||
if (this.loadingScreen == null) {
|
||||
this.loadingScreen = new LoadingScreen(roboRallyWrapper);
|
||||
}
|
||||
return loadingScreen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an instance of the main menu screen
|
||||
* @param roboRallyWrapper The robo rally launcher instance to use
|
||||
|
@ -0,0 +1,128 @@
|
||||
package inf112.fiasko.roborally.game_wrapper;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.Screen;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||
import com.badlogic.gdx.utils.viewport.Viewport;
|
||||
|
||||
public class StartMenuScreen implements Screen {
|
||||
private final RoboRallyWrapper roboRallyWrapper;
|
||||
|
||||
private final OrthographicCamera camera;
|
||||
private final Viewport viewport;
|
||||
private final Stage stage;
|
||||
private final int applicationWidth = 600;
|
||||
private final int applicationHeight = 800;
|
||||
private Boolean press = false;
|
||||
public StartMenuScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||
camera = new OrthographicCamera();
|
||||
viewport = new FitViewport(applicationWidth, applicationHeight, camera);
|
||||
stage = new Stage();
|
||||
|
||||
TextButton serverButton = new SimpleButton("Create", roboRallyWrapper.font).getButton();
|
||||
stage.addActor(serverButton);
|
||||
serverButton.setY(applicationHeight/2f);
|
||||
serverButton.setX(applicationWidth/2f);
|
||||
this.roboRallyWrapper = roboRallyWrapper;
|
||||
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
||||
Gdx.input.setInputProcessor(stage);
|
||||
serverButton.addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
MyTextInputListener nameinput = new MyTextInputListener();
|
||||
Gdx.input.getTextInput(nameinput, "Name input", "input name her", "");
|
||||
press = true;
|
||||
return true;//her we do stuff
|
||||
}
|
||||
});
|
||||
|
||||
TextButton clientButton = new SimpleButton("Join", roboRallyWrapper.font).getButton();
|
||||
stage.addActor(clientButton);
|
||||
clientButton.setY(applicationHeight/2f);
|
||||
clientButton.setX(applicationWidth/2f+serverButton.getWidth()+20);
|
||||
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
||||
Gdx.input.setInputProcessor(stage);
|
||||
clientButton.addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
press = true;
|
||||
MyTextInputListener nameinput = new MyTextInputListener();
|
||||
Gdx.input.getTextInput(nameinput, "Name input", "input name her", "");
|
||||
|
||||
return true;//her we do stuff
|
||||
}
|
||||
});
|
||||
|
||||
TextButton quitButton = new SimpleButton("Quit", roboRallyWrapper.font).getButton();
|
||||
stage.addActor(quitButton);
|
||||
quitButton.setY(applicationHeight/2f);
|
||||
quitButton.setX(applicationWidth/2f+serverButton.getWidth()+40+clientButton.getWidth());
|
||||
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
||||
Gdx.input.setInputProcessor(stage);
|
||||
quitButton.addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||
System.exit(0);
|
||||
return true;//her we do stuff
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
//Nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
Gdx.gl.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
camera.update();
|
||||
roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
|
||||
|
||||
roboRallyWrapper.batch.begin();
|
||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "RoboRally",
|
||||
applicationWidth/2f-380/2f,applicationHeight/2f +100,380, 1, true);
|
||||
roboRallyWrapper.batch.end();
|
||||
stage.draw();
|
||||
|
||||
if (press){
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
viewport.update(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
//Nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
//Nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
//Nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
//Nothing to do
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user