tiny portion of refactoring

This commit is contained in:
ramollia
2025-10-03 01:41:11 +02:00
parent 8ac76dd17f
commit 5e1d53e96b
3 changed files with 5 additions and 101 deletions

View File

@@ -60,7 +60,7 @@ public final class App extends Application {
final StackPane root = new StackPane(new MainMenu().getPane()); final StackPane root = new StackPane(new MainMenu().getPane());
final Scene scene = new Scene(root); final Scene scene = new Scene(root);
scene.getStylesheets().add(((CssAsset)ResourceManager.get("app.css")).getUrl()); scene.getStylesheets().add(ResourceManager.get(CssAsset.class, "app.css").getUrl());
stage.setTitle("pism"); stage.setTitle("pism");
stage.setMinWidth(1080); stage.setMinWidth(1080);
@@ -90,7 +90,9 @@ public final class App extends Application {
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).asyncPostEvent(); new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).asyncPostEvent();
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(0.1)).asyncPostEvent(); new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(0.1)).asyncPostEvent();
TicTacToeCanvas canvas = new TicTacToeCanvas(); // Todo: Temp Obviously
// Replace with game of life
final TicTacToeCanvas canvas = new TicTacToeCanvas();
root.getChildren().addLast(canvas.getCanvas()); root.getChildren().addLast(canvas.getCanvas());
} }

View File

@@ -1,99 +0,0 @@
package org.toop.app.menu.game;
import javafx.geometry.Pos;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import org.toop.app.App;
import org.toop.app.menu.MainMenu;
import org.toop.app.menu.Menu;
public abstract class GameMenu extends Menu {
protected final class Cell {
public float x;
public float y;
public float width;
public float height;
public Cell(float x, float y, float width, float height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public boolean check(float x, float y) {
return x >= this.x && y >= this.y && x <= this.x + width && y <= this.y + height;
}
}
protected final int size;
protected final Canvas canvas;
protected final GraphicsContext graphics;
protected final int rows;
protected final int columns;
protected final int gapSize;
protected final Cell[] cells;
protected GameMenu(int rows, int columns, int gapSize) {
final int size = Math.min(App.getWidth(), App.getHeight()) / 5 * 4;
final Canvas canvas = new Canvas(size, size);
final GraphicsContext graphics = canvas.getGraphicsContext2D();
this.size = size;
this.canvas = canvas;
this.graphics = graphics;
this.rows = rows;
this.columns = columns;
this.gapSize = gapSize;
cells = new Cell[rows * columns];
final float cellWidth = ((float)size - (rows - 1) * gapSize) / rows;
final float cellHeight = ((float)size - (columns - 1) * gapSize) / rows;
for (int y = 0; y < columns; y++) {
final float startY = y * cellHeight + y * gapSize;
for (int x = 0; x < rows; x++) {
final float startX = x * cellWidth + x * gapSize;
cells[y * rows + x] = new Cell(startX, startY, cellWidth, cellHeight);
}
}
final Region background = createBackground();
final Text player1 = createText("player_1", "Player 1");
final Text player2 = createText("player_2", "Player 2");
final HBox playersContainer = new HBox(100, player1, player2);
playersContainer.setAlignment(Pos.TOP_CENTER);
playersContainer.setPickOnBounds(false);
playersContainer.setTranslateY(50);
final Button hint = createButton("Hint", () -> {});
final Button back = createButton("Back", () -> { App.activate(new MainMenu()); });
final VBox controlContainer = new VBox(hint, back);
StackPane.setAlignment(controlContainer, Pos.BOTTOM_LEFT);
controlContainer.setPickOnBounds(false);
pane = new StackPane(background, canvas, playersContainer, controlContainer);
}
}

View File

@@ -8,6 +8,7 @@ public class AppContext {
public static void setCurrentLocale(Locale locale) { public static void setCurrentLocale(Locale locale) {
currentLocale = locale; currentLocale = locale;
} }
public static Locale getLocale() { public static Locale getLocale() {
return currentLocale; return currentLocale;
} }