mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
Merge remote-tracking branch 'origin/UI' into UI
# Conflicts: # app/src/main/java/org/toop/app/GameType.java # app/src/main/java/org/toop/app/layer/layers/GameLayer.java
This commit is contained in:
@@ -1,23 +1,30 @@
|
||||
package org.toop.app;
|
||||
|
||||
import org.toop.app.canvas.GameCanvas;
|
||||
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 org.toop.framework.asset.resources.SettingsAsset;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.stage.Stage;
|
||||
import org.toop.local.AppSettings;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
public final class App extends Application {
|
||||
private static Stage stage;
|
||||
private static StackPane root;
|
||||
|
||||
private static int width;
|
||||
private static int height;
|
||||
private static Stack<Layer> stack;
|
||||
private static int height;
|
||||
private static int width;
|
||||
private static SettingsAsset settingsAsset;
|
||||
|
||||
private static boolean isQuitting;
|
||||
|
||||
@@ -27,12 +34,19 @@ public final class App extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
final StackPane root = new StackPane();
|
||||
|
||||
App.stage = stage;
|
||||
final StackPane root = new StackPane();
|
||||
App.root = root;
|
||||
App.stack = new Stack<>();
|
||||
|
||||
AppSettings settings = new AppSettings();
|
||||
settings.applySettings();
|
||||
|
||||
final Scene scene = new Scene(root);
|
||||
scene.getStylesheets().add(ResourceManager.get(CssAsset.class, "app.css").getUrl());
|
||||
scene.getStylesheets().add(ResourceManager.<CssAsset>get("app.css").getUrl());
|
||||
|
||||
stage.setTitle("pism");
|
||||
stage.setTitle(AppContext.getString("appTitle"));
|
||||
stage.setWidth(1080);
|
||||
stage.setHeight(720);
|
||||
|
||||
@@ -51,14 +65,16 @@ 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();
|
||||
App.width = (int) stage.getWidth();
|
||||
App.height = (int) stage.getHeight();
|
||||
|
||||
App.isQuitting = false;
|
||||
|
||||
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).asyncPostEvent();
|
||||
activate(new MainLayer());
|
||||
}
|
||||
}
|
||||
|
||||
public static void activate(Layer layer) {
|
||||
popAll();
|
||||
@@ -66,16 +82,15 @@ public final class App extends Application {
|
||||
}
|
||||
|
||||
public static void push(Layer layer) {
|
||||
root.getChildren().addLast(layer.getLayer());
|
||||
root.getChildren().addLast(layer.getLayer());
|
||||
stack.push(layer);
|
||||
}
|
||||
|
||||
public static void pop() {
|
||||
root.getChildren().removeLast();
|
||||
isQuitting = false;
|
||||
}
|
||||
stack.pop();
|
||||
|
||||
public static void pushCanvas(GameCanvas canvas) {
|
||||
root.getChildren().addLast(canvas.getCanvas());
|
||||
isQuitting = false;
|
||||
}
|
||||
|
||||
public static void popAll() {
|
||||
@@ -84,6 +99,8 @@ public final class App extends Application {
|
||||
for (int i = 0; i < childrenCount; i++) {
|
||||
root.getChildren().removeLast();
|
||||
}
|
||||
|
||||
stack.removeAllElements();
|
||||
}
|
||||
|
||||
public static void quitPopup() {
|
||||
@@ -95,6 +112,28 @@ public final class App extends Application {
|
||||
stage.close();
|
||||
}
|
||||
|
||||
public static int getWidth() { return width; }
|
||||
public static int getHeight() { return height; }
|
||||
public static void reloadAll() {
|
||||
stage.setTitle(AppContext.getString("appTitle"));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static int getHeight() {
|
||||
return height;
|
||||
}
|
||||
}
|
||||
5
app/src/main/java/org/toop/app/GameInformation.java
Normal file
5
app/src/main/java/org/toop/app/GameInformation.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package org.toop.app;
|
||||
|
||||
public record GameInformation(String[] playerName, boolean[] isPlayerHuman, int[] computerDifficulty,
|
||||
boolean isConnectionLocal, String serverIP, String serverPort) {
|
||||
}
|
||||
@@ -3,31 +3,49 @@ package org.toop.app.canvas;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class GameCanvas {
|
||||
protected record Cell(float x, float y, float width, float height) {}
|
||||
|
||||
protected final int width;
|
||||
protected final int height;
|
||||
protected record Cell(float x, float y, float width, float height) {
|
||||
}
|
||||
|
||||
protected final Canvas canvas;
|
||||
protected final GraphicsContext graphics;
|
||||
|
||||
protected final Color color;
|
||||
|
||||
protected int width;
|
||||
protected int height;
|
||||
|
||||
protected final int rows;
|
||||
protected final int columns;
|
||||
|
||||
protected final int gapSize;
|
||||
protected final boolean edges;
|
||||
|
||||
protected final Cell[] cells;
|
||||
|
||||
protected GameCanvas(int width, int height, int rows, int columns, int gapSize) {
|
||||
final Canvas canvas = new Canvas(width, height);
|
||||
final GraphicsContext graphics = canvas.getGraphicsContext2D();
|
||||
protected GameCanvas(Color color, int width, int height, int rows, int columns, int gapSize, boolean edges, Consumer<Integer> onCellClicked) {
|
||||
canvas = new Canvas(width, height);
|
||||
graphics = canvas.getGraphicsContext2D();
|
||||
|
||||
final Cell[] cells = new Cell[rows * columns];
|
||||
this.color = color;
|
||||
|
||||
final float cellWidth = ((float)width - (rows - 1) * gapSize) / rows;
|
||||
final float cellHeight = ((float)height - (columns - 1) * gapSize) / columns;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
this.rows = rows;
|
||||
this.columns = columns;
|
||||
|
||||
this.gapSize = gapSize;
|
||||
this.edges = edges;
|
||||
|
||||
cells = new Cell[rows * columns];
|
||||
|
||||
final float cellWidth = ((float) width - (rows - 1) * gapSize) / rows;
|
||||
final float cellHeight = ((float) height - (columns - 1) * gapSize) / columns;
|
||||
|
||||
for (int y = 0; y < columns; y++) {
|
||||
final float startY = y * cellHeight + y * gapSize;
|
||||
@@ -39,39 +57,67 @@ public abstract class GameCanvas {
|
||||
}
|
||||
|
||||
canvas.setOnMouseClicked(event -> {
|
||||
final MouseButton button = event.getButton();
|
||||
|
||||
if (button != MouseButton.PRIMARY && button != MouseButton.SECONDARY) {
|
||||
if (event.getButton() != MouseButton.PRIMARY) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int column = (int)((event.getX() / width) * rows);
|
||||
final int row = (int)((event.getY() / height) * columns);
|
||||
final int column = (int) ((event.getX() / width) * rows);
|
||||
final int row = (int) ((event.getY() / height) * columns);
|
||||
|
||||
event.consume();
|
||||
onCellClicked(row * rows + column, button == MouseButton.PRIMARY);
|
||||
onCellClicked.accept(row * rows + column);
|
||||
});
|
||||
|
||||
render();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
graphics.clearRect(0, 0, width, height);
|
||||
}
|
||||
|
||||
public void render() {
|
||||
graphics.setFill(color);
|
||||
|
||||
for (int x = 1; x < rows; x++) {
|
||||
graphics.fillRect(cells[x].x() - gapSize, 0, gapSize, height);
|
||||
}
|
||||
|
||||
for (int y = 1; y < columns; y++) {
|
||||
graphics.fillRect(0, cells[y * rows].y() - gapSize, width, gapSize);
|
||||
}
|
||||
|
||||
if (edges) {
|
||||
graphics.fillRect(-gapSize, 0, gapSize, height);
|
||||
graphics.fillRect(0, -gapSize, width, gapSize);
|
||||
|
||||
graphics.fillRect(width - gapSize, 0, gapSize, height);
|
||||
graphics.fillRect(0, height - gapSize, width, gapSize);
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Color color, int cell) {
|
||||
final float x = cells[cell].x() + gapSize;
|
||||
final float y = cells[cell].y() + gapSize;
|
||||
|
||||
final float width = cells[cell].width() - gapSize * 2;
|
||||
final float height = cells[cell].height() - gapSize * 2;
|
||||
|
||||
graphics.setFill(color);
|
||||
graphics.fillRect(x, y, width, height);
|
||||
}
|
||||
|
||||
public void resize(int width, int height) {
|
||||
canvas.setWidth(width);
|
||||
canvas.setHeight(height);
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
this.canvas = canvas;
|
||||
this.graphics = graphics;
|
||||
|
||||
this.rows = rows;
|
||||
this.columns = columns;
|
||||
|
||||
this.gapSize = gapSize;
|
||||
|
||||
this.cells = cells;
|
||||
clear();
|
||||
render();
|
||||
}
|
||||
|
||||
protected void clearCell(int cell) {
|
||||
assert cell >= 0 && cell < cells.length;
|
||||
graphics.clearRect(cells[cell].x(), cells[cell].y(), cells[cell].width(), cells[cell].height());
|
||||
public Canvas getCanvas() {
|
||||
return canvas;
|
||||
}
|
||||
|
||||
protected abstract void onCellClicked(int cell, boolean primary);
|
||||
|
||||
public Canvas getCanvas() { return canvas; }
|
||||
}
|
||||
@@ -1,30 +1,16 @@
|
||||
package org.toop.app.canvas;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
import org.toop.app.App;
|
||||
import org.toop.game.Game;
|
||||
import org.toop.game.tictactoe.TicTacToe;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class TicTacToeCanvas extends GameCanvas {
|
||||
private final TicTacToe game;
|
||||
|
||||
public TicTacToeCanvas() {
|
||||
super(App.getHeight(), App.getHeight(), 3, 3, 10);
|
||||
game = new TicTacToe();
|
||||
|
||||
graphics.setFill(Color.CYAN);
|
||||
|
||||
for (int x = 1; x < rows; x++) {
|
||||
graphics.fillRect(cells[x].x() - gapSize, 0, gapSize, height);
|
||||
}
|
||||
|
||||
for (int y = 1; y < columns; y++) {
|
||||
graphics.fillRect(0, cells[y * rows].y() - gapSize, width, gapSize);
|
||||
}
|
||||
public TicTacToeCanvas(Color color, int width, int height, Consumer<Integer> onCellClicked) {
|
||||
super(color, width, height, 3, 3, 10, false, onCellClicked);
|
||||
}
|
||||
|
||||
public void placeX(int cell) {
|
||||
graphics.setStroke(Color.ORANGERED);
|
||||
public void drawX(Color color, int cell) {
|
||||
graphics.setStroke(color);
|
||||
graphics.setLineWidth(gapSize);
|
||||
|
||||
final float x = cells[cell].x() + gapSize;
|
||||
@@ -37,8 +23,8 @@ public class TicTacToeCanvas extends GameCanvas {
|
||||
graphics.strokeLine(x + width, y, x, y + height);
|
||||
}
|
||||
|
||||
public void placeO(int cell) {
|
||||
graphics.setStroke(Color.DEEPSKYBLUE);
|
||||
public void drawO(Color color, int cell) {
|
||||
graphics.setStroke(color);
|
||||
graphics.setLineWidth(gapSize);
|
||||
|
||||
final float x = cells[cell].x() + gapSize;
|
||||
@@ -49,33 +35,4 @@ public class TicTacToeCanvas extends GameCanvas {
|
||||
|
||||
graphics.strokeOval(x, y, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCellClicked(int cell, boolean primary) {
|
||||
for (final Game.Move move : game.getLegalMoves()) {
|
||||
if (move.position() == cell) {
|
||||
if (move.value() == 'X') {
|
||||
placeX(cell);
|
||||
} else {
|
||||
placeO(cell);
|
||||
}
|
||||
|
||||
final Game.State state = game.play(move);
|
||||
|
||||
if (state == Game.State.WIN) {
|
||||
for (int i = 0; i < game.board.length; i++) {
|
||||
if (game.board[i] != move.value()) {
|
||||
clearCell(i);
|
||||
}
|
||||
}
|
||||
|
||||
graphics.setFill(Color.GREEN);
|
||||
graphics.fillRect(cells[4].x(), cells[4].y(), cells[4].width(), cells[4].height());
|
||||
} else if (state == Game.State.DRAW) {
|
||||
graphics.setFill(Color.DARKORANGE);
|
||||
graphics.fillRect(cells[4].x(), cells[4].y(), cells[4].width(), cells[4].height());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,5 @@ import org.toop.framework.eventbus.events.EventWithoutSnowflake;
|
||||
import org.toop.framework.eventbus.events.EventsBase;
|
||||
|
||||
public class AppEvents extends EventsBase {
|
||||
public record OnNodeHover() implements EventWithoutSnowflake {}
|
||||
|
||||
public record OnNodeClick() implements EventWithoutSnowflake {}
|
||||
|
||||
public record OnLanguageChange(String language) implements EventWithoutSnowflake {}
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
package org.toop.app.layer;
|
||||
|
||||
import org.toop.app.events.AppEvents;
|
||||
import org.toop.framework.eventbus.GlobalEventBus;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.geometry.Orientation;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.scene.text.TextFlow;
|
||||
@@ -18,53 +19,51 @@ public abstract class Container {
|
||||
public abstract Region getContainer();
|
||||
|
||||
public abstract void addNode(Node node);
|
||||
|
||||
public abstract void addContainer(Container container, boolean fill);
|
||||
|
||||
public void addText(String cssClass, String x, boolean wrap) {
|
||||
public Text addText(String cssClass, String x, boolean wrap) {
|
||||
final Text element = new Text(x);
|
||||
element.getStyleClass().add(cssClass);
|
||||
|
||||
if (wrap) {
|
||||
addNode(new TextFlow(element));
|
||||
} else { addNode(element); }
|
||||
} else {
|
||||
addNode(element);
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public void addText(String x, boolean wrap) {
|
||||
addText("text", x, wrap);
|
||||
public Text addText(String x, boolean wrap) {
|
||||
return addText("text", x, wrap);
|
||||
}
|
||||
|
||||
public void addButton(String cssClass, String x, Runnable runnable) {
|
||||
public Label addButton(String cssClass, String x, Runnable runnable) {
|
||||
final Label element = new Label(x);
|
||||
element.getStyleClass().add(cssClass);
|
||||
|
||||
element.setOnMouseEntered(_ -> {
|
||||
GlobalEventBus.post(new AppEvents.OnNodeHover());
|
||||
});
|
||||
|
||||
element.setOnMouseClicked(_ -> {
|
||||
GlobalEventBus.post(new AppEvents.OnNodeClick());
|
||||
new EventFlow().addPostEvent(new AudioEvents.ClickButton()).asyncPostEvent();
|
||||
runnable.run();
|
||||
});
|
||||
|
||||
addNode(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
public void addButton(String x, Runnable runnable) {
|
||||
addButton("button", x, runnable);
|
||||
public Label addButton(String x, Runnable runnable) {
|
||||
return addButton("button", x, runnable);
|
||||
}
|
||||
|
||||
public void addToggle(String cssClass, String x1, String x2, boolean toggled, Consumer<Boolean> consumer) {
|
||||
final Label element = new Label(toggled? x2 : x1);
|
||||
public Label addToggle(String cssClass, String x1, String x2, boolean toggled, Consumer<Boolean> consumer) {
|
||||
final Label element = new Label(toggled ? x2 : x1);
|
||||
element.getStyleClass().add(cssClass);
|
||||
|
||||
final BooleanProperty checked = new SimpleBooleanProperty(toggled);
|
||||
|
||||
element.setOnMouseEntered(_ -> {
|
||||
GlobalEventBus.post(new AppEvents.OnNodeHover());
|
||||
});
|
||||
|
||||
element.setOnMouseClicked(_ -> {
|
||||
GlobalEventBus.post(new AppEvents.OnNodeClick());
|
||||
new EventFlow().addPostEvent(new AudioEvents.ClickButton()).asyncPostEvent();
|
||||
checked.set(!checked.get());
|
||||
|
||||
if (checked.get()) {
|
||||
@@ -77,18 +76,46 @@ public abstract class Container {
|
||||
});
|
||||
|
||||
addNode(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
public void addToggle(String x1, String x2, boolean toggled, Consumer<Boolean> consumer) {
|
||||
addToggle("toggle", x1, x2, toggled, consumer);
|
||||
public Label addToggle(String x1, String x2, boolean toggled, Consumer<Boolean> consumer) {
|
||||
return addToggle("toggle", x1, x2, toggled, consumer);
|
||||
}
|
||||
|
||||
public void addInput(String cssClass, String input, Consumer<String> consumer) {
|
||||
public Slider addSlider(String cssClass, int max, int initial, Consumer<Integer> consumer) {
|
||||
final Slider element = new Slider(0, max, initial);
|
||||
element.getStyleClass().add(cssClass);
|
||||
|
||||
element.setMinorTickCount(0);
|
||||
element.setMajorTickUnit(1);
|
||||
element.setBlockIncrement(1);
|
||||
|
||||
element.setSnapToTicks(true);
|
||||
element.setShowTickLabels(true);
|
||||
|
||||
element.setOnMouseClicked(_ -> {
|
||||
new EventFlow().addPostEvent(new AudioEvents.ClickButton()).asyncPostEvent();
|
||||
});
|
||||
|
||||
element.valueProperty().addListener((_, _, newValue) -> {
|
||||
consumer.accept(newValue.intValue());
|
||||
});
|
||||
|
||||
addNode(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
public Slider addSlider(int max, int initial, Consumer<Integer> consumer) {
|
||||
return addSlider("slider", max, initial, consumer);
|
||||
}
|
||||
|
||||
public TextField addInput(String cssClass, String input, Consumer<String> consumer) {
|
||||
final TextField element = new TextField(input);
|
||||
element.getStyleClass().add(cssClass);
|
||||
|
||||
element.setOnMouseEntered(_ -> {
|
||||
GlobalEventBus.post(new AppEvents.OnNodeHover());
|
||||
element.setOnMouseClicked(_ -> {
|
||||
new EventFlow().addPostEvent(new AudioEvents.ClickButton()).asyncPostEvent();
|
||||
});
|
||||
|
||||
element.textProperty().addListener((_, _, newValue) -> {
|
||||
@@ -96,9 +123,43 @@ public abstract class Container {
|
||||
});
|
||||
|
||||
addNode(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
public void addInput(String input, Consumer<String> consumer) {
|
||||
addInput("input", input, consumer);
|
||||
public TextField addInput(String input, Consumer<String> consumer) {
|
||||
return addInput("input", input, consumer);
|
||||
}
|
||||
|
||||
public <T> ChoiceBox<T> addChoiceBox(String cssClass, Consumer<T> consumer) {
|
||||
final ChoiceBox<T> element = new ChoiceBox<>();
|
||||
element.getStyleClass().add(cssClass);
|
||||
|
||||
element.setOnMouseClicked(_ -> {
|
||||
new EventFlow().addPostEvent(new AudioEvents.ClickButton()).asyncPostEvent();
|
||||
});
|
||||
|
||||
element.valueProperty().addListener((_, _, newValue) -> {
|
||||
consumer.accept(newValue);
|
||||
});
|
||||
|
||||
addNode(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
public <T> ChoiceBox<T> addChoiceBox(Consumer<T> consumer) {
|
||||
return addChoiceBox("choicebox", consumer);
|
||||
}
|
||||
|
||||
public Separator addSeparator(String cssClass, boolean horizontal) {
|
||||
final Separator element = new Separator(horizontal ? Orientation.HORIZONTAL : Orientation.VERTICAL);
|
||||
element.getStyleClass().add(cssClass);
|
||||
element.setMinSize(50, 50);
|
||||
|
||||
addNode(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
public Separator addSeparator(boolean horizontal) {
|
||||
return addSeparator("separator", horizontal);
|
||||
}
|
||||
}
|
||||
@@ -13,22 +13,17 @@ public abstract class Layer {
|
||||
protected StackPane layer;
|
||||
protected Region background;
|
||||
|
||||
protected Layer(String cssFile, String backgroundCssClass) {
|
||||
protected Layer(String cssFile) {
|
||||
layer = new StackPane();
|
||||
layer.setPickOnBounds(false);
|
||||
layer.getStylesheets().add(ResourceManager.get(CssAsset.class, cssFile).getUrl());
|
||||
layer.getStylesheets().add(ResourceManager.<CssAsset>get(cssFile).getUrl());
|
||||
|
||||
background = new Region();
|
||||
background.getStyleClass().add("background");
|
||||
background.setPrefSize(Double.MAX_VALUE, Double.MAX_VALUE);
|
||||
background.getStyleClass().add(backgroundCssClass);
|
||||
|
||||
layer.getChildren().addLast(background);
|
||||
}
|
||||
|
||||
protected Layer(String cssFile) {
|
||||
this(cssFile, "background");
|
||||
}
|
||||
|
||||
protected void addContainer(Container container, Pos position, int xOffset, int yOffset, int widthPercent, int heightPercent) {
|
||||
StackPane.setAlignment(container.getContainer(), position);
|
||||
|
||||
@@ -37,11 +32,15 @@ public abstract class Layer {
|
||||
|
||||
if (widthPercent > 0) {
|
||||
container.getContainer().setMaxWidth(widthPercent * widthUnit);
|
||||
} else { container.getContainer().setMaxWidth(Region.USE_PREF_SIZE); }
|
||||
} else {
|
||||
container.getContainer().setMaxWidth(Region.USE_PREF_SIZE);
|
||||
}
|
||||
|
||||
if (heightPercent > 0) {
|
||||
container.getContainer().setMaxHeight(heightPercent * heightUnit);
|
||||
} else { container.getContainer().setMaxHeight(Region.USE_PREF_SIZE); }
|
||||
} else {
|
||||
container.getContainer().setMaxHeight(Region.USE_PREF_SIZE);
|
||||
}
|
||||
|
||||
container.getContainer().setTranslateX(xOffset * widthUnit);
|
||||
container.getContainer().setTranslateY(yOffset * heightUnit);
|
||||
@@ -49,20 +48,12 @@ public abstract class Layer {
|
||||
layer.getChildren().addLast(container.getContainer());
|
||||
}
|
||||
|
||||
protected void addCanvas(GameCanvas canvas, Pos position, int xOffset, int yOffset, int widthPercent, int heightPercent) {
|
||||
protected void addGameCanvas(GameCanvas canvas, Pos position, int xOffset, int yOffset) {
|
||||
StackPane.setAlignment(canvas.getCanvas(), position);
|
||||
|
||||
final double widthUnit = App.getWidth() / 100.0;
|
||||
final double heightUnit = App.getHeight() / 100.0;
|
||||
|
||||
if (widthPercent > 0) {
|
||||
canvas.getCanvas().setWidth(widthPercent * widthUnit);
|
||||
} else { canvas.getCanvas().setWidth(Region.USE_PREF_SIZE); }
|
||||
|
||||
if (heightPercent > 0) {
|
||||
canvas.getCanvas().setHeight(heightPercent * heightUnit);
|
||||
} else { canvas.getCanvas().setHeight(Region.USE_PREF_SIZE); }
|
||||
|
||||
canvas.getCanvas().setTranslateX(xOffset * widthUnit);
|
||||
canvas.getCanvas().setTranslateY(yOffset * heightUnit);
|
||||
|
||||
@@ -85,8 +76,9 @@ public abstract class Layer {
|
||||
}
|
||||
}
|
||||
|
||||
public StackPane getLayer() { return layer; }
|
||||
public Region getBackground() { return background; }
|
||||
public StackPane getLayer() {
|
||||
return layer;
|
||||
}
|
||||
|
||||
public abstract void reload();
|
||||
}
|
||||
@@ -21,7 +21,9 @@ public final class HorizontalContainer extends Container {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Region getContainer() { return container; }
|
||||
public Region getContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNode(Node node) {
|
||||
@@ -51,7 +53,7 @@ public final class HorizontalContainer extends Container {
|
||||
|
||||
for (final Node child : children) {
|
||||
if (child instanceof Region) {
|
||||
((Region)child).setPrefWidth(widthPerChild);
|
||||
((Region) child).setPrefWidth(widthPerChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ public final class VerticalContainer extends Container {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Region getContainer() { return container; }
|
||||
public Region getContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNode(Node node) {
|
||||
@@ -51,7 +53,7 @@ public final class VerticalContainer extends Container {
|
||||
|
||||
for (final Node child : children) {
|
||||
if (child instanceof Region) {
|
||||
((Region)child).setPrefHeight(heightPerChild);
|
||||
((Region) child).setPrefHeight(heightPerChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package org.toop.app.layer.layers;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.layer.Container;
|
||||
import org.toop.app.layer.Layer;
|
||||
import org.toop.app.layer.containers.HorizontalContainer;
|
||||
import org.toop.app.layer.containers.VerticalContainer;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.animation.PauseTransition;
|
||||
import javafx.animation.TranslateTransition;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.util.Duration;
|
||||
|
||||
public final class CreditsLayer extends Layer {
|
||||
private final int lineHeight = 100;
|
||||
|
||||
CreditsLayer() {
|
||||
super("credits.css");
|
||||
reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
|
||||
final String[] credits = {
|
||||
AppContext.getString("scrumMaster") + ": Stef",
|
||||
AppContext.getString("productOwner") + ": Omar",
|
||||
AppContext.getString("mergeCommander") + ": Bas",
|
||||
AppContext.getString("localization") + ": Ticho",
|
||||
AppContext.getString("ai") + ": Michiel",
|
||||
AppContext.getString("developers") + ": Michiel, Bas, Stef, Omar, Ticho",
|
||||
AppContext.getString("moralSupport") + ": Wesley",
|
||||
AppContext.getString("opengl") + ": Omar"
|
||||
};
|
||||
|
||||
final Container creditsContainer = new HorizontalContainer(0);
|
||||
|
||||
final Container animatedContainer = new VerticalContainer("animated_credits_container", lineHeight);
|
||||
creditsContainer.addContainer(animatedContainer, true);
|
||||
|
||||
for (final String credit : credits) {
|
||||
animatedContainer.addText("credit-text", credit, false);
|
||||
}
|
||||
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
controlContainer.addButton(AppContext.getString("back"), () -> {
|
||||
App.activate(new MainLayer());
|
||||
});
|
||||
|
||||
addContainer(creditsContainer, Pos.CENTER, 0, 0, 50, 100);
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2, 0, 0);
|
||||
|
||||
playCredits(animatedContainer, App.getHeight());
|
||||
}
|
||||
|
||||
private void playCredits(Container container, double sceneLength) {
|
||||
container.getContainer().setTranslateY(-sceneLength);
|
||||
|
||||
final TranslateTransition scrollCredits = new TranslateTransition(Duration.seconds(20), container.getContainer());
|
||||
scrollCredits.setFromY(-sceneLength - lineHeight);
|
||||
scrollCredits.setToY(sceneLength + lineHeight);
|
||||
|
||||
scrollCredits.setOnFinished(_ -> {
|
||||
final PauseTransition pauseCredits = new PauseTransition(Duration.seconds(3));
|
||||
pauseCredits.setOnFinished(_ -> playCredits(container, sceneLength));
|
||||
pauseCredits.play();
|
||||
});
|
||||
|
||||
scrollCredits.play();
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
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 org.toop.app.layer.containers.VerticalContainer;
|
||||
import org.toop.game.othello.Othello;
|
||||
import org.toop.game.tictactoe.TicTacToe;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
@@ -19,15 +21,30 @@ public final class MainLayer extends Layer {
|
||||
popAll();
|
||||
|
||||
final Container gamesContainer = new VerticalContainer(5);
|
||||
gamesContainer.addButton("Tic Tac Toe", () -> { App.activate(new MultiplayerLayer(GameType.TICTACTOE)); });
|
||||
gamesContainer.addButton("Othello", () -> { App.activate(new MultiplayerLayer(GameType.OTHELLO)); });
|
||||
|
||||
gamesContainer.addButton(AppContext.getString("tictactoe"), () -> {
|
||||
App.activate(new MultiplayerLayer());
|
||||
});
|
||||
|
||||
gamesContainer.addButton(AppContext.getString("othello"), () -> {
|
||||
App.activate(new MultiplayerLayer());
|
||||
});
|
||||
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
controlContainer.addButton("Credits", () -> {});
|
||||
controlContainer.addButton("Options", () -> {});
|
||||
controlContainer.addButton("Quit", () -> { App.quitPopup(); });
|
||||
|
||||
addContainer(gamesContainer, Pos.TOP_LEFT, 2, 2, 25, 0);
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2, 25, 0);
|
||||
controlContainer.addButton(AppContext.getString("credits"), () -> {
|
||||
App.activate(new CreditsLayer());
|
||||
});
|
||||
|
||||
controlContainer.addButton(AppContext.getString("options"), () -> {
|
||||
App.activate(new OptionsLayer());
|
||||
});
|
||||
|
||||
controlContainer.addButton(AppContext.getString("quit"), () -> {
|
||||
App.quitPopup();
|
||||
});
|
||||
|
||||
addContainer(gamesContainer, Pos.TOP_LEFT, 2, 2, 20, 0);
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2, 20, 0);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,31 @@
|
||||
package org.toop.app.layer.layers;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.GameType;
|
||||
import org.toop.app.canvas.TicTacToeCanvas;
|
||||
import org.toop.app.GameInformation;
|
||||
import org.toop.app.layer.Container;
|
||||
import org.toop.app.layer.Layer;
|
||||
import org.toop.app.layer.containers.HorizontalContainer;
|
||||
import org.toop.app.layer.containers.VerticalContainer;
|
||||
import org.toop.app.layer.layers.game.TicTacToeLayer;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
public class MultiplayerLayer extends Layer {
|
||||
boolean isConnectionLocal = true;
|
||||
public final class MultiplayerLayer extends Layer {
|
||||
private boolean isConnectionLocal = true;
|
||||
|
||||
boolean isPlayer1Human = true;
|
||||
boolean isPlayer2Human = true;
|
||||
private boolean isPlayer1Human = true;
|
||||
private String player1Name = "";
|
||||
private int computer1Difficulty = 0;
|
||||
|
||||
protected MultiplayerLayer(GameType type) {
|
||||
private boolean isPlayer2Human = true;
|
||||
private String player2Name = "";
|
||||
private int computer2Difficulty = 0;
|
||||
|
||||
private String serverIP = "";
|
||||
private String serverPort = "";
|
||||
|
||||
public MultiplayerLayer() {
|
||||
super("multiplayer.css");
|
||||
reload();
|
||||
}
|
||||
@@ -26,64 +35,87 @@ public class MultiplayerLayer extends Layer {
|
||||
popAll();
|
||||
|
||||
final Container mainContainer = new VerticalContainer(5);
|
||||
mainContainer.addToggle("Local", "Server", !isConnectionLocal, (server) -> {
|
||||
|
||||
mainContainer.addToggle(AppContext.getString("local"), AppContext.getString("server"), !isConnectionLocal, (server) -> {
|
||||
isConnectionLocal = !server;
|
||||
reload();
|
||||
});
|
||||
|
||||
final Container playersContainer = new HorizontalContainer(50);
|
||||
|
||||
mainContainer.addContainer(playersContainer, true);
|
||||
|
||||
final Container player1Container = new VerticalContainer("player_container", 5);
|
||||
|
||||
playersContainer.addContainer(player1Container, true);
|
||||
|
||||
playersContainer.addText("VS", false);
|
||||
|
||||
final Container player2Container = new VerticalContainer("player_container", 5);
|
||||
|
||||
playersContainer.addContainer(player2Container, true);
|
||||
|
||||
if (isConnectionLocal) {
|
||||
mainContainer.addButton("Start", () -> {});
|
||||
} else {
|
||||
mainContainer.addButton("Connnect", () -> { App.activate(new GameLayer()); });
|
||||
}
|
||||
mainContainer.addButton(isConnectionLocal? AppContext.getString("start") : AppContext.getString("connect"), () -> {
|
||||
App.activate(new TicTacToeLayer(new GameInformation(
|
||||
new String[] { player1Name, player2Name },
|
||||
new boolean[] { isPlayer1Human, isPlayer2Human },
|
||||
new int[] { computer1Difficulty, computer2Difficulty },
|
||||
isConnectionLocal, serverIP, serverPort)));
|
||||
});
|
||||
|
||||
player1Container.addToggle("Human", "Computer", !isPlayer1Human, (computer) -> {
|
||||
player1Container.addToggle(AppContext.getString("human"), AppContext.getString("computer"), !isPlayer1Human, (computer) -> {
|
||||
isPlayer1Human = !computer;
|
||||
reload();
|
||||
});
|
||||
|
||||
if (isPlayer1Human) {
|
||||
player1Container.addText("player is human", true);
|
||||
player1Container.addText("input player name here: ...", true);
|
||||
player1Container.addText(AppContext.getString("playerName"), true);
|
||||
player1Container.addInput(player1Name, (name) -> {
|
||||
player1Name = name;
|
||||
});
|
||||
} else {
|
||||
player1Container.addText("playing against ai", true);
|
||||
player1Container.addToggle("Easy", "Hard", false, (hard) -> {});
|
||||
player1Container.addText(AppContext.getString("computerDifficulty"), true);
|
||||
player1Container.addSlider(5, computer1Difficulty, (difficulty) -> {
|
||||
computer1Difficulty = difficulty;
|
||||
});
|
||||
}
|
||||
|
||||
if (isConnectionLocal) {
|
||||
player2Container.addToggle("Human", "Computer", !isPlayer2Human, (computer) -> {
|
||||
player2Container.addToggle(AppContext.getString("human"), AppContext.getString("computer"), !isPlayer2Human, (computer) -> {
|
||||
isPlayer2Human = !computer;
|
||||
reload();
|
||||
});
|
||||
|
||||
if (isPlayer2Human) {
|
||||
player2Container.addText("player is human", true);
|
||||
player2Container.addText("input player name here: ...", true);
|
||||
player2Container.addText(AppContext.getString("playerName"), true);
|
||||
player2Container.addInput(player2Name, (name) -> {
|
||||
player2Name = name;
|
||||
});
|
||||
} else {
|
||||
player2Container.addText("playing against ai", true);
|
||||
player2Container.addToggle("Easy", "Hard", false, (hard) -> {});
|
||||
player2Container.addText(AppContext.getString("computerDifficulty"), true);
|
||||
player2Container.addSlider(5, computer2Difficulty, (difficulty) -> {
|
||||
computer2Difficulty = difficulty;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
player2Container.addText("Server IP", true);
|
||||
player2Container.addInput("", (input) -> {});
|
||||
player2Container.addText(AppContext.getString("serverIP"), true);
|
||||
player2Container.addInput(serverIP, (ip) -> {
|
||||
serverIP = ip;
|
||||
});
|
||||
|
||||
player2Container.addText("Server Port", true);
|
||||
player2Container.addInput("", (input) -> {});
|
||||
player2Container.addSeparator(true);
|
||||
|
||||
player2Container.addText(AppContext.getString("serverPort"), true);
|
||||
player2Container.addInput(serverPort, (port) -> {
|
||||
serverPort = port;
|
||||
});
|
||||
}
|
||||
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
controlContainer.addButton("Back", () -> { App.activate(new MainLayer()); });
|
||||
|
||||
controlContainer.addButton(AppContext.getString("back"), () -> {
|
||||
App.activate(new MainLayer());
|
||||
});
|
||||
|
||||
addContainer(mainContainer, Pos.CENTER, 0, 0, 75, 75);
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2, 0, 0);
|
||||
|
||||
105
app/src/main/java/org/toop/app/layer/layers/OptionsLayer.java
Normal file
105
app/src/main/java/org/toop/app/layer/layers/OptionsLayer.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package org.toop.app.layer.layers;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.layer.Container;
|
||||
import org.toop.app.layer.Layer;
|
||||
import org.toop.app.layer.containers.VerticalContainer;
|
||||
import org.toop.framework.asset.resources.SettingsAsset;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.ChoiceBox;
|
||||
import org.toop.local.AppSettings;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public final class OptionsLayer extends Layer {
|
||||
AppSettings appSettings = new AppSettings();
|
||||
SettingsAsset settings = appSettings.getPath();
|
||||
|
||||
private int currentVolume = settings.getVolume();
|
||||
private boolean isWindowed = !(settings.getFullscreen());
|
||||
|
||||
OptionsLayer() {
|
||||
super("options.css");
|
||||
reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
|
||||
final Container optionsContainer = new VerticalContainer(5);
|
||||
optionsContainer.addText(AppContext.getString("language"), false);
|
||||
addLanguageBox(optionsContainer);
|
||||
optionsContainer.addSeparator(true);
|
||||
|
||||
optionsContainer.addText(AppContext.getString("volume"), false);
|
||||
addVolumeSlider(optionsContainer);
|
||||
optionsContainer.addSeparator(true);
|
||||
|
||||
addFullscreenToggle(optionsContainer);
|
||||
|
||||
final Container mainContainer = new VerticalContainer(50);
|
||||
mainContainer.addText(AppContext.getString("options"), false);
|
||||
mainContainer.addContainer(optionsContainer, true);
|
||||
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
controlContainer.addButton(AppContext.getString("back"), () -> {
|
||||
App.activate(new MainLayer());
|
||||
});
|
||||
|
||||
addContainer(mainContainer, Pos.CENTER, 0, 0, 30, 60);
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2, 0, 0);
|
||||
}
|
||||
|
||||
private void addLanguageBox(Container container) {
|
||||
assert AppContext.getLocalization() != null;
|
||||
|
||||
final ChoiceBox<Locale> languageBox = container.addChoiceBox((locale) -> {
|
||||
if (locale == AppContext.getLocale()) {
|
||||
return;
|
||||
}
|
||||
|
||||
AppContext.setLocale(locale);
|
||||
settings.setLocale(locale.toString());
|
||||
App.reloadAll();
|
||||
});
|
||||
|
||||
for (final Locale localeFile : AppContext.getLocalization().getAvailableLocales()) {
|
||||
languageBox.getItems().add(localeFile);
|
||||
}
|
||||
|
||||
languageBox.setConverter(new javafx.util.StringConverter<>() {
|
||||
@Override
|
||||
public String toString(Locale locale) {
|
||||
return AppContext.getString(locale.getDisplayName().toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale fromString(String string) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
languageBox.setValue(AppContext.getLocale());
|
||||
}
|
||||
|
||||
private void addVolumeSlider(Container container) {
|
||||
container.addSlider(100, currentVolume, (volume) -> {
|
||||
currentVolume = volume;
|
||||
settings.setVolume(volume);
|
||||
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(volume.doubleValue())).asyncPostEvent();
|
||||
});
|
||||
}
|
||||
|
||||
private void addFullscreenToggle(Container container) {
|
||||
container.addToggle(AppContext.getString("windowed"), AppContext.getString("fullscreen"), !isWindowed, (fullscreen) -> {
|
||||
isWindowed = !fullscreen;
|
||||
App.setFullscreen(fullscreen);
|
||||
settings.setFullscreen(fullscreen);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,13 @@ import org.toop.app.layer.Container;
|
||||
import org.toop.app.layer.Layer;
|
||||
import org.toop.app.layer.containers.HorizontalContainer;
|
||||
import org.toop.app.layer.containers.VerticalContainer;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
public final class QuitLayer extends Layer {
|
||||
public QuitLayer() {
|
||||
super("quit.css", "quit_background");
|
||||
super("quit.css");
|
||||
reload();
|
||||
}
|
||||
|
||||
@@ -19,13 +20,19 @@ public final class QuitLayer extends Layer {
|
||||
popAll();
|
||||
|
||||
final Container mainContainer = new VerticalContainer(30);
|
||||
mainContainer.addText("Are you sure?", false);
|
||||
mainContainer.addText(AppContext.getString("quitSure"), false);
|
||||
|
||||
final Container controlContainer = new HorizontalContainer(30);
|
||||
|
||||
mainContainer.addContainer(controlContainer, false);
|
||||
|
||||
controlContainer.addButton("Yes", () -> { App.quit(); });
|
||||
controlContainer.addButton("No", () -> { App.pop(); });
|
||||
controlContainer.addButton(AppContext.getString("yes"), () -> {
|
||||
App.quit();
|
||||
});
|
||||
|
||||
controlContainer.addButton(AppContext.getString("no"), () -> {
|
||||
App.pop();
|
||||
});
|
||||
|
||||
addContainer(mainContainer, Pos.CENTER, 0, 0, 30, 30);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
package org.toop.app.layer.layers.game;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.paint.Color;
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.GameInformation;
|
||||
import org.toop.app.canvas.TicTacToeCanvas;
|
||||
import org.toop.app.layer.Container;
|
||||
import org.toop.app.layer.Layer;
|
||||
import org.toop.app.layer.containers.VerticalContainer;
|
||||
import org.toop.app.layer.layers.MainLayer;
|
||||
import org.toop.game.Game;
|
||||
import org.toop.game.tictactoe.TicTacToe;
|
||||
import org.toop.game.tictactoe.TicTacToeAI;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public final class TicTacToeLayer extends Layer {
|
||||
private TicTacToeCanvas canvas;
|
||||
|
||||
private TicTacToe ticTacToe;
|
||||
private TicTacToeAI ticTacToeAI;
|
||||
|
||||
private GameInformation information;
|
||||
|
||||
private final BlockingQueue<Game.Move> playerMoveQueue = new LinkedBlockingQueue<>();
|
||||
|
||||
public TicTacToeLayer(GameInformation information) {
|
||||
super("game.css");
|
||||
|
||||
canvas = new TicTacToeCanvas(Color.WHITE, (App.getHeight() / 100) * 75, (App.getHeight() / 100) * 75, (cell) -> {
|
||||
try {
|
||||
if (information.isConnectionLocal()) {
|
||||
if (ticTacToe.getCurrentTurn() == 0) {
|
||||
playerMoveQueue.put(new Game.Move(cell, 'X'));
|
||||
} else {
|
||||
playerMoveQueue.put(new Game.Move(cell, 'O'));
|
||||
}
|
||||
} else {
|
||||
if (ticTacToe.getCurrentTurn() == 0) {
|
||||
// Todo: identify if we are x or o and put in queue
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
ticTacToe = new TicTacToe();
|
||||
ticTacToeAI = new TicTacToeAI();
|
||||
|
||||
this.information = information;
|
||||
|
||||
if (information.isConnectionLocal()) {
|
||||
new Thread(this::localGameThread).start();
|
||||
} else {
|
||||
new Thread(this::serverGameThread).start();
|
||||
}
|
||||
|
||||
reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
|
||||
canvas.resize((App.getHeight() / 100) * 75, (App.getHeight() / 100) * 75);
|
||||
|
||||
for (int i = 0; i < ticTacToe.board.length; i++) {
|
||||
final char value = ticTacToe.board[i];
|
||||
|
||||
if (value == 'X') {
|
||||
canvas.drawX(Color.RED, i);
|
||||
} else if (value == 'O') {
|
||||
canvas.drawO(Color.BLUE, i);
|
||||
}
|
||||
}
|
||||
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
|
||||
if (information.isPlayerHuman()[0] || information.isConnectionLocal() && information.isPlayerHuman()[1]) {
|
||||
controlContainer.addButton(AppContext.getString("hint"), () -> {
|
||||
});
|
||||
}
|
||||
|
||||
controlContainer.addButton(AppContext.getString("back"), () -> {
|
||||
App.activate(new MainLayer());
|
||||
});
|
||||
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2, 0, 0);
|
||||
addGameCanvas(canvas, Pos.CENTER, 0, 0);
|
||||
}
|
||||
|
||||
private int compurterDifficultyToDepth(int maxDifficulty, int difficulty) {
|
||||
return (int) (((float) maxDifficulty / difficulty) * 9);
|
||||
}
|
||||
|
||||
private void localGameThread() {
|
||||
boolean running = true;
|
||||
|
||||
while (running) {
|
||||
final int currentPlayer = ticTacToe.getCurrentTurn();
|
||||
|
||||
Game.Move move = null;
|
||||
|
||||
if (information.isPlayerHuman()[currentPlayer]) {
|
||||
try {
|
||||
move = playerMoveQueue.take();
|
||||
} catch (InterruptedException exception) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
move = ticTacToeAI.findBestMove(ticTacToe, compurterDifficultyToDepth(5, information.computerDifficulty()[currentPlayer]));
|
||||
}
|
||||
|
||||
assert move != null;
|
||||
final Game.State state = ticTacToe.play(move);
|
||||
|
||||
if (move.value() == 'X') {
|
||||
canvas.drawX(Color.RED, move.position());
|
||||
} else if (move.value() == 'O') {
|
||||
canvas.drawO(Color.BLUE, move.position());
|
||||
}
|
||||
|
||||
if (state != Game.State.NORMAL) {
|
||||
if (state == Game.State.WIN) {
|
||||
// Win logic
|
||||
} else if (state == Game.State.DRAW) {
|
||||
// Draw logic
|
||||
}
|
||||
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void serverGameThread() {
|
||||
boolean running = true;
|
||||
|
||||
while (running) {
|
||||
final int currentPlayer = ticTacToe.getCurrentTurn();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
// package org.toop.app.menu;
|
||||
//
|
||||
// import javafx.animation.Interpolator;
|
||||
// import javafx.animation.PauseTransition;
|
||||
// import javafx.animation.TranslateTransition;
|
||||
// import javafx.application.Platform;
|
||||
// import javafx.geometry.Pos;
|
||||
// import javafx.scene.control.Button;
|
||||
// import javafx.scene.layout.Region;
|
||||
// import javafx.scene.layout.StackPane;
|
||||
// import javafx.scene.layout.VBox;
|
||||
// import javafx.util.Duration;
|
||||
// import org.toop.app.App;
|
||||
// import org.toop.framework.asset.ResourceManager;
|
||||
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
// import org.toop.framework.eventbus.EventFlow;
|
||||
// import org.toop.local.AppContext;
|
||||
// import org.toop.local.LocalizationEvents;
|
||||
//
|
||||
// import java.util.Locale;
|
||||
//
|
||||
// public final class CreditsMenu extends Menu { ;
|
||||
// private Locale currentLocale = AppContext.getLocale();
|
||||
// private LocalizationAsset loc = ResourceManager.get("localization_en_us.properties");
|
||||
//
|
||||
// String[] credits = {
|
||||
// "Scrum Master: Stef",
|
||||
// "Product Owner: Omar",
|
||||
// "Merge Commander: Bas",
|
||||
// "Localization: Ticho",
|
||||
// "AI: Michiel",
|
||||
// "Developers: Michiel, Bas, Stef, Omar, Ticho",
|
||||
// "Moral Support: Wesley (voor 1 week)",
|
||||
// "OpenGL: Omar"
|
||||
// };
|
||||
//
|
||||
// double scrollDuration = 20.0;
|
||||
// double lineHeight = 40.0;
|
||||
//
|
||||
// public CreditsMenu() {
|
||||
// VBox creditsBox = new VBox(lineHeight / 2);
|
||||
// for (int i = credits.length - 1; i >= 0; i--) {
|
||||
// creditsBox.getChildren().add(createText(credits[i]));
|
||||
// creditsBox.setAlignment(Pos.CENTER);
|
||||
// }
|
||||
//
|
||||
// Button exit = new Button("<");
|
||||
// exit.setStyle(
|
||||
// "-fx-background-color: transparent;" +
|
||||
// "-fx-text-fill: white;" +
|
||||
// "-fx-font-size: 72px;" +
|
||||
// "-fx-padding: 10 20 10 20;"
|
||||
// );
|
||||
// exit.setOnAction(e -> App.pop());
|
||||
//
|
||||
// final Region background = createBackground();
|
||||
// StackPane.setAlignment(exit, Pos.TOP_LEFT);
|
||||
// pane = new StackPane(background, creditsBox, exit);
|
||||
//
|
||||
// Platform.runLater(() -> playCredits(creditsBox, 800));
|
||||
//
|
||||
// try {
|
||||
// new EventFlow()
|
||||
// .listen(this::handleChangeLanguage);
|
||||
//
|
||||
// }catch (Exception e){
|
||||
// System.out.println("Something went wrong while trying to change the language.");
|
||||
// throw e;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void playCredits(VBox creditsBox, double sceneLength) {
|
||||
// double height = (credits.length * lineHeight);
|
||||
// double startY = -sceneLength;
|
||||
// double endY = height;
|
||||
//
|
||||
// creditsBox.setTranslateY(startY);
|
||||
//
|
||||
// TranslateTransition scrollCredits = new TranslateTransition();
|
||||
// scrollCredits.setNode(creditsBox);
|
||||
// scrollCredits.setFromY(startY);
|
||||
// scrollCredits.setToY(endY / 2 - 200);
|
||||
// scrollCredits.setDuration(Duration.seconds(scrollDuration));
|
||||
// scrollCredits.setInterpolator(Interpolator.LINEAR);
|
||||
//
|
||||
// scrollCredits.setOnFinished(e -> {
|
||||
// PauseTransition pauseCredits = new PauseTransition(Duration.seconds(5));
|
||||
// pauseCredits.setOnFinished(a -> playCredits(creditsBox, sceneLength));
|
||||
// pauseCredits.play();
|
||||
// });
|
||||
//
|
||||
// scrollCredits.play();
|
||||
// }
|
||||
// private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
// Platform.runLater(() -> {
|
||||
// currentLocale = AppContext.getLocale();
|
||||
// //credits.setText(loc.getString("credits",currentLocale));
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
@@ -1,66 +0,0 @@
|
||||
// package org.toop.app.menu;
|
||||
//
|
||||
// import javafx.application.Platform;
|
||||
// import javafx.scene.control.ComboBox;
|
||||
// import javafx.scene.control.TextField;
|
||||
// import javafx.scene.layout.HBox;
|
||||
// import javafx.scene.layout.Region;
|
||||
// import javafx.scene.layout.StackPane;
|
||||
// import javafx.scene.layout.VBox;
|
||||
// import org.toop.app.GameType;
|
||||
// import org.toop.framework.asset.ResourceManager;
|
||||
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
// import org.toop.framework.eventbus.EventFlow;
|
||||
// import org.toop.local.AppContext;
|
||||
//
|
||||
// import java.util.Locale;
|
||||
//
|
||||
// public class GameSelectMenu extends Menu {
|
||||
// private Locale currentLocale = AppContext.getLocale();
|
||||
// private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
//
|
||||
// final ComboBox<String> selectedMode, selectedGame;
|
||||
// final TextField serverIpField;
|
||||
//
|
||||
// public GameSelectMenu(GameType type) {
|
||||
// final Region background = createBackground();
|
||||
//
|
||||
// selectedGame = new ComboBox<>();
|
||||
// selectedGame.getItems().add(GameType.toName(GameType.TICTACTOE));
|
||||
// selectedGame.getItems().add(GameType.toName(GameType.REVERSI));
|
||||
// selectedGame.setValue(GameType.toName(type));
|
||||
//
|
||||
// selectedMode = new ComboBox<>();
|
||||
// selectedMode.getItems().add("Local");
|
||||
// selectedMode.getItems().add("Online");
|
||||
// selectedMode.setValue("Local");
|
||||
//
|
||||
// final HBox selectedContainer = new HBox(10, selectedGame, selectedMode);
|
||||
//
|
||||
// serverIpField = new TextField();
|
||||
// serverIpField.setPromptText(loc.getString("gameSelectMenuEnterIP",currentLocale));
|
||||
//
|
||||
// VBox box = new VBox(selectedContainer, serverIpField);
|
||||
// pane = new StackPane(background, box);
|
||||
// try {
|
||||
// new EventFlow()
|
||||
// .listen(this::handleChangeLanguage);
|
||||
//
|
||||
// }catch (Exception e){
|
||||
// System.out.println("Something went wrong while trying to change the language.");
|
||||
// throw e;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
// Platform.runLater(() -> {
|
||||
// currentLocale = AppContext.getLocale();
|
||||
// serverIpField.setPromptText(loc.getString("gameSelectMenuEnterIP",currentLocale));
|
||||
// selectedGame.getItems().set(0, loc.getString("mainMenuSelectTicTacToe",currentLocale));
|
||||
// selectedGame.getItems().set(1, loc.getString("mainMenuSelectReversi",currentLocale));
|
||||
// selectedMode.getItems().set(0, loc.getString("gameSelectMenuLocal",currentLocale));
|
||||
// selectedMode.getItems().set(1, loc.getString("gameSelectMenuOnline",currentLocale));
|
||||
// });
|
||||
//
|
||||
// }
|
||||
// }
|
||||
@@ -1,69 +0,0 @@
|
||||
// package org.toop.app.menu;
|
||||
//
|
||||
// import javafx.application.Platform;
|
||||
// import org.toop.app.App;
|
||||
// import org.toop.app.GameType;
|
||||
//
|
||||
// import javafx.geometry.Pos;
|
||||
// import javafx.scene.control.Button;
|
||||
// import javafx.scene.layout.*;
|
||||
// import org.toop.framework.asset.ResourceManager;
|
||||
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
// import org.toop.framework.eventbus.EventFlow;
|
||||
// import org.toop.game.tictactoe.TicTacToe;
|
||||
// import org.toop.local.AppContext;
|
||||
// import org.toop.local.LocalizationEvents;
|
||||
//
|
||||
// import java.util.Locale;
|
||||
//
|
||||
// public final class MainMenu extends Menu {
|
||||
// private Locale currentLocale = AppContext.getLocale();
|
||||
// private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
// private final Button tictactoe,reversi,credits,options,quit;
|
||||
// public MainMenu() {
|
||||
// final Region background = createBackground();
|
||||
//
|
||||
// tictactoe = createButton(
|
||||
// loc.getString("mainMenuSelectTicTacToe",currentLocale), () -> { App.activate(new GameSelectMenu(GameType.TICTACTOE)); });
|
||||
// reversi = createButton(
|
||||
// loc.getString("mainMenuSelectReversi",currentLocale), () -> { App.activate(new GameSelectMenu(GameType.REVERSI)); });
|
||||
//
|
||||
// final VBox gamesBox = new VBox(10, tictactoe, reversi);
|
||||
// gamesBox.setAlignment(Pos.TOP_LEFT);
|
||||
// gamesBox.setPickOnBounds(false);
|
||||
// gamesBox.setTranslateY(50);
|
||||
// gamesBox.setTranslateX(25);
|
||||
//
|
||||
// credits = createButton(loc.getString("mainMenuSelectCredits",currentLocale), () -> { App.push(new CreditsMenu()); });
|
||||
// options = createButton(loc.getString("mainMenuSelectOptions",currentLocale), () -> { App.push(new OptionsMenu()); });
|
||||
// quit = createButton(loc.getString("mainMenuSelectQuit",currentLocale), () -> { App.quitPopup(); });
|
||||
//
|
||||
// final VBox controlBox = new VBox(10, credits, options, quit);
|
||||
// controlBox.setAlignment(Pos.BOTTOM_LEFT);
|
||||
// controlBox.setPickOnBounds(false);
|
||||
// controlBox.setTranslateY(-50);
|
||||
// controlBox.setTranslateX(25);
|
||||
//
|
||||
// pane = new StackPane(background, gamesBox, controlBox);
|
||||
// try {
|
||||
// new EventFlow()
|
||||
// .listen(this::handleChangeLanguage);
|
||||
//
|
||||
// }catch (Exception e){
|
||||
// System.out.println("Something went wrong while trying to change the language.");
|
||||
// throw e;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
// Platform.runLater(() -> {
|
||||
// currentLocale = AppContext.getLocale();
|
||||
// tictactoe.setText(loc.getString("mainMenuSelectTicTacToe",currentLocale));
|
||||
// reversi.setText(loc.getString("mainMenuSelectReversi",currentLocale));
|
||||
// credits.setText(loc.getString("mainMenuSelectCredits",currentLocale));
|
||||
// options.setText(loc.getString("mainMenuSelectOptions",currentLocale));
|
||||
// quit.setText(loc.getString("mainMenuSelectQuit",currentLocale));
|
||||
// });
|
||||
//
|
||||
// }
|
||||
// }
|
||||
@@ -1,51 +0,0 @@
|
||||
package org.toop.app.menu;
|
||||
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.text.Text;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
|
||||
public abstract class Menu {
|
||||
protected Pane pane;
|
||||
public Pane getPane() { return pane; }
|
||||
|
||||
public Region createBackground(String css) {
|
||||
final Region background = new Region();
|
||||
background.setPrefSize(Double.MAX_VALUE, Double.MAX_VALUE);
|
||||
background.getStyleClass().add(css);
|
||||
|
||||
return background;
|
||||
}
|
||||
|
||||
public Region createBackground() {
|
||||
return createBackground("background");
|
||||
}
|
||||
|
||||
public Text createText(String css, String x) {
|
||||
final Text text = new Text(x);
|
||||
text.getStyleClass().add(css);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
public Text createText(String x) {
|
||||
return createText("text", x);
|
||||
}
|
||||
|
||||
public Button createButton(String css, String x, Runnable runnable) {
|
||||
final Button button = new Button(x);
|
||||
button.setOnAction(_ -> {
|
||||
new EventFlow().addPostEvent(new AudioEvents.clickButton()).asyncPostEvent();
|
||||
runnable.run();
|
||||
});
|
||||
button.getStyleClass().add(css);
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
public Button createButton(String x, Runnable runnable) {
|
||||
return createButton("button", x, runnable);
|
||||
}
|
||||
}
|
||||
@@ -1,174 +0,0 @@
|
||||
// package org.toop.app.menu;
|
||||
//
|
||||
// import javafx.geometry.Pos;
|
||||
// import javafx.scene.control.*;
|
||||
// import javafx.scene.control.Button;
|
||||
// import javafx.scene.control.Label;
|
||||
// import javafx.scene.layout.Region;
|
||||
// import javafx.scene.layout.StackPane;
|
||||
// import javafx.scene.layout.VBox;
|
||||
// import org.toop.app.App;
|
||||
// import org.toop.framework.asset.ResourceManager;
|
||||
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
// import org.toop.framework.audio.events.AudioEvents;
|
||||
// import org.toop.framework.eventbus.EventFlow;
|
||||
// import org.toop.local.AppContext;
|
||||
//
|
||||
// import java.awt.*;
|
||||
// import java.util.Locale;
|
||||
//
|
||||
// public final class OptionsMenu extends Menu {
|
||||
// private Locale currentLocale = AppContext.getLocale();
|
||||
// private LocalizationAsset loc = ResourceManager.get("localization");
|
||||
// private GraphicsDevice currentScreenDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0];
|
||||
//
|
||||
// public OptionsMenu() {
|
||||
// final Label selectLanguageLabel = new Label(
|
||||
// loc.getString("optionsMenuLabelSelectLanguage", currentLocale)
|
||||
// );
|
||||
//
|
||||
// final Button exitOptionsButton = createButton("Exit Options", () -> { App.pop(); } );
|
||||
//
|
||||
// final VBox optionsBox = new VBox(10,
|
||||
// selectLanguageLabel,
|
||||
// languageSelectorCreation(),
|
||||
// screenDeviceSelectorCreation(),
|
||||
// displayModeSelectorCreation(),
|
||||
// selectFullscreenCreation(),
|
||||
// volumeSelectorCreation(),
|
||||
// exitOptionsButton);
|
||||
//
|
||||
// optionsBox.setAlignment(Pos.CENTER);
|
||||
// optionsBox.setPickOnBounds(false);
|
||||
// optionsBox.setTranslateY(50);
|
||||
// optionsBox.setTranslateX(25);
|
||||
//
|
||||
// pane = new StackPane(optionsBox);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private ChoiceBox<Locale> languageSelectorCreation() {
|
||||
// final ChoiceBox<Locale> selectLanguage = new ChoiceBox<>();
|
||||
// selectLanguage.setValue(currentLocale);
|
||||
//
|
||||
// for (Locale locFile : loc.getAvailableLocales()) {
|
||||
// selectLanguage.getItems().add(locFile);
|
||||
// }
|
||||
//
|
||||
// selectLanguage.setConverter(new javafx.util.StringConverter<>() {
|
||||
// @Override
|
||||
// public String toString(Locale locale) {
|
||||
// return locale.getDisplayName();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Locale fromString(String string) {
|
||||
// return null;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// selectLanguage.setOnShowing(event -> {
|
||||
// new EventFlow().addPostEvent(new AudioEvents.clickButton()).asyncPostEvent();
|
||||
// });
|
||||
//
|
||||
// selectLanguage.setOnAction(event -> {
|
||||
// new EventFlow().addPostEvent(new AudioEvents.clickButton()).asyncPostEvent();
|
||||
// Locale selectedLocale = selectLanguage.getSelectionModel().getSelectedItem();
|
||||
// if (selectedLocale != null) {
|
||||
// AppContext.setLocale(selectedLocale);
|
||||
// App.pop();
|
||||
// App.push(new OptionsMenu());
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// return selectLanguage;
|
||||
// }
|
||||
//
|
||||
// private ChoiceBox<GraphicsDevice> screenDeviceSelectorCreation() {
|
||||
// GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
// GraphicsDevice[] devices = ge.getScreenDevices();
|
||||
// final ChoiceBox<GraphicsDevice> selectScreen = new ChoiceBox<>();
|
||||
// for (GraphicsDevice screen : devices) {
|
||||
// selectScreen.getItems().add(screen);
|
||||
// }
|
||||
//
|
||||
// selectScreen.setOnShowing(event -> {
|
||||
// new EventFlow().addPostEvent(new AudioEvents.clickButton()).asyncPostEvent();
|
||||
// });
|
||||
//
|
||||
// selectScreen.setOnAction(event -> {
|
||||
// new EventFlow().addPostEvent(new AudioEvents.clickButton()).asyncPostEvent();
|
||||
// int selectedIndex = selectScreen.getSelectionModel().getSelectedIndex();
|
||||
// Object selectedItem = selectScreen.getSelectionModel().getSelectedItem();
|
||||
//
|
||||
// System.out.println("Selection made: [" + selectedIndex + "] " + selectedItem);
|
||||
// System.out.println(" ChoiceBox.getValue(): " + selectScreen.getValue());
|
||||
// });
|
||||
// return selectScreen;
|
||||
// }
|
||||
//
|
||||
// private ChoiceBox<DisplayMode> displayModeSelectorCreation() {
|
||||
// final ChoiceBox<DisplayMode> selectWindowSize = new ChoiceBox<>();
|
||||
// for (DisplayMode displayMode : currentScreenDevice.getDisplayModes()) {
|
||||
// selectWindowSize.getItems().add(displayMode);
|
||||
// }
|
||||
// selectWindowSize.setOnShowing(event -> {
|
||||
// new EventFlow().addPostEvent(new AudioEvents.clickButton()).asyncPostEvent();
|
||||
// });
|
||||
// selectWindowSize.setOnAction(event -> {
|
||||
// new EventFlow().addPostEvent(new AudioEvents.clickButton()).asyncPostEvent();
|
||||
// int selectedIndex = selectWindowSize.getSelectionModel().getSelectedIndex();
|
||||
// Object selectedItem = selectWindowSize.getSelectionModel().getSelectedItem();
|
||||
//
|
||||
// System.out.println("Selection made: [" + selectedIndex + "] " + selectedItem);
|
||||
// System.out.println(" ChoiceBox.getValue(): " + selectWindowSize.getValue());
|
||||
// });
|
||||
// return selectWindowSize;
|
||||
// }
|
||||
//
|
||||
// private CheckBox selectFullscreenCreation() {
|
||||
// final CheckBox setFullscreen = new CheckBox("Fullscreen");
|
||||
// setFullscreen.setSelected(App.isFullscreen());
|
||||
// setFullscreen.setOnAction(event -> {
|
||||
// new EventFlow().addPostEvent(new AudioEvents.clickButton()).asyncPostEvent();
|
||||
// boolean isSelected = setFullscreen.isSelected();
|
||||
// App.setFullscreen(isSelected);
|
||||
// });
|
||||
// return setFullscreen;
|
||||
// }
|
||||
//
|
||||
// private Slider volumeSelectorCreation() {
|
||||
// Slider volumeSlider = new Slider(0, 100, 50);
|
||||
// new EventFlow()
|
||||
// .addPostEvent(AudioEvents.GetCurrentVolume.class)
|
||||
// .onResponse(AudioEvents.GetCurrentVolumeReponse.class, event -> {
|
||||
// volumeSlider.setValue(event.currentVolume() * 100);
|
||||
// }, true).asyncPostEvent();
|
||||
// volumeSlider.setShowTickLabels(true);
|
||||
// volumeSlider.setShowTickMarks(true);
|
||||
// volumeSlider.setMajorTickUnit(25);
|
||||
// volumeSlider.setMinorTickCount(4);
|
||||
// volumeSlider.setBlockIncrement(5);
|
||||
// volumeSlider.setMaxWidth(225);
|
||||
//
|
||||
// Label valueLabel = new Label(String.valueOf((int) volumeSlider.getValue()));
|
||||
//
|
||||
// final long[] lastPlayed = {0};
|
||||
// final long cooldown = 50;
|
||||
// volumeSlider.valueProperty().addListener((obs, oldVal, newVal) -> {
|
||||
// long now = System.currentTimeMillis();
|
||||
//
|
||||
// if (now - lastPlayed[0] >= cooldown) {
|
||||
// lastPlayed[0] = now;
|
||||
// // new EventFlow().addPostEvent(new AudioEvents.clickButton())
|
||||
// // .asyncPostEvent(); // TODO: creates double sound bug, WHYYY????
|
||||
// }
|
||||
// valueLabel.setText(String.valueOf(newVal.intValue()));
|
||||
// new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(newVal.doubleValue()/100.0))
|
||||
// .asyncPostEvent();
|
||||
// });
|
||||
//
|
||||
// return volumeSlider;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
@@ -1,127 +0,0 @@
|
||||
// package org.toop.app.menu.game;
|
||||
//
|
||||
// import javafx.application.Platform;
|
||||
// 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;
|
||||
// import org.toop.framework.asset.ResourceManager;
|
||||
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
// import org.toop.framework.eventbus.EventFlow;
|
||||
// import org.toop.local.AppContext;
|
||||
//
|
||||
// import java.util.Locale;
|
||||
//
|
||||
// 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;
|
||||
//
|
||||
// private Locale currentLocale = AppContext.getLocale();
|
||||
// private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
// private final Button hint,back;
|
||||
// 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);
|
||||
//
|
||||
// hint = createButton(loc.getString("gameMenuHint",currentLocale), () -> {});
|
||||
// back = createButton(loc.getString("gameMenuBack",currentLocale), () -> { 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);
|
||||
// try {
|
||||
// new EventFlow()
|
||||
// .listen(this::handleChangeLanguage);
|
||||
//
|
||||
// }catch (Exception e){
|
||||
// System.out.println("Something went wrong while trying to change the language.");
|
||||
// throw e;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
// Platform.runLater(() -> {
|
||||
// currentLocale = AppContext.getLocale();
|
||||
// hint.setText(loc.getString("gameMenuHint",currentLocale));
|
||||
// back.setText(loc.getString("gameMenuBack",currentLocale));
|
||||
// });
|
||||
//
|
||||
// }
|
||||
// }
|
||||
@@ -1,24 +1,28 @@
|
||||
package org.toop.local;
|
||||
|
||||
import org.toop.app.events.AppEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class AppContext {
|
||||
private static Locale currentLocale = Locale.getDefault();
|
||||
private static final LocalizationAsset localization = ResourceManager.get("localization");
|
||||
private static Locale locale = Locale.forLanguageTag("en");
|
||||
|
||||
public static void setLocale(Locale locale) {
|
||||
currentLocale = locale;
|
||||
new EventFlow().addPostEvent(new AppEvents.OnLanguageChange(locale.getLanguage())).asyncPostEvent();
|
||||
}
|
||||
public static LocalizationAsset getLocalization() {
|
||||
return localization;
|
||||
}
|
||||
|
||||
public static void setCurrentLocale(Locale locale) {
|
||||
currentLocale = locale;
|
||||
new EventFlow().addPostEvent(new AppEvents.OnLanguageChange(locale.getLanguage())).asyncPostEvent();
|
||||
}
|
||||
public static void setLocale(Locale locale) {
|
||||
AppContext.locale = locale;
|
||||
}
|
||||
|
||||
public static Locale getLocale() {
|
||||
return currentLocale;
|
||||
}
|
||||
public static Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public static String getString(String key) {
|
||||
assert localization != null;
|
||||
return localization.getString(key, locale);
|
||||
}
|
||||
}
|
||||
|
||||
50
app/src/main/java/org/toop/local/AppSettings.java
Normal file
50
app/src/main/java/org/toop/local/AppSettings.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package org.toop.local;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.framework.asset.resources.SettingsAsset;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.settings.Settings;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
|
||||
public class AppSettings {
|
||||
|
||||
private SettingsAsset settingsAsset;
|
||||
|
||||
public void applySettings() {
|
||||
SettingsAsset settings = getPath();
|
||||
if (!settings.isLoaded()) {
|
||||
settings.load();
|
||||
}
|
||||
Settings settingsData = settings.getContent();
|
||||
|
||||
AppContext.setLocale(Locale.of(settingsData.locale));
|
||||
App.setFullscreen(settingsData.fullScreen);
|
||||
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(settingsData.volume)).asyncPostEvent();
|
||||
|
||||
}
|
||||
|
||||
public SettingsAsset getPath() {
|
||||
if (this.settingsAsset == null) {
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
String basePath;
|
||||
|
||||
if (os.contains("win")) {
|
||||
basePath = System.getenv("APPDATA");
|
||||
if (basePath == null) {
|
||||
basePath = System.getProperty("user.home");
|
||||
}
|
||||
} else if (os.contains("mac")) {
|
||||
basePath = System.getProperty("user.home") + "/Library/Application Support";
|
||||
} else {
|
||||
basePath = System.getProperty("user.home") + "/.config";
|
||||
}
|
||||
|
||||
File settingsFile = new File(basePath + File.separator + "ISY1" + File.separator + "settings.json");
|
||||
this.settingsAsset = new SettingsAsset(settingsFile);
|
||||
}
|
||||
return this.settingsAsset;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user