Deleted more methods associated with the player list that are not needed anymore.

The ChatView is now directly added to the anchor pone in the "Bottom"Child of the BorderPane representing the LoungeSceneView.fxml Root
This commit is contained in:
Sebastian Lenzlinger 2022-05-13 12:04:32 +02:00
parent b605669395
commit 65303a4bb6
3 changed files with 7 additions and 150 deletions

View File

@ -368,10 +368,6 @@ public class Client {
case GuiParameters.VoteIsOver: case GuiParameters.VoteIsOver:
chatApp.getGameController().clearAllNoiseDisplay(); chatApp.getGameController().clearAllNoiseDisplay();
break; break;
case GuiParameters.listOfPLayers:
updateListOfClients(data);
//TODO
break;
case GuiParameters.getMembersInLobby: case GuiParameters.getMembersInLobby:
updateLobbyMembers(data); updateLobbyMembers(data);
break; break;
@ -392,9 +388,6 @@ public class Client {
case GuiParameters.newLobbyCreated: case GuiParameters.newLobbyCreated:
makeNewLobby(data); makeNewLobby(data);
break; break;
case GuiParameters.newPlayerOnServer:
addNewPlayerToGui(data);
break;
case GuiParameters.updateHighScore: case GuiParameters.updateHighScore:
chatApp.getLoungeSceneViewController().addHighScore(data); chatApp.getLoungeSceneViewController().addHighScore(data);
break; break;
@ -422,11 +415,6 @@ public class Client {
LOGGER.debug("Made it into removeLobbyFromGui()"); LOGGER.debug("Made it into removeLobbyFromGui()");
} }
private void addNewPlayerToGui(String data) {
loungeSceneViewController.addClientToList(data);
LOGGER.debug("addNewPlayerToGui() seems to have finished");
}
private void makeNewLobby(String data) { private void makeNewLobby(String data) {
String[] params = data.split(":"); String[] params = data.split(":");
loungeSceneViewController.newLobby(params[0], params[1]); loungeSceneViewController.newLobby(params[0], params[1]);
@ -457,14 +445,6 @@ public class Client {
//TODO //TODO
} }
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 + 1) {
loungeSceneViewController.addClientToList(arr[i]);
}
}
/** /**
* Starts a new thread, thad adds a message to notificationText in the gameController, waits 3 * Starts a new thread, thad adds a message to notificationText in the gameController, waits 3

View File

@ -61,10 +61,6 @@ public class LoungeSceneViewController implements Initializable {
@FXML @FXML
private SplitPane chatSplitPane; private SplitPane chatSplitPane;
@FXML @FXML
private AnchorPane chatAnchorPane;
@FXML
private AnchorPane otherNotificationAnchorPane;
@FXML
public Button highScoreButton; public Button highScoreButton;
@FXML @FXML
private Button leaveLobbyButton; private Button leaveLobbyButton;
@ -79,8 +75,6 @@ public class LoungeSceneViewController implements Initializable {
@FXML @FXML
public ListView<LobbyListItem> LobbyListView; public ListView<LobbyListItem> LobbyListView;
@FXML @FXML
public ListView<ClientListItem> ClientListView;
@FXML
private Button ChangeNameButton; private Button ChangeNameButton;
@FXML @FXML
private Button LeaveServerButton; private Button LeaveServerButton;
@ -92,7 +86,6 @@ public class LoungeSceneViewController implements Initializable {
private ToolBar NTtBToolBar; private ToolBar NTtBToolBar;
public static ListView<LobbyListItem> lListView; public static ListView<LobbyListItem> lListView;
public static ListView<ClientListItem> cListView;
public static ClientModel client; public static ClientModel client;
private static ChatApp chatApp; private static ChatApp chatApp;
@ -145,92 +138,12 @@ public class LoungeSceneViewController implements Initializable {
newGameButton.setOnAction(event -> newGame()); newGameButton.setOnAction(event -> newGame());
LobbyListView.setVisible(true); LobbyListView.setVisible(true);
lListView = LobbyListView; lListView = LobbyListView;
cListView = ClientListView;
LOGGER.debug("Lobby in initialize" + LobbyListView); LOGGER.debug("Lobby in initialize" + LobbyListView);
ClientListView.setVisible(true);
ClientListView.setItems(clients);
addChatView(); addChatView();
addBackgroundDay(); addBackgroundDay();
LOGGER.debug("cApp = " + cApp); LOGGER.debug("cApp = " + cApp);
LOGGER.debug("chatApp = " + chatApp); LOGGER.debug("chatApp = " + chatApp);
TrainAnimationDayController.setcApp(cApp); TrainAnimationDayController.setcApp(cApp);
ClientListView.setItems(clients);
ClientListView.setCellFactory(param -> {
ListCell<ClientListItem> cell = new ListCell<>() {
Label name = new Label();
Label id = new Label();
HBox nameAndId = new HBox(name, id);
{
nameAndId.setAlignment(Pos.CENTER_LEFT);
}
/**
* The updateItem method should not be called by developers, but it is the
* best method for developers to override to allow for them to customise the
* visuals of the cell. To clarify, developers should never call this method
* in their code (they should leave it up to the UI control, such as the
* {@link ListView} control) to call this method. However, the purpose of
* having the updateItem method is so that developers, when specifying
* custom cell factories (again, like the ListView {@link
* ListView#cellFactoryProperty() cell factory}), the updateItem method can
* be overridden to allow for complete customisation of the cell.
*
* <p>It is <strong>very important</strong> that subclasses
* of Cell override the updateItem method properly, as failure to do so will
* lead to issues such as blank cells or cells with unexpected content
* appearing within them. Here is an example of how to properly override the
* updateItem method:
*
* <pre>
* protected void updateItem(T item, boolean empty) {
* super.updateItem(item, empty);
*
* if (empty || item == null) {
* setText(null);
* setGraphic(null);
* } else {
* setText(item.toString());
* }
* }
* </pre>
*
* <p>Note in this code sample two important points:
* <ol>
* <li>We call the super.updateItem(T, boolean) method. If this is not
* done, the item and empty properties are not correctly set, and you are
* likely to end up with graphical issues.</li>
* <li>We test for the <code>empty</code> condition, and if true, we
* set the text and graphic properties to null. If we do not do this,
* it is almost guaranteed that end users will see graphical artifacts
* in cells unexpectedly.</li>
* </ol>
* @param item The new item for the cell.
*
* @param empty whether or not this cell represents data from the list. If
* it is empty, then it does not represent any domain data, but
* is a cell
*/
@Override
protected void updateItem(ClientListItem item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
LOGGER.debug("In updateItem(item, empty) Method. Else branch -> nonnull item");
name.setText(item.getName());
name.setTextFill(Color.BLACK);
id.setText(String.valueOf(item.getId()));
id.setTextFill(Color.BLACK);
setGraphic(nameAndId);
}
}
};
return cell;
});
LobbyListView.setItems(lobbies); LobbyListView.setItems(lobbies);
LOGGER.debug("In Initialize 2 LobbyListView" + LobbyListView); LOGGER.debug("In Initialize 2 LobbyListView" + LobbyListView);
LobbyListView.setCellFactory(param -> { LobbyListView.setCellFactory(param -> {
@ -375,7 +288,7 @@ public class LoungeSceneViewController implements Initializable {
@Override @Override
public void run() { public void run() {
try { try {
chatAnchorPane.getChildren().add(chatApp.chat); ChatArea.getChildren().add(chatApp.chat);
} catch (Exception e) { } catch (Exception e) {
LOGGER.debug("Not yet initialized: chatAnchorPane"); LOGGER.debug("Not yet initialized: chatAnchorPane");
} }
@ -493,45 +406,6 @@ public class LoungeSceneViewController implements Initializable {
client.getClient().sendMsgToServer(Protocol.clientQuitRequest); 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}
*
* @param s the information corresponding to to the client in String from
*/
public void addClientToList(String s) {
ClientListItem cl = new ClientListItem(s);
ClientListView = cListView;
Platform.runLater(new Runnable() {
@Override
public void run() {
clients.add(cl);
LOGGER.debug("in addClientToList() in run()");
LOGGER.debug(cl.toString() + " in run()");
}
});
}
/**
* Sould remove a client of a certain name from the ListView
*
* @param name the name of the client to be removed
*/
public void removeClientFromList(String name) {
Iterator<ClientListItem> it = clients.iterator();
while (it.hasNext()) {
String uid = it.next().getName();
if (uid.equals(name)) {
it.remove();
break;
}
}
}
public void removeClientFromLobby(String s) {
//todo
}
/** /**
* Sends the create New Lobby Protocol message * Sends the create New Lobby Protocol message
*/ */

View File

@ -34,9 +34,13 @@
</AnchorPane> </AnchorPane>
</center> </center>
<bottom> <bottom>
<AnchorPane fx:id="ChatArea" pickOnBounds="false" BorderPane.alignment="CENTER"> <AnchorPane fx:id="ChatArea" pickOnBounds="false" prefHeight="83.0" prefWidth="578.0" BorderPane.alignment="CENTER">
<children> <children>
<SplitPane fx:id="chatSplitPane" minHeight="50.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" /> <SplitPane fx:id="chatSplitPane" disable="true" dividerPositions="0.5" layoutY="-34.0" minHeight="50.0" prefHeight="46.0" prefWidth="578.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane fx:id="ChatArea" prefHeight="200.0" prefWidth="200.0" />
<AnchorPane prefHeight="200.0" prefWidth="200.0" />
</items></SplitPane>
</children> </children>
</AnchorPane> </AnchorPane>
</bottom> </bottom>
@ -56,6 +60,5 @@
</left> </left>
</BorderPane> </BorderPane>
<AnchorPane fx:id="gameDisplayAnchorPane" pickOnBounds="false" /> <AnchorPane fx:id="gameDisplayAnchorPane" pickOnBounds="false" />
<Line endX="100.0" startX="-100.0" />
</children> </children>
</AnchorPane> </AnchorPane>