Created new lobby menu. Working on animated background for menu.
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
package visualiser.Controllers;
|
||||
|
||||
import javafx.animation.Animation;
|
||||
import javafx.application.Platform;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.geometry.Rectangle2D;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.util.Duration;
|
||||
import mock.app.Event;
|
||||
import org.xml.sax.SAXException;
|
||||
import mock.exceptions.EventConstructionException;
|
||||
@@ -10,6 +16,7 @@ import shared.exceptions.InvalidBoatDataException;
|
||||
import shared.exceptions.InvalidRaceDataException;
|
||||
import shared.exceptions.InvalidRegattaDataException;
|
||||
import shared.exceptions.XMLReaderException;
|
||||
import visualiser.model.SpriteAnimation;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
@@ -25,12 +32,22 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
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 hostNameField;
|
||||
|
||||
@FXML
|
||||
TextField gameNameField;
|
||||
|
||||
@FXML
|
||||
TextField hostNameField;
|
||||
private ImageView imageView;
|
||||
|
||||
@FXML
|
||||
AnchorPane hostWrapper;
|
||||
@@ -81,12 +98,20 @@ public class HostController extends Controller {
|
||||
* Hosts a game.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
public void menuBtnPressed(){
|
||||
hostWrapper.setVisible(false);
|
||||
parent.enterTitle();
|
||||
}
|
||||
// public void menuBtnPressed(){
|
||||
// hostWrapper.setVisible(false);
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user