Forbedrer og forenkler skjermer

Endrer litt på listener for knapper for at knapper skal ha en oppførsel mer lik forventet
Lager en klasse InteractiveScreen som forenkler laging av en interaktiv skjerm
Flytter en del intitialisering opp til AbstractScreen
Legger til navn på spiller på WinningScreen
Legger til sjekking av lengden på spillernavn
This commit is contained in:
Kristian Knarvik 2020-04-24 19:20:42 +02:00
parent 35fccac794
commit 1d03e24b71
11 changed files with 135 additions and 118 deletions

View File

@ -1,6 +1,7 @@
package inf112.fiasko.roborally.gamewrapper.screens; package inf112.fiasko.roborally.gamewrapper.screens;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.Screen; import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.OrthographicCamera;
@ -14,13 +15,15 @@ public abstract class AbstractScreen implements Screen {
protected final int applicationWidth = 600; protected final int applicationWidth = 600;
protected final int applicationHeight = 800; protected final int applicationHeight = 800;
protected OrthographicCamera camera; protected OrthographicCamera camera = new OrthographicCamera();
protected Viewport viewport; protected Viewport viewport;
protected Stage stage; protected Stage stage = new Stage();
protected InputMultiplexer inputMultiplexer = new InputMultiplexer();
@Override @Override
public void show() { public void show() {
Gdx.input.setInputProcessor(stage); inputMultiplexer.addProcessor(stage);
Gdx.input.setInputProcessor(inputMultiplexer);
stage.cancelTouchFocus(); stage.cancelTouchFocus();
} }

View File

@ -1,17 +1,12 @@
package inf112.fiasko.roborally.gamewrapper.screens; package inf112.fiasko.roborally.gamewrapper.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.viewport.ExtendViewport; import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import inf112.fiasko.roborally.elementproperties.Direction; import inf112.fiasko.roborally.elementproperties.Direction;
import inf112.fiasko.roborally.elementproperties.GameState; import inf112.fiasko.roborally.elementproperties.GameState;
import inf112.fiasko.roborally.elementproperties.RobotID; import inf112.fiasko.roborally.elementproperties.RobotID;
@ -29,13 +24,11 @@ import java.util.List;
/** /**
* This screen shows the game board in real time * This screen shows the game board in real time
*/ */
public class BoardActiveScreen extends AbstractScreen implements InputProcessor { public class BoardActiveScreen extends InteractiveScreen {
private final RoboRallyWrapper roboRallyWrapper; private final RoboRallyWrapper roboRallyWrapper;
private final OrthographicCamera camera;
private final int tileDimensions = 64; private final int tileDimensions = 64;
private final int viewPortWidth = 12 * tileDimensions; private final int viewPortWidth = 12 * tileDimensions;
private final int viewPortHeight = 12 * tileDimensions; private final int viewPortHeight = 12 * tileDimensions;
private final Viewport viewport;
private float cameraZoom = 1; private float cameraZoom = 1;
private int cameraX = 0; private int cameraX = 0;
private int cameraY = 0; private int cameraY = 0;
@ -49,7 +42,6 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
public BoardActiveScreen(final RoboRallyWrapper roboRallyWrapper) { public BoardActiveScreen(final RoboRallyWrapper roboRallyWrapper) {
this.roboRallyWrapper = roboRallyWrapper; this.roboRallyWrapper = roboRallyWrapper;
camera = new OrthographicCamera();
camera.setToOrtho(false, viewPortWidth, viewPortHeight); camera.setToOrtho(false, viewPortWidth, viewPortHeight);
camera.position.set(viewPortWidth / 2f, viewPortHeight / 2f, 0); camera.position.set(viewPortWidth / 2f, viewPortHeight / 2f, 0);
viewport = new ExtendViewport(viewPortWidth, viewPortHeight, camera); viewport = new ExtendViewport(viewPortWidth, viewPortHeight, camera);
@ -59,21 +51,14 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
@Override @Override
public void show() { public void show() {
Gdx.input.setInputProcessor(this); super.show();
inputMultiplexer.addProcessor(this);
resetCamera(); resetCamera();
} }
@Override
public void resize(int width, int height) {
viewport.update(width, height);
}
@Override @Override
public void render(float delta) { public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1); super.render(delta);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT |
(Gdx.graphics.getBufferFormat().coverageSampling ? GL20.GL_COVERAGE_BUFFER_BIT_NV : 0));
updateCamera(); updateCamera();
roboRallyWrapper.batch.setProjectionMatrix(camera.combined); roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
roboRallyWrapper.batch.begin(); roboRallyWrapper.batch.begin();
@ -104,11 +89,6 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
} }
} }
@Override
public boolean keyDown(int keyCode) {
return false;
}
@Override @Override
public boolean keyUp(int keyCode) { public boolean keyUp(int keyCode) {
if (keyCode == Input.Keys.TAB && roboRallyWrapper.roboRallyGame.getGameState() == GameState.CHOOSING_CARDS) { if (keyCode == Input.Keys.TAB && roboRallyWrapper.roboRallyGame.getGameState() == GameState.CHOOSING_CARDS) {
@ -156,11 +136,6 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
return true; return true;
} }
@Override
public boolean mouseMoved(int screenX, int screenY) {
return false;
}
@Override @Override
public boolean scrolled(int amount) { public boolean scrolled(int amount) {
if (amount < 0 && cameraZoom > 0.3 || amount > 0 && cameraZoom < 3) { if (amount < 0 && cameraZoom > 0.3 || amount > 0 && cameraZoom < 3) {

View File

@ -2,21 +2,17 @@ package inf112.fiasko.roborally.gamewrapper.screens;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.InputMultiplexer; import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.Screen; import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.GlyphLayout; import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import inf112.fiasko.roborally.elementproperties.GameState; import inf112.fiasko.roborally.elementproperties.GameState;
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper; import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.gamewrapper.SimpleButton; import inf112.fiasko.roborally.gamewrapper.SimpleButton;
@ -27,6 +23,7 @@ import javax.swing.JOptionPane;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.badlogic.gdx.graphics.Color.BLACK;
import static com.badlogic.gdx.graphics.Color.GRAY; import static com.badlogic.gdx.graphics.Color.GRAY;
import static com.badlogic.gdx.graphics.Color.RED; import static com.badlogic.gdx.graphics.Color.RED;
import static com.badlogic.gdx.graphics.Color.WHITE; import static com.badlogic.gdx.graphics.Color.WHITE;
@ -34,17 +31,13 @@ import static com.badlogic.gdx.graphics.Color.WHITE;
/** /**
* This screen is used to let the user choose their program * This screen is used to let the user choose their program
*/ */
public class CardChoiceScreen extends InputAdapter implements Screen { public class CardChoiceScreen extends InteractiveScreen implements Screen {
private final RoboRallyWrapper roboRallyWrapper; private final RoboRallyWrapper roboRallyWrapper;
private final OrthographicCamera camera;
private final List<CardRectangle> cardRectangles; private final List<CardRectangle> cardRectangles;
private final ShapeRenderer shapeRenderer; private final ShapeRenderer shapeRenderer;
private final Viewport viewport;
private final List<CardRectangle> chosenCards; private final List<CardRectangle> chosenCards;
private final int maxCards; private final int maxCards;
private final Stage stage;
private final InputMultiplexer inputMultiplexer;
/** /**
* Instantiates a new card choice screen * Instantiates a new card choice screen
@ -54,10 +47,11 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) { public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) {
ProgrammingCardDeck deck = roboRallyWrapper.roboRallyGame.getPlayerHand(); ProgrammingCardDeck deck = roboRallyWrapper.roboRallyGame.getPlayerHand();
this.roboRallyWrapper = roboRallyWrapper; this.roboRallyWrapper = roboRallyWrapper;
camera = new OrthographicCamera(); maxCards = roboRallyWrapper.roboRallyGame.getProgramSize();
int applicationWidth = 600; if (maxCards == -1) {
int applicationHeight = 800; throw new IllegalArgumentException("This player should not be able to choose any cards at this point in " +
this.maxCards = roboRallyWrapper.roboRallyGame.getProgramSize(); "time.");
}
camera.setToOrtho(false, applicationWidth, applicationHeight); camera.setToOrtho(false, applicationWidth, applicationHeight);
viewport = new FitViewport(applicationWidth, applicationHeight, camera); viewport = new FitViewport(applicationWidth, applicationHeight, camera);
cardRectangles = new ArrayList<>(); cardRectangles = new ArrayList<>();
@ -69,8 +63,6 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
generateCards(deck); generateCards(deck);
this.chosenCards = new ArrayList<>(); this.chosenCards = new ArrayList<>();
stage = new Stage();
TextButton confirmCards = new SimpleButton("Confirm cards", roboRallyWrapper.font).getButton(); TextButton confirmCards = new SimpleButton("Confirm cards", roboRallyWrapper.font).getButton();
stage.addActor(confirmCards); stage.addActor(confirmCards);
confirmCards.setY(viewport.getWorldHeight() - confirmCards.getHeight()); confirmCards.setY(viewport.getWorldHeight() - confirmCards.getHeight());
@ -87,10 +79,15 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
* *
* @return An input listener * @return An input listener
*/ */
private InputListener getConfirmListener() { private ClickListener getConfirmListener() {
return new InputListener() { return new ClickListener() {
@Override @Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
if (chosenCards.size() == maxCards) { if (chosenCards.size() == maxCards) {
List<ProgrammingCard> oldProgram = roboRallyWrapper.roboRallyGame.getProgram(); List<ProgrammingCard> oldProgram = roboRallyWrapper.roboRallyGame.getProgram();
int lockedCardsInt = 5 - maxCards; int lockedCardsInt = 5 - maxCards;
@ -102,12 +99,10 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
roboRallyWrapper.roboRallyGame.setProgram(newProgram); roboRallyWrapper.roboRallyGame.setProgram(newProgram);
roboRallyWrapper.roboRallyGame.setGameState(GameState.CHOOSING_POWER_DOWN); roboRallyWrapper.roboRallyGame.setGameState(GameState.CHOOSING_POWER_DOWN);
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getPowerDownScreen(roboRallyWrapper)); roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getPowerDownScreen(roboRallyWrapper));
return true;
} else { } else {
JOptionPane.showMessageDialog(null, "You need to choose all your cards" JOptionPane.showMessageDialog(null, "You need to choose all your cards"
+ " before confirming."); + " before confirming.");
} }
return false;
} }
}; };
} }
@ -148,8 +143,8 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
@Override @Override
public void show() { public void show() {
super.show();
Gdx.input.setInputProcessor(inputMultiplexer); Gdx.input.setInputProcessor(inputMultiplexer);
stage.cancelTouchFocus();
} }
@Override @Override
@ -205,6 +200,13 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
float fontY = cardRectangle.rectangle.y + cardRectangle.rectangle.height - 30; float fontY = cardRectangle.rectangle.y + cardRectangle.rectangle.height - 30;
roboRallyWrapper.font.draw(roboRallyWrapper.batch, layout, fontX, fontY); roboRallyWrapper.font.draw(roboRallyWrapper.batch, layout, fontX, fontY);
drawCardSymbol(cardRectangle); drawCardSymbol(cardRectangle);
int chosenIndex = chosenCards.indexOf(cardRectangle);
if (chosenIndex != -1) {
roboRallyWrapper.font.setColor(BLACK);
roboRallyWrapper.font.draw(roboRallyWrapper.batch, String.valueOf(chosenIndex + 1),
cardRectangle.rectangle.x + cardRectangle.rectangle.width - 20, cardRectangle.rectangle.y + cardRectangle.rectangle.height - 5);
roboRallyWrapper.font.setColor(WHITE);
}
} }
} }

