mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
started the great ui redesign
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -13,7 +13,7 @@
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_24" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,67 +1,24 @@
|
||||
package org.toop.app;
|
||||
|
||||
import javafx.stage.Screen;
|
||||
import org.toop.app.canvas.TicTacToeCanvas;
|
||||
import javafx.application.Platform;
|
||||
import org.toop.app.menu.MainMenu;
|
||||
import org.toop.app.menu.Menu;
|
||||
import org.toop.app.layer.Layer;
|
||||
import org.toop.app.layer.layers.MainLayer;
|
||||
import org.toop.app.layer.layers.QuitLayer;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.Stage;
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.CssAsset;
|
||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.local.AppContext;
|
||||
import org.toop.local.LocalizationEvents;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public final class App extends Application {
|
||||
private static Stage stage;
|
||||
private static StackPane root;
|
||||
|
||||
private static Screen screen; // TODO set screen
|
||||
private static int width;
|
||||
private static int height;
|
||||
|
||||
private static boolean isQuitting;
|
||||
private Locale currentLocale = AppContext.getLocale();
|
||||
private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
|
||||
private static class QuitMenu extends Menu {
|
||||
private Locale currentLocale = AppContext.getLocale();
|
||||
private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
public QuitMenu() {
|
||||
final Region background = createBackground("quit_background");
|
||||
|
||||
final Text sure = createText(loc.getString("quitMenuTextSure",currentLocale));
|
||||
|
||||
final Button yes = createButton(loc.getString("quitMenuButtonYes",currentLocale), () -> { stage.close(); });
|
||||
final Button no = createButton(loc.getString("quitMenuButtonNo",currentLocale), () -> { pop(); isQuitting = false; });
|
||||
|
||||
final HBox buttons = new HBox(50, yes, no);
|
||||
buttons.setAlignment(Pos.CENTER);
|
||||
|
||||
final VBox box = new VBox(35, sure, buttons);
|
||||
box.getStyleClass().add("quit_box");
|
||||
box.setAlignment(Pos.CENTER);
|
||||
box.setMaxWidth(350);
|
||||
box.setMaxHeight(200);
|
||||
|
||||
pane = new StackPane(background, box);
|
||||
pane.getStylesheets().add(ResourceManager.get(CssAsset.class, "quit.css").getUrl());
|
||||
}
|
||||
}
|
||||
|
||||
public static void run(String[] args) {
|
||||
launch(args);
|
||||
@@ -69,14 +26,14 @@ public final class App extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
final StackPane root = new StackPane(new MainMenu().getPane());
|
||||
final StackPane root = new StackPane();
|
||||
|
||||
final Scene scene = new Scene(root);
|
||||
scene.getStylesheets().add(ResourceManager.get(CssAsset.class, "app.css").getUrl());
|
||||
|
||||
stage.setTitle(loc.getString("windowTitle",currentLocale));
|
||||
stage.setMinWidth(1080);
|
||||
stage.setMinHeight(720);
|
||||
stage.setTitle("pism");
|
||||
stage.setWidth(1080);
|
||||
stage.setHeight(720);
|
||||
|
||||
stage.setOnCloseRequest(event -> {
|
||||
event.consume();
|
||||
@@ -99,69 +56,27 @@ public final class App extends Application {
|
||||
|
||||
App.isQuitting = false;
|
||||
|
||||
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).asyncPostEvent();
|
||||
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(0.1)).asyncPostEvent();
|
||||
|
||||
// Todo: Temp Obviously
|
||||
// Replace with game of life
|
||||
final TicTacToeCanvas canvas = new TicTacToeCanvas();
|
||||
root.getChildren().addLast(canvas.getCanvas());
|
||||
|
||||
try {
|
||||
new EventFlow()
|
||||
.listen(this::handleChangeLanguage);
|
||||
|
||||
}catch (Exception e){
|
||||
System.out.println("Something went wrong while trying to change the language.");
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
Platform.runLater(() -> {
|
||||
currentLocale = AppContext.getLocale();
|
||||
stage.setTitle(loc.getString("windowTitle", currentLocale));
|
||||
});
|
||||
|
||||
push(new MainLayer());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void quitPopup() {
|
||||
isQuitting = true;
|
||||
push(new QuitMenu());
|
||||
}
|
||||
|
||||
public static void activate(Menu menu) {
|
||||
pop();
|
||||
push(menu);
|
||||
}
|
||||
|
||||
public static void push(Menu menu) {
|
||||
root.getChildren().addLast(menu.getPane());
|
||||
public static void push(Layer layer) {
|
||||
root.getChildren().addLast(layer.getLayer());
|
||||
}
|
||||
|
||||
public static void pop() {
|
||||
root.getChildren().removeLast();
|
||||
isQuitting = false;
|
||||
}
|
||||
|
||||
public static void quitPopup() {
|
||||
push(new QuitLayer());
|
||||
isQuitting = true;
|
||||
}
|
||||
|
||||
public static void quit() {
|
||||
stage.close();
|
||||
}
|
||||
|
||||
public static int getWidth() { return width; }
|
||||
public static int getHeight() { return height; }
|
||||
|
||||
public static void setWidth(int widthSetter) {
|
||||
width = widthSetter;
|
||||
}
|
||||
|
||||
public static void setHeight(int heightSetter) {
|
||||
height = heightSetter;
|
||||
}
|
||||
|
||||
public static boolean isFullscreen() {
|
||||
return stage.isFullScreen();
|
||||
}
|
||||
|
||||
public static void setFullscreen(boolean fullscreen) {
|
||||
stage.setFullScreen(fullscreen);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -63,14 +63,14 @@ public class TicTacToeCanvas extends GameCanvas {
|
||||
final Game.State state = game.play(move);
|
||||
|
||||
if (state == Game.State.WIN) {
|
||||
graphics.setFill(Color.GREEN);
|
||||
graphics.fillRect(cells[4].x(), cells[4].y(), cells[4].width(), cells[4].height());
|
||||
|
||||
for (int i = 0; i < game.board.length; i++) {
|
||||
if (game.board[i] != move.value()) {
|
||||
clearCell(i);
|
||||
}
|
||||
}
|
||||
|
||||
graphics.setFill(Color.GREEN);
|
||||
graphics.fillRect(cells[4].x(), cells[4].y(), cells[4].width(), cells[4].height());
|
||||
} else if (state == Game.State.DRAW) {
|
||||
graphics.setFill(Color.DARKORANGE);
|
||||
graphics.fillRect(cells[4].x(), cells[4].y(), cells[4].width(), cells[4].height());
|
||||
|
||||
12
app/src/main/java/org/toop/app/events/AppEvents.java
Normal file
12
app/src/main/java/org/toop/app/events/AppEvents.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package org.toop.app.events;
|
||||
|
||||
import org.toop.framework.eventbus.events.EventWithoutSnowflake;
|
||||
import org.toop.framework.eventbus.events.EventsBase;
|
||||
|
||||
public class AppEvents extends EventsBase {
|
||||
public record OnNodeHover() implements EventWithoutSnowflake {}
|
||||
|
||||
public record OnNodeClick() implements EventWithoutSnowflake {}
|
||||
|
||||
public record OnLanguageChange(String language) implements EventWithoutSnowflake {}
|
||||
}
|
||||
86
app/src/main/java/org/toop/app/layer/Container.java
Normal file
86
app/src/main/java/org/toop/app/layer/Container.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package org.toop.app.layer;
|
||||
|
||||
import org.toop.app.events.AppEvents;
|
||||
import org.toop.framework.eventbus.GlobalEventBus;
|
||||
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
|
||||
public final class Container {
|
||||
public enum Type {
|
||||
VERTICAL, HORIZONTAL,
|
||||
}
|
||||
|
||||
public static Container create(String cssClass, Type type, int spacing) {
|
||||
final Container container = new Container();
|
||||
|
||||
switch (type) {
|
||||
case VERTICAL:
|
||||
container.container = new VBox(spacing);
|
||||
break;
|
||||
case HORIZONTAL:
|
||||
container.container = new HBox(spacing);
|
||||
break;
|
||||
}
|
||||
|
||||
container.container.getStyleClass().add(cssClass);
|
||||
return container;
|
||||
}
|
||||
|
||||
public static Container create(Type type, int spacing) {
|
||||
return create("container", type, spacing);
|
||||
}
|
||||
|
||||
private Pane container;
|
||||
|
||||
public Container addContainer(String cssClass, Type type, int spacing) {
|
||||
final Container element = create(cssClass, type, spacing);
|
||||
element.container.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
|
||||
|
||||
container.getChildren().add(element.container);
|
||||
return element;
|
||||
}
|
||||
|
||||
public Container addContainer(Type type, int spacing) {
|
||||
return addContainer("container", type, spacing);
|
||||
}
|
||||
|
||||
public Text addText(String cssClass, String x) {
|
||||
final Text element = new Text(x);
|
||||
element.getStyleClass().add(cssClass);
|
||||
|
||||
container.getChildren().addLast(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
public Text addText(String x) {
|
||||
return addText("text", x);
|
||||
}
|
||||
|
||||
public Button addButton(String cssClass, String x, Runnable runnable) {
|
||||
final Button element = new Button(x);
|
||||
element.getStyleClass().add(cssClass);
|
||||
|
||||
element.setOnMouseEntered(_ -> {
|
||||
GlobalEventBus.post(new AppEvents.OnNodeHover());
|
||||
});
|
||||
|
||||
element.setOnAction(_ -> {
|
||||
GlobalEventBus.post(new AppEvents.OnNodeClick());
|
||||
runnable.run();
|
||||
});
|
||||
|
||||
container.getChildren().addLast(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
public Button addButton(String x, Runnable runnable) {
|
||||
return addButton("button", x, runnable);
|
||||
}
|
||||
|
||||
public Pane getContainer() { return container; }
|
||||
}
|
||||
57
app/src/main/java/org/toop/app/layer/Layer.java
Normal file
57
app/src/main/java/org/toop/app/layer/Layer.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package org.toop.app.layer;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.canvas.GameCanvas;
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.CssAsset;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.StackPane;
|
||||
|
||||
public abstract class Layer {
|
||||
protected StackPane layer;
|
||||
protected Region background;
|
||||
|
||||
protected Layer(String cssFile) {
|
||||
layer = new StackPane();
|
||||
layer.setPickOnBounds(false);
|
||||
layer.getStylesheets().add(ResourceManager.get(CssAsset.class, cssFile).getUrl());
|
||||
|
||||
background = new Region();
|
||||
background.setPrefSize(Double.MAX_VALUE, Double.MAX_VALUE);
|
||||
background.getStyleClass().add("background");
|
||||
|
||||
layer.getChildren().addLast(background);
|
||||
}
|
||||
|
||||
protected void addContainer(Container container, Pos position, int xOffset, int yOffset) {
|
||||
StackPane.setAlignment(container.getContainer(), position);
|
||||
|
||||
container.getContainer().setMaxWidth(Region.USE_PREF_SIZE);
|
||||
container.getContainer().setMaxHeight(Region.USE_PREF_SIZE);
|
||||
|
||||
final double xPercent = xOffset * (App.getWidth() / 100.0);
|
||||
final double yPercent = yOffset * (App.getHeight() / 100.0);
|
||||
|
||||
container.getContainer().setTranslateX(xPercent);
|
||||
container.getContainer().setTranslateY(yPercent);
|
||||
|
||||
layer.getChildren().addLast(container.getContainer());
|
||||
}
|
||||
|
||||
protected void addCanvas(GameCanvas canvas, Pos position, int xOffset, int yOffset) {
|
||||
StackPane.setAlignment(canvas.getCanvas(), position);
|
||||
|
||||
final double xPercent = xOffset * (App.getWidth() / 100.0);
|
||||
final double yPercent = yOffset * (App.getHeight() / 100.0);
|
||||
|
||||
canvas.getCanvas().setTranslateX(xPercent);
|
||||
canvas.getCanvas().setTranslateX(yPercent);
|
||||
|
||||
layer.getChildren().addLast(canvas.getCanvas());
|
||||
}
|
||||
|
||||
public StackPane getLayer() { return layer; }
|
||||
public Region getBackground() { return background; }
|
||||
}
|
||||
25
app/src/main/java/org/toop/app/layer/layers/MainLayer.java
Normal file
25
app/src/main/java/org/toop/app/layer/layers/MainLayer.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package org.toop.app.layer.layers;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.layer.Container;
|
||||
import org.toop.app.layer.Layer;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
public final class MainLayer extends Layer {
|
||||
public MainLayer() {
|
||||
super("main.css");
|
||||
|
||||
final Container gamesContainer = Container.create(Container.Type.VERTICAL, 10);
|
||||
gamesContainer.addButton("Tic Tac Toe", () -> {});
|
||||
gamesContainer.addButton("Othello", () -> {});
|
||||
|
||||
final Container controlContainer = Container.create(Container.Type.VERTICAL, 10);
|
||||
controlContainer.addButton("Credits", () -> {});
|
||||
controlContainer.addButton("Options", () -> {});
|
||||
controlContainer.addButton("Quit", () -> { App.quitPopup(); });
|
||||
|
||||
addContainer(gamesContainer, Pos.TOP_LEFT, 2, 2);
|
||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2);
|
||||
}
|
||||
}
|
||||
21
app/src/main/java/org/toop/app/layer/layers/QuitLayer.java
Normal file
21
app/src/main/java/org/toop/app/layer/layers/QuitLayer.java
Normal file
@@ -0,0 +1,21 @@
|
||||
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;
|
||||
|
||||
public final class QuitLayer extends Layer {
|
||||
public QuitLayer() {
|
||||
super("quit.css");
|
||||
|
||||
final Container mainContainer = Container.create(Container.Type.VERTICAL, 30);
|
||||
mainContainer.addText("Are you sure?");
|
||||
|
||||
final Container controlContainer = mainContainer.addContainer(Container.Type.HORIZONTAL, 50);
|
||||
controlContainer.addButton("Yes", () -> { App.quit(); });
|
||||
controlContainer.addButton("No", () -> { App.pop(); });
|
||||
|
||||
addContainer(mainContainer, Pos.CENTER, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,32 @@
|
||||
package org.toop.app.menu;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.local.AppContext;
|
||||
import org.toop.local.LocalizationEvents;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public final class CreditsMenu extends Menu {
|
||||
private Locale currentLocale = AppContext.getLocale();
|
||||
private LocalizationAsset loc = ResourceManager.get("localization_en_us.properties");
|
||||
public CreditsMenu() {
|
||||
try {
|
||||
new EventFlow()
|
||||
.listen(this::handleChangeLanguage);
|
||||
|
||||
}catch (Exception e){
|
||||
System.out.println("Something went wrong while trying to change the language.");
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
Platform.runLater(() -> {
|
||||
currentLocale = AppContext.getLocale();
|
||||
//credits.setText(loc.getString("credits",currentLocale));
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
// package org.toop.app.menu;
|
||||
//
|
||||
// import javafx.application.Platform;
|
||||
// import org.toop.framework.asset.ResourceManager;
|
||||
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
// import org.toop.framework.eventbus.EventFlow;
|
||||
// import org.toop.local.AppContext;
|
||||
//
|
||||
// import java.util.Locale;
|
||||
//
|
||||
// public final class CreditsMenu extends Menu {
|
||||
// private Locale currentLocale = AppContext.getLocale();
|
||||
// private LocalizationAsset loc = ResourceManager.get("localization_en_us.properties");
|
||||
// public CreditsMenu() {
|
||||
// try {
|
||||
// new EventFlow()
|
||||
// .listen(this::handleChangeLanguage);
|
||||
//
|
||||
// }catch (Exception e){
|
||||
// System.out.println("Something went wrong while trying to change the language.");
|
||||
// throw e;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
// Platform.runLater(() -> {
|
||||
// currentLocale = AppContext.getLocale();
|
||||
// //credits.setText(loc.getString("credits",currentLocale));
|
||||
// });
|
||||
//
|
||||
// }
|
||||
// }
|
||||
@@ -1,67 +1,66 @@
|
||||
package org.toop.app.menu;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.toop.app.GameType;
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.local.AppContext;
|
||||
import org.toop.local.LocalizationEvents;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class GameSelectMenu extends Menu {
|
||||
private Locale currentLocale = AppContext.getLocale();
|
||||
private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
|
||||
final ComboBox<String> selectedMode, selectedGame;
|
||||
final TextField serverIpField;
|
||||
|
||||
public GameSelectMenu(GameType type) {
|
||||
final Region background = createBackground();
|
||||
|
||||
selectedGame = new ComboBox<>();
|
||||
selectedGame.getItems().add(GameType.toName(GameType.TICTACTOE));
|
||||
selectedGame.getItems().add(GameType.toName(GameType.REVERSI));
|
||||
selectedGame.setValue(GameType.toName(type));
|
||||
|
||||
selectedMode = new ComboBox<>();
|
||||
selectedMode.getItems().add("Local");
|
||||
selectedMode.getItems().add("Online");
|
||||
selectedMode.setValue("Local");
|
||||
|
||||
final HBox selectedContainer = new HBox(10, selectedGame, selectedMode);
|
||||
|
||||
serverIpField = new TextField();
|
||||
serverIpField.setPromptText(loc.getString("gameSelectMenuEnterIP",currentLocale));
|
||||
|
||||
VBox box = new VBox(selectedContainer, serverIpField);
|
||||
pane = new StackPane(background, box);
|
||||
try {
|
||||
new EventFlow()
|
||||
.listen(this::handleChangeLanguage);
|
||||
|
||||
}catch (Exception e){
|
||||
System.out.println("Something went wrong while trying to change the language.");
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
Platform.runLater(() -> {
|
||||
currentLocale = AppContext.getLocale();
|
||||
serverIpField.setPromptText(loc.getString("gameSelectMenuEnterIP",currentLocale));
|
||||
selectedGame.getItems().set(0, loc.getString("mainMenuSelectTicTacToe",currentLocale));
|
||||
selectedGame.getItems().set(1, loc.getString("mainMenuSelectReversi",currentLocale));
|
||||
selectedMode.getItems().set(0, loc.getString("gameSelectMenuLocal",currentLocale));
|
||||
selectedMode.getItems().set(1, loc.getString("gameSelectMenuOnline",currentLocale));
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
// package org.toop.app.menu;
|
||||
//
|
||||
// import javafx.application.Platform;
|
||||
// import javafx.scene.control.ComboBox;
|
||||
// import javafx.scene.control.TextField;
|
||||
// import javafx.scene.layout.HBox;
|
||||
// import javafx.scene.layout.Region;
|
||||
// import javafx.scene.layout.StackPane;
|
||||
// import javafx.scene.layout.VBox;
|
||||
// import org.toop.app.GameType;
|
||||
// import org.toop.framework.asset.ResourceManager;
|
||||
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
// import org.toop.framework.eventbus.EventFlow;
|
||||
// import org.toop.local.AppContext;
|
||||
//
|
||||
// import java.util.Locale;
|
||||
//
|
||||
// public class GameSelectMenu extends Menu {
|
||||
// private Locale currentLocale = AppContext.getLocale();
|
||||
// private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
//
|
||||
// final ComboBox<String> selectedMode, selectedGame;
|
||||
// final TextField serverIpField;
|
||||
//
|
||||
// public GameSelectMenu(GameType type) {
|
||||
// final Region background = createBackground();
|
||||
//
|
||||
// selectedGame = new ComboBox<>();
|
||||
// selectedGame.getItems().add(GameType.toName(GameType.TICTACTOE));
|
||||
// selectedGame.getItems().add(GameType.toName(GameType.REVERSI));
|
||||
// selectedGame.setValue(GameType.toName(type));
|
||||
//
|
||||
// selectedMode = new ComboBox<>();
|
||||
// selectedMode.getItems().add("Local");
|
||||
// selectedMode.getItems().add("Online");
|
||||
// selectedMode.setValue("Local");
|
||||
//
|
||||
// final HBox selectedContainer = new HBox(10, selectedGame, selectedMode);
|
||||
//
|
||||
// serverIpField = new TextField();
|
||||
// serverIpField.setPromptText(loc.getString("gameSelectMenuEnterIP",currentLocale));
|
||||
//
|
||||
// VBox box = new VBox(selectedContainer, serverIpField);
|
||||
// pane = new StackPane(background, box);
|
||||
// try {
|
||||
// new EventFlow()
|
||||
// .listen(this::handleChangeLanguage);
|
||||
//
|
||||
// }catch (Exception e){
|
||||
// System.out.println("Something went wrong while trying to change the language.");
|
||||
// throw e;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
// Platform.runLater(() -> {
|
||||
// currentLocale = AppContext.getLocale();
|
||||
// serverIpField.setPromptText(loc.getString("gameSelectMenuEnterIP",currentLocale));
|
||||
// selectedGame.getItems().set(0, loc.getString("mainMenuSelectTicTacToe",currentLocale));
|
||||
// selectedGame.getItems().set(1, loc.getString("mainMenuSelectReversi",currentLocale));
|
||||
// selectedMode.getItems().set(0, loc.getString("gameSelectMenuLocal",currentLocale));
|
||||
// selectedMode.getItems().set(1, loc.getString("gameSelectMenuOnline",currentLocale));
|
||||
// });
|
||||
//
|
||||
// }
|
||||
// }
|
||||
@@ -1,67 +1,65 @@
|
||||
package org.toop.app.menu;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.GameType;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.*;
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.game.tictactoe.TicTacToe;
|
||||
import org.toop.local.AppContext;
|
||||
import org.toop.local.LocalizationEvents;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public final class MainMenu extends Menu {
|
||||
private Locale currentLocale = AppContext.getLocale();
|
||||
private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
private final Button tictactoe,reversi,credits,options,quit;
|
||||
public MainMenu() {
|
||||
final Region background = createBackground();
|
||||
|
||||
tictactoe = createButton(loc.getString("mainMenuSelectTicTacToe",currentLocale), () -> { App.activate(new GameSelectMenu(GameType.TICTACTOE)); });
|
||||
reversi = createButton(loc.getString("mainMenuSelectReversi",currentLocale), () -> { App.activate(new GameSelectMenu(GameType.REVERSI)); });
|
||||
|
||||
final VBox gamesBox = new VBox(10, tictactoe, reversi);
|
||||
gamesBox.setAlignment(Pos.TOP_LEFT);
|
||||
gamesBox.setPickOnBounds(false);
|
||||
gamesBox.setTranslateY(50);
|
||||
gamesBox.setTranslateX(25);
|
||||
|
||||
credits = createButton(loc.getString("mainMenuSelectCredits",currentLocale), () -> { App.push(new CreditsMenu()); });
|
||||
options = createButton(loc.getString("mainMenuSelectOptions",currentLocale), () -> { App.push(new OptionsMenu()); });
|
||||
quit = createButton(loc.getString("mainMenuSelectQuit",currentLocale), () -> { App.quitPopup(); });
|
||||
|
||||
final VBox controlBox = new VBox(10, credits, options, quit);
|
||||
controlBox.setAlignment(Pos.BOTTOM_LEFT);
|
||||
controlBox.setPickOnBounds(false);
|
||||
controlBox.setTranslateY(-50);
|
||||
controlBox.setTranslateX(25);
|
||||
|
||||
pane = new StackPane(background, gamesBox, controlBox);
|
||||
try {
|
||||
new EventFlow()
|
||||
.listen(this::handleChangeLanguage);
|
||||
|
||||
}catch (Exception e){
|
||||
System.out.println("Something went wrong while trying to change the language.");
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
Platform.runLater(() -> {
|
||||
currentLocale = AppContext.getLocale();
|
||||
tictactoe.setText(loc.getString("mainMenuSelectTicTacToe",currentLocale));
|
||||
reversi.setText(loc.getString("mainMenuSelectReversi",currentLocale));
|
||||
credits.setText(loc.getString("mainMenuSelectCredits",currentLocale));
|
||||
options.setText(loc.getString("mainMenuSelectOptions",currentLocale));
|
||||
quit.setText(loc.getString("mainMenuSelectQuit",currentLocale));
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
// package org.toop.app.menu;
|
||||
//
|
||||
// import javafx.application.Platform;
|
||||
// import org.toop.app.App;
|
||||
// import org.toop.app.GameType;
|
||||
//
|
||||
// import javafx.geometry.Pos;
|
||||
// import javafx.scene.control.Button;
|
||||
// import javafx.scene.layout.*;
|
||||
// import org.toop.framework.asset.ResourceManager;
|
||||
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
// import org.toop.framework.eventbus.EventFlow;
|
||||
// import org.toop.local.AppContext;
|
||||
//
|
||||
// import java.util.Locale;
|
||||
//
|
||||
// public final class MainMenu extends Menu {
|
||||
// private Locale currentLocale = AppContext.getLocale();
|
||||
// private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
// private final Button tictactoe,reversi,credits,options,quit;
|
||||
// public MainMenu() {
|
||||
// final Region background = createBackground();
|
||||
//
|
||||
// tictactoe = createButton(loc.getString("mainMenuSelectTicTacToe",currentLocale), () -> { App.activate(new GameSelectMenu(GameType.TICTACTOE)); });
|
||||
// reversi = createButton(loc.getString("mainMenuSelectReversi",currentLocale), () -> { App.activate(new GameSelectMenu(GameType.REVERSI)); });
|
||||
//
|
||||
// final VBox gamesBox = new VBox(10, tictactoe, reversi);
|
||||
// gamesBox.setAlignment(Pos.TOP_LEFT);
|
||||
// gamesBox.setPickOnBounds(false);
|
||||
// gamesBox.setTranslateY(50);
|
||||
// gamesBox.setTranslateX(25);
|
||||
//
|
||||
// credits = createButton(loc.getString("mainMenuSelectCredits",currentLocale), () -> { App.push(new CreditsMenu()); });
|
||||
// options = createButton(loc.getString("mainMenuSelectOptions",currentLocale), () -> { App.push(new OptionsMenu()); });
|
||||
// quit = createButton(loc.getString("mainMenuSelectQuit",currentLocale), () -> { App.quitPopup(); });
|
||||
//
|
||||
// final VBox controlBox = new VBox(10, credits, options, quit);
|
||||
// controlBox.setAlignment(Pos.BOTTOM_LEFT);
|
||||
// controlBox.setPickOnBounds(false);
|
||||
// controlBox.setTranslateY(-50);
|
||||
// controlBox.setTranslateX(25);
|
||||
//
|
||||
// pane = new StackPane(background, gamesBox, controlBox);
|
||||
// try {
|
||||
// new EventFlow()
|
||||
// .listen(this::handleChangeLanguage);
|
||||
//
|
||||
// }catch (Exception e){
|
||||
// System.out.println("Something went wrong while trying to change the language.");
|
||||
// throw e;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
// Platform.runLater(() -> {
|
||||
// currentLocale = AppContext.getLocale();
|
||||
// tictactoe.setText(loc.getString("mainMenuSelectTicTacToe",currentLocale));
|
||||
// reversi.setText(loc.getString("mainMenuSelectReversi",currentLocale));
|
||||
// credits.setText(loc.getString("mainMenuSelectCredits",currentLocale));
|
||||
// options.setText(loc.getString("mainMenuSelectOptions",currentLocale));
|
||||
// quit.setText(loc.getString("mainMenuSelectQuit",currentLocale));
|
||||
// });
|
||||
//
|
||||
// }
|
||||
// }
|
||||
@@ -1,142 +1,142 @@
|
||||
package org.toop.app.menu;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.toop.app.App;
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class OptionsMenu extends Menu {
|
||||
private Locale currentLocale = AppContext.getLocale();
|
||||
private LocalizationAsset loc = ResourceManager.get("localization");
|
||||
private GraphicsDevice currentScreenDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0];
|
||||
|
||||
public OptionsMenu() {
|
||||
final Label selectLanguageLabel = new Label(
|
||||
loc.getString("optionsMenuLabelSelectLanguage", currentLocale)
|
||||
);
|
||||
|
||||
final Button exitOptionsButton = createButton("Exit Options", () -> { App.pop(); } );
|
||||
|
||||
final VBox optionsBox = new VBox(10,
|
||||
selectLanguageLabel,
|
||||
languageSelectorCreation(),
|
||||
screenDeviceSelectorCreation(),
|
||||
displayModeSelectorCreation(),
|
||||
selectFullscreenCreation(),
|
||||
volumeSelectorCreation(),
|
||||
exitOptionsButton);
|
||||
|
||||
optionsBox.setAlignment(Pos.CENTER);
|
||||
optionsBox.setPickOnBounds(false);
|
||||
optionsBox.setTranslateY(50);
|
||||
optionsBox.setTranslateX(25);
|
||||
|
||||
pane = new StackPane(optionsBox);
|
||||
|
||||
}
|
||||
|
||||
private ChoiceBox<Locale> languageSelectorCreation() {
|
||||
final ChoiceBox<Locale> selectLanguage = new ChoiceBox<>();
|
||||
selectLanguage.setValue(currentLocale);
|
||||
|
||||
for (Locale locFile : loc.getAvailableLocales()) {
|
||||
selectLanguage.getItems().add(locFile);
|
||||
}
|
||||
|
||||
selectLanguage.setConverter(new javafx.util.StringConverter<Locale>() {
|
||||
@Override
|
||||
public String toString(Locale locale) {
|
||||
return locale.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale fromString(String string) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
selectLanguage.setOnAction(event -> {
|
||||
Locale selectedLocale = selectLanguage.getSelectionModel().getSelectedItem();
|
||||
if (selectedLocale != null) {
|
||||
AppContext.setLocale(selectedLocale);
|
||||
App.pop();
|
||||
App.push(new OptionsMenu());
|
||||
}
|
||||
});
|
||||
|
||||
return selectLanguage;
|
||||
}
|
||||
|
||||
private ChoiceBox<GraphicsDevice> screenDeviceSelectorCreation() {
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice[] devices = ge.getScreenDevices();
|
||||
final ChoiceBox<GraphicsDevice> selectScreen = new ChoiceBox<>();
|
||||
for (GraphicsDevice screen : devices) {
|
||||
selectScreen.getItems().add(screen);
|
||||
}
|
||||
|
||||
selectScreen.setOnAction(event -> {
|
||||
int selectedIndex = selectScreen.getSelectionModel().getSelectedIndex();
|
||||
Object selectedItem = selectScreen.getSelectionModel().getSelectedItem();
|
||||
|
||||
System.out.println("Selection made: [" + selectedIndex + "] " + selectedItem);
|
||||
System.out.println(" ChoiceBox.getValue(): " + selectScreen.getValue());
|
||||
});
|
||||
return selectScreen;
|
||||
}
|
||||
|
||||
private ChoiceBox<DisplayMode> displayModeSelectorCreation() {
|
||||
final ChoiceBox<DisplayMode> selectWindowSize = new ChoiceBox<>();
|
||||
for (DisplayMode displayMode : currentScreenDevice.getDisplayModes()) {
|
||||
selectWindowSize.getItems().add(displayMode);
|
||||
}
|
||||
return selectWindowSize;
|
||||
}
|
||||
|
||||
private CheckBox selectFullscreenCreation() {
|
||||
final CheckBox setFullscreen = new CheckBox("Fullscreen");
|
||||
setFullscreen.setSelected(App.isFullscreen());
|
||||
setFullscreen.setOnAction(event -> {
|
||||
boolean isSelected = setFullscreen.isSelected();
|
||||
App.setFullscreen(isSelected);
|
||||
});
|
||||
return setFullscreen;
|
||||
}
|
||||
|
||||
private Slider volumeSelectorCreation() {
|
||||
Slider volumeSlider = new Slider(0, 100, 50);
|
||||
new EventFlow()
|
||||
.addPostEvent(AudioEvents.GetCurrentVolume.class)
|
||||
.onResponse(AudioEvents.GetCurrentVolumeReponse.class, event -> {
|
||||
volumeSlider.setValue(event.currentVolume() * 100);
|
||||
}).asyncPostEvent();
|
||||
volumeSlider.setShowTickLabels(true);
|
||||
volumeSlider.setShowTickMarks(true);
|
||||
volumeSlider.setMajorTickUnit(25);
|
||||
volumeSlider.setMinorTickCount(4);
|
||||
volumeSlider.setBlockIncrement(5);
|
||||
volumeSlider.setMaxWidth(225);
|
||||
|
||||
Label valueLabel = new Label(String.valueOf((int) volumeSlider.getValue()));
|
||||
|
||||
volumeSlider.valueProperty().addListener((obs, oldVal, newVal) -> {
|
||||
valueLabel.setText(String.valueOf(newVal.intValue()));
|
||||
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(newVal.doubleValue()/100.0))
|
||||
.asyncPostEvent();
|
||||
});
|
||||
return volumeSlider;
|
||||
}
|
||||
|
||||
}
|
||||
// package org.toop.app.menu;
|
||||
//
|
||||
// import javafx.geometry.Pos;
|
||||
// import javafx.scene.control.*;
|
||||
// import javafx.scene.control.Button;
|
||||
// import javafx.scene.control.Label;
|
||||
// import javafx.scene.layout.Region;
|
||||
// import javafx.scene.layout.StackPane;
|
||||
// import javafx.scene.layout.VBox;
|
||||
// import org.toop.app.App;
|
||||
// import org.toop.framework.asset.ResourceManager;
|
||||
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
// import org.toop.framework.audio.events.AudioEvents;
|
||||
// import org.toop.framework.eventbus.EventFlow;
|
||||
// import org.toop.local.AppContext;
|
||||
//
|
||||
// import java.awt.*;
|
||||
// import java.util.Locale;
|
||||
//
|
||||
// public final class OptionsMenu extends Menu {
|
||||
// private Locale currentLocale = AppContext.getLocale();
|
||||
// private LocalizationAsset loc = ResourceManager.get("localization");
|
||||
// private GraphicsDevice currentScreenDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0];
|
||||
//
|
||||
// public OptionsMenu() {
|
||||
// final Label selectLanguageLabel = new Label(
|
||||
// loc.getString("optionsMenuLabelSelectLanguage", currentLocale)
|
||||
// );
|
||||
//
|
||||
// final Button exitOptionsButton = createButton("Exit Options", () -> { App.pop(); } );
|
||||
//
|
||||
// final VBox optionsBox = new VBox(10,
|
||||
// selectLanguageLabel,
|
||||
// languageSelectorCreation(),
|
||||
// screenDeviceSelectorCreation(),
|
||||
// displayModeSelectorCreation(),
|
||||
// selectFullscreenCreation(),
|
||||
// volumeSelectorCreation(),
|
||||
// exitOptionsButton);
|
||||
//
|
||||
// optionsBox.setAlignment(Pos.CENTER);
|
||||
// optionsBox.setPickOnBounds(false);
|
||||
// optionsBox.setTranslateY(50);
|
||||
// optionsBox.setTranslateX(25);
|
||||
//
|
||||
// pane = new StackPane(optionsBox);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private ChoiceBox<Locale> languageSelectorCreation() {
|
||||
// final ChoiceBox<Locale> selectLanguage = new ChoiceBox<>();
|
||||
// selectLanguage.setValue(currentLocale);
|
||||
//
|
||||
// for (Locale locFile : loc.getAvailableLocales()) {
|
||||
// selectLanguage.getItems().add(locFile);
|
||||
// }
|
||||
//
|
||||
// selectLanguage.setConverter(new javafx.util.StringConverter<Locale>() {
|
||||
// @Override
|
||||
// public String toString(Locale locale) {
|
||||
// return locale.getDisplayName();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Locale fromString(String string) {
|
||||
// return null;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// selectLanguage.setOnAction(event -> {
|
||||
// Locale selectedLocale = selectLanguage.getSelectionModel().getSelectedItem();
|
||||
// if (selectedLocale != null) {
|
||||
// AppContext.setLocale(selectedLocale);
|
||||
// App.pop();
|
||||
// App.push(new OptionsMenu());
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// return selectLanguage;
|
||||
// }
|
||||
//
|
||||
// private ChoiceBox<GraphicsDevice> screenDeviceSelectorCreation() {
|
||||
// GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
// GraphicsDevice[] devices = ge.getScreenDevices();
|
||||
// final ChoiceBox<GraphicsDevice> selectScreen = new ChoiceBox<>();
|
||||
// for (GraphicsDevice screen : devices) {
|
||||
// selectScreen.getItems().add(screen);
|
||||
// }
|
||||
//
|
||||
// selectScreen.setOnAction(event -> {
|
||||
// int selectedIndex = selectScreen.getSelectionModel().getSelectedIndex();
|
||||
// Object selectedItem = selectScreen.getSelectionModel().getSelectedItem();
|
||||
//
|
||||
// System.out.println("Selection made: [" + selectedIndex + "] " + selectedItem);
|
||||
// System.out.println(" ChoiceBox.getValue(): " + selectScreen.getValue());
|
||||
// });
|
||||
// return selectScreen;
|
||||
// }
|
||||
//
|
||||
// private ChoiceBox<DisplayMode> displayModeSelectorCreation() {
|
||||
// final ChoiceBox<DisplayMode> selectWindowSize = new ChoiceBox<>();
|
||||
// for (DisplayMode displayMode : currentScreenDevice.getDisplayModes()) {
|
||||
// selectWindowSize.getItems().add(displayMode);
|
||||
// }
|
||||
// return selectWindowSize;
|
||||
// }
|
||||
//
|
||||
// private CheckBox selectFullscreenCreation() {
|
||||
// final CheckBox setFullscreen = new CheckBox("Fullscreen");
|
||||
// setFullscreen.setSelected(App.isFullscreen());
|
||||
// setFullscreen.setOnAction(event -> {
|
||||
// boolean isSelected = setFullscreen.isSelected();
|
||||
// App.setFullscreen(isSelected);
|
||||
// });
|
||||
// return setFullscreen;
|
||||
// }
|
||||
//
|
||||
// private Slider volumeSelectorCreation() {
|
||||
// Slider volumeSlider = new Slider(0, 100, 50);
|
||||
// new EventFlow()
|
||||
// .addPostEvent(AudioEvents.GetCurrentVolume.class)
|
||||
// .onResponse(AudioEvents.GetCurrentVolumeReponse.class, event -> {
|
||||
// volumeSlider.setValue(event.currentVolume() * 100);
|
||||
// }).asyncPostEvent();
|
||||
// volumeSlider.setShowTickLabels(true);
|
||||
// volumeSlider.setShowTickMarks(true);
|
||||
// volumeSlider.setMajorTickUnit(25);
|
||||
// volumeSlider.setMinorTickCount(4);
|
||||
// volumeSlider.setBlockIncrement(5);
|
||||
// volumeSlider.setMaxWidth(225);
|
||||
//
|
||||
// Label valueLabel = new Label(String.valueOf((int) volumeSlider.getValue()));
|
||||
//
|
||||
// volumeSlider.valueProperty().addListener((obs, oldVal, newVal) -> {
|
||||
// valueLabel.setText(String.valueOf(newVal.intValue()));
|
||||
// new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(newVal.doubleValue()/100.0))
|
||||
// .asyncPostEvent();
|
||||
// });
|
||||
// return volumeSlider;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
@@ -1,128 +1,127 @@
|
||||
package org.toop.app.menu.game;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.menu.MainMenu;
|
||||
import org.toop.app.menu.Menu;
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.local.AppContext;
|
||||
import org.toop.local.LocalizationEvents;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public abstract class GameMenu extends Menu {
|
||||
protected final class Cell {
|
||||
public float x;
|
||||
public float y;
|
||||
|
||||
public float width;
|
||||
public float height;
|
||||
|
||||
public Cell(float x, float y, float width, float height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public boolean check(float x, float y) {
|
||||
return x >= this.x && y >= this.y && x <= this.x + width && y <= this.y + height;
|
||||
}
|
||||
}
|
||||
|
||||
protected final int size;
|
||||
|
||||
protected final Canvas canvas;
|
||||
protected final GraphicsContext graphics;
|
||||
|
||||
protected final int rows;
|
||||
protected final int columns;
|
||||
|
||||
protected final int gapSize;
|
||||
|
||||
protected final Cell[] cells;
|
||||
|
||||
private Locale currentLocale = AppContext.getLocale();
|
||||
private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
private final Button hint,back;
|
||||
protected GameMenu(int rows, int columns, int gapSize) {
|
||||
|
||||
final int size = Math.min(App.getWidth(), App.getHeight()) / 5 * 4;
|
||||
|
||||
final Canvas canvas = new Canvas(size, size);
|
||||
|
||||
final GraphicsContext graphics = canvas.getGraphicsContext2D();
|
||||
|
||||
this.size = size;
|
||||
|
||||
this.canvas = canvas;
|
||||
this.graphics = graphics;
|
||||
|
||||
this.rows = rows;
|
||||
this.columns = columns;
|
||||
|
||||
this.gapSize = gapSize;
|
||||
|
||||
cells = new Cell[rows * columns];
|
||||
|
||||
final float cellWidth = ((float)size - (rows - 1) * gapSize) / rows;
|
||||
final float cellHeight = ((float)size - (columns - 1) * gapSize) / rows;
|
||||
|
||||
for (int y = 0; y < columns; y++) {
|
||||
final float startY = y * cellHeight + y * gapSize;
|
||||
|
||||
for (int x = 0; x < rows; x++) {
|
||||
final float startX = x * cellWidth + x * gapSize;
|
||||
cells[y * rows + x] = new Cell(startX, startY, cellWidth, cellHeight);
|
||||
}
|
||||
}
|
||||
|
||||
final Region background = createBackground();
|
||||
|
||||
final Text player1 = createText("player_1", "Player 1");
|
||||
final Text player2 = createText("player_2", "Player 2");
|
||||
|
||||
final HBox playersContainer = new HBox(100, player1, player2);
|
||||
playersContainer.setAlignment(Pos.TOP_CENTER);
|
||||
playersContainer.setPickOnBounds(false);
|
||||
playersContainer.setTranslateY(50);
|
||||
|
||||
hint = createButton(loc.getString("gameMenuHint",currentLocale), () -> {});
|
||||
back = createButton(loc.getString("gameMenuBack",currentLocale), () -> { App.activate(new MainMenu()); });
|
||||
|
||||
final VBox controlContainer = new VBox(hint, back);
|
||||
StackPane.setAlignment(controlContainer, Pos.BOTTOM_LEFT);
|
||||
controlContainer.setPickOnBounds(false);
|
||||
|
||||
pane = new StackPane(background, canvas, playersContainer, controlContainer);
|
||||
try {
|
||||
new EventFlow()
|
||||
.listen(this::handleChangeLanguage);
|
||||
|
||||
}catch (Exception e){
|
||||
System.out.println("Something went wrong while trying to change the language.");
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
Platform.runLater(() -> {
|
||||
currentLocale = AppContext.getLocale();
|
||||
hint.setText(loc.getString("gameMenuHint",currentLocale));
|
||||
back.setText(loc.getString("gameMenuBack",currentLocale));
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
// package org.toop.app.menu.game;
|
||||
//
|
||||
// import javafx.application.Platform;
|
||||
// import javafx.geometry.Pos;
|
||||
// import javafx.scene.canvas.Canvas;
|
||||
// import javafx.scene.canvas.GraphicsContext;
|
||||
// import javafx.scene.control.Button;
|
||||
// import javafx.scene.layout.HBox;
|
||||
// import javafx.scene.layout.Region;
|
||||
// import javafx.scene.layout.StackPane;
|
||||
// import javafx.scene.layout.VBox;
|
||||
// import javafx.scene.text.Text;
|
||||
// import org.toop.app.App;
|
||||
// import org.toop.app.menu.MainMenu;
|
||||
// import org.toop.app.menu.Menu;
|
||||
// import org.toop.framework.asset.ResourceManager;
|
||||
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
// import org.toop.framework.eventbus.EventFlow;
|
||||
// import org.toop.local.AppContext;
|
||||
//
|
||||
// import java.util.Locale;
|
||||
//
|
||||
// public abstract class GameMenu extends Menu {
|
||||
// protected final class Cell {
|
||||
// public float x;
|
||||
// public float y;
|
||||
//
|
||||
// public float width;
|
||||
// public float height;
|
||||
//
|
||||
// public Cell(float x, float y, float width, float height) {
|
||||
// this.x = x;
|
||||
// this.y = y;
|
||||
//
|
||||
// this.width = width;
|
||||
// this.height = height;
|
||||
// }
|
||||
//
|
||||
// public boolean check(float x, float y) {
|
||||
// return x >= this.x && y >= this.y && x <= this.x + width && y <= this.y + height;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// protected final int size;
|
||||
//
|
||||
// protected final Canvas canvas;
|
||||
// protected final GraphicsContext graphics;
|
||||
//
|
||||
// protected final int rows;
|
||||
// protected final int columns;
|
||||
//
|
||||
// protected final int gapSize;
|
||||
//
|
||||
// protected final Cell[] cells;
|
||||
//
|
||||
// private Locale currentLocale = AppContext.getLocale();
|
||||
// private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
// private final Button hint,back;
|
||||
// protected GameMenu(int rows, int columns, int gapSize) {
|
||||
//
|
||||
// final int size = Math.min(App.getWidth(), App.getHeight()) / 5 * 4;
|
||||
//
|
||||
// final Canvas canvas = new Canvas(size, size);
|
||||
//
|
||||
// final GraphicsContext graphics = canvas.getGraphicsContext2D();
|
||||
//
|
||||
// this.size = size;
|
||||
//
|
||||
// this.canvas = canvas;
|
||||
// this.graphics = graphics;
|
||||
//
|
||||
// this.rows = rows;
|
||||
// this.columns = columns;
|
||||
//
|
||||
// this.gapSize = gapSize;
|
||||
//
|
||||
// cells = new Cell[rows * columns];
|
||||
//
|
||||
// final float cellWidth = ((float)size - (rows - 1) * gapSize) / rows;
|
||||
// final float cellHeight = ((float)size - (columns - 1) * gapSize) / rows;
|
||||
//
|
||||
// for (int y = 0; y < columns; y++) {
|
||||
// final float startY = y * cellHeight + y * gapSize;
|
||||
//
|
||||
// for (int x = 0; x < rows; x++) {
|
||||
// final float startX = x * cellWidth + x * gapSize;
|
||||
// cells[y * rows + x] = new Cell(startX, startY, cellWidth, cellHeight);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// final Region background = createBackground();
|
||||
//
|
||||
// final Text player1 = createText("player_1", "Player 1");
|
||||
// final Text player2 = createText("player_2", "Player 2");
|
||||
//
|
||||
// final HBox playersContainer = new HBox(100, player1, player2);
|
||||
// playersContainer.setAlignment(Pos.TOP_CENTER);
|
||||
// playersContainer.setPickOnBounds(false);
|
||||
// playersContainer.setTranslateY(50);
|
||||
//
|
||||
// hint = createButton(loc.getString("gameMenuHint",currentLocale), () -> {});
|
||||
// back = createButton(loc.getString("gameMenuBack",currentLocale), () -> { App.activate(new MainMenu()); });
|
||||
//
|
||||
// final VBox controlContainer = new VBox(hint, back);
|
||||
// StackPane.setAlignment(controlContainer, Pos.BOTTOM_LEFT);
|
||||
// controlContainer.setPickOnBounds(false);
|
||||
//
|
||||
// pane = new StackPane(background, canvas, playersContainer, controlContainer);
|
||||
// try {
|
||||
// new EventFlow()
|
||||
// .listen(this::handleChangeLanguage);
|
||||
//
|
||||
// }catch (Exception e){
|
||||
// System.out.println("Something went wrong while trying to change the language.");
|
||||
// throw e;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
// Platform.runLater(() -> {
|
||||
// currentLocale = AppContext.getLocale();
|
||||
// hint.setText(loc.getString("gameMenuHint",currentLocale));
|
||||
// back.setText(loc.getString("gameMenuBack",currentLocale));
|
||||
// });
|
||||
//
|
||||
// }
|
||||
// }
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.toop.local;
|
||||
|
||||
import org.toop.app.events.AppEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Locale;
|
||||
|
||||
public class AppContext {
|
||||
@@ -10,12 +10,12 @@ public class AppContext {
|
||||
|
||||
public static void setLocale(Locale locale) {
|
||||
currentLocale = locale;
|
||||
new EventFlow().addPostEvent(new LocalizationEvents.LanguageHasChanged(locale.getLanguage())).asyncPostEvent();
|
||||
new EventFlow().addPostEvent(new AppEvents.OnLanguageChange(locale.getLanguage())).asyncPostEvent();
|
||||
}
|
||||
|
||||
public static void setCurrentLocale(Locale locale) {
|
||||
currentLocale = locale;
|
||||
new EventFlow().addPostEvent(new LocalizationEvents.LanguageHasChanged(locale.getLanguage())).asyncPostEvent();
|
||||
new EventFlow().addPostEvent(new AppEvents.OnLanguageChange(locale.getLanguage())).asyncPostEvent();
|
||||
}
|
||||
|
||||
public static Locale getLocale() {
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package org.toop.local;
|
||||
|
||||
|
||||
import org.toop.framework.eventbus.events.EventWithoutSnowflake;
|
||||
import org.toop.framework.eventbus.events.EventsBase;
|
||||
|
||||
public class LocalizationEvents extends EventsBase {
|
||||
public record LanguageHasChanged(String language) implements EventWithoutSnowflake {}
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
.background {
|
||||
-fx-background-color: linear-gradient(to bottom right, #21a7b2, #8f32b9);
|
||||
.container {
|
||||
-fx-background-color: linear-gradient(to bottom right, orange, indigo), #1d1d1d;
|
||||
-fx-background-insets: 0, 2;
|
||||
-fx-background-radius: 8;
|
||||
-fx-padding: 10;
|
||||
|
||||
-fx-alignment: center;
|
||||
-fx-text-alignment: center;
|
||||
}
|
||||
|
||||
.text {
|
||||
@@ -10,28 +16,20 @@
|
||||
-fx-font-size: 24px;
|
||||
}
|
||||
|
||||
.button, .text-field, .combo-box, .combo-box-popup .list-cell {
|
||||
-fx-padding: 10 20;
|
||||
.button {
|
||||
-fx-padding: 10;
|
||||
|
||||
-fx-background-color: transparent;
|
||||
-fx-border-color: transparent;
|
||||
|
||||
-fx-transition: all 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
.combo-box-popup .list-view {
|
||||
-fx-background-color: #1d1d1d;
|
||||
}
|
||||
|
||||
.text-field {
|
||||
-fx-text-fill: white;
|
||||
}
|
||||
|
||||
.button:hover, .text-field:hover, .combo-box:hover, .combo-box-popup .list-cell:hover {
|
||||
.button:hover {
|
||||
-fx-cursor: hand;
|
||||
|
||||
-fx-effect: dropshadow(gaussian, #00ffff7f, 10, 0.5, 0, 0);
|
||||
-fx-border-color: white;
|
||||
}
|
||||
-fx-scale-x: 1.1;
|
||||
-fx-scale-y: 1.1;
|
||||
|
||||
.text-field:focused, .combo-box:focused {
|
||||
-fx-border-color: white;
|
||||
-fx-effect: dropshadow(gaussian, #007fff, 10, 0.5, 0, 0);
|
||||
}
|
||||
3
app/src/main/resources/assets/style/main.css
Normal file
3
app/src/main/resources/assets/style/main.css
Normal file
@@ -0,0 +1,3 @@
|
||||
.background {
|
||||
-fx-background-color: linear-gradient(to bottom right, #21a7b2, #8f32b9);
|
||||
}
|
||||
@@ -1,8 +1,3 @@
|
||||
.quit_background {
|
||||
-fx-background-color: rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
.quit_box {
|
||||
-fx-background-color: rgba(30, 30, 30, 0.5);
|
||||
-fx-background-radius: 15;
|
||||
.background {
|
||||
-fx-background-color: #0000007f;
|
||||
}
|
||||
Reference in New Issue
Block a user