Added start button for host on the ingameLobby screen.
#story[1352]
This commit is contained in:
@@ -63,6 +63,8 @@ public class Event {
|
|||||||
*/
|
*/
|
||||||
private SourceIdAllocator sourceIdAllocator;
|
private SourceIdAllocator sourceIdAllocator;
|
||||||
|
|
||||||
|
private RaceLogic raceLogic;
|
||||||
|
|
||||||
private Thread raceThread;
|
private Thread raceThread;
|
||||||
|
|
||||||
private Thread connectionThread;
|
private Thread connectionThread;
|
||||||
@@ -171,20 +173,20 @@ public class Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RaceLogic newRace = new RaceLogic(
|
this.raceLogic = new RaceLogic(
|
||||||
mockRace,
|
mockRace,
|
||||||
this.latestMessages,
|
this.latestMessages,
|
||||||
this.compositeCommand);
|
this.compositeCommand);
|
||||||
|
|
||||||
this.raceThread = new Thread(newRace, "Event.Start()->RaceLogic thread");
|
this.raceThread = new Thread(raceLogic, "Event.Start()->RaceLogic thread");
|
||||||
raceThread.start();
|
raceThread.start();
|
||||||
|
|
||||||
|
|
||||||
//Create connection acceptor.
|
//Create connection acceptor.
|
||||||
this.sourceIdAllocator = new SourceIdAllocator(newRace.getRace());
|
this.sourceIdAllocator = new SourceIdAllocator(raceLogic.getRace());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.connectionAcceptor = new ConnectionAcceptor(latestMessages, compositeCommand, sourceIdAllocator, newRace);
|
this.connectionAcceptor = new ConnectionAcceptor(latestMessages, compositeCommand, sourceIdAllocator, raceLogic);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new EventConstructionException("Could not create ConnectionAcceptor.", e);
|
throw new EventConstructionException("Could not create ConnectionAcceptor.", e);
|
||||||
@@ -241,4 +243,9 @@ public class Event {
|
|||||||
return new HostGame(ip, 3779,(byte) 1,(byte) 1, RaceStatusEnum.PRESTART, (byte) 1, (byte) 1);
|
return new HostGame(ip, 3779,(byte) 1,(byte) 1, RaceStatusEnum.PRESTART, (byte) 1, (byte) 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public RaceLogic getRaceLogic() {
|
||||||
|
return raceLogic;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,6 +195,19 @@ public class MockRace extends RaceState {
|
|||||||
this.racePreparatoryTime = racePreparatoryTime;
|
this.racePreparatoryTime = racePreparatoryTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getRacePreparatoryTime() {
|
||||||
|
return racePreparatoryTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the race in #timeToStartMilli milliseconds.
|
||||||
|
* @param timeToStartMilli Millseconds before starting the race.
|
||||||
|
*/
|
||||||
|
public void startRace(long timeToStartMilli) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the status of all boats in the race to RACING.
|
* Sets the status of all boats in the race to RACING.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import javafx.fxml.FXML;
|
|||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.ButtonType;
|
import javafx.scene.control.ButtonType;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
@@ -78,6 +79,12 @@ public class InGameLobbyController extends Controller {
|
|||||||
@FXML
|
@FXML
|
||||||
private Label countdownTenText;
|
private Label countdownTenText;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button startButton;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button quitButton;
|
||||||
|
|
||||||
private Event game;
|
private Event game;
|
||||||
|
|
||||||
private View3D playerBoat;
|
private View3D playerBoat;
|
||||||
@@ -291,6 +298,8 @@ public class InGameLobbyController extends Controller {
|
|||||||
|
|
||||||
this.visualiserRaceEvent.getVisualiserRaceState().getBoats().addListener(this.lobbyUpdateListener);
|
this.visualiserRaceEvent.getVisualiserRaceState().getBoats().addListener(this.lobbyUpdateListener);
|
||||||
|
|
||||||
|
enableStartIfHost();
|
||||||
|
|
||||||
startRace();
|
startRace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
//TODO should probably let this propagate, so that we only enter this scene if everything works
|
//TODO should probably let this propagate, so that we only enter this scene if everything works
|
||||||
@@ -298,6 +307,22 @@ public class InGameLobbyController extends Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables the start button if the client is the host of the game.
|
||||||
|
*/
|
||||||
|
private void enableStartIfHost() {
|
||||||
|
if (isHost) {
|
||||||
|
startButton.setVisible(true);
|
||||||
|
startButton.setDisable(false);
|
||||||
|
} else {
|
||||||
|
startButton.setVisible(false);
|
||||||
|
startButton.setDisable(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Menu button pressed. Prompt alert then return to menu
|
* Menu button pressed. Prompt alert then return to menu
|
||||||
* @throws IOException socket erro
|
* @throws IOException socket erro
|
||||||
@@ -325,7 +350,7 @@ public class InGameLobbyController extends Controller {
|
|||||||
* Start button pressed. Currently only prints out start
|
* Start button pressed. Currently only prints out start
|
||||||
*/
|
*/
|
||||||
public void startBtnPressed(){
|
public void startBtnPressed(){
|
||||||
//System.out.println("Should start the race. This button is only visible for the host");
|
App.game.getRaceLogic().getRace().startRace(App.game.getRaceLogic().getRace().getRacePreparatoryTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void joinSpecPressed(){
|
public void joinSpecPressed(){
|
||||||
|
|||||||
@@ -1,30 +1,19 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import java.lang.*?>
|
|
||||||
<?import javafx.geometry.*?>
|
|
||||||
<?import javafx.scene.control.*?>
|
|
||||||
<?import javafx.scene.image.*?>
|
|
||||||
<?import javafx.scene.layout.*?>
|
|
||||||
<?import javafx.scene.text.*?>
|
|
||||||
<?import javafx.geometry.Insets?>
|
<?import javafx.geometry.Insets?>
|
||||||
<?import javafx.scene.control.Button?>
|
<?import javafx.scene.control.Button?>
|
||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.control.SplitPane?>
|
|
||||||
<?import javafx.scene.control.TableColumn?>
|
|
||||||
<?import javafx.scene.control.TableView?>
|
|
||||||
<?import javafx.scene.image.Image?>
|
|
||||||
<?import javafx.scene.image.ImageView?>
|
|
||||||
<?import javafx.scene.layout.AnchorPane?>
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
<?import javafx.scene.layout.ColumnConstraints?>
|
<?import javafx.scene.layout.ColumnConstraints?>
|
||||||
<?import javafx.scene.layout.GridPane?>
|
<?import javafx.scene.layout.GridPane?>
|
||||||
<?import javafx.scene.layout.RowConstraints?>
|
<?import javafx.scene.layout.RowConstraints?>
|
||||||
<?import javafx.scene.text.Font?>
|
<?import javafx.scene.text.Font?>
|
||||||
|
|
||||||
<AnchorPane fx:id="gameLobbyWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" style="-fx-background-color: rgba(100, 100, 100, 0.2);" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.InGameLobbyController">
|
<AnchorPane fx:id="gameLobbyWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" style="-fx-background-color: rgba(100, 100, 100, 0.2);" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.InGameLobbyController">
|
||||||
<children>
|
<children>
|
||||||
<GridPane style="-fx-background-color: rgba(0, 0, 0, 0.3);" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
<GridPane style="-fx-background-color: rgba(0, 0, 0, 0.3);" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
<children>
|
<children>
|
||||||
<Button mnemonicParsing="false" onAction="#menuBtnPressed" text="Quit" GridPane.rowIndex="2">
|
<Button fx:id="quitButton" mnemonicParsing="false" onAction="#menuBtnPressed" text="Quit" GridPane.rowIndex="2">
|
||||||
<GridPane.margin>
|
<GridPane.margin>
|
||||||
<Insets left="20.0" />
|
<Insets left="20.0" />
|
||||||
</GridPane.margin>
|
</GridPane.margin>
|
||||||
@@ -82,6 +71,7 @@
|
|||||||
<Font name="Cabin-Bold" size="17.0" />
|
<Font name="Cabin-Bold" size="17.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
|
<Button fx:id="startButton" mnemonicParsing="false" onAction="#startBtnPressed" text="Start!" GridPane.columnIndex="2" GridPane.rowIndex="2" />
|
||||||
</children>
|
</children>
|
||||||
<columnConstraints>
|
<columnConstraints>
|
||||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||||
|
|||||||
Reference in New Issue
Block a user