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>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</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" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -1,67 +1,24 @@
|
|||||||
package org.toop.app;
|
package org.toop.app;
|
||||||
|
|
||||||
import javafx.stage.Screen;
|
import org.toop.app.layer.Layer;
|
||||||
import org.toop.app.canvas.TicTacToeCanvas;
|
import org.toop.app.layer.layers.MainLayer;
|
||||||
import javafx.application.Platform;
|
import org.toop.app.layer.layers.QuitLayer;
|
||||||
import org.toop.app.menu.MainMenu;
|
|
||||||
import org.toop.app.menu.Menu;
|
|
||||||
|
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.geometry.Pos;
|
|
||||||
import javafx.scene.Scene;
|
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.StackPane;
|
||||||
import javafx.scene.layout.VBox;
|
|
||||||
import javafx.scene.text.Text;
|
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import org.toop.framework.asset.ResourceManager;
|
import org.toop.framework.asset.ResourceManager;
|
||||||
import org.toop.framework.asset.resources.CssAsset;
|
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 {
|
public final class App extends Application {
|
||||||
private static Stage stage;
|
private static Stage stage;
|
||||||
private static StackPane root;
|
private static StackPane root;
|
||||||
|
|
||||||
private static Screen screen; // TODO set screen
|
|
||||||
private static int width;
|
private static int width;
|
||||||
private static int height;
|
private static int height;
|
||||||
|
|
||||||
private static boolean isQuitting;
|
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) {
|
public static void run(String[] args) {
|
||||||
launch(args);
|
launch(args);
|
||||||
@@ -69,14 +26,14 @@ public final class App extends Application {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) throws Exception {
|
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);
|
final Scene scene = new Scene(root);
|
||||||
scene.getStylesheets().add(ResourceManager.get(CssAsset.class, "app.css").getUrl());
|
scene.getStylesheets().add(ResourceManager.get(CssAsset.class, "app.css").getUrl());
|
||||||
|
|
||||||
stage.setTitle(loc.getString("windowTitle",currentLocale));
|
stage.setTitle("pism");
|
||||||
stage.setMinWidth(1080);
|
stage.setWidth(1080);
|
||||||
stage.setMinHeight(720);
|
stage.setHeight(720);
|
||||||
|
|
||||||
stage.setOnCloseRequest(event -> {
|
stage.setOnCloseRequest(event -> {
|
||||||
event.consume();
|
event.consume();
|
||||||
@@ -99,69 +56,27 @@ public final class App extends Application {
|
|||||||
|
|
||||||
App.isQuitting = false;
|
App.isQuitting = false;
|
||||||
|
|
||||||
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).asyncPostEvent();
|
push(new MainLayer());
|
||||||
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));
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void push(Layer layer) {
|
||||||
|
root.getChildren().addLast(layer.getLayer());
|
||||||
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 pop() {
|
public static void pop() {
|
||||||
root.getChildren().removeLast();
|
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 getWidth() { return width; }
|
||||||
public static int getHeight() { return height; }
|
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);
|
final Game.State state = game.play(move);
|
||||||
|
|
||||||
if (state == Game.State.WIN) {
|
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++) {
|
for (int i = 0; i < game.board.length; i++) {
|
||||||
if (game.board[i] != move.value()) {
|
if (game.board[i] != move.value()) {
|
||||||
clearCell(i);
|
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) {
|
} else if (state == Game.State.DRAW) {
|
||||||
graphics.setFill(Color.DARKORANGE);
|
graphics.setFill(Color.DARKORANGE);
|
||||||
graphics.fillRect(cells[4].x(), cells[4].y(), cells[4].width(), cells[4].height());
|
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;
|
// package org.toop.app.menu;
|
||||||
|
//
|
||||||
import javafx.application.Platform;
|
// import javafx.application.Platform;
|
||||||
import org.toop.framework.asset.ResourceManager;
|
// import org.toop.framework.asset.ResourceManager;
|
||||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||||
import org.toop.framework.eventbus.EventFlow;
|
// import org.toop.framework.eventbus.EventFlow;
|
||||||
import org.toop.local.AppContext;
|
// import org.toop.local.AppContext;
|
||||||
import org.toop.local.LocalizationEvents;
|
//
|
||||||
|
// import java.util.Locale;
|
||||||
import java.util.Locale;
|
//
|
||||||
|
// public final class CreditsMenu extends Menu {
|
||||||
public final class CreditsMenu extends Menu {
|
// private Locale currentLocale = AppContext.getLocale();
|
||||||
private Locale currentLocale = AppContext.getLocale();
|
// private LocalizationAsset loc = ResourceManager.get("localization_en_us.properties");
|
||||||
private LocalizationAsset loc = ResourceManager.get("localization_en_us.properties");
|
// public CreditsMenu() {
|
||||||
public CreditsMenu() {
|
// try {
|
||||||
try {
|
// new EventFlow()
|
||||||
new EventFlow()
|
// .listen(this::handleChangeLanguage);
|
||||||
.listen(this::handleChangeLanguage);
|
//
|
||||||
|
// }catch (Exception e){
|
||||||
}catch (Exception e){
|
// System.out.println("Something went wrong while trying to change the language.");
|
||||||
System.out.println("Something went wrong while trying to change the language.");
|
// throw e;
|
||||||
throw e;
|
// }
|
||||||
}
|
//
|
||||||
|
// }
|
||||||
}
|
// private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||||
private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
// Platform.runLater(() -> {
|
||||||
Platform.runLater(() -> {
|
// currentLocale = AppContext.getLocale();
|
||||||
currentLocale = AppContext.getLocale();
|
// //credits.setText(loc.getString("credits",currentLocale));
|
||||||
//credits.setText(loc.getString("credits",currentLocale));
|
// });
|
||||||
});
|
//
|
||||||
|
// }
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
@@ -1,67 +1,66 @@
|
|||||||
package org.toop.app.menu;
|
// package org.toop.app.menu;
|
||||||
|
//
|
||||||
import javafx.application.Platform;
|
// import javafx.application.Platform;
|
||||||
import javafx.scene.control.ComboBox;
|
// import javafx.scene.control.ComboBox;
|
||||||
import javafx.scene.control.TextField;
|
// import javafx.scene.control.TextField;
|
||||||
import javafx.scene.layout.HBox;
|
// import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.Region;
|
// import javafx.scene.layout.Region;
|
||||||
import javafx.scene.layout.StackPane;
|
// import javafx.scene.layout.StackPane;
|
||||||
import javafx.scene.layout.VBox;
|
// import javafx.scene.layout.VBox;
|
||||||
import org.toop.app.GameType;
|
// import org.toop.app.GameType;
|
||||||
import org.toop.framework.asset.ResourceManager;
|
// import org.toop.framework.asset.ResourceManager;
|
||||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||||
import org.toop.framework.eventbus.EventFlow;
|
// import org.toop.framework.eventbus.EventFlow;
|
||||||
import org.toop.local.AppContext;
|
// import org.toop.local.AppContext;
|
||||||
import org.toop.local.LocalizationEvents;
|
//
|
||||||
|
// import java.util.Locale;
|
||||||
import java.util.Locale;
|
//
|
||||||
|
// public class GameSelectMenu extends Menu {
|
||||||
public class GameSelectMenu extends Menu {
|
// private Locale currentLocale = AppContext.getLocale();
|
||||||
private Locale currentLocale = AppContext.getLocale();
|
// private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||||
private final LocalizationAsset loc = ResourceManager.get("localization");
|
//
|
||||||
|
// final ComboBox<String> selectedMode, selectedGame;
|
||||||
final ComboBox<String> selectedMode, selectedGame;
|
// final TextField serverIpField;
|
||||||
final TextField serverIpField;
|
//
|
||||||
|
// public GameSelectMenu(GameType type) {
|
||||||
public GameSelectMenu(GameType type) {
|
// final Region background = createBackground();
|
||||||
final Region background = createBackground();
|
//
|
||||||
|
// selectedGame = new ComboBox<>();
|
||||||
selectedGame = new ComboBox<>();
|
// selectedGame.getItems().add(GameType.toName(GameType.TICTACTOE));
|
||||||
selectedGame.getItems().add(GameType.toName(GameType.TICTACTOE));
|
// selectedGame.getItems().add(GameType.toName(GameType.REVERSI));
|
||||||
selectedGame.getItems().add(GameType.toName(GameType.REVERSI));
|
// selectedGame.setValue(GameType.toName(type));
|
||||||
selectedGame.setValue(GameType.toName(type));
|
//
|
||||||
|
// selectedMode = new ComboBox<>();
|
||||||
selectedMode = new ComboBox<>();
|
// selectedMode.getItems().add("Local");
|
||||||
selectedMode.getItems().add("Local");
|
// selectedMode.getItems().add("Online");
|
||||||
selectedMode.getItems().add("Online");
|
// selectedMode.setValue("Local");
|
||||||
selectedMode.setValue("Local");
|
//
|
||||||
|
// final HBox selectedContainer = new HBox(10, selectedGame, selectedMode);
|
||||||
final HBox selectedContainer = new HBox(10, selectedGame, selectedMode);
|
//
|
||||||
|
// serverIpField = new TextField();
|
||||||
serverIpField = new TextField();
|
// serverIpField.setPromptText(loc.getString("gameSelectMenuEnterIP",currentLocale));
|
||||||
serverIpField.setPromptText(loc.getString("gameSelectMenuEnterIP",currentLocale));
|
//
|
||||||
|
// VBox box = new VBox(selectedContainer, serverIpField);
|
||||||
VBox box = new VBox(selectedContainer, serverIpField);
|
// pane = new StackPane(background, box);
|
||||||
pane = new StackPane(background, box);
|
// try {
|
||||||
try {
|
// new EventFlow()
|
||||||
new EventFlow()
|
// .listen(this::handleChangeLanguage);
|
||||||
.listen(this::handleChangeLanguage);
|
//
|
||||||
|
// }catch (Exception e){
|
||||||
}catch (Exception e){
|
// System.out.println("Something went wrong while trying to change the language.");
|
||||||
System.out.println("Something went wrong while trying to change the language.");
|
// throw e;
|
||||||
throw e;
|
// }
|
||||||
}
|
//
|
||||||
|
// }
|
||||||
}
|
// private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||||
private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
// Platform.runLater(() -> {
|
||||||
Platform.runLater(() -> {
|
// currentLocale = AppContext.getLocale();
|
||||||
currentLocale = AppContext.getLocale();
|
// serverIpField.setPromptText(loc.getString("gameSelectMenuEnterIP",currentLocale));
|
||||||
serverIpField.setPromptText(loc.getString("gameSelectMenuEnterIP",currentLocale));
|
// selectedGame.getItems().set(0, loc.getString("mainMenuSelectTicTacToe",currentLocale));
|
||||||
selectedGame.getItems().set(0, loc.getString("mainMenuSelectTicTacToe",currentLocale));
|
// selectedGame.getItems().set(1, loc.getString("mainMenuSelectReversi",currentLocale));
|
||||||
selectedGame.getItems().set(1, loc.getString("mainMenuSelectReversi",currentLocale));
|
// selectedMode.getItems().set(0, loc.getString("gameSelectMenuLocal",currentLocale));
|
||||||
selectedMode.getItems().set(0, loc.getString("gameSelectMenuLocal",currentLocale));
|
// selectedMode.getItems().set(1, loc.getString("gameSelectMenuOnline",currentLocale));
|
||||||
selectedMode.getItems().set(1, loc.getString("gameSelectMenuOnline",currentLocale));
|
// });
|
||||||
});
|
//
|
||||||
|
// }
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
@@ -1,67 +1,65 @@
|
|||||||
package org.toop.app.menu;
|
// package org.toop.app.menu;
|
||||||
|
//
|
||||||
import javafx.application.Platform;
|
// import javafx.application.Platform;
|
||||||
import org.toop.app.App;
|
// import org.toop.app.App;
|
||||||
import org.toop.app.GameType;
|
// import org.toop.app.GameType;
|
||||||
|
//
|
||||||
import javafx.geometry.Pos;
|
// import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.Button;
|
// import javafx.scene.control.Button;
|
||||||
import javafx.scene.layout.*;
|
// import javafx.scene.layout.*;
|
||||||
import org.toop.framework.asset.ResourceManager;
|
// import org.toop.framework.asset.ResourceManager;
|
||||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||||
import org.toop.framework.eventbus.EventFlow;
|
// import org.toop.framework.eventbus.EventFlow;
|
||||||
import org.toop.game.tictactoe.TicTacToe;
|
// import org.toop.local.AppContext;
|
||||||
import org.toop.local.AppContext;
|
//
|
||||||
import org.toop.local.LocalizationEvents;
|
// import java.util.Locale;
|
||||||
|
//
|
||||||
import java.util.Locale;
|
// public final class MainMenu extends Menu {
|
||||||
|
// private Locale currentLocale = AppContext.getLocale();
|
||||||
public final class MainMenu extends Menu {
|
// private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||||
private Locale currentLocale = AppContext.getLocale();
|
// private final Button tictactoe,reversi,credits,options,quit;
|
||||||
private final LocalizationAsset loc = ResourceManager.get("localization");
|
// public MainMenu() {
|
||||||
private final Button tictactoe,reversi,credits,options,quit;
|
// final Region background = createBackground();
|
||||||
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)); });
|
||||||
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);
|
||||||
final VBox gamesBox = new VBox(10, tictactoe, reversi);
|
// gamesBox.setPickOnBounds(false);
|
||||||
gamesBox.setAlignment(Pos.TOP_LEFT);
|
// gamesBox.setTranslateY(50);
|
||||||
gamesBox.setPickOnBounds(false);
|
// gamesBox.setTranslateX(25);
|
||||||
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()); });
|
||||||
credits = createButton(loc.getString("mainMenuSelectCredits",currentLocale), () -> { App.push(new CreditsMenu()); });
|
// quit = createButton(loc.getString("mainMenuSelectQuit",currentLocale), () -> { App.quitPopup(); });
|
||||||
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);
|
||||||
final VBox controlBox = new VBox(10, credits, options, quit);
|
// controlBox.setPickOnBounds(false);
|
||||||
controlBox.setAlignment(Pos.BOTTOM_LEFT);
|
// controlBox.setTranslateY(-50);
|
||||||
controlBox.setPickOnBounds(false);
|
// controlBox.setTranslateX(25);
|
||||||
controlBox.setTranslateY(-50);
|
//
|
||||||
controlBox.setTranslateX(25);
|
// pane = new StackPane(background, gamesBox, controlBox);
|
||||||
|
// try {
|
||||||
pane = new StackPane(background, gamesBox, controlBox);
|
// new EventFlow()
|
||||||
try {
|
// .listen(this::handleChangeLanguage);
|
||||||
new EventFlow()
|
//
|
||||||
.listen(this::handleChangeLanguage);
|
// }catch (Exception e){
|
||||||
|
// System.out.println("Something went wrong while trying to change the language.");
|
||||||
}catch (Exception e){
|
// throw e;
|
||||||
System.out.println("Something went wrong while trying to change the language.");
|
// }
|
||||||
throw e;
|
//
|
||||||
}
|
// }
|
||||||
|
// private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||||
}
|
// Platform.runLater(() -> {
|
||||||
private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
// currentLocale = AppContext.getLocale();
|
||||||
Platform.runLater(() -> {
|
// tictactoe.setText(loc.getString("mainMenuSelectTicTacToe",currentLocale));
|
||||||
currentLocale = AppContext.getLocale();
|
// reversi.setText(loc.getString("mainMenuSelectReversi",currentLocale));
|
||||||
tictactoe.setText(loc.getString("mainMenuSelectTicTacToe",currentLocale));
|
// credits.setText(loc.getString("mainMenuSelectCredits",currentLocale));
|
||||||
reversi.setText(loc.getString("mainMenuSelectReversi",currentLocale));
|
// options.setText(loc.getString("mainMenuSelectOptions",currentLocale));
|
||||||
credits.setText(loc.getString("mainMenuSelectCredits",currentLocale));
|
// quit.setText(loc.getString("mainMenuSelectQuit",currentLocale));
|
||||||
options.setText(loc.getString("mainMenuSelectOptions",currentLocale));
|
// });
|
||||||
quit.setText(loc.getString("mainMenuSelectQuit",currentLocale));
|
//
|
||||||
});
|
// }
|
||||||
|
// }
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,142 +1,142 @@
|
|||||||
package org.toop.app.menu;
|
// package org.toop.app.menu;
|
||||||
|
//
|
||||||
import javafx.geometry.Pos;
|
// import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.*;
|
// import javafx.scene.control.*;
|
||||||
import javafx.scene.control.Button;
|
// import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Label;
|
// import javafx.scene.control.Label;
|
||||||
import javafx.scene.layout.Region;
|
// import javafx.scene.layout.Region;
|
||||||
import javafx.scene.layout.StackPane;
|
// import javafx.scene.layout.StackPane;
|
||||||
import javafx.scene.layout.VBox;
|
// import javafx.scene.layout.VBox;
|
||||||
import org.toop.app.App;
|
// import org.toop.app.App;
|
||||||
import org.toop.framework.asset.ResourceManager;
|
// import org.toop.framework.asset.ResourceManager;
|
||||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||||
import org.toop.framework.audio.events.AudioEvents;
|
// import org.toop.framework.audio.events.AudioEvents;
|
||||||
import org.toop.framework.eventbus.EventFlow;
|
// import org.toop.framework.eventbus.EventFlow;
|
||||||
import org.toop.local.AppContext;
|
// import org.toop.local.AppContext;
|
||||||
|
//
|
||||||
import java.awt.*;
|
// import java.awt.*;
|
||||||
import java.util.Locale;
|
// import java.util.Locale;
|
||||||
|
//
|
||||||
public final class OptionsMenu extends Menu {
|
// public final class OptionsMenu extends Menu {
|
||||||
private Locale currentLocale = AppContext.getLocale();
|
// private Locale currentLocale = AppContext.getLocale();
|
||||||
private LocalizationAsset loc = ResourceManager.get("localization");
|
// private LocalizationAsset loc = ResourceManager.get("localization");
|
||||||
private GraphicsDevice currentScreenDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0];
|
// private GraphicsDevice currentScreenDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0];
|
||||||
|
//
|
||||||
public OptionsMenu() {
|
// public OptionsMenu() {
|
||||||
final Label selectLanguageLabel = new Label(
|
// final Label selectLanguageLabel = new Label(
|
||||||
loc.getString("optionsMenuLabelSelectLanguage", currentLocale)
|
// loc.getString("optionsMenuLabelSelectLanguage", currentLocale)
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
final Button exitOptionsButton = createButton("Exit Options", () -> { App.pop(); } );
|
// final Button exitOptionsButton = createButton("Exit Options", () -> { App.pop(); } );
|
||||||
|
//
|
||||||
final VBox optionsBox = new VBox(10,
|
// final VBox optionsBox = new VBox(10,
|
||||||
selectLanguageLabel,
|
// selectLanguageLabel,
|
||||||
languageSelectorCreation(),
|
// languageSelectorCreation(),
|
||||||
screenDeviceSelectorCreation(),
|
// screenDeviceSelectorCreation(),
|
||||||
displayModeSelectorCreation(),
|
// displayModeSelectorCreation(),
|
||||||
selectFullscreenCreation(),
|
// selectFullscreenCreation(),
|
||||||
volumeSelectorCreation(),
|
// volumeSelectorCreation(),
|
||||||
exitOptionsButton);
|
// exitOptionsButton);
|
||||||
|
//
|
||||||
optionsBox.setAlignment(Pos.CENTER);
|
// optionsBox.setAlignment(Pos.CENTER);
|
||||||
optionsBox.setPickOnBounds(false);
|
// optionsBox.setPickOnBounds(false);
|
||||||
optionsBox.setTranslateY(50);
|
// optionsBox.setTranslateY(50);
|
||||||
optionsBox.setTranslateX(25);
|
// optionsBox.setTranslateX(25);
|
||||||
|
//
|
||||||
pane = new StackPane(optionsBox);
|
// pane = new StackPane(optionsBox);
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private ChoiceBox<Locale> languageSelectorCreation() {
|
// private ChoiceBox<Locale> languageSelectorCreation() {
|
||||||
final ChoiceBox<Locale> selectLanguage = new ChoiceBox<>();
|
// final ChoiceBox<Locale> selectLanguage = new ChoiceBox<>();
|
||||||
selectLanguage.setValue(currentLocale);
|
// selectLanguage.setValue(currentLocale);
|
||||||
|
//
|
||||||
for (Locale locFile : loc.getAvailableLocales()) {
|
// for (Locale locFile : loc.getAvailableLocales()) {
|
||||||
selectLanguage.getItems().add(locFile);
|
// selectLanguage.getItems().add(locFile);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
selectLanguage.setConverter(new javafx.util.StringConverter<Locale>() {
|
// selectLanguage.setConverter(new javafx.util.StringConverter<Locale>() {
|
||||||
@Override
|
// @Override
|
||||||
public String toString(Locale locale) {
|
// public String toString(Locale locale) {
|
||||||
return locale.getDisplayName();
|
// return locale.getDisplayName();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public Locale fromString(String string) {
|
// public Locale fromString(String string) {
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
selectLanguage.setOnAction(event -> {
|
// selectLanguage.setOnAction(event -> {
|
||||||
Locale selectedLocale = selectLanguage.getSelectionModel().getSelectedItem();
|
// Locale selectedLocale = selectLanguage.getSelectionModel().getSelectedItem();
|
||||||
if (selectedLocale != null) {
|
// if (selectedLocale != null) {
|
||||||
AppContext.setLocale(selectedLocale);
|
// AppContext.setLocale(selectedLocale);
|
||||||
App.pop();
|
// App.pop();
|
||||||
App.push(new OptionsMenu());
|
// App.push(new OptionsMenu());
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
return selectLanguage;
|
// return selectLanguage;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private ChoiceBox<GraphicsDevice> screenDeviceSelectorCreation() {
|
// private ChoiceBox<GraphicsDevice> screenDeviceSelectorCreation() {
|
||||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
// GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||||
GraphicsDevice[] devices = ge.getScreenDevices();
|
// GraphicsDevice[] devices = ge.getScreenDevices();
|
||||||
final ChoiceBox<GraphicsDevice> selectScreen = new ChoiceBox<>();
|
// final ChoiceBox<GraphicsDevice> selectScreen = new ChoiceBox<>();
|
||||||
for (GraphicsDevice screen : devices) {
|
// for (GraphicsDevice screen : devices) {
|
||||||
selectScreen.getItems().add(screen);
|
// selectScreen.getItems().add(screen);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
selectScreen.setOnAction(event -> {
|
// selectScreen.setOnAction(event -> {
|
||||||
int selectedIndex = selectScreen.getSelectionModel().getSelectedIndex();
|
// int selectedIndex = selectScreen.getSelectionModel().getSelectedIndex();
|
||||||
Object selectedItem = selectScreen.getSelectionModel().getSelectedItem();
|
// Object selectedItem = selectScreen.getSelectionModel().getSelectedItem();
|
||||||
|
//
|
||||||
System.out.println("Selection made: [" + selectedIndex + "] " + selectedItem);
|
// System.out.println("Selection made: [" + selectedIndex + "] " + selectedItem);
|
||||||
System.out.println(" ChoiceBox.getValue(): " + selectScreen.getValue());
|
// System.out.println(" ChoiceBox.getValue(): " + selectScreen.getValue());
|
||||||
});
|
// });
|
||||||
return selectScreen;
|
// return selectScreen;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private ChoiceBox<DisplayMode> displayModeSelectorCreation() {
|
// private ChoiceBox<DisplayMode> displayModeSelectorCreation() {
|
||||||
final ChoiceBox<DisplayMode> selectWindowSize = new ChoiceBox<>();
|
// final ChoiceBox<DisplayMode> selectWindowSize = new ChoiceBox<>();
|
||||||
for (DisplayMode displayMode : currentScreenDevice.getDisplayModes()) {
|
// for (DisplayMode displayMode : currentScreenDevice.getDisplayModes()) {
|
||||||
selectWindowSize.getItems().add(displayMode);
|
// selectWindowSize.getItems().add(displayMode);
|
||||||
}
|
// }
|
||||||
return selectWindowSize;
|
// return selectWindowSize;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private CheckBox selectFullscreenCreation() {
|
// private CheckBox selectFullscreenCreation() {
|
||||||
final CheckBox setFullscreen = new CheckBox("Fullscreen");
|
// final CheckBox setFullscreen = new CheckBox("Fullscreen");
|
||||||
setFullscreen.setSelected(App.isFullscreen());
|
// setFullscreen.setSelected(App.isFullscreen());
|
||||||
setFullscreen.setOnAction(event -> {
|
// setFullscreen.setOnAction(event -> {
|
||||||
boolean isSelected = setFullscreen.isSelected();
|
// boolean isSelected = setFullscreen.isSelected();
|
||||||
App.setFullscreen(isSelected);
|
// App.setFullscreen(isSelected);
|
||||||
});
|
// });
|
||||||
return setFullscreen;
|
// return setFullscreen;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private Slider volumeSelectorCreation() {
|
// private Slider volumeSelectorCreation() {
|
||||||
Slider volumeSlider = new Slider(0, 100, 50);
|
// Slider volumeSlider = new Slider(0, 100, 50);
|
||||||
new EventFlow()
|
// new EventFlow()
|
||||||
.addPostEvent(AudioEvents.GetCurrentVolume.class)
|
// .addPostEvent(AudioEvents.GetCurrentVolume.class)
|
||||||
.onResponse(AudioEvents.GetCurrentVolumeReponse.class, event -> {
|
// .onResponse(AudioEvents.GetCurrentVolumeReponse.class, event -> {
|
||||||
volumeSlider.setValue(event.currentVolume() * 100);
|
// volumeSlider.setValue(event.currentVolume() * 100);
|
||||||
}).asyncPostEvent();
|
// }).asyncPostEvent();
|
||||||
volumeSlider.setShowTickLabels(true);
|
// volumeSlider.setShowTickLabels(true);
|
||||||
volumeSlider.setShowTickMarks(true);
|
// volumeSlider.setShowTickMarks(true);
|
||||||
volumeSlider.setMajorTickUnit(25);
|
// volumeSlider.setMajorTickUnit(25);
|
||||||
volumeSlider.setMinorTickCount(4);
|
// volumeSlider.setMinorTickCount(4);
|
||||||
volumeSlider.setBlockIncrement(5);
|
// volumeSlider.setBlockIncrement(5);
|
||||||
volumeSlider.setMaxWidth(225);
|
// volumeSlider.setMaxWidth(225);
|
||||||
|
//
|
||||||
Label valueLabel = new Label(String.valueOf((int) volumeSlider.getValue()));
|
// Label valueLabel = new Label(String.valueOf((int) volumeSlider.getValue()));
|
||||||
|
//
|
||||||
volumeSlider.valueProperty().addListener((obs, oldVal, newVal) -> {
|
// volumeSlider.valueProperty().addListener((obs, oldVal, newVal) -> {
|
||||||
valueLabel.setText(String.valueOf(newVal.intValue()));
|
// valueLabel.setText(String.valueOf(newVal.intValue()));
|
||||||
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(newVal.doubleValue()/100.0))
|
// new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(newVal.doubleValue()/100.0))
|
||||||
.asyncPostEvent();
|
// .asyncPostEvent();
|
||||||
});
|
// });
|
||||||
return volumeSlider;
|
// return volumeSlider;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
@@ -1,128 +1,127 @@
|
|||||||
package org.toop.app.menu.game;
|
// package org.toop.app.menu.game;
|
||||||
|
//
|
||||||
import javafx.application.Platform;
|
// import javafx.application.Platform;
|
||||||
import javafx.geometry.Pos;
|
// import javafx.geometry.Pos;
|
||||||
import javafx.scene.canvas.Canvas;
|
// import javafx.scene.canvas.Canvas;
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
// import javafx.scene.canvas.GraphicsContext;
|
||||||
import javafx.scene.control.Button;
|
// import javafx.scene.control.Button;
|
||||||
import javafx.scene.layout.HBox;
|
// import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.Region;
|
// import javafx.scene.layout.Region;
|
||||||
import javafx.scene.layout.StackPane;
|
// import javafx.scene.layout.StackPane;
|
||||||
import javafx.scene.layout.VBox;
|
// import javafx.scene.layout.VBox;
|
||||||
import javafx.scene.text.Text;
|
// import javafx.scene.text.Text;
|
||||||
import org.toop.app.App;
|
// import org.toop.app.App;
|
||||||
import org.toop.app.menu.MainMenu;
|
// import org.toop.app.menu.MainMenu;
|
||||||
import org.toop.app.menu.Menu;
|
// import org.toop.app.menu.Menu;
|
||||||
import org.toop.framework.asset.ResourceManager;
|
// import org.toop.framework.asset.ResourceManager;
|
||||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||||
import org.toop.framework.eventbus.EventFlow;
|
// import org.toop.framework.eventbus.EventFlow;
|
||||||
import org.toop.local.AppContext;
|
// import org.toop.local.AppContext;
|
||||||
import org.toop.local.LocalizationEvents;
|
//
|
||||||
|
// import java.util.Locale;
|
||||||
import java.util.Locale;
|
//
|
||||||
|
// public abstract class GameMenu extends Menu {
|
||||||
public abstract class GameMenu extends Menu {
|
// protected final class Cell {
|
||||||
protected final class Cell {
|
// public float x;
|
||||||
public float x;
|
// public float y;
|
||||||
public float y;
|
//
|
||||||
|
// public float width;
|
||||||
public float width;
|
// public float height;
|
||||||
public float height;
|
//
|
||||||
|
// public Cell(float x, float y, float width, float height) {
|
||||||
public Cell(float x, float y, float width, float height) {
|
// this.x = x;
|
||||||
this.x = x;
|
// this.y = y;
|
||||||
this.y = y;
|
//
|
||||||
|
// this.width = width;
|
||||||
this.width = width;
|
// this.height = height;
|
||||||
this.height = height;
|
// }
|
||||||
}
|
//
|
||||||
|
// public boolean check(float x, float y) {
|
||||||
public boolean check(float x, float y) {
|
// return x >= this.x && y >= this.y && x <= this.x + width && y <= this.y + height;
|
||||||
return x >= this.x && y >= this.y && x <= this.x + width && y <= this.y + height;
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
|
// protected final int size;
|
||||||
protected final int size;
|
//
|
||||||
|
// protected final Canvas canvas;
|
||||||
protected final Canvas canvas;
|
// protected final GraphicsContext graphics;
|
||||||
protected final GraphicsContext graphics;
|
//
|
||||||
|
// protected final int rows;
|
||||||
protected final int rows;
|
// protected final int columns;
|
||||||
protected final int columns;
|
//
|
||||||
|
// protected final int gapSize;
|
||||||
protected final int gapSize;
|
//
|
||||||
|
// protected final Cell[] cells;
|
||||||
protected final Cell[] cells;
|
//
|
||||||
|
// private Locale currentLocale = AppContext.getLocale();
|
||||||
private Locale currentLocale = AppContext.getLocale();
|
// private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||||
private final LocalizationAsset loc = ResourceManager.get("localization");
|
// private final Button hint,back;
|
||||||
private final Button hint,back;
|
// protected GameMenu(int rows, int columns, int gapSize) {
|
||||||
protected GameMenu(int rows, int columns, int gapSize) {
|
//
|
||||||
|
// final int size = Math.min(App.getWidth(), App.getHeight()) / 5 * 4;
|
||||||
final int size = Math.min(App.getWidth(), App.getHeight()) / 5 * 4;
|
//
|
||||||
|
// final Canvas canvas = new Canvas(size, size);
|
||||||
final Canvas canvas = new Canvas(size, size);
|
//
|
||||||
|
// final GraphicsContext graphics = canvas.getGraphicsContext2D();
|
||||||
final GraphicsContext graphics = canvas.getGraphicsContext2D();
|
//
|
||||||
|
// this.size = size;
|
||||||
this.size = size;
|
//
|
||||||
|
// this.canvas = canvas;
|
||||||
this.canvas = canvas;
|
// this.graphics = graphics;
|
||||||
this.graphics = graphics;
|
//
|
||||||
|
// this.rows = rows;
|
||||||
this.rows = rows;
|
// this.columns = columns;
|
||||||
this.columns = columns;
|
//
|
||||||
|
// this.gapSize = gapSize;
|
||||||
this.gapSize = gapSize;
|
//
|
||||||
|
// cells = new Cell[rows * columns];
|
||||||
cells = new Cell[rows * columns];
|
//
|
||||||
|
// final float cellWidth = ((float)size - (rows - 1) * gapSize) / rows;
|
||||||
final float cellWidth = ((float)size - (rows - 1) * gapSize) / rows;
|
// final float cellHeight = ((float)size - (columns - 1) * gapSize) / rows;
|
||||||
final float cellHeight = ((float)size - (columns - 1) * gapSize) / rows;
|
//
|
||||||
|
// for (int y = 0; y < columns; y++) {
|
||||||
for (int y = 0; y < columns; y++) {
|
// final float startY = y * cellHeight + y * gapSize;
|
||||||
final float startY = y * cellHeight + y * gapSize;
|
//
|
||||||
|
// for (int x = 0; x < rows; x++) {
|
||||||
for (int x = 0; x < rows; x++) {
|
// final float startX = x * cellWidth + x * gapSize;
|
||||||
final float startX = x * cellWidth + x * gapSize;
|
// cells[y * rows + x] = new Cell(startX, startY, cellWidth, cellHeight);
|
||||||
cells[y * rows + x] = new Cell(startX, startY, cellWidth, cellHeight);
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
|
// final Region background = createBackground();
|
||||||
final Region background = createBackground();
|
//
|
||||||
|
// final Text player1 = createText("player_1", "Player 1");
|
||||||
final Text player1 = createText("player_1", "Player 1");
|
// final Text player2 = createText("player_2", "Player 2");
|
||||||
final Text player2 = createText("player_2", "Player 2");
|
//
|
||||||
|
// final HBox playersContainer = new HBox(100, player1, player2);
|
||||||
final HBox playersContainer = new HBox(100, player1, player2);
|
// playersContainer.setAlignment(Pos.TOP_CENTER);
|
||||||
playersContainer.setAlignment(Pos.TOP_CENTER);
|
// playersContainer.setPickOnBounds(false);
|
||||||
playersContainer.setPickOnBounds(false);
|
// playersContainer.setTranslateY(50);
|
||||||
playersContainer.setTranslateY(50);
|
//
|
||||||
|
// hint = createButton(loc.getString("gameMenuHint",currentLocale), () -> {});
|
||||||
hint = createButton(loc.getString("gameMenuHint",currentLocale), () -> {});
|
// back = createButton(loc.getString("gameMenuBack",currentLocale), () -> { App.activate(new MainMenu()); });
|
||||||
back = createButton(loc.getString("gameMenuBack",currentLocale), () -> { App.activate(new MainMenu()); });
|
//
|
||||||
|
// final VBox controlContainer = new VBox(hint, back);
|
||||||
final VBox controlContainer = new VBox(hint, back);
|
// StackPane.setAlignment(controlContainer, Pos.BOTTOM_LEFT);
|
||||||
StackPane.setAlignment(controlContainer, Pos.BOTTOM_LEFT);
|
// controlContainer.setPickOnBounds(false);
|
||||||
controlContainer.setPickOnBounds(false);
|
//
|
||||||
|
// pane = new StackPane(background, canvas, playersContainer, controlContainer);
|
||||||
pane = new StackPane(background, canvas, playersContainer, controlContainer);
|
// try {
|
||||||
try {
|
// new EventFlow()
|
||||||
new EventFlow()
|
// .listen(this::handleChangeLanguage);
|
||||||
.listen(this::handleChangeLanguage);
|
//
|
||||||
|
// }catch (Exception e){
|
||||||
}catch (Exception e){
|
// System.out.println("Something went wrong while trying to change the language.");
|
||||||
System.out.println("Something went wrong while trying to change the language.");
|
// throw e;
|
||||||
throw e;
|
// }
|
||||||
}
|
//
|
||||||
|
// }
|
||||||
}
|
// private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||||
private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
// Platform.runLater(() -> {
|
||||||
Platform.runLater(() -> {
|
// currentLocale = AppContext.getLocale();
|
||||||
currentLocale = AppContext.getLocale();
|
// hint.setText(loc.getString("gameMenuHint",currentLocale));
|
||||||
hint.setText(loc.getString("gameMenuHint",currentLocale));
|
// back.setText(loc.getString("gameMenuBack",currentLocale));
|
||||||
back.setText(loc.getString("gameMenuBack",currentLocale));
|
// });
|
||||||
});
|
//
|
||||||
|
// }
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package org.toop.local;
|
package org.toop.local;
|
||||||
|
|
||||||
|
import org.toop.app.events.AppEvents;
|
||||||
import org.toop.framework.eventbus.EventFlow;
|
import org.toop.framework.eventbus.EventFlow;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class AppContext {
|
public class AppContext {
|
||||||
@@ -10,12 +10,12 @@ public class AppContext {
|
|||||||
|
|
||||||
public static void setLocale(Locale locale) {
|
public static void setLocale(Locale locale) {
|
||||||
currentLocale = 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) {
|
public static void setCurrentLocale(Locale locale) {
|
||||||
currentLocale = 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() {
|
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 {
|
.container {
|
||||||
-fx-background-color: linear-gradient(to bottom right, #21a7b2, #8f32b9);
|
-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 {
|
.text {
|
||||||
@@ -10,28 +16,20 @@
|
|||||||
-fx-font-size: 24px;
|
-fx-font-size: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button, .text-field, .combo-box, .combo-box-popup .list-cell {
|
.button {
|
||||||
-fx-padding: 10 20;
|
-fx-padding: 10;
|
||||||
|
|
||||||
-fx-background-color: transparent;
|
-fx-background-color: transparent;
|
||||||
-fx-border-color: transparent;
|
-fx-border-color: transparent;
|
||||||
|
|
||||||
|
-fx-transition: all 0.3s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
.combo-box-popup .list-view {
|
.button:hover {
|
||||||
-fx-background-color: #1d1d1d;
|
|
||||||
}
|
|
||||||
|
|
||||||
.text-field {
|
|
||||||
-fx-text-fill: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button:hover, .text-field:hover, .combo-box:hover, .combo-box-popup .list-cell:hover {
|
|
||||||
-fx-cursor: hand;
|
-fx-cursor: hand;
|
||||||
|
|
||||||
-fx-effect: dropshadow(gaussian, #00ffff7f, 10, 0.5, 0, 0);
|
-fx-scale-x: 1.1;
|
||||||
-fx-border-color: white;
|
-fx-scale-y: 1.1;
|
||||||
}
|
|
||||||
|
|
||||||
.text-field:focused, .combo-box:focused {
|
-fx-effect: dropshadow(gaussian, #007fff, 10, 0.5, 0, 0);
|
||||||
-fx-border-color: white;
|
|
||||||
}
|
}
|
||||||
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 {
|
.background {
|
||||||
-fx-background-color: rgba(0, 0, 0, 0.6);
|
-fx-background-color: #0000007f;
|
||||||
}
|
|
||||||
|
|
||||||
.quit_box {
|
|
||||||
-fx-background-color: rgba(30, 30, 30, 0.5);
|
|
||||||
-fx-background-radius: 15;
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user