mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Fixed issue that when go back to start screen, start view doesn't fit
in to the decorator properly. - Moved start screen view initialization logic into ViewManager. - When go back to start screen view, a new stage within the start screen view will be initialized. #story[1245]
This commit is contained in:
@@ -67,38 +67,9 @@ public class App extends Application {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) throws Exception {
|
||||||
Parent root = FXMLLoader.load(getClass().getResource("/views/StartScreenView.fxml"));
|
ViewManager.getInstance().initialStartView(primaryStage);
|
||||||
primaryStage.setTitle("Party Parrots At Sea");
|
|
||||||
|
|
||||||
JFXDecorator decorator = new JFXDecorator(primaryStage, root,false, true, true);
|
|
||||||
decorator.setCustomMaximize(true);
|
|
||||||
decorator.applyCss();
|
|
||||||
decorator.getStylesheets()
|
|
||||||
.add(getClass().getResource("/css/master.css").toExternalForm());
|
|
||||||
|
|
||||||
ViewManager.getInstance().setDecorator(decorator);
|
|
||||||
|
|
||||||
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/PP.png")));
|
|
||||||
Scene scene = new Scene(decorator, 1200, 800);
|
|
||||||
primaryStage.setMinHeight(800);
|
|
||||||
primaryStage.setMinWidth(1200);
|
|
||||||
primaryStage.setScene(scene);
|
|
||||||
primaryStage.show();
|
|
||||||
|
|
||||||
primaryStage.setOnCloseRequest(e -> closeAll());
|
|
||||||
|
|
||||||
decorator.setOnCloseButtonAction(this::closeAll);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void closeAll(){
|
|
||||||
try {
|
|
||||||
ServerAdvertiser.getInstance().unregister();
|
|
||||||
} catch (IOException e1) {
|
|
||||||
logger.warn("Could not un-register game");
|
|
||||||
}
|
|
||||||
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import javafx.scene.control.Alert;
|
|||||||
import javafx.scene.control.Alert.AlertType;
|
import javafx.scene.control.Alert.AlertType;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
|
import seng302.gameServer.GameStages;
|
||||||
import seng302.gameServer.GameState;
|
import seng302.gameServer.GameState;
|
||||||
import seng302.gameServer.MainServerThread;
|
import seng302.gameServer.MainServerThread;
|
||||||
import seng302.gameServer.ServerDescription;
|
import seng302.gameServer.ServerDescription;
|
||||||
@@ -437,6 +438,7 @@ public class GameClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void stopGame() {
|
public void stopGame() {
|
||||||
|
GameState.setCurrentStage(GameStages.CANCELLED);
|
||||||
if (server != null) server.terminate();
|
if (server != null) server.terminate();
|
||||||
if (socketThread != null) socketThread.setSocketToClose();
|
if (socketThread != null) socketThread.setSocketToClose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,6 @@ public class LobbyController implements Initializable {
|
|||||||
|
|
||||||
public void leaveLobby() {
|
public void leaveLobby() {
|
||||||
// TODO: 10/07/17 wmu16 - Finish function!
|
// TODO: 10/07/17 wmu16 - Finish function!
|
||||||
GameState.setCurrentStage(GameStages.CANCELLED);
|
|
||||||
// for (LobbyController_old.LobbyCloseListener readyListener : lobbyListeners)
|
// for (LobbyController_old.LobbyCloseListener readyListener : lobbyListeners)
|
||||||
// readyListener.notify(LobbyController_old.CloseStatus.LEAVE);
|
// readyListener.notify(LobbyController_old.CloseStatus.LEAVE);
|
||||||
ViewManager.getInstance().getGameClient().stopGame();
|
ViewManager.getInstance().getGameClient().stopGame();
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
ServerListener.getInstance().setDelegate(this);
|
ServerListener.getInstance().setDelegate(this);
|
||||||
System.out.println("Setting DH");
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warn("Could not start Server Listener Delegate");
|
logger.warn("Could not start Server Listener Delegate");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,14 @@ import javafx.collections.ObservableList;
|
|||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.stage.Stage;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import seng302.gameServer.ServerAdvertiser;
|
||||||
import seng302.visualiser.GameClient;
|
import seng302.visualiser.GameClient;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -22,12 +26,13 @@ public class ViewManager {
|
|||||||
private static ViewManager instance;
|
private static ViewManager instance;
|
||||||
private GameClient gameClient;
|
private GameClient gameClient;
|
||||||
private JFXDecorator decorator;
|
private JFXDecorator decorator;
|
||||||
private HashMap<String, String> props; //TODO is this the best way to do this??
|
private HashMap<String, String> properties; //TODO is this the best way to do this??
|
||||||
private ObservableList<String> playerList;
|
private ObservableList<String> playerList;
|
||||||
private Logger logger = LoggerFactory.getLogger(ViewManager.class);
|
private Logger logger = LoggerFactory.getLogger(ViewManager.class);
|
||||||
|
private Stage stage;
|
||||||
|
|
||||||
private ViewManager(){
|
private ViewManager(){
|
||||||
props = new HashMap<>();
|
properties = new HashMap<>();
|
||||||
gameClient = new GameClient(decorator);
|
gameClient = new GameClient(decorator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,8 +50,43 @@ public class ViewManager {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDecorator(JFXDecorator decorator){
|
/**
|
||||||
|
* Initialize the start view in the given stage.
|
||||||
|
*/
|
||||||
|
public void initialStartView(Stage stage) throws Exception {
|
||||||
|
this.stage = stage;
|
||||||
|
Parent root = FXMLLoader.load(getClass().getResource("/views/StartScreenView.fxml"));
|
||||||
|
stage.setTitle("Party Parrots At Sea");
|
||||||
|
|
||||||
|
JFXDecorator decorator = new JFXDecorator(stage, root, false, true, true);
|
||||||
|
decorator.setCustomMaximize(true);
|
||||||
|
decorator.applyCss();
|
||||||
|
decorator.getStylesheets()
|
||||||
|
.add(getClass().getResource("/css/master.css").toExternalForm());
|
||||||
|
|
||||||
this.decorator = decorator;
|
this.decorator = decorator;
|
||||||
|
|
||||||
|
stage.getIcons().add(new Image(getClass().getResourceAsStream("/PP.png")));
|
||||||
|
Scene scene = new Scene(decorator, 1200, 800);
|
||||||
|
stage.setMinHeight(800);
|
||||||
|
stage.setMinWidth(1200);
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.show();
|
||||||
|
|
||||||
|
stage.setOnCloseRequest(e -> closeAll());
|
||||||
|
|
||||||
|
decorator.setOnCloseButtonAction(this::closeAll);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void closeAll() {
|
||||||
|
try {
|
||||||
|
ServerAdvertiser.getInstance().unregister();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
logger.warn("Could not un-register game");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JFXDecorator getDecorator() {
|
public JFXDecorator getDecorator() {
|
||||||
@@ -57,11 +97,15 @@ public class ViewManager {
|
|||||||
Platform.runLater(() -> decorator.setContent(scene));
|
Platform.runLater(() -> decorator.setContent(scene));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new stage and re-initialize the start view in the new stage.
|
||||||
|
*/
|
||||||
public void goToStartView() {
|
public void goToStartView() {
|
||||||
try {
|
try {
|
||||||
Parent root = FXMLLoader.load(getClass().getResource("/views/StartScreenView.fxml"));
|
this.stage.close();
|
||||||
this.setScene(root);
|
Stage stage = new Stage();
|
||||||
} catch (IOException e) {
|
initialStartView(stage);
|
||||||
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,11 +115,11 @@ public class ViewManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getProperty(String key){
|
public String getProperty(String key){
|
||||||
return props.get(key);
|
return properties.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProperty(String key, String val){
|
public void setProperty(String key, String val){
|
||||||
props.put(key, val);
|
properties.put(key, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlayerList(ObservableList<String> playerList) {
|
public void setPlayerList(ObservableList<String> playerList) {
|
||||||
|
|||||||
Reference in New Issue
Block a user