|
|
@ -7,16 +7,10 @@ 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.listeners.ResetErrorListener;
|
|
|
|
import eu.jonahbauer.wizard.client.libgdx.state.AwaitingJoinSession;
|
|
|
|
|
|
|
|
import eu.jonahbauer.wizard.client.libgdx.state.Lobby;
|
|
|
|
import eu.jonahbauer.wizard.client.libgdx.state.Lobby;
|
|
|
|
import eu.jonahbauer.wizard.client.libgdx.state.Menu;
|
|
|
|
|
|
|
|
import eu.jonahbauer.wizard.common.messages.client.JoinSessionMessage;
|
|
|
|
|
|
|
|
import eu.jonahbauer.wizard.common.messages.data.SessionData;
|
|
|
|
import eu.jonahbauer.wizard.common.messages.data.SessionData;
|
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.stream.StreamSupport;
|
|
|
|
import java.util.stream.StreamSupport;
|
|
|
|
|
|
|
|
|
|
|
@ -31,33 +25,34 @@ public class LobbyScreen extends MenuScreen {
|
|
|
|
private Label labelSessionName;
|
|
|
|
private Label labelSessionName;
|
|
|
|
private Label labelSessionPlayerCount;
|
|
|
|
private Label labelSessionPlayerCount;
|
|
|
|
private Label labelSessionConfiguration;
|
|
|
|
private Label labelSessionConfiguration;
|
|
|
|
|
|
|
|
|
|
|
|
private UUID selectedSession;
|
|
|
|
private final String oldPlayerName;
|
|
|
|
|
|
|
|
private SessionData selectedSession;
|
|
|
|
private List<SessionData> sessions;
|
|
|
|
private List<SessionData> sessions;
|
|
|
|
private ScrollPane sessionListContainer;
|
|
|
|
private ScrollPane sessionListContainer;
|
|
|
|
private final Map<UUID, SessionData> sessionData = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Lobby state;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final ChangeListener listener = new ChangeListener() {
|
|
|
|
private final ChangeListener listener = new ChangeListener() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void changed(ChangeEvent event, Actor actor) {
|
|
|
|
public void changed(ChangeEvent event, Actor actor) {
|
|
|
|
if (actor == buttonBack) {
|
|
|
|
if (actor == buttonBack) {
|
|
|
|
game.getClient().transition(new Menu());
|
|
|
|
game.getClient().execute(Lobby.class, Lobby::disconnect);
|
|
|
|
sfxClick();
|
|
|
|
sfxClick();
|
|
|
|
} else if (actor == buttonJoin) {
|
|
|
|
} else if (actor == buttonJoin) {
|
|
|
|
join();
|
|
|
|
join();
|
|
|
|
sfxClick();
|
|
|
|
sfxClick();
|
|
|
|
} else if (actor == buttonCreate) {
|
|
|
|
} else if (actor == buttonCreate) {
|
|
|
|
game.setScreen(new CreateGameScreen(game));
|
|
|
|
game.getClient().execute(Lobby.class, (s, c) -> {
|
|
|
|
|
|
|
|
s.setPlayerName(playerName.getText());
|
|
|
|
|
|
|
|
return s.showCreateScreen(c);
|
|
|
|
|
|
|
|
});
|
|
|
|
sfxClick();
|
|
|
|
sfxClick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
public LobbyScreen(WizardGame game) {
|
|
|
|
public LobbyScreen(WizardGame game, String playerName) {
|
|
|
|
super(game);
|
|
|
|
super(game);
|
|
|
|
this.state = (Lobby) game.getClient().getState();
|
|
|
|
this.oldPlayerName = playerName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -112,13 +107,11 @@ public class LobbyScreen extends MenuScreen {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void addSession(SessionData session) {
|
|
|
|
public void addSession(SessionData session) {
|
|
|
|
this.sessionData.put(session.getUuid(), session);
|
|
|
|
|
|
|
|
this.sessions.getItems().add(session);
|
|
|
|
this.sessions.getItems().add(session);
|
|
|
|
this.sessions.invalidateHierarchy();
|
|
|
|
this.sessions.invalidateHierarchy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void removeSession(UUID session) {
|
|
|
|
public void removeSession(UUID session) {
|
|
|
|
this.sessionData.remove(session);
|
|
|
|
|
|
|
|
var items = this.sessions.getItems();
|
|
|
|
var items = this.sessions.getItems();
|
|
|
|
for (int i = 0; i < items.size; i++) {
|
|
|
|
for (int i = 0; i < items.size; i++) {
|
|
|
|
if (items.get(i).getUuid().equals(session)) {
|
|
|
|
if (items.get(i).getUuid().equals(session)) {
|
|
|
@ -128,13 +121,12 @@ public class LobbyScreen extends MenuScreen {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.sessions.invalidateHierarchy();
|
|
|
|
this.sessions.invalidateHierarchy();
|
|
|
|
|
|
|
|
|
|
|
|
if (session.equals(selectedSession)) {
|
|
|
|
if (selectedSession != null && selectedSession.getUuid().equals(session)) {
|
|
|
|
updateData(null);
|
|
|
|
updateData(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void modifySession(SessionData session) {
|
|
|
|
public void modifySession(SessionData session) {
|
|
|
|
this.sessionData.put(session.getUuid(), session);
|
|
|
|
|
|
|
|
var items = this.sessions.getItems();
|
|
|
|
var items = this.sessions.getItems();
|
|
|
|
for (int i = 0; i < items.size; i++) {
|
|
|
|
for (int i = 0; i < items.size; i++) {
|
|
|
|
if (items.get(i).getUuid().equals(session.getUuid())) {
|
|
|
|
if (items.get(i).getUuid().equals(session.getUuid())) {
|
|
|
@ -144,17 +136,16 @@ public class LobbyScreen extends MenuScreen {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.sessions.invalidateHierarchy();
|
|
|
|
this.sessions.invalidateHierarchy();
|
|
|
|
|
|
|
|
|
|
|
|
if (session.getUuid().equals(selectedSession)) {
|
|
|
|
if (selectedSession != null && selectedSession.getUuid().equals(session.getUuid())) {
|
|
|
|
updateData(session);
|
|
|
|
updateData(session);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setSessions(SessionData... sessions) {
|
|
|
|
public void setSessions(SessionData... sessions) {
|
|
|
|
this.sessionData.clear();
|
|
|
|
|
|
|
|
Arrays.stream(sessions).forEach(s -> this.sessionData.put(s.getUuid(), s));
|
|
|
|
|
|
|
|
var items = this.sessions.getItems();
|
|
|
|
var items = this.sessions.getItems();
|
|
|
|
items.clear();
|
|
|
|
items.clear();
|
|
|
|
items.addAll(sessions);
|
|
|
|
items.addAll(sessions);
|
|
|
|
|
|
|
|
this.selectedSession = null;
|
|
|
|
this.sessions.invalidateHierarchy();
|
|
|
|
this.sessions.invalidateHierarchy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -163,7 +154,7 @@ public class LobbyScreen extends MenuScreen {
|
|
|
|
labelSessionName.setText(data.getName());
|
|
|
|
labelSessionName.setText(data.getName());
|
|
|
|
labelSessionPlayerCount.setText(Integer.toString(data.getPlayerCount()));
|
|
|
|
labelSessionPlayerCount.setText(Integer.toString(data.getPlayerCount()));
|
|
|
|
labelSessionConfiguration.setText(data.getConfiguration().toString());
|
|
|
|
labelSessionConfiguration.setText(data.getConfiguration().toString());
|
|
|
|
selectedSession = data.getUuid();
|
|
|
|
selectedSession = data;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
labelSessionName.setText("");
|
|
|
|
labelSessionName.setText("");
|
|
|
|
labelSessionPlayerCount.setText("");
|
|
|
|
labelSessionPlayerCount.setText("");
|
|
|
@ -175,14 +166,8 @@ public class LobbyScreen extends MenuScreen {
|
|
|
|
private Table createInfoTable() {
|
|
|
|
private Table createInfoTable() {
|
|
|
|
float infoTableWidth = 0.3f * WizardGame.WIDTH - 20;
|
|
|
|
float infoTableWidth = 0.3f * WizardGame.WIDTH - 20;
|
|
|
|
|
|
|
|
|
|
|
|
playerName = new TextField(state.getPlayerName(), game.data.skin);
|
|
|
|
playerName = new TextField(oldPlayerName, game.data.skin);
|
|
|
|
playerName.addListener(new ResetErrorListener(game.data.skin));
|
|
|
|
playerName.addListener(new ResetErrorListener(game.data.skin));
|
|
|
|
playerName.addListener(new ChangeListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void changed(ChangeEvent event, Actor actor) {
|
|
|
|
|
|
|
|
state.setPlayerName(playerName.getText());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
@ -218,8 +203,7 @@ public class LobbyScreen extends MenuScreen {
|
|
|
|
error = true;
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SessionData session = sessionData.get(selectedSession);
|
|
|
|
if (selectedSession == null) {
|
|
|
|
if (session == null) {
|
|
|
|
|
|
|
|
log.warn("Please select a session.");
|
|
|
|
log.warn("Please select a session.");
|
|
|
|
this.sessionListContainer.setStyle(game.data.skin.get("error", ScrollPane.ScrollPaneStyle.class));
|
|
|
|
this.sessionListContainer.setStyle(game.data.skin.get("error", ScrollPane.ScrollPaneStyle.class));
|
|
|
|
error = true;
|
|
|
|
error = true;
|
|
|
@ -227,8 +211,7 @@ public class LobbyScreen extends MenuScreen {
|
|
|
|
|
|
|
|
|
|
|
|
if (!error) {
|
|
|
|
if (!error) {
|
|
|
|
var client = game.getClient();
|
|
|
|
var client = game.getClient();
|
|
|
|
client.transition(new AwaitingJoinSession(session.getUuid(), session.getName(), session.getConfiguration(), playerName));
|
|
|
|
client.execute(Lobby.class, (s, c) -> s.joinSession(client, selectedSession, playerName));
|
|
|
|
client.send(new JoinSessionMessage(selectedSession, playerName));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|