mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 02:44:50 +00:00
started working on the game selection layer
This commit is contained in:
@@ -3,13 +3,13 @@ package org.toop.app;
|
||||
import org.toop.app.layer.Layer;
|
||||
import org.toop.app.layer.layers.MainLayer;
|
||||
import org.toop.app.layer.layers.QuitLayer;
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.CssAsset;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.stage.Stage;
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.CssAsset;
|
||||
|
||||
public final class App extends Application {
|
||||
private static Stage stage;
|
||||
@@ -56,9 +56,14 @@ public final class App extends Application {
|
||||
|
||||
App.isQuitting = false;
|
||||
|
||||
push(new MainLayer());
|
||||
activate(new MainLayer());
|
||||
}
|
||||
|
||||
public static void activate(Layer layer) {
|
||||
popAll();
|
||||
push(layer);
|
||||
}
|
||||
|
||||
public static void push(Layer layer) {
|
||||
root.getChildren().addLast(layer.getLayer());
|
||||
}
|
||||
@@ -68,6 +73,14 @@ public final class App extends Application {
|
||||
isQuitting = false;
|
||||
}
|
||||
|
||||
public static void popAll() {
|
||||
final int childrenCount = root.getChildren().size();
|
||||
|
||||
for (int i = 0; i < childrenCount; i++) {
|
||||
root.getChildren().removeLast();
|
||||
}
|
||||
}
|
||||
|
||||
public static void quitPopup() {
|
||||
push(new QuitLayer());
|
||||
isQuitting = true;
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
package org.toop.app;
|
||||
|
||||
public enum GameType {
|
||||
TICTACTOE, REVERSI;
|
||||
TICTACTOE, OTHELLO;
|
||||
|
||||
public static String toName(GameType type) {
|
||||
return switch (type) {
|
||||
case TICTACTOE -> "Tic Tac Toe";
|
||||
case REVERSI -> "Reversi";
|
||||
case OTHELLO -> "Othello";
|
||||
};
|
||||
}
|
||||
|
||||
public static GameType toType(String name) {
|
||||
return switch (name) {
|
||||
case "Tic Tac Toe" -> TICTACTOE;
|
||||
case "Reversi" -> REVERSI;
|
||||
case "Reversi" -> OTHELLO;
|
||||
|
||||
default -> TICTACTOE;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.toop.app.layer.layers;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.GameType;
|
||||
import org.toop.app.layer.Container;
|
||||
import org.toop.app.layer.Layer;
|
||||
|
||||
@@ -10,11 +11,11 @@ public final class MainLayer extends Layer {
|
||||
public MainLayer() {
|
||||
super("main.css");
|
||||
|
||||
final Container gamesContainer = Container.create(Container.Type.VERTICAL, 10);
|
||||
gamesContainer.addButton("Tic Tac Toe", () -> {});
|
||||
gamesContainer.addButton("Othello", () -> {});
|
||||
final Container gamesContainer = Container.create(Container.Type.VERTICAL, 5);
|
||||
gamesContainer.addButton("Tic Tac Toe", () -> { App.activate(new SelectionLayer(GameType.TICTACTOE)); });
|
||||
gamesContainer.addButton("Othello", () -> { App.activate(new SelectionLayer(GameType.OTHELLO)); });
|
||||
|
||||
final Container controlContainer = Container.create(Container.Type.VERTICAL, 10);
|
||||
final Container controlContainer = Container.create(Container.Type.VERTICAL, 5);
|
||||
controlContainer.addButton("Credits", () -> {});
|
||||
controlContainer.addButton("Options", () -> {});
|
||||
controlContainer.addButton("Quit", () -> { App.quitPopup(); });
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package org.toop.app.layer.layers;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.layer.Container;
|
||||
import org.toop.app.layer.Layer;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
public final class QuitLayer extends Layer {
|
||||
public QuitLayer() {
|
||||
super("quit.css");
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.toop.app.layer.layers;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.GameType;
|
||||
import org.toop.app.layer.Container;
|
||||
import org.toop.app.layer.Layer;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
public class SelectionLayer extends Layer {
|
||||
protected SelectionLayer(GameType type) {
|
||||
super("selection.css");
|
||||
|
||||
final Container controlContainer = Container.create(Container.Type.VERTICAL, 5);
|
||||
controlContainer.addButton("Back", () -> { App.activate(new MainLayer()); });
|
||||
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2);
|
||||
}
|
||||
}
|
||||
3
app/src/main/resources/assets/style/selection.css
Normal file
3
app/src/main/resources/assets/style/selection.css
Normal file
@@ -0,0 +1,3 @@
|
||||
.background {
|
||||
-fx-background-color: linear-gradient(to bottom right, #21a7b2, #8f32b9);
|
||||
}
|
||||
Reference in New Issue
Block a user