View File

@ -1,9 +1,7 @@
package inf112.fiasko.roborally.gamewrapper.screens; package inf112.fiasko.roborally.gamewrapper.screens;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox; import com.badlogic.gdx.scenes.scene2d.ui.SelectBox;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
@ -13,7 +11,6 @@ import com.badlogic.gdx.utils.viewport.FitViewport;
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper; import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.networking.RoboRallyClient; import inf112.fiasko.roborally.networking.RoboRallyClient;
import javax.swing.*; import javax.swing.*;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
@ -35,8 +32,6 @@ public class IPAddressScreen extends AbstractScreen {
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen * @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
*/ */
public IPAddressScreen(final RoboRallyWrapper roboRallyWrapper) { public IPAddressScreen(final RoboRallyWrapper roboRallyWrapper) {
stage = new Stage();
Skin skin = new Skin(Gdx.files.internal("uiskin.json")); Skin skin = new Skin(Gdx.files.internal("uiskin.json"));
TextButton joinButton = new TextButton("Join", skin); TextButton joinButton = new TextButton("Join", skin);
joinButton.setSize(300, 60); joinButton.setSize(300, 60);
@ -85,18 +80,12 @@ public class IPAddressScreen extends AbstractScreen {
stage.addActor(textInput); stage.addActor(textInput);
stage.addActor(joinButton); stage.addActor(joinButton);
camera = new OrthographicCamera();
viewport = new FitViewport(applicationWidth, applicationHeight, camera); viewport = new FitViewport(applicationWidth, applicationHeight, camera);
this.roboRallyWrapper = roboRallyWrapper; this.roboRallyWrapper = roboRallyWrapper;
camera.setToOrtho(false, applicationWidth, applicationHeight); camera.setToOrtho(false, applicationWidth, applicationHeight);
stage.setViewport(viewport); stage.setViewport(viewport);
} }
@Override
public void show() {
Gdx.input.setInputProcessor(stage);
}
@Override @Override
public void render(float delta) { public void render(float delta) {
super.render(delta); super.render(delta);

View File

@ -0,0 +1,48 @@
package inf112.fiasko.roborally.gamewrapper.screens;
import com.badlogic.gdx.InputProcessor;
/**
* This class overrides all InputProcessor methods to make cleaner abstract screens with input processors
*/
public abstract class InteractiveScreen extends AbstractScreen implements InputProcessor {
@Override
public boolean keyDown(int i) {
return false;
}
@Override
public boolean keyUp(int i) {
return false;
}
@Override
public boolean keyTyped(char c) {
return false;
}
@Override
public boolean touchDown(int i, int i1, int i2, int i3) {
return false;
}
@Override
public boolean touchUp(int i, int i1, int i2, int i3) {
return false;
}
@Override
public boolean touchDragged(int i, int i1, int i2) {
return false;
}
@Override
public boolean mouseMoved(int i, int i1) {
return false;
}
@Override
public boolean scrolled(int i) {
return false;
}
}

View File

@ -2,8 +2,6 @@ package inf112.fiasko.roborally.gamewrapper.screens;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.viewport.ExtendViewport; import com.badlogic.gdx.utils.viewport.ExtendViewport;
import inf112.fiasko.roborally.elementproperties.GameState; import inf112.fiasko.roborally.elementproperties.GameState;
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper; import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
@ -24,10 +22,8 @@ public class LoadingScreen extends AbstractScreen {
*/ */
public LoadingScreen(final RoboRallyWrapper roboRallyWrapper) { public LoadingScreen(final RoboRallyWrapper roboRallyWrapper) {
this.roboRallyWrapper = roboRallyWrapper; this.roboRallyWrapper = roboRallyWrapper;
camera = new OrthographicCamera();
camera.setToOrtho(false, applicationWidth, applicationHeight); camera.setToOrtho(false, applicationWidth, applicationHeight);
viewport = new ExtendViewport(applicationWidth, applicationHeight, camera); viewport = new ExtendViewport(applicationWidth, applicationHeight, camera);
stage = new Stage();
} }
@Override @Override

View File

@ -1,14 +1,12 @@
package inf112.fiasko.roborally.gamewrapper.screens; package inf112.fiasko.roborally.gamewrapper.screens;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.InputEvent; 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.Dialog; import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox; import com.badlogic.gdx.scenes.scene2d.ui.SelectBox;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.FitViewport;
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper; import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.gamewrapper.SimpleButton; import inf112.fiasko.roborally.gamewrapper.SimpleButton;
@ -32,9 +30,7 @@ public class LobbyScreen extends AbstractScreen {
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen * @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
*/ */
public LobbyScreen(final RoboRallyWrapper roboRallyWrapper) { public LobbyScreen(final RoboRallyWrapper roboRallyWrapper) {
camera = new OrthographicCamera();
viewport = new FitViewport(applicationWidth, applicationHeight, camera); viewport = new FitViewport(applicationWidth, applicationHeight, camera);
stage = new Stage();
TextButton startGameButton = new SimpleButton("Start", roboRallyWrapper.font).getButton(); TextButton startGameButton = new SimpleButton("Start", roboRallyWrapper.font).getButton();
stage.addActor(startGameButton); stage.addActor(startGameButton);
startGameButton.setY(applicationHeight / 2f - 50); startGameButton.setY(applicationHeight / 2f - 50);
@ -47,7 +43,6 @@ public class LobbyScreen extends AbstractScreen {
Dialog dialog = new Dialog("Setting", skin); Dialog dialog = new Dialog("Setting", skin);
final SelectBox<String> selectBox = new SelectBox<>(skin); final SelectBox<String> selectBox = new SelectBox<>(skin);
selectBox.setItems("Dizzy_Dash", "Checkmate", "Risky_Exchange"); selectBox.setItems("Dizzy_Dash", "Checkmate", "Risky_Exchange");
selectBox.setPosition(Gdx.graphics.getWidth() / 2f - 100, Gdx.graphics.getHeight() / 2f - 100); selectBox.setPosition(Gdx.graphics.getWidth() / 2f - 100, Gdx.graphics.getHeight() / 2f - 100);
@ -58,19 +53,23 @@ public class LobbyScreen extends AbstractScreen {
stage.addActor(selectBox); stage.addActor(selectBox);
startGameButton.addListener(new InputListener() { startGameButton.addListener(new ClickListener() {
@Override @Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
roboRallyWrapper.server.startGame(); roboRallyWrapper.server.startGame();
Map<Connection, String> playerNames = roboRallyWrapper.server.getPlayerNames(); Map<Connection, String> playerNames = roboRallyWrapper.server.getPlayerNames();
List<Player> playerList = IOUtil.playerGenerator(playerNames, List<Player> playerList = IOUtil.playerGenerator(playerNames,
roboRallyWrapper.server.getRobotID()); roboRallyWrapper.server.getRobotID());
for (Connection connection : playerNames.keySet()) { for (Connection connection : playerNames.keySet()) {
roboRallyWrapper.server.sendToClient(connection, new GameStartInfoResponse(selectBox.getSelected() + ".txt" roboRallyWrapper.server.sendToClient(connection, new GameStartInfoResponse(
, playerList, playerNames.get(connection))); selectBox.getSelected() + ".txt", playerList, playerNames.get(connection)));
} }
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(roboRallyWrapper)); roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(roboRallyWrapper));
return true;
} }
}); });
Gdx.input.setInputProcessor(stage); Gdx.input.setInputProcessor(stage);

View File

@ -1,10 +1,8 @@
package inf112.fiasko.roborally.gamewrapper.screens; package inf112.fiasko.roborally.gamewrapper.screens;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.InputEvent; 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.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.FitViewport;
import inf112.fiasko.roborally.elementproperties.GameState; import inf112.fiasko.roborally.elementproperties.GameState;
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper; import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
@ -25,9 +23,7 @@ public class PowerDownScreen extends AbstractScreen {
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen * @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
*/ */
public PowerDownScreen(final RoboRallyWrapper roboRallyWrapper) { public PowerDownScreen(final RoboRallyWrapper roboRallyWrapper) {
camera = new OrthographicCamera();
viewport = new FitViewport(applicationWidth, applicationHeight, camera); viewport = new FitViewport(applicationWidth, applicationHeight, camera);
stage = new Stage();
stage.setViewport(viewport); stage.setViewport(viewport);
TextButton powerDownButton = new SimpleButton("PowerDown", roboRallyWrapper.font).getButton(); TextButton powerDownButton = new SimpleButton("PowerDown", roboRallyWrapper.font).getButton();
stage.addActor(powerDownButton); stage.addActor(powerDownButton);
@ -35,12 +31,16 @@ public class PowerDownScreen extends AbstractScreen {
powerDownButton.setX(applicationWidth / 2f - powerDownButton.getWidth() / 2f); powerDownButton.setX(applicationWidth / 2f - powerDownButton.getWidth() / 2f);
this.roboRallyWrapper = roboRallyWrapper; this.roboRallyWrapper = roboRallyWrapper;
camera.setToOrtho(false, applicationWidth, applicationHeight); camera.setToOrtho(false, applicationWidth, applicationHeight);
powerDownButton.addListener(new InputListener() { powerDownButton.addListener(new ClickListener() {
@Override @Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
sendPowerDownStatus(true);
return true; return true;
} }
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
sendPowerDownStatus(true);
}
}); });
} }

View File

@ -1,11 +1,9 @@
package inf112.fiasko.roborally.gamewrapper.screens; package inf112.fiasko.roborally.gamewrapper.screens;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.InputEvent; 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.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.FitViewport;
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper; import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.gamewrapper.SimpleButton; import inf112.fiasko.roborally.gamewrapper.SimpleButton;
@ -26,18 +24,21 @@ public class StartMenuScreen extends AbstractScreen {
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen * @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
*/ */
public StartMenuScreen(final RoboRallyWrapper roboRallyWrapper) { public StartMenuScreen(final RoboRallyWrapper roboRallyWrapper) {
camera = new OrthographicCamera();
viewport = new FitViewport(applicationWidth, applicationHeight, camera); viewport = new FitViewport(applicationWidth, applicationHeight, camera);
stage = new Stage();
stage.setViewport(viewport); stage.setViewport(viewport);
TextButton 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);
this.roboRallyWrapper = roboRallyWrapper; this.roboRallyWrapper = roboRallyWrapper;
camera.setToOrtho(false, applicationWidth, applicationHeight); camera.setToOrtho(false, applicationWidth, applicationHeight);
serverButton.addListener(new InputListener() { serverButton.addListener(new ClickListener() {
@Override @Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
try { try {
roboRallyWrapper.server = new RoboRallyServer(roboRallyWrapper.defaultTCPPort, roboRallyWrapper.discoverUDPPort); roboRallyWrapper.server = new RoboRallyServer(roboRallyWrapper.defaultTCPPort, roboRallyWrapper.discoverUDPPort);
roboRallyWrapper.client = new RoboRallyClient(roboRallyWrapper); roboRallyWrapper.client = new RoboRallyClient(roboRallyWrapper);
@ -47,7 +48,6 @@ public class StartMenuScreen extends AbstractScreen {
//Hard fail //Hard fail
roboRallyWrapper.quit("Server could not be started"); roboRallyWrapper.quit("Server could not be started");
} }
return true;
} }
}); });
@ -56,24 +56,32 @@ public class StartMenuScreen extends AbstractScreen {
clientButton.setY(applicationHeight / 2f); clientButton.setY(applicationHeight / 2f);
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 ClickListener() {
@Override @Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getIPAddressScreen(roboRallyWrapper));
return true; return true;
} }
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getIPAddressScreen(roboRallyWrapper));
}
}); });
TextButton 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);
camera.setToOrtho(false, applicationWidth, applicationHeight); camera.setToOrtho(false, applicationWidth, applicationHeight);
quitButton.addListener(new InputListener() { quitButton.addListener(new ClickListener() {
@Override @Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
roboRallyWrapper.quit();
return true; return true;
} }
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
roboRallyWrapper.quit();
}
}); });
serverButton.setX(applicationWidth / 2f - serverButton.getWidth() - clientButton.getWidth() / 2 - 10); serverButton.setX(applicationWidth / 2f - serverButton.getWidth() - clientButton.getWidth() / 2 - 10);
clientButton.setX(applicationWidth / 2f - clientButton.getWidth() / 2); clientButton.setX(applicationWidth / 2f - clientButton.getWidth() / 2);

