Added the chat to the lobby view, isnt resizable yet but works just fine

This commit is contained in:
Seraina 2022-05-01 14:42:10 +02:00
parent f0f4f9142e
commit f16d87f8d3
5 changed files with 65 additions and 39 deletions

View File

@ -31,9 +31,11 @@ public class ServerGameInfoHandler {
switch (msg) {
case ClientGameInfoHandler.ghostVoteRequest:
msg = Protocol.serverRequestsGhostVote + "$" + passenger.getPosition() + "$";
passenger.getClientHandler().sendMsgToClient(Protocol.printToClientConsole + "$" + ClientGameInfoHandler.ghostVoteRequest);
break;
case ClientGameInfoHandler.humanVoteRequest:
msg = Protocol.serverRequestsHumanVote + "$" + passenger.getPosition() + "$";
passenger.getClientHandler().sendMsgToClient(Protocol.printToClientConsole + "$" + ClientGameInfoHandler.humanVoteRequest);
break;
default:
if(!msg.contains("$")) {

View File

@ -129,7 +129,6 @@ public class ChatApp extends Application {
public void start(Stage primaryStage) throws Exception {
this.setcModel(clientModel);
this.setGameC(gameController);
gameC.setClient(cModel);
gameC.setGameStateModel(GameController.getGameStateModel());
try {

View File

@ -33,6 +33,7 @@ import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.control.ToolBar;
@ -48,6 +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 SplitPane chatSplitPane;
@FXML
private AnchorPane chatAnchorPane;
@FXML
private AnchorPane otherNotificationAnchorPane;
@FXML
private Button leaveLobbyButton;
@FXML
@ -67,8 +75,6 @@ public class LoungeSceneViewController implements Initializable {
@FXML
private AnchorPane ChatArea;
@FXML
private HBox ChatAreaHBox;
@FXML
private BorderPane LoungeSceneBorderPane;
@FXML
private ToolBar NTtBToolBar;
@ -110,6 +116,7 @@ public class LoungeSceneViewController implements Initializable {
LobbyListView.setVisible(true);
ClientListView.setVisible(true);
ClientListView.setItems(client.getAllClients());
addChatView();
LobbyListView.setPlaceholder(new Text("No open lobbies!"));
client.getAllClients().addListener(new ListChangeListener<SimpleStringProperty>() {
@Override
@ -152,6 +159,19 @@ public class LoungeSceneViewController implements Initializable {
});
}
public void addChatView() {
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
chatAnchorPane.getChildren().add(chatApp.chat);
} catch (Exception e) {
LOGGER.debug("Not yet initialized: chatAnchorPane");
}
}
});
}
public void updateClientListView(ObservableList<SimpleStringProperty> names) {
ObservableList<SimpleStringProperty> clientsLeft = ClientListView.getItems();
clientsLeft.removeAll(names);
@ -162,8 +182,8 @@ public class LoungeSceneViewController implements Initializable {
}
/**
* Adds players to a lobby
* "NMEMB" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters}
* Adds players to a lobby "NMEMB" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters}
*
* @param lobbyID
* @param player
*/
@ -173,8 +193,9 @@ public class LoungeSceneViewController implements Initializable {
}
/**
* Used when a new lobby shall be added to the view.
* "NLOBBY" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters}
* Used when a new lobby shall be added to the view. "NLOBBY" {@link
* ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters}
*
* @param lobbyID
* @param adminName
*/
@ -223,12 +244,18 @@ public class LoungeSceneViewController implements Initializable {
//addGameView();
}
public void leaveLobby() {client.getClient().sendMsgToServer(Protocol.leaveLobby);}
public void leaveLobby() {
client.getClient().sendMsgToServer(Protocol.leaveLobby);
removeGameView();
}
public void leaveServer() {
client.getClient().sendMsgToServer(Protocol.clientQuitRequest);
}
public void leaveServer() {client.getClient().sendMsgToServer(Protocol.clientQuitRequest);}
/**
* Used to add a new player to the list of players.
* "NPLOS" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters}
* Used to add a new player to the list of players. "NPLOS" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters}
*
* @param s
*/
public void addClientToList(String s) {
@ -272,12 +299,5 @@ public class LoungeSceneViewController implements Initializable {
public static void setClient(ClientModel client) {
LoungeSceneViewController.client = client;
}
public HBox getChatAreaHBox() {
return ChatAreaHBox;
}
public void setChatAreaHBox(HBox chatAreaHBox) {
ChatAreaHBox = chatAreaHBox;
}
}

View File

@ -12,9 +12,9 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane fx:id="chatPaneRoot" prefHeight="251.0" prefWidth="343.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatController">
<AnchorPane fx:id="chatPaneRoot" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatController">
<children>
<GridPane alignment="CENTER" layoutY="149.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="251.0" prefWidth="343.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<GridPane alignment="CENTER" layoutY="149.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="273.5" prefWidth="2072.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="100.0" />
</columnConstraints>
@ -34,19 +34,19 @@
</AnchorPane>
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.rowIndex="1">
<children>
<GridPane alignment="CENTER" layoutX="10.0" layoutY="20.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="75.0" prefWidth="343.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<GridPane alignment="CENTER" layoutX="10.0" layoutY="20.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="82.0" prefWidth="2072.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="7.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="67.0" />
<ColumnConstraints hgrow="SOMETIMES" percentWidth="3.0" />
<ColumnConstraints hgrow="SOMETIMES" percentWidth="10.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="20.0" percentWidth="87.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" percentHeight="90.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="92.0" prefWidth="98.0" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.valignment="CENTER" GridPane.vgrow="ALWAYS">
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="56.0" prefWidth="125.0" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.valignment="CENTER" GridPane.vgrow="ALWAYS">
<children>
<Button fx:id="sendButton" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="157.0" prefWidth="223.5" text="Send" textOverrun="CENTER_WORD_ELLIPSIS" wrapText="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<Button fx:id="sendButton" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="56.0" prefWidth="178.0" text="Send" textOverrun="CENTER_WORD_ELLIPSIS" wrapText="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<font>
<Font size="10.0" />
</font></Button>
@ -57,7 +57,7 @@
</AnchorPane>
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="92.0" prefWidth="85.0" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.valignment="CENTER" GridPane.vgrow="ALWAYS">
<children>
<TextField fx:id="whisperTargetSelectField" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="50.0" prefWidth="79.0" promptText="whisper..." AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<TextField fx:id="whisperTargetSelectField" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="56.0" prefWidth="488.0" promptText="whisper..." AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
<GridPane.margin>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
@ -65,7 +65,7 @@
</AnchorPane>
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="92.0" prefWidth="366.0" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.valignment="CENTER" GridPane.vgrow="ALWAYS">
<children>
<TextField fx:id="chatMsgField" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="50.0" prefWidth="213.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<TextField fx:id="chatMsgField" layoutX="-420.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="56.0" prefWidth="1372.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
<GridPane.margin>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
@ -86,7 +86,7 @@
</AnchorPane>
</children>
</GridPane>
<GridPane fx:id="vBoxGridPane" alignment="CENTER" disable="true" layoutX="-14.0" layoutY="-235.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="167.0" prefWidth="331.0">
<GridPane fx:id="vBoxGridPane" alignment="CENTER" disable="true" layoutX="-14.0" layoutY="-235.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0" percentWidth="73.0" prefWidth="100.0" />
<ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0" percentWidth="66.0" prefWidth="100.0" />

View File

@ -2,10 +2,10 @@
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.ToolBar?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<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">
<children>
@ -22,16 +22,21 @@
<center>
<AnchorPane BorderPane.alignment="CENTER">
<children>
<Button fx:id="newGameButton" layoutX="136.0" layoutY="105.0" mnemonicParsing="false" text="New Lobby" />
<Button fx:id="newGameButton" layoutX="68.0" layoutY="101.0" mnemonicParsing="false" text="New Lobby" />
<AnchorPane fx:id="gameAnchorPane" />
<Button fx:id="startGame" layoutX="136.0" layoutY="141.0" mnemonicParsing="false" onAction="#startGame" text="Start Game" />
<Button fx:id="startGame" layoutX="68.0" layoutY="156.0" mnemonicParsing="false" onAction="#startGame" text="Start Game" />
</children>
</AnchorPane>
</center>
<bottom>
<AnchorPane fx:id="ChatArea" BorderPane.alignment="CENTER">
<AnchorPane fx:id="ChatArea" minHeight="100.0" BorderPane.alignment="CENTER">
<children>
<HBox fx:id="ChatAreaHBox" layoutX="394.0" layoutY="-33.0" prefWidth="842.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="-33.0" />
<SplitPane fx:id="chatSplitPane" dividerPositions="0.5" 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" />
</items>
</SplitPane>
</children>
</AnchorPane>
</bottom>