mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Added 3D element to lobby screen to show the player their boat before the race.
tags: #story[1245]
This commit is contained in:
@@ -1,5 +1,15 @@
|
||||
package seng302.visualiser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
@@ -32,13 +42,11 @@ import seng302.utilities.Sounds;
|
||||
import seng302.utilities.StreamParser;
|
||||
import seng302.utilities.XMLGenerator;
|
||||
import seng302.utilities.XMLParser;
|
||||
import seng302.visualiser.controllers.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.*;
|
||||
import seng302.visualiser.controllers.FinishScreenViewController;
|
||||
import seng302.visualiser.controllers.LobbyController;
|
||||
import seng302.visualiser.controllers.LobbyController_old;
|
||||
import seng302.visualiser.controllers.RaceViewController;
|
||||
import seng302.visualiser.controllers.ViewManager;
|
||||
|
||||
/**
|
||||
* This class is a client side instance of a yacht racing game in JavaFX. The game is instantiated
|
||||
@@ -293,6 +301,9 @@ public class GameClient {
|
||||
clientLobbyList.add(boat.getBoatName())
|
||||
);
|
||||
raceState.setBoats(allBoatsMap.values());
|
||||
if (lobbyController != null) {
|
||||
lobbyController.setBoats(allBoatsMap);
|
||||
}
|
||||
break;
|
||||
|
||||
case RACE_START_STATUS:
|
||||
@@ -512,4 +523,8 @@ public class GameClient {
|
||||
if (server != null) server.terminate();
|
||||
if (socketThread != null) socketThread.setSocketToClose();
|
||||
}
|
||||
|
||||
public Map<Integer, ClientYacht> getAllBoatsMap() {
|
||||
return allBoatsMap;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,12 @@ package seng302.visualiser.controllers;
|
||||
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXDialog;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.fxml.FXML;
|
||||
@@ -23,6 +21,7 @@ import javafx.scene.layout.VBox;
|
||||
import javafx.scene.paint.Color;
|
||||
import seng302.gameServer.GameStages;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.model.ClientYacht;
|
||||
import seng302.model.Colors;
|
||||
import seng302.model.Limit;
|
||||
import seng302.model.RaceState;
|
||||
@@ -30,7 +29,6 @@ import seng302.model.mark.CompoundMark;
|
||||
import seng302.model.mark.Corner;
|
||||
import seng302.model.stream.xml.parser.RaceXMLData;
|
||||
import seng302.utilities.Sounds;
|
||||
import seng302.utilities.XMLGenerator;
|
||||
import seng302.visualiser.GameView;
|
||||
import seng302.visualiser.controllers.cells.PlayerCell;
|
||||
|
||||
@@ -57,12 +55,15 @@ public class LobbyController implements Initializable {
|
||||
private RaceState raceState;
|
||||
private JFXDialog customizationDialog;
|
||||
public Color playersColor;
|
||||
private Map<Integer, ClientYacht> playerBoats;
|
||||
private Double mapWidth, mapHeight;
|
||||
private GameView gameView;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
||||
this.playerBoats = ViewManager.getInstance().getGameClient().getAllBoatsMap();
|
||||
|
||||
if (this.playersColor == null) {
|
||||
this.playersColor = Colors.getColor(ViewManager.getInstance().getGameClient().getServerThread().getClientId() - 1);
|
||||
}
|
||||
@@ -121,6 +122,10 @@ public class LobbyController implements Initializable {
|
||||
gameView.updateCourse(marks, corners);
|
||||
}
|
||||
|
||||
private void getPlayerColors() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -162,23 +167,28 @@ public class LobbyController implements Initializable {
|
||||
*/
|
||||
private void refreshPlayerList() {
|
||||
playerListVBox.getChildren().clear();
|
||||
|
||||
for (String player : ViewManager.getInstance().getPlayerList()) {
|
||||
if (this.playerBoats == null || this.playerBoats.size() == 0) {
|
||||
this.playerBoats = ViewManager.getInstance().getGameClient().getAllBoatsMap();
|
||||
}
|
||||
// TODO: 12/09/2017 ajm412: Make it so that it only removes players who's details have changed.
|
||||
for (Integer playerId : playerBoats.keySet()) {
|
||||
VBox pane = null;
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(
|
||||
getClass().getResource("/views/cells/PlayerCell.fxml"));
|
||||
ClientYacht yacht = playerBoats.get(playerId);
|
||||
|
||||
loader.setController(new PlayerCell(player));
|
||||
FXMLLoader loader = new FXMLLoader(
|
||||
getClass().getResource("/views/cells/PlayerCell.fxml"));
|
||||
|
||||
loader.setController(new PlayerCell(playerId, yacht.getBoatName(), yacht.getColour()));
|
||||
|
||||
try {
|
||||
pane = loader.load();
|
||||
} catch (IOException e) {
|
||||
// TODO replace with logger
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
playerListVBox.getChildren().add(pane);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,6 +217,10 @@ public class LobbyController implements Initializable {
|
||||
this.beginRaceButton.setText("Starting in: " + raceState.getRaceTimeStr());
|
||||
}
|
||||
|
||||
public void setBoats(Map<Integer, ClientYacht> boats) {
|
||||
this.playerBoats = boats;
|
||||
}
|
||||
|
||||
public void closeCustomizationDialog() {
|
||||
customizationDialog.close();
|
||||
}
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
package seng302.visualiser.controllers.cells;
|
||||
|
||||
import javafx.animation.AnimationTimer;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.geometry.Point3D;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.effect.DropShadow;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import javafx.scene.transform.Scale;
|
||||
import javafx.scene.transform.Translate;
|
||||
import seng302.utilities.Sounds;
|
||||
import seng302.visualiser.fxObjects.assets_3D.BoatMeshType;
|
||||
import seng302.visualiser.fxObjects.assets_3D.BoatModel;
|
||||
import seng302.visualiser.fxObjects.assets_3D.ModelFactory;
|
||||
|
||||
public class PlayerCell {
|
||||
|
||||
@@ -15,16 +24,61 @@ public class PlayerCell {
|
||||
private Label playerName;
|
||||
@FXML
|
||||
private GridPane playerListCell;
|
||||
@FXML
|
||||
private Pane boatPane;
|
||||
//---------FXML END---------//
|
||||
|
||||
private String name;
|
||||
private Integer boatAngle;
|
||||
private Color boatColor;
|
||||
private Integer playerId;
|
||||
|
||||
public PlayerCell(String playerName) {
|
||||
public PlayerCell(Integer playerId, String playerName, Color color) {
|
||||
this.playerId = playerId;
|
||||
this.name = playerName;
|
||||
this.boatColor = color;
|
||||
this.boatAngle = -45;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
playerName.setText(name);
|
||||
|
||||
Group group = new Group();
|
||||
boatPane.getChildren().add(group);
|
||||
|
||||
BoatModel bo = ModelFactory.boatIconView(BoatMeshType.DINGHY, this.boatColor);
|
||||
bo.showSail();
|
||||
bo.rotateSail(45);
|
||||
bo.getAssets().getTransforms().setAll(
|
||||
new Scale(4, 4, 4),
|
||||
new Translate(12, 14, 0),
|
||||
new Rotate(270, new Point3D(1, 0, 0)),
|
||||
new Rotate(-45, new Point3D(0, 0, 1))
|
||||
);
|
||||
|
||||
bo.setAnimation(new AnimationTimer() {
|
||||
Group group = bo.getAssets();
|
||||
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
((Rotate) group.getTransforms().get(3)).setAngle(boatAngle++);
|
||||
}
|
||||
});
|
||||
|
||||
group.getChildren().add(bo.getAssets());
|
||||
|
||||
}
|
||||
|
||||
public Integer getPlayerId() {
|
||||
return playerId;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Color getBoatColor() {
|
||||
return boatColor;
|
||||
}
|
||||
|
||||
public void playButtonHoverSound(MouseEvent mouseEvent) {
|
||||
|
||||
@@ -19,7 +19,7 @@ public class Model {
|
||||
}
|
||||
}
|
||||
|
||||
void setAnimation(AnimationTimer animation) {
|
||||
public void setAnimation(AnimationTimer animation) {
|
||||
animationTimer = animation;
|
||||
if (animation != null) {
|
||||
animation.start();
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#playerName {
|
||||
-fx-text-fill: -fx-pp-dark-text-color;
|
||||
-fx-text-fill: -fx-pp-light-text-color;
|
||||
-fx-font-size: 18px;
|
||||
}
|
||||
|
||||
#playerListCell {
|
||||
-fx-background-color: -fx-pp-front-color;
|
||||
-fx-background-color: skyblue;
|
||||
-fx-effect: -fx-pp-dropshadow-light;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import com.jfoenix.controls.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
|
||||
<?import java.lang.String?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.ColumnConstraints?>
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.layout.Pane?>
|
||||
<?import javafx.scene.layout.RowConstraints?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<VBox fx:id="playerCellVBox" maxHeight="-Infinity" maxWidth="1.7976931348623157E308"
|
||||
minHeight="-Infinity" minWidth="-Infinity" prefHeight="80.0" xmlns="http://javafx.com/javafx/8"
|
||||
xmlns:fx="http://javafx.com/fxml/1">
|
||||
minHeight="-Infinity" minWidth="-Infinity" prefHeight="80.0"
|
||||
xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<stylesheets>
|
||||
<String fx:value="/css/master.css" />
|
||||
<String fx:value="/css/cells/PlayerCell.css"/>
|
||||
@@ -18,17 +19,19 @@
|
||||
<GridPane fx:id="playerListCell" maxHeight="-Infinity" maxWidth="1.7976931348623157E308"
|
||||
minHeight="-Infinity" prefHeight="70.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="355.0" minWidth="355.0"
|
||||
prefWidth="355.0"/>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="80.0" minWidth="80.0" prefWidth="80.0"/>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="290.0" minWidth="290.0"
|
||||
prefWidth="290.0"/>
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="80.0" minHeight="80.0" prefHeight="80.0" vgrow="SOMETIMES"/>
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label fx:id="playerName" text="Party parrots in space">
|
||||
<Label fx:id="playerName" text="Party parrots in space" GridPane.columnIndex="1">
|
||||
<padding>
|
||||
<Insets left="20.0" />
|
||||
</padding></Label>
|
||||
<Pane fx:id="boatPane" prefHeight="200.0" prefWidth="200.0"/>
|
||||
</children>
|
||||
<VBox.margin>
|
||||
<Insets right="40.0"/>
|
||||
|
||||
Reference in New Issue
Block a user