Working ordering for in game AND race finish screen.

List in RaceState holds a sorted list of yachts.
A Listener is added to this list, listening for a permutation change, on perm change, sorts the list by comparitor of leg number of each yacht (stable sort)
This commit is contained in:
William Muir
2017-08-16 23:22:58 +12:00
parent 9727e86249
commit 65286f273b
4 changed files with 16 additions and 10 deletions
@@ -198,7 +198,7 @@ public class GameClient {
}
FinishScreenViewController controller = fxmlLoader.getController();
controller.setFinishers(allBoatsMap.values());
controller.setFinishers(raceState.getPlayerPositions());
}
private void parsePackets() {
@@ -338,6 +338,11 @@ public class GameClient {
if (legNumber != clientYacht.getLegNumber()) {
clientYacht.setLegNumber(legNumber);
raceState.sortPlayers();
// System.out.println("ORDER:");
// for (ClientYacht clientYacht1 : raceState.getPlayerPositions()) {
// System.out.println(clientYacht1.getShortName());
// }
// System.out.println();
}
}
}
@@ -394,17 +394,17 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
private void updateOrder(ObservableList<ClientYacht> yachts) {
List<Text> vboxEntries = new ArrayList<>();
for (ClientYacht clientYacht : yachts) {
for (int i = 0; i < yachts.size(); i++) {
// System.out.println("yacht == null " + String.valueOf(yacht == null));
if (clientYacht.getBoatStatus() == 3) { // 3 is finish status
Text textToAdd = new Text(clientYacht.getPositionInteger() + ". " +
clientYacht.getShortName() + " (Finished)");
if (yachts.get(i).getBoatStatus() == 3) { // 3 is finish status
Text textToAdd = new Text(i + 1 + ". " +
yachts.get(i).getShortName() + " (Finished)");
textToAdd.setFill(Paint.valueOf("#d3d3d3"));
vboxEntries.add(textToAdd);
} else {
Text textToAdd = new Text(clientYacht.getPositionInteger() + ". " +
clientYacht.getShortName() + " ");
Text textToAdd = new Text(i + 1 + ". " +
yachts.get(i).getShortName() + " ");
textToAdd.setFill(Paint.valueOf("#d3d3d3"));
textToAdd.setStyle("");
vboxEntries.add(textToAdd);