visual improvements
@ -1,22 +1,39 @@
|
|||||||
package eu.jonahbauer.wizard.client.libgdx.listeners;
|
package eu.jonahbauer.wizard.client.libgdx.listeners;
|
||||||
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox;
|
import com.badlogic.gdx.scenes.scene2d.ui.*;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class ResetErrorListener extends ChangeListener {
|
public class ResetErrorListener extends ChangeListener {
|
||||||
private final Skin skin;
|
private final Skin skin;
|
||||||
|
private final Actor target;
|
||||||
|
private final String style;
|
||||||
|
|
||||||
|
public ResetErrorListener(Skin skin) {
|
||||||
|
this(skin, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResetErrorListener(Skin skin, Actor target) {
|
||||||
|
this(skin, target, "default");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResetErrorListener(Skin skin, Actor target, String style) {
|
||||||
|
this.skin = skin;
|
||||||
|
this.target = target;
|
||||||
|
this.style = style;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void changed(ChangeEvent event, Actor actor) {
|
public void changed(ChangeEvent event, Actor actor) {
|
||||||
if (event.getTarget() instanceof TextField textField) {
|
var target = this.target != null ? this.target : event.getTarget();
|
||||||
textField.setStyle(skin.get(TextField.TextFieldStyle.class));
|
if (target instanceof TextField textField) {
|
||||||
} else if (event.getTarget() instanceof SelectBox<?> box) {
|
textField.setStyle(skin.get(style, TextField.TextFieldStyle.class));
|
||||||
box.setStyle(skin.get(SelectBox.SelectBoxStyle.class));
|
} else if (target instanceof SelectBox<?> box) {
|
||||||
|
box.setStyle(skin.get(style, SelectBox.SelectBoxStyle.class));
|
||||||
|
} else if (target instanceof List<?> list) {
|
||||||
|
list.setStyle(skin.get(style, List.ListStyle.class));
|
||||||
|
} else if (target instanceof ScrollPane scrollPane) {
|
||||||
|
scrollPane.setStyle(skin.get(style, ScrollPane.ScrollPaneStyle.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ public class CreateGameScreen extends MenuScreen {
|
|||||||
sfxClick();
|
sfxClick();
|
||||||
} else if (actor == buttonContinue) {
|
} else if (actor == buttonContinue) {
|
||||||
create();
|
create();
|
||||||
|
sfxClick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -125,14 +126,14 @@ public class CreateGameScreen extends MenuScreen {
|
|||||||
|
|
||||||
String sessionName = this.sessionName.getText();
|
String sessionName = this.sessionName.getText();
|
||||||
if (sessionName.isBlank()) {
|
if (sessionName.isBlank()) {
|
||||||
System.out.println("Please select a session name.");
|
System.out.println("Please choose a session name.");
|
||||||
this.sessionName.setStyle(game.data.skin.get("error", TextField.TextFieldStyle.class));
|
this.sessionName.setStyle(game.data.skin.get("error", TextField.TextFieldStyle.class));
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String playerName = this.playerName.getText();
|
String playerName = this.playerName.getText();
|
||||||
if (playerName.isBlank()) {
|
if (playerName.isBlank()) {
|
||||||
System.out.println("Please select a name.");
|
System.out.println("Please choose a name.");
|
||||||
this.playerName.setStyle(game.data.skin.get("error", TextField.TextFieldStyle.class));
|
this.playerName.setStyle(game.data.skin.get("error", TextField.TextFieldStyle.class));
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
@ -141,7 +142,7 @@ public class CreateGameScreen extends MenuScreen {
|
|||||||
try {
|
try {
|
||||||
timeout = Long.parseLong(this.timeOut.getText());
|
timeout = Long.parseLong(this.timeOut.getText());
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
System.out.println("Please select a valid timeout.");
|
System.out.println("Please choose a valid timeout.");
|
||||||
this.timeOut.setStyle(game.data.skin.get("error", TextField.TextFieldStyle.class));
|
this.timeOut.setStyle(game.data.skin.get("error", TextField.TextFieldStyle.class));
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.*;
|
|||||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||||
import eu.jonahbauer.wizard.client.libgdx.WizardGame;
|
import eu.jonahbauer.wizard.client.libgdx.WizardGame;
|
||||||
import eu.jonahbauer.wizard.client.libgdx.actors.AutoFocusScrollPane;
|
import eu.jonahbauer.wizard.client.libgdx.actors.AutoFocusScrollPane;
|
||||||
|
import eu.jonahbauer.wizard.client.libgdx.listeners.ResetErrorListener;
|
||||||
import eu.jonahbauer.wizard.client.libgdx.state.AwaitingJoinSession;
|
import eu.jonahbauer.wizard.client.libgdx.state.AwaitingJoinSession;
|
||||||
import eu.jonahbauer.wizard.client.libgdx.state.Menu;
|
import eu.jonahbauer.wizard.client.libgdx.state.Menu;
|
||||||
import eu.jonahbauer.wizard.common.messages.client.JoinSessionMessage;
|
import eu.jonahbauer.wizard.common.messages.client.JoinSessionMessage;
|
||||||
@ -30,6 +31,7 @@ public class LobbyScreen extends MenuScreen {
|
|||||||
|
|
||||||
private UUID selectedSession;
|
private UUID selectedSession;
|
||||||
private List<SessionData> sessions;
|
private List<SessionData> sessions;
|
||||||
|
private ScrollPane sessionListContainer;
|
||||||
private final Map<UUID, SessionData> sessionData = new HashMap<>();
|
private final Map<UUID, SessionData> sessionData = new HashMap<>();
|
||||||
|
|
||||||
private final ChangeListener listener = new ChangeListener() {
|
private final ChangeListener listener = new ChangeListener() {
|
||||||
@ -39,16 +41,7 @@ public class LobbyScreen extends MenuScreen {
|
|||||||
game.getClient().transition(new Menu());
|
game.getClient().transition(new Menu());
|
||||||
sfxClick();
|
sfxClick();
|
||||||
} else if (actor == buttonJoin) {
|
} else if (actor == buttonJoin) {
|
||||||
if(playerName.getText().isEmpty()) {
|
join();
|
||||||
System.out.println("Please choose a player name");
|
|
||||||
game.getClient().transition(new Menu());
|
|
||||||
}
|
|
||||||
if (selectedSession != null) {
|
|
||||||
var name = playerName.getText();
|
|
||||||
var session = sessionData.get(selectedSession);
|
|
||||||
game.getClient().transition(new AwaitingJoinSession(session.getUuid(), session.getName(), session.getConfiguration(), name));
|
|
||||||
game.getClient().send(new JoinSessionMessage(selectedSession, name));
|
|
||||||
}
|
|
||||||
sfxClick();
|
sfxClick();
|
||||||
} else if (actor == buttonCreate) {
|
} else if (actor == buttonCreate) {
|
||||||
game.setScreen(new CreateGameScreen(game));
|
game.setScreen(new CreateGameScreen(game));
|
||||||
@ -83,14 +76,16 @@ public class LobbyScreen extends MenuScreen {
|
|||||||
updateData(selected);
|
updateData(selected);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var listContainer = new AutoFocusScrollPane(sessions, game.data.skin);
|
sessionListContainer = new AutoFocusScrollPane(sessions, game.data.skin);
|
||||||
listContainer.layout();
|
sessionListContainer.layout();
|
||||||
|
|
||||||
|
sessions.addListener(new ResetErrorListener(game.data.skin, sessionListContainer));
|
||||||
|
|
||||||
var content = new HorizontalGroup().grow().space(20);
|
var content = new HorizontalGroup().grow().space(20);
|
||||||
content.setPosition(0.25f * WizardGame.WIDTH, 0.3f * WizardGame.HEIGHT);
|
content.setPosition(0.25f * WizardGame.WIDTH, 0.3f * WizardGame.HEIGHT);
|
||||||
content.setSize(0.5f * WizardGame.WIDTH, 400);
|
content.setSize(0.5f * WizardGame.WIDTH, 400);
|
||||||
content.addActor(new Container<>(listContainer).width(0.2f * WizardGame.WIDTH).height(400));
|
content.addActor(new Container<>(sessionListContainer).width(0.2f * WizardGame.WIDTH).height(400));
|
||||||
content.addActor(createInfoTable());
|
content.addActor(createInfoTable());
|
||||||
content.layout();
|
content.layout();
|
||||||
|
|
||||||
@ -177,6 +172,8 @@ public class LobbyScreen extends MenuScreen {
|
|||||||
float infoTableWidth = 0.3f * WizardGame.WIDTH - 20;
|
float infoTableWidth = 0.3f * WizardGame.WIDTH - 20;
|
||||||
|
|
||||||
playerName = new TextField("", game.data.skin);
|
playerName = new TextField("", game.data.skin);
|
||||||
|
playerName.addListener(new ResetErrorListener(game.data.skin));
|
||||||
|
|
||||||
labelSessionName = new Label("", game.data.skin, "textfield");
|
labelSessionName = new Label("", game.data.skin, "textfield");
|
||||||
labelSessionConfiguration = new Label("", game.data.skin, "textfield");
|
labelSessionConfiguration = new Label("", game.data.skin, "textfield");
|
||||||
labelSessionPlayerCount = new Label("", game.data.skin, "textfield");
|
labelSessionPlayerCount = new Label("", game.data.skin, "textfield");
|
||||||
@ -200,4 +197,28 @@ public class LobbyScreen extends MenuScreen {
|
|||||||
|
|
||||||
return infoTable;
|
return infoTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void join() {
|
||||||
|
boolean error = false;
|
||||||
|
|
||||||
|
String playerName = this.playerName.getText();
|
||||||
|
if (playerName.isBlank()) {
|
||||||
|
System.out.println("Please choose a player name");
|
||||||
|
this.playerName.setStyle(game.data.skin.get("error", TextField.TextFieldStyle.class));
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
SessionData session = sessionData.get(selectedSession);
|
||||||
|
if (session == null) {
|
||||||
|
System.out.println("Please select a session.");
|
||||||
|
this.sessionListContainer.setStyle(game.data.skin.get("error", ScrollPane.ScrollPaneStyle.class));
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!error) {
|
||||||
|
var client = game.getClient();
|
||||||
|
client.transition(new AwaitingJoinSession(session.getUuid(), session.getName(), session.getConfiguration(), playerName));
|
||||||
|
client.send(new JoinSessionMessage(selectedSession, playerName));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 104 KiB |
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"BitmapFont": {
|
"BitmapFont": {
|
||||||
"default-font": {
|
"default-font": {
|
||||||
"file": "font/coolvetica.fnt",
|
"file": "font/coolvetica.fnt"
|
||||||
},
|
},
|
||||||
"enchanted": {
|
"enchanted": {
|
||||||
"file": "font/enchanted.fnt"
|
"file": "font/enchanted.fnt"
|
||||||
@ -71,6 +71,10 @@
|
|||||||
"background": "default-pane",
|
"background": "default-pane",
|
||||||
"hScroll": "default-scroll",
|
"hScroll": "default-scroll",
|
||||||
"vScrollKnob": "default-round-large"
|
"vScrollKnob": "default-round-large"
|
||||||
|
},
|
||||||
|
"error": {
|
||||||
|
"parent": "default",
|
||||||
|
"background": "default-pane-error"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"SelectBoxStyle": {
|
"SelectBoxStyle": {
|
||||||
|
After Width: | Height: | Size: 223 B |
Before Width: | Height: | Size: 311 B After Width: | Height: | Size: 225 B |
Before Width: | Height: | Size: 85 B |
After Width: | Height: | Size: 185 B |
Before Width: | Height: | Size: 119 B |
Before Width: | Height: | Size: 236 B After Width: | Height: | Size: 248 B |
Before Width: | Height: | Size: 241 B After Width: | Height: | Size: 253 B |