-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChangeSceneManager.java
67 lines (59 loc) · 1.64 KB
/
ChangeSceneManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package org.snake.utils;
import java.io.IOException;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import lombok.Getter;
import lombok.Setter;
import org.snake.SnakeGame;
import org.snake.logger.MyLogger;
import org.snake.viewmodel.View;
/**
* Loader scenes class.
*/
public class ChangeSceneManager {
@Getter
private static Scene currentScene;
@Getter
@Setter
private static Stage primaryStage;
/**
* Loads scene from fxml.
*
* @param fxmlFile name of file in resources
*/
private static void loadScene(String fxmlFile) {
FXMLLoader loader = new FXMLLoader(SnakeGame.class.getResource(fxmlFile));
Scene scene;
try {
scene = new Scene(loader.load());
} catch (IOException e) {
MyLogger.err("Failed to load file in", ChangeSceneManager.class);
return;
}
primaryStage.setScene(scene);
primaryStage.show();
currentScene = scene;
View view = loader.getController();
view.startScene();
}
/**
* Method to change a current scene.
*
* @param type scene type
*/
public static void changeScene(SceneType type) {
switch (type) {
case GAME:
loadScene("game_space.fxml");
MyLogger.info("Game scene loaded", ChangeSceneManager.class);
break;
case MENU:
loadScene("menu.fxml");
MyLogger.info("Menu scene loaded", ChangeSceneManager.class);
break;
default:
break;
}
}
}