added method for adding a lobby to lobbylistview
This commit is contained in:
parent
77d1976332
commit
6e00128997
@ -8,6 +8,7 @@ import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GameStateModel;
|
|||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp;
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatController;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatController;
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeSceneViewController;
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ClientPinger;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ClientPinger;
|
||||||
|
|
||||||
|
|
||||||
@ -42,6 +43,7 @@ public class Client {
|
|||||||
private ClientModel clientModel;
|
private ClientModel clientModel;
|
||||||
private GameStateModel gameStateModel;
|
private GameStateModel gameStateModel;
|
||||||
private GameController gameController;
|
private GameController gameController;
|
||||||
|
private LoungeSceneViewController loungeSceneViewController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the position of the client, gets refreshed everytime the client gets a vote request.
|
* Saves the position of the client, gets refreshed everytime the client gets a vote request.
|
||||||
@ -75,6 +77,8 @@ public class Client {
|
|||||||
clientPinger = new ClientPinger(this, this.socket);
|
clientPinger = new ClientPinger(this, this.socket);
|
||||||
this.gameStateModel = new GameStateModel();
|
this.gameStateModel = new GameStateModel();
|
||||||
this.gameController = new GameController(ChatApp.getClientModel(), gameStateModel);
|
this.gameController = new GameController(ChatApp.getClientModel(), gameStateModel);
|
||||||
|
this.loungeSceneViewController = new LoungeSceneViewController();
|
||||||
|
LoungeSceneViewController.setClient(ChatApp.getClientModel());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -351,7 +355,7 @@ public class Client {
|
|||||||
//TODO
|
//TODO
|
||||||
break;
|
break;
|
||||||
case GuiParameters.listOfPLayers:
|
case GuiParameters.listOfPLayers:
|
||||||
updateListOfClients(data);
|
updateListOfClients(data);
|
||||||
//TODO
|
//TODO
|
||||||
break;
|
break;
|
||||||
//case GuiParameters.viewChangeToGame: (commented out due to compiling error)
|
//case GuiParameters.viewChangeToGame: (commented out due to compiling error)
|
||||||
@ -380,7 +384,7 @@ public class Client {
|
|||||||
int n = arr.length;
|
int n = arr.length;
|
||||||
for (int i = 0; i < n; i = i + 2) {
|
for (int i = 0; i < n; i = i + 2) {
|
||||||
list.add(new SimpleStringProperty(arr[i]));
|
list.add(new SimpleStringProperty(arr[i]));
|
||||||
ChatController.getClient().addLobbyToList(new SimpleStringProperty(arr[i]));
|
loungeSceneViewController.addLobbyToList(new SimpleStringProperty(arr[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,10 +392,10 @@ public class Client {
|
|||||||
String[] arr = data.split(":");
|
String[] arr = data.split(":");
|
||||||
ObservableList<SimpleStringProperty> list = new SimpleListProperty<>();
|
ObservableList<SimpleStringProperty> list = new SimpleListProperty<>();
|
||||||
int n = arr.length;
|
int n = arr.length;
|
||||||
for (int i = 0; i < n; i = i + 2) {
|
for (int i = 0; i < n; i = i + 1) {
|
||||||
list.add(new SimpleStringProperty(arr[i]));
|
list.add(new SimpleStringProperty(arr[i]));
|
||||||
}
|
}
|
||||||
ChatController.getClient().getAllClients().setAll();
|
loungeSceneViewController.updateClientListView(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -70,6 +70,10 @@ public class ClientModel {
|
|||||||
this.allClients.add(nameAndId);
|
this.allClients.add(nameAndId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateClientList(ObservableList<SimpleStringProperty> clients) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void removeClientFromList(String id){
|
public void removeClientFromList(String id){
|
||||||
Iterator<SimpleStringProperty> it = allClients.iterator();
|
Iterator<SimpleStringProperty> it = allClients.iterator();
|
||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
|
|||||||
@ -1,19 +1,22 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge;
|
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.beans.property.StringProperty;
|
import javafx.beans.property.StringProperty;
|
||||||
|
import javafx.collections.ObservableSet;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.ListCell;
|
||||||
import javafx.scene.control.ToggleButton;
|
import javafx.scene.control.ToggleButton;
|
||||||
|
|
||||||
public class LobbyListItem {
|
public class LobbyListItem extends ListCell {
|
||||||
|
|
||||||
private final Label lobbyID;
|
private final String lobbyID;
|
||||||
private final Label adminName;
|
private final String adminName;
|
||||||
private Set<StringProperty> clientsInLobby;
|
private ObservableSet<SimpleStringProperty> clientsInLobby;
|
||||||
private final ToggleButton button;
|
private final ToggleButton button;
|
||||||
|
|
||||||
public LobbyListItem(Label lobbyID, Label adminName,
|
public LobbyListItem(String lobbyID, String adminName,
|
||||||
Set<StringProperty> clientsInLobby, ToggleButton button) {
|
ObservableSet<SimpleStringProperty> clientsInLobby, ToggleButton button) {
|
||||||
this.lobbyID = lobbyID;
|
this.lobbyID = lobbyID;
|
||||||
this.adminName = adminName;
|
this.adminName = adminName;
|
||||||
this.clientsInLobby = clientsInLobby;
|
this.clientsInLobby = clientsInLobby;
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.events.LeaveServerButtonP
|
|||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import javafx.beans.property.SimpleListProperty;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.beans.property.StringProperty;
|
import javafx.beans.property.StringProperty;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
@ -17,6 +18,7 @@ import javafx.scene.control.Button;
|
|||||||
import javafx.scene.control.ListCell;
|
import javafx.scene.control.ListCell;
|
||||||
import javafx.scene.control.ListView;
|
import javafx.scene.control.ListView;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.control.TitledPane;
|
||||||
import javafx.scene.control.ToolBar;
|
import javafx.scene.control.ToolBar;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
@ -47,6 +49,11 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
|
|
||||||
public static ClientModel client;
|
public static ClientModel client;
|
||||||
|
|
||||||
|
public LoungeSceneViewController() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to initialize a controller after its root element has been completely processed.
|
* Called to initialize a controller after its root element has been completely processed.
|
||||||
@ -74,8 +81,27 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
this.ClientListView.setItems(names);
|
this.ClientListView.setItems(names);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLobby(LobbyListItem lobby) {
|
/**
|
||||||
//TODO
|
* Adds a lobby to the view
|
||||||
|
* @param lobbyID
|
||||||
|
* @param admin
|
||||||
|
* @param players
|
||||||
|
*/
|
||||||
|
public void addLobby(String lobbyID, String admin, String players) {
|
||||||
|
TitledPane lobbyObject = new TitledPane();
|
||||||
|
lobbyObject.setId(lobbyID+admin);
|
||||||
|
lobbyObject.textProperty().setValue("Lobby Nr: " + lobbyID + " Admin: " + admin);
|
||||||
|
|
||||||
|
ObservableList<SimpleStringProperty> listOfPlayersInLobby = new SimpleListProperty<>();
|
||||||
|
|
||||||
|
String[] playersArr = players.split(":");
|
||||||
|
int noOfPlayers = playersArr.length;
|
||||||
|
for(int i = 0; i < noOfPlayers; i++){
|
||||||
|
listOfPlayersInLobby.add(new SimpleStringProperty(playersArr[i]));
|
||||||
|
}
|
||||||
|
ListView view = new ListView(listOfPlayersInLobby);
|
||||||
|
lobbyObject.contentProperty().set(view);
|
||||||
|
LobbyListView.getItems().add(lobbyObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addClientToList(String s) {
|
public void addClientToList(String s) {
|
||||||
|
|||||||
Reference in New Issue
Block a user