Adding Functionality to the view
This commit is contained in:
parent
d2907aa8ac
commit
9f7fc2556b
@ -2,6 +2,19 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.ClientListItem;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.server.Lobby;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import javafx.beans.property.SimpleListProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.collections.ObservableMap;
|
||||
import javafx.collections.ObservableSet;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -14,9 +27,17 @@ public class ClientModel {
|
||||
private Client client;
|
||||
private String incomingChatMsg;
|
||||
|
||||
private ObservableList<ClientListItem> allClients;
|
||||
private ObservableMap<Integer, SimpleStringProperty> idToNameMap;
|
||||
|
||||
|
||||
private HashSet<String> clientsOnServer;
|
||||
|
||||
public ClientModel(String username, Client client) {
|
||||
this.username = username;
|
||||
this.client = client;
|
||||
this.allClients = FXCollections.observableArrayList();
|
||||
this.idToNameMap = FXCollections.observableHashMap();
|
||||
}
|
||||
|
||||
//private Number;
|
||||
@ -36,4 +57,23 @@ public class ClientModel {
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public ObservableList<ClientListItem> getAllClients() {
|
||||
return allClients;
|
||||
}
|
||||
|
||||
public void addClientToList(ClientListItem nameAndId) {
|
||||
this.allClients.add(nameAndId);
|
||||
}
|
||||
|
||||
public void removeClientFromList(int id){
|
||||
Iterator<ClientListItem> it = allClients.iterator();
|
||||
while(it.hasNext()){
|
||||
int uid = it.next().getId();
|
||||
if(uid == id){
|
||||
it.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,8 +12,6 @@ import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Group;
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge;
|
||||
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
|
||||
public class ClientListItem {
|
||||
|
||||
private SimpleStringProperty name;
|
||||
private final SimpleIntegerProperty id;
|
||||
|
||||
public ClientListItem(SimpleStringProperty name, SimpleIntegerProperty id) {
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return name + " ID: " + id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name.get();
|
||||
}
|
||||
|
||||
public SimpleStringProperty nameProperty() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name.set(name);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id.get();
|
||||
}
|
||||
|
||||
public SimpleIntegerProperty idProperty() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
@ -1,14 +1,22 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ToggleButton;
|
||||
|
||||
public class LobbyListItem {
|
||||
|
||||
private Label lobbyID;
|
||||
private Label adminName;
|
||||
private List<String> clientInLobby;
|
||||
private ToggleButton button;
|
||||
private final Label lobbyID;
|
||||
private final Label adminName;
|
||||
private Set<StringProperty> clientsInLobby;
|
||||
private final ToggleButton button;
|
||||
|
||||
public LobbyListItem(Label lobbyID, Label adminName,
|
||||
Set<StringProperty> clientsInLobby, ToggleButton button) {
|
||||
this.lobbyID = lobbyID;
|
||||
this.adminName = adminName;
|
||||
this.clientsInLobby = clientsInLobby;
|
||||
this.button = button;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,76 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge;
|
||||
|
||||
public class LoungeSceneViewController {
|
||||
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 java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.beans.property.StringProperty;
|
||||
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.ToolBar;
|
||||
import javafx.scene.control.TreeView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
|
||||
public class LoungeSceneViewController implements Initializable {
|
||||
|
||||
|
||||
@FXML
|
||||
private TreeView LobbyTreeView;
|
||||
@FXML
|
||||
private ListView ClientListView;
|
||||
@FXML
|
||||
private Button ChangeNameButton;
|
||||
@FXML
|
||||
private Button LeaveServerButton;
|
||||
@FXML
|
||||
private AnchorPane ChatArea;
|
||||
@FXML
|
||||
private HBox ChatAreaHBox;
|
||||
@FXML
|
||||
private BorderPane LoungeSceneBorderPane;
|
||||
@FXML
|
||||
private ToolBar NTtBToolBar;
|
||||
|
||||
public static ClientModel client;
|
||||
|
||||
|
||||
/**
|
||||
* Called to initialize a controller after its root element has been completely processed.
|
||||
*
|
||||
* @param location The location used to resolve relative paths for the root object, or {@code
|
||||
* null} if the location is not known.
|
||||
* @param resources The resources used to localize the root object, or {@code null} if
|
||||
*/
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
ChangeNameButton.setOnAction(new ChangeNameButtonPressedEventHandler());
|
||||
LeaveServerButton.setOnAction(new LeaveServerButtonPressedEventHandler());
|
||||
}
|
||||
|
||||
public void updateLobbyListView(){
|
||||
|
||||
}
|
||||
|
||||
public void updateClientListView(){
|
||||
|
||||
}
|
||||
|
||||
public void addClientToList(ClientListItem player) {
|
||||
ListCell<StringProperty> playerCell = new ListCell<>();
|
||||
ClientListView.ite
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to set the client model for this class
|
||||
* @param client, the client model
|
||||
*/
|
||||
public static void setClient(ClientModel client) {
|
||||
LoungeSceneViewController.client = client;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<?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?>
|
||||
|
||||
|
||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="1080.0" prefWidth="1920.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" />
|
||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="1080.0" prefWidth="1920.0" 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>
|
||||
<BorderPane fx:id="LoungeSceneBorderPane" layoutX="860.0" layoutY="440.0" prefHeight="1080.0" prefWidth="1920.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<top>
|
||||
<ToolBar fx:id="NTtBToolBar" prefHeight="77.0" prefWidth="1913.0" BorderPane.alignment="CENTER">
|
||||
<items>
|
||||
<Button fx:id="ChangeNameButton" mnemonicParsing="false" text="Change Name" />
|
||||
<Button fx:id="LeaveServerButton" mnemonicParsing="false" text="Leave server" />
|
||||
</items>
|
||||
</ToolBar>
|
||||
</top>
|
||||
<center>
|
||||
<AnchorPane prefHeight="661.0" prefWidth="600.0" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<Button fx:id="newGameButton" mnemonicParsing="false" text="New Game" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</center>
|
||||
<bottom>
|
||||
<AnchorPane fx:id="ChatArea" prefHeight="342.0" prefWidth="1920.0" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<HBox fx:id="ChatAreaHBox" layoutX="394.0" layoutY="-9.0" prefHeight="322.0" prefWidth="1920.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</bottom>
|
||||
<left>
|
||||
<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" />
|
||||
</right>
|
||||
</BorderPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
||||
Reference in New Issue
Block a user