Finished up lobby menu. Set split pane to not change size on resize. Disabled divider on split pane. Added quit button and start button (start only prints to terminal for now). Panes are now wrapped in an anchor pane to fix resizing issues. TODO: Will be working on making a nicer background animation.

main
David Wu 9 years ago
parent c63403d1de
commit 0621e1bdb1

@ -1,28 +1,18 @@
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.Alert;
import javafx.scene.control.TextField; import javafx.scene.control.ButtonType;
import javafx.scene.image.Image; import javafx.scene.control.SplitPane;
import javafx.scene.image.ImageView; 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 mock.exceptions.EventConstructionException; import mock.exceptions.EventConstructionException;
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;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import java.net.URL; import java.net.URL;
import java.util.Optional;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -32,13 +22,6 @@ 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 // @FXML
// TextField gameNameField; // TextField gameNameField;
@ -52,6 +35,15 @@ public class HostController extends Controller {
@FXML @FXML
AnchorPane hostWrapper; AnchorPane hostWrapper;
@FXML
AnchorPane imagePane;
@FXML
SplitPane splitPane;
@FXML
AnchorPane specPane;
private Event game; private Event game;
@ -98,20 +90,27 @@ public class HostController extends Controller {
* Hosts a game. * Hosts a game.
*/ */
public void hostGame(){ public void hostGame(){
splitPane.setResizableWithParent(specPane, false);
Platform.runLater(() -> { splitPane.lookupAll(".split-pane-divider").stream().forEach(div -> div.setMouseTransparent(true));
imageView.setImage(new Image("https://media.tenor.com/images/3059eba221c9537eff1cf84ff4eabffc/tenor.gif")); imageView.fitWidthProperty().bind(imagePane.widthProperty());
imageView.setViewport(new Rectangle2D(OFFSET_X, OFFSET_Y, WIDTH, HEIGHT)); imageView.fitHeightProperty().bind(imagePane.heightProperty());
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); Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
// parent.enterTitle(); alert.setTitle("Quitting race");
// } alert.setContentText("Do you wish to quit the race?");
alert.setHeaderText("You are about to quit the race");
Optional<ButtonType> result = alert.showAndWait();
if(result.get() == ButtonType.OK){
hostWrapper.setVisible(false);
parent.enterTitle();
}
}
public void startBtnPressed(){
System.out.println("Should start the race. This button is only visible for the host");
}
} }

@ -96,15 +96,15 @@ public class App extends Application {
); );
updateMessage("Preparing ingredients . . ."); updateMessage("Preparing ingredients . . .");
Thread.sleep(1000); Thread.sleep(200);
for (int i = 0; i < burgerFilling.size(); i++) { for (int i = 0; i < burgerFilling.size(); i++) {
Thread.sleep(800); Thread.sleep(100);
updateProgress(i + 1, burgerFilling.size()); updateProgress(i + 1, burgerFilling.size());
String nextFilling = burgerFilling.get(i); String nextFilling = burgerFilling.get(i);
addedFilling.add(nextFilling); addedFilling.add(nextFilling);
updateMessage("Adding the " + nextFilling + " . . ."); updateMessage("Adding the " + nextFilling + " . . .");
} }
Thread.sleep(400); Thread.sleep(100);
updateMessage("Burger's done!"); updateMessage("Burger's done!");
return addedFilling; return addedFilling;

@ -1,53 +0,0 @@
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;
}
}
}
Loading…
Cancel
Save