View File

@ -1,9 +1,7 @@
package inf112.fiasko.roborally.gamewrapper.screens; package inf112.fiasko.roborally.gamewrapper.screens;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputEvent;
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.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField; import com.badlogic.gdx.scenes.scene2d.ui.TextField;
@ -27,8 +25,6 @@ public class UsernameScreen extends AbstractScreen {
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen * @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
*/ */
public UsernameScreen(final RoboRallyWrapper roboRallyWrapper) { public UsernameScreen(final RoboRallyWrapper roboRallyWrapper) {
stage = new Stage();
Skin skin = new Skin(Gdx.files.internal("uiskin.json")); Skin skin = new Skin(Gdx.files.internal("uiskin.json"));
TextButton confirm = new TextButton("Confirm", skin); TextButton confirm = new TextButton("Confirm", skin);
confirm.setSize(300, 60); confirm.setSize(300, 60);
@ -43,7 +39,8 @@ public class UsernameScreen extends AbstractScreen {
public void touchUp(InputEvent e, float x, float y, int point, int button) { public void touchUp(InputEvent e, float x, float y, int point, int button) {
String userName = textInput.getText(); String userName = textInput.getText();
if (nameInvalid(userName)) { if (nameInvalid(userName)) {
JOptionPane.showMessageDialog(null, "Username cannot be empty."); JOptionPane.showMessageDialog(null, "Username cannot be empty or more " +
"than 20 characters.");
return; return;
} }
if (roboRallyWrapper.server == null) { if (roboRallyWrapper.server == null) {
@ -60,7 +57,6 @@ public class UsernameScreen extends AbstractScreen {
stage.addActor(textInput); stage.addActor(textInput);
stage.addActor(confirm); stage.addActor(confirm);
camera = new OrthographicCamera();
viewport = new FitViewport(applicationWidth, applicationHeight, camera); viewport = new FitViewport(applicationWidth, applicationHeight, camera);
this.roboRallyWrapper = roboRallyWrapper; this.roboRallyWrapper = roboRallyWrapper;
camera.setToOrtho(false, applicationWidth, applicationHeight); camera.setToOrtho(false, applicationWidth, applicationHeight);
@ -75,7 +71,7 @@ public class UsernameScreen extends AbstractScreen {
*/ */
private boolean nameInvalid(String userName) { private boolean nameInvalid(String userName) {
//TODO: Find a way to ask the server if the name is taken //TODO: Find a way to ask the server if the name is taken
return "".equals(userName); return "".equals(userName) || userName.length() > 20;
} }
@Override @Override

View File

@ -1,11 +1,9 @@
package inf112.fiasko.roborally.gamewrapper.screens; package inf112.fiasko.roborally.gamewrapper.screens;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.InputEvent; 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.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.FitViewport;
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper; import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.gamewrapper.SimpleButton; import inf112.fiasko.roborally.gamewrapper.SimpleButton;
@ -22,20 +20,22 @@ public class WinnerScreen extends AbstractScreen {
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen * @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
*/ */
public WinnerScreen(final RoboRallyWrapper roboRallyWrapper) { public WinnerScreen(final RoboRallyWrapper roboRallyWrapper) {
camera = new OrthographicCamera();
viewport = new FitViewport(applicationWidth, applicationHeight, camera); viewport = new FitViewport(applicationWidth, applicationHeight, camera);
stage = new Stage();
stage.setViewport(viewport); stage.setViewport(viewport);
TextButton 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);
camera.setToOrtho(false, applicationWidth, applicationHeight); camera.setToOrtho(false, applicationWidth, applicationHeight);
quitButton.addListener(new InputListener() { quitButton.addListener(new ClickListener() {
@Override @Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
Gdx.app.exit();
return true; return true;
} }
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
Gdx.app.exit();
}
}); });
quitButton.setX(applicationWidth / 2f + quitButton.getWidth() / 2); quitButton.setX(applicationWidth / 2f + quitButton.getWidth() / 2);
this.roboRallyWrapper = roboRallyWrapper; this.roboRallyWrapper = roboRallyWrapper;
@ -48,7 +48,8 @@ public class WinnerScreen extends AbstractScreen {
roboRallyWrapper.batch.setProjectionMatrix(camera.combined); roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
roboRallyWrapper.batch.begin(); roboRallyWrapper.batch.begin();
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "The winner is: ", applicationWidth / 2f - 380 / 2f, roboRallyWrapper.font.draw(roboRallyWrapper.batch, "The winner is: " +
roboRallyWrapper.roboRallyGame.getWinningPlayerName(), applicationWidth / 2f - 380 / 2f,
applicationHeight / 2f + 300, 380, 1, applicationHeight / 2f + 300, 380, 1,
true); true);
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click the button to exit the game", roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click the button to exit the game",