|
|
|
@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.*;
|
|
|
|
|
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
|
|
|
|
import com.badlogic.gdx.utils.Array;
|
|
|
|
|
import eu.jonahbauer.wizard.client.libgdx.WizardGame;
|
|
|
|
|
import eu.jonahbauer.wizard.client.libgdx.listeners.ResetErrorListener;
|
|
|
|
|
import eu.jonahbauer.wizard.client.libgdx.state.AwaitingJoinSession;
|
|
|
|
|
import eu.jonahbauer.wizard.common.messages.client.CreateSessionMessage;
|
|
|
|
|
import eu.jonahbauer.wizard.common.model.Configuration;
|
|
|
|
@ -18,10 +19,7 @@ public class CreateGameScreen extends MenuScreen {
|
|
|
|
|
private TextField sessionName;
|
|
|
|
|
private TextField playerName;
|
|
|
|
|
private TextField timeOut;
|
|
|
|
|
|
|
|
|
|
long selectedTimeOut;
|
|
|
|
|
String userName;
|
|
|
|
|
SelectBox<String> configurations;
|
|
|
|
|
private SelectBox<String> configurations;
|
|
|
|
|
|
|
|
|
|
private final ChangeListener listener = new ChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
@ -30,24 +28,7 @@ public class CreateGameScreen extends MenuScreen {
|
|
|
|
|
game.setScreen(new LobbyScreen(game));
|
|
|
|
|
sfxClick();
|
|
|
|
|
} else if (actor == buttonContinue) {
|
|
|
|
|
if (sessionName.getText() == null) {
|
|
|
|
|
System.out.println("Please select a session name.");
|
|
|
|
|
sessionName.clear();
|
|
|
|
|
}
|
|
|
|
|
if (playerName.getText() == null) {
|
|
|
|
|
userName = "Mallory";
|
|
|
|
|
System.out.println("Your name will be " + userName + ".");
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
selectedTimeOut = Long.parseLong(timeOut.getText());
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
System.out.println("Please select a valid timeout.");
|
|
|
|
|
timeOut.clear();
|
|
|
|
|
}
|
|
|
|
|
int selected = configurations.getSelectedIndex();
|
|
|
|
|
Configuration config = Configuration.values()[selected];
|
|
|
|
|
game.getClient().transition(new AwaitingJoinSession(null, sessionName.getText(), config, playerName.getText()));
|
|
|
|
|
game.getClient().send(new CreateSessionMessage(sessionName.getText(), playerName.getText(), selectedTimeOut, config));
|
|
|
|
|
create();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
@ -60,51 +41,76 @@ public class CreateGameScreen extends MenuScreen {
|
|
|
|
|
public void show() {
|
|
|
|
|
super.show();
|
|
|
|
|
|
|
|
|
|
buttonBack = new TextButton(game.messages.get("menu.connect.back"), game.data.skin);
|
|
|
|
|
buttonBack = new TextButton(game.messages.get("menu.create_game.back"), game.data.skin);
|
|
|
|
|
buttonBack.setPosition(WizardGame.WIDTH * 0.275f, BUTTON_BAR_Y);
|
|
|
|
|
buttonContinue = new TextButton("Erstellen", game.data.skin);
|
|
|
|
|
buttonContinue = new TextButton(game.messages.get("menu.create_game.create"), game.data.skin);
|
|
|
|
|
buttonContinue.setPosition(WizardGame.WIDTH * 0.725f - buttonContinue.getWidth(), BUTTON_BAR_Y);
|
|
|
|
|
|
|
|
|
|
var errorListener = new ResetErrorListener(game.data.skin);
|
|
|
|
|
|
|
|
|
|
sessionName = new TextField("", game.data.skin);
|
|
|
|
|
sessionName.setPosition(WizardGame.WIDTH * 0.3f, WizardGame.HEIGHT * 0.5f);
|
|
|
|
|
sessionName.setSize(0.4f * WizardGame.WIDTH, 64);
|
|
|
|
|
sessionName.addListener(errorListener);
|
|
|
|
|
sessionName.setProgrammaticChangeEvents(true);
|
|
|
|
|
|
|
|
|
|
playerName = new TextField("", game.data.skin);
|
|
|
|
|
playerName.setPosition(WizardGame.WIDTH * 0.3f, WizardGame.HEIGHT * 0.45f);
|
|
|
|
|
playerName.setSize(0.4f * WizardGame.WIDTH, 64);
|
|
|
|
|
playerName.addListener(errorListener);
|
|
|
|
|
playerName.setTextFieldListener(new TextField.TextFieldListener() {
|
|
|
|
|
private final String format = game.messages.get("menu.create_game.session_name.default");
|
|
|
|
|
private String oldName = "";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void keyTyped(TextField textField, char c) {
|
|
|
|
|
if (textField == playerName) {
|
|
|
|
|
var player = playerName.getText();
|
|
|
|
|
var session = sessionName.getText();
|
|
|
|
|
if (session.isEmpty() || session.equals(format.formatted(oldName))) {
|
|
|
|
|
if (player.isEmpty()) {
|
|
|
|
|
sessionName.setText("");
|
|
|
|
|
} else {
|
|
|
|
|
sessionName.setText(format.formatted(player));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
oldName = player;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
timeOut = new TextField("", game.data.skin);
|
|
|
|
|
timeOut.setPosition(WizardGame.WIDTH * 0.3f, WizardGame.HEIGHT * 0.4f);
|
|
|
|
|
timeOut.setSize(0.4f * WizardGame.WIDTH, 64);
|
|
|
|
|
timeOut.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter());
|
|
|
|
|
timeOut.addListener(errorListener);
|
|
|
|
|
|
|
|
|
|
configurations = new SelectBox<>(game.data.skin);
|
|
|
|
|
configurations.setSize(400, 64);
|
|
|
|
|
configurations.setPosition(WizardGame.WIDTH * 0.3f, WizardGame.HEIGHT * 0.3f);
|
|
|
|
|
configurations.addListener(errorListener);
|
|
|
|
|
|
|
|
|
|
Array<String> values = new Array<>();
|
|
|
|
|
for (Configuration value : Configuration.values()) {
|
|
|
|
|
values.add(value.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
configurations.setItems(values);
|
|
|
|
|
|
|
|
|
|
var contentTable = new Table().center().left();
|
|
|
|
|
contentTable.columnDefaults(0).growX().width(0.4f * WizardGame.WIDTH - 20);
|
|
|
|
|
contentTable.setSize(0.4f * WizardGame.WIDTH - 20, 400);
|
|
|
|
|
contentTable.setPosition(WizardGame.WIDTH * 0.3f, WizardGame.HEIGHT * 0.3f);
|
|
|
|
|
|
|
|
|
|
contentTable.add(new Label(game.messages.get("menu.lobby.player_name.label"), game.data.skin)).row();
|
|
|
|
|
contentTable.add(new Label(game.messages.get("menu.create_game.player_name.label"), game.data.skin)).row();
|
|
|
|
|
contentTable.add(playerName).row();
|
|
|
|
|
contentTable.add(new Label(game.messages.get("menu.lobby.session_name.label"), game.data.skin)).row();
|
|
|
|
|
contentTable.add(new Label(game.messages.get("menu.create_game.session_name.label"), game.data.skin)).row();
|
|
|
|
|
contentTable.add(sessionName).row();
|
|
|
|
|
contentTable.add(new Label(game.messages.get("menu.lobby.create_session.timeout.label"), game.data.skin)).row();
|
|
|
|
|
contentTable.add(new Label(game.messages.get("menu.create_game.session_timeout.label"), game.data.skin)).row();
|
|
|
|
|
contentTable.add(timeOut).row();
|
|
|
|
|
contentTable.add(new Label(game.messages.get("menu.lobby.session_configuration.label"), game.data.skin)).row();
|
|
|
|
|
contentTable.add(new Label(game.messages.get("menu.create_game.session_configuration.label"), game.data.skin)).row();
|
|
|
|
|
contentTable.add(configurations).row();
|
|
|
|
|
|
|
|
|
|
contentTable.setPosition(WizardGame.WIDTH * 0.3f, WizardGame.HEIGHT * 0.3f);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Gdx.input.setInputProcessor(game.data.stage);
|
|
|
|
|
game.data.stage.addActor(buttonContinue);
|
|
|
|
|
game.data.stage.addActor(contentTable);
|
|
|
|
@ -113,4 +119,47 @@ public class CreateGameScreen extends MenuScreen {
|
|
|
|
|
buttonContinue.addListener(listener);
|
|
|
|
|
buttonBack.addListener(listener);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void create() {
|
|
|
|
|
boolean error = false;
|
|
|
|
|
|
|
|
|
|
String sessionName = this.sessionName.getText();
|
|
|
|
|
if (sessionName.isBlank()) {
|
|
|
|
|
System.out.println("Please select a session name.");
|
|
|
|
|
this.sessionName.setStyle(game.data.skin.get("error", TextField.TextFieldStyle.class));
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String playerName = this.playerName.getText();
|
|
|
|
|
if (playerName.isBlank()) {
|
|
|
|
|
System.out.println("Please select a name.");
|
|
|
|
|
this.playerName.setStyle(game.data.skin.get("error", TextField.TextFieldStyle.class));
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long timeout = 0;
|
|
|
|
|
try {
|
|
|
|
|
timeout = Long.parseLong(this.timeOut.getText());
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
System.out.println("Please select a valid timeout.");
|
|
|
|
|
this.timeOut.setStyle(game.data.skin.get("error", TextField.TextFieldStyle.class));
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Configuration config = null;
|
|
|
|
|
try {
|
|
|
|
|
int selected = configurations.getSelectedIndex();
|
|
|
|
|
config = Configuration.values()[selected];
|
|
|
|
|
} catch (ArrayIndexOutOfBoundsException e) {
|
|
|
|
|
System.out.println("Please select a valid configuration.");
|
|
|
|
|
this.configurations.setStyle(game.data.skin.get("error", SelectBox.SelectBoxStyle.class));
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!error) {
|
|
|
|
|
var client = game.getClient();
|
|
|
|
|
client.transition(new AwaitingJoinSession(null, sessionName, config, playerName));
|
|
|
|
|
client.send(new CreateSessionMessage(sessionName, playerName, 1000 * timeout, config));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|