Merge remote-tracking branch 'origin/master'

This commit is contained in:
Sebastian Lenzlinger 2022-05-13 12:47:21 +02:00
commit 7ecb910c83
7 changed files with 218 additions and 10 deletions

View File

@ -140,6 +140,7 @@ public class Client {
String pos = msg.substring(0, msgIndex);
try {
position = Integer.parseInt(pos);
gameStateModel.setRoleFromPosition(position);
} catch (NumberFormatException e) {
LOGGER.warn("Position got scrabbled on the way here");
}
@ -155,6 +156,7 @@ public class Client {
public void setPosition(int position) {
this.position = position;
gameStateModel.setRoleFromPosition(position);
}
/**
@ -343,11 +345,15 @@ public class Client {
switch (parameter) {
case GuiParameters.night: //ClientGameInfoHandler;
gameStateModel.setDayClone(false);
LOGGER.debug("----------------Night, Your role is:" + gameStateModel.getYourRole() + gameStateModel);
chatApp.getGameController().setNoiseButtonInvisible();
chatApp.getGameController().setVoteButtonVisibilityNight();
break;
case GuiParameters.day: //ClientGameInfoHandler
gameStateModel.setDayClone(true);
LOGGER.debug("----------------Day, Your role is:" + gameStateModel.getYourRole()+ gameStateModel);
chatApp.getGameController().setNoiseButtonVisible();
chatApp.getGameController().setVoteButtonVisibilityDay();
break;
case GuiParameters.updateGameState:
gameStateModel.setGSFromString(data);

View File

@ -10,9 +10,16 @@ import javafx.util.Duration;
public class BGAnimation extends Transition {
ImageView imageView;
private static final Image bgFull = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/Day/BG_small.jpg");
int index;
int lastIndex;
BGAnimation(Duration duration, ImageView imageView) {
public BGAnimation(Duration duration, ImageView imageView) {
index = 0;
lastIndex = 1034;
this.imageView = imageView;
imageView.setFitHeight(1950);
imageView.setFitWidth(6667.968);
imageView.setImage(bgFull);
setCycleDuration(duration);
setInterpolator(Interpolator.DISCRETE);
@ -20,6 +27,14 @@ public class BGAnimation extends Transition {
@Override
protected void interpolate(double frac) {
if(index == lastIndex) {
index = 0;
imageView.setX(0);
imageView.setY(0);
}
imageView.setX(index * -5);
imageView.setY(index * -1.07);
index++;
}
}

View File

@ -74,6 +74,10 @@ public class ClientModel {
}
public int getClientPosition() {
return client.getPosition();
}
public void removeClientFromList(String id){
Iterator<SimpleStringProperty> it = allClients.iterator();
while(it.hasNext()){

View File

@ -28,7 +28,7 @@ public class GameStateModel {
/**
* A primitive clone of the passengerTrain in the GameState of the server.
* in passengerTrainClone[0] the names of the passengers are stored, in passengerTrainClone[1] the roles
* (human/ghost/spectator). The indices of the array correspond with the positions
* (h/g/s). The indices of the array correspond with the positions
*/
private String[][] passengerTrainClone;
@ -41,8 +41,9 @@ public class GameStateModel {
this.nrOfPlayers = 6;
passengerTrainClone = new String[2][nrOfPlayers];
for(String role : passengerTrainClone[1]) {
role = "";
role = "h";
}
yourRole = "h";
kickedOff = new boolean[nrOfPlayers];
isDayClone = false;
}
@ -69,9 +70,12 @@ public class GameStateModel {
public void setYourRole(String yourRole) {
if(yourRole.equals("h") || yourRole.equals("g") || yourRole.equals("s")) {
this.yourRole = yourRole;
} else {
this.yourRole = "h";
}
}
public String getYourRole() {
return yourRole;
}
@ -125,4 +129,18 @@ public class GameStateModel {
LOGGER.warn("data has wrong format");
}
}
/**
* Gets an integer and extracts the string from the passengerTrain[1] string at the index of the integer
* @param position the index of the array
*/
public void setRoleFromPosition(int position) {
String role = "h";
try {
role = passengerTrainClone[1][position];
} catch (Exception e) {
LOGGER.warn("Not an integer between 0-5");
}
setYourRole(role);
}
}

View File

@ -131,6 +131,73 @@ public class GameController implements Initializable {
return chatAreaGame;
}
public void setVoteButtonVisibilityDay(){
Platform.runLater(new Runnable() {
@Override
public void run() {
LOGGER.debug(buttonRoom0);
if (gameStateModel.getYourRole().equals("h")) {
try {
buttonRoom0.setVisible(true);
buttonRoom1.setVisible(true);
buttonRoom2.setVisible(true);
buttonRoom3.setVisible(true);
buttonRoom4.setVisible(true);
buttonRoom5.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
} else {
try {
buttonRoom0.setVisible(false);
buttonRoom1.setVisible(false);
buttonRoom2.setVisible(false);
buttonRoom3.setVisible(false);
buttonRoom4.setVisible(false);
buttonRoom5.setVisible(false);
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
public void setVoteButtonVisibilityNight(){
Platform.runLater(new Runnable() {
@Override
public void run() {
LOGGER.debug(buttonRoom0);
if (gameStateModel.getYourRole().equals("g")) {
try {
buttonRoom0.setVisible(true);
buttonRoom1.setVisible(true);
buttonRoom2.setVisible(true);
buttonRoom3.setVisible(true);
buttonRoom4.setVisible(true);
buttonRoom5.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
} else {
try {
buttonRoom0.setVisible(false);
buttonRoom1.setVisible(false);
buttonRoom2.setVisible(false);
buttonRoom3.setVisible(false);
buttonRoom4.setVisible(false);
buttonRoom5.setVisible(false);
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
/**
* If button 0 is clicked, send the vote message 0 to the server
*/

View File

@ -1,16 +1,19 @@
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.BGAnimation;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ChatApp;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.LobbyListView;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.TrainAnimationDayController;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.WheelsAnimation;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
import ch.unibas.dmi.dbis.cs108.multiplayer.server.JServerProtocolParser;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.ResourceBundle;
import javafx.animation.Animation;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.property.SimpleBooleanProperty;
@ -35,6 +38,7 @@ import javafx.scene.control.SplitPane;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.control.ToolBar;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
@ -42,6 +46,7 @@ import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import javafx.util.Duration;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -50,6 +55,9 @@ public class LoungeSceneViewController implements Initializable {
public static final Logger LOGGER = LogManager.getLogger(LoungeSceneViewController.class);
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
@FXML
private AnchorPane backGroundAnimationPane;
@FXML
private AnchorPane backGroundAnchorPane;
@FXML
@ -144,6 +152,86 @@ public class LoungeSceneViewController implements Initializable {
LOGGER.debug("cApp = " + cApp);
LOGGER.debug("chatApp = " + chatApp);
TrainAnimationDayController.setcApp(cApp);
ImageView bgAnimationView = new ImageView();
bgAnimationView.setFitHeight(1950);
bgAnimationView.setFitWidth(6667.968);
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);
LOGGER.debug("In Initialize 2 LobbyListView" + LobbyListView);
LobbyListView.setCellFactory(param -> {
@ -237,6 +325,15 @@ public class LoungeSceneViewController implements Initializable {
};
return cell;
});
Platform.runLater(new Runnable() {
@Override
public void run() {
backGroundAnimationPane.getChildren().add(bgAnimationView);
Animation backGround = new BGAnimation(Duration.millis(17), bgAnimationView);
backGround.setCycleCount(Animation.INDEFINITE);
backGround.play();
}
});
LOGGER.debug("In Initialize 3 LobbyListView" + LobbyListView);
LobbyListView.setPlaceholder(new Text("No open lobbies!"));
LobbyListView.setVisible(true);

View File

@ -12,15 +12,16 @@
<AnchorPane fx:id="backGroundAnchorPane" pickOnBounds="false" stylesheets="@loungStyle.css" 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>
<AnchorPane fx:id="backGroundAnimationPane" maxHeight="843.75" maxWidth="1500.0" />
<BorderPane fx:id="LoungeSceneBorderPane" layoutX="860.0" layoutY="440.0" pickOnBounds="false" stylesheets="@boarderPane.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<top>
<ToolBar fx:id="NTtBToolBar" pickOnBounds="false" prefHeight="77.0" BorderPane.alignment="CENTER">
<ToolBar fx:id="NTtBToolBar" pickOnBounds="false" prefHeight="30.0" BorderPane.alignment="CENTER">
<items>
<Button fx:id="highScoreButton" mnemonicParsing="false" onAction="#sendHIghScore" text="High Score" />
<Button fx:id="lobbyPrintButton" mnemonicParsing="false" onAction="#sendLilstle" text="Lobby List" />
<Button fx:id="LeaveServerButton" mnemonicParsing="false" text="Leave server" />
<Button fx:id="leaveLobbyButton" mnemonicParsing="false" onAction="#leaveLobby" text="Leave Lobby" />
<Button fx:id="ChangeNameButton" mnemonicParsing="false" text="Change Name" />
<Button fx:id="highScoreButton" mnemonicParsing="false" onAction="#sendHIghScore" pickOnBounds="false" text="High Score" />
<Button fx:id="lobbyPrintButton" mnemonicParsing="false" onAction="#sendLilstle" pickOnBounds="false" text="Lobby List" />
<Button fx:id="LeaveServerButton" mnemonicParsing="false" pickOnBounds="false" text="Leave server" />
<Button fx:id="leaveLobbyButton" mnemonicParsing="false" onAction="#leaveLobby" pickOnBounds="false" text="Leave Lobby" />
<Button fx:id="ChangeNameButton" mnemonicParsing="false" pickOnBounds="false" text="Change Name" />
</items>
</ToolBar>
</top>
@ -59,6 +60,6 @@
</AnchorPane>
</left>
</BorderPane>
<AnchorPane fx:id="gameDisplayAnchorPane" pickOnBounds="false" />
<AnchorPane fx:id="gameDisplayAnchorPane" maxHeight="843.75" maxWidth="1500.0" pickOnBounds="false" />
</children>
</AnchorPane>