Added a way to list HighScore and added very simple textFlow view for LobbyDisplay, in case ListView wont work till tomorrow
This commit is contained in:
parent
68d84b9493
commit
a655df2e41
@ -406,6 +406,10 @@ public class Client {
|
||||
case GuiParameters.updateHighScore:
|
||||
chatApp.getLoungeSceneViewController().addHighScore(data);
|
||||
break;
|
||||
case GuiParameters.updatePrintLobby:
|
||||
chatApp.getLoungeSceneViewController().clearLobbyPrint();
|
||||
chatApp.getLoungeSceneViewController().addLobbyPrint(data);
|
||||
break;
|
||||
default:
|
||||
notificationTextDisplay(data);
|
||||
//TODO(Sebi,Seraina): should the gameController be in the Application just like the ChatController?
|
||||
|
||||
@ -49,9 +49,13 @@ public class LoungeSceneViewController implements Initializable {
|
||||
public static final Logger LOGGER = LogManager.getLogger(LoungeSceneViewController.class);
|
||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||
|
||||
|
||||
|
||||
@FXML
|
||||
private TextFlow highScore;
|
||||
@FXML
|
||||
public TextFlow lobbyPrint;
|
||||
@FXML
|
||||
private SplitPane chatSplitPane;
|
||||
@FXML
|
||||
private AnchorPane chatAnchorPane;
|
||||
@ -62,6 +66,8 @@ public class LoungeSceneViewController implements Initializable {
|
||||
@FXML
|
||||
private Button leaveLobbyButton;
|
||||
@FXML
|
||||
private Button lobbyPrintButton;
|
||||
@FXML
|
||||
private Button startGame;
|
||||
@FXML
|
||||
private Button newGameButton;
|
||||
@ -495,6 +501,14 @@ public class LoungeSceneViewController implements Initializable {
|
||||
client.getClient().sendMsgToServer(Protocol.highScoreList);
|
||||
}
|
||||
|
||||
public void sendLilstle() {
|
||||
client.getClient().sendMsgToServer(Protocol.listLobbies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a String to the highScore Text Flow
|
||||
* @param data the String to be added
|
||||
*/
|
||||
public void addHighScore(String data) {
|
||||
String[] arguments = data.split("/n");
|
||||
LOGGER.debug(arguments.length);
|
||||
@ -511,5 +525,37 @@ public class LoungeSceneViewController implements Initializable {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a String to the lobbyPrint TextFlow
|
||||
* @param data the String to be added
|
||||
* */
|
||||
public void addLobbyPrint(String data) {
|
||||
String[] arguments = data.split("/n");
|
||||
LOGGER.debug(arguments.length);
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for(String argument : arguments) {
|
||||
LOGGER.debug("HighScore " + argument);
|
||||
Text text = new Text(argument + System.lineSeparator());
|
||||
text.setFill(Color.BLACK);
|
||||
lobbyPrint.getChildren().add(text);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the lobbyPrint TextFlow
|
||||
*/
|
||||
public void clearLobbyPrint() {
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lobbyPrint.getChildren().clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -86,5 +86,14 @@ public class GuiParameters {
|
||||
*/
|
||||
public static final String removePlayerFromList = "RMVLST";
|
||||
|
||||
/**
|
||||
* Tells Gui to update its HighScore TextFlow according to the following data
|
||||
*/
|
||||
public static final String updateHighScore = "HISCR";
|
||||
|
||||
/**
|
||||
* Tells Gui to add a String to printLobby TextFlow - a provisory solution in case ListeView won't
|
||||
* pan out
|
||||
*/
|
||||
public static final String updatePrintLobby = "PRLOBB";
|
||||
}
|
||||
|
||||
@ -563,6 +563,46 @@ public class ClientHandler implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all lobbies and their members, along with players outside lobbies to this clientHandler's
|
||||
* client a GUI message in a form, the gui can decode.
|
||||
*/
|
||||
public void listLobbiesGuiFormat() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (Lobby.lobbies.isEmpty()) {
|
||||
stringBuilder.append("No Lobbies.").append("/n");
|
||||
} else {
|
||||
for (Lobby l : Lobby.lobbies) {
|
||||
String lobbyStatus = "closed";
|
||||
if (l.getLobbyIsOpen()) {
|
||||
lobbyStatus = "open";
|
||||
}
|
||||
stringBuilder.append("Lobby nr. " + l.getLobbyID() + ": (" + lobbyStatus + ")").append("/n");
|
||||
for (ClientHandler c : l.getLobbyClients()) {
|
||||
if (c.equals(l.getAdmin())) {
|
||||
stringBuilder.append(" -" + c.getClientUserName() + " (admin)").append("/n");
|
||||
} else {
|
||||
stringBuilder.append(" -" + c.getClientUserName()).append("/n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean helper = false; //used to print "Clients not in lobbies" only once, if needed.
|
||||
for (ClientHandler c : connectedClients) {
|
||||
if (Lobby.clientIsInLobby(c) == -1) {
|
||||
if (!helper) {
|
||||
helper = true;
|
||||
stringBuilder.append("Clients not in lobbies:").append("/n");
|
||||
}
|
||||
stringBuilder.append(" -").append(c.getClientUserName()).append("/n");
|
||||
}
|
||||
}
|
||||
if (!helper) {
|
||||
stringBuilder.append("No clients outside of lobbies").append("/n");
|
||||
}
|
||||
sendMsgToClient(Protocol.printToGUI + "$" + GuiParameters.updatePrintLobby + "$" + stringBuilder.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all players in the client's lobby. If the client is not in a Lobby, it will say "You are
|
||||
* not in a lobby."
|
||||
|
||||
@ -99,6 +99,7 @@ public class JServerProtocolParser {
|
||||
break;
|
||||
case Protocol.listLobbies:
|
||||
h.listLobbies();
|
||||
h.listLobbiesGuiFormat();
|
||||
break;
|
||||
case Protocol.listPlayersInLobby:
|
||||
h.listPlayersInLobby();
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
<?import javafx.scene.control.ToolBar?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?import javafx.scene.shape.Line?>
|
||||
<?import javafx.scene.text.TextFlow?>
|
||||
|
||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeSceneViewController">
|
||||
@ -16,16 +17,17 @@
|
||||
<ToolBar fx:id="NTtBToolBar" prefHeight="77.0" BorderPane.alignment="CENTER">
|
||||
<items>
|
||||
<Button fx:id="highScoreButton" mnemonicParsing="false" onAction="#sendHIghScore" text="High Score" />
|
||||
<Button fx:id="ChangeNameButton" mnemonicParsing="false" text="Change Name" />
|
||||
<Button fx:id="lobbyPrintButton" mnemonicParsing="false" onAction="#sendLilstle" text="Lobby List" />
|
||||
<Button fx:id="LeaveServerButton" mnemonicParsing="false" text="Leave server" />
|
||||
<Button fx:id="leaveLobbyButton" mnemonicParsing="false" onAction="#leaveLobby" text="Leave Lobby" />
|
||||
<Button fx:id="ChangeNameButton" mnemonicParsing="false" text="Change Name" />
|
||||
</items>
|
||||
</ToolBar>
|
||||
</top>
|
||||
<center>
|
||||
<AnchorPane BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<Button fx:id="newGameButton" layoutX="68.0" layoutY="101.0" mnemonicParsing="false" text="New Lobby" />
|
||||
<Button fx:id="newGameButton" layoutX="34.0" layoutY="101.0" mnemonicParsing="false" text="New Lobby" />
|
||||
<AnchorPane fx:id="gameAnchorPane" />
|
||||
<Button fx:id="startGame" layoutX="68.0" layoutY="156.0" mnemonicParsing="false" onAction="#startGame" opacity="0.0" text="Start Game" />
|
||||
</children>
|
||||
@ -34,13 +36,16 @@
|
||||
<bottom>
|
||||
<AnchorPane fx:id="ChatArea" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<SplitPane fx:id="chatSplitPane" dividerPositions="0.8555729984301413" minHeight="50.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<SplitPane fx:id="chatSplitPane" dividerPositions="0.46467817896389324" minHeight="50.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<items>
|
||||
<AnchorPane fx:id="chatAnchorPane" minHeight="0.0" minWidth="0.0" />
|
||||
<AnchorPane fx:id="otherNotificationAnchorPane" minHeight="0.0" minWidth="0.0">
|
||||
<children>
|
||||
<Label text="High Score:" />
|
||||
<TextFlow fx:id="highScore" layoutY="18.0" prefHeight="30.0" prefWidth="315.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="18.0" />
|
||||
<TextFlow fx:id="highScore" layoutY="18.0" prefHeight="30.0" prefWidth="99.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="239.0" AnchorPane.topAnchor="18.0" />
|
||||
<Label layoutX="120.0" text="Lobbies:" />
|
||||
<TextFlow fx:id="lobbyPrint" layoutX="120.0" layoutY="18.0" />
|
||||
<Line endX="-6.5" endY="-24.0" layoutX="120.0" layoutY="24.0" startX="-6.5" startY="48.5" AnchorPane.bottomAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</items>
|
||||
|
||||
Reference in New Issue
Block a user