UI fully redone and revamped. Fixed some minor bugs

master
EmaMaker 2020-05-01 22:48:45 +02:00
parent 12e9b7f41a
commit 876c259511
15 changed files with 631 additions and 620 deletions

View File

@ -11,6 +11,7 @@ public class AndroidLauncher extends AndroidApplication {
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.useImmersiveMode = true;
initialize(new AMazeIng(), config);
}
}

View File

@ -10,6 +10,7 @@ import com.emamaker.amazeing.AMazeIng;
import com.emamaker.amazeing.maze.MazeGenerator;
import com.emamaker.amazeing.maze.settings.MazeSettings;
import com.emamaker.amazeing.player.MazePlayer;
import com.emamaker.amazeing.ui.screens.PreGameScreen;
import com.emamaker.voxelengine.block.CellId;
import com.emamaker.voxelengine.player.Player;
@ -85,8 +86,6 @@ public class GameManager {
}
resetCamera();
setCamera(new Vector3(mazeGen.w / 2, (MazeSettings.MAZEX + MazeSettings.MAZEZ) * 0.45f, mazeGen.h / 2),
new Vector3(0, -90, 0));
gameStarted = true;
}
@ -94,8 +93,12 @@ public class GameManager {
public void update() {
if (gameStarted && !anyoneWon) {
if (getShowGame())
if (getShowGame()) {
main.world.render();
resetCamera();
setCamera(new Vector3(mazeGen.w / 2, (MazeSettings.MAZEX + MazeSettings.MAZEZ) * 0.45f, mazeGen.h / 2),
new Vector3(0, -90, 0));
}
main.world.modelBatch.begin(main.world.cam);
if (players != null) {
@ -119,7 +122,9 @@ public class GameManager {
if (type == GameType.LOCAL) {
main.setScreen(main.uiManager.playersScreen);
} else if (type == GameType.SERVER) {
main.uiManager.preGameScreen.setGameType(GameType.SERVER);
((PreGameScreen)main.uiManager.preGameScreen)
.setGameType(GameType.SERVER);
main.setScreen(main.uiManager.preGameScreen);
}
}

View File

@ -25,6 +25,7 @@ import com.emamaker.amazeing.player.MazePlayer;
import com.emamaker.amazeing.player.MazePlayerLocal;
import com.emamaker.amazeing.player.MazePlayerRemote;
import com.emamaker.amazeing.player.PlayerUtils;
import com.emamaker.amazeing.ui.screens.PreGameScreen;
import com.esotericsoftware.kryonet.Client;
import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;
@ -76,7 +77,8 @@ public class GameClient {
toAdd.add("Local" + localPlrQueue.get(0).uuid);
client.sendTCP(object);
System.out.println("Received UUID " + localPlrQueue.get(0).uuid + " for player " + localPlrQueue.get(0) + " giving confirmation");
System.out.println("Received UUID " + localPlrQueue.get(0).uuid + " for player "
+ localPlrQueue.get(0) + " giving confirmation");
// When we receive the connection accept from the server, we can show the
// pre-game screen listing the players' names, setting this flag to let the main
@ -84,16 +86,17 @@ public class GameClient {
showPreGame = true;
} else if (object instanceof AddNewPlayer) {
AddNewPlayer msg = (AddNewPlayer) object;
if (!players.containsKey(msg.uuid) && !toAdd.contains("Local"+msg.uuid)) {
if (!players.containsKey(msg.uuid) && !toAdd.contains("Local" + msg.uuid)) {
toAdd.add("Remote" + msg.uuid);
System.out.println("Remote player with uuid " + msg.uuid.toString() + " has joined the game :)");
System.out
.println("Remote player with uuid " + msg.uuid.toString() + " has joined the game :)");
}
} else if (object instanceof RemovePlayer) {
RemovePlayer msg = (RemovePlayer) object;
if (players.containsKey(msg.uuid)) {
toRemove.add(msg.uuid);
System.out.println("Player with uuid " + msg.uuid.toString() + " is leaving the game :(");
}else {
} else {
System.out.println("Player remove received, but I don't know that player :/");
}
} else if (object instanceof NetworkCommon.UpdatePlayerTransformServer) {
@ -134,7 +137,7 @@ public class GameClient {
try {
client.connect(5000, addr, port);
System.out.println("Connecting to server...");
//Tell the server you just connected, but still no players have to be add
// Tell the server you just connected, but still no players have to be add
client.sendTCP(new JustConnected());
return true;
// Server communication after connection can go here, or in
@ -155,7 +158,8 @@ public class GameClient {
if (clientRunning) {
try {
for (String s : toAdd) {
if (!(players.containsKey(s.replace("Local", "")) || players.containsKey(s.replace("Remote", "")))) {
if (!(players.containsKey(s.replace("Local", ""))
|| players.containsKey(s.replace("Remote", "")))) {
if (s.startsWith("Local")) {
// System.out.println(s + " | " + s.replace("Local", "") + " | " + localPlrQueue.get(0).uuid);
if (localPlrQueue.get(0) != null) {
@ -185,7 +189,7 @@ public class GameClient {
// the server is running in the same instance, client if not
// In this way server host is shown the start game button.
if (!main.server.isRunning())
main.uiManager.preGameScreen.setGameType(GameType.CLIENT);
((PreGameScreen) main.uiManager.preGameScreen).setGameType(GameType.CLIENT);
main.setScreen(main.uiManager.preGameScreen);
showPreGame = false;
}

View File

@ -2,6 +2,7 @@ package com.emamaker.amazeing.maze.settings;
import java.util.Arrays;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
@ -13,21 +14,23 @@ public class MazeSetting {
/*This object holds whatever is needed for a single setting to be changed, this includes:
* A set of possible options
* Two buttons to go back and forth between the options
* Thread buttons to go back and forth between the options and reset them
* A label with the current option
* A label with the name of the option
* Methods to set the correct variables, this should be overwritten by every single class
*/
protected UIManager uiManager;
protected int currentOption = 0;
protected String[] options;
protected String name;
protected Table table;
private UIManager uiManager;
private Label currentOptLabel;
private int defaultOption;
private int prevState;
Label nameLabel, currentOptLabel;
TextButton backBtn, forthBtn, resetBtn;
public MazeSetting(String name_, String[] options_, UIManager uiManager_) {
this(name_, options_, 0, uiManager_);
}
@ -41,11 +44,11 @@ public class MazeSetting {
//Build the Table which will be later used to add this to the screen
table = new Table();
Label nameLabel = new Label(this.name, uiManager.skin);
nameLabel = new Label(this.name+"\t\t\t", uiManager.skin);
currentOptLabel = new Label(this.options[currentOption], uiManager.skin);
TextButton backBtn = new TextButton("<", uiManager.skin);
TextButton forthBtn = new TextButton(">", uiManager.skin);
TextButton resetBtn = new TextButton("R", uiManager.skin);
backBtn = new TextButton("<", uiManager.skin);
forthBtn = new TextButton(">", uiManager.skin);
resetBtn = new TextButton("R", uiManager.skin);
update();
// Add actions to the buttons
@ -73,12 +76,7 @@ public class MazeSetting {
}
});
table.row().expandX().fillX();
table.add(nameLabel).fillX();
table.add(backBtn).fillX();
table.add(currentOptLabel).fillX();
table.add(forthBtn).fillX();
table.add(resetBtn).fillX();
buildTable();
}
public Table getTable() {
@ -92,7 +90,6 @@ public class MazeSetting {
public void update() {
preUpdate();
customUpdate();
}
public void saveState() {
@ -103,12 +100,32 @@ public class MazeSetting {
currentOption = prevState;
}
public void buildTable() {
table.clear();
float width = Gdx.graphics.getWidth();
float height = Gdx.graphics.getHeight();
float d = (float) Math.sqrt(width*width + height*height);
float labScale = d * .00080f;
// float butto nDim = d * 0.05f;
nameLabel.setFontScale(labScale);
currentOptLabel.setFontScale(labScale);
backBtn.getLabel().setFontScale(labScale);
forthBtn.getLabel().setFontScale(labScale);
resetBtn.getLabel().setFontScale(labScale);
table.row().colspan(2).expandX().fillX();
table.add(nameLabel).fillX().expandX();
table.add(backBtn).fillX().expandX();
table.add(currentOptLabel).fillX().expandX();
table.add(forthBtn).fillX().expandX();
table.add(resetBtn).fillX().expandX();
}
public void preUpdate() {
this.currentOption = (this.currentOption+this.options.length)%this.options.length;
this.currentOptLabel.setText(this.options[currentOption]);
}
//This is the method to overwrite to update the MazeSettings variables
public void customUpdate() {}
}

View File

@ -18,7 +18,8 @@ public class MazeSettingDimension extends MazeSetting{
}
@Override
public void customUpdate(){
public void update(){
super.update();
String opt = options[currentOption];
String[] split = opt.split("x");
MazeSettings.MAZEX = Integer.valueOf(split[0]);

View File

@ -14,7 +14,8 @@ public class MazeSettingMaxPlayers extends MazeSetting{
}
@Override
public void customUpdate(){
public void update(){
super.update();
MazeSettings.MAXPLAYERS = Integer.valueOf(options[currentOption]);
}

View File

@ -17,7 +17,7 @@ public class MazeSettings {
public MazeSettings() {
//Add various settings here
setDim = new MazeSettingDimension("MAZE DIMENSIONS: ", new String[] {
setDim = new MazeSettingDimension("MAZE DIMENSIONS:", new String[] {
"10x10", "20x20", "30x30"
}, 1, AMazeIng.getMain().uiManager);
setPlayers = new MazeSettingMaxPlayers("MAX NUMBER OF PLAYERS: ", new String[] {

View File

@ -2,6 +2,9 @@ package com.emamaker.amazeing.ui;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.emamaker.amazeing.AMazeIng;
import com.emamaker.amazeing.ui.screens.PlayerChooseScreen;
@ -45,5 +48,17 @@ public class UIManager {
public void dispose() {
titleScreen.dispose();
}
public BitmapFont generatefont(int size) {
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("data/default.fnt"));
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = size;
parameter.magFilter = Texture.TextureFilter.Linear;
parameter.minFilter = Texture.TextureFilter.Linear;
BitmapFont font32 = generator.generateFont(parameter); // font size 32 pixels
font32.getData().setScale(0.15f);
generator.dispose();
return font32;
}
}

View File

@ -0,0 +1,123 @@
package com.emamaker.amazeing.ui.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.emamaker.amazeing.ui.UIManager;
public class MyScreen implements Screen{
//This method makes the UI super easy to scale and resize with just a little effort in code
//Main stage. Must only contain tableContainer
Stage stage;
//Container for main stage table. This must only contain table
Container<Table> tableContainer = new Container<Table>();
//Table that contains all the stage. Must be cleared any time the window is resize. Look at buildTable1()
Table table = new Table();
UIManager uiManager;
MyScreen prevScreen;
float width = Gdx.graphics.getWidth(), height = Gdx.graphics.getHeight();
static float sw, sh;
float cw, ch;
float cwmult = 0.8f, chmult = 1f;
public MyScreen(UIManager uiManager_) {
this.uiManager = uiManager_;
stage = new Stage(new ScreenViewport());
stage = new Stage(new ScreenViewport());
tableContainer.setActor(table);
stage.addActor(tableContainer);
// table.setDebug(true);
sw = width;
sh = height;
cw = sw * cwmult;
ch = sh * chmult;
createTable();
buildTable();
}
//Classes that inherit from this must use createTable to prepare the stage (create actors and listeners) and buildTable() to layout them
//buildTable1 make sure the table is cleared before it's layout, since position and sizes have to recalculated each time the window is resized
public void createTable() {}
public void buildTable() {
table.clear();
sw = width;
sh = height;
cw = sw * cwmult;
ch = sh * chmult;
tableContainer.setSize(cw, ch);
tableContainer.setPosition((sw - cw) / 2.0f, (sh - ch) / 2.0f);
tableContainer.fill();
}
public void update() {}
@Override
public void show() {
uiManager.main.multiplexer.addProcessor(stage);
}
@Override
public void hide() {
uiManager.main.multiplexer.removeProcessor(stage);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
update();
stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
stage.draw();
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
this.width = width;
this.height = height;
buildTable();
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
stage.dispose();
}
public float containerDiagonal() {
return (float) Math.sqrt( cw*cw + ch*ch );
}
public static float screenDiagonal() {
return (float) Math.sqrt( sw*sw + sh*sh );
}
public void setPrevScreen(MyScreen s) {
this.prevScreen = s;
}
}

View File

@ -5,132 +5,57 @@ import java.util.HashSet;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
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.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.emamaker.amazeing.maze.settings.MazeSettings;
import com.emamaker.amazeing.player.MazePlayer;
import com.emamaker.amazeing.player.MazePlayerLocal;
import com.emamaker.amazeing.player.PlayerUtils;
import com.emamaker.amazeing.ui.UIManager;
public class PlayerChooseScreen implements Screen {
UIManager uiManager;
Stage stage;
Table table;
public class PlayerChooseScreen extends MyScreen {
Label[] labels;
int currentLabel = 0;
ArrayList<MazePlayer> players = new ArrayList<MazePlayer>();
Screen thisScreen;
MyScreen thisScreen;
Container<Table> firstRowContainer;
Table firstRowTable;
Label instLab;
TextButton backBtn, setBtn, helpBtn, playBtn;
Dialog helpDlg;
public PlayerChooseScreen(UIManager uiManager_) {
uiManager = uiManager_;
show();
//
// stage = new Stage(new ScreenViewport());
//
// Container<Table> tableContainer = new Container<Table>();
//
// float sw = Gdx.graphics.getWidth();
// float sh = Gdx.graphics.getHeight();
//
// float cw = sw * 0.7f;
// float ch = sh * 0.5f;
//
// tableContainer.setSize(cw, ch);
// tableContainer.setPosition((sw - cw) / 2.0f, (sh - ch) / 2.0f);
// tableContainer.fillX();
//
// Table table = new Table(uiManager.skin);
//
// Label topLabel = new Label("A LABEL", uiManager.skin);
// topLabel.setAlignment(Align.center);
// Slider slider = new Slider(0, 100, 1, false, uiManager.skin);
// Label anotherLabel = new Label("ANOTHER LABEL", uiManager.skin);
// anotherLabel.setAlignment(Align.center);
//
// CheckBox checkBoxA = new CheckBox("Checkbox Left", uiManager.skin);
// CheckBox checkBoxB = new CheckBox("Checkbox Center", uiManager.skin);
// CheckBox checkBoxC = new CheckBox("Checkbox Right", uiManager.skin);
//
// Table buttonTable = new Table(uiManager.skin);
//
// TextButton buttonA = new TextButton("LEFT", uiManager.skin);
// TextButton buttonB = new TextButton("RIGHT", uiManager.skin);
//
// table.row().colspan(3).expandX().fillX();
// table.add(topLabel).fillX();
// table.row().colspan(3).expandX().fillX();
// table.add(slider).fillX();
// table.row().colspan(3).expandX().fillX();
// table.add(anotherLabel).fillX();
// table.row().expandX().fillX();
//
// table.add(checkBoxA).expandX().fillX();
// table.add(checkBoxB).expandX().fillX();
// table.add(checkBoxC).expandX().fillX();
// table.row().expandX().fillX();;
//
// table.add(buttonTable).colspan(3);
//
// buttonTable.pad(16);
// buttonTable.row().space(5);
// buttonTable.add(buttonA).width(cw/3.0f);
// buttonTable.add(buttonB).width(cw/3.0f);
//
// tableContainer.setActor(table);
// stage.addActor(tableContainer);
// float sw = Gdx.graphics.getWidth();
// float sh = Gdx.graphics.getHeight();
// Table buttonTable = new Table();
//
// table.add(buttonTable).colspan(3);
// buttonTable.pad(16);
// buttonTable.add(backBtn).width(80);
// buttonTable.add(playBtn).width(80);
//
// tableContainer.setActor(table);
// stage.addActor(tableContainer);
super(uiManager_);
chmult = 0.8f;
}
@Override
public void show() {
public void createTable() {
super.createTable();
thisScreen = this;
labels = new Label[MazeSettings.MAXPLAYERS];
stage = new Stage(new ScreenViewport());
Container<Table> tableContainer = new Container<Table>();
Table table = new Table();
firstRowContainer = new Container<Table>();
firstRowTable = new Table();
float cw = stage.getWidth();
float ch = stage.getHeight();
firstRowContainer.setActor(firstRowTable);
tableContainer.setSize(cw, ch);
tableContainer.setPosition(0, 0);
Label instLab = new Label("Use WASD, ARROWS, or button on controller to join the match", uiManager.skin);
TextButton backBtn = new TextButton("<", uiManager.skin);
TextButton setBtn = new TextButton("Settings", uiManager.skin);
TextButton helpBtn = new TextButton("?", uiManager.skin);
TextButton playBtn = new TextButton("Play!", uiManager.skin);
final Dialog helpDlg = new Dialog("Help", uiManager.skin);
instLab = new Label("Use WASD, ARROWS, or button on controller to join the match", uiManager.skin);
backBtn = new TextButton("<", uiManager.skin);
setBtn = new TextButton("Settings", uiManager.skin);
helpBtn = new TextButton("?", uiManager.skin);
playBtn = new TextButton("Play!", uiManager.skin);
/* HELP DIALOG */
helpDlg = new Dialog("Help", uiManager.skin);
helpDlg.text("Here you can start a singleplayer or multiplayer game on the local machine:\n"
+ "For keyboard players, pressing W,A,S,D or the directional arrows will toggle two different players.\n"
+ "Pressing a button on a controller will toggle a player.\n"
@ -183,51 +108,60 @@ public class PlayerChooseScreen implements Screen {
}
});
}
@Override
public void buildTable() {
super.buildTable();
firstRowTable.clear();
labels = new Label[MazeSettings.MAXPLAYERS];
// Labels to know if players joined
for (int i = 0; i < labels.length; i++) {
labels[i] = new Label("-- empty slot --", uiManager.skin);
}
/* BUILD UP TABLE */
Table firstRowTable = new Table();
float d = containerDiagonal();
float labScale = d * .00080f;
float buttonDim = d * 0.05f;
firstRowContainer.setSize(cw, ch * 0.2f);
firstRowContainer.setPosition(tableContainer.getX(), ch * 0.1f);
firstRowContainer.fill();
helpDlg.setScale(d * 0.00075f);
helpDlg.setPosition(width / 2, height / 2);
instLab.setFontScale(labScale);
backBtn.getLabel().setFontScale(labScale);
setBtn.getLabel().setFontScale(labScale);
helpBtn.getLabel().setFontScale(labScale);
playBtn.getLabel().setFontScale(labScale);
firstRowTable.add(backBtn).fillX().expandX().space(cw * 0.005f).width(buttonDim).height(buttonDim);
firstRowTable.add(instLab).space(cw * 0.25f);
firstRowTable.add(setBtn).fillX().expandX().space(cw * 0.005f).height(buttonDim);
firstRowTable.add(helpBtn).fillX().expandX().space(cw * 0.005f).width(buttonDim).height(buttonDim);
firstRowTable.add(backBtn).width(50).height(50).fillX().expandX().space(cw * 0.005f);
firstRowTable.add(instLab).height(50).fillX().expandX().space(cw * 0.25f);
firstRowTable.add(setBtn).height(50).fillX().expandX().space(cw * 0.005f);
firstRowTable.add(helpBtn).width(50).height(50).fillX().expandX().space(cw * 0.005f);
firstRowTable.setOrigin(Align.center | Align.top);
table.row().colspan(MazeSettings.MAXPLAYERS == 2 ? 2 : 4);
table.add(firstRowTable);
table.add(firstRowContainer);
for (int i = 0; i < labels.length; i++) {
labels[i].setFontScale(labScale);
if (i % 4 == 0)
table.row().expandY().fillY();
table.add(labels[i]).space(1);
}
table.row().colspan(MazeSettings.MAXPLAYERS == 2 ? 2 : 4);
table.add(playBtn).fillX().width(cw * 0.06f);
tableContainer.setActor(table);
stage.addActor(tableContainer);
uiManager.main.multiplexer.addProcessor(stage);
}
@Override
public void hide() {
uiManager.main.multiplexer.removeProcessor(stage);
// table.add(playBtn).fillX().width(buttonDim*2f).height(buttonDim);
table.add(playBtn).fillX().expandX().height(buttonDim);
}
MazePlayerLocal p;
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act();
stage.draw();
public void update() {
// Consantly search for new players to be added
// First search for keyboard players (WASD and ARROWS)
if (Gdx.input.isKeyJustPressed(Keys.W) || Gdx.input.isKeyJustPressed(Keys.A)
@ -247,33 +181,11 @@ public class PlayerChooseScreen implements Screen {
// togglePlayer(p);
// }
// }
// Update labels
for (int i = 0; i < labels.length; i++) {
labels[i].setText(i < players.size() ? "-- Player Ready! --" : "-- empty slot --");
}
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
stage.dispose();
}
}

View File

@ -1,67 +1,76 @@
package com.emamaker.amazeing.ui.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
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.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.emamaker.amazeing.manager.GameType;
import com.emamaker.amazeing.maze.settings.MazeSettings;
import com.emamaker.amazeing.player.MazePlayer;
import com.emamaker.amazeing.ui.UIManager;
public class PreGameScreen implements Screen {
UIManager uiManager;
Stage stage;
Table table;
public class PreGameScreen extends MyScreen {
Label[] labels;
MazePlayer[] players, tmp;
MazePlayer[] players;
int nPlayers, nPlayersOld;
// GameType we are runnig. assuming server for default. If client, the StartGame
// button shouldn't appear
GameType type = GameType.SERVER;
MyScreen thisScreen;
Screen thisScreen;
Container<Table> firstRowContainer;
Table firstRowTable;
Label instLab;
TextButton backBtn, setBtn, helpBtn, playBtn;
Dialog helpDlg;
public PreGameScreen(UIManager uiManager_) {
uiManager = uiManager_;
super(uiManager_);
chmult = 0.8f;
}
@Override
public void show() {
public void createTable() {
super.createTable();
thisScreen = this;
labels = new Label[MazeSettings.MAXPLAYERS];
players = new MazePlayer[MazeSettings.MAXPLAYERS];
// tmp = new MazePlayer[MazeSettings.MAXPLAYERS];
nPlayers = 0;
nPlayersOld = 0;
stage = new Stage(new ScreenViewport());
Container<Table> tableContainer = new Container<Table>();
Table table = new Table();
firstRowTable = new Table();
firstRowContainer = new Container<Table>();
float cw = stage.getWidth();
float ch = stage.getHeight();
instLab = new Label("Waiting for players to join...", uiManager.skin);
backBtn = new TextButton("Back", uiManager.skin);
setBtn = new TextButton("Settings", uiManager.skin);
helpBtn = new TextButton("?", uiManager.skin);
playBtn = new TextButton("Start the match!", uiManager.skin);
tableContainer.setSize(cw, ch);
tableContainer.setPosition(0, 0);
Label instLab = new Label("Waiting for players to join...", uiManager.skin);
TextButton backBtn = new TextButton("Back", uiManager.skin);
TextButton setBtn = new TextButton("Settings", uiManager.skin);
TextButton helpBtn = new TextButton("?", uiManager.skin);
TextButton playBtn = new TextButton("Start the match!", uiManager.skin);
/* HELP DIALOG */
helpDlg = new Dialog("Help", uiManager.skin);
helpDlg.text("An online game is about to start!\n"
+ "If you're a client, just wait for the server to start the game.\n"
+ "If you're a server, wait for players and start the game pressing the \"Start the match!\" button.\n"
+ "How to join (for both client and server):\n"
+ "On a computer players can join or leave the game pressing WASD, Arrow buttons or\n"
+ "a button on the controller\n" + "On mobile players can be toggled using the buttons below.");
TextButton helpDlgOkBtn = new TextButton("OK", uiManager.skin);
helpDlg.button(helpDlgOkBtn);
helpDlgOkBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
helpDlg.hide();
return true;
}
});
if (type == GameType.CLIENT)
instLab.setText("Waiting for server to start the game...");
@ -86,49 +95,71 @@ public class PreGameScreen implements Screen {
return true;
}
});
if (type == GameType.SERVER) {
// Add actions to the buttons
playBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
hide();
uiManager.main.server.startGame();
return true;
}
});
// Add actions to the buttons
setBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
hide();
uiManager.setScreen.setPrevScreen(thisScreen);
uiManager.main.setScreen(uiManager.setScreen);
return true;
}
});
}
// Add actions to the buttons
playBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
hide();
uiManager.main.server.startGame();
return true;
}
});
// Add actions to the buttons
setBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
hide();
uiManager.setScreen.setPrevScreen(thisScreen);
uiManager.main.setScreen(uiManager.setScreen);
System.out.println("Bup");
return true;
}
});
// Add actions to the buttons
helpBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Make this appear help dialog (TODO)");
helpDlg.show(stage);
return true;
}
});
Table firstRowTable = new Table();
firstRowContainer.setActor(firstRowTable);
tableContainer.setActor(table);
stage.addActor(tableContainer);
}
firstRowTable.add(backBtn).width(50).height(50).fillX().expandX().space(cw * 0.005f);
firstRowTable.add(instLab).height(50).fillX().expandX().space(cw * 0.25f);
@Override
public void buildTable() {
super.buildTable();
firstRowTable.clear();
float d = containerDiagonal();
float labScale = d * .00080f;
float buttonDim = d * 0.05f;
firstRowContainer.setSize(cw, ch * 0.2f);
firstRowContainer.setPosition(tableContainer.getX(), ch * 0.1f);
firstRowContainer.fill();
instLab.setFontScale(labScale);
backBtn.getLabel().setFontScale(labScale);
setBtn.getLabel().setFontScale(labScale);
helpBtn.getLabel().setFontScale(labScale);
playBtn.getLabel().setFontScale(labScale);
firstRowTable.add(backBtn).fillX().expandX().space(cw * 0.005f).width(buttonDim).height(buttonDim);
firstRowTable.add(instLab).space(cw * 0.25f);
if (type == GameType.SERVER)
firstRowTable.add(setBtn).height(50).fillX().expandX().space(cw * 0.005f);
firstRowTable.add(helpBtn).width(50).height(50).fillX().expandX().space(cw * 0.005f);
firstRowTable.setOrigin(Align.center | Align.top);
table.row().colspan(4);
firstRowTable.add(setBtn).fillX().expandX().space(cw * 0.005f).height(buttonDim);
firstRowTable.add(helpBtn).fillX().expandX().space(cw * 0.005f).width(buttonDim).height(buttonDim);
table.add(firstRowTable);
table.row().colspan(MazeSettings.MAXPLAYERS == 2 ? 2 : 4);
table.add(firstRowContainer);
for (int i = 0; i < labels.length; i++) {
labels[i].setFontScale(labScale);
if (i % 4 == 0)
table.row().expandY().fillY();
table.add(labels[i]).space(1);
@ -136,40 +167,21 @@ public class PreGameScreen implements Screen {
if (type == GameType.SERVER) {
table.row().colspan(4);
table.add(playBtn).fillX().width(cw * 0.06f);
table.add(playBtn).fillX().width(buttonDim * 2f).height(buttonDim);
}
tableContainer.setActor(table);
stage.addActor(tableContainer);
uiManager.main.multiplexer.addProcessor(stage);
}
@Override
public void hide() {
uiManager.main.multiplexer.removeProcessor(stage);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act();
stage.draw();
public void update() {
instLab.setText(type.toString() + ": Waiting for players to join...");
// Constantly update player labels, comparing with the remote players present on
// server
nPlayers = type == GameType.SERVER ? uiManager.main.server.remotePlayers.values().size()
: uiManager.main.client.players.size();
// tmp = type == GameType.SERVER
// ? Arrays.copyOf(uiManager.main.server.remotePlayers.values().toArray(),
// uiManager.main.server.remotePlayers.values().size(), MazePlayer[].class)
// : Arrays.copyOf(uiManager.main.client.players.toArray(), uiManager.main.client.players.size(),
// MazePlayer[].class);
if (nPlayers != nPlayersOld) {
// Update Labels
for (int i = 0; i < labels.length; i++) {
labels[i].setText(i < nPlayers ? "-- Player Ready! --" : "-- empty slot --" );
labels[i].setText(i < nPlayers ? "-- Player Ready! --" : "-- empty slot --");
}
}
nPlayersOld = nPlayers;
@ -184,25 +196,4 @@ public class PreGameScreen implements Screen {
return type;
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
stage.dispose();
}
}

View File

@ -1,49 +1,44 @@
package com.emamaker.amazeing.ui.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
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.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextArea;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.emamaker.amazeing.manager.GameType;
import com.emamaker.amazeing.ui.UIManager;
public class ServerJoinScreen implements Screen {
public class ServerJoinScreen extends MyScreen {
Stage stage;
UIManager uiManager;
Label instLab, srvIpL;
TextButton backBtn, connectBtn, helpBtn;
TextArea srvIp;
Container<Table> firstRowContainer;
Table firstRowTable;
public ServerJoinScreen(UIManager uiManager_) {
super(uiManager_);
chmult=.8f;
}
uiManager = uiManager_;
stage = new Stage(new ScreenViewport());
Container<Table> tableContainer = new Container<Table>();
Table table = new Table();
float cw = stage.getWidth();
float ch = stage.getHeight();
tableContainer.setSize(cw, ch);
tableContainer.setPosition(0, 0);
Label instLab = new Label("Enter ip address and port and connect to the server!", uiManager.skin);
TextButton backBtn = new TextButton("Main menu", uiManager.skin);
TextButton connectBtn = new TextButton("Connect to the server!", uiManager.skin);
TextButton helpBtn = new TextButton("?", uiManager.skin);
Label srvIpL = new Label("Server IP: ", uiManager.skin);
Label srvPortL = new Label("Server Port: ", uiManager.skin);
final TextArea srvIp = new TextArea("", uiManager.skin);
final TextArea srvPort = new TextArea("", uiManager.skin);
@Override
public void createTable() {
super.createTable();
firstRowTable = new Table();
firstRowContainer = new Container<Table>();
firstRowContainer.setActor(firstRowTable);
instLab = new Label("Enter ip address and port and connect to the server!", uiManager.skin);
backBtn = new TextButton("<", uiManager.skin);
connectBtn = new TextButton("Connect to the server!", uiManager.skin);
helpBtn = new TextButton("?", uiManager.skin);
srvIpL = new Label("Server IP: ", uiManager.skin);
srvIp = new TextArea("", uiManager.skin);
final Dialog helpDlg = new Dialog("Help", uiManager.skin);
/* HELP DIALOG */
@ -93,72 +88,57 @@ public class ServerJoinScreen implements Screen {
connectBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
if (uiManager.main.client.start(srvIp.getText(), Integer.valueOf(srvPort.getText()))) {
hide();
uiManager.preGameScreen.setGameType(uiManager.main.server.isRunning() ? GameType.SERVER : GameType.CLIENT);
uiManager.main.setScreen(uiManager.preGameScreen);
}else
try {
String addr = srvIp.getText().split(":")[0];
String port = srvIp.getText().split(":")[1];
if (uiManager.main.client.start(addr, Integer.valueOf(port))) {
hide();
uiManager.preGameScreen.setGameType(uiManager.main.server.isRunning() ? GameType.SERVER : GameType.CLIENT);
uiManager.main.setScreen(uiManager.preGameScreen);
} else {
failDlg.show(stage);
}
} catch (Exception e) {
failDlg.show(stage);
}
return true;
}
});
}
Table firstRowTable = new Table();
firstRowTable.add(backBtn).fillX().expandX().space(cw * 0.005f);
firstRowTable.add(instLab).height(50).fillX().expandX().space(cw * 0.25f);
firstRowTable.add(helpBtn).width(50).height(50).fillX().expandX().space(cw * 0.005f);
firstRowTable.setOrigin(Align.center | Align.top);
@Override
public void buildTable() {
super.buildTable();
firstRowTable.clear();
float d = containerDiagonal();
float labScale = d * .00080f;
float buttonDim = d * 0.05f;
firstRowContainer.setSize(cw, ch * 0.2f);
firstRowContainer.setPosition(tableContainer.getX(), ch * 0.1f);
firstRowContainer.fill();
instLab.setFontScale(labScale);
backBtn.getLabel().setFontScale(labScale);
helpBtn.getLabel().setFontScale(labScale);
firstRowTable.add(backBtn).fillX().expandX().space(cw * 0.005f).width(buttonDim).height(buttonDim);
firstRowTable.add(instLab).space(cw * 0.25f);
firstRowTable.add(helpBtn).fillX().expandX().space(cw * 0.005f).width(buttonDim).height(buttonDim);
table.row().colspan(4);
table.add(firstRowTable);
table.row().colspan(2);
table.add(srvIpL).expandX();
table.add(srvIp).expandX();
table.row().colspan(2);
table.add(srvPortL).fillX().expandX();
table.add(srvPort).fillX().expandX();
table.add(firstRowContainer);
table.row().colspan(2).fillX().expandX();
table.add(srvIpL).space(buttonDim).width(buttonDim*4f).height(buttonDim*0.5f).fillY().expandY();
table.add(srvIp).space(buttonDim).width(buttonDim*4f).height(buttonDim*0.5f).fillY().expandY();
table.row().colspan(4);
table.add(connectBtn).fillX().expandX();
tableContainer.setActor(table);
stage.addActor(tableContainer);
}
@Override
public void show() {
uiManager.main.multiplexer.addProcessor(stage);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act();
stage.draw();
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}
@Override
public void hide() {
uiManager.main.multiplexer.removeProcessor(stage);
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
// table.add(connectBtn).fillX().width(buttonDim*3f).height(buttonDim);
table.add(connectBtn).fillX().expandX().height(buttonDim);
}
}

View File

@ -1,50 +1,46 @@
package com.emamaker.amazeing.ui.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
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.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextArea;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.emamaker.amazeing.manager.GameType;
import com.emamaker.amazeing.ui.UIManager;
public class ServerLaunchScreen implements Screen {
public class ServerLaunchScreen extends MyScreen {
Stage stage;
UIManager uiManager;
Screen thisScreen;
MyScreen thisScreen;
Label instLab, srvPortL;
TextButton backBtn, connectBtn, setBtn, helpBtn;
TextArea srvPort;
Table firstRowTable;
Container<Table> firstRowContainer;
public ServerLaunchScreen(UIManager uiManager_) {
uiManager = uiManager_;
super(uiManager_);
thisScreen = this;
chmult = .8f;
}
@Override
public void createTable() {
super.createTable();
stage = new Stage(new ScreenViewport());
Container<Table> tableContainer = new Container<Table>();
Table table = new Table();
float cw = stage.getWidth();
float ch = stage.getHeight();
tableContainer.setSize(cw, ch);
tableContainer.setPosition(0, 0);
Label instLab = new Label("Enter the port the server must start on", uiManager.skin);
TextButton backBtn = new TextButton("<", uiManager.skin);
TextButton connectBtn = new TextButton("Launch the server!", uiManager.skin);
TextButton setBtn = new TextButton("Settings", uiManager.skin);
TextButton helpBtn = new TextButton("?", uiManager.skin);
Label srvPortL = new Label("Port: ", uiManager.skin);
final TextArea srvPort = new TextArea("", uiManager.skin);
firstRowTable = new Table();
firstRowContainer = new Container<Table>();
instLab = new Label("Enter the port the server must start on", uiManager.skin);
backBtn = new TextButton("<", uiManager.skin);
connectBtn = new TextButton("Launch the server!", uiManager.skin);
setBtn = new TextButton("Settings", uiManager.skin);
helpBtn = new TextButton("?", uiManager.skin);
srvPortL = new Label("Port: ", uiManager.skin);
srvPort = new TextArea("", uiManager.skin);
final Dialog helpDlg = new Dialog("Help", uiManager.skin);
/* HELP DIALOG */
@ -117,60 +113,40 @@ public class ServerLaunchScreen implements Screen {
}
});
Table firstRowTable = new Table();
firstRowTable.add(backBtn).fillX().expandX().space(cw * 0.005f);
firstRowTable.add(instLab).height(50).fillX().expandX().space(cw * 0.25f);
firstRowTable.add(setBtn).width(50).height(50).fillX().expandX().space(cw * 0.005f);
firstRowTable.add(helpBtn).width(50).height(50).fillX().expandX().space(cw * 0.005f);
firstRowTable.setOrigin(Align.center | Align.top);
firstRowContainer.setActor(firstRowTable);
}
@Override
public void buildTable() {
super.buildTable();
firstRowTable.clear();
float d = containerDiagonal();
float labScale = d * .00080f;
float buttonDim = d * 0.05f;
firstRowContainer.setSize(cw, ch * 0.2f);
firstRowContainer.setPosition(tableContainer.getX(), ch * 0.1f);
firstRowContainer.fill();
instLab.setFontScale(labScale);
backBtn.getLabel().setFontScale(labScale);
helpBtn.getLabel().setFontScale(labScale);
firstRowTable.add(backBtn).fillX().expandX().space(cw * 0.005f).width(buttonDim).height(buttonDim);
firstRowTable.add(instLab).space(cw * 0.25f);
firstRowTable.add(helpBtn).fillX().expandX().space(cw * 0.005f).width(buttonDim).height(buttonDim);
table.row().colspan(4);
table.add(firstRowTable);
table.row().colspan(2);
table.add(srvPortL).expandX();
table.add(srvPort).expandX();
table.add(firstRowContainer);
table.row().colspan(2).fillX().expandX();
table.add(srvPortL).space(buttonDim).width(buttonDim*4f).height(buttonDim*0.5f).fillY().expandY();
table.add(srvPort).space(buttonDim).width(buttonDim*4f).height(buttonDim*0.5f).fillY().expandY();
table.row().colspan(4);
table.add(connectBtn).fillX().expandX();
tableContainer.setActor(table);
stage.addActor(tableContainer);
table.add(connectBtn).fillX().width(buttonDim*3f).height(buttonDim);
}
@Override
public void show() {
uiManager.main.multiplexer.addProcessor(stage);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act();
stage.draw();
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}
@Override
public void hide() {
uiManager.main.multiplexer.removeProcessor(stage);
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
}

View File

@ -1,47 +1,45 @@
package com.emamaker.amazeing.ui.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
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.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.emamaker.amazeing.maze.settings.MazeSetting;
import com.emamaker.amazeing.maze.settings.MazeSettings;
import com.emamaker.amazeing.ui.UIManager;
public class SettingsScreen implements Screen{
UIManager uiManager;
Stage stage;
Screen prevScreen;
public class SettingsScreen extends MyScreen {
Label instLab;
TextButton backBtn, resetBtn, saveBtn, helpBtn;
ScrollPane scrollPane;
Container<Table> firstRowContainer;
Table firstRowTable;
public SettingsScreen(UIManager uiManager_) {
this.uiManager = uiManager_;
stage = new Stage(new ScreenViewport());
Container<Table> tableContainer = new Container<Table>();
Table table = new Table();
super(uiManager_);
chmult = 0.8f;
}
float cw = stage.getWidth();
float ch = stage.getHeight();
@Override
public void createTable() {
super.createTable();
firstRowContainer = new Container<Table>();
firstRowTable = new Table();
tableContainer.setSize(cw, ch);
tableContainer.setPosition(0, 0);
Label instLab = new Label("Here you can customize game settings!", uiManager.skin);
TextButton backBtn = new TextButton("<", uiManager.skin);
TextButton resetBtn = new TextButton("Reset All", uiManager.skin);
TextButton saveBtn = new TextButton("Save", uiManager.skin);
TextButton helpBtn = new TextButton("?", uiManager.skin);
firstRowContainer.setActor(firstRowTable);
instLab = new Label("Here you can customize game settings!", uiManager.skin);
backBtn = new TextButton("<", uiManager.skin);
resetBtn = new TextButton("Reset All", uiManager.skin);
saveBtn = new TextButton("Save", uiManager.skin);
helpBtn = new TextButton("?", uiManager.skin);
scrollPane = new ScrollPane(setSettings(), uiManager.skin);
final Dialog helpDlg = new Dialog("Help", uiManager.skin);
/* HELP DIALOG */
helpDlg.text("Here you can customize game settings:\n"
@ -58,11 +56,11 @@ public class SettingsScreen implements Screen{
});
/* BACK DIALOG */
final Dialog backDlg = new Dialog("Go Back", uiManager.skin);
backDlg.text("Are you sure you want to go back without saving changes?\nThis cannot be reverted");
backDlg.text("Are you sure you want to go back without saving changes?\nThis cannot be reverted");
TextButton backDlgCancelBtn = new TextButton("Cancel", uiManager.skin);
TextButton backDlgOkBtn = new TextButton("OK", uiManager.skin);
backDlg.button(backDlgOkBtn);
backDlg.button(backDlgCancelBtn);
backDlg.button(backDlgOkBtn);
backDlgOkBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
@ -81,7 +79,7 @@ public class SettingsScreen implements Screen{
});
/* RESET DIALOG */
final Dialog resetDlg = new Dialog("Reset All Settings", uiManager.skin);
resetDlg.text("Are you sure you want to reset all settings?\nThis cannot be reverted");
resetDlg.text("Are you sure you want to reset all settings?\nThis cannot be reverted");
TextButton resetDlgCancelBtn = new TextButton("Cancel", uiManager.skin);
TextButton resetDlgOkBtn = new TextButton("OK", uiManager.skin);
resetDlg.button(resetDlgOkBtn);
@ -101,8 +99,8 @@ public class SettingsScreen implements Screen{
return true;
}
});
/*ACTIONS TO BUTTONS*/
/* ACTIONS TO BUTTONS */
backBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
@ -132,79 +130,68 @@ public class SettingsScreen implements Screen{
return true;
}
});
}
@Override
public void buildTable() {
super.buildTable();
firstRowTable.clear();
Table firstRowTable = new Table();
firstRowTable.add(backBtn).width(50).height(50).fillX().expandX().space(cw*0.005f);
firstRowTable.add(instLab).height(50).fillX().expandX().space(cw*0.25f);
firstRowTable.add(helpBtn).width(50).height(50).fillX().expandX().space(cw*0.005f);
firstRowTable.setOrigin(Align.center | Align.top);
float d = containerDiagonal();
float labScale = d * .00080f;
float buttonDim = d * 0.05f;
firstRowContainer.setSize(cw, ch * 0.2f);
firstRowContainer.setPosition(tableContainer.getX(), ch * 0.1f);
firstRowContainer.fill();
instLab.setFontScale(labScale);
backBtn.getLabel().setFontScale(labScale);
helpBtn.getLabel().setFontScale(labScale);
resetBtn.getLabel().setFontScale(labScale);
saveBtn.getLabel().setFontScale(labScale);
firstRowTable.add(backBtn).fillX().expandX().space(cw * 0.005f).width(buttonDim).height(buttonDim);
firstRowTable.add(instLab).space(cw * 0.25f);
firstRowTable.add(helpBtn).fillX().expandX().space(cw * 0.005f).width(buttonDim).height(buttonDim);;
table.row().colspan(4);
table.add(firstRowTable);
table.row().colspan(4);
table.add(setSettings());
table.add(firstRowContainer);
table.row().colspan(2);
table.add(resetBtn).fillX().expandX();
table.add(saveBtn).fillX().expandX();
table.add(scrollPane).fill().expand();
tableContainer.setActor(table);
stage.addActor(tableContainer);
table.row();
table.add(resetBtn).fillX().expandX().width(buttonDim*2f).height(buttonDim);
table.add(saveBtn).fillX().expandX().width(buttonDim*2f).height(buttonDim);
// table.add(resetBtn).fillX().expandX().pad(buttonDim/2).height(buttonDim);
// table.add(saveBtn).fillX().expandX().pad(buttonDim/2).height(buttonDim);
}
VerticalGroup setSettings() {
VerticalGroup group = new VerticalGroup().space(5).pad(5).fill();
group.addActor(MazeSettings.setDim.getTable());
group.addActor(MazeSettings.setPlayers.getTable());
public Table setSettings() {
Table table = new Table();
table.row().colspan(2);
table.add(MazeSettings.setDim.getTable());
table.row().colspan(2);
table.add(MazeSettings.setPlayers.getTable());
return group;
return table;
}
@Override
public void resize(int width, int height) {
super.resize(width, height);
for(MazeSetting s : MazeSettings.settings) s.buildTable();
}
void saveStates() {
MazeSettings.setDim.saveState();
MazeSettings.setPlayers.saveState();
}
public void setPrevScreen(Screen s) {
this.prevScreen = s;
}
@Override
public void show() {
MazeSettings.saveStates();
uiManager.main.multiplexer.addProcessor(stage);
}
@Override
public void hide() {
uiManager.main.multiplexer.removeProcessor(stage);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0,0,0,0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act();
stage.draw();
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
}

View File

@ -1,60 +1,70 @@
package com.emamaker.amazeing.ui.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
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.Table;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.emamaker.amazeing.ui.UIManager;
public class TitleScreen implements Screen {
public class TitleScreen extends MyScreen {
Label amazeingLab;
TextButton setBut, makeSrvBtn, joinSrvBtn, localBut, quitBut;
UIManager uiManager;
Stage stage;
public TitleScreen(UIManager uiManager_) {
uiManager = uiManager_;
stage = new Stage(new ScreenViewport());
Table table = new Table();
super(uiManager_);
}
VerticalGroup mainScreenGroup = new VerticalGroup().space(5).pad(5).fill();
TextButton setBut = new TextButton("Customize Game Settings", uiManager.skin);
mainScreenGroup.addActor(setBut);
TextButton makeSrvBtn = new TextButton("Start Server and play online (WIP)", uiManager.skin);
mainScreenGroup.addActor(makeSrvBtn);
TextButton joinSrvBtn = new TextButton("Join Server and play online (WIP)", uiManager.skin);
mainScreenGroup.addActor(joinSrvBtn);
TextButton localBut = new TextButton("Start a game on the local machine", uiManager.skin);
mainScreenGroup.addActor(localBut);
TextButton quitBut = new TextButton("Quit game", uiManager.skin);
@Override
public void createTable() {
amazeingLab = new Label("A - MAZE - ING", uiManager.skin);
setBut = new TextButton("CUSTOMIZE GAME SETTINGS", uiManager.skin);
makeSrvBtn = new TextButton("START SERVER", uiManager.skin);
joinSrvBtn = new TextButton("JOIN SERVER", uiManager.skin);
localBut = new TextButton("LOCAL GAME", uiManager.skin);
quitBut = new TextButton("QUIT GAME", uiManager.skin);
table.setPosition(stage.getWidth() *0.5f-mainScreenGroup.getWidth(), stage.getHeight() * 0.2f, Align.center);
table.add(mainScreenGroup);
stage.addActor(table);
//Add actions to the buttons
localBut.addListener(new InputListener(){
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
hide();
uiManager.main.setScreen(uiManager.playersScreen);
return true;
}
/* QUIT DIALOG */
final Dialog quitDlg = new Dialog("Quit?", uiManager.skin);
quitDlg.text("Are you sure you want to quit the game?");
TextButton quitDlgCancelBtn = new TextButton("Cancel", uiManager.skin);
TextButton quitDlgOkBtn = new TextButton("OK", uiManager.skin);
quitDlg.button(quitDlgCancelBtn);
quitDlg.button(quitDlgOkBtn);
quitDlgOkBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Bye bye");
Gdx.app.exit();
return true;
}
});
quitBut.addListener(new InputListener(){
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Bye bye!");
Gdx.app.exit();
return true;
}
quitDlgCancelBtn.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
quitDlg.hide();
return true;
}
});
// Add actions to the buttons
localBut.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
hide();
uiManager.main.setScreen(uiManager.playersScreen);
return true;
}
});
quitBut.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
quitDlg.show(stage);
return true;
}
});
makeSrvBtn.addListener(new InputListener() {
@Override
@ -76,57 +86,45 @@ public class TitleScreen implements Screen {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
hide();
uiManager.main.setScreen(uiManager.setScreen);
uiManager.main.setScreen(uiManager.setScreen);
return true;
}
});
//Add actors to the group
mainScreenGroup.addActor(setBut);
mainScreenGroup.addActor(makeSrvBtn);
mainScreenGroup.addActor(joinSrvBtn);
mainScreenGroup.addActor(localBut);
mainScreenGroup.addActor(quitBut);
}
@Override
public void show() {
uiManager.main.multiplexer.addProcessor(stage);
}
@Override
public void hide() {
uiManager.main.multiplexer.removeProcessor(stage);
}
public void buildTable() {
super.buildTable();
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0,0,0,0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act();
stage.draw();
}
float d = containerDiagonal();
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}
amazeingLab.setFontScale(d * .005f);
@Override
public void pause() {
// TODO Auto-generated method stub
}
float spaceBetweenBtns = d * 0.015f;
float btnHeight = spaceBetweenBtns * 2.4f;
float btnWidth = cw*0.46f;
float n = d * 0.0015f;
setBut.getLabel().setFontScale(n);
makeSrvBtn.getLabel().setFontScale(n);
joinSrvBtn.getLabel().setFontScale(n);
localBut.getLabel().setFontScale(n);
quitBut.getLabel().setFontScale(n);
@Override
public void resume() {
// TODO Auto-generated method stub
}
// Add actors to the group
table.row().colspan(1);
table.add(amazeingLab).spaceBottom(spaceBetweenBtns * 3);
table.row();
table.add(setBut).spaceBottom(spaceBetweenBtns).height(btnHeight).width(btnWidth);
table.row();
table.add(makeSrvBtn).spaceBottom(spaceBetweenBtns).height(btnHeight).width(btnWidth);
table.row();
table.add(joinSrvBtn).spaceBottom(spaceBetweenBtns).height(btnHeight).width(btnWidth);
table.row();
table.add(localBut).spaceBottom(spaceBetweenBtns).height(btnHeight).width(btnWidth);
table.row();
table.add(quitBut).spaceBottom(ch * 0.05f).height(btnHeight).width(btnWidth);
@Override
public void dispose() {
stage.dispose();
}
}