mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 02:44:50 +00:00
add: fullscreen option
This commit is contained in:
@@ -11,9 +11,12 @@ import javafx.scene.Scene;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
public final class App extends Application {
|
||||
private static Stage stage;
|
||||
private static StackPane root;
|
||||
private static Stack<Layer> stack;
|
||||
|
||||
private static int width;
|
||||
private static int height;
|
||||
@@ -50,6 +53,7 @@ public final class App extends Application {
|
||||
|
||||
App.stage = stage;
|
||||
App.root = root;
|
||||
App.stack = new Stack<>();
|
||||
|
||||
App.width = (int) stage.getWidth();
|
||||
App.height = (int) stage.getHeight();
|
||||
@@ -66,10 +70,13 @@ public final class App extends Application {
|
||||
|
||||
public static void push(Layer layer) {
|
||||
root.getChildren().addLast(layer.getLayer());
|
||||
stack.push(layer);
|
||||
}
|
||||
|
||||
public static void pop() {
|
||||
root.getChildren().removeLast();
|
||||
stack.pop();
|
||||
|
||||
isQuitting = false;
|
||||
}
|
||||
|
||||
@@ -79,6 +86,8 @@ public final class App extends Application {
|
||||
for (int i = 0; i < childrenCount; i++) {
|
||||
root.getChildren().removeLast();
|
||||
}
|
||||
|
||||
stack.removeAllElements();
|
||||
}
|
||||
|
||||
public static void quitPopup() {
|
||||
@@ -90,6 +99,21 @@ public final class App extends Application {
|
||||
stage.close();
|
||||
}
|
||||
|
||||
public static void reloadAll() {
|
||||
for (final Layer layer : stack) {
|
||||
layer.reload();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setFullscreen(boolean fullscreen) {
|
||||
stage.setFullScreen(fullscreen);
|
||||
|
||||
width = (int) stage.getWidth();
|
||||
height = (int) stage.getHeight();
|
||||
|
||||
reloadAll();
|
||||
}
|
||||
|
||||
public static int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public final class MainLayer extends Layer {
|
||||
App.quitPopup();
|
||||
});
|
||||
|
||||
addContainer(gamesContainer, Pos.TOP_LEFT, 2, 2, 25, 0);
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2, 25, 0);
|
||||
addContainer(gamesContainer, Pos.TOP_LEFT, 2, 2, 20, 0);
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2, 20, 0);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import org.toop.app.layer.containers.VerticalContainer;
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
public final class OptionsLayer extends Layer {
|
||||
private static boolean isWindowed = true;
|
||||
|
||||
OptionsLayer() {
|
||||
super("options.css");
|
||||
reload();
|
||||
@@ -17,12 +19,26 @@ public final class OptionsLayer extends Layer {
|
||||
public void reload() {
|
||||
popAll();
|
||||
|
||||
final Container mainContainer = new VerticalContainer(50);
|
||||
|
||||
mainContainer.addText("Options", false);
|
||||
|
||||
final Container optionsContainer = new VerticalContainer(5);
|
||||
|
||||
mainContainer.addContainer(optionsContainer, true);
|
||||
|
||||
optionsContainer.addToggle("Windowed", "Fullscreen", !isWindowed, (fullscreen) -> {
|
||||
isWindowed = !fullscreen;
|
||||
App.setFullscreen(fullscreen);
|
||||
});
|
||||
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
|
||||
controlContainer.addButton("Back", () -> {
|
||||
App.activate(new MainLayer());
|
||||
});
|
||||
|
||||
addContainer(mainContainer, Pos.CENTER, 0, 0, 30, 60);
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2, 0, 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user