mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 02:44:50 +00:00
Formatting
This commit is contained in:
@@ -8,14 +8,14 @@ import org.toop.framework.networking.NetworkingClientManager;
|
||||
import org.toop.framework.networking.NetworkingInitializationException;
|
||||
|
||||
public final class Main {
|
||||
public static void main(String[] args) {
|
||||
initSystems();
|
||||
App.run(args);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
initSystems();
|
||||
App.run(args);
|
||||
}
|
||||
|
||||
private static void initSystems() throws NetworkingInitializationException {
|
||||
ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/assets"));
|
||||
new Thread(NetworkingClientManager::new).start();
|
||||
new Thread(SoundManager::new).start();
|
||||
}
|
||||
}
|
||||
private static void initSystems() throws NetworkingInitializationException {
|
||||
ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/assets"));
|
||||
new Thread(NetworkingClientManager::new).start();
|
||||
new Thread(SoundManager::new).start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package org.toop.app;
|
||||
|
||||
import java.util.Stack;
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.stage.Stage;
|
||||
import org.toop.app.layer.Layer;
|
||||
import org.toop.app.layer.layers.MainLayer;
|
||||
import org.toop.app.layer.layers.QuitPopup;
|
||||
@@ -9,155 +14,154 @@ import org.toop.framework.asset.resources.CssAsset;
|
||||
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 Scene scene;
|
||||
private static StackPane root;
|
||||
private static Stage stage;
|
||||
private static Scene scene;
|
||||
private static StackPane root;
|
||||
|
||||
private static Stack<Layer> stack;
|
||||
private static Stack<Layer> stack;
|
||||
private static int height;
|
||||
private static int width;
|
||||
|
||||
private static boolean isQuitting;
|
||||
private static boolean isQuitting;
|
||||
|
||||
public static void run(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
public static void run(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
final StackPane root = new StackPane();
|
||||
final Scene scene = new Scene(root);
|
||||
final Scene scene = new Scene(root);
|
||||
|
||||
stage.setTitle(AppContext.getString("appTitle"));
|
||||
stage.setWidth(1080);
|
||||
stage.setHeight(720);
|
||||
stage.setTitle(AppContext.getString("appTitle"));
|
||||
stage.setWidth(1080);
|
||||
stage.setHeight(720);
|
||||
|
||||
stage.setOnCloseRequest(event -> {
|
||||
event.consume();
|
||||
stage.setOnCloseRequest(
|
||||
event -> {
|
||||
event.consume();
|
||||
|
||||
if (!isQuitting) {
|
||||
quitPopup();
|
||||
}
|
||||
});
|
||||
if (!isQuitting) {
|
||||
quitPopup();
|
||||
}
|
||||
});
|
||||
|
||||
stage.setScene(scene);
|
||||
stage.setResizable(false);
|
||||
stage.setScene(scene);
|
||||
stage.setResizable(false);
|
||||
|
||||
stage.show();
|
||||
stage.show();
|
||||
|
||||
App.stage = stage;
|
||||
App.scene = scene;
|
||||
App.root = root;
|
||||
App.stage = stage;
|
||||
App.scene = scene;
|
||||
App.root = root;
|
||||
|
||||
App.stack = new Stack<>();
|
||||
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;
|
||||
App.isQuitting = false;
|
||||
|
||||
final AppSettings settings = new AppSettings();
|
||||
settings.applySettings();
|
||||
final AppSettings settings = new AppSettings();
|
||||
settings.applySettings();
|
||||
|
||||
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).asyncPostEvent();
|
||||
activate(new MainLayer());
|
||||
}
|
||||
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).asyncPostEvent();
|
||||
activate(new MainLayer());
|
||||
}
|
||||
|
||||
public static void activate(Layer layer) {
|
||||
Platform.runLater(() -> {
|
||||
popAll();
|
||||
push(layer);
|
||||
});
|
||||
}
|
||||
public static void activate(Layer layer) {
|
||||
Platform.runLater(
|
||||
() -> {
|
||||
popAll();
|
||||
push(layer);
|
||||
});
|
||||
}
|
||||
|
||||
public static void push(Layer layer) {
|
||||
Platform.runLater(() -> {
|
||||
root.getChildren().addLast(layer.getLayer());
|
||||
stack.push(layer);
|
||||
});
|
||||
}
|
||||
public static void push(Layer layer) {
|
||||
Platform.runLater(
|
||||
() -> {
|
||||
root.getChildren().addLast(layer.getLayer());
|
||||
stack.push(layer);
|
||||
});
|
||||
}
|
||||
|
||||
public static void pop() {
|
||||
Platform.runLater(() -> {
|
||||
root.getChildren().removeLast();
|
||||
stack.pop();
|
||||
public static void pop() {
|
||||
Platform.runLater(
|
||||
() -> {
|
||||
root.getChildren().removeLast();
|
||||
stack.pop();
|
||||
|
||||
isQuitting = false;
|
||||
});
|
||||
}
|
||||
isQuitting = false;
|
||||
});
|
||||
}
|
||||
|
||||
public static void popAll() {
|
||||
Platform.runLater(() -> {
|
||||
final int childrenCount = root.getChildren().size();
|
||||
public static void popAll() {
|
||||
Platform.runLater(
|
||||
() -> {
|
||||
final int childrenCount = root.getChildren().size();
|
||||
|
||||
for (int i = 0; i < childrenCount; i++) {
|
||||
try {
|
||||
root.getChildren().removeLast();
|
||||
} catch (Exception e) {
|
||||
IO.println(e);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < childrenCount; i++) {
|
||||
try {
|
||||
root.getChildren().removeLast();
|
||||
} catch (Exception e) {
|
||||
IO.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
stack.removeAllElements();
|
||||
});
|
||||
}
|
||||
stack.removeAllElements();
|
||||
});
|
||||
}
|
||||
|
||||
public static void quitPopup() {
|
||||
Platform.runLater(() -> {
|
||||
push(new QuitPopup());
|
||||
isQuitting = true;
|
||||
});
|
||||
}
|
||||
public static void quitPopup() {
|
||||
Platform.runLater(
|
||||
() -> {
|
||||
push(new QuitPopup());
|
||||
isQuitting = true;
|
||||
});
|
||||
}
|
||||
|
||||
public static void quit() {
|
||||
stage.close();
|
||||
}
|
||||
public static void quit() {
|
||||
stage.close();
|
||||
}
|
||||
|
||||
public static void reloadAll() {
|
||||
stage.setTitle(AppContext.getString("appTitle"));
|
||||
public static void reloadAll() {
|
||||
stage.setTitle(AppContext.getString("appTitle"));
|
||||
|
||||
for (final Layer layer : stack) {
|
||||
layer.reload();
|
||||
}
|
||||
}
|
||||
for (final Layer layer : stack) {
|
||||
layer.reload();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setFullscreen(boolean fullscreen) {
|
||||
stage.setFullScreen(fullscreen);
|
||||
public static void setFullscreen(boolean fullscreen) {
|
||||
stage.setFullScreen(fullscreen);
|
||||
|
||||
width = (int) stage.getWidth();
|
||||
height = (int) stage.getHeight();
|
||||
width = (int) stage.getWidth();
|
||||
height = (int) stage.getHeight();
|
||||
|
||||
reloadAll();
|
||||
}
|
||||
reloadAll();
|
||||
}
|
||||
|
||||
public static void setStyle(String theme, String layoutSize) {
|
||||
final int stylesCount = scene.getStylesheets().size();
|
||||
public static void setStyle(String theme, String layoutSize) {
|
||||
final int stylesCount = scene.getStylesheets().size();
|
||||
|
||||
for (int i = 0; i < stylesCount; i++) {
|
||||
scene.getStylesheets().removeLast();
|
||||
}
|
||||
for (int i = 0; i < stylesCount; i++) {
|
||||
scene.getStylesheets().removeLast();
|
||||
}
|
||||
|
||||
scene.getStylesheets().add(ResourceManager.<CssAsset>get(theme + ".css").getUrl());
|
||||
scene.getStylesheets().add(ResourceManager.<CssAsset>get(layoutSize + ".css").getUrl());
|
||||
scene.getStylesheets().add(ResourceManager.<CssAsset>get(theme + ".css").getUrl());
|
||||
scene.getStylesheets().add(ResourceManager.<CssAsset>get(layoutSize + ".css").getUrl());
|
||||
|
||||
reloadAll();
|
||||
}
|
||||
reloadAll();
|
||||
}
|
||||
|
||||
public static int getWidth() {
|
||||
return width;
|
||||
}
|
||||
public static int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public static int getHeight() {
|
||||
return height;
|
||||
}
|
||||
}
|
||||
public static int getHeight() {
|
||||
return height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package org.toop.app;
|
||||
|
||||
public record GameInformation(String[] playerName, boolean[] isPlayerHuman,
|
||||
int[] computerDifficulty, int[] computerThinkTime,
|
||||
boolean isConnectionLocal, String serverIP, String serverPort) {
|
||||
}
|
||||
public record GameInformation(
|
||||
String[] playerName,
|
||||
boolean[] isPlayerHuman,
|
||||
int[] computerDifficulty,
|
||||
int[] computerThinkTime,
|
||||
boolean isConnectionLocal,
|
||||
String serverIP,
|
||||
String serverPort) {}
|
||||
|
||||
@@ -1,123 +1,130 @@
|
||||
package org.toop.app.canvas;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
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 record Cell(float x, float y, float width, float height) {}
|
||||
|
||||
protected final Canvas canvas;
|
||||
protected final GraphicsContext graphics;
|
||||
protected final Canvas canvas;
|
||||
protected final GraphicsContext graphics;
|
||||
|
||||
protected final Color color;
|
||||
protected final Color color;
|
||||
|
||||
protected int width;
|
||||
protected int height;
|
||||
protected int width;
|
||||
protected int height;
|
||||
|
||||
protected final int rows;
|
||||
protected final int columns;
|
||||
protected final int rows;
|
||||
protected final int columns;
|
||||
|
||||
protected final int gapSize;
|
||||
protected final boolean edges;
|
||||
protected final int gapSize;
|
||||
protected final boolean edges;
|
||||
|
||||
protected final Cell[] cells;
|
||||
protected final Cell[] cells;
|
||||
|
||||
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();
|
||||
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();
|
||||
|
||||
this.color = color;
|
||||
this.color = color;
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
this.rows = rows;
|
||||
this.columns = columns;
|
||||
this.rows = rows;
|
||||
this.columns = columns;
|
||||
|
||||
this.gapSize = gapSize;
|
||||
this.edges = edges;
|
||||
this.gapSize = gapSize;
|
||||
this.edges = edges;
|
||||
|
||||
cells = new Cell[rows * columns];
|
||||
cells = new Cell[rows * columns];
|
||||
|
||||
final float cellWidth = ((float) width - (rows - 1) * gapSize) / rows;
|
||||
final float cellHeight = ((float) height - (columns - 1) * gapSize) / 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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < rows; x++) {
|
||||
final float startX = x * cellWidth + x * gapSize;
|
||||
cells[y * rows + x] = new Cell(startX, startY, cellWidth, cellHeight);
|
||||
}
|
||||
}
|
||||
|
||||
canvas.setOnMouseClicked(event -> {
|
||||
if (event.getButton() != MouseButton.PRIMARY) {
|
||||
return;
|
||||
}
|
||||
canvas.setOnMouseClicked(
|
||||
event -> {
|
||||
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.accept(row * rows + column);
|
||||
});
|
||||
event.consume();
|
||||
onCellClicked.accept(row * rows + column);
|
||||
});
|
||||
|
||||
render();
|
||||
}
|
||||
render();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
graphics.clearRect(0, 0, width, height);
|
||||
}
|
||||
public void clear() {
|
||||
graphics.clearRect(0, 0, width, height);
|
||||
}
|
||||
|
||||
public void render() {
|
||||
graphics.setFill(color);
|
||||
public void render() {
|
||||
graphics.setFill(color);
|
||||
|
||||
for (int x = 1; x < rows; x++) {
|
||||
graphics.fillRect(cells[x].x() - gapSize, 0, gapSize, height);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
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;
|
||||
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;
|
||||
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);
|
||||
}
|
||||
graphics.setFill(color);
|
||||
graphics.fillRect(x, y, width, height);
|
||||
}
|
||||
|
||||
public void resize(int width, int height) {
|
||||
canvas.setWidth(width);
|
||||
canvas.setHeight(height);
|
||||
public void resize(int width, int height) {
|
||||
canvas.setWidth(width);
|
||||
canvas.setHeight(height);
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
clear();
|
||||
render();
|
||||
}
|
||||
clear();
|
||||
render();
|
||||
}
|
||||
|
||||
public Canvas getCanvas() {
|
||||
return canvas;
|
||||
}
|
||||
}
|
||||
public Canvas getCanvas() {
|
||||
return canvas;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,37 @@
|
||||
package org.toop.app.canvas;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class TicTacToeCanvas extends GameCanvas {
|
||||
public TicTacToeCanvas(Color color, int width, int height, Consumer<Integer> onCellClicked) {
|
||||
super(color, width, height, 3, 3, 10, false, onCellClicked);
|
||||
}
|
||||
public TicTacToeCanvas(Color color, int width, int height, Consumer<Integer> onCellClicked) {
|
||||
super(color, width, height, 3, 3, 10, false, onCellClicked);
|
||||
}
|
||||
|
||||
public void drawX(Color color, int cell) {
|
||||
graphics.setStroke(color);
|
||||
graphics.setLineWidth(gapSize);
|
||||
public void drawX(Color color, int cell) {
|
||||
graphics.setStroke(color);
|
||||
graphics.setLineWidth(gapSize);
|
||||
|
||||
final float x = cells[cell].x() + gapSize;
|
||||
final float y = cells[cell].y() + gapSize;
|
||||
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;
|
||||
final float width = cells[cell].width() - gapSize * 2;
|
||||
final float height = cells[cell].height() - gapSize * 2;
|
||||
|
||||
graphics.strokeLine(x, y, x + width, y + height);
|
||||
graphics.strokeLine(x + width, y, x, y + height);
|
||||
}
|
||||
graphics.strokeLine(x, y, x + width, y + height);
|
||||
graphics.strokeLine(x + width, y, x, y + height);
|
||||
}
|
||||
|
||||
public void drawO(Color color, int cell) {
|
||||
graphics.setStroke(color);
|
||||
graphics.setLineWidth(gapSize);
|
||||
public void drawO(Color color, int cell) {
|
||||
graphics.setStroke(color);
|
||||
graphics.setLineWidth(gapSize);
|
||||
|
||||
final float x = cells[cell].x() + gapSize;
|
||||
final float y = cells[cell].y() + gapSize;
|
||||
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;
|
||||
final float width = cells[cell].width() - gapSize * 2;
|
||||
final float height = cells[cell].height() - gapSize * 2;
|
||||
|
||||
graphics.strokeOval(x, y, width, height);
|
||||
}
|
||||
}
|
||||
graphics.strokeOval(x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,9 @@ import javafx.scene.Node;
|
||||
import javafx.scene.layout.Region;
|
||||
|
||||
public abstract class Container {
|
||||
public abstract Region getContainer();
|
||||
public abstract Region getContainer();
|
||||
|
||||
public abstract void addNodes(Node... nodes);
|
||||
public abstract void addContainer(Container container, boolean fill);
|
||||
}
|
||||
public abstract void addNodes(Node... nodes);
|
||||
|
||||
public abstract void addContainer(Container container, boolean fill);
|
||||
}
|
||||
|
||||
@@ -1,81 +1,86 @@
|
||||
package org.toop.app.layer;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.canvas.GameCanvas;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.canvas.GameCanvas;
|
||||
|
||||
public abstract class Layer {
|
||||
protected StackPane layer;
|
||||
protected Region background;
|
||||
protected StackPane layer;
|
||||
protected Region background;
|
||||
|
||||
protected Layer(String... backgroundStyles) {
|
||||
layer = new StackPane();
|
||||
protected Layer(String... backgroundStyles) {
|
||||
layer = new StackPane();
|
||||
|
||||
background = new Region();
|
||||
background.getStyleClass().addAll(backgroundStyles);
|
||||
background.setPrefSize(Double.MAX_VALUE, Double.MAX_VALUE);
|
||||
background = new Region();
|
||||
background.getStyleClass().addAll(backgroundStyles);
|
||||
background.setPrefSize(Double.MAX_VALUE, Double.MAX_VALUE);
|
||||
|
||||
layer.getChildren().addLast(background);
|
||||
}
|
||||
layer.getChildren().addLast(background);
|
||||
}
|
||||
|
||||
protected void addContainer(Container container, Pos position, int xOffset, int yOffset, int widthPercent, int heightPercent) {
|
||||
StackPane.setAlignment(container.getContainer(), position);
|
||||
protected void addContainer(
|
||||
Container container,
|
||||
Pos position,
|
||||
int xOffset,
|
||||
int yOffset,
|
||||
int widthPercent,
|
||||
int heightPercent) {
|
||||
StackPane.setAlignment(container.getContainer(), position);
|
||||
|
||||
final double widthUnit = App.getWidth() / 100.0;
|
||||
final double heightUnit = App.getHeight() / 100.0;
|
||||
final double widthUnit = App.getWidth() / 100.0;
|
||||
final double heightUnit = App.getHeight() / 100.0;
|
||||
|
||||
if (widthPercent > 0) {
|
||||
container.getContainer().setMaxWidth(widthPercent * widthUnit);
|
||||
} else {
|
||||
container.getContainer().setMaxWidth(Region.USE_PREF_SIZE);
|
||||
}
|
||||
if (widthPercent > 0) {
|
||||
container.getContainer().setMaxWidth(widthPercent * widthUnit);
|
||||
} else {
|
||||
container.getContainer().setMaxWidth(Region.USE_PREF_SIZE);
|
||||
}
|
||||
|
||||
if (heightPercent > 0) {
|
||||
container.getContainer().setMaxHeight(heightPercent * heightUnit);
|
||||
} else {
|
||||
container.getContainer().setMaxHeight(Region.USE_PREF_SIZE);
|
||||
}
|
||||
if (heightPercent > 0) {
|
||||
container.getContainer().setMaxHeight(heightPercent * heightUnit);
|
||||
} else {
|
||||
container.getContainer().setMaxHeight(Region.USE_PREF_SIZE);
|
||||
}
|
||||
|
||||
container.getContainer().setTranslateX(xOffset * widthUnit);
|
||||
container.getContainer().setTranslateY(yOffset * heightUnit);
|
||||
container.getContainer().setTranslateX(xOffset * widthUnit);
|
||||
container.getContainer().setTranslateY(yOffset * heightUnit);
|
||||
|
||||
layer.getChildren().addLast(container.getContainer());
|
||||
}
|
||||
layer.getChildren().addLast(container.getContainer());
|
||||
}
|
||||
|
||||
protected void addGameCanvas(GameCanvas canvas, Pos position, int xOffset, int yOffset) {
|
||||
StackPane.setAlignment(canvas.getCanvas(), position);
|
||||
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;
|
||||
final double widthUnit = App.getWidth() / 100.0;
|
||||
final double heightUnit = App.getHeight() / 100.0;
|
||||
|
||||
canvas.getCanvas().setTranslateX(xOffset * widthUnit);
|
||||
canvas.getCanvas().setTranslateY(yOffset * heightUnit);
|
||||
canvas.getCanvas().setTranslateX(xOffset * widthUnit);
|
||||
canvas.getCanvas().setTranslateY(yOffset * heightUnit);
|
||||
|
||||
layer.getChildren().addLast(canvas.getCanvas());
|
||||
}
|
||||
layer.getChildren().addLast(canvas.getCanvas());
|
||||
}
|
||||
|
||||
protected void pop() {
|
||||
if (layer.getChildren().size() <= 1) {
|
||||
return;
|
||||
}
|
||||
protected void pop() {
|
||||
if (layer.getChildren().size() <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
layer.getChildren().removeLast();
|
||||
}
|
||||
layer.getChildren().removeLast();
|
||||
}
|
||||
|
||||
protected void popAll() {
|
||||
final int containers = layer.getChildren().size();
|
||||
protected void popAll() {
|
||||
final int containers = layer.getChildren().size();
|
||||
|
||||
for (int i = 1; i < containers; i++) {
|
||||
layer.getChildren().removeLast();
|
||||
}
|
||||
}
|
||||
for (int i = 1; i < containers; i++) {
|
||||
layer.getChildren().removeLast();
|
||||
}
|
||||
}
|
||||
|
||||
public StackPane getLayer() {
|
||||
return layer;
|
||||
}
|
||||
public StackPane getLayer() {
|
||||
return layer;
|
||||
}
|
||||
|
||||
public abstract void reload();
|
||||
}
|
||||
public abstract void reload();
|
||||
}
|
||||
|
||||
@@ -1,131 +1,140 @@
|
||||
package org.toop.app.layer;
|
||||
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.geometry.Orientation;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.text.Text;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
|
||||
public final class NodeBuilder {
|
||||
public static void addCss(Node node, String... cssClasses) {
|
||||
node.getStyleClass().addAll(cssClasses);
|
||||
}
|
||||
public static void addCss(Node node, String... cssClasses) {
|
||||
node.getStyleClass().addAll(cssClasses);
|
||||
}
|
||||
|
||||
public static void setCss(Node node, String... cssClasses) {
|
||||
node.getStyleClass().removeAll();
|
||||
node.getStyleClass().addAll(cssClasses);
|
||||
}
|
||||
public static void setCss(Node node, String... cssClasses) {
|
||||
node.getStyleClass().removeAll();
|
||||
node.getStyleClass().addAll(cssClasses);
|
||||
}
|
||||
|
||||
public static Text header(String x) {
|
||||
final Text element = new Text(x);
|
||||
setCss(element, "text-primary", "text-header");
|
||||
public static Text header(String x) {
|
||||
final Text element = new Text(x);
|
||||
setCss(element, "text-primary", "text-header");
|
||||
|
||||
return element;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public static Text text(String x) {
|
||||
final Text element = new Text(x);
|
||||
setCss(element, "text-secondary", "text-normal");
|
||||
public static Text text(String x) {
|
||||
final Text element = new Text(x);
|
||||
setCss(element, "text-secondary", "text-normal");
|
||||
|
||||
return element;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public static Label button(String x, Runnable runnable) {
|
||||
final Label element = new Label(x);
|
||||
setCss(element, "button", "text-normal");
|
||||
public static Label button(String x, Runnable runnable) {
|
||||
final Label element = new Label(x);
|
||||
setCss(element, "button", "text-normal");
|
||||
|
||||
element.setOnMouseClicked(_ -> {
|
||||
new EventFlow().addPostEvent(new AudioEvents.ClickButton()).asyncPostEvent();
|
||||
runnable.run();
|
||||
});
|
||||
element.setOnMouseClicked(
|
||||
_ -> {
|
||||
new EventFlow().addPostEvent(new AudioEvents.ClickButton()).asyncPostEvent();
|
||||
runnable.run();
|
||||
});
|
||||
|
||||
return element;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public static Label toggle(String x1, String x2, boolean toggled, Consumer<Boolean> consumer) {
|
||||
final Label element = new Label(toggled ? x2 : x1);
|
||||
setCss(element, "toggle", "text-normal");
|
||||
public static Label toggle(String x1, String x2, boolean toggled, Consumer<Boolean> consumer) {
|
||||
final Label element = new Label(toggled ? x2 : x1);
|
||||
setCss(element, "toggle", "text-normal");
|
||||
|
||||
final BooleanProperty checked = new SimpleBooleanProperty(toggled);
|
||||
final BooleanProperty checked = new SimpleBooleanProperty(toggled);
|
||||
|
||||
element.setOnMouseClicked(_ -> {
|
||||
new EventFlow().addPostEvent(new AudioEvents.ClickButton()).asyncPostEvent();
|
||||
checked.set(!checked.get());
|
||||
element.setOnMouseClicked(
|
||||
_ -> {
|
||||
new EventFlow().addPostEvent(new AudioEvents.ClickButton()).asyncPostEvent();
|
||||
checked.set(!checked.get());
|
||||
|
||||
if (checked.get()) {
|
||||
element.setText(x1);
|
||||
} else {
|
||||
element.setText(x2);
|
||||
}
|
||||
if (checked.get()) {
|
||||
element.setText(x1);
|
||||
} else {
|
||||
element.setText(x2);
|
||||
}
|
||||
|
||||
consumer.accept(checked.get());
|
||||
});
|
||||
consumer.accept(checked.get());
|
||||
});
|
||||
|
||||
return element;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public static Slider slider(int max, int initial, Consumer<Integer> consumer) {
|
||||
final Slider element = new Slider(0, max, initial);
|
||||
setCss(element, "bg-slider-track");
|
||||
public static Slider slider(int max, int initial, Consumer<Integer> consumer) {
|
||||
final Slider element = new Slider(0, max, initial);
|
||||
setCss(element, "bg-slider-track");
|
||||
|
||||
element.setMinorTickCount(0);
|
||||
element.setMajorTickUnit(1);
|
||||
element.setBlockIncrement(1);
|
||||
element.setMinorTickCount(0);
|
||||
element.setMajorTickUnit(1);
|
||||
element.setBlockIncrement(1);
|
||||
|
||||
element.setSnapToTicks(true);
|
||||
element.setShowTickLabels(true);
|
||||
element.setSnapToTicks(true);
|
||||
element.setShowTickLabels(true);
|
||||
|
||||
element.setOnMouseClicked(_ -> {
|
||||
new EventFlow().addPostEvent(new AudioEvents.ClickButton()).asyncPostEvent();
|
||||
});
|
||||
element.setOnMouseClicked(
|
||||
_ -> {
|
||||
new EventFlow().addPostEvent(new AudioEvents.ClickButton()).asyncPostEvent();
|
||||
});
|
||||
|
||||
element.valueProperty().addListener((_, _, newValue) -> {
|
||||
consumer.accept(newValue.intValue());
|
||||
});
|
||||
element.valueProperty()
|
||||
.addListener(
|
||||
(_, _, newValue) -> {
|
||||
consumer.accept(newValue.intValue());
|
||||
});
|
||||
|
||||
return element;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public static TextField input(String x, Consumer<String> consumer) {
|
||||
final TextField element = new TextField(x);
|
||||
setCss(element, "input", "text-normal");
|
||||
public static TextField input(String x, Consumer<String> consumer) {
|
||||
final TextField element = new TextField(x);
|
||||
setCss(element, "input", "text-normal");
|
||||
|
||||
element.setOnMouseClicked(_ -> {
|
||||
new EventFlow().addPostEvent(new AudioEvents.ClickButton()).asyncPostEvent();
|
||||
});
|
||||
element.setOnMouseClicked(
|
||||
_ -> {
|
||||
new EventFlow().addPostEvent(new AudioEvents.ClickButton()).asyncPostEvent();
|
||||
});
|
||||
|
||||
element.textProperty().addListener((_, _, newValue) -> {
|
||||
consumer.accept(newValue);
|
||||
});
|
||||
element.textProperty()
|
||||
.addListener(
|
||||
(_, _, newValue) -> {
|
||||
consumer.accept(newValue);
|
||||
});
|
||||
|
||||
return element;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public static <T> ChoiceBox<T> choiceBox(Consumer<T> consumer) {
|
||||
final ChoiceBox<T> element = new ChoiceBox<>();
|
||||
setCss(element, "choice-box", "text-normal");
|
||||
public static <T> ChoiceBox<T> choiceBox(Consumer<T> consumer) {
|
||||
final ChoiceBox<T> element = new ChoiceBox<>();
|
||||
setCss(element, "choice-box", "text-normal");
|
||||
|
||||
element.setOnMouseClicked(_ -> {
|
||||
new EventFlow().addPostEvent(new AudioEvents.ClickButton()).asyncPostEvent();
|
||||
});
|
||||
element.setOnMouseClicked(
|
||||
_ -> {
|
||||
new EventFlow().addPostEvent(new AudioEvents.ClickButton()).asyncPostEvent();
|
||||
});
|
||||
|
||||
element.valueProperty().addListener((_, _, newValue) -> {
|
||||
consumer.accept(newValue);
|
||||
});
|
||||
element.valueProperty()
|
||||
.addListener(
|
||||
(_, _, newValue) -> {
|
||||
consumer.accept(newValue);
|
||||
});
|
||||
|
||||
return element;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public static Separator separator() {
|
||||
final Separator element = new Separator(Orientation.HORIZONTAL);
|
||||
setCss(element, "separator");
|
||||
public static Separator separator() {
|
||||
final Separator element = new Separator(Orientation.HORIZONTAL);
|
||||
setCss(element, "separator");
|
||||
|
||||
return element;
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,17 +3,18 @@ package org.toop.app.layer;
|
||||
import org.toop.app.App;
|
||||
|
||||
public abstract class Popup extends Layer {
|
||||
protected Popup(boolean popOnBackground, String... backgroundStyles) {
|
||||
super(backgroundStyles);
|
||||
protected Popup(boolean popOnBackground, String... backgroundStyles) {
|
||||
super(backgroundStyles);
|
||||
|
||||
if (popOnBackground) {
|
||||
background.setOnMouseClicked(_ -> {
|
||||
App.pop();
|
||||
});
|
||||
}
|
||||
}
|
||||
if (popOnBackground) {
|
||||
background.setOnMouseClicked(
|
||||
_ -> {
|
||||
App.pop();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected Popup(boolean popOnBackground) {
|
||||
this(popOnBackground, "bg-popup");
|
||||
}
|
||||
}
|
||||
protected Popup(boolean popOnBackground) {
|
||||
this(popOnBackground, "bg-popup");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +1,59 @@
|
||||
package org.toop.app.layer.containers;
|
||||
|
||||
import org.toop.app.layer.Container;
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
import org.toop.app.layer.Container;
|
||||
|
||||
public final class HorizontalContainer extends Container {
|
||||
private final HBox container;
|
||||
private final HBox container;
|
||||
|
||||
public HorizontalContainer(int spacing, String... cssClasses) {
|
||||
container = new HBox(spacing);
|
||||
container.getStyleClass().addAll(cssClasses);
|
||||
}
|
||||
public HorizontalContainer(int spacing, String... cssClasses) {
|
||||
container = new HBox(spacing);
|
||||
container.getStyleClass().addAll(cssClasses);
|
||||
}
|
||||
|
||||
public HorizontalContainer(int spacing) {
|
||||
this(spacing, "container");
|
||||
}
|
||||
public HorizontalContainer(int spacing) {
|
||||
this(spacing, "container");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Region getContainer() {
|
||||
return container;
|
||||
}
|
||||
@Override
|
||||
public Region getContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNodes(Node... nodes) {
|
||||
container.getChildren().addAll(nodes);
|
||||
}
|
||||
@Override
|
||||
public void addNodes(Node... nodes) {
|
||||
container.getChildren().addAll(nodes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addContainer(Container container, boolean fill) {
|
||||
if (fill) {
|
||||
container.getContainer().setMinSize(0, 0);
|
||||
container.getContainer().setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
|
||||
HBox.setHgrow(container.getContainer(), Priority.ALWAYS);
|
||||
} else {
|
||||
container.getContainer().setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
|
||||
}
|
||||
@Override
|
||||
public void addContainer(Container container, boolean fill) {
|
||||
if (fill) {
|
||||
container.getContainer().setMinSize(0, 0);
|
||||
container.getContainer().setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
|
||||
HBox.setHgrow(container.getContainer(), Priority.ALWAYS);
|
||||
} else {
|
||||
container.getContainer().setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
|
||||
}
|
||||
|
||||
this.container.getChildren().add(container.getContainer());
|
||||
this.container.getChildren().add(container.getContainer());
|
||||
|
||||
if (fill) {
|
||||
balanceChildWidths();
|
||||
}
|
||||
}
|
||||
if (fill) {
|
||||
balanceChildWidths();
|
||||
}
|
||||
}
|
||||
|
||||
private void balanceChildWidths() {
|
||||
final ObservableList<Node> children = container.getChildren();
|
||||
final double widthPerChild = container.getWidth() / children.size();
|
||||
private void balanceChildWidths() {
|
||||
final ObservableList<Node> children = container.getChildren();
|
||||
final double widthPerChild = container.getWidth() / children.size();
|
||||
|
||||
for (final Node child : children) {
|
||||
if (child instanceof Region) {
|
||||
((Region) child).setPrefWidth(widthPerChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final Node child : children) {
|
||||
if (child instanceof Region) {
|
||||
((Region) child).setPrefWidth(widthPerChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +1,59 @@
|
||||
package org.toop.app.layer.containers;
|
||||
|
||||
import org.toop.app.layer.Container;
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.toop.app.layer.Container;
|
||||
|
||||
public final class VerticalContainer extends Container {
|
||||
private final VBox container;
|
||||
private final VBox container;
|
||||
|
||||
public VerticalContainer(int spacing, String... cssClasses) {
|
||||
container = new VBox(spacing);
|
||||
container.getStyleClass().addAll(cssClasses);
|
||||
}
|
||||
public VerticalContainer(int spacing, String... cssClasses) {
|
||||
container = new VBox(spacing);
|
||||
container.getStyleClass().addAll(cssClasses);
|
||||
}
|
||||
|
||||
public VerticalContainer(int spacing) {
|
||||
this(spacing, "container");
|
||||
}
|
||||
public VerticalContainer(int spacing) {
|
||||
this(spacing, "container");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Region getContainer() {
|
||||
return container;
|
||||
}
|
||||
@Override
|
||||
public Region getContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNodes(Node... nodes) {
|
||||
container.getChildren().addAll(nodes);
|
||||
}
|
||||
@Override
|
||||
public void addNodes(Node... nodes) {
|
||||
container.getChildren().addAll(nodes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addContainer(Container container, boolean fill) {
|
||||
if (fill) {
|
||||
container.getContainer().setMinSize(0, 0);
|
||||
container.getContainer().setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
|
||||
VBox.setVgrow(container.getContainer(), Priority.ALWAYS);
|
||||
} else {
|
||||
container.getContainer().setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
|
||||
}
|
||||
@Override
|
||||
public void addContainer(Container container, boolean fill) {
|
||||
if (fill) {
|
||||
container.getContainer().setMinSize(0, 0);
|
||||
container.getContainer().setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
|
||||
VBox.setVgrow(container.getContainer(), Priority.ALWAYS);
|
||||
} else {
|
||||
container.getContainer().setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
|
||||
}
|
||||
|
||||
this.container.getChildren().add(container.getContainer());
|
||||
this.container.getChildren().add(container.getContainer());
|
||||
|
||||
if (fill) {
|
||||
balanceChildHeights();
|
||||
}
|
||||
}
|
||||
if (fill) {
|
||||
balanceChildHeights();
|
||||
}
|
||||
}
|
||||
|
||||
private void balanceChildHeights() {
|
||||
final ObservableList<Node> children = container.getChildren();
|
||||
final double heightPerChild = container.getHeight() / children.size();
|
||||
private void balanceChildHeights() {
|
||||
final ObservableList<Node> children = container.getChildren();
|
||||
final double heightPerChild = container.getHeight() / children.size();
|
||||
|
||||
for (final Node child : children) {
|
||||
if (child instanceof Region) {
|
||||
((Region) child).setPrefHeight(heightPerChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final Node child : children) {
|
||||
if (child instanceof Region) {
|
||||
((Region) child).setPrefHeight(heightPerChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
package org.toop.app.layer.layers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListView;
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.GameInformation;
|
||||
import org.toop.app.layer.Container;
|
||||
@@ -14,169 +22,214 @@ import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.networking.events.NetworkEvents;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListView;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public final class ConnectedLayer extends Layer {
|
||||
private static Timer pollTimer = new Timer();
|
||||
private static Timer pollTimer = new Timer();
|
||||
|
||||
private static class ChallengePopup extends Popup {
|
||||
private final GameInformation information;
|
||||
private static class ChallengePopup extends Popup {
|
||||
private final GameInformation information;
|
||||
|
||||
private final String challenger;
|
||||
private final String game;
|
||||
private final String challenger;
|
||||
private final String game;
|
||||
|
||||
private final long clientID;
|
||||
private final int challengeID;
|
||||
private final long clientID;
|
||||
private final int challengeID;
|
||||
|
||||
public ChallengePopup(GameInformation information, String challenger, String game, long clientID, String challengeID) {
|
||||
super(false, "bg-popup");
|
||||
public ChallengePopup(
|
||||
GameInformation information,
|
||||
String challenger,
|
||||
String game,
|
||||
long clientID,
|
||||
String challengeID) {
|
||||
super(false, "bg-popup");
|
||||
|
||||
this.information = information;
|
||||
this.information = information;
|
||||
|
||||
this.challenger = challenger;
|
||||
this.game = game;
|
||||
this.challenger = challenger;
|
||||
this.game = game;
|
||||
|
||||
this.clientID = clientID;
|
||||
this.challengeID = Integer.parseInt(challengeID.substring(18, challengeID.length() - 2));
|
||||
this.clientID = clientID;
|
||||
this.challengeID =
|
||||
Integer.parseInt(challengeID.substring(18, challengeID.length() - 2));
|
||||
|
||||
reload();
|
||||
}
|
||||
reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
|
||||
final var challengeText = NodeBuilder.header(AppContext.getString("challengeText"));
|
||||
final var challengerNameText = NodeBuilder.header(challenger);
|
||||
final var challengeText = NodeBuilder.header(AppContext.getString("challengeText"));
|
||||
final var challengerNameText = NodeBuilder.header(challenger);
|
||||
|
||||
final var gameText = NodeBuilder.text(AppContext.getString("gameIsText"));
|
||||
final var gameNameText = NodeBuilder.text(game);
|
||||
final var gameText = NodeBuilder.text(AppContext.getString("gameIsText"));
|
||||
final var gameNameText = NodeBuilder.text(game);
|
||||
|
||||
final var acceptButton = NodeBuilder.button(AppContext.getString("accept"), () -> {
|
||||
pollTimer.cancel();
|
||||
final var acceptButton =
|
||||
NodeBuilder.button(
|
||||
AppContext.getString("accept"),
|
||||
() -> {
|
||||
pollTimer.cancel();
|
||||
|
||||
new EventFlow().addPostEvent(new NetworkEvents.SendAcceptChallenge(clientID, challengeID)).postEvent();
|
||||
App.activate(new TicTacToeLayer(information, clientID));
|
||||
});
|
||||
new EventFlow()
|
||||
.addPostEvent(
|
||||
new NetworkEvents.SendAcceptChallenge(
|
||||
clientID, challengeID))
|
||||
.postEvent();
|
||||
App.activate(new TicTacToeLayer(information, clientID));
|
||||
});
|
||||
|
||||
final var denyButton = NodeBuilder.button(AppContext.getString("deny"), () -> {
|
||||
App.pop();
|
||||
});
|
||||
final var denyButton =
|
||||
NodeBuilder.button(
|
||||
AppContext.getString("deny"),
|
||||
() -> {
|
||||
App.pop();
|
||||
});
|
||||
|
||||
final Container controlContainer = new HorizontalContainer(30);
|
||||
controlContainer.addNodes(acceptButton, denyButton);
|
||||
final Container controlContainer = new HorizontalContainer(30);
|
||||
controlContainer.addNodes(acceptButton, denyButton);
|
||||
|
||||
final Container mainContainer = new VerticalContainer(30);
|
||||
mainContainer.addNodes(challengeText, challengerNameText);
|
||||
mainContainer.addNodes(gameText, gameNameText);
|
||||
final Container mainContainer = new VerticalContainer(30);
|
||||
mainContainer.addNodes(challengeText, challengerNameText);
|
||||
mainContainer.addNodes(gameText, gameNameText);
|
||||
|
||||
mainContainer.addContainer(controlContainer, false);
|
||||
mainContainer.addContainer(controlContainer, false);
|
||||
|
||||
addContainer(mainContainer, Pos.CENTER, 0, 0, 30, 30);
|
||||
}
|
||||
}
|
||||
addContainer(mainContainer, Pos.CENTER, 0, 0, 30, 30);
|
||||
}
|
||||
}
|
||||
|
||||
GameInformation information;
|
||||
long clientId;
|
||||
String user;
|
||||
List<String> onlinePlayers = new CopyOnWriteArrayList<>();
|
||||
GameInformation information;
|
||||
long clientId;
|
||||
String user;
|
||||
List<String> onlinePlayers = new CopyOnWriteArrayList<>();
|
||||
|
||||
public ConnectedLayer(GameInformation information) {
|
||||
super("bg-primary");
|
||||
public ConnectedLayer(GameInformation information) {
|
||||
super("bg-primary");
|
||||
|
||||
this.information = information;
|
||||
this.information = information;
|
||||
|
||||
new EventFlow()
|
||||
.addPostEvent(NetworkEvents.StartClient.class, information.serverIP(), Integer.parseInt(information.serverPort()))
|
||||
.onResponse(NetworkEvents.StartClientResponse.class, e -> {
|
||||
clientId = e.clientId();
|
||||
user = information.playerName()[0].replaceAll("\\s+", "");
|
||||
new EventFlow()
|
||||
.addPostEvent(
|
||||
NetworkEvents.StartClient.class,
|
||||
information.serverIP(),
|
||||
Integer.parseInt(information.serverPort()))
|
||||
.onResponse(
|
||||
NetworkEvents.StartClientResponse.class,
|
||||
e -> {
|
||||
clientId = e.clientId();
|
||||
user = information.playerName()[0].replaceAll("\\s+", "");
|
||||
|
||||
new EventFlow().addPostEvent(new NetworkEvents.SendLogin(this.clientId, this.user)).postEvent();
|
||||
new EventFlow()
|
||||
.addPostEvent(
|
||||
new NetworkEvents.SendLogin(this.clientId, this.user))
|
||||
.postEvent();
|
||||
|
||||
Thread popThread = new Thread(this::populatePlayerList);
|
||||
popThread.setDaemon(false);
|
||||
popThread.start();
|
||||
}).postEvent();
|
||||
Thread popThread = new Thread(this::populatePlayerList);
|
||||
popThread.setDaemon(false);
|
||||
popThread.start();
|
||||
})
|
||||
.postEvent();
|
||||
|
||||
new EventFlow().listen(this::handleReceivedChallenge);
|
||||
new EventFlow().listen(this::handleReceivedChallenge);
|
||||
|
||||
reload();
|
||||
}
|
||||
}
|
||||
|
||||
private void populatePlayerList() {
|
||||
EventFlow sendGetPlayerList = new EventFlow().addPostEvent(new NetworkEvents.SendGetPlayerlist(this.clientId));
|
||||
new EventFlow().listen(NetworkEvents.PlayerlistResponse.class, e -> {
|
||||
if (e.clientId() == this.clientId) {
|
||||
List<String> playerList = new java.util.ArrayList<>(List.of(e.playerlist())); // TODO: Garbage, but works
|
||||
playerList.removeIf(name -> name.equalsIgnoreCase(user));
|
||||
if (this.onlinePlayers != playerList) {
|
||||
this.onlinePlayers.clear();
|
||||
this.onlinePlayers.addAll(playerList);
|
||||
}
|
||||
}
|
||||
});
|
||||
private void populatePlayerList() {
|
||||
EventFlow sendGetPlayerList =
|
||||
new EventFlow().addPostEvent(new NetworkEvents.SendGetPlayerlist(this.clientId));
|
||||
new EventFlow()
|
||||
.listen(
|
||||
NetworkEvents.PlayerlistResponse.class,
|
||||
e -> {
|
||||
if (e.clientId() == this.clientId) {
|
||||
List<String> playerList =
|
||||
new java.util.ArrayList<>(
|
||||
List.of(e.playerlist())); // TODO: Garbage,
|
||||
// but works
|
||||
playerList.removeIf(name -> name.equalsIgnoreCase(user));
|
||||
if (this.onlinePlayers != playerList) {
|
||||
this.onlinePlayers.clear();
|
||||
this.onlinePlayers.addAll(playerList);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
TimerTask task = new TimerTask() {
|
||||
public void run() {
|
||||
sendGetPlayerList.postEvent();
|
||||
Platform.runLater(() -> reload());
|
||||
}
|
||||
};
|
||||
TimerTask task =
|
||||
new TimerTask() {
|
||||
public void run() {
|
||||
sendGetPlayerList.postEvent();
|
||||
Platform.runLater(() -> reload());
|
||||
}
|
||||
};
|
||||
|
||||
pollTimer.schedule(task, 0L, 5000L); // TODO: Block app exit, fix later
|
||||
}
|
||||
pollTimer.schedule(task, 0L, 5000L); // TODO: Block app exit, fix later
|
||||
}
|
||||
|
||||
private void sendChallenge(String oppUsername, String gameType) {
|
||||
final AtomicInteger challengeId = new AtomicInteger(-1);
|
||||
private void sendChallenge(String oppUsername, String gameType) {
|
||||
final AtomicInteger challengeId = new AtomicInteger(-1);
|
||||
|
||||
if (onlinePlayers.contains(oppUsername)) {
|
||||
new EventFlow().addPostEvent(new NetworkEvents.SendChallenge(this.clientId, oppUsername, gameType))
|
||||
.listen(NetworkEvents.ChallengeResponse.class, e -> {
|
||||
challengeId.set(Integer.parseInt(e.challengeId().substring(18, e.challengeId().length() - 2)));
|
||||
})
|
||||
.listen(NetworkEvents.GameMatchResponse.class, e -> {
|
||||
if (e.clientId() == this.clientId) {
|
||||
pollTimer.cancel();
|
||||
App.activate(new TicTacToeLayer(information, this.clientId));
|
||||
}
|
||||
}, false).postEvent();
|
||||
// ^
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
}
|
||||
}
|
||||
if (onlinePlayers.contains(oppUsername)) {
|
||||
new EventFlow()
|
||||
.addPostEvent(
|
||||
new NetworkEvents.SendChallenge(this.clientId, oppUsername, gameType))
|
||||
.listen(
|
||||
NetworkEvents.ChallengeResponse.class,
|
||||
e -> {
|
||||
challengeId.set(
|
||||
Integer.parseInt(
|
||||
e.challengeId()
|
||||
.substring(
|
||||
18, e.challengeId().length() - 2)));
|
||||
})
|
||||
.listen(
|
||||
NetworkEvents.GameMatchResponse.class,
|
||||
e -> {
|
||||
if (e.clientId() == this.clientId) {
|
||||
pollTimer.cancel();
|
||||
App.activate(new TicTacToeLayer(information, this.clientId));
|
||||
}
|
||||
},
|
||||
false)
|
||||
.postEvent();
|
||||
// ^
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
}
|
||||
}
|
||||
|
||||
private void handleReceivedChallenge(NetworkEvents.ChallengeResponse response) {
|
||||
App.push(new ChallengePopup(information, response.challengerName(), response.gameType(), clientId, response.challengeId()));
|
||||
}
|
||||
private void handleReceivedChallenge(NetworkEvents.ChallengeResponse response) {
|
||||
App.push(
|
||||
new ChallengePopup(
|
||||
information,
|
||||
response.challengerName(),
|
||||
response.gameType(),
|
||||
clientId,
|
||||
response.challengeId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
|
||||
ListView<Label> players = new ListView<>();
|
||||
ListView<Label> players = new ListView<>();
|
||||
|
||||
for (int i = 0; i < onlinePlayers.size(); i++) {
|
||||
for (int i = 0; i < onlinePlayers.size(); i++) {
|
||||
int finalI = i;
|
||||
players.getItems().add(NodeBuilder.button(onlinePlayers.get(i), () -> {
|
||||
String clickedPlayer = onlinePlayers.get(finalI);
|
||||
sendChallenge(clickedPlayer, "tic-tac-toe");
|
||||
}));
|
||||
}
|
||||
players.getItems()
|
||||
.add(
|
||||
NodeBuilder.button(
|
||||
onlinePlayers.get(i),
|
||||
() -> {
|
||||
String clickedPlayer = onlinePlayers.get(finalI);
|
||||
sendChallenge(clickedPlayer, "tic-tac-toe");
|
||||
}));
|
||||
}
|
||||
|
||||
final Container playersContainer = new VerticalContainer(10);
|
||||
playersContainer.addNodes(players);
|
||||
final Container playersContainer = new VerticalContainer(10);
|
||||
playersContainer.addNodes(players);
|
||||
|
||||
addContainer(playersContainer, Pos.CENTER, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
addContainer(playersContainer, Pos.CENTER, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package org.toop.app.layer.layers;
|
||||
|
||||
import javafx.animation.PauseTransition;
|
||||
import javafx.animation.TranslateTransition;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.util.Duration;
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.layer.Container;
|
||||
import org.toop.app.layer.NodeBuilder;
|
||||
@@ -8,65 +13,61 @@ 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.scene.text.Text;
|
||||
import javafx.util.Duration;
|
||||
|
||||
public final class CreditsPopup extends Popup {
|
||||
private final int lineHeight = 100;
|
||||
private final int lineHeight = 100;
|
||||
|
||||
public CreditsPopup() {
|
||||
super(true, "bg-primary");
|
||||
reload();
|
||||
}
|
||||
public CreditsPopup() {
|
||||
super(true, "bg-primary");
|
||||
reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
@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 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 Text[] creditsHeaders = new Text[credits.length];
|
||||
final Text[] creditsHeaders = new Text[credits.length];
|
||||
|
||||
for (int i = 0; i < credits.length; i++) {
|
||||
creditsHeaders[i] = NodeBuilder.header(credits[i]);
|
||||
}
|
||||
for (int i = 0; i < credits.length; i++) {
|
||||
creditsHeaders[i] = NodeBuilder.header(credits[i]);
|
||||
}
|
||||
|
||||
final Container creditsContainer = new HorizontalContainer(0);
|
||||
final Container creditsContainer = new HorizontalContainer(0);
|
||||
|
||||
final Container animatedContainer = new VerticalContainer(lineHeight);
|
||||
creditsContainer.addContainer(animatedContainer, true);
|
||||
final Container animatedContainer = new VerticalContainer(lineHeight);
|
||||
creditsContainer.addContainer(animatedContainer, true);
|
||||
|
||||
animatedContainer.addNodes(creditsHeaders);
|
||||
addContainer(creditsContainer, Pos.CENTER, 0, 0, 50, 100);
|
||||
animatedContainer.addNodes(creditsHeaders);
|
||||
addContainer(creditsContainer, Pos.CENTER, 0, 0, 50, 100);
|
||||
|
||||
playCredits(animatedContainer, App.getHeight());
|
||||
}
|
||||
playCredits(animatedContainer, App.getHeight());
|
||||
}
|
||||
|
||||
private void playCredits(Container container, double sceneLength) {
|
||||
container.getContainer().setTranslateY(-sceneLength);
|
||||
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);
|
||||
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.setOnFinished(
|
||||
_ -> {
|
||||
final PauseTransition pauseCredits = new PauseTransition(Duration.seconds(3));
|
||||
pauseCredits.setOnFinished(_ -> playCredits(container, sceneLength));
|
||||
pauseCredits.play();
|
||||
});
|
||||
|
||||
scrollCredits.play();
|
||||
}
|
||||
}
|
||||
scrollCredits.play();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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;
|
||||
@@ -7,45 +8,58 @@ import org.toop.app.layer.NodeBuilder;
|
||||
import org.toop.app.layer.containers.VerticalContainer;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
public final class MainLayer extends Layer {
|
||||
public MainLayer() {
|
||||
super("bg-primary");
|
||||
reload();
|
||||
}
|
||||
public MainLayer() {
|
||||
super("bg-primary");
|
||||
reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
|
||||
final var tictactoeButton = NodeBuilder.button(AppContext.getString("tictactoe"), () -> {
|
||||
App.activate(new MultiplayerLayer());
|
||||
});
|
||||
final var tictactoeButton =
|
||||
NodeBuilder.button(
|
||||
AppContext.getString("tictactoe"),
|
||||
() -> {
|
||||
App.activate(new MultiplayerLayer());
|
||||
});
|
||||
|
||||
final var othelloButton = NodeBuilder.button(AppContext.getString("othello"), () -> {
|
||||
App.activate(new MultiplayerLayer());
|
||||
});
|
||||
final var othelloButton =
|
||||
NodeBuilder.button(
|
||||
AppContext.getString("othello"),
|
||||
() -> {
|
||||
App.activate(new MultiplayerLayer());
|
||||
});
|
||||
|
||||
final var creditsButton = NodeBuilder.button(AppContext.getString("credits"), () -> {
|
||||
App.push(new CreditsPopup());
|
||||
});
|
||||
final var creditsButton =
|
||||
NodeBuilder.button(
|
||||
AppContext.getString("credits"),
|
||||
() -> {
|
||||
App.push(new CreditsPopup());
|
||||
});
|
||||
|
||||
final var optionsButton = NodeBuilder.button(AppContext.getString("options"), () -> {
|
||||
App.push(new OptionsPopup());
|
||||
});
|
||||
final var optionsButton =
|
||||
NodeBuilder.button(
|
||||
AppContext.getString("options"),
|
||||
() -> {
|
||||
App.push(new OptionsPopup());
|
||||
});
|
||||
|
||||
final var quitButton = NodeBuilder.button(AppContext.getString("quit"), () -> {
|
||||
App.quitPopup();
|
||||
});
|
||||
final var quitButton =
|
||||
NodeBuilder.button(
|
||||
AppContext.getString("quit"),
|
||||
() -> {
|
||||
App.quitPopup();
|
||||
});
|
||||
|
||||
final Container gamesContainer = new VerticalContainer(5);
|
||||
gamesContainer.addNodes(tictactoeButton, othelloButton);
|
||||
final Container gamesContainer = new VerticalContainer(5);
|
||||
gamesContainer.addNodes(tictactoeButton, othelloButton);
|
||||
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
controlContainer.addNodes(creditsButton, optionsButton, quitButton);
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
controlContainer.addNodes(creditsButton, optionsButton, quitButton);
|
||||
|
||||
addContainer(gamesContainer, Pos.TOP_LEFT, 2, 2, 20, 0);
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2, 20, 0);
|
||||
}
|
||||
}
|
||||
addContainer(gamesContainer, Pos.TOP_LEFT, 2, 2, 20, 0);
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2, 20, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.toop.app.layer.layers;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import javafx.geometry.Pos;
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.GameInformation;
|
||||
import org.toop.app.layer.Container;
|
||||
@@ -10,167 +12,230 @@ import org.toop.app.layer.containers.VerticalContainer;
|
||||
import org.toop.app.layer.layers.game.TicTacToeLayer;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public final class MultiplayerLayer extends Layer {
|
||||
private boolean isConnectionLocal = true;
|
||||
private boolean isConnectionLocal = true;
|
||||
|
||||
private boolean isPlayer1Human = true;
|
||||
private String player1Name = "";
|
||||
private int computer1Difficulty = 0;
|
||||
private int computer1ThinkTime = 0;
|
||||
private boolean isPlayer1Human = true;
|
||||
private String player1Name = "";
|
||||
private int computer1Difficulty = 0;
|
||||
private int computer1ThinkTime = 0;
|
||||
|
||||
private boolean isPlayer2Human = true;
|
||||
private String player2Name = "";
|
||||
private int computer2Difficulty = 0;
|
||||
private int computer2ThinkTime = 0;
|
||||
private boolean isPlayer2Human = true;
|
||||
private String player2Name = "";
|
||||
private int computer2Difficulty = 0;
|
||||
private int computer2ThinkTime = 0;
|
||||
|
||||
private String serverIP = "";
|
||||
private String serverPort = "";
|
||||
private String serverIP = "";
|
||||
private String serverPort = "";
|
||||
|
||||
public MultiplayerLayer() {
|
||||
super("bg-primary");
|
||||
reload();
|
||||
}
|
||||
public MultiplayerLayer() {
|
||||
super("bg-primary");
|
||||
reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
|
||||
final Container player1Container = new VerticalContainer(20);
|
||||
final Container player2Container = new VerticalContainer(20);
|
||||
final Container player1Container = new VerticalContainer(20);
|
||||
final Container player2Container = new VerticalContainer(20);
|
||||
|
||||
final var isPlayer1HumanToggle = NodeBuilder.toggle(AppContext.getString("human"), AppContext.getString("computer"), !isPlayer1Human, (computer) -> {
|
||||
isPlayer1Human = !computer;
|
||||
reload();
|
||||
});
|
||||
final var isPlayer1HumanToggle =
|
||||
NodeBuilder.toggle(
|
||||
AppContext.getString("human"),
|
||||
AppContext.getString("computer"),
|
||||
!isPlayer1Human,
|
||||
(computer) -> {
|
||||
isPlayer1Human = !computer;
|
||||
reload();
|
||||
});
|
||||
|
||||
player1Container.addNodes(isPlayer1HumanToggle);
|
||||
player1Container.addNodes(isPlayer1HumanToggle);
|
||||
|
||||
if (isPlayer1Human) {
|
||||
final var playerNameText = NodeBuilder.text(AppContext.getString("playerName"));
|
||||
final var playerNameInput = NodeBuilder.input(player1Name, (name) -> {
|
||||
player1Name = name;
|
||||
});
|
||||
if (isPlayer1Human) {
|
||||
final var playerNameText = NodeBuilder.text(AppContext.getString("playerName"));
|
||||
final var playerNameInput =
|
||||
NodeBuilder.input(
|
||||
player1Name,
|
||||
(name) -> {
|
||||
player1Name = name;
|
||||
});
|
||||
|
||||
player1Container.addNodes(playerNameText, playerNameInput);
|
||||
} else {
|
||||
player1Name = "Pism Bot V" + LocalDateTime.now().getSecond();
|
||||
player1Container.addNodes(playerNameText, playerNameInput);
|
||||
} else {
|
||||
player1Name = "Pism Bot V" + LocalDateTime.now().getSecond();
|
||||
|
||||
final var computerNameText = NodeBuilder.text(player1Name);
|
||||
final var computerNameSeparator = NodeBuilder.separator();
|
||||
final var computerNameText = NodeBuilder.text(player1Name);
|
||||
final var computerNameSeparator = NodeBuilder.separator();
|
||||
|
||||
final var computerDifficultyText = NodeBuilder.text(AppContext.getString("computerDifficulty"));
|
||||
final var computerDifficultySeparator = NodeBuilder.separator();
|
||||
final var computerDifficultySlider = NodeBuilder.slider(10, computer1Difficulty, (difficulty) ->
|
||||
computer1Difficulty = difficulty);
|
||||
final var computerDifficultyText =
|
||||
NodeBuilder.text(AppContext.getString("computerDifficulty"));
|
||||
final var computerDifficultySeparator = NodeBuilder.separator();
|
||||
final var computerDifficultySlider =
|
||||
NodeBuilder.slider(
|
||||
10,
|
||||
computer1Difficulty,
|
||||
(difficulty) -> computer1Difficulty = difficulty);
|
||||
|
||||
final var computerThinkTimeText = NodeBuilder.text(AppContext.getString("computerThinkTime"));
|
||||
final var computerThinkTimeSlider = NodeBuilder.slider(5, computer1ThinkTime, (thinkTime) ->
|
||||
computer1ThinkTime = thinkTime);
|
||||
final var computerThinkTimeText =
|
||||
NodeBuilder.text(AppContext.getString("computerThinkTime"));
|
||||
final var computerThinkTimeSlider =
|
||||
NodeBuilder.slider(
|
||||
5, computer1ThinkTime, (thinkTime) -> computer1ThinkTime = thinkTime);
|
||||
|
||||
player1Container.addNodes(computerNameText, computerNameSeparator,
|
||||
computerDifficultyText, computerDifficultySlider, computerDifficultySeparator,
|
||||
computerThinkTimeText, computerThinkTimeSlider);
|
||||
}
|
||||
player1Container.addNodes(
|
||||
computerNameText,
|
||||
computerNameSeparator,
|
||||
computerDifficultyText,
|
||||
computerDifficultySlider,
|
||||
computerDifficultySeparator,
|
||||
computerThinkTimeText,
|
||||
computerThinkTimeSlider);
|
||||
}
|
||||
|
||||
if (isConnectionLocal) {
|
||||
final var isPlayer2HumanToggle = NodeBuilder.toggle(AppContext.getString("human"), AppContext.getString("computer"), !isPlayer2Human, (computer) -> {
|
||||
isPlayer2Human = !computer;
|
||||
reload();
|
||||
});
|
||||
if (isConnectionLocal) {
|
||||
final var isPlayer2HumanToggle =
|
||||
NodeBuilder.toggle(
|
||||
AppContext.getString("human"),
|
||||
AppContext.getString("computer"),
|
||||
!isPlayer2Human,
|
||||
(computer) -> {
|
||||
isPlayer2Human = !computer;
|
||||
reload();
|
||||
});
|
||||
|
||||
player2Container.addNodes(isPlayer2HumanToggle);
|
||||
player2Container.addNodes(isPlayer2HumanToggle);
|
||||
|
||||
if (isPlayer2Human) {
|
||||
final var playerNameText = NodeBuilder.text(AppContext.getString("playerName"));
|
||||
final var playerNameInput = NodeBuilder.input(player2Name, (name) -> {
|
||||
player2Name = name;
|
||||
});
|
||||
if (isPlayer2Human) {
|
||||
final var playerNameText = NodeBuilder.text(AppContext.getString("playerName"));
|
||||
final var playerNameInput =
|
||||
NodeBuilder.input(
|
||||
player2Name,
|
||||
(name) -> {
|
||||
player2Name = name;
|
||||
});
|
||||
|
||||
player2Container.addNodes(playerNameText, playerNameInput);
|
||||
} else {
|
||||
player2Name = "Pism Bot V" + LocalDateTime.now().getSecond();
|
||||
player2Container.addNodes(playerNameText, playerNameInput);
|
||||
} else {
|
||||
player2Name = "Pism Bot V" + LocalDateTime.now().getSecond();
|
||||
|
||||
final var computerNameText = NodeBuilder.text(player2Name);
|
||||
final var computerNameSeparator = NodeBuilder.separator();
|
||||
final var computerNameText = NodeBuilder.text(player2Name);
|
||||
final var computerNameSeparator = NodeBuilder.separator();
|
||||
|
||||
final var computerDifficultyText = NodeBuilder.text(AppContext.getString("computerDifficulty"));
|
||||
final var computerDifficultySeparator = NodeBuilder.separator();
|
||||
final var computerDifficultySlider = NodeBuilder.slider(10, computer2Difficulty, (difficulty) ->
|
||||
computer2Difficulty = difficulty);
|
||||
final var computerDifficultyText =
|
||||
NodeBuilder.text(AppContext.getString("computerDifficulty"));
|
||||
final var computerDifficultySeparator = NodeBuilder.separator();
|
||||
final var computerDifficultySlider =
|
||||
NodeBuilder.slider(
|
||||
10,
|
||||
computer2Difficulty,
|
||||
(difficulty) -> computer2Difficulty = difficulty);
|
||||
|
||||
final var computerThinkTimeText = NodeBuilder.text(AppContext.getString("computerThinkTime"));
|
||||
final var computerThinkTimeSlider = NodeBuilder.slider(5, computer2ThinkTime, (thinkTime) ->
|
||||
computer2ThinkTime = thinkTime);
|
||||
final var computerThinkTimeText =
|
||||
NodeBuilder.text(AppContext.getString("computerThinkTime"));
|
||||
final var computerThinkTimeSlider =
|
||||
NodeBuilder.slider(
|
||||
5,
|
||||
computer2ThinkTime,
|
||||
(thinkTime) -> computer2ThinkTime = thinkTime);
|
||||
|
||||
player2Container.addNodes(computerNameText, computerNameSeparator,
|
||||
computerDifficultyText, computerDifficultySlider, computerDifficultySeparator,
|
||||
computerThinkTimeText, computerThinkTimeSlider);
|
||||
}
|
||||
} else {
|
||||
final var serverIPText = NodeBuilder.text(AppContext.getString("serverIP"));
|
||||
final var serverIPSeparator = NodeBuilder.separator();
|
||||
final var serverIPInput = NodeBuilder.input(serverIP, (ip) -> {
|
||||
serverIP = ip;
|
||||
});
|
||||
player2Container.addNodes(
|
||||
computerNameText,
|
||||
computerNameSeparator,
|
||||
computerDifficultyText,
|
||||
computerDifficultySlider,
|
||||
computerDifficultySeparator,
|
||||
computerThinkTimeText,
|
||||
computerThinkTimeSlider);
|
||||
}
|
||||
} else {
|
||||
final var serverIPText = NodeBuilder.text(AppContext.getString("serverIP"));
|
||||
final var serverIPSeparator = NodeBuilder.separator();
|
||||
final var serverIPInput =
|
||||
NodeBuilder.input(
|
||||
serverIP,
|
||||
(ip) -> {
|
||||
serverIP = ip;
|
||||
});
|
||||
|
||||
final var serverPortText = NodeBuilder.text(AppContext.getString("serverPort"));
|
||||
final var serverPortInput = NodeBuilder.input(serverPort, (port) -> {
|
||||
serverPort = port;
|
||||
});
|
||||
final var serverPortText = NodeBuilder.text(AppContext.getString("serverPort"));
|
||||
final var serverPortInput =
|
||||
NodeBuilder.input(
|
||||
serverPort,
|
||||
(port) -> {
|
||||
serverPort = port;
|
||||
});
|
||||
|
||||
player2Container.addNodes(serverIPText, serverIPInput, serverIPSeparator,
|
||||
serverPortText, serverPortInput);
|
||||
}
|
||||
player2Container.addNodes(
|
||||
serverIPText,
|
||||
serverIPInput,
|
||||
serverIPSeparator,
|
||||
serverPortText,
|
||||
serverPortInput);
|
||||
}
|
||||
|
||||
final var versusText = NodeBuilder.header("VS");
|
||||
final var versusText = NodeBuilder.header("VS");
|
||||
|
||||
final var connectionTypeText = NodeBuilder.text(AppContext.getString("connectionType") + ":");
|
||||
final var connectionTypeToggle = NodeBuilder.toggle(AppContext.getString("local"), AppContext.getString("server"), !isConnectionLocal, (server) -> {
|
||||
isConnectionLocal = !server;
|
||||
reload();
|
||||
});
|
||||
final var connectionTypeText =
|
||||
NodeBuilder.text(AppContext.getString("connectionType") + ":");
|
||||
final var connectionTypeToggle =
|
||||
NodeBuilder.toggle(
|
||||
AppContext.getString("local"),
|
||||
AppContext.getString("server"),
|
||||
!isConnectionLocal,
|
||||
(server) -> {
|
||||
isConnectionLocal = !server;
|
||||
reload();
|
||||
});
|
||||
|
||||
final var playButton = NodeBuilder.button(isConnectionLocal ? AppContext.getString("start") : AppContext.getString("connect"), () -> {
|
||||
final var information = new GameInformation(
|
||||
new String[]{player1Name, player2Name},
|
||||
new boolean[]{isPlayer1Human, isPlayer2Human},
|
||||
new int[]{computer1Difficulty, computer2Difficulty},
|
||||
new int[]{computer1ThinkTime, computer2ThinkTime},
|
||||
isConnectionLocal, serverIP, serverPort);
|
||||
final var playButton =
|
||||
NodeBuilder.button(
|
||||
isConnectionLocal
|
||||
? AppContext.getString("start")
|
||||
: AppContext.getString("connect"),
|
||||
() -> {
|
||||
final var information =
|
||||
new GameInformation(
|
||||
new String[] {player1Name, player2Name},
|
||||
new boolean[] {isPlayer1Human, isPlayer2Human},
|
||||
new int[] {computer1Difficulty, computer2Difficulty},
|
||||
new int[] {computer1ThinkTime, computer2ThinkTime},
|
||||
isConnectionLocal,
|
||||
serverIP,
|
||||
serverPort);
|
||||
|
||||
if (isConnectionLocal) {
|
||||
App.activate(new TicTacToeLayer(information));
|
||||
} else {
|
||||
App.activate(new ConnectedLayer(information));
|
||||
}
|
||||
});
|
||||
if (isConnectionLocal) {
|
||||
App.activate(new TicTacToeLayer(information));
|
||||
} else {
|
||||
App.activate(new ConnectedLayer(information));
|
||||
}
|
||||
});
|
||||
|
||||
final Container mainContainer = new VerticalContainer(10);
|
||||
final Container playersContainer = new HorizontalContainer(5);
|
||||
final Container connectionTypeContainer = new HorizontalContainer(10);
|
||||
final Container mainContainer = new VerticalContainer(10);
|
||||
final Container playersContainer = new HorizontalContainer(5);
|
||||
final Container connectionTypeContainer = new HorizontalContainer(10);
|
||||
|
||||
mainContainer.addContainer(playersContainer, true);
|
||||
mainContainer.addContainer(connectionTypeContainer, false);
|
||||
mainContainer.addNodes(playButton);
|
||||
mainContainer.addContainer(playersContainer, true);
|
||||
mainContainer.addContainer(connectionTypeContainer, false);
|
||||
mainContainer.addNodes(playButton);
|
||||
|
||||
connectionTypeContainer.addNodes(connectionTypeText, connectionTypeToggle);
|
||||
connectionTypeContainer.addNodes(connectionTypeText, connectionTypeToggle);
|
||||
|
||||
playersContainer.addContainer(player1Container, true);
|
||||
playersContainer.addNodes(versusText);
|
||||
playersContainer.addContainer(player2Container, true);
|
||||
playersContainer.addContainer(player1Container, true);
|
||||
playersContainer.addNodes(versusText);
|
||||
playersContainer.addContainer(player2Container, true);
|
||||
|
||||
final var backButton = NodeBuilder.button(AppContext.getString("back"), () -> {
|
||||
App.activate(new MainLayer());
|
||||
});
|
||||
final var backButton =
|
||||
NodeBuilder.button(
|
||||
AppContext.getString("back"),
|
||||
() -> {
|
||||
App.activate(new MainLayer());
|
||||
});
|
||||
|
||||
final Container controlContainer = new VerticalContainer(0);
|
||||
controlContainer.addNodes(backButton);
|
||||
final Container controlContainer = new VerticalContainer(0);
|
||||
controlContainer.addNodes(backButton);
|
||||
|
||||
addContainer(mainContainer, Pos.CENTER, 0, 0, 75, 75);
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2, 0, 0);
|
||||
}
|
||||
}
|
||||
addContainer(mainContainer, Pos.CENTER, 0, 0, 75, 75);
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package org.toop.app.layer.layers;
|
||||
|
||||
import java.util.Locale;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.ChoiceBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Slider;
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.layer.Container;
|
||||
import org.toop.app.layer.NodeBuilder;
|
||||
@@ -11,32 +16,25 @@ import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.local.AppContext;
|
||||
import org.toop.local.AppSettings;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.ChoiceBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Slider;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public final class OptionsPopup extends Popup {
|
||||
AppSettings appSettings = new AppSettings();
|
||||
SettingsAsset settings = appSettings.getPath();
|
||||
private boolean isWindowed = !(settings.getFullscreen());
|
||||
private boolean isWindowed = !(settings.getFullscreen());
|
||||
|
||||
public OptionsPopup() {
|
||||
super(true, "bg-primary");
|
||||
reload();
|
||||
}
|
||||
public OptionsPopup() {
|
||||
super(true, "bg-primary");
|
||||
reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
|
||||
final var languageHeader = NodeBuilder.header(AppContext.getString("language"));
|
||||
final var languageSeparator = NodeBuilder.separator();
|
||||
final var languageHeader = NodeBuilder.header(AppContext.getString("language"));
|
||||
final var languageSeparator = NodeBuilder.separator();
|
||||
|
||||
final var volumeHeader = NodeBuilder.header(AppContext.getString("volume"));
|
||||
final var volumeSeparator = NodeBuilder.separator();
|
||||
final var volumeHeader = NodeBuilder.header(AppContext.getString("volume"));
|
||||
final var volumeSeparator = NodeBuilder.separator();
|
||||
|
||||
final var fxVolumeHeader = NodeBuilder.header(AppContext.getString("effectsVolume"));
|
||||
final var fxVolumeSeparator = NodeBuilder.separator();
|
||||
@@ -44,151 +42,181 @@ public final class OptionsPopup extends Popup {
|
||||
final var musicVolumeHeader = NodeBuilder.header(AppContext.getString("musicVolume"));
|
||||
final var musicVolumeSeparator = NodeBuilder.separator();
|
||||
|
||||
final var themeHeader = NodeBuilder.header(AppContext.getString("theme"));
|
||||
final var themeSeparator = NodeBuilder.separator();
|
||||
final var themeHeader = NodeBuilder.header(AppContext.getString("theme"));
|
||||
final var themeSeparator = NodeBuilder.separator();
|
||||
|
||||
final var layoutSizeHeader = NodeBuilder.header(AppContext.getString("layoutSize"));
|
||||
final var layoutSizeSeparator = NodeBuilder.separator();
|
||||
final var layoutSizeHeader = NodeBuilder.header(AppContext.getString("layoutSize"));
|
||||
final var layoutSizeSeparator = NodeBuilder.separator();
|
||||
|
||||
final var optionsContainer = new VerticalContainer(5);
|
||||
optionsContainer.addNodes(languageHeader, languageChoiceBox(), languageSeparator);
|
||||
optionsContainer.addNodes(volumeHeader, volumeSlider(), volumeSeparator);
|
||||
final var optionsContainer = new VerticalContainer(5);
|
||||
optionsContainer.addNodes(languageHeader, languageChoiceBox(), languageSeparator);
|
||||
optionsContainer.addNodes(volumeHeader, volumeSlider(), volumeSeparator);
|
||||
optionsContainer.addNodes(fxVolumeHeader, fxVolumeSlider(), fxVolumeSeparator);
|
||||
optionsContainer.addNodes(musicVolumeHeader, musicVolumeSlider(), musicVolumeSeparator);
|
||||
optionsContainer.addNodes(themeHeader, themeChoiceBox(), themeSeparator);
|
||||
optionsContainer.addNodes(layoutSizeHeader, layoutSizeChoiceBox(), layoutSizeSeparator);
|
||||
optionsContainer.addNodes(fullscreenToggle());
|
||||
optionsContainer.addNodes(themeHeader, themeChoiceBox(), themeSeparator);
|
||||
optionsContainer.addNodes(layoutSizeHeader, layoutSizeChoiceBox(), layoutSizeSeparator);
|
||||
optionsContainer.addNodes(fullscreenToggle());
|
||||
|
||||
final Container mainContainer = new VerticalContainer(50, "");
|
||||
mainContainer.addContainer(optionsContainer, true);
|
||||
final Container mainContainer = new VerticalContainer(50, "");
|
||||
mainContainer.addContainer(optionsContainer, true);
|
||||
|
||||
final var backButton = NodeBuilder.button(AppContext.getString("back"), () -> {
|
||||
App.pop();
|
||||
});
|
||||
final var backButton =
|
||||
NodeBuilder.button(
|
||||
AppContext.getString("back"),
|
||||
() -> {
|
||||
App.pop();
|
||||
});
|
||||
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
controlContainer.addNodes(backButton);
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
controlContainer.addNodes(backButton);
|
||||
|
||||
addContainer(mainContainer, Pos.CENTER, 0, 0, 0, 0);
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2, 0, 0);
|
||||
}
|
||||
addContainer(mainContainer, Pos.CENTER, 0, 0, 0, 0);
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2, 0, 0);
|
||||
}
|
||||
|
||||
private ChoiceBox<Locale> languageChoiceBox() {
|
||||
assert AppContext.getLocalization() != null;
|
||||
private ChoiceBox<Locale> languageChoiceBox() {
|
||||
assert AppContext.getLocalization() != null;
|
||||
|
||||
final ChoiceBox<Locale> languageChoiceBox = NodeBuilder.choiceBox((locale) -> {
|
||||
if (locale == AppContext.getLocale()) {
|
||||
return;
|
||||
}
|
||||
final ChoiceBox<Locale> languageChoiceBox =
|
||||
NodeBuilder.choiceBox(
|
||||
(locale) -> {
|
||||
if (locale == AppContext.getLocale()) {
|
||||
return;
|
||||
}
|
||||
|
||||
settings.setLocale(locale.toString());
|
||||
AppContext.setLocale(locale);
|
||||
settings.setLocale(locale.toString());
|
||||
AppContext.setLocale(locale);
|
||||
|
||||
App.reloadAll();
|
||||
});
|
||||
App.reloadAll();
|
||||
});
|
||||
|
||||
languageChoiceBox.setConverter(new javafx.util.StringConverter<>() {
|
||||
@Override
|
||||
public String toString(Locale locale) {
|
||||
return AppContext.getString(locale.getDisplayName().toLowerCase());
|
||||
}
|
||||
languageChoiceBox.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;
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public Locale fromString(String string) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
languageChoiceBox.getItems().addAll(AppContext.getLocalization().getAvailableLocales());
|
||||
languageChoiceBox.setValue(AppContext.getLocale());
|
||||
languageChoiceBox.getItems().addAll(AppContext.getLocalization().getAvailableLocales());
|
||||
languageChoiceBox.setValue(AppContext.getLocale());
|
||||
|
||||
return languageChoiceBox;
|
||||
}
|
||||
return languageChoiceBox;
|
||||
}
|
||||
|
||||
private Slider volumeSlider() {
|
||||
return NodeBuilder.slider(100, settings.getVolume(), (volume) -> {
|
||||
settings.setVolume(volume);
|
||||
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(volume.doubleValue())).asyncPostEvent();
|
||||
});
|
||||
}
|
||||
private Slider volumeSlider() {
|
||||
return NodeBuilder.slider(
|
||||
100,
|
||||
settings.getVolume(),
|
||||
(volume) -> {
|
||||
settings.setVolume(volume);
|
||||
new EventFlow()
|
||||
.addPostEvent(new AudioEvents.ChangeVolume(volume.doubleValue()))
|
||||
.asyncPostEvent();
|
||||
});
|
||||
}
|
||||
|
||||
private Slider fxVolumeSlider() {
|
||||
return NodeBuilder.slider(100, settings.getFxVolume(), (volume) -> {
|
||||
settings.setFxVolume(volume);
|
||||
new EventFlow().addPostEvent(new AudioEvents.ChangeFxVolume(volume.doubleValue())).asyncPostEvent();
|
||||
});
|
||||
return NodeBuilder.slider(
|
||||
100,
|
||||
settings.getFxVolume(),
|
||||
(volume) -> {
|
||||
settings.setFxVolume(volume);
|
||||
new EventFlow()
|
||||
.addPostEvent(new AudioEvents.ChangeFxVolume(volume.doubleValue()))
|
||||
.asyncPostEvent();
|
||||
});
|
||||
}
|
||||
|
||||
private Slider musicVolumeSlider() {
|
||||
return NodeBuilder.slider(100, settings.getMusicVolume(), (volume) -> {
|
||||
settings.setMusicVolume(volume);
|
||||
new EventFlow().addPostEvent(new AudioEvents.ChangeMusicVolume(volume.doubleValue())).asyncPostEvent();
|
||||
});
|
||||
return NodeBuilder.slider(
|
||||
100,
|
||||
settings.getMusicVolume(),
|
||||
(volume) -> {
|
||||
settings.setMusicVolume(volume);
|
||||
new EventFlow()
|
||||
.addPostEvent(new AudioEvents.ChangeMusicVolume(volume.doubleValue()))
|
||||
.asyncPostEvent();
|
||||
});
|
||||
}
|
||||
|
||||
private Label fullscreenToggle() {
|
||||
return NodeBuilder.toggle(
|
||||
AppContext.getString("windowed"),
|
||||
AppContext.getString("fullscreen"),
|
||||
!isWindowed,
|
||||
(fullscreen) -> {
|
||||
isWindowed = !fullscreen;
|
||||
|
||||
private Label fullscreenToggle() {
|
||||
return NodeBuilder.toggle(AppContext.getString("windowed"), AppContext.getString("fullscreen"), !isWindowed, (fullscreen) -> {
|
||||
isWindowed = !fullscreen;
|
||||
settings.setFullscreen(fullscreen);
|
||||
App.setFullscreen(fullscreen);
|
||||
});
|
||||
}
|
||||
|
||||
settings.setFullscreen(fullscreen);
|
||||
App.setFullscreen(fullscreen);
|
||||
});
|
||||
}
|
||||
private ChoiceBox<String> themeChoiceBox() {
|
||||
final ChoiceBox<String> themeChoiceBox =
|
||||
NodeBuilder.choiceBox(
|
||||
(theme) -> {
|
||||
if (theme.equalsIgnoreCase(settings.getTheme())) {
|
||||
return;
|
||||
}
|
||||
|
||||
private ChoiceBox<String> themeChoiceBox() {
|
||||
final ChoiceBox<String> themeChoiceBox = NodeBuilder.choiceBox((theme) -> {
|
||||
if (theme.equalsIgnoreCase(settings.getTheme())) {
|
||||
return;
|
||||
}
|
||||
settings.setTheme(theme);
|
||||
App.setStyle(theme, settings.getLayoutSize());
|
||||
});
|
||||
|
||||
settings.setTheme(theme);
|
||||
App.setStyle(theme, settings.getLayoutSize());
|
||||
});
|
||||
themeChoiceBox.setConverter(
|
||||
new javafx.util.StringConverter<>() {
|
||||
@Override
|
||||
public String toString(String theme) {
|
||||
return AppContext.getString(theme);
|
||||
}
|
||||
|
||||
themeChoiceBox.setConverter(new javafx.util.StringConverter<>() {
|
||||
@Override
|
||||
public String toString(String theme) {
|
||||
return AppContext.getString(theme);
|
||||
}
|
||||
@Override
|
||||
public String fromString(String string) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public String fromString(String string) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
themeChoiceBox.getItems().addAll("dark", "light", "dark-hc", "light-hc");
|
||||
themeChoiceBox.setValue(settings.getTheme());
|
||||
|
||||
themeChoiceBox.getItems().addAll("dark", "light", "dark-hc", "light-hc");
|
||||
themeChoiceBox.setValue(settings.getTheme());
|
||||
return themeChoiceBox;
|
||||
}
|
||||
|
||||
return themeChoiceBox;
|
||||
}
|
||||
private ChoiceBox<String> layoutSizeChoiceBox() {
|
||||
final ChoiceBox<String> layoutSizeChoiceBox =
|
||||
NodeBuilder.choiceBox(
|
||||
(layoutSize) -> {
|
||||
if (layoutSize.equalsIgnoreCase(settings.getLayoutSize())) {
|
||||
return;
|
||||
}
|
||||
|
||||
private ChoiceBox<String> layoutSizeChoiceBox() {
|
||||
final ChoiceBox<String> layoutSizeChoiceBox = NodeBuilder.choiceBox((layoutSize) -> {
|
||||
if (layoutSize.equalsIgnoreCase(settings.getLayoutSize())) {
|
||||
return;
|
||||
}
|
||||
settings.setLayoutSize(layoutSize);
|
||||
App.setStyle(settings.getTheme(), layoutSize);
|
||||
});
|
||||
|
||||
settings.setLayoutSize(layoutSize);
|
||||
App.setStyle(settings.getTheme(), layoutSize);
|
||||
});
|
||||
layoutSizeChoiceBox.setConverter(
|
||||
new javafx.util.StringConverter<>() {
|
||||
@Override
|
||||
public String toString(String layoutSize) {
|
||||
return AppContext.getString(layoutSize);
|
||||
}
|
||||
|
||||
layoutSizeChoiceBox.setConverter(new javafx.util.StringConverter<>() {
|
||||
@Override
|
||||
public String toString(String layoutSize) {
|
||||
return AppContext.getString(layoutSize);
|
||||
}
|
||||
@Override
|
||||
public String fromString(String string) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public String fromString(String string) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
layoutSizeChoiceBox.getItems().addAll("small", "medium", "large");
|
||||
layoutSizeChoiceBox.setValue(settings.getLayoutSize());
|
||||
|
||||
layoutSizeChoiceBox.getItems().addAll("small", "medium", "large");
|
||||
layoutSizeChoiceBox.setValue(settings.getLayoutSize());
|
||||
|
||||
return layoutSizeChoiceBox;
|
||||
}
|
||||
}
|
||||
return layoutSizeChoiceBox;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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.NodeBuilder;
|
||||
@@ -8,35 +9,39 @@ 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 QuitPopup extends Popup {
|
||||
public QuitPopup() {
|
||||
super(true);
|
||||
reload();
|
||||
}
|
||||
public QuitPopup() {
|
||||
super(true);
|
||||
reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
|
||||
final var sureText = NodeBuilder.header(AppContext.getString("quitSure"));
|
||||
final var sureText = NodeBuilder.header(AppContext.getString("quitSure"));
|
||||
|
||||
final var yesButton = NodeBuilder.button(AppContext.getString("yes"), () -> {
|
||||
App.quit();
|
||||
});
|
||||
final var yesButton =
|
||||
NodeBuilder.button(
|
||||
AppContext.getString("yes"),
|
||||
() -> {
|
||||
App.quit();
|
||||
});
|
||||
|
||||
final var noButton = NodeBuilder.button(AppContext.getString("no"), () -> {
|
||||
App.pop();
|
||||
});
|
||||
final var noButton =
|
||||
NodeBuilder.button(
|
||||
AppContext.getString("no"),
|
||||
() -> {
|
||||
App.pop();
|
||||
});
|
||||
|
||||
final Container controlContainer = new HorizontalContainer(30);
|
||||
controlContainer.addNodes(yesButton, noButton);
|
||||
final Container controlContainer = new HorizontalContainer(30);
|
||||
controlContainer.addNodes(yesButton, noButton);
|
||||
|
||||
final Container mainContainer = new VerticalContainer(30);
|
||||
mainContainer.addNodes(sureText);
|
||||
mainContainer.addContainer(controlContainer, false);
|
||||
final Container mainContainer = new VerticalContainer(30);
|
||||
mainContainer.addNodes(sureText);
|
||||
mainContainer.addContainer(controlContainer, false);
|
||||
|
||||
addContainer(mainContainer, Pos.CENTER, 0, 0, 30, 30);
|
||||
}
|
||||
}
|
||||
addContainer(mainContainer, Pos.CENTER, 0, 0, 30, 30);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.toop.app.layer.layers.game;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.layer.Container;
|
||||
import org.toop.app.layer.NodeBuilder;
|
||||
@@ -8,45 +9,47 @@ import org.toop.app.layer.containers.VerticalContainer;
|
||||
import org.toop.app.layer.layers.MainLayer;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
public class GameFinishedPopup extends Popup {
|
||||
private final boolean isDraw;
|
||||
private final String winner;
|
||||
private final boolean isDraw;
|
||||
private final String winner;
|
||||
|
||||
public GameFinishedPopup(boolean isDraw, String winner) {
|
||||
super(true, "bg-popup");
|
||||
public GameFinishedPopup(boolean isDraw, String winner) {
|
||||
super(true, "bg-popup");
|
||||
|
||||
this.isDraw = isDraw;
|
||||
this.winner = winner;
|
||||
this.isDraw = isDraw;
|
||||
this.winner = winner;
|
||||
|
||||
reload();
|
||||
}
|
||||
reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
|
||||
final Container mainContainer = new VerticalContainer(30);
|
||||
final Container mainContainer = new VerticalContainer(30);
|
||||
|
||||
if (isDraw) {
|
||||
final var drawHeader = NodeBuilder.header(AppContext.getString("drawText"));
|
||||
final var goodGameText = NodeBuilder.text(AppContext.getString("goodGameText"));
|
||||
if (isDraw) {
|
||||
final var drawHeader = NodeBuilder.header(AppContext.getString("drawText"));
|
||||
final var goodGameText = NodeBuilder.text(AppContext.getString("goodGameText"));
|
||||
|
||||
mainContainer.addNodes(drawHeader, goodGameText);
|
||||
} else {
|
||||
final var winHeader = NodeBuilder.header(AppContext.getString("congratulations") + ": " + winner);
|
||||
final var goodGameText = NodeBuilder.text(AppContext.getString("goodGameText"));
|
||||
mainContainer.addNodes(drawHeader, goodGameText);
|
||||
} else {
|
||||
final var winHeader =
|
||||
NodeBuilder.header(AppContext.getString("congratulations") + ": " + winner);
|
||||
final var goodGameText = NodeBuilder.text(AppContext.getString("goodGameText"));
|
||||
|
||||
mainContainer.addNodes(winHeader, goodGameText);
|
||||
}
|
||||
mainContainer.addNodes(winHeader, goodGameText);
|
||||
}
|
||||
|
||||
final var backToMainMenuButton = NodeBuilder.button(AppContext.getString("backToMainMenu"), () -> {
|
||||
App.activate(new MainLayer());
|
||||
});
|
||||
final var backToMainMenuButton =
|
||||
NodeBuilder.button(
|
||||
AppContext.getString("backToMainMenu"),
|
||||
() -> {
|
||||
App.activate(new MainLayer());
|
||||
});
|
||||
|
||||
mainContainer.addNodes(backToMainMenuButton);
|
||||
mainContainer.addNodes(backToMainMenuButton);
|
||||
|
||||
addContainer(mainContainer, Pos.CENTER, 0, 0, 30, 30);
|
||||
}
|
||||
}
|
||||
addContainer(mainContainer, Pos.CENTER, 0, 0, 30, 30);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package org.toop.app.layer.layers.game;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.text.Text;
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.GameInformation;
|
||||
@@ -17,280 +23,307 @@ import org.toop.game.tictactoe.TicTacToe;
|
||||
import org.toop.game.tictactoe.TicTacToeAI;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public final class TicTacToeLayer extends Layer {
|
||||
private TicTacToeCanvas canvas;
|
||||
private TicTacToeCanvas canvas;
|
||||
|
||||
private AtomicReference<TicTacToe> ticTacToe;
|
||||
private TicTacToeAI ticTacToeAI;
|
||||
private AtomicReference<TicTacToe> ticTacToe;
|
||||
private TicTacToeAI ticTacToeAI;
|
||||
|
||||
private GameInformation information;
|
||||
private GameInformation information;
|
||||
|
||||
private final Text currentPlayerNameText;
|
||||
private final Text currentPlayerMoveText;
|
||||
private final Text currentPlayerNameText;
|
||||
private final Text currentPlayerMoveText;
|
||||
|
||||
private final BlockingQueue<Game.Move> playerMoveQueue = new LinkedBlockingQueue<>();
|
||||
private final BlockingQueue<Game.Move> playerMoveQueue = new LinkedBlockingQueue<>();
|
||||
|
||||
// Todo: set these from the server
|
||||
private char currentPlayerMove = Game.EMPTY;
|
||||
private String player2Name = "";
|
||||
// Todo: set these from the server
|
||||
private char currentPlayerMove = Game.EMPTY;
|
||||
private String player2Name = "";
|
||||
|
||||
final AtomicBoolean firstPlayerIsMe = new AtomicBoolean(true);
|
||||
final AtomicBoolean firstPlayerIsMe = new AtomicBoolean(true);
|
||||
|
||||
public TicTacToeLayer(GameInformation information) {
|
||||
super("bg-primary");
|
||||
public TicTacToeLayer(GameInformation information) {
|
||||
super("bg-primary");
|
||||
|
||||
canvas = new TicTacToeCanvas(Color.LIME, (App.getHeight() / 100) * 75, (App.getHeight() / 100) * 75, (cell) -> {
|
||||
try {
|
||||
if (information.isConnectionLocal()) {
|
||||
if (ticTacToe.get().getCurrentTurn() == 0) {
|
||||
playerMoveQueue.put(new Game.Move(cell, 'X'));
|
||||
} else {
|
||||
playerMoveQueue.put(new Game.Move(cell, 'O'));
|
||||
}
|
||||
} else {
|
||||
if (information.isPlayerHuman()[0] && currentPlayerMove != Game.EMPTY) {
|
||||
playerMoveQueue.put(new Game.Move(cell, firstPlayerIsMe.get()? 'X' : 'O'));
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException _) {}
|
||||
});
|
||||
canvas =
|
||||
new TicTacToeCanvas(
|
||||
Color.LIME,
|
||||
(App.getHeight() / 100) * 75,
|
||||
(App.getHeight() / 100) * 75,
|
||||
(cell) -> {
|
||||
try {
|
||||
if (information.isConnectionLocal()) {
|
||||
if (ticTacToe.get().getCurrentTurn() == 0) {
|
||||
playerMoveQueue.put(new Game.Move(cell, 'X'));
|
||||
} else {
|
||||
playerMoveQueue.put(new Game.Move(cell, 'O'));
|
||||
}
|
||||
} else {
|
||||
if (information.isPlayerHuman()[0]
|
||||
&& currentPlayerMove != Game.EMPTY) {
|
||||
playerMoveQueue.put(
|
||||
new Game.Move(
|
||||
cell, firstPlayerIsMe.get() ? 'X' : 'O'));
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException _) {
|
||||
}
|
||||
});
|
||||
|
||||
ticTacToe = new AtomicReference<>(new TicTacToe());
|
||||
ticTacToeAI = new TicTacToeAI();
|
||||
ticTacToe = new AtomicReference<>(new TicTacToe());
|
||||
ticTacToeAI = new TicTacToeAI();
|
||||
|
||||
this.information = information;
|
||||
this.information = information;
|
||||
|
||||
if (information.isConnectionLocal()) {
|
||||
new Thread(this::localGameThread).start();
|
||||
}
|
||||
if (information.isConnectionLocal()) {
|
||||
new Thread(this::localGameThread).start();
|
||||
}
|
||||
|
||||
currentPlayerNameText = NodeBuilder.header("");
|
||||
currentPlayerMoveText = NodeBuilder.header("");
|
||||
currentPlayerNameText = NodeBuilder.header("");
|
||||
currentPlayerMoveText = NodeBuilder.header("");
|
||||
|
||||
reload();
|
||||
}
|
||||
reload();
|
||||
}
|
||||
|
||||
public TicTacToeLayer(GameInformation information, long clientID) {
|
||||
this(information);
|
||||
public TicTacToeLayer(GameInformation information, long clientID) {
|
||||
this(information);
|
||||
|
||||
Thread a = new Thread(this::serverGameThread);
|
||||
a.setDaemon(false);
|
||||
a.start();
|
||||
Thread a = new Thread(this::serverGameThread);
|
||||
a.setDaemon(false);
|
||||
a.start();
|
||||
|
||||
reload();
|
||||
}
|
||||
reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
@Override
|
||||
public void reload() {
|
||||
popAll();
|
||||
|
||||
canvas.resize((App.getHeight() / 100) * 75, (App.getHeight() / 100) * 75);
|
||||
canvas.resize((App.getHeight() / 100) * 75, (App.getHeight() / 100) * 75);
|
||||
|
||||
for (int i = 0; i < ticTacToe.get().board.length; i++) {
|
||||
final char value = ticTacToe.get().board[i];
|
||||
for (int i = 0; i < ticTacToe.get().board.length; i++) {
|
||||
final char value = ticTacToe.get().board[i];
|
||||
|
||||
if (value == 'X') {
|
||||
canvas.drawX(Color.RED, i);
|
||||
} else if (value == 'O') {
|
||||
canvas.drawO(Color.BLUE, i);
|
||||
}
|
||||
}
|
||||
if (value == 'X') {
|
||||
canvas.drawX(Color.RED, i);
|
||||
} else if (value == 'O') {
|
||||
canvas.drawO(Color.BLUE, i);
|
||||
}
|
||||
}
|
||||
|
||||
final var backButton = NodeBuilder.button(AppContext.getString("back"), () -> {
|
||||
App.activate(new MainLayer());
|
||||
});
|
||||
final var backButton =
|
||||
NodeBuilder.button(
|
||||
AppContext.getString("back"),
|
||||
() -> {
|
||||
App.activate(new MainLayer());
|
||||
});
|
||||
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
controlContainer.addNodes(backButton);
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
controlContainer.addNodes(backButton);
|
||||
|
||||
final Container informationContainer = new HorizontalContainer(15);
|
||||
informationContainer.addNodes(currentPlayerNameText, currentPlayerMoveText);
|
||||
final Container informationContainer = new HorizontalContainer(15);
|
||||
informationContainer.addNodes(currentPlayerNameText, currentPlayerMoveText);
|
||||
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2, 0, 0);
|
||||
addContainer(informationContainer, Pos.TOP_LEFT, 2, 2, 0, 0);
|
||||
addGameCanvas(canvas, Pos.CENTER, 0, 0);
|
||||
}
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2, 0, 0);
|
||||
addContainer(informationContainer, Pos.TOP_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 int compurterDifficultyToDepth(int maxDifficulty, int difficulty) {
|
||||
return (int) (((float) maxDifficulty / difficulty) * 9);
|
||||
}
|
||||
|
||||
private void localGameThread() {
|
||||
boolean running = true;
|
||||
private void localGameThread() {
|
||||
boolean running = true;
|
||||
|
||||
while (running) {
|
||||
final int currentPlayer = ticTacToe.get().getCurrentTurn();
|
||||
while (running) {
|
||||
final int currentPlayer = ticTacToe.get().getCurrentTurn();
|
||||
|
||||
currentPlayerNameText.setText(information.playerName()[currentPlayer]);
|
||||
currentPlayerMoveText.setText(ticTacToe.get().getCurrentTurn() == 0? "X" : "O");
|
||||
currentPlayerNameText.setText(information.playerName()[currentPlayer]);
|
||||
currentPlayerMoveText.setText(ticTacToe.get().getCurrentTurn() == 0 ? "X" : "O");
|
||||
|
||||
Game.Move move = null;
|
||||
Game.Move move = null;
|
||||
|
||||
if (information.isPlayerHuman()[currentPlayer]) {
|
||||
try {
|
||||
final Game.Move wants = playerMoveQueue.take();
|
||||
final Game.Move[] legalMoves = ticTacToe.get().getLegalMoves();
|
||||
if (information.isPlayerHuman()[currentPlayer]) {
|
||||
try {
|
||||
final Game.Move wants = playerMoveQueue.take();
|
||||
final Game.Move[] legalMoves = ticTacToe.get().getLegalMoves();
|
||||
|
||||
for (final Game.Move legalMove : legalMoves) {
|
||||
if (legalMove.position() == wants.position() && legalMove.value() == wants.value()) {
|
||||
move = wants;
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException _) {}
|
||||
} else {
|
||||
final long start = System.currentTimeMillis();
|
||||
for (final Game.Move legalMove : legalMoves) {
|
||||
if (legalMove.position() == wants.position()
|
||||
&& legalMove.value() == wants.value()) {
|
||||
move = wants;
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException _) {
|
||||
}
|
||||
} else {
|
||||
final long start = System.currentTimeMillis();
|
||||
|
||||
move = ticTacToeAI.findBestMove(ticTacToe.get(), compurterDifficultyToDepth(10,
|
||||
information.computerDifficulty()[currentPlayer]));
|
||||
move =
|
||||
ticTacToeAI.findBestMove(
|
||||
ticTacToe.get(),
|
||||
compurterDifficultyToDepth(
|
||||
10, information.computerDifficulty()[currentPlayer]));
|
||||
|
||||
if (information.computerThinkTime()[currentPlayer] > 0) {
|
||||
final long elapsedTime = System.currentTimeMillis() - start;
|
||||
final long sleepTime = information.computerThinkTime()[currentPlayer] * 1000L - elapsedTime;
|
||||
if (information.computerThinkTime()[currentPlayer] > 0) {
|
||||
final long elapsedTime = System.currentTimeMillis() - start;
|
||||
final long sleepTime =
|
||||
information.computerThinkTime()[currentPlayer] * 1000L - elapsedTime;
|
||||
|
||||
try {
|
||||
Thread.sleep(sleepTime);
|
||||
} catch (InterruptedException _) {}
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(sleepTime);
|
||||
} catch (InterruptedException _) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (move == null) {
|
||||
continue;
|
||||
}
|
||||
if (move == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final Game.State state = ticTacToe.get().play(move);
|
||||
final Game.State state = ticTacToe.get().play(move);
|
||||
|
||||
if (move.value() == 'X') {
|
||||
canvas.drawX(Color.RED, move.position());
|
||||
} else if (move.value() == 'O') {
|
||||
canvas.drawO(Color.BLUE, move.position());
|
||||
}
|
||||
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) {
|
||||
App.push(new GameFinishedPopup(false, information.playerName()[ticTacToe.get().getCurrentTurn()]));
|
||||
} else if (state == Game.State.DRAW) {
|
||||
App.push(new GameFinishedPopup(true, ""));
|
||||
}
|
||||
if (state != Game.State.NORMAL) {
|
||||
if (state == Game.State.WIN) {
|
||||
App.push(
|
||||
new GameFinishedPopup(
|
||||
false,
|
||||
information.playerName()[ticTacToe.get().getCurrentTurn()]));
|
||||
} else if (state == Game.State.DRAW) {
|
||||
App.push(new GameFinishedPopup(true, ""));
|
||||
}
|
||||
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void serverGameThread() {
|
||||
new EventFlow()
|
||||
.listen(this::handleServerGameStart) // <-----------
|
||||
.listen(this::yourTurnResponse)
|
||||
.listen(this::onMoveResponse)
|
||||
.listen(this::handleReceivedMessage);
|
||||
}
|
||||
private void serverGameThread() {
|
||||
new EventFlow()
|
||||
.listen(this::handleServerGameStart) // <-----------
|
||||
.listen(this::yourTurnResponse)
|
||||
.listen(this::onMoveResponse)
|
||||
.listen(this::handleReceivedMessage);
|
||||
}
|
||||
|
||||
private void handleServerGameStart(NetworkEvents.GameMatchResponse resp) {
|
||||
// Meneer Bas de Jong. Dit functie wordt niet aangeroepen als je de challenger bent.
|
||||
// Ik heb veel dingen geprobeert. FUCKING veel dingen. Hij doet het niet.
|
||||
// Ik heb zelfs in jou code gekeken en unsubscribeAfterSuccess op false gezet. (zie ConnectedLayer).
|
||||
// Alle andere functies worden wel gecalt. Behalve dit.
|
||||
private void handleServerGameStart(NetworkEvents.GameMatchResponse resp) {
|
||||
// Meneer Bas de Jong. Dit functie wordt niet aangeroepen als je de challenger bent.
|
||||
// Ik heb veel dingen geprobeert. FUCKING veel dingen. Hij doet het niet.
|
||||
// Ik heb zelfs in jou code gekeken en unsubscribeAfterSuccess op false gezet. (zie
|
||||
// ConnectedLayer).
|
||||
// Alle andere functies worden wel gecalt. Behalve dit.
|
||||
|
||||
// Ben jij gehandicapt of ik? Want het moet 1 van de 2 zijn. Ik ben dit al 2 uur aan het debuggen.
|
||||
// Ik ga nu slapen (04:46).
|
||||
// Ben jij gehandicapt of ik? Want het moet 1 van de 2 zijn. Ik ben dit al 2 uur aan het
|
||||
// debuggen.
|
||||
// Ik ga nu slapen (04:46).
|
||||
|
||||
// ⠀⠀⠀⠀⠀⠀⣀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⢀⣴⣿⣿⠿⣟⢷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⢸⣏⡏⠀⠀⠀⢣⢻⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⢸⣟⠧⠤⠤⠔⠋⠀⢿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⠀⣿⡆⠀⠀⠀⠀⠀⠸⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⠀⠘⣿⡀⢀⣶⠤⠒⠀⢻⣇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠈⢿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⠀⠀⠀⣿⡆⠀⠀⠀⠀⠀⠈⢿⣆⣠⣤⣤⣤⣤⣴⣦⣄⡀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⠀⢀⣾⢿⢿⠀⠀⠀⢀⣀⣀⠘⣿⠋⠁⠀⠙⢇⠀⠀⠙⢿⣦⡀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⢀⣾⢇⡞⠘⣧⠀⢖⡭⠞⢛⡄⠘⣆⠀⠀⠀⠈⢧⠀⠀⠀⠙⢿⣄⠀⠀⠀⠀
|
||||
// ⠀⠀⣠⣿⣛⣥⠤⠤⢿⡄⠀⠀⠈⠉⠀⠀⠹⡄⠀⠀⠀⠈⢧⠀⠀⠀⠈⠻⣦⠀⠀⠀
|
||||
// ⠀⣼⡟⡱⠛⠙⠀⠀⠘⢷⡀⠀⠀⠀⠀⠀⠀⠹⡀⠀⠀⠀⠈⣧⠀⠀⠀⠀⠹⣧⡀⠀
|
||||
// ⢸⡏⢠⠃⠀⠀⠀⠀⠀⠀⢳⡀⠀⠀⠀⠀⠀⠀⢳⡀⠀⠀⠀⠘⣧⠀⠀⠀⠀⠸⣷⡀
|
||||
// ⠸⣧⠘⡇⠀⠀⠀⠀⠀⠀⠀⢳⡀⠀⠀⠀⠀⠀⠀⢣⠀⠀⠀⠀⢹⡇⠀⠀⠀⠀⣿⠇
|
||||
// ⠀⣿⡄⢳⠀⠀⠀⠀⠀⠀⠀⠈⣷⠀⠀⠀⠀⠀⠀⠈⠆⠀⠀⠀⠀⠀⠀⠀⠀⣼⡟⠀
|
||||
// ⠀⢹⡇⠘⣇⠀⠀⠀⠀⠀⠀⠰⣿⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠀⣼⡟⠀⠀
|
||||
// ⠀⢸⡇⠀⢹⡆⠀⠀⠀⠀⠀⠀⠙⠁⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⢳⣼⠟⠀⠀⠀
|
||||
// ⠀⠸⣧⣀⠀⢳⡀⠀⠀⠀⠀⠀⠀⠀⡄⠀⠀⠀⠀⠀⠀⠀⢃⠀⢀⣴⡿⠁⠀⠀⠀⠀
|
||||
// ⠀⠀⠈⠙⢷⣄⢳⡀⠀⠀⠀⠀⠀⠀⢳⡀⠀⠀⠀⠀⠀⣠⡿⠟⠛⠉⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⠀⠈⠻⢿⣷⣦⣄⣀⣀⣠⣤⠾⠷⣦⣤⣤⡶⠟⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⠀⠀⠀⠀⠈⠉⠛⠛⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⠀⠀⠀⣀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⢀⣴⣿⣿⠿⣟⢷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⢸⣏⡏⠀⠀⠀⢣⢻⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⢸⣟⠧⠤⠤⠔⠋⠀⢿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⠀⣿⡆⠀⠀⠀⠀⠀⠸⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⠀⠘⣿⡀⢀⣶⠤⠒⠀⢻⣇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠈⢿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⠀⠀⠀⣿⡆⠀⠀⠀⠀⠀⠈⢿⣆⣠⣤⣤⣤⣤⣴⣦⣄⡀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⠀⢀⣾⢿⢿⠀⠀⠀⢀⣀⣀⠘⣿⠋⠁⠀⠙⢇⠀⠀⠙⢿⣦⡀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⢀⣾⢇⡞⠘⣧⠀⢖⡭⠞⢛⡄⠘⣆⠀⠀⠀⠈⢧⠀⠀⠀⠙⢿⣄⠀⠀⠀⠀
|
||||
// ⠀⠀⣠⣿⣛⣥⠤⠤⢿⡄⠀⠀⠈⠉⠀⠀⠹⡄⠀⠀⠀⠈⢧⠀⠀⠀⠈⠻⣦⠀⠀⠀
|
||||
// ⠀⣼⡟⡱⠛⠙⠀⠀⠘⢷⡀⠀⠀⠀⠀⠀⠀⠹⡀⠀⠀⠀⠈⣧⠀⠀⠀⠀⠹⣧⡀⠀
|
||||
// ⢸⡏⢠⠃⠀⠀⠀⠀⠀⠀⢳⡀⠀⠀⠀⠀⠀⠀⢳⡀⠀⠀⠀⠘⣧⠀⠀⠀⠀⠸⣷⡀
|
||||
// ⠸⣧⠘⡇⠀⠀⠀⠀⠀⠀⠀⢳⡀⠀⠀⠀⠀⠀⠀⢣⠀⠀⠀⠀⢹⡇⠀⠀⠀⠀⣿⠇
|
||||
// ⠀⣿⡄⢳⠀⠀⠀⠀⠀⠀⠀⠈⣷⠀⠀⠀⠀⠀⠀⠈⠆⠀⠀⠀⠀⠀⠀⠀⠀⣼⡟⠀
|
||||
// ⠀⢹⡇⠘⣇⠀⠀⠀⠀⠀⠀⠰⣿⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠀⣼⡟⠀⠀
|
||||
// ⠀⢸⡇⠀⢹⡆⠀⠀⠀⠀⠀⠀⠙⠁⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⢳⣼⠟⠀⠀⠀
|
||||
// ⠀⠸⣧⣀⠀⢳⡀⠀⠀⠀⠀⠀⠀⠀⡄⠀⠀⠀⠀⠀⠀⠀⢃⠀⢀⣴⡿⠁⠀⠀⠀⠀
|
||||
// ⠀⠀⠈⠙⢷⣄⢳⡀⠀⠀⠀⠀⠀⠀⢳⡀⠀⠀⠀⠀⠀⣠⡿⠟⠛⠉⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⠀⠈⠻⢿⣷⣦⣄⣀⣀⣠⣤⠾⠷⣦⣤⣤⡶⠟⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
// ⠀⠀⠀⠀⠀⠀⠀⠈⠉⠛⠛⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||
|
||||
player2Name = resp.opponent();
|
||||
System.out.println(player2Name);
|
||||
player2Name = resp.opponent();
|
||||
System.out.println(player2Name);
|
||||
|
||||
currentPlayerMoveText.setText("X");
|
||||
currentPlayerMoveText.setText("X");
|
||||
|
||||
if(!resp.playerToMove().equalsIgnoreCase(resp.opponent())) {
|
||||
currentPlayerNameText.setText(information.playerName()[0]);
|
||||
firstPlayerIsMe.set(true);
|
||||
if (!resp.playerToMove().equalsIgnoreCase(resp.opponent())) {
|
||||
currentPlayerNameText.setText(information.playerName()[0]);
|
||||
firstPlayerIsMe.set(true);
|
||||
|
||||
System.out.printf("I am starting: My client id is %d\n", resp.clientId());
|
||||
} else {
|
||||
currentPlayerNameText.setText(player2Name);
|
||||
firstPlayerIsMe.set(false);
|
||||
System.out.printf("I am starting: My client id is %d\n", resp.clientId());
|
||||
} else {
|
||||
currentPlayerNameText.setText(player2Name);
|
||||
firstPlayerIsMe.set(false);
|
||||
|
||||
System.out.printf("I am NOT starting: My client id is %d\n", resp.clientId());
|
||||
}
|
||||
}
|
||||
System.out.printf("I am NOT starting: My client id is %d\n", resp.clientId());
|
||||
}
|
||||
}
|
||||
|
||||
private void onMoveResponse(NetworkEvents.GameMoveResponse resp) {
|
||||
char playerChar;
|
||||
private void onMoveResponse(NetworkEvents.GameMoveResponse resp) {
|
||||
char playerChar;
|
||||
|
||||
if (!resp.player().equalsIgnoreCase(player2Name)) {
|
||||
playerChar = firstPlayerIsMe.get()? 'X' : 'O';
|
||||
} else {
|
||||
playerChar = firstPlayerIsMe.get()? 'O' : 'X';
|
||||
}
|
||||
if (!resp.player().equalsIgnoreCase(player2Name)) {
|
||||
playerChar = firstPlayerIsMe.get() ? 'X' : 'O';
|
||||
} else {
|
||||
playerChar = firstPlayerIsMe.get() ? 'O' : 'X';
|
||||
}
|
||||
|
||||
final Game.Move move = new Game.Move(Integer.parseInt(resp.move()), playerChar);
|
||||
final Game.State state = ticTacToe.get().play(move);
|
||||
final Game.Move move = new Game.Move(Integer.parseInt(resp.move()), playerChar);
|
||||
final Game.State state = ticTacToe.get().play(move);
|
||||
|
||||
if (state != Game.State.NORMAL) { //todo differentiate between future draw guaranteed and is currently a draw
|
||||
if (state == Game.State.WIN) {
|
||||
App.push(new GameFinishedPopup(false, information.playerName()[ticTacToe.get().getCurrentTurn()]));
|
||||
} else if (state == Game.State.DRAW) {
|
||||
App.push(new GameFinishedPopup(true, ""));
|
||||
}
|
||||
}
|
||||
if (state
|
||||
!= Game.State.NORMAL) { // todo differentiate between future draw guaranteed and is
|
||||
// currently a draw
|
||||
if (state == Game.State.WIN) {
|
||||
App.push(
|
||||
new GameFinishedPopup(
|
||||
false, information.playerName()[ticTacToe.get().getCurrentTurn()]));
|
||||
} else if (state == Game.State.DRAW) {
|
||||
App.push(new GameFinishedPopup(true, ""));
|
||||
}
|
||||
}
|
||||
|
||||
if (move.value() == 'X') {
|
||||
canvas.drawX(Color.RED, move.position());
|
||||
} else if (move.value() == 'O') {
|
||||
canvas.drawO(Color.BLUE, move.position());
|
||||
}
|
||||
if (move.value() == 'X') {
|
||||
canvas.drawX(Color.RED, move.position());
|
||||
} else if (move.value() == 'O') {
|
||||
canvas.drawO(Color.BLUE, move.position());
|
||||
}
|
||||
|
||||
currentPlayerNameText.setText(ticTacToe.get().getCurrentTurn() == (firstPlayerIsMe.get()? 0 : 1)? information.playerName()[0] : player2Name);
|
||||
currentPlayerMoveText.setText(ticTacToe.get().getCurrentTurn() == 0? "X" : "O");
|
||||
}
|
||||
currentPlayerNameText.setText(
|
||||
ticTacToe.get().getCurrentTurn() == (firstPlayerIsMe.get() ? 0 : 1)
|
||||
? information.playerName()[0]
|
||||
: player2Name);
|
||||
currentPlayerMoveText.setText(ticTacToe.get().getCurrentTurn() == 0 ? "X" : "O");
|
||||
}
|
||||
|
||||
private void yourTurnResponse(NetworkEvents.YourTurnResponse response) {
|
||||
int position = -1;
|
||||
private void yourTurnResponse(NetworkEvents.YourTurnResponse response) {
|
||||
int position = -1;
|
||||
|
||||
if (information.isPlayerHuman()[0]) {
|
||||
try {
|
||||
position = playerMoveQueue.take().position();
|
||||
} catch (InterruptedException _) {}
|
||||
} else {
|
||||
final Game.Move move = ticTacToeAI.findBestMove(ticTacToe.get(), compurterDifficultyToDepth(10,
|
||||
information.computerDifficulty()[0]));
|
||||
if (information.isPlayerHuman()[0]) {
|
||||
try {
|
||||
position = playerMoveQueue.take().position();
|
||||
} catch (InterruptedException _) {
|
||||
}
|
||||
} else {
|
||||
final Game.Move move =
|
||||
ticTacToeAI.findBestMove(
|
||||
ticTacToe.get(),
|
||||
compurterDifficultyToDepth(10, information.computerDifficulty()[0]));
|
||||
|
||||
position = move.position();
|
||||
}
|
||||
position = move.position();
|
||||
}
|
||||
|
||||
new EventFlow().addPostEvent(new NetworkEvents.SendMove(response.clientId(), (short)position))
|
||||
.postEvent();
|
||||
}
|
||||
new EventFlow()
|
||||
.addPostEvent(new NetworkEvents.SendMove(response.clientId(), (short) position))
|
||||
.postEvent();
|
||||
}
|
||||
|
||||
private void handleReceivedMessage(NetworkEvents.ReceivedMessage msg) {
|
||||
System.out.println("Received Message: " + msg.message()); //todo add chat window
|
||||
}
|
||||
}
|
||||
private void handleReceivedMessage(NetworkEvents.ReceivedMessage msg) {
|
||||
System.out.println("Received Message: " + msg.message()); // todo add chat window
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,27 @@
|
||||
package org.toop.local;
|
||||
|
||||
import java.util.Locale;
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class AppContext {
|
||||
private static final LocalizationAsset localization = ResourceManager.get("localization");
|
||||
private static Locale locale = Locale.forLanguageTag("en");
|
||||
private static final LocalizationAsset localization = ResourceManager.get("localization");
|
||||
private static Locale locale = Locale.forLanguageTag("en");
|
||||
|
||||
public static LocalizationAsset getLocalization() {
|
||||
return localization;
|
||||
}
|
||||
public static LocalizationAsset getLocalization() {
|
||||
return localization;
|
||||
}
|
||||
|
||||
public static void setLocale(Locale locale) {
|
||||
AppContext.locale = locale;
|
||||
}
|
||||
public static void setLocale(Locale locale) {
|
||||
AppContext.locale = locale;
|
||||
}
|
||||
|
||||
public static Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
public static Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public static String getString(String key) {
|
||||
assert localization != null;
|
||||
return localization.getString(key, locale);
|
||||
}
|
||||
}
|
||||
public static String getString(String key) {
|
||||
assert localization != null;
|
||||
return localization.getString(key, locale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package org.toop.local;
|
||||
|
||||
import jdk.jfr.Event;
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
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;
|
||||
@@ -23,10 +21,16 @@ public class AppSettings {
|
||||
|
||||
AppContext.setLocale(Locale.of(settingsData.locale));
|
||||
App.setFullscreen(settingsData.fullScreen);
|
||||
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(settingsData.volume)).asyncPostEvent();
|
||||
new EventFlow().addPostEvent(new AudioEvents.ChangeFxVolume(settingsData.fxVolume)).asyncPostEvent();
|
||||
new EventFlow().addPostEvent(new AudioEvents.ChangeMusicVolume(settingsData.musicVolume)).asyncPostEvent();
|
||||
App.setStyle(settingsAsset.getTheme(), settingsAsset.getLayoutSize());
|
||||
new EventFlow()
|
||||
.addPostEvent(new AudioEvents.ChangeVolume(settingsData.volume))
|
||||
.asyncPostEvent();
|
||||
new EventFlow()
|
||||
.addPostEvent(new AudioEvents.ChangeFxVolume(settingsData.fxVolume))
|
||||
.asyncPostEvent();
|
||||
new EventFlow()
|
||||
.addPostEvent(new AudioEvents.ChangeMusicVolume(settingsData.musicVolume))
|
||||
.asyncPostEvent();
|
||||
App.setStyle(settingsAsset.getTheme(), settingsAsset.getLayoutSize());
|
||||
}
|
||||
|
||||
public SettingsAsset getPath() {
|
||||
@@ -45,7 +49,8 @@ public class AppSettings {
|
||||
basePath = System.getProperty("user.home") + "/.config";
|
||||
}
|
||||
|
||||
File settingsFile = new File(basePath + File.separator + "ISY1" + File.separator + "settings.json");
|
||||
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