You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
4.1 KiB

package visualiser.Controllers;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import mock.app.Event;
import mock.exceptions.EventConstructionException;
import visualiser.app.App;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Controller for the opening title window.
* Has two initial buttons for a user to decide how to play their game. Has a
* burger-boat and comic sans styling to allure and entice users into playing
* the game.
*/
public class TitleController extends Controller {
//FXML stuff
@FXML
Button btnJoin;
@FXML
AnchorPane titleWrapper;
@FXML
RadioButton dayModeRD;
@FXML
RadioButton nightModeRD;
@FXML
Label tutorialLabel;
@FXML
Pane menuPane;
@FXML
ImageView imgSun;
/**
* Method called when the 'host a game' button is pressed.
* Opens the next window allowing a user to host their own game.
* Currently used to run the RaceVision mock.
* @throws IOException if main has problems
*/
public void hostAGame() throws IOException {
titleWrapper.setVisible(false);
parent.setGameType(0);
parent.hostGame();
App.getStage().setResizable(true);
}
/**
* Switch the scene to the title page.
*/
public void enterTitle(){
titleWrapper.setVisible(true);
}
/**
* To be implemented at a later date- will open the next scene displaying
* games a player can join. Place holder method for now!
*/
public void joinAGame() {
titleWrapper.setVisible(false);
parent.enterLobby();
App.getStage().setResizable(true);
}
/**
* Switches the css of the program to day mode theme
*/
public void setDayMode(){
dayModeRD.getScene().getStylesheets().clear();
menuPane.getStylesheets().clear();
imgSun.setImage(new Image(getClass().getResource("/visualiser/images/sun.png").toExternalForm()));
dayModeRD.getScene().getStylesheets().add("/css/dayMode.css");
menuPane.setStyle("-fx-background-color: #6be6ff;");
nightModeRD.setSelected(false);
}
/**
* Switches the css of the program to night mode theme
*/
public void setNightMode(){
nightModeRD.getScene().getStylesheets().clear();
menuPane.getStylesheets().clear();
imgSun.setImage(new Image(getClass().getResource("/visualiser/images/sunsleep.png").toExternalForm()));
nightModeRD.getScene().getStylesheets().add("/css/nightMode.css");
menuPane.setStyle("-fx-background-color: #1f2c60;");
dayModeRD.setSelected(false);
}
@Override
public void initialize(URL location, ResourceBundle resources) {
tutorialLabel.setWrapText(true);
}
/**
* Called when control button is pressed. New pop up window displaying controls
*/
public void controlBtnPressed(){
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/visualiser/scenes/controls.fxml"));
Parent layout;
try {
layout = loader.load();
Scene scene = new Scene(layout);
Stage popupStage = new Stage();
popupStage.setResizable(false);
popupStage.setTitle("Game Controls");
popupStage.initModality(Modality.WINDOW_MODAL);
popupStage.setScene(scene);
popupStage.showAndWait();
} catch (Exception e){
e.printStackTrace();
}
}
public void tutorialStartPressed() throws IOException {
titleWrapper.setVisible(false);
System.out.println("Start the tutorial!");
parent.setGameType(2);
parent.beginGame();
}
}