mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Boats now move on screen as intended.
TODO - Make the client connect to the server.
This commit is contained in:
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import seng302.model.Player;
|
||||
@@ -77,7 +78,7 @@ public class GameState implements Runnable {
|
||||
public static void addPlayer(Player player) {
|
||||
players.add(player);
|
||||
String playerText = player.getYacht().getSourceId() + " " + player.getYacht().getBoatName() + " " + player.getYacht().getCountry();
|
||||
observablePlayers.add(playerText);
|
||||
Platform.runLater(() -> observablePlayers.add(playerText)); //Had to add this to handle javaFX window using array
|
||||
playerStringMap.put(player, playerText);
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ public class ClientToServerThread implements Runnable {
|
||||
} else {
|
||||
streamPackets.add(new StreamPacket(type, payloadLength, timeStamp, payload));
|
||||
for (ClientSocketListener csl : listeners)
|
||||
csl.newPacket();
|
||||
Platform.runLater(csl::newPacket);
|
||||
}
|
||||
} else {
|
||||
clientLog("Packet has been dropped", 1);
|
||||
@@ -147,7 +147,6 @@ public class ClientToServerThread implements Runnable {
|
||||
clientLog(e.getMessage(), 1);
|
||||
return;
|
||||
}
|
||||
System.out.println("streamPackets.size() = " + streamPackets.size());
|
||||
}
|
||||
closeSocket();
|
||||
clientLog("Closed connection to Server", 0);
|
||||
@@ -247,4 +246,8 @@ public class ClientToServerThread implements Runnable {
|
||||
public Thread getThread() {
|
||||
return thread;
|
||||
}
|
||||
|
||||
public int getClientId () {
|
||||
return clientId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,16 @@
|
||||
package seng302.visualiser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.gameServer.MainServerThread;
|
||||
import seng302.model.RaceState;
|
||||
@@ -53,7 +46,7 @@ public class GameClient {
|
||||
private RaceXMLData courseData;
|
||||
private RaceState raceState = new RaceState();
|
||||
|
||||
private ObservableList<String> lobbyList = FXCollections.observableArrayList();
|
||||
private ObservableList<String> clientLobbyList = FXCollections.observableArrayList();
|
||||
|
||||
private long lastSendingTime;
|
||||
private int KEY_STROKE_SENDING_FREQUENCY = 50;
|
||||
@@ -70,7 +63,7 @@ public class GameClient {
|
||||
System.out.println("Unable to connect to host...");
|
||||
}
|
||||
LobbyController lobbyController = loadLobby("/views/LobbyView.fxml");
|
||||
lobbyController.setPlayerListSource(lobbyList);
|
||||
lobbyController.setPlayerListSource(clientLobbyList);
|
||||
lobbyController.disableReadyButton();
|
||||
lobbyController.setTitle("Connected to host - IP : " + ipAddress + " Port : " + portNumber);
|
||||
lobbyController.addCloseListener((exitCause) -> this.loadStartScreen());
|
||||
@@ -134,26 +127,20 @@ public class GameClient {
|
||||
}
|
||||
|
||||
private void loadRaceView() {
|
||||
// allBoatsMap.forEach((id, boat) -> {
|
||||
// if (courseData.getParticipants().contains(id))
|
||||
// racingBoats.put(id, boat);
|
||||
// });
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(
|
||||
RaceViewController.class.getResource("/views/RaceView.fxml"));
|
||||
// raceView = fxmlLoader.getController();
|
||||
try {
|
||||
Node node = fxmlLoader.load();
|
||||
Platform.runLater(() -> {
|
||||
holderPane.getChildren().clear();
|
||||
holderPane.getChildren().add(node);
|
||||
});
|
||||
holderPane.getChildren().clear();
|
||||
holderPane.getChildren().add(node);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
holderPane.getScene().setOnKeyPressed(this::keyPressed);
|
||||
holderPane.getScene().setOnKeyReleased(this::keyReleased);
|
||||
raceView = fxmlLoader.getController();
|
||||
raceView.loadRace(allBoatsMap, courseData, raceState);
|
||||
Yacht player = allBoatsMap.get(socketThread.getClientId());
|
||||
raceView.loadRace(allBoatsMap, courseData, raceState, player);
|
||||
}
|
||||
|
||||
private void parsePackets() {
|
||||
@@ -166,7 +153,6 @@ public class GameClient {
|
||||
break;
|
||||
|
||||
case REGATTA_XML:
|
||||
System.out.println("REGATTA XML");
|
||||
regattaData = XMLParser.parseRegatta(
|
||||
StreamParser.extractXmlMessage(packet)
|
||||
);
|
||||
@@ -175,40 +161,27 @@ public class GameClient {
|
||||
ZoneId.ofOffset("UTC", ZoneOffset.ofHours(regattaData.getUtcOffset()))
|
||||
)
|
||||
);
|
||||
// startRaceIfAllDataReceived();
|
||||
break;
|
||||
|
||||
case RACE_XML:
|
||||
try {
|
||||
TransformerFactory tf = TransformerFactory.newInstance();
|
||||
Transformer transformer = tf.newTransformer();
|
||||
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
StringWriter writer = new StringWriter();
|
||||
transformer.transform(new DOMSource(StreamParser.extractXmlMessage(packet)),
|
||||
new StreamResult(writer));
|
||||
// String output = writer.getBuffer().toString().replaceAll("\n|\r", "");
|
||||
System.out.println(writer.getBuffer().toString());
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
courseData = XMLParser.parseRace(
|
||||
StreamParser.extractXmlMessage(packet)
|
||||
);
|
||||
if (raceView != null) {
|
||||
raceView.updateRaceData(courseData);
|
||||
}
|
||||
// startRaceIfAllDataReceived();
|
||||
break;
|
||||
|
||||
case BOAT_XML:
|
||||
System.out.println("BOAT XML");
|
||||
allBoatsMap = XMLParser.parseBoats(
|
||||
StreamParser.extractXmlMessage(packet)
|
||||
);
|
||||
lobbyList.clear();
|
||||
allBoatsMap
|
||||
.forEach((id, boat) -> lobbyList.add(id.toString() + boat.getBoatName()));
|
||||
allBoatsMap.forEach((i, b) -> System.out.println(b.getBoatName()));
|
||||
clientLobbyList.clear();
|
||||
allBoatsMap.forEach((id, boat) -> {
|
||||
clientLobbyList.add(id + " " + boat.getBoatName());
|
||||
System.out.println(id + " " + boat.getBoatName());
|
||||
|
||||
});
|
||||
// startRaceIfAllDataReceived();
|
||||
break;
|
||||
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package seng302.visualiser;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javafx.animation.AnimationTimer;
|
||||
import javafx.beans.property.ReadOnlyBooleanProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.Group;
|
||||
@@ -98,15 +95,6 @@ public class GameView extends Pane {
|
||||
gameObjects.add(raceBorder);
|
||||
gameObjects.add(markers);
|
||||
initializeTimer();
|
||||
// this.widthProperty().addListener(resize -> {
|
||||
// canvasWidth = this.getWidth();
|
||||
// canvasHeight = this.getHeight();
|
||||
// if (borderPoints != null) {
|
||||
// updateBorder(borderPoints);
|
||||
// } else if (course != null) {
|
||||
// updateCourse(course, markSequence);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
private void initializeTimer () {
|
||||
@@ -201,6 +189,7 @@ public class GameView extends Pane {
|
||||
//Create mark dots
|
||||
for (Mark mark : cMark.getMarks()) {
|
||||
makeAndBindMarker(mark, colour);
|
||||
System.out.println("hi" + mark.getName());
|
||||
}
|
||||
//Create gate line
|
||||
if (cMark.isGate()) {
|
||||
@@ -309,13 +298,22 @@ public class GameView extends Pane {
|
||||
public void setBoats(List<Yacht> yachts) {
|
||||
BoatObject newBoat;
|
||||
for (Yacht yacht : yachts) {
|
||||
Paint colour = Colors.getColor();
|
||||
newBoat = new BoatObject();
|
||||
newBoat.setFill(Colors.getColor());
|
||||
newBoat.setFill(colour);
|
||||
boatObjects.put(yacht, newBoat);
|
||||
createAndBindAnnotationBox(yacht, colour);
|
||||
wakesGroup.getChildren().add(newBoat.getWake());
|
||||
boatObjectGroup.getChildren().add(newBoat);
|
||||
trails.getChildren().add(newBoat.getTrail());
|
||||
// TODO: 1/08/17 Make this less vile to look at.
|
||||
yacht.addLocationListener((boat, lat, lon, heading, velocity) ->{
|
||||
BoatObject bo = boatObjects.get(boat);
|
||||
Point2D p2d = findScaledXY(lat, lon);
|
||||
bo.moveTo(p2d.getX(), p2d.getY(), heading);
|
||||
// annotations.get(boat).setLayoutX(p2d.getX());
|
||||
// annotations.get(boat).setLayoutY(p2d.getY());
|
||||
// annotations.get(boat).setLocation(100d, 100d);
|
||||
annotations.get(boat).setLocation(p2d.getX(), p2d.getY());
|
||||
bo.setTrajectory(
|
||||
heading,
|
||||
@@ -323,13 +321,10 @@ public class GameView extends Pane {
|
||||
metersPerPixelX,
|
||||
metersPerPixelY);
|
||||
});
|
||||
createAndBindAnnotationBox(yacht);
|
||||
wakesGroup.getChildren().add(newBoat.getWake());
|
||||
boatObjectGroup.getChildren().add(newBoat);
|
||||
trails.getChildren().add(newBoat.getTrail());
|
||||
}
|
||||
annotationsGroup.getChildren().addAll(annotations.values());
|
||||
gameObjects.addAll(trails);
|
||||
gameObjects.add(wakesGroup);
|
||||
gameObjects.addAll(annotationsGroup);
|
||||
gameObjects.addAll(boatObjectGroup);
|
||||
}
|
||||
@@ -346,32 +341,33 @@ public class GameView extends Pane {
|
||||
// metersPerPixelY);
|
||||
// }
|
||||
|
||||
private void createAndBindAnnotationBox (Yacht yacht) {
|
||||
AnnotationBox newAnnotation;
|
||||
newAnnotation = new AnnotationBox();
|
||||
newAnnotation.addAnnotation("name", yacht.getShortName());
|
||||
// newAnnotation.addAnnotation("country", boat.getCountry());
|
||||
private void createAndBindAnnotationBox (Yacht yacht, Paint colour) {
|
||||
AnnotationBox newAnnotation = new AnnotationBox();
|
||||
newAnnotation.setFill(colour);
|
||||
newAnnotation.addAnnotation(
|
||||
"velocity",
|
||||
yacht.getVelocityProperty(),
|
||||
(velocity) -> String.format("Speed: %.2f ms", velocity.doubleValue())
|
||||
);
|
||||
newAnnotation.addAnnotation(
|
||||
"nextMark",
|
||||
yacht.timeTillNextProperty(),
|
||||
(time) -> {
|
||||
DateFormat format = new SimpleDateFormat("mm:ss");
|
||||
return format.format(time);
|
||||
}
|
||||
);
|
||||
newAnnotation.addAnnotation(
|
||||
"lastMark",
|
||||
yacht.timeTillNextProperty(),
|
||||
(time) -> {
|
||||
DateFormat format = new SimpleDateFormat("mm:ss");
|
||||
return format.format(time);
|
||||
}
|
||||
"name", "Player: " + yacht.getShortName()
|
||||
);
|
||||
// newAnnotation.addAnnotation(
|
||||
// "velocity",
|
||||
// yacht.getVelocityProperty(),
|
||||
// (velocity) -> String.format("Speed: %.2f ms", velocity.doubleValue())
|
||||
// );
|
||||
// newAnnotation.addAnnotation(
|
||||
// "nextMark",
|
||||
// yacht.timeTillNextProperty(),
|
||||
// (time) -> {
|
||||
// DateFormat format = new SimpleDateFormat("mm:ss");
|
||||
// return format.format(time);
|
||||
// }
|
||||
// );
|
||||
// newAnnotation.addAnnotation(
|
||||
// "lastMark",
|
||||
// yacht.timeTillNextProperty(),
|
||||
// (time) -> {
|
||||
// DateFormat format = new SimpleDateFormat("mm:ss");
|
||||
// return format.format(time);
|
||||
// }
|
||||
// );
|
||||
annotations.put(yacht, newAnnotation);
|
||||
}
|
||||
|
||||
@@ -555,10 +551,6 @@ public class GameView extends Pane {
|
||||
fpsDisplay.setVisible(visibility);
|
||||
}
|
||||
|
||||
public ReadOnlyBooleanProperty getFPSVisibilityProperty () {
|
||||
return fpsDisplay.visibleProperty();
|
||||
}
|
||||
|
||||
public void selectBoat (Yacht selectedYacht) {
|
||||
boatObjects.forEach((boat, group) ->
|
||||
group.setIsSelected(boat == selectedYacht)
|
||||
@@ -575,6 +567,10 @@ public class GameView extends Pane {
|
||||
|
||||
public void setBoatAsPlayer (Yacht playerYacht) {
|
||||
boatObjects.get(playerYacht).setAsPlayer();
|
||||
// annotations.get(playerYacht).setAsPlayer();
|
||||
annotations.get(playerYacht).addAnnotation(
|
||||
"velocity",
|
||||
playerYacht.getVelocityProperty(),
|
||||
(velocity) -> String.format("Speed: %.2f ms", velocity.doubleValue())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
package seng302.visualiser.controllers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.text.Text;
|
||||
import seng302.gameServer.GameStages;
|
||||
import seng302.gameServer.GameState;
|
||||
@@ -24,7 +20,7 @@ import seng302.gameServer.GameState;
|
||||
* A class describing the actions of the lobby screen
|
||||
* Created by wmu16 on 10/07/17.
|
||||
*/
|
||||
public class LobbyController implements Initializable {
|
||||
public class LobbyController {
|
||||
|
||||
public enum CloseStatus {
|
||||
LEAVE,
|
||||
@@ -75,182 +71,67 @@ public class LobbyController implements Initializable {
|
||||
@FXML
|
||||
private ImageView eighthImageView;
|
||||
|
||||
private static List<ObservableList<String>> competitors = new ArrayList<>();
|
||||
private static ObservableList<String> firstCompetitor = FXCollections.observableArrayList();
|
||||
private static ObservableList<String> secondCompetitor = FXCollections.observableArrayList();
|
||||
private static ObservableList<String> thirdCompetitor = FXCollections.observableArrayList();
|
||||
private static ObservableList<String> fourthCompetitor = FXCollections.observableArrayList();
|
||||
private static ObservableList<String> fifthCompetitor = FXCollections.observableArrayList();
|
||||
private static ObservableList<String> sixthCompetitor = FXCollections.observableArrayList();
|
||||
private static ObservableList<String> seventhCompetitor = FXCollections.observableArrayList();
|
||||
private static ObservableList<String> eighthCompetitor = FXCollections.observableArrayList();
|
||||
// private ClientStateQueryingRunnable clientStateQueryingRunnable;
|
||||
private static List<ImageView> imageViews;
|
||||
private static List<ListView> listViews;
|
||||
private List<ObservableList<String>> competitors = new ArrayList<>();
|
||||
private ObservableList<String> firstCompetitor = FXCollections.observableArrayList();
|
||||
private ObservableList<String> secondCompetitor = FXCollections.observableArrayList();
|
||||
private ObservableList<String> thirdCompetitor = FXCollections.observableArrayList();
|
||||
private ObservableList<String> fourthCompetitor = FXCollections.observableArrayList();
|
||||
private ObservableList<String> fifthCompetitor = FXCollections.observableArrayList();
|
||||
private ObservableList<String> sixthCompetitor = FXCollections.observableArrayList();
|
||||
private ObservableList<String> seventhCompetitor = FXCollections.observableArrayList();
|
||||
private ObservableList<String> eighthCompetitor = FXCollections.observableArrayList();
|
||||
|
||||
private List<ImageView> imageViews = new ArrayList<>();
|
||||
private List<ListView> listViews;
|
||||
|
||||
private int MAX_NUM_PLAYERS = 8;
|
||||
|
||||
private Boolean switchedPane = false;
|
||||
|
||||
private List<LobbyCloseListener> lobbyListeners = new ArrayList<>();
|
||||
private ObservableList<String> players = FXCollections.observableArrayList();
|
||||
|
||||
private void setContentPane(String jfxUrl) {
|
||||
try {
|
||||
AnchorPane contentPane = (AnchorPane) lobbyScreen.getParent();
|
||||
contentPane.getChildren().removeAll();
|
||||
contentPane.getChildren().clear();
|
||||
contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
|
||||
contentPane.getChildren()
|
||||
.addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl)));
|
||||
} catch (javafx.fxml.LoadException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
public void initialize() {
|
||||
imageViews = new ArrayList<>();
|
||||
Collections
|
||||
.addAll(imageViews, firstImageView, secondImageView, thirdImageView, fourthImageView,
|
||||
fifthImageView, sixthImageView, seventhImageView, eighthImageView);
|
||||
listViews = new ArrayList<>();
|
||||
Collections.addAll(listViews, firstListView, secondListView, thirdListView, fourthListView, fifthListView,
|
||||
sixthListView, seventhListView, eighthListView);
|
||||
competitors = new ArrayList<>();
|
||||
Collections.addAll(competitors, firstCompetitor, secondCompetitor, thirdCompetitor,
|
||||
fourthCompetitor, fifthCompetitor, sixthCompetitor, seventhCompetitor, eighthCompetitor);
|
||||
|
||||
initialiseImageView();
|
||||
}
|
||||
|
||||
private void initialiseListView() {
|
||||
listViews.forEach(listView -> listView.getItems().clear());
|
||||
imageViews.forEach(gif -> gif.setVisible(false));
|
||||
competitors.forEach(ol -> ol.removeAll());
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
competitors.get(i).add(players.get(i));
|
||||
listViews.get(i).setItems(competitors.get(i));
|
||||
imageViews.get(i).setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
// if (ClientState.isHost()) {
|
||||
// lobbyIpText.setText("Lobby Host IP: " + ClientState.getHostIp());
|
||||
// readyButton.setDisable(false);
|
||||
// }
|
||||
// else {
|
||||
// lobbyIpText.setText("Connected to IP: ");
|
||||
// readyButton.setDisable(true);
|
||||
// readyButton.setVisible(false);
|
||||
// }
|
||||
// initialiseListView();
|
||||
// initialiseLobbyControllerThread();
|
||||
// initialiseImageView(); // parrot gif init
|
||||
// if (ClientState.isHost()) {
|
||||
// lobbyIpText.setText("Lobby Host IP: " + ClientState.getHostIp());
|
||||
// readyButton.setDisable(false);
|
||||
// }
|
||||
// else {
|
||||
// lobbyIpText.setText("Connected to IP: ");
|
||||
// readyButton.setDisable(true);
|
||||
// }
|
||||
//
|
||||
// imageViews = new ArrayList<>();
|
||||
// Collections.addAll(imageViews, firstImageView, secondImageView, thirdImageView, fourthImageView,
|
||||
// fifthImageView, sixthImageView, seventhImageView, eighthImageView);
|
||||
// listViews = new ArrayList<>();
|
||||
// Collections.addAll(listViews, firstListView, secondListView, thirdListView, fourthListView, fifthListView,
|
||||
// sixthListView, seventhListView, eighthListView);
|
||||
// competitors = new ArrayList<>();
|
||||
// Collections.addAll(competitors, firstCompetitor, secondCompetitor, thirdCompetitor,
|
||||
// fourthCompetitor, fifthCompetitor, sixthCompetitor, seventhCompetitor, eighthCompetitor);
|
||||
//
|
||||
// initialiseListView();
|
||||
// initialiseImageView(); // parrot gif init
|
||||
|
||||
// set up client state query thread, so that when it receives the race-started packet
|
||||
// it can switch to the race view
|
||||
// ClientStateQueryingRunnable clientStateQueryingRunnable = new ClientStateQueryingRunnable();
|
||||
// clientStateQueryingRunnable.addObserver(this);
|
||||
// Thread clientStateQueryingThread = new Thread(clientStateQueryingRunnable, "Client State querying thread");
|
||||
// clientStateQueryingThread.setDaemon(true);
|
||||
// clientStateQueryingThread.start();
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void update(Observable o, Object arg) {
|
||||
// Platform.runLater(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// if (arg.equals("game started") && !switchedPane) {
|
||||
// switchToRaceView();
|
||||
// }
|
||||
// if (arg.equals(("update players"))) {
|
||||
// initialiseListView();
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
|
||||
|
||||
private void initialiseListView() {
|
||||
// firstListView.getItems().clear();
|
||||
// secondListView.getItems().clear();
|
||||
// thirdListView.getItems().clear();
|
||||
// fourthListView.getItems().clear();
|
||||
// fifthListView.getItems().clear();
|
||||
// sixthListView.getItems().clear();
|
||||
// seventhListView.getItems().clear();
|
||||
// eighthListView.getItems().clear();
|
||||
|
||||
// listViews.forEach(listView -> listView.getItems().clear());
|
||||
// imageViews.forEach(gif -> gif.setVisible(false));
|
||||
// competitors.forEach(ol -> ol.removeAll());
|
||||
//
|
||||
// List<Integer> ids = new ArrayList<>(ClientState.getBoats().keySet());
|
||||
// for (int i = 0; i < ids.size(); i++) {
|
||||
// competitors.get(i).add(String.format("Player ID: %d", ids.get(i)));
|
||||
// listViews.get(i).setItems(competitors.get(i));
|
||||
// imageViews.get(i).setVisible(true);
|
||||
// }
|
||||
|
||||
// firstCompetitor.add(ClientState.getClientSourceId());
|
||||
|
||||
// int competitorIndex = 1;
|
||||
// for (Integer yachtId : ClientState.getBoats().keySet()) {
|
||||
// // break if there are more than 7 competitors
|
||||
// if (competitorIndex >= 8) {
|
||||
// break;
|
||||
// }
|
||||
// if (!yachtId.equals(Integer.parseInt(ClientState.getClientSourceId()))) {
|
||||
// competitors.get(competitorIndex).add(String.valueOf(yachtId));
|
||||
// competitorIndex++;
|
||||
// }
|
||||
// }
|
||||
|
||||
// firstListView.setItems(firstCompetitor);
|
||||
// secondListView.setItems(secondCompetitor);
|
||||
// thirdListView.setItems(thirdCompetitor);
|
||||
// fourthListView.setItems(fourthCompetitor);
|
||||
// fifthListView.setItems(fifthCompetitor);
|
||||
// sixthListView.setItems(sixthCompetitor);
|
||||
// seventhListView.setItems(seventhCompetitor);
|
||||
// eighthListView.setItems(eighthCompetitor);
|
||||
// }
|
||||
|
||||
// private void initialiseLobbyControllerThread() {
|
||||
// Thread thread = new Thread(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// Platform.runLater(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
//
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// thread.start();
|
||||
}
|
||||
|
||||
private void initialiseImageView() {
|
||||
// for (int i = 0; i < MAX_NUM_PLAYERS; i++) {
|
||||
// imageViews.get(i).setImage(new Image(getClass().getResourceAsStream("/pics/sail.png")));
|
||||
// }
|
||||
// Image image1 = new Image(getClass().getResourceAsStream("/pics/sail.png"));
|
||||
// firstImageView.setImage(image1);
|
||||
// Image image2 = new Image(getClass().getResourceAsStream("/pics/sail.png"));
|
||||
// secondImageView.setImage(image2);
|
||||
// Image image3 = new Image(getClass().getResourceAsStream("/pics/sail.png"));
|
||||
// thirdImageView.setImage(image3);
|
||||
// Image image4 = new Image(getClass().getResourceAsStream("/pics/sail.png"));
|
||||
// fourthImageView.setImage(image4);
|
||||
// Image image5 = new Image(getClass().getResourceAsStream("/pics/sail.png"));
|
||||
// fifthImageView.setImage(image5);
|
||||
// Image image6 = new Image(getClass().getResourceAsStream("/pics/sail.png"));
|
||||
// sixthImageView.setImage(image6);
|
||||
// Image image7 = new Image(getClass().getResourceAsStream("/pics/sail.png"));
|
||||
// seventhImageView.setImage(image7);
|
||||
// Image image8 = new Image(getClass().getResourceAsStream("/pics/sail.png"));
|
||||
// eighthImageView.setImage(image8);
|
||||
imageViews.add(firstImageView);
|
||||
imageViews.add(secondImageView);
|
||||
imageViews.add(thirdImageView);
|
||||
imageViews.add(fourthImageView);
|
||||
imageViews.add(fifthImageView);
|
||||
imageViews.add(sixthImageView);
|
||||
imageViews.add(seventhImageView);
|
||||
imageViews.add(eighthImageView);
|
||||
for (int i = 0; i < MAX_NUM_PLAYERS; i++) {
|
||||
imageViews.get(i).setImage(
|
||||
new Image(
|
||||
RaceViewController.class.getResourceAsStream(
|
||||
"/pics/sail.png")
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
@@ -267,8 +148,6 @@ public class LobbyController implements Initializable {
|
||||
|
||||
@FXML
|
||||
public void readyButtonPressed() {
|
||||
// setContentPane("/views/RaceView.fxml");
|
||||
// playTheme();
|
||||
GameState.setCurrentStage(GameStages.RACING);
|
||||
for (LobbyCloseListener readyListener : lobbyListeners)
|
||||
readyListener.notify(CloseStatus.READY);
|
||||
@@ -308,13 +187,13 @@ public class LobbyController implements Initializable {
|
||||
lobbyListeners.add(listener);
|
||||
}
|
||||
|
||||
// TODO: 1/08/17 could definitely do this in a cleaner way.
|
||||
public void setPlayerListSource (ObservableList<String> players) {
|
||||
// if (competitorsListView != null)
|
||||
// competitorsListView.setItems(players);
|
||||
// if (firstListView != null) {
|
||||
firstListView.setItems(players);
|
||||
firstImageView.setVisible(false);
|
||||
// }
|
||||
this.players = players;
|
||||
players.addListener((ListChangeListener<? super String>) (lcl) ->
|
||||
initialiseListView()
|
||||
);
|
||||
initialiseListView();
|
||||
}
|
||||
|
||||
public void disableReadyButton () {
|
||||
|
||||
@@ -9,7 +9,6 @@ import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javafx.animation.KeyFrame;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
@@ -101,7 +100,9 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
selectAnnotationBtn.setOnAction(event -> loadSelectAnnotationView());
|
||||
}
|
||||
|
||||
public void loadRace (Map<Integer, Yacht> participants, RaceXMLData raceData, RaceState raceState) {
|
||||
public void loadRace (
|
||||
Map<Integer, Yacht> participants, RaceXMLData raceData, RaceState raceState, Yacht player
|
||||
) {
|
||||
this.participants = participants;
|
||||
this.courseData = raceData;
|
||||
this.markers = raceData.getCompoundMarks();
|
||||
@@ -113,19 +114,14 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
initialiseBoatSelectionComboBox();
|
||||
|
||||
gameView = new GameView();
|
||||
System.out.println("haha");
|
||||
Platform.runLater(() -> {
|
||||
contentAnchorPane.getChildren().add(gameView);
|
||||
|
||||
// contentAnchorPane.getChildren().add(gameView);
|
||||
System.out.println("hehe");
|
||||
gameView.setBoats(new ArrayList<>(participants.values()));
|
||||
gameView.updateBorder(raceData.getCourseLimit());
|
||||
gameView.updateCourse(
|
||||
new ArrayList<>(raceData.getCompoundMarks().values()), raceData.getMarkSequence()
|
||||
);
|
||||
gameView.startRace();
|
||||
});
|
||||
contentAnchorPane.getChildren().add(gameView);
|
||||
gameView.setBoats(new ArrayList<>(participants.values()));
|
||||
gameView.updateBorder(raceData.getCourseLimit());
|
||||
gameView.updateCourse(
|
||||
new ArrayList<>(raceData.getCompoundMarks().values()), raceData.getMarkSequence()
|
||||
);
|
||||
gameView.setBoatAsPlayer(player);
|
||||
gameView.startRace();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -610,5 +606,4 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
this.courseData = raceData;
|
||||
gameView.updateBorder(raceData.getCourseLimit());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package seng302.visualiser.fxObjects;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.scene.CacheHint;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.Paint;
|
||||
@@ -60,8 +61,8 @@ public class AnnotationBox extends Group{
|
||||
}
|
||||
|
||||
//Text offset constants
|
||||
private static final double X_OFFSET_TEXT = 18d;
|
||||
private static final double Y_OFFSET_TEXT_INIT = -29d;
|
||||
private static final double X_OFFSET_TEXT = 20d;
|
||||
private static final double Y_OFFSET_TEXT_INIT = -35d;
|
||||
private static final double Y_OFFSET_PER_TEXT = 12d;
|
||||
//Background constants
|
||||
private static final double TEXT_BUFFER = 3;
|
||||
@@ -71,7 +72,7 @@ public class AnnotationBox extends Group{
|
||||
private static final double BACKGROUND_ARC_SIZE = 10;
|
||||
|
||||
private int visibleAnnotations = 0;
|
||||
private double backgroundWidth = 125d;
|
||||
private double backgroundWidth = 145d;
|
||||
|
||||
private Rectangle background = new Rectangle();
|
||||
private Paint theme = Color.BLACK;
|
||||
@@ -79,7 +80,7 @@ public class AnnotationBox extends Group{
|
||||
private Map<String, Annotation> annotationsByName = new HashMap<>();
|
||||
|
||||
public AnnotationBox() {
|
||||
// this.setCache(true);
|
||||
this.setCache(true);
|
||||
background.setX(BACKGROUND_X);
|
||||
background.setY(BACKGROUND_Y);
|
||||
background.setWidth(backgroundWidth);
|
||||
@@ -89,8 +90,8 @@ public class AnnotationBox extends Group{
|
||||
background.setFill(new Color(1, 1, 1, 0.75));
|
||||
background.setStroke(theme);
|
||||
background.setStrokeWidth(2);
|
||||
// background.setCache(true);
|
||||
// background.setCacheHint(CacheHint.SPEED);
|
||||
background.setCache(true);
|
||||
background.setCacheHint(CacheHint.SPEED);
|
||||
this.getChildren().add(background);
|
||||
}
|
||||
|
||||
@@ -123,17 +124,18 @@ public class AnnotationBox extends Group{
|
||||
}
|
||||
|
||||
public void setAnnotationVisibility (String annotationName, boolean visibility) {
|
||||
Text textField = annotationsByName.get(annotationName).text;
|
||||
boolean currentState = textField.visibleProperty().get();
|
||||
|
||||
if (visibility != currentState) {
|
||||
if (visibility)
|
||||
visibleAnnotations++;
|
||||
else
|
||||
visibleAnnotations--;
|
||||
if (annotationsByName.containsKey(annotationName)) {
|
||||
Text textField = annotationsByName.get(annotationName).text;
|
||||
boolean currentState = textField.visibleProperty().get();
|
||||
if (visibility != currentState) {
|
||||
if (visibility)
|
||||
visibleAnnotations++;
|
||||
else
|
||||
visibleAnnotations--;
|
||||
}
|
||||
textField.setVisible(visibility);
|
||||
update();
|
||||
}
|
||||
textField.setVisible(visibility);
|
||||
update();
|
||||
}
|
||||
|
||||
public void removeAnnotation (String annotationName) {
|
||||
@@ -143,13 +145,32 @@ public class AnnotationBox extends Group{
|
||||
update();
|
||||
}
|
||||
|
||||
public void bindLocation () {
|
||||
|
||||
}
|
||||
|
||||
public void setLocation (double x, double y) {
|
||||
this.setTranslateX(x);
|
||||
this.setTranslateY(y);
|
||||
// double dx = x - this.getLayoutX();
|
||||
// double dy = y - this.getLayoutY();
|
||||
// this.relocate(x, y);
|
||||
//// this.relocate(x, y);
|
||||
// for (Node n : this.getChildren()) {
|
||||
// n.relocate(
|
||||
// n.getLayoutX() + dx,
|
||||
// n.getLayoutY() + dy
|
||||
// );
|
||||
//// n.setLayoutX(n.getLayoutX() + dx);
|
||||
//// n.setLayoutY(n.getLayoutY() + dy);
|
||||
// }
|
||||
// update();
|
||||
this.relocate(x + BACKGROUND_X, y + BACKGROUND_Y);
|
||||
// for (int i = 1; i <= visibleAnnotations; i++) {
|
||||
// Text text = (Text) this.getChildren().get(i);
|
||||
// if (text.visibleProperty().get()) {
|
||||
// text.setLayoutX(x + X_OFFSET_TEXT);
|
||||
// text.setLayoutY(y + Y_OFFSET_TEXT_INIT * Y_OFFSET_PER_TEXT * (i + 1));
|
||||
// }
|
||||
// }
|
||||
// moveTexts(x, y);
|
||||
// for (Node n : this.getChildren()) {
|
||||
// n.relocate(x, y);
|
||||
// }
|
||||
}
|
||||
|
||||
public void setWidth (double width) {
|
||||
@@ -160,10 +181,19 @@ public class AnnotationBox extends Group{
|
||||
private void update () {
|
||||
background.setVisible(visibleAnnotations != 0);
|
||||
background.setHeight(Math.abs(BACKGROUND_X) + TEXT_BUFFER + BACKGROUND_H_PER_TEXT * visibleAnnotations);
|
||||
// System.out.println("visibleAnnotations = " + visibleAnnotations);
|
||||
for (int i = 1; i <= visibleAnnotations; i++) {
|
||||
Text text = (Text) this.getChildren().get(i);
|
||||
if (text.visibleProperty().get())
|
||||
text.relocate(X_OFFSET_TEXT, Y_OFFSET_TEXT_INIT * Y_OFFSET_PER_TEXT * (i + 1));
|
||||
if (text.visibleProperty().get()) {
|
||||
// System.out.println("AYY LMAO");
|
||||
// System.out.println("text.getText() = " + text.getText());
|
||||
//// System.out
|
||||
//// .println("text.visibleProperty().get() = " + text.visibleProperty().get());
|
||||
// System.out.println(text.getLayoutX());
|
||||
// System.out.println(background.getLayoutX());
|
||||
text.setX(X_OFFSET_TEXT);
|
||||
text.setY(Y_OFFSET_TEXT_INIT + Y_OFFSET_PER_TEXT * i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,8 +206,8 @@ public class AnnotationBox extends Group{
|
||||
Text text = new Text();
|
||||
text.setFill(theme);
|
||||
text.setStrokeWidth(2);
|
||||
// text.setCacheHint(CacheHint.SPEED);
|
||||
// text.setCache(true);
|
||||
text.setCacheHint(CacheHint.SPEED);
|
||||
text.setCache(true);
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,8 +80,8 @@ public class BoatObject extends Group {
|
||||
boatPoly.setStroke(Color.BLACK);
|
||||
});
|
||||
boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected));
|
||||
// boatPoly.setCache(true);
|
||||
// boatPoly.setCacheHint(CacheHint.SPEED);
|
||||
boatPoly.setCache(true);
|
||||
boatPoly.setCacheHint(CacheHint.SPEED);
|
||||
|
||||
// annotationBox = new AnnotationBox();
|
||||
// annotationBox.setFill(colour);
|
||||
@@ -260,8 +260,6 @@ public class BoatObject extends Group {
|
||||
);
|
||||
boatPoly.setStroke(Color.BLACK);
|
||||
boatPoly.setStrokeWidth(3);
|
||||
// boatAnnotations.setAsPlayer();
|
||||
// isPlayer = true;
|
||||
}
|
||||
|
||||
public void setTrajectory(double heading, double velocity) {
|
||||
|
||||
@@ -27,31 +27,7 @@
|
||||
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.665316" TargetLng="11.827184" SourceID="126" />
|
||||
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.664190" TargetLng="11.829576" SourceID="127" />
|
||||
</CompoundMark>
|
||||
<CompoundMark CompoundMarkID="5" Name="Mark2">
|
||||
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="124" />
|
||||
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="125" />
|
||||
</CompoundMark>
|
||||
<CompoundMark CompoundMarkID="6" Name="Mark3">
|
||||
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="126" />
|
||||
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="127" />
|
||||
</CompoundMark>
|
||||
<CompoundMark CompoundMarkID="7" Name="Mark2">
|
||||
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="124" />
|
||||
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="125" />
|
||||
</CompoundMark>
|
||||
<CompoundMark CompoundMarkID="8" Name="Mark3">
|
||||
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="126" />
|
||||
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="127" />
|
||||
</CompoundMark>
|
||||
<CompoundMark CompoundMarkID="9" Name="Mark2">
|
||||
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="124" />
|
||||
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="125" />
|
||||
</CompoundMark>
|
||||
<CompoundMark CompoundMarkID="10" Name="Mark3">
|
||||
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="126" />
|
||||
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="127" />
|
||||
</CompoundMark>
|
||||
<CompoundMark CompoundMarkID="11" Name="Mark4">
|
||||
<CompoundMark CompoundMarkID="5" Name="Mark4">
|
||||
<Mark SeqID="1" Name="Finish Line 1" TargetLat="57.672350" TargetLng="11.842535" SourceID="128" />
|
||||
<Mark SeqID="2" Name="Finish Line 2" TargetLat="57.6715240" TargetLng="11.8444950" SourceID="129" />
|
||||
</CompoundMark>
|
||||
@@ -61,13 +37,13 @@
|
||||
<Corner SeqID="2" CompoundMarkID="2" Rounding="Port" ZoneSize="3" />
|
||||
<Corner SeqID="3" CompoundMarkID="3" Rounding="SP" ZoneSize="3" />
|
||||
<Corner SeqID="4" CompoundMarkID="4" Rounding="PS" ZoneSize="3" />
|
||||
<Corner SeqID="5" CompoundMarkID="5" Rounding="SP" ZoneSize="3" />
|
||||
<Corner SeqID="6" CompoundMarkID="6" Rounding="PS" ZoneSize="3" />
|
||||
<Corner SeqID="7" CompoundMarkID="7" Rounding="SP" ZoneSize="3" />
|
||||
<Corner SeqID="8" CompoundMarkID="8" Rounding="PS" ZoneSize="3" />
|
||||
<Corner SeqID="9" CompoundMarkID="9" Rounding="SP" ZoneSize="3" />
|
||||
<Corner SeqID="10" CompoundMarkID="10" Rounding="PS" ZoneSize="3" />
|
||||
<Corner SeqID="11" CompoundMarkID="11" Rounding="PS" ZoneSize="3" />
|
||||
<Corner SeqID="5" CompoundMarkID="3" Rounding="SP" ZoneSize="3" />
|
||||
<Corner SeqID="6" CompoundMarkID="4" Rounding="PS" ZoneSize="3" />
|
||||
<Corner SeqID="7" CompoundMarkID="3" Rounding="SP" ZoneSize="3" />
|
||||
<Corner SeqID="8" CompoundMarkID="4" Rounding="PS" ZoneSize="3" />
|
||||
<Corner SeqID="9" CompoundMarkID="3" Rounding="SP" ZoneSize="3" />
|
||||
<Corner SeqID="10" CompoundMarkID="4" Rounding="PS" ZoneSize="3" />
|
||||
<Corner SeqID="11" CompoundMarkID="5" Rounding="PS" ZoneSize="3" />
|
||||
</CompoundMarkSequence>
|
||||
<CourseLimit>
|
||||
<Limit SeqID="1" Lat="57.6739450" Lon="11.8417100" />
|
||||
|
||||
Reference in New Issue
Block a user