Added Method for adding clients to gui view
This commit is contained in:
parent
2996f7aca7
commit
6a520ca83a
@ -20,6 +20,7 @@ import java.io.*;
|
|||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ public class Client {
|
|||||||
|
|
||||||
private ChatApp chatApp;
|
private ChatApp chatApp;
|
||||||
private GUI chatGui;
|
private GUI chatGui;
|
||||||
|
private ClientModel clientModel;
|
||||||
private GameStateModel gameStateModel;
|
private GameStateModel gameStateModel;
|
||||||
private GameController gameController;
|
private GameController gameController;
|
||||||
|
|
||||||
@ -133,13 +135,13 @@ public class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts infromation about names and positions and roles from string and adds it to
|
* Extracts infromation about names and positions and roles from string and adds it to the
|
||||||
* the GameStateModel
|
* GameStateModel
|
||||||
|
*
|
||||||
* @param msg
|
* @param msg
|
||||||
*/
|
*/
|
||||||
public void gameStateModelSetter(String msg) {
|
public void gameStateModelSetter(String msg) {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -224,6 +226,7 @@ public class Client {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The main Method used for testing in IDE
|
* The main Method used for testing in IDE
|
||||||
|
*
|
||||||
* @param args not used in this main
|
* @param args not used in this main
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -262,6 +265,7 @@ public class Client {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The main-method used for the jar build of this project
|
* The main-method used for the jar build of this project
|
||||||
|
*
|
||||||
* @param address the IP address of the Server (can be localhost)
|
* @param address the IP address of the Server (can be localhost)
|
||||||
* @param port the port for the connection
|
* @param port the port for the connection
|
||||||
* @param username the username of this client
|
* @param username the username of this client
|
||||||
@ -310,9 +314,12 @@ public class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* funnels a message to the gui, where depending on the parameter different functions/controls/methods
|
* funnels a message to the gui, where depending on the parameter different
|
||||||
* of the gui are targeted. The data contains more information the gui needs
|
* functions/controls/methods of the gui are targeted. The data contains more information the gui
|
||||||
* @param parameter a string according to {@link GuiParameters} and {@link ClientGameInfoHandler} can be empty
|
* needs
|
||||||
|
*
|
||||||
|
* @param parameter a string according to {@link GuiParameters} and {@link ClientGameInfoHandler}
|
||||||
|
* can be empty
|
||||||
* @param data some information in a string, separators can be $ or :
|
* @param data some information in a string, separators can be $ or :
|
||||||
* TODO(Seraina&Sebi): evtl. auslagern?
|
* TODO(Seraina&Sebi): evtl. auslagern?
|
||||||
*/
|
*/
|
||||||
@ -338,9 +345,11 @@ public class Client {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GuiParameters.listOfLobbies:
|
case GuiParameters.listOfLobbies:
|
||||||
|
updateListOfLobbies(data);
|
||||||
//TODO
|
//TODO
|
||||||
break;
|
break;
|
||||||
case GuiParameters.listOfPLayers:
|
case GuiParameters.listOfPLayers:
|
||||||
|
updateListOfClients(data);
|
||||||
//TODO
|
//TODO
|
||||||
break;
|
break;
|
||||||
case GuiParameters.viewChangeToGame:
|
case GuiParameters.viewChangeToGame:
|
||||||
@ -363,9 +372,18 @@ public class Client {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateListOfClients(String data) {
|
||||||
|
String[] arr = data.split(":");
|
||||||
|
int n = arr.length;
|
||||||
|
for (int i = 0; i < n; i = i + 2) {
|
||||||
|
ChatController.getClient().addClientToList(new SimpleStringProperty(arr[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a new thread, thad adds a message to notificationText in the gameController,
|
* Starts a new thread, thad adds a message to notificationText in the gameController, waits 3
|
||||||
* waits 3 seconds and deletes it again.
|
* seconds and deletes it again.
|
||||||
|
*
|
||||||
* @param data the message to be added
|
* @param data the message to be added
|
||||||
*/
|
*/
|
||||||
public void notificationTextDisplay(String data) {
|
public void notificationTextDisplay(String data) {
|
||||||
|
|||||||
@ -27,7 +27,7 @@ public class ClientModel {
|
|||||||
private Client client;
|
private Client client;
|
||||||
private String incomingChatMsg;
|
private String incomingChatMsg;
|
||||||
|
|
||||||
private ObservableList<ClientListItem> allClients;
|
private ObservableList<SimpleStringProperty> allClients;
|
||||||
private ObservableMap<Integer, SimpleStringProperty> idToNameMap;
|
private ObservableMap<Integer, SimpleStringProperty> idToNameMap;
|
||||||
|
|
||||||
|
|
||||||
@ -58,19 +58,20 @@ public class ClientModel {
|
|||||||
this.username = username;
|
this.username = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableList<ClientListItem> getAllClients() {
|
public ObservableList<SimpleStringProperty> getAllClients() {
|
||||||
return allClients;
|
return allClients;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addClientToList(ClientListItem nameAndId) {
|
public void addClientToList(SimpleStringProperty nameAndId) {
|
||||||
|
if(!allClients.contains(nameAndId))
|
||||||
this.allClients.add(nameAndId);
|
this.allClients.add(nameAndId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeClientFromList(int id){
|
public void removeClientFromList(String id){
|
||||||
Iterator<ClientListItem> it = allClients.iterator();
|
Iterator<SimpleStringProperty> it = allClients.iterator();
|
||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
int uid = it.next().getId();
|
String uid = it.next().getValue();
|
||||||
if(uid == id){
|
if(uid.equals(id)){
|
||||||
it.remove();
|
it.remove();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import javafx.scene.layout.HBox;
|
|||||||
public class LoungeSceneViewController implements Initializable {
|
public class LoungeSceneViewController implements Initializable {
|
||||||
|
|
||||||
|
|
||||||
|
public Button newGameButton;
|
||||||
@FXML
|
@FXML
|
||||||
private TreeView LobbyTreeView;
|
private TreeView LobbyTreeView;
|
||||||
@FXML
|
@FXML
|
||||||
@ -51,6 +52,8 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
ChangeNameButton.setOnAction(new ChangeNameButtonPressedEventHandler());
|
ChangeNameButton.setOnAction(new ChangeNameButtonPressedEventHandler());
|
||||||
LeaveServerButton.setOnAction(new LeaveServerButtonPressedEventHandler());
|
LeaveServerButton.setOnAction(new LeaveServerButtonPressedEventHandler());
|
||||||
|
|
||||||
|
ClientListView.setItems(client.getAllClients());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateLobbyListView(){
|
public void updateLobbyListView(){
|
||||||
@ -61,9 +64,12 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addLobby(LobbyListItem lobby) {
|
||||||
|
LobbyTreeView.
|
||||||
|
}
|
||||||
|
|
||||||
public void addClientToList(ClientListItem player) {
|
public void addClientToList(ClientListItem player) {
|
||||||
ListCell<StringProperty> playerCell = new ListCell<>();
|
ListCell<StringProperty> playerCell = new ListCell<>();
|
||||||
ClientListView.ite
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.multiplayer.helpers;
|
package ch.unibas.dmi.dbis.cs108.multiplayer.helpers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class contains parameters for the PTGUI protocol message
|
* This class contains all parameters for the PTGUI protocol message
|
||||||
*/
|
*/
|
||||||
public class GuiParameters {
|
public class GuiParameters {
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ public class GuiParameters {
|
|||||||
public static final String listOfLobbies = "LOBBIES";
|
public static final String listOfLobbies = "LOBBIES";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells Gui, that what follows is a list of players per Lobby
|
* Tells Gui, that what follows is a list of players (per Lobby?)
|
||||||
*/
|
*/
|
||||||
public static final String listOfPLayers = "PLAYERS";
|
public static final String listOfPLayers = "PLAYERS";
|
||||||
|
|
||||||
@ -25,21 +25,10 @@ public class GuiParameters {
|
|||||||
*/
|
*/
|
||||||
public static final String noiseHeardAtPosition = "NOISE";
|
public static final String noiseHeardAtPosition = "NOISE";
|
||||||
|
|
||||||
/**
|
|
||||||
* Tells Gui, that the start view should be displayed
|
|
||||||
*/
|
|
||||||
public static final String viewChangeToStart = "VCSTART";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells Gui, that the lobby view should be displayed
|
* Tells, Gui, who the members of a specified Lobby are.
|
||||||
|
* Form: {@code LMEMBS$<lobbyID>$<member names>$..}
|
||||||
*/
|
*/
|
||||||
public static final String viewChangeToLobby = "VCLOBBY";
|
public static String viewChangeToLobby = "LMEMBS";
|
||||||
|
|
||||||
/**
|
|
||||||
* Tells Gui, that the game view should be displayed
|
|
||||||
*/
|
|
||||||
public static final String viewChangeToGame = "VCGAME";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user