Fever dream
This commit is contained in:
parent
9007870d19
commit
2e9a47cbd4
@ -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.LoungeApp;
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeSceneViewController;
|
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;
|
||||||
|
|
||||||
@ -39,10 +40,15 @@ public class Client {
|
|||||||
public ClientPinger clientPinger;
|
public ClientPinger clientPinger;
|
||||||
|
|
||||||
private ChatApp chatApp;
|
private ChatApp chatApp;
|
||||||
private GUI chatGui;
|
//private GUI chatGui;
|
||||||
private ClientModel clientModel;
|
private ClientModel clientModel;
|
||||||
private GameStateModel gameStateModel;
|
private GameStateModel gameStateModel;
|
||||||
private GameController gameController;
|
private GameController gameController;
|
||||||
|
|
||||||
|
private GUI gui;
|
||||||
|
|
||||||
|
private LoungeApp loungeApp;
|
||||||
|
//private GUI loungeGui;
|
||||||
private LoungeSceneViewController loungeSceneViewController;
|
private LoungeSceneViewController loungeSceneViewController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,10 +79,13 @@ public class Client {
|
|||||||
}
|
}
|
||||||
sendMsgToServer(Protocol.clientLogin + "$" + systemName);
|
sendMsgToServer(Protocol.clientLogin + "$" + systemName);
|
||||||
this.chatApp = new ChatApp(new ClientModel(systemName, this));
|
this.chatApp = new ChatApp(new ClientModel(systemName, this));
|
||||||
this.chatGui = new GUI(this.chatApp);
|
//this.chatGui = new GUI(this.chatApp);
|
||||||
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.loungeApp = new LoungeApp(ChatApp.getClientModel());
|
||||||
|
//this.loungeGui = new GUI(this.loungeApp);
|
||||||
|
this.gui = new GUI(this.chatApp,this.loungeApp);
|
||||||
this.loungeSceneViewController = new LoungeSceneViewController();
|
this.loungeSceneViewController = new LoungeSceneViewController();
|
||||||
LoungeSceneViewController.setClient(ChatApp.getClientModel());
|
LoungeSceneViewController.setClient(ChatApp.getClientModel());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -257,7 +266,7 @@ public class Client {
|
|||||||
cP.start();
|
cP.start();
|
||||||
client.userInputListener(); //this one blocks.
|
client.userInputListener(); //this one blocks.
|
||||||
//Start the GUI
|
//Start the GUI
|
||||||
GUI gui = new GUI(client.chatApp);
|
GUI gui = new GUI(client.chatApp,client.loungeApp);
|
||||||
Thread guiThread = new Thread(gui);
|
Thread guiThread = new Thread(gui);
|
||||||
guiThread.start();
|
guiThread.start();
|
||||||
LOGGER.info("7");
|
LOGGER.info("7");
|
||||||
@ -287,7 +296,7 @@ public class Client {
|
|||||||
cP.start();
|
cP.start();
|
||||||
client.userInputListener(); //this one blocks.
|
client.userInputListener(); //this one blocks.
|
||||||
LOGGER.info("7.1");
|
LOGGER.info("7.1");
|
||||||
Thread guiThread = new Thread(client.chatGui);
|
Thread guiThread = new Thread(client.gui);
|
||||||
LOGGER.info("8");
|
LOGGER.info("8");
|
||||||
guiThread.start();
|
guiThread.start();
|
||||||
LOGGER.info("9");
|
LOGGER.info("9");
|
||||||
|
|||||||
@ -61,12 +61,12 @@ public class JClientProtocolParser {
|
|||||||
break;
|
break;
|
||||||
case Protocol.printToGUI:
|
case Protocol.printToGUI:
|
||||||
String substring = msg.substring(6);
|
String substring = msg.substring(6);
|
||||||
int index = msg.indexOf("$");
|
int index = substring.indexOf("$");
|
||||||
String parameter = "";
|
String parameter = "";
|
||||||
String data = substring;
|
String data = substring;
|
||||||
try {
|
try {
|
||||||
parameter = msg.substring(0,index);
|
parameter = substring.substring(0,index);
|
||||||
data = msg.substring(index+1);
|
data = substring.substring(index+1);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.warn("No parameter in PTGUI");
|
LOGGER.warn("No parameter in PTGUI");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
|
|||||||
|
|
||||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||||
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.lounge.LoungeApp;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@ -12,12 +13,21 @@ public class GUI implements Runnable {
|
|||||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||||
|
|
||||||
private ChatApp chatApp;
|
private ChatApp chatApp;
|
||||||
|
private LoungeApp loungeApp;
|
||||||
|
|
||||||
public GUI(ChatApp chatApp) {
|
public GUI(ChatApp chatApp) {
|
||||||
this.chatApp = chatApp;
|
this.chatApp = chatApp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GUI(LoungeApp loungeApp) {
|
||||||
|
this.loungeApp = loungeApp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GUI(ChatApp chatApp,
|
||||||
|
LoungeApp loungeApp) {
|
||||||
|
this.chatApp = chatApp;
|
||||||
|
this.loungeApp = loungeApp;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When an object implementing interface {@code Runnable} is used to create a thread, starting the
|
* When an object implementing interface {@code Runnable} is used to create a thread, starting the
|
||||||
@ -32,6 +42,7 @@ public class GUI implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
LOGGER.info("here");
|
LOGGER.info("here");
|
||||||
Application.launch(this.chatApp.getClass());
|
//Application.launch(this.chatApp.getClass());
|
||||||
|
Application.launch(this.loungeApp.getClass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
|
|||||||
|
|
||||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeSceneViewController;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
@ -21,6 +22,8 @@ public class ChatApp extends Application {
|
|||||||
private static ChatController chatController;
|
private static ChatController chatController;
|
||||||
private ClientModel cModel;
|
private ClientModel cModel;
|
||||||
|
|
||||||
|
private static LoungeSceneViewController loungeSceneViewController;
|
||||||
|
|
||||||
public ChatApp() {
|
public ChatApp() {
|
||||||
super();
|
super();
|
||||||
LOGGER.info("Empty ChatApp constructor got called: ");
|
LOGGER.info("Empty ChatApp constructor got called: ");
|
||||||
@ -66,6 +69,10 @@ public class ChatApp extends Application {
|
|||||||
return chatController;
|
return chatController;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setLoungeSceneViewController(LoungeSceneViewController controller) {
|
||||||
|
loungeSceneViewController = controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main entry point for all JavaFX applications. The start method is called after the init
|
* The main entry point for all JavaFX applications. The start method is called after the init
|
||||||
@ -94,6 +101,7 @@ public class ChatApp extends Application {
|
|||||||
Objects.requireNonNull(ChatApp.class.getResource(
|
Objects.requireNonNull(ChatApp.class.getResource(
|
||||||
"ChatView.fxml")));
|
"ChatView.fxml")));
|
||||||
// TODO bin chatController.getChatPaneRoot() border to root border for rezising
|
// TODO bin chatController.getChatPaneRoot() border to root border for rezising
|
||||||
|
|
||||||
Scene scene = new Scene(root);
|
Scene scene = new Scene(root);
|
||||||
scene.setRoot(root);
|
scene.setRoot(root);
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(scene);
|
||||||
@ -101,7 +109,7 @@ public class ChatApp extends Application {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
primaryStage.setResizable(true);
|
primaryStage.setResizable(true);
|
||||||
primaryStage.setTitle("Chat");
|
primaryStage.setTitle("Lounge");
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,128 @@
|
|||||||
|
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge;
|
||||||
|
|
||||||
|
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatController;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Objects;
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for debugging the lounge gui scene
|
||||||
|
*/
|
||||||
|
public class LoungeApp extends Application {
|
||||||
|
|
||||||
|
public static final Logger LOGGER = LogManager.getLogger(ChatApp.class);
|
||||||
|
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||||
|
|
||||||
|
private static ClientModel clientModel;
|
||||||
|
private static ChatController chatController;
|
||||||
|
private ClientModel cModel;
|
||||||
|
|
||||||
|
private static LoungeSceneViewController loungeSceneViewController;
|
||||||
|
|
||||||
|
public LoungeApp() {
|
||||||
|
super();
|
||||||
|
LOGGER.info("Empty ChatApp constructor got called: ");
|
||||||
|
}
|
||||||
|
|
||||||
|
public LoungeApp(ClientModel clientM) {
|
||||||
|
clientModel = clientM;
|
||||||
|
chatController = new ChatController(clientM);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the ChatController for the Application, needs to be static, but only one application can
|
||||||
|
* be launched per programm
|
||||||
|
*
|
||||||
|
* @param chatC the ChatController to be linked to this chatApp
|
||||||
|
*/
|
||||||
|
public static void setChatController(ChatController chatC) {
|
||||||
|
chatController = chatC;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the non-static ClientModel field of this class
|
||||||
|
*
|
||||||
|
* @param cModel the non static ClientModel to be added
|
||||||
|
*/
|
||||||
|
public void setcModel(ClientModel cModel) {
|
||||||
|
this.cModel = cModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientModel getcModel() {
|
||||||
|
return cModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setClientModel(ClientModel clientM) {
|
||||||
|
clientModel = clientM;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ClientModel getClientModel() {
|
||||||
|
return clientModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChatController getChatController() {
|
||||||
|
return chatController;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setLoungeSceneViewController(LoungeSceneViewController controller) {
|
||||||
|
loungeSceneViewController = controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main entry point for all JavaFX applications. The start method is called after the init
|
||||||
|
* method has returned, and after the system is ready for the application to begin running.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* NOTE: This method is called on the JavaFX Application Thread.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param primaryStage the primary stage for this application, onto which the application scene
|
||||||
|
* can be set. Applications may create other stages, if needed, but they will
|
||||||
|
* not be primary stages.
|
||||||
|
* @throws Exception if something goes wrong
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void start(Stage primaryStage) throws Exception {
|
||||||
|
this.setcModel(clientModel);
|
||||||
|
URL resource = ChatApp.class.getResource(
|
||||||
|
"LoungeSceneView.fxml");
|
||||||
|
if (resource == null) {
|
||||||
|
LOGGER.info("File wasnt found. Name: LoungeSceneView.fxml");
|
||||||
|
}
|
||||||
|
//ChatApp chatApp = new ChatApp(new ClientModel());
|
||||||
|
try {
|
||||||
|
Parent root = FXMLLoader.load(
|
||||||
|
Objects.requireNonNull(LoungeApp.class.getResource(
|
||||||
|
"LoungeSceneView.fxml")));
|
||||||
|
// TODO bin chatController.getChatPaneRoot() border to root border for rezising
|
||||||
|
// loungeSceneViewController.getChatAreaHBox().getChildren()
|
||||||
|
// .add(FXMLLoader.load(Objects.requireNonNull(ChatApp.class.getResource("ChatView.fxml"))));
|
||||||
|
Scene scene = new Scene(root);
|
||||||
|
scene.setRoot(root);
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
primaryStage.setResizable(true);
|
||||||
|
primaryStage.setTitle("Lounge");
|
||||||
|
primaryStage.show();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge;
|
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.ClientModel;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp;
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.events.ChangeNameButtonPressedEventHandler;
|
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.client.gui.events.LeaveServerButtonPressedEventHandler;
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
||||||
@ -9,6 +10,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import javafx.application.Application;
|
||||||
import javafx.beans.binding.StringBinding;
|
import javafx.beans.binding.StringBinding;
|
||||||
import javafx.beans.property.SimpleListProperty;
|
import javafx.beans.property.SimpleListProperty;
|
||||||
import javafx.beans.property.SimpleMapProperty;
|
import javafx.beans.property.SimpleMapProperty;
|
||||||
@ -57,6 +59,7 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
private ToolBar NTtBToolBar;
|
private ToolBar NTtBToolBar;
|
||||||
|
|
||||||
public static ClientModel client;
|
public static ClientModel client;
|
||||||
|
public static ChatApp chatApp;
|
||||||
|
|
||||||
private ObservableMap<String, ObservableList<String>> lobbyToMemberssMap;
|
private ObservableMap<String, ObservableList<String>> lobbyToMemberssMap;
|
||||||
private HashMap<String, String> clientToLobbyMap;
|
private HashMap<String, String> clientToLobbyMap;
|
||||||
@ -76,11 +79,13 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
ChatApp.setLoungeSceneViewController(this);
|
||||||
this.protocol = new Protocol();
|
this.protocol = new Protocol();
|
||||||
ChangeNameButton.setOnAction(event -> changeName());
|
ChangeNameButton.setOnAction(event -> changeName());
|
||||||
LeaveServerButton.setOnAction(new LeaveServerButtonPressedEventHandler());
|
LeaveServerButton.setOnAction(new LeaveServerButtonPressedEventHandler());
|
||||||
newGameButton.setOnAction(event -> newGame());
|
newGameButton.setOnAction(event -> newGame());
|
||||||
|
LobbyListView.setVisible(true);
|
||||||
|
ClientListView.setVisible(true);
|
||||||
ClientListView.setItems(client.getAllClients());
|
ClientListView.setItems(client.getAllClients());
|
||||||
LobbyListView.setPlaceholder(new Text("No open lobbies!"));
|
LobbyListView.setPlaceholder(new Text("No open lobbies!"));
|
||||||
client.getAllClients().addListener(new ListChangeListener<SimpleStringProperty>() {
|
client.getAllClients().addListener(new ListChangeListener<SimpleStringProperty>() {
|
||||||
@ -136,8 +141,9 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
HBox lobby = new HBox();
|
HBox lobby = new HBox();
|
||||||
Label idLabel = new Label();
|
Label idLabel = new Label();
|
||||||
Label adminLabel = new Label();
|
Label adminLabel = new Label();
|
||||||
idLabel.textProperty().bind(id);
|
idLabel.setText(lobbyID);
|
||||||
adminLabel.textProperty().bind(admin);
|
adminLabel.setText(adminName);
|
||||||
|
startOrJoin.setVisible(true);
|
||||||
lobby.getChildren().add(idLabel);
|
lobby.getChildren().add(idLabel);
|
||||||
lobby.getChildren().add(adminLabel);
|
lobby.getChildren().add(adminLabel);
|
||||||
lobby.getChildren().add(startOrJoin);
|
lobby.getChildren().add(startOrJoin);
|
||||||
@ -151,6 +157,7 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
}
|
}
|
||||||
lobby.setId(lobbyID);
|
lobby.setId(lobbyID);
|
||||||
lobbyToMemberssMap.put(lobbyID, members.getItems());
|
lobbyToMemberssMap.put(lobbyID, members.getItems());
|
||||||
|
lobby.setVisible(true);
|
||||||
LobbyListView.getItems().add(lobby);
|
LobbyListView.getItems().add(lobby);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,6 +171,11 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to add a new player to the list of players.
|
||||||
|
* "NPLOS" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters}
|
||||||
|
* @param s
|
||||||
|
*/
|
||||||
public void addClientToList(String s) {
|
public void addClientToList(String s) {
|
||||||
ClientListView.getItems().add(new SimpleStringProperty(s));
|
ClientListView.getItems().add(new SimpleStringProperty(s));
|
||||||
}
|
}
|
||||||
@ -174,13 +186,14 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
|
|
||||||
|
|
||||||
public void changeName() {
|
public void changeName() {
|
||||||
TextField name = new TextField("Enter new name!");
|
TextField name = new TextField();
|
||||||
|
name.setPromptText("Enter new Nickname!");
|
||||||
this.NTtBToolBar.getItems().add(name);
|
this.NTtBToolBar.getItems().add(name);
|
||||||
name.setOnAction(new EventHandler<ActionEvent>() {
|
name.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(ActionEvent event) {
|
public void handle(ActionEvent event) {
|
||||||
client.getClient().sendMsgToServer(Protocol.nameChange + "$" + name.getText());
|
client.getClient().sendMsgToServer(Protocol.nameChange + "$" + name.getText());
|
||||||
NTtBToolBar.getItems().remove(NTtBToolBar.getItems().size());
|
NTtBToolBar.getItems().remove(name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -204,4 +217,12 @@ public class LoungeSceneViewController implements Initializable {
|
|||||||
public static void setClient(ClientModel client) {
|
public static void setClient(ClientModel client) {
|
||||||
LoungeSceneViewController.client = client;
|
LoungeSceneViewController.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HBox getChatAreaHBox() {
|
||||||
|
return ChatAreaHBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChatAreaHBox(HBox chatAreaHBox) {
|
||||||
|
ChatAreaHBox = chatAreaHBox;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,8 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.helpers;
|
|||||||
public class GuiParameters {
|
public class GuiParameters {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells GUI to update the gameStateModel, in the form {@code UPDATE$name:role:kickedOff$name:role:kickedOff} ... usw.
|
* Tells GUI to update the gameStateModel, in the form {@code UPDATE$name:role:kickedOff$name:role:kickedOff}
|
||||||
|
* ... usw.
|
||||||
*/
|
*/
|
||||||
public static final String updateGameState = "UPDATE";
|
public static final String updateGameState = "UPDATE";
|
||||||
/**
|
/**
|
||||||
@ -20,8 +21,8 @@ public class GuiParameters {
|
|||||||
public static final String listOfPLayers = "PLAYERS";
|
public static final String listOfPLayers = "PLAYERS";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells Gui, that the passenger at position {@code position} has heard some noise
|
* Tells Gui, that the passenger at position {@code position} has heard some noise Form: {@code
|
||||||
* Form: {@code NOISE$position$}
|
* NOISE$position$}
|
||||||
*/
|
*/
|
||||||
public static final String noiseHeardAtPosition = "NOISE";
|
public static final String noiseHeardAtPosition = "NOISE";
|
||||||
|
|
||||||
@ -41,22 +42,29 @@ public class GuiParameters {
|
|||||||
public static final String viewChangeToGame = "VCGAME";
|
public static final String viewChangeToGame = "VCGAME";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells Gui, who the members of a specified Lobby are.
|
* Tells Gui, who the members of a specified Lobby are. Form: {@code LMEMBS$<lobbyID>:<ADMIN
|
||||||
* Form: {@code LMEMBS$<lobbyID>:<ADMIN NAME>:<member names>:<..>}
|
* NAME>:<member names>:<..>}
|
||||||
*/
|
*/
|
||||||
public static final String getMembersInLobby = "LMEMBS";
|
public static final String getMembersInLobby = "LMEMBS";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells Gui, that a new Lobby has been created.
|
* Tells Gui, that a new Lobby has been created. Form: {@code NLOBBY$<lobbyID>:<Admin Name>}
|
||||||
* Form: {@code NLOBBY$<lobbyID>:<Admin Name>}
|
|
||||||
*/
|
*/
|
||||||
public static final String newLobbyCreated = "NLOBBY";
|
public static final String newLobbyCreated = "NLOBBY";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells Gui, to add a player to a lobby.
|
* Tells Gui, to add a player to a lobby. Form: {@code NMEMB$<LobbyIS>:<PlayerNamse>}
|
||||||
* Form: {@code NMEMB$<LobbyIS>:<PlayerNamse>}
|
|
||||||
*/
|
*/
|
||||||
public static final String addNewMemberToLobby = "NMEMB";
|
public static final String addNewMemberToLobby = "NMEMB";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates a player changed their username. Form: {@code NCHANG$<oldName>:<newName>}
|
||||||
|
*/
|
||||||
|
public static final String nameChanged = "NCHANG";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates a player has joined the server. Form: {@code NPLOS$<playerName>}
|
||||||
|
*/
|
||||||
|
public static final String newPlayerOnServer = "NPLOS";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import ch.unibas.dmi.dbis.cs108.gamelogic.Game;
|
|||||||
import ch.unibas.dmi.dbis.cs108.gamelogic.TrainOverflow;
|
import ch.unibas.dmi.dbis.cs108.gamelogic.TrainOverflow;
|
||||||
import ch.unibas.dmi.dbis.cs108.gamelogic.VoteHandler;
|
import ch.unibas.dmi.dbis.cs108.gamelogic.VoteHandler;
|
||||||
import ch.unibas.dmi.dbis.cs108.highscore.OgGhostHighScore;
|
import ch.unibas.dmi.dbis.cs108.highscore.OgGhostHighScore;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters;
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ServerPinger;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ServerPinger;
|
||||||
|
|
||||||
@ -126,8 +127,12 @@ public class ClientHandler implements Runnable {
|
|||||||
*/
|
*/
|
||||||
public void changeUsername(String newName) {
|
public void changeUsername(String newName) {
|
||||||
String helper = this.getClientUserName();
|
String helper = this.getClientUserName();
|
||||||
|
String oldName = getClientUserName();
|
||||||
this.clientUserName = nameDuplicateChecker.checkName(newName);
|
this.clientUserName = nameDuplicateChecker.checkName(newName);
|
||||||
|
guiUpdateAll(Protocol.printToGUI + "$" + GuiParameters.nameChanged + "$" + oldName + ":"
|
||||||
|
+ getClientUserName());
|
||||||
sendMsgToClient(Protocol.changedUserName + "$" + newName);
|
sendMsgToClient(Protocol.changedUserName + "$" + newName);
|
||||||
|
|
||||||
broadcastAnnouncementToAll(helper + " has changed their nickname to " + clientUserName);
|
broadcastAnnouncementToAll(helper + " has changed their nickname to " + clientUserName);
|
||||||
try {
|
try {
|
||||||
getLobby().getGame().getGameState().changeUsername(helper, newName);
|
getLobby().getGame().getGameState().changeUsername(helper, newName);
|
||||||
@ -245,6 +250,13 @@ public class ClientHandler implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void guiUpdateAll(String msg) {
|
||||||
|
System.out.println(msg);
|
||||||
|
for (ClientHandler client : connectedClients) {
|
||||||
|
client.sendMsgToClient(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Broadcasts a non-chat Message to all clients in the same lobby. This can be used for server
|
* Broadcasts a non-chat Message to all clients in the same lobby. This can be used for server
|
||||||
* messages / announcements rather than chat messages. The message will be printed to the user
|
* messages / announcements rather than chat messages. The message will be printed to the user
|
||||||
@ -306,7 +318,8 @@ public class ClientHandler implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a given message to all connected client. The message has to already be protocol-formatted.
|
* Sends a given message to all connected client. The message has to already be
|
||||||
|
* protocol-formatted.
|
||||||
*
|
*
|
||||||
* @param msg the given message. Should already be protocol-formatted.
|
* @param msg the given message. Should already be protocol-formatted.
|
||||||
*/
|
*/
|
||||||
@ -317,7 +330,9 @@ public class ClientHandler implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a Message to all clients in the same lobby. The message has to already be protocol-formatted.
|
* Sends a Message to all clients in the same lobby. The message has to already be
|
||||||
|
* protocol-formatted.
|
||||||
|
*
|
||||||
* @param msg the given message. Should already be protocol-formatted.
|
* @param msg the given message. Should already be protocol-formatted.
|
||||||
*/
|
*/
|
||||||
public void sendMsgToClientsInLobby(String msg) {
|
public void sendMsgToClientsInLobby(String msg) {
|
||||||
@ -456,6 +471,8 @@ public class ClientHandler implements Runnable {
|
|||||||
public void createNewLobby() {
|
public void createNewLobby() {
|
||||||
if (Lobby.clientIsInLobby(this) == -1) {
|
if (Lobby.clientIsInLobby(this) == -1) {
|
||||||
Lobby newGame = new Lobby(this);
|
Lobby newGame = new Lobby(this);
|
||||||
|
guiUpdateAll(Protocol.printToGUI + "$" + GuiParameters.newLobbyCreated + "$" + getLobby()
|
||||||
|
.getLobbyID() + ":" + getClientUserName());
|
||||||
} else {
|
} else {
|
||||||
sendAnnouncementToClient("You are already in lobby nr. " + Lobby.clientIsInLobby(this));
|
sendAnnouncementToClient("You are already in lobby nr. " + Lobby.clientIsInLobby(this));
|
||||||
}
|
}
|
||||||
@ -472,6 +489,8 @@ public class ClientHandler implements Runnable {
|
|||||||
if (l != null) {
|
if (l != null) {
|
||||||
if (l.getLobbyIsOpen()) {
|
if (l.getLobbyIsOpen()) {
|
||||||
l.addPlayer(this);
|
l.addPlayer(this);
|
||||||
|
guiUpdateAll(Protocol.printToGUI + "$" + GuiParameters.addNewMemberToLobby + "$" + i + ":"
|
||||||
|
+ getClientUserName());
|
||||||
} else {
|
} else {
|
||||||
sendAnnouncementToClient("The game in Lobby " + l.getLobbyID()
|
sendAnnouncementToClient("The game in Lobby " + l.getLobbyID()
|
||||||
+ " has already started, or the lobby is already full.");
|
+ " has already started, or the lobby is already full.");
|
||||||
|
|||||||
@ -82,7 +82,6 @@ public class JServerProtocolParser {
|
|||||||
try {
|
try {
|
||||||
int i = Integer.parseInt(msg.substring(6, 7));
|
int i = Integer.parseInt(msg.substring(6, 7));
|
||||||
h.joinLobby(i);
|
h.joinLobby(i);
|
||||||
h.sendMsgToClient(Protocol.printToGUI + "$" + GuiParameters.viewChangeToLobby + "$");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
h.sendMsgToClient(Protocol.printToClientConsole
|
h.sendMsgToClient(Protocol.printToClientConsole
|
||||||
+ "$Invalid input. Please use JOINL$1 to join Lobby 1, for example.");
|
+ "$Invalid input. Please use JOINL$1 to join Lobby 1, for example.");
|
||||||
@ -90,7 +89,12 @@ public class JServerProtocolParser {
|
|||||||
break;
|
break;
|
||||||
case Protocol.createNewLobby:
|
case Protocol.createNewLobby:
|
||||||
h.createNewLobby();
|
h.createNewLobby();
|
||||||
h.sendMsgToClient(Protocol.printToGUI + "$" + GuiParameters.viewChangeToLobby+ "$");
|
h.sendMsgToClient(
|
||||||
|
Protocol.printToGUI + "$" + GuiParameters.newLobbyCreated + "$" + h.getLobby()
|
||||||
|
.getLobbyID() + ":" + h.getClientUserName());
|
||||||
|
h.guiUpdateAll(Protocol.printToGUI + "$" + GuiParameters.newLobbyCreated + "$" + h.getLobby()
|
||||||
|
.getLobbyID() + ":" + h.getClientUserName());
|
||||||
|
LOGGER.info("Here");
|
||||||
break;
|
break;
|
||||||
case Protocol.listLobbies:
|
case Protocol.listLobbies:
|
||||||
h.listLobbies();
|
h.listLobbies();
|
||||||
|
|||||||
@ -3,12 +3,10 @@
|
|||||||
<?import javafx.scene.control.Button?>
|
<?import javafx.scene.control.Button?>
|
||||||
<?import javafx.scene.control.ListView?>
|
<?import javafx.scene.control.ListView?>
|
||||||
<?import javafx.scene.control.ToolBar?>
|
<?import javafx.scene.control.ToolBar?>
|
||||||
<?import javafx.scene.control.TreeView?>
|
|
||||||
<?import javafx.scene.layout.AnchorPane?>
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
<?import javafx.scene.layout.BorderPane?>
|
<?import javafx.scene.layout.BorderPane?>
|
||||||
<?import javafx.scene.layout.HBox?>
|
<?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" fx:controller="ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeSceneViewController">
|
<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>
|
<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">
|
<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">
|
||||||
@ -23,7 +21,7 @@
|
|||||||
<center>
|
<center>
|
||||||
<AnchorPane prefHeight="661.0" prefWidth="600.0" BorderPane.alignment="CENTER">
|
<AnchorPane prefHeight="661.0" prefWidth="600.0" BorderPane.alignment="CENTER">
|
||||||
<children>
|
<children>
|
||||||
<Button fx:id="newGameButton" mnemonicParsing="false" text="New Game" />
|
<Button fx:id="newGameButton" layoutX="272.0" layoutY="103.0" mnemonicParsing="false" text="New Game" />
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
</center>
|
</center>
|
||||||
|
|||||||
Reference in New Issue
Block a user