Created new lobby menu. Working on animated background for menu.

main
David Wu 9 years ago
parent 7086af6057
commit c63403d1de

@ -1,8 +1,14 @@
package visualiser.Controllers; package visualiser.Controllers;
import javafx.animation.Animation;
import javafx.application.Platform;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.geometry.Rectangle2D;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.util.Duration;
import mock.app.Event; import mock.app.Event;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import mock.exceptions.EventConstructionException; import mock.exceptions.EventConstructionException;
@ -10,6 +16,7 @@ import shared.exceptions.InvalidBoatDataException;
import shared.exceptions.InvalidRaceDataException; import shared.exceptions.InvalidRaceDataException;
import shared.exceptions.InvalidRegattaDataException; import shared.exceptions.InvalidRegattaDataException;
import shared.exceptions.XMLReaderException; import shared.exceptions.XMLReaderException;
import visualiser.model.SpriteAnimation;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
@ -25,12 +32,22 @@ import java.util.logging.Logger;
*/ */
public class HostController extends Controller { public class HostController extends Controller {
private static final int COLUMNS = 4;
private static final int COUNT = 10;
private static final int OFFSET_X = 18;
private static final int OFFSET_Y = 25;
private static final int WIDTH = 374;
private static final int HEIGHT = 243;
@FXML
TextField gameNameField; // @FXML
// TextField gameNameField;
//
// @FXML
// TextField hostNameField;
@FXML @FXML
TextField hostNameField; private ImageView imageView;
@FXML @FXML
AnchorPane hostWrapper; AnchorPane hostWrapper;
@ -81,12 +98,20 @@ public class HostController extends Controller {
* Hosts a game. * Hosts a game.
*/ */
public void hostGame(){ public void hostGame(){
Platform.runLater(() -> {
imageView.setImage(new Image("https://media.tenor.com/images/3059eba221c9537eff1cf84ff4eabffc/tenor.gif"));
imageView.setViewport(new Rectangle2D(OFFSET_X, OFFSET_Y, WIDTH, HEIGHT));
final Animation animation = new SpriteAnimation(imageView, Duration.millis(250), COUNT, COLUMNS, OFFSET_X, OFFSET_Y, WIDTH, HEIGHT);
animation.setCycleCount(Animation.INDEFINITE);
animation.play();
});
hostWrapper.setVisible(true); hostWrapper.setVisible(true);
} }
public void menuBtnPressed(){ // public void menuBtnPressed(){
hostWrapper.setVisible(false); // hostWrapper.setVisible(false);
parent.enterTitle(); // parent.enterTitle();
} // }
} }

@ -0,0 +1,53 @@
package visualiser.model;
import javafx.animation.Interpolator;
import javafx.animation.Transition;
import javafx.geometry.Rectangle2D;
import javafx.scene.image.ImageView;
import javafx.util.Duration;
/**
* Created by zwu18 on 29/08/17.
*/
public class SpriteAnimation extends Transition {
private final ImageView imageView;
private final int count;
private final int columns;
private final int offsetX;
private final int offsetY;
private final int width;
private final int height;
private int lastIndex;
public SpriteAnimation(
ImageView imageView,
Duration duration,
int count, int columns,
int offsetX, int offsetY,
int width, int height) {
this.imageView = imageView;
this.count = count;
this.columns = columns;
this.offsetX = offsetX;
this.offsetY = offsetY;
this.width = width;
this.height = height;
setCycleDuration(duration);
setInterpolator(Interpolator.LINEAR);
}
protected void interpolate(double k) {
final int index = Math.min((int) Math.floor(k * count), count - 1);
if (index != lastIndex) {
final int x = (index % columns) * width + offsetX;
final int y = (index / columns) * height + offsetY;
imageView.setViewport(new Rectangle2D(x, y, width, height));
lastIndex = index;
}
}
}

@ -1,40 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?> <!--<?xml version="1.0" encoding="UTF-8"?>-->
<?import javafx.scene.control.Button?> <!--<?import java.lang.*?>-->
<?import javafx.scene.control.Label?> <!--<?import javafx.scene.control.*?>-->
<?import javafx.scene.layout.*?> <!--<?import javafx.scene.text.*?>-->
<?import javafx.scene.text.Font?> <!--<?import javafx.scene.control.Button?>-->
<AnchorPane fx:id="hostWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" visible="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.HostController"> <!--<?import javafx.scene.control.Label?>-->
<children> <!--<?import javafx.scene.layout.*?>-->
<GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <!--<?import javafx.scene.text.Font?>-->
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <!--<AnchorPane fx:id="hostWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" visible="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">-->
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <!--<children>-->
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <!--<GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">-->
</columnConstraints> <!--<columnConstraints>-->
<rowConstraints> <!--<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />-->
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <!--<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />-->
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <!--<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />-->
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <!--</columnConstraints>-->
</rowConstraints> <!--<rowConstraints>-->
<children> <!--<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />-->
<Button fx:id="hostGameBtn" mnemonicParsing="false" onAction="#hostGamePressed" text="Start Game" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="2"> <!--<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />-->
<font> <!--<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />-->
<Font size="20.0" /> <!--</rowConstraints>-->
</font> <!--<children>-->
</Button> <!--<Button fx:id="hostGameBtn" mnemonicParsing="false" onAction="#hostGamePressed" text="Start Game" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="2">-->
<Label text="Address: 127.0.0.1" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="TOP"> <!--<font>-->
<font> <!--<Font size="20.0" />-->
<Font size="17.0" /> <!--</font>-->
</font> <!--</Button>-->
</Label> <!--<Label text="Address: 127.0.0.1" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="TOP">-->
<Label text="Port: 4942" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1"> <!--<font>-->
<font> <!--<Font size="17.0" />-->
<Font size="17.0" /> <!--</font>-->
</font> <!--</Label>-->
</Label> <!--<Label text="Port: 4942" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1">-->
<Button mnemonicParsing="false" onAction="#menuBtnPressed" text="Main Menu" GridPane.halignment="CENTER" /> <!--<font>-->
</children> <!--<Font size="17.0" />-->
</GridPane> <!--</font>-->
</children> <!--</Label>-->
</AnchorPane> <!--<Button mnemonicParsing="false" onAction="#menuBtnPressed" text="Main Menu" GridPane.halignment="CENTER" />-->
<!--</children>-->
<!--</GridPane>-->
<!--</children>-->
<!--</AnchorPane>-->

@ -7,7 +7,7 @@
<fx:include fx:id="start" source="start.fxml" /> <fx:include fx:id="start" source="start.fxml" />
<fx:include fx:id="connection" source="connect.fxml" /> <fx:include fx:id="connection" source="connect.fxml" />
<fx:include fx:id="finish" source="finish.fxml" /> <fx:include fx:id="finish" source="finish.fxml" />
<fx:include fx:id="host" source="hostgame.fxml" /> <fx:include fx:id="host" source="hostlobby.fxml" />
<fx:include fx:id="title" source="titleScreen.fxml" /> <fx:include fx:id="title" source="titleScreen.fxml" />
<fx:include fx:id="lobby" source="lobby.fxml" /> <fx:include fx:id="lobby" source="lobby.fxml" />
</children> </children>

@ -1,61 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?> <!--<?xml version="1.0" encoding="UTF-8"?>-->
<?import javafx.geometry.*?> <!--<?import javafx.geometry.*?>-->
<?import javafx.scene.control.*?> <!--<?import javafx.scene.control.*?>-->
<?import javafx.scene.layout.*?> <!--<?import javafx.scene.layout.*?>-->
<?import javafx.scene.text.Font?> <!--<?import javafx.scene.text.Font?>-->
<AnchorPane fx:id="connectionWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.ConnectionController"> <!--<AnchorPane fx:id="connectionWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.ConnectionController">-->
<children> <!--<children>-->
<GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <!--<GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">-->
<columnConstraints> <!--<columnConstraints>-->
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <!--<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />-->
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <!--<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />-->
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <!--<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />-->
</columnConstraints> <!--</columnConstraints>-->
<rowConstraints> <!--<rowConstraints>-->
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <!--<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />-->
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <!--<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />-->
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <!--<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />-->
</rowConstraints> <!--</rowConstraints>-->
<children> <!--<children>-->
<Button fx:id="hostGameTitleBtn" maxWidth="204.0" mnemonicParsing="false" text="Host Game" GridPane.halignment="LEFT" GridPane.rowIndex="1"> <!--<Button fx:id="hostGameTitleBtn" maxWidth="204.0" mnemonicParsing="false" text="Host Game" GridPane.halignment="LEFT" GridPane.rowIndex="1">-->
<font> <!--<font>-->
<Font size="20.0" /> <!--<Font size="20.0" />-->
</font> <!--</font>-->
<GridPane.margin> <!--<GridPane.margin>-->
<Insets left="50.0" /> <!--<Insets left="50.0" />-->
</GridPane.margin> <!--</GridPane.margin>-->
</Button> <!--</Button>-->
<Button fx:id="connectGameBtn" maxWidth="204.0" mnemonicParsing="false" text="Connect to Game" GridPane.columnIndex="2" GridPane.halignment="RIGHT" GridPane.rowIndex="1"> <!--<Button fx:id="connectGameBtn" maxWidth="204.0" mnemonicParsing="false" text="Connect to Game" GridPane.columnIndex="2" GridPane.halignment="RIGHT" GridPane.rowIndex="1">-->
<font> <!--<font>-->
<Font size="20.0" /> <!--<Font size="20.0" />-->
</font> <!--</font>-->
<GridPane.margin> <!--<GridPane.margin>-->
<Insets right="50.0" /> <!--<Insets right="50.0" />-->
</GridPane.margin> <!--</GridPane.margin>-->
</Button> <!--</Button>-->
<RadioButton fx:id="nightRadioBtn" mnemonicParsing="false" text="Night Mode" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowIndex="2"> <!--<RadioButton fx:id="nightRadioBtn" mnemonicParsing="false" text="Night Mode" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowIndex="2">-->
<padding> <!--<padding>-->
<Insets bottom="-50.0" /> <!--<Insets bottom="-50.0" />-->
</padding> <!--</padding>-->
<GridPane.margin> <!--<GridPane.margin>-->
<Insets left="80.0" /> <!--<Insets left="80.0" />-->
</GridPane.margin> <!--</GridPane.margin>-->
</RadioButton> <!--</RadioButton>-->
<RadioButton fx:id="dayRadioBtn" mnemonicParsing="false" text="Day Mode" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowIndex="2"> <!--<RadioButton fx:id="dayRadioBtn" mnemonicParsing="false" text="Day Mode" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowIndex="2">-->
<padding> <!--<padding>-->
<Insets top="-50.0" /> <!--<Insets top="-50.0" />-->
</padding> <!--</padding>-->
<GridPane.margin> <!--<GridPane.margin>-->
<Insets left="80.0" /> <!--<Insets left="80.0" />-->
</GridPane.margin> <!--</GridPane.margin>-->
</RadioButton> <!--</RadioButton>-->
<Label text="Game" textAlignment="CENTER" GridPane.columnIndex="1" GridPane.halignment="CENTER"> <!--<Label text="Game" textAlignment="CENTER" GridPane.columnIndex="1" GridPane.halignment="CENTER">-->
<font> <!--<font>-->
<Font size="60.0" /> <!--<Font size="60.0" />-->
</font> <!--</font>-->
</Label> <!--</Label>-->
</children> <!--</children>-->
</GridPane> <!--</GridPane>-->
</children> <!--</children>-->
</AnchorPane> <!--</AnchorPane>-->

Loading…
Cancel
Save