mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Forbedring av kodekvalitet og flere kommentarer
This commit is contained in:
parent
9fa8f04ef7
commit
0c8b9f47d9
@ -16,25 +16,28 @@ import inf112.fiasko.roborally.networking.RoboRallyServer;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This screen is the first screen shown to a player
|
||||||
|
*/
|
||||||
public class StartMenuScreen extends AbstractScreen {
|
public class StartMenuScreen extends AbstractScreen {
|
||||||
private final RoboRallyWrapper roboRallyWrapper;
|
private final RoboRallyWrapper roboRallyWrapper;
|
||||||
|
|
||||||
private final OrthographicCamera camera;
|
private final OrthographicCamera camera;
|
||||||
private final Viewport viewport;
|
private final Viewport viewport;
|
||||||
private final Stage stage;
|
private final Stage stage;
|
||||||
private final int applicationWidth = 600;
|
|
||||||
private final int applicationHeight = 800;
|
/**
|
||||||
private TextButton serverButton;
|
* Instantiates a new start menu screen
|
||||||
private TextButton clientButton;
|
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
|
||||||
private TextButton quitButton;
|
*/
|
||||||
public StartMenuScreen(final RoboRallyWrapper roboRallyWrapper) {
|
public StartMenuScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||||
camera = new OrthographicCamera();
|
camera = new OrthographicCamera();
|
||||||
viewport = new FitViewport(applicationWidth, applicationHeight, camera);
|
viewport = new FitViewport(applicationWidth, applicationHeight, camera);
|
||||||
stage = new Stage();
|
stage = new Stage();
|
||||||
serverButton = new SimpleButton("Create", roboRallyWrapper.font).getButton();
|
TextButton serverButton = new SimpleButton("Create", roboRallyWrapper.font).getButton();
|
||||||
stage.addActor(serverButton);
|
stage.addActor(serverButton);
|
||||||
serverButton.setY(applicationHeight/2f);
|
serverButton.setY(applicationHeight / 2f);
|
||||||
serverButton.setX(applicationWidth/2f);
|
serverButton.setX(applicationWidth / 2f);
|
||||||
this.roboRallyWrapper = roboRallyWrapper;
|
this.roboRallyWrapper = roboRallyWrapper;
|
||||||
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
||||||
Gdx.input.setInputProcessor(stage);
|
Gdx.input.setInputProcessor(stage);
|
||||||
@ -48,36 +51,38 @@ public class StartMenuScreen extends AbstractScreen {
|
|||||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getUsernameScreen(roboRallyWrapper));
|
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getUsernameScreen(roboRallyWrapper));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
//Hard fail
|
||||||
|
System.exit(1);
|
||||||
}
|
}
|
||||||
return true; // Here do stuff
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
clientButton = new SimpleButton("Join", roboRallyWrapper.font).getButton();
|
TextButton clientButton = new SimpleButton("Join", roboRallyWrapper.font).getButton();
|
||||||
stage.addActor(clientButton);
|
stage.addActor(clientButton);
|
||||||
clientButton.setY(applicationHeight/2f);
|
clientButton.setY(applicationHeight / 2f);
|
||||||
clientButton.setX(applicationWidth/2f+serverButton.getWidth()+20);
|
clientButton.setX(applicationWidth / 2f + serverButton.getWidth() + 20);
|
||||||
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
||||||
Gdx.input.setInputProcessor(stage);
|
Gdx.input.setInputProcessor(stage);
|
||||||
clientButton.addListener(new InputListener() {
|
clientButton.addListener(new InputListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getIPAddressScreen(roboRallyWrapper));
|
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getIPAddressScreen(roboRallyWrapper));
|
||||||
return true;// Here we do stuff
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
quitButton = new SimpleButton("Quit", roboRallyWrapper.font).getButton();
|
TextButton quitButton = new SimpleButton("Quit", roboRallyWrapper.font).getButton();
|
||||||
stage.addActor(quitButton);
|
stage.addActor(quitButton);
|
||||||
quitButton.setY(applicationHeight/2f);
|
quitButton.setY(applicationHeight / 2f);
|
||||||
quitButton.setX(applicationWidth/2f+serverButton.getWidth()+40+clientButton.getWidth());
|
quitButton.setX(applicationWidth / 2f + serverButton.getWidth() + 40 + clientButton.getWidth());
|
||||||
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
camera.setToOrtho(false, applicationWidth, applicationHeight);
|
||||||
Gdx.input.setInputProcessor(stage);
|
Gdx.input.setInputProcessor(stage);
|
||||||
quitButton.addListener(new InputListener() {
|
quitButton.addListener(new InputListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
return true;//her we do stuff
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -91,7 +96,8 @@ public class StartMenuScreen extends AbstractScreen {
|
|||||||
|
|
||||||
roboRallyWrapper.batch.begin();
|
roboRallyWrapper.batch.begin();
|
||||||
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "RoboRally",
|
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "RoboRally",
|
||||||
applicationWidth/2f-380/2f,applicationHeight/2f +100,380, 1, true);
|
applicationWidth / 2f - 380 / 2f,applicationHeight / 2f + 100,380, 1,
|
||||||
|
true);
|
||||||
roboRallyWrapper.batch.end();
|
roboRallyWrapper.batch.end();
|
||||||
stage.draw();
|
stage.draw();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user