C
This commit is contained in:
parent
c066763f97
commit
017a8a1c99
@ -20,7 +20,9 @@ import java.io.*;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Objects;
|
||||
import java.util.Scanner;
|
||||
import javafx.beans.property.SimpleListProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -372,14 +374,26 @@ public class Client {
|
||||
|
||||
}
|
||||
|
||||
private void updateListOfClients(String data) {
|
||||
private void updateListOfLobbies(String data) {
|
||||
String[] arr = data.split(":");
|
||||
ObservableList<SimpleStringProperty> list = new SimpleListProperty<>();
|
||||
int n = arr.length;
|
||||
for (int i = 0; i < n; i = i + 2) {
|
||||
ChatController.getClient().addClientToList(new SimpleStringProperty(arr[i]));
|
||||
list.add(new SimpleStringProperty(arr[i]));
|
||||
ChatController.getClient().addLobbyToList(new SimpleStringProperty(arr[i]));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateListOfClients(String data) {
|
||||
String[] arr = data.split(":");
|
||||
ObservableList<SimpleStringProperty> list = new SimpleListProperty<>();
|
||||
int n = arr.length;
|
||||
for (int i = 0; i < n; i = i + 2) {
|
||||
list.add(new SimpleStringProperty(arr[i]));
|
||||
}
|
||||
ChatController.getClient().getAllClients().setAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new thread, thad adds a message to notificationText in the gameController, waits 3
|
||||
* seconds and deletes it again.
|
||||
|
||||
@ -30,6 +30,8 @@ public class ClientModel {
|
||||
private ObservableList<SimpleStringProperty> allClients;
|
||||
private ObservableMap<Integer, SimpleStringProperty> idToNameMap;
|
||||
|
||||
private ObservableList<SimpleStringProperty> lobbies;
|
||||
|
||||
|
||||
private HashSet<String> clientsOnServer;
|
||||
|
||||
@ -38,6 +40,7 @@ public class ClientModel {
|
||||
this.client = client;
|
||||
this.allClients = FXCollections.observableArrayList();
|
||||
this.idToNameMap = FXCollections.observableHashMap();
|
||||
this.lobbies = FXCollections.observableArrayList();
|
||||
}
|
||||
|
||||
//private Number;
|
||||
|
||||
@ -3,26 +3,33 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.events.ChangeNameButtonPressedEventHandler;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.events.LeaveServerButtonPressedEventHandler;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.ToolBar;
|
||||
import javafx.scene.control.TreeView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.text.Text;
|
||||
|
||||
public class LoungeSceneViewController implements Initializable {
|
||||
|
||||
Protocol protocol;
|
||||
|
||||
public Button newGameButton;
|
||||
@FXML
|
||||
private TreeView LobbyTreeView;
|
||||
private ListView LobbyListView;
|
||||
@FXML
|
||||
private ListView ClientListView;
|
||||
@FXML
|
||||
@ -50,30 +57,52 @@ public class LoungeSceneViewController implements Initializable {
|
||||
*/
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
ChangeNameButton.setOnAction(new ChangeNameButtonPressedEventHandler());
|
||||
this.protocol = new Protocol();
|
||||
ChangeNameButton.setOnAction(event -> changeName());
|
||||
LeaveServerButton.setOnAction(new LeaveServerButtonPressedEventHandler());
|
||||
newGameButton.setOnAction(event -> newGame());
|
||||
|
||||
ClientListView.se
|
||||
|
||||
ClientListView.setItems(client.getAllClients());
|
||||
LobbyListView.setPlaceholder(new Text("No open lobbies!"));
|
||||
}
|
||||
|
||||
public void updateLobbyListView(){
|
||||
|
||||
public void updateLobbyListView() {
|
||||
//TODO
|
||||
}
|
||||
|
||||
public void updateClientListView(){
|
||||
|
||||
public void updateClientListView(ObservableList<SimpleStringProperty> names) {
|
||||
this.ClientListView.setItems(names);
|
||||
}
|
||||
|
||||
public void addLobby(LobbyListItem lobby) {
|
||||
//TODO fix/complete following code: LobbyTreeView. (commented out due to compiling error)
|
||||
//TODO
|
||||
}
|
||||
|
||||
public void addClientToList(ClientListItem player) {
|
||||
ListCell<StringProperty> playerCell = new ListCell<>();
|
||||
public void addClientToList(String s) {
|
||||
ClientListView.getItems().add(new SimpleStringProperty(s));
|
||||
}
|
||||
|
||||
public void newGame() {
|
||||
client.getClient().sendMsgToServer(Protocol.createNewLobby);
|
||||
}
|
||||
|
||||
public void changeName() {
|
||||
TextField name = new TextField("Enter new name!");
|
||||
this.NTtBToolBar.getItems().add(name);
|
||||
name.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
client.getClient().sendMsgToServer(Protocol.nameChange + "$" + name.getText());
|
||||
NTtBToolBar.getItems().remove(NTtBToolBar.getItems().size());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to set the client model for this class
|
||||
*
|
||||
* @param client, the client model
|
||||
*/
|
||||
public static void setClient(ClientModel client) {
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
<ListView fx:id="ClientListView" prefHeight="681.0" prefWidth="661.0" BorderPane.alignment="CENTER" />
|
||||
</left>
|
||||
<right>
|
||||
<TreeView fx:id="LobbyTreeView" prefHeight="681.0" prefWidth="641.0" BorderPane.alignment="CENTER" />
|
||||
<ListView fx:id="LobbyListView" prefHeight="681.0" prefWidth="641.0" BorderPane.alignment="CENTER" />
|
||||
</right>
|
||||
</BorderPane>
|
||||
</children>
|
||||
|
||||
Reference in New Issue
Block a user