Implemented highScore functionality into Gui
This commit is contained in:
parent
d6f28a63e8
commit
c9f0654eef
@ -1,6 +1,7 @@
|
||||
package ch.unibas.dmi.dbis.cs108.highscore;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
@ -83,8 +84,8 @@ public class OgGhostHighScore {
|
||||
hm.remove(firstplace);
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -402,6 +402,10 @@ public class Client {
|
||||
break;
|
||||
case GuiParameters.newPlayerOnServer:
|
||||
addNewPlayerToGui(data);
|
||||
break;
|
||||
case GuiParameters.updateHighScore:
|
||||
chatApp.getLoungeSceneViewController().addHighScore(data);
|
||||
break;
|
||||
default:
|
||||
notificationTextDisplay(data);
|
||||
//TODO(Sebi,Seraina): should the gameController be in the Application just like the ChatController?
|
||||
|
||||
@ -29,7 +29,6 @@ public class JClientProtocolParser {
|
||||
header = msg.substring(0, 5);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
System.out.println("Received unknown command");
|
||||
e.printStackTrace();
|
||||
}
|
||||
switch (header) {
|
||||
case Protocol.pingFromServer:
|
||||
|
||||
@ -199,7 +199,7 @@ public class GameController implements Initializable {
|
||||
*/
|
||||
public void addMessageToNotificationText(String msg) {
|
||||
LOGGER.trace("addMessage " + msg);
|
||||
Text notification = new Text(msg);
|
||||
Text notification = new Text("\\R" + msg);
|
||||
notification.setFill(Color.BLACK);
|
||||
notification.setStyle("-fx-font: 50 arial;");
|
||||
Platform.runLater(new Runnable() {
|
||||
|
||||
@ -40,6 +40,7 @@ import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.scene.text.TextFlow;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -48,13 +49,16 @@ public class LoungeSceneViewController implements Initializable {
|
||||
public static final Logger LOGGER = LogManager.getLogger(LoungeSceneViewController.class);
|
||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||
|
||||
@FXML
|
||||
private TextFlow highScore;
|
||||
@FXML
|
||||
private SplitPane chatSplitPane;
|
||||
@FXML
|
||||
private AnchorPane chatAnchorPane;
|
||||
@FXML
|
||||
private AnchorPane otherNotificationAnchorPane;
|
||||
|
||||
@FXML
|
||||
public Button highScoreButton;
|
||||
@FXML
|
||||
private Button leaveLobbyButton;
|
||||
@FXML
|
||||
@ -486,5 +490,26 @@ public class LoungeSceneViewController implements Initializable {
|
||||
public static void setClient(ClientModel client) {
|
||||
LoungeSceneViewController.client = client;
|
||||
}
|
||||
|
||||
public void sendHIghScore() {
|
||||
client.getClient().sendMsgToServer(Protocol.highScoreList);
|
||||
}
|
||||
|
||||
public void addHighScore(String data) {
|
||||
String[] arguments = data.split("/n");
|
||||
LOGGER.debug(arguments.length);
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
highScore.getChildren().clear();
|
||||
for(String argument : arguments) {
|
||||
LOGGER.debug("HighScore " + argument);
|
||||
Text text = new Text(argument + System.lineSeparator());
|
||||
text.setFill(Color.BLACK);
|
||||
highScore.getChildren().add(text);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -85,4 +85,6 @@ public class GuiParameters {
|
||||
* RMVLST$<playerName>}
|
||||
*/
|
||||
public static final String removePlayerFromList = "RMVLST";
|
||||
|
||||
public static final String updateHighScore = "HISCR";
|
||||
}
|
||||
|
||||
@ -652,8 +652,15 @@ public class ClientHandler implements Runnable {
|
||||
public void sendHighScoreList() {
|
||||
String list = OgGhostHighScore.formatGhostHighscoreList();
|
||||
String[] listarray = list.split("\\R");
|
||||
StringBuilder forGui = new StringBuilder();
|
||||
for (String s : listarray) {
|
||||
sendAnnouncementToClient(s);
|
||||
forGui.append(s).append("/n");
|
||||
}
|
||||
sendMsgToClient(Protocol.printToGUI + "$" + GuiParameters.updateHighScore + "$" + forGui.toString());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.text.TextFlow?>
|
||||
|
||||
<AnchorPane id="BG" fx:id="gameBG" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1200.0" styleClass="theme" stylesheets="@GameDay.css" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController">
|
||||
<AnchorPane id="BG" fx:id="gameBG" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" styleClass="theme" stylesheets="@GameDay.css" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController">
|
||||
<children>
|
||||
<Group fx:id="roomButtonGroupDay" layoutX="230.5" layoutY="220.0">
|
||||
<children>
|
||||
@ -107,11 +107,11 @@
|
||||
</HBox>
|
||||
</children>
|
||||
</Group>
|
||||
<Button fx:id="noiseButton" alignment="CENTER" layoutX="267.0" layoutY="610.0" mnemonicParsing="false" onAction="#noise" prefHeight="114.0" prefWidth="217.0" text="I heard some noise">
|
||||
<Button fx:id="noiseButton" alignment="CENTER" layoutX="267.0" layoutY="482.0" mnemonicParsing="false" onAction="#noise" prefHeight="114.0" prefWidth="217.0" text="I heard some noise">
|
||||
<font>
|
||||
<Font name="System Bold" size="21.0" />
|
||||
</font></Button>
|
||||
<TextFlow fx:id="notificationText" accessibleRole="PARENT" layoutX="210.0" layoutY="20.0" prefHeight="200.0" prefWidth="800.0" textAlignment="CENTER" />
|
||||
<AnchorPane fx:id="chatAreaGame" layoutY="738.0" prefHeight="342.0" prefWidth="1920.0" />
|
||||
<AnchorPane fx:id="chatAreaGame" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<?import javafx.scene.control.SplitPane?>
|
||||
<?import javafx.scene.control.ToolBar?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?import javafx.scene.text.TextFlow?>
|
||||
|
||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" 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>
|
||||
@ -13,6 +15,7 @@
|
||||
<top>
|
||||
<ToolBar fx:id="NTtBToolBar" prefHeight="77.0" BorderPane.alignment="CENTER">
|
||||
<items>
|
||||
<Button fx:id="highScoreButton" mnemonicParsing="false" onAction="#sendHIghScore" text="High Score" />
|
||||
<Button fx:id="ChangeNameButton" mnemonicParsing="false" text="Change Name" />
|
||||
<Button fx:id="LeaveServerButton" mnemonicParsing="false" text="Leave server" />
|
||||
<Button fx:id="leaveLobbyButton" mnemonicParsing="false" onAction="#leaveLobby" text="Leave Lobby" />
|
||||
@ -24,17 +27,22 @@
|
||||
<children>
|
||||
<Button fx:id="newGameButton" layoutX="68.0" layoutY="101.0" mnemonicParsing="false" text="New Lobby" />
|
||||
<AnchorPane fx:id="gameAnchorPane" />
|
||||
<Button fx:id="startGame" layoutX="68.0" layoutY="156.0" mnemonicParsing="false" onAction="#startGame" text="Start Game" />
|
||||
<Button fx:id="startGame" layoutX="68.0" layoutY="156.0" mnemonicParsing="false" onAction="#startGame" opacity="0.0" text="Start Game" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</center>
|
||||
<bottom>
|
||||
<AnchorPane fx:id="ChatArea" minHeight="100.0" BorderPane.alignment="CENTER">
|
||||
<AnchorPane fx:id="ChatArea" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<SplitPane fx:id="chatSplitPane" dividerPositions="0.5" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<SplitPane fx:id="chatSplitPane" dividerPositions="0.5" minHeight="50.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<items>
|
||||
<AnchorPane fx:id="chatAnchorPane" minHeight="0.0" minWidth="0.0" />
|
||||
<AnchorPane fx:id="otherNotificationAnchorPane" minHeight="0.0" minWidth="0.0" />
|
||||
<AnchorPane fx:id="otherNotificationAnchorPane" minHeight="0.0" minWidth="0.0">
|
||||
<children>
|
||||
<Label text="High Score:" />
|
||||
<TextFlow fx:id="highScore" layoutY="18.0" prefHeight="30.0" prefWidth="315.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="18.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</items>
|
||||
</SplitPane>
|
||||
</children>
|
||||
|
||||
Reference in New Issue
Block a user