Added start button for host on the ingameLobby screen.

#story[1352]
main
fjc40 8 years ago
parent 951c3771fa
commit 612b4b455e

@ -63,6 +63,8 @@ public class Event {
*/
private SourceIdAllocator sourceIdAllocator;
private RaceLogic raceLogic;
private Thread raceThread;
private Thread connectionThread;
@ -171,20 +173,20 @@ public class Event {
}
RaceLogic newRace = new RaceLogic(
this.raceLogic = new RaceLogic(
mockRace,
this.latestMessages,
this.compositeCommand);
this.raceThread = new Thread(newRace, "Event.Start()->RaceLogic thread");
this.raceThread = new Thread(raceLogic, "Event.Start()->RaceLogic thread");
raceThread.start();
//Create connection acceptor.
this.sourceIdAllocator = new SourceIdAllocator(newRace.getRace());
this.sourceIdAllocator = new SourceIdAllocator(raceLogic.getRace());
try {
this.connectionAcceptor = new ConnectionAcceptor(latestMessages, compositeCommand, sourceIdAllocator, newRace);
this.connectionAcceptor = new ConnectionAcceptor(latestMessages, compositeCommand, sourceIdAllocator, raceLogic);
} catch (IOException 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);
}
public RaceLogic getRaceLogic() {
return raceLogic;
}
}

@ -195,6 +195,19 @@ public class MockRace extends RaceState {
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.
*/

@ -10,6 +10,7 @@ import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
@ -78,6 +79,12 @@ public class InGameLobbyController extends Controller {
@FXML
private Label countdownTenText;
@FXML
private Button startButton;
@FXML
private Button quitButton;
private Event game;
private View3D playerBoat;
@ -291,6 +298,8 @@ public class InGameLobbyController extends Controller {
this.visualiserRaceEvent.getVisualiserRaceState().getBoats().addListener(this.lobbyUpdateListener);
enableStartIfHost();
startRace();
} catch (IOException e) {
//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
* @throws IOException socket erro
@ -325,7 +350,7 @@ public class InGameLobbyController extends Controller {
* Start button pressed. Currently only prints out start
*/
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(){

@ -1,30 +1,19 @@
<?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.scene.control.Button?>
<?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.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?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>
<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>
<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>
<Insets left="20.0" />
</GridPane.margin>
@ -82,6 +71,7 @@
<Font name="Cabin-Bold" size="17.0" />
</font>
</Label>
<Button fx:id="startButton" mnemonicParsing="false" onAction="#startBtnPressed" text="Start!" GridPane.columnIndex="2" GridPane.rowIndex="2" />
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />

Loading…
Cancel
Save