mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
readd: localization
This commit is contained in:
@@ -5,6 +5,7 @@ import org.toop.app.layer.layers.MainLayer;
|
||||
import org.toop.app.layer.layers.QuitLayer;
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.CssAsset;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
@@ -34,7 +35,7 @@ public final class App extends Application {
|
||||
final Scene scene = new Scene(root);
|
||||
scene.getStylesheets().add(ResourceManager.get(CssAsset.class, "app.css").getUrl());
|
||||
|
||||
stage.setTitle("pism");
|
||||
stage.setTitle(AppContext.getString("appTitle"));
|
||||
stage.setWidth(1080);
|
||||
stage.setHeight(720);
|
||||
|
||||
@@ -100,6 +101,8 @@ public final class App extends Application {
|
||||
}
|
||||
|
||||
public static void reloadAll() {
|
||||
stage.setTitle(AppContext.getString("appTitle"));
|
||||
|
||||
for (final Layer layer : stack) {
|
||||
layer.reload();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,4 @@ import org.toop.framework.eventbus.events.EventsBase;
|
||||
|
||||
public class AppEvents extends EventsBase {
|
||||
public record OnNodeHover() implements EventWithoutSnowflake {}
|
||||
|
||||
public record OnLanguageChange(String language) implements EventWithoutSnowflake {}
|
||||
}
|
||||
@@ -12,22 +12,17 @@ public abstract class Layer {
|
||||
protected StackPane layer;
|
||||
protected Region background;
|
||||
|
||||
protected Layer(String cssFile, String backgroundCssClass) {
|
||||
protected Layer(String cssFile) {
|
||||
layer = new StackPane();
|
||||
layer.setPickOnBounds(false);
|
||||
layer.getStylesheets().add(ResourceManager.get(CssAsset.class, cssFile).getUrl());
|
||||
|
||||
background = new Region();
|
||||
background.getStyleClass().add("background");
|
||||
background.setPrefSize(Double.MAX_VALUE, Double.MAX_VALUE);
|
||||
background.getStyleClass().add(backgroundCssClass);
|
||||
|
||||
layer.getChildren().addLast(background);
|
||||
}
|
||||
|
||||
protected Layer(String cssFile) {
|
||||
this(cssFile, "background");
|
||||
}
|
||||
|
||||
protected void addContainer(Container container, Pos position, int xOffset, int yOffset, int widthPercent, int heightPercent) {
|
||||
StackPane.setAlignment(container.getContainer(), position);
|
||||
|
||||
@@ -72,9 +67,5 @@ public abstract class Layer {
|
||||
return layer;
|
||||
}
|
||||
|
||||
public Region getBackground() {
|
||||
return background;
|
||||
}
|
||||
|
||||
public abstract void reload();
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import org.toop.app.layer.Container;
|
||||
import org.toop.app.layer.Layer;
|
||||
import org.toop.app.layer.containers.HorizontalContainer;
|
||||
import org.toop.app.layer.containers.VerticalContainer;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.animation.PauseTransition;
|
||||
import javafx.animation.TranslateTransition;
|
||||
@@ -14,17 +15,6 @@ import javafx.util.Duration;
|
||||
public final class CreditsLayer extends Layer {
|
||||
private final int lineHeight = 100;
|
||||
|
||||
private final String[] credits = {
|
||||
"Scrum Master: Stef",
|
||||
"Product Owner: Omar",
|
||||
"Merge Commander: Bas",
|
||||
"Localization: Ticho",
|
||||
"AI: Michiel",
|
||||
"Developers: Michiel, Bas, Stef, Omar, Ticho",
|
||||
"Moral Support: Wesley (voor 1 week)",
|
||||
"OpenGL: Omar"
|
||||
};
|
||||
|
||||
CreditsLayer() {
|
||||
super("credits.css");
|
||||
reload();
|
||||
@@ -34,6 +24,17 @@ public final class CreditsLayer extends Layer {
|
||||
public void reload() {
|
||||
popAll();
|
||||
|
||||
final String[] credits = {
|
||||
AppContext.getString("scrumMaster") + ": Stef",
|
||||
AppContext.getString("productOwner") + ": Omar",
|
||||
AppContext.getString("mergeCommander") + ": Bas",
|
||||
AppContext.getString("localization") + ": Ticho",
|
||||
AppContext.getString("ai") + ": Michiel",
|
||||
AppContext.getString("developers") + ": Michiel, Bas, Stef, Omar, Ticho",
|
||||
AppContext.getString("moralSupport") + ": Wesley",
|
||||
AppContext.getString("opengl") + ": Omar"
|
||||
};
|
||||
|
||||
final Container creditsContainer = new HorizontalContainer(0);
|
||||
|
||||
final Container animatedContainer = new VerticalContainer("animated_credits_container", lineHeight);
|
||||
@@ -44,7 +45,7 @@ public final class CreditsLayer extends Layer {
|
||||
}
|
||||
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
controlContainer.addButton("Back", () -> {
|
||||
controlContainer.addButton(AppContext.getString("back"), () -> {
|
||||
App.activate(new MainLayer());
|
||||
});
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.toop.app.App;
|
||||
import org.toop.app.layer.Container;
|
||||
import org.toop.app.layer.Layer;
|
||||
import org.toop.app.layer.containers.VerticalContainer;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
@@ -19,7 +20,7 @@ public class GameLayer extends Layer {
|
||||
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
|
||||
controlContainer.addButton("Back", () -> {
|
||||
controlContainer.addButton(AppContext.getString("back"), () -> {
|
||||
App.activate(new MainLayer());
|
||||
});
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.toop.app.layer.Layer;
|
||||
import org.toop.app.layer.containers.VerticalContainer;
|
||||
import org.toop.game.othello.Othello;
|
||||
import org.toop.game.tictactoe.TicTacToe;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
@@ -21,25 +22,25 @@ public final class MainLayer extends Layer {
|
||||
|
||||
final Container gamesContainer = new VerticalContainer(5);
|
||||
|
||||
gamesContainer.addButton("Tic Tac Toe", () -> {
|
||||
gamesContainer.addButton(AppContext.getString("tictactoe"), () -> {
|
||||
App.activate(new MultiplayerLayer<TicTacToe>());
|
||||
});
|
||||
|
||||
gamesContainer.addButton("Othello", () -> {
|
||||
gamesContainer.addButton(AppContext.getString("othello"), () -> {
|
||||
App.activate(new MultiplayerLayer<Othello>());
|
||||
});
|
||||
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
|
||||
controlContainer.addButton("Credits", () -> {
|
||||
controlContainer.addButton(AppContext.getString("credits"), () -> {
|
||||
App.activate(new CreditsLayer());
|
||||
});
|
||||
|
||||
controlContainer.addButton("Options", () -> {
|
||||
controlContainer.addButton(AppContext.getString("options"), () -> {
|
||||
App.activate(new OptionsLayer());
|
||||
});
|
||||
|
||||
controlContainer.addButton("Quit", () -> {
|
||||
controlContainer.addButton(AppContext.getString("quit"), () -> {
|
||||
App.quitPopup();
|
||||
});
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.toop.app.layer.Layer;
|
||||
import org.toop.app.layer.containers.HorizontalContainer;
|
||||
import org.toop.app.layer.containers.VerticalContainer;
|
||||
import org.toop.game.TurnBasedGame;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
@@ -34,7 +35,7 @@ public final class MultiplayerLayer<T extends TurnBasedGame> extends Layer {
|
||||
|
||||
final Container mainContainer = new VerticalContainer(5);
|
||||
|
||||
mainContainer.addToggle("Local", "Server", !isConnectionLocal, (server) -> {
|
||||
mainContainer.addToggle(AppContext.getString("local"), AppContext.getString("server"), !isConnectionLocal, (server) -> {
|
||||
isConnectionLocal = !server;
|
||||
reload();
|
||||
});
|
||||
@@ -54,56 +55,56 @@ public final class MultiplayerLayer<T extends TurnBasedGame> extends Layer {
|
||||
playersContainer.addContainer(player2Container, true);
|
||||
|
||||
if (isConnectionLocal) {
|
||||
mainContainer.addButton("Start", () -> {
|
||||
mainContainer.addButton(AppContext.getString("start"), () -> {
|
||||
});
|
||||
} else {
|
||||
mainContainer.addButton("Connect", () -> {
|
||||
mainContainer.addButton(AppContext.getString("connect"), () -> {
|
||||
});
|
||||
}
|
||||
|
||||
player1Container.addToggle("Human", "Computer", !isPlayer1Human, (computer) -> {
|
||||
player1Container.addToggle(AppContext.getString("human"), AppContext.getString("computer"), !isPlayer1Human, (computer) -> {
|
||||
isPlayer1Human = !computer;
|
||||
reload();
|
||||
});
|
||||
|
||||
if (isPlayer1Human) {
|
||||
player1Container.addText("Player name", true);
|
||||
player1Container.addText(AppContext.getString("playerName"), true);
|
||||
player1Container.addInput(player1Name, (name) -> {
|
||||
player1Name = name;
|
||||
});
|
||||
} else {
|
||||
player1Container.addText("Computer difficulty", true);
|
||||
player1Container.addText(AppContext.getString("computerDifficulty"), true);
|
||||
player1Container.addSlider(5, computer1Difficulty, (difficulty) -> {
|
||||
computer1Difficulty = difficulty;
|
||||
});
|
||||
}
|
||||
|
||||
if (isConnectionLocal) {
|
||||
player2Container.addToggle("Human", "Computer", !isPlayer2Human, (computer) -> {
|
||||
player2Container.addToggle(AppContext.getString("human"), AppContext.getString("computer"), !isPlayer2Human, (computer) -> {
|
||||
isPlayer2Human = !computer;
|
||||
reload();
|
||||
});
|
||||
|
||||
if (isPlayer2Human) {
|
||||
player2Container.addText("Player name", true);
|
||||
player2Container.addText(AppContext.getString("playerName"), true);
|
||||
player2Container.addInput(player2Name, (name) -> {
|
||||
player2Name = name;
|
||||
});
|
||||
} else {
|
||||
player2Container.addText("Computer difficulty", true);
|
||||
player2Container.addText(AppContext.getString("computerDifficulty"), true);
|
||||
player2Container.addSlider(5, computer2Difficulty, (difficulty) -> {
|
||||
computer2Difficulty = difficulty;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
player2Container.addText("Server IP", true);
|
||||
player2Container.addText(AppContext.getString("serverIP"), true);
|
||||
player2Container.addInput(serverIP, (ip) -> {
|
||||
serverIP = ip;
|
||||
});
|
||||
|
||||
player2Container.addSeparator(true);
|
||||
|
||||
player2Container.addText("Server Port", true);
|
||||
player2Container.addText(AppContext.getString("serverPort"), true);
|
||||
player2Container.addInput(serverPort, (port) -> {
|
||||
serverPort = port;
|
||||
});
|
||||
@@ -111,7 +112,7 @@ public final class MultiplayerLayer<T extends TurnBasedGame> extends Layer {
|
||||
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
|
||||
controlContainer.addButton("Back", () -> {
|
||||
controlContainer.addButton(AppContext.getString("back"), () -> {
|
||||
App.activate(new MainLayer());
|
||||
});
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@ import org.toop.app.App;
|
||||
import org.toop.app.layer.Container;
|
||||
import org.toop.app.layer.Layer;
|
||||
import org.toop.app.layer.containers.VerticalContainer;
|
||||
import org.toop.framework.asset.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;
|
||||
@@ -16,9 +14,6 @@ import javafx.scene.control.ChoiceBox;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class OptionsLayer extends Layer {
|
||||
private Locale currentLocale = AppContext.getLocale();
|
||||
private LocalizationAsset locale = ResourceManager.get("localization");
|
||||
|
||||
private static int currentVolume = 25;
|
||||
private static boolean isWindowed = true;
|
||||
|
||||
@@ -32,20 +27,22 @@ public final class OptionsLayer extends Layer {
|
||||
popAll();
|
||||
|
||||
final Container optionsContainer = new VerticalContainer(5);
|
||||
optionsContainer.addText("Language", false);
|
||||
optionsContainer.addText(AppContext.getString("language"), false);
|
||||
addLanguageBox(optionsContainer);
|
||||
optionsContainer.addSeparator(true);
|
||||
optionsContainer.addText("Volume", false);
|
||||
|
||||
optionsContainer.addText(AppContext.getString("volume"), false);
|
||||
addVolumeSlider(optionsContainer);
|
||||
optionsContainer.addSeparator(true);
|
||||
|
||||
addFullscreenToggle(optionsContainer);
|
||||
|
||||
final Container mainContainer = new VerticalContainer(50);
|
||||
mainContainer.addText("Options", false);
|
||||
mainContainer.addText(AppContext.getString("options"), false);
|
||||
mainContainer.addContainer(optionsContainer, true);
|
||||
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
controlContainer.addButton("Back", () -> {
|
||||
controlContainer.addButton(AppContext.getString("back"), () -> {
|
||||
App.activate(new MainLayer());
|
||||
});
|
||||
|
||||
@@ -54,24 +51,34 @@ public final class OptionsLayer extends Layer {
|
||||
}
|
||||
|
||||
private void addLanguageBox(Container container) {
|
||||
assert AppContext.getLocalization() != null;
|
||||
|
||||
final ChoiceBox<Locale> languageBox = container.addChoiceBox((locale) -> {
|
||||
if (locale == currentLocale) {
|
||||
if (locale == AppContext.getLocale()) {
|
||||
return;
|
||||
}
|
||||
|
||||
AppContext.setLocale(locale);
|
||||
|
||||
this.currentLocale = AppContext.getLocale();
|
||||
this.locale = ResourceManager.get("localization");
|
||||
|
||||
App.reloadAll();
|
||||
});
|
||||
|
||||
for (final Locale localeFile : locale.getAvailableLocales()) {
|
||||
for (final Locale localeFile : AppContext.getLocalization().getAvailableLocales()) {
|
||||
languageBox.getItems().add(localeFile);
|
||||
}
|
||||
|
||||
languageBox.setValue(currentLocale);
|
||||
languageBox.setConverter(new javafx.util.StringConverter<>() {
|
||||
@Override
|
||||
public String toString(Locale locale) {
|
||||
return AppContext.getString(locale.getDisplayName().toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale fromString(String string) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
languageBox.setValue(AppContext.getLocale());
|
||||
}
|
||||
|
||||
private void addVolumeSlider(Container container) {
|
||||
@@ -82,7 +89,7 @@ public final class OptionsLayer extends Layer {
|
||||
}
|
||||
|
||||
private void addFullscreenToggle(Container container) {
|
||||
container.addToggle("Windowed", "Fullscreen", !isWindowed, (fullscreen) -> {
|
||||
container.addToggle(AppContext.getString("windowed"), AppContext.getString("fullscreen"), !isWindowed, (fullscreen) -> {
|
||||
isWindowed = !fullscreen;
|
||||
App.setFullscreen(fullscreen);
|
||||
});
|
||||
|
||||
@@ -5,12 +5,13 @@ import org.toop.app.layer.Container;
|
||||
import org.toop.app.layer.Layer;
|
||||
import org.toop.app.layer.containers.HorizontalContainer;
|
||||
import org.toop.app.layer.containers.VerticalContainer;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
public final class QuitLayer extends Layer {
|
||||
public QuitLayer() {
|
||||
super("quit.css", "quit_background");
|
||||
super("quit.css");
|
||||
reload();
|
||||
}
|
||||
|
||||
@@ -19,18 +20,17 @@ public final class QuitLayer extends Layer {
|
||||
popAll();
|
||||
|
||||
final Container mainContainer = new VerticalContainer(30);
|
||||
|
||||
mainContainer.addText("Are you sure?", false);
|
||||
mainContainer.addText(AppContext.getString("quitSure"), false);
|
||||
|
||||
final Container controlContainer = new HorizontalContainer(30);
|
||||
|
||||
mainContainer.addContainer(controlContainer, false);
|
||||
|
||||
controlContainer.addButton("Yes", () -> {
|
||||
controlContainer.addButton(AppContext.getString("yes"), () -> {
|
||||
App.quit();
|
||||
});
|
||||
|
||||
controlContainer.addButton("No", () -> {
|
||||
controlContainer.addButton(AppContext.getString("no"), () -> {
|
||||
App.pop();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
// package org.toop.app.menu;
|
||||
//
|
||||
// import javafx.animation.Interpolator;
|
||||
// import javafx.animation.PauseTransition;
|
||||
// import javafx.animation.TranslateTransition;
|
||||
// import javafx.application.Platform;
|
||||
// import javafx.geometry.Pos;
|
||||
// import javafx.scene.control.Button;
|
||||
// import javafx.scene.layout.Region;
|
||||
// import javafx.scene.layout.StackPane;
|
||||
// import javafx.scene.layout.VBox;
|
||||
// import javafx.util.Duration;
|
||||
// import org.toop.app.App;
|
||||
// import org.toop.framework.asset.ResourceManager;
|
||||
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
// import org.toop.framework.eventbus.EventFlow;
|
||||
// import org.toop.local.AppContext;
|
||||
// import org.toop.local.LocalizationEvents;
|
||||
//
|
||||
// import java.util.Locale;
|
||||
//
|
||||
// public final class CreditsMenu extends Menu { ;
|
||||
// private Locale currentLocale = AppContext.getLocale();
|
||||
// private LocalizationAsset loc = ResourceManager.get("localization_en_us.properties");
|
||||
//
|
||||
// String[] credits = {
|
||||
// "Scrum Master: Stef",
|
||||
// "Product Owner: Omar",
|
||||
// "Merge Commander: Bas",
|
||||
// "Localization: Ticho",
|
||||
// "AI: Michiel",
|
||||
// "Developers: Michiel, Bas, Stef, Omar, Ticho",
|
||||
// "Moral Support: Wesley (voor 1 week)",
|
||||
// "OpenGL: Omar"
|
||||
// };
|
||||
//
|
||||
// double scrollDuration = 20.0;
|
||||
// double lineHeight = 40.0;
|
||||
//
|
||||
// public CreditsMenu() {
|
||||
// VBox creditsBox = new VBox(lineHeight / 2);
|
||||
// for (int i = credits.length - 1; i >= 0; i--) {
|
||||
// creditsBox.getChildren().add(createText(credits[i]));
|
||||
// creditsBox.setAlignment(Pos.CENTER);
|
||||
// }
|
||||
//
|
||||
// Button exit = new Button("<");
|
||||
// exit.setStyle(
|
||||
// "-fx-background-color: transparent;" +
|
||||
// "-fx-text-fill: white;" +
|
||||
// "-fx-font-size: 72px;" +
|
||||
// "-fx-padding: 10 20 10 20;"
|
||||
// );
|
||||
// exit.setOnAction(e -> App.pop());
|
||||
//
|
||||
// final Region background = createBackground();
|
||||
// StackPane.setAlignment(exit, Pos.TOP_LEFT);
|
||||
// pane = new StackPane(background, creditsBox, exit);
|
||||
//
|
||||
// Platform.runLater(() -> playCredits(creditsBox, 800));
|
||||
//
|
||||
// try {
|
||||
// new EventFlow()
|
||||
// .listen(this::handleChangeLanguage);
|
||||
//
|
||||
// }catch (Exception e){
|
||||
// System.out.println("Something went wrong while trying to change the language.");
|
||||
// throw e;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void playCredits(VBox creditsBox, double sceneLength) {
|
||||
// double height = (credits.length * lineHeight);
|
||||
// double startY = -sceneLength;
|
||||
// double endY = height;
|
||||
//
|
||||
// creditsBox.setTranslateY(startY);
|
||||
//
|
||||
// TranslateTransition scrollCredits = new TranslateTransition();
|
||||
// scrollCredits.setNode(creditsBox);
|
||||
// scrollCredits.setFromY(startY);
|
||||
// scrollCredits.setToY(endY / 2 - 200);
|
||||
// scrollCredits.setDuration(Duration.seconds(scrollDuration));
|
||||
// scrollCredits.setInterpolator(Interpolator.LINEAR);
|
||||
//
|
||||
// scrollCredits.setOnFinished(e -> {
|
||||
// PauseTransition pauseCredits = new PauseTransition(Duration.seconds(5));
|
||||
// pauseCredits.setOnFinished(a -> playCredits(creditsBox, sceneLength));
|
||||
// pauseCredits.play();
|
||||
// });
|
||||
//
|
||||
// scrollCredits.play();
|
||||
// }
|
||||
// private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
// Platform.runLater(() -> {
|
||||
// currentLocale = AppContext.getLocale();
|
||||
// //credits.setText(loc.getString("credits",currentLocale));
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
@@ -1,66 +0,0 @@
|
||||
// package org.toop.app.menu;
|
||||
//
|
||||
// import javafx.application.Platform;
|
||||
// import javafx.scene.control.ComboBox;
|
||||
// import javafx.scene.control.TextField;
|
||||
// import javafx.scene.layout.HBox;
|
||||
// import javafx.scene.layout.Region;
|
||||
// import javafx.scene.layout.StackPane;
|
||||
// import javafx.scene.layout.VBox;
|
||||
// import org.toop.app.GameType;
|
||||
// import org.toop.framework.asset.ResourceManager;
|
||||
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
// import org.toop.framework.eventbus.EventFlow;
|
||||
// import org.toop.local.AppContext;
|
||||
//
|
||||
// import java.util.Locale;
|
||||
//
|
||||
// public class GameSelectMenu extends Menu {
|
||||
// private Locale currentLocale = AppContext.getLocale();
|
||||
// private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
//
|
||||
// final ComboBox<String> selectedMode, selectedGame;
|
||||
// final TextField serverIpField;
|
||||
//
|
||||
// public GameSelectMenu(GameType type) {
|
||||
// final Region background = createBackground();
|
||||
//
|
||||
// selectedGame = new ComboBox<>();
|
||||
// selectedGame.getItems().add(GameType.toName(GameType.TICTACTOE));
|
||||
// selectedGame.getItems().add(GameType.toName(GameType.REVERSI));
|
||||
// selectedGame.setValue(GameType.toName(type));
|
||||
//
|
||||
// selectedMode = new ComboBox<>();
|
||||
// selectedMode.getItems().add("Local");
|
||||
// selectedMode.getItems().add("Online");
|
||||
// selectedMode.setValue("Local");
|
||||
//
|
||||
// final HBox selectedContainer = new HBox(10, selectedGame, selectedMode);
|
||||
//
|
||||
// serverIpField = new TextField();
|
||||
// serverIpField.setPromptText(loc.getString("gameSelectMenuEnterIP",currentLocale));
|
||||
//
|
||||
// VBox box = new VBox(selectedContainer, serverIpField);
|
||||
// pane = new StackPane(background, box);
|
||||
// try {
|
||||
// new EventFlow()
|
||||
// .listen(this::handleChangeLanguage);
|
||||
//
|
||||
// }catch (Exception e){
|
||||
// System.out.println("Something went wrong while trying to change the language.");
|
||||
// throw e;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
// Platform.runLater(() -> {
|
||||
// currentLocale = AppContext.getLocale();
|
||||
// serverIpField.setPromptText(loc.getString("gameSelectMenuEnterIP",currentLocale));
|
||||
// selectedGame.getItems().set(0, loc.getString("mainMenuSelectTicTacToe",currentLocale));
|
||||
// selectedGame.getItems().set(1, loc.getString("mainMenuSelectReversi",currentLocale));
|
||||
// selectedMode.getItems().set(0, loc.getString("gameSelectMenuLocal",currentLocale));
|
||||
// selectedMode.getItems().set(1, loc.getString("gameSelectMenuOnline",currentLocale));
|
||||
// });
|
||||
//
|
||||
// }
|
||||
// }
|
||||
@@ -1,69 +0,0 @@
|
||||
// package org.toop.app.menu;
|
||||
//
|
||||
// import javafx.application.Platform;
|
||||
// import org.toop.app.App;
|
||||
// import org.toop.app.GameType;
|
||||
//
|
||||
// import javafx.geometry.Pos;
|
||||
// import javafx.scene.control.Button;
|
||||
// import javafx.scene.layout.*;
|
||||
// import org.toop.framework.asset.ResourceManager;
|
||||
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
// import org.toop.framework.eventbus.EventFlow;
|
||||
// import org.toop.game.tictactoe.TicTacToe;
|
||||
// import org.toop.local.AppContext;
|
||||
// import org.toop.local.LocalizationEvents;
|
||||
//
|
||||
// import java.util.Locale;
|
||||
//
|
||||
// public final class MainMenu extends Menu {
|
||||
// private Locale currentLocale = AppContext.getLocale();
|
||||
// private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
// private final Button tictactoe,reversi,credits,options,quit;
|
||||
// public MainMenu() {
|
||||
// final Region background = createBackground();
|
||||
//
|
||||
// tictactoe = createButton(
|
||||
// loc.getString("mainMenuSelectTicTacToe",currentLocale), () -> { App.activate(new GameSelectMenu(GameType.TICTACTOE)); });
|
||||
// reversi = createButton(
|
||||
// loc.getString("mainMenuSelectReversi",currentLocale), () -> { App.activate(new GameSelectMenu(GameType.REVERSI)); });
|
||||
//
|
||||
// final VBox gamesBox = new VBox(10, tictactoe, reversi);
|
||||
// gamesBox.setAlignment(Pos.TOP_LEFT);
|
||||
// gamesBox.setPickOnBounds(false);
|
||||
// gamesBox.setTranslateY(50);
|
||||
// gamesBox.setTranslateX(25);
|
||||
//
|
||||
// credits = createButton(loc.getString("mainMenuSelectCredits",currentLocale), () -> { App.push(new CreditsMenu()); });
|
||||
// options = createButton(loc.getString("mainMenuSelectOptions",currentLocale), () -> { App.push(new OptionsMenu()); });
|
||||
// quit = createButton(loc.getString("mainMenuSelectQuit",currentLocale), () -> { App.quitPopup(); });
|
||||
//
|
||||
// final VBox controlBox = new VBox(10, credits, options, quit);
|
||||
// controlBox.setAlignment(Pos.BOTTOM_LEFT);
|
||||
// controlBox.setPickOnBounds(false);
|
||||
// controlBox.setTranslateY(-50);
|
||||
// controlBox.setTranslateX(25);
|
||||
//
|
||||
// pane = new StackPane(background, gamesBox, controlBox);
|
||||
// try {
|
||||
// new EventFlow()
|
||||
// .listen(this::handleChangeLanguage);
|
||||
//
|
||||
// }catch (Exception e){
|
||||
// System.out.println("Something went wrong while trying to change the language.");
|
||||
// throw e;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
// Platform.runLater(() -> {
|
||||
// currentLocale = AppContext.getLocale();
|
||||
// tictactoe.setText(loc.getString("mainMenuSelectTicTacToe",currentLocale));
|
||||
// reversi.setText(loc.getString("mainMenuSelectReversi",currentLocale));
|
||||
// credits.setText(loc.getString("mainMenuSelectCredits",currentLocale));
|
||||
// options.setText(loc.getString("mainMenuSelectOptions",currentLocale));
|
||||
// quit.setText(loc.getString("mainMenuSelectQuit",currentLocale));
|
||||
// });
|
||||
//
|
||||
// }
|
||||
// }
|
||||
@@ -1,51 +0,0 @@
|
||||
package org.toop.app.menu;
|
||||
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.text.Text;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
|
||||
public abstract class Menu {
|
||||
protected Pane pane;
|
||||
public Pane getPane() { return pane; }
|
||||
|
||||
public Region createBackground(String css) {
|
||||
final Region background = new Region();
|
||||
background.setPrefSize(Double.MAX_VALUE, Double.MAX_VALUE);
|
||||
background.getStyleClass().add(css);
|
||||
|
||||
return background;
|
||||
}
|
||||
|
||||
public Region createBackground() {
|
||||
return createBackground("background");
|
||||
}
|
||||
|
||||
public Text createText(String css, String x) {
|
||||
final Text text = new Text(x);
|
||||
text.getStyleClass().add(css);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
public Text createText(String x) {
|
||||
return createText("text", x);
|
||||
}
|
||||
|
||||
public Button createButton(String css, String x, Runnable runnable) {
|
||||
final Button button = new Button(x);
|
||||
button.setOnAction(_ -> {
|
||||
new EventFlow().addPostEvent(new AudioEvents.clickButton()).asyncPostEvent();
|
||||
runnable.run();
|
||||
});
|
||||
button.getStyleClass().add(css);
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
public Button createButton(String x, Runnable runnable) {
|
||||
return createButton("button", x, runnable);
|
||||
}
|
||||
}
|
||||
@@ -1,174 +0,0 @@
|
||||
// package org.toop.app.menu;
|
||||
//
|
||||
// import javafx.geometry.Pos;
|
||||
// import javafx.scene.control.*;
|
||||
// import javafx.scene.control.Button;
|
||||
// import javafx.scene.control.Label;
|
||||
// import javafx.scene.layout.Region;
|
||||
// import javafx.scene.layout.StackPane;
|
||||
// import javafx.scene.layout.VBox;
|
||||
// import org.toop.app.App;
|
||||
// import org.toop.framework.asset.ResourceManager;
|
||||
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
// import org.toop.framework.audio.events.AudioEvents;
|
||||
// import org.toop.framework.eventbus.EventFlow;
|
||||
// import org.toop.local.AppContext;
|
||||
//
|
||||
// import java.awt.*;
|
||||
// import java.util.Locale;
|
||||
//
|
||||
// public final class OptionsMenu extends Menu {
|
||||
// private Locale currentLocale = AppContext.getLocale();
|
||||
// private LocalizationAsset loc = ResourceManager.get("localization");
|
||||
// private GraphicsDevice currentScreenDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0];
|
||||
//
|
||||
// public OptionsMenu() {
|
||||
// final Label selectLanguageLabel = new Label(
|
||||
// loc.getString("optionsMenuLabelSelectLanguage", currentLocale)
|
||||
// );
|
||||
//
|
||||
// final Button exitOptionsButton = createButton("Exit Options", () -> { App.pop(); } );
|
||||
//
|
||||
// final VBox optionsBox = new VBox(10,
|
||||
// selectLanguageLabel,
|
||||
// languageSelectorCreation(),
|
||||
// screenDeviceSelectorCreation(),
|
||||
// displayModeSelectorCreation(),
|
||||
// selectFullscreenCreation(),
|
||||
// volumeSelectorCreation(),
|
||||
// exitOptionsButton);
|
||||
//
|
||||
// optionsBox.setAlignment(Pos.CENTER);
|
||||
// optionsBox.setPickOnBounds(false);
|
||||
// optionsBox.setTranslateY(50);
|
||||
// optionsBox.setTranslateX(25);
|
||||
//
|
||||
// pane = new StackPane(optionsBox);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private ChoiceBox<Locale> languageSelectorCreation() {
|
||||
// final ChoiceBox<Locale> selectLanguage = new ChoiceBox<>();
|
||||
// selectLanguage.setValue(currentLocale);
|
||||
//
|
||||
// for (Locale locFile : loc.getAvailableLocales()) {
|
||||
// selectLanguage.getItems().add(locFile);
|
||||
// }
|
||||
//
|
||||
// selectLanguage.setConverter(new javafx.util.StringConverter<>() {
|
||||
// @Override
|
||||
// public String toString(Locale locale) {
|
||||
// return locale.getDisplayName();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Locale fromString(String string) {
|
||||
// return null;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// selectLanguage.setOnShowing(event -> {
|
||||
// new EventFlow().addPostEvent(new AudioEvents.clickButton()).asyncPostEvent();
|
||||
// });
|
||||
//
|
||||
// selectLanguage.setOnAction(event -> {
|
||||
// new EventFlow().addPostEvent(new AudioEvents.clickButton()).asyncPostEvent();
|
||||
// Locale selectedLocale = selectLanguage.getSelectionModel().getSelectedItem();
|
||||
// if (selectedLocale != null) {
|
||||
// AppContext.setLocale(selectedLocale);
|
||||
// App.pop();
|
||||
// App.push(new OptionsMenu());
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// return selectLanguage;
|
||||
// }
|
||||
//
|
||||
// private ChoiceBox<GraphicsDevice> screenDeviceSelectorCreation() {
|
||||
// GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
// GraphicsDevice[] devices = ge.getScreenDevices();
|
||||
// final ChoiceBox<GraphicsDevice> selectScreen = new ChoiceBox<>();
|
||||
// for (GraphicsDevice screen : devices) {
|
||||
// selectScreen.getItems().add(screen);
|
||||
// }
|
||||
//
|
||||
// selectScreen.setOnShowing(event -> {
|
||||
// new EventFlow().addPostEvent(new AudioEvents.clickButton()).asyncPostEvent();
|
||||
// });
|
||||
//
|
||||
// selectScreen.setOnAction(event -> {
|
||||
// new EventFlow().addPostEvent(new AudioEvents.clickButton()).asyncPostEvent();
|
||||
// int selectedIndex = selectScreen.getSelectionModel().getSelectedIndex();
|
||||
// Object selectedItem = selectScreen.getSelectionModel().getSelectedItem();
|
||||
//
|
||||
// System.out.println("Selection made: [" + selectedIndex + "] " + selectedItem);
|
||||
// System.out.println(" ChoiceBox.getValue(): " + selectScreen.getValue());
|
||||
// });
|
||||
// return selectScreen;
|
||||
// }
|
||||
//
|
||||
// private ChoiceBox<DisplayMode> displayModeSelectorCreation() {
|
||||
// final ChoiceBox<DisplayMode> selectWindowSize = new ChoiceBox<>();
|
||||
// for (DisplayMode displayMode : currentScreenDevice.getDisplayModes()) {
|
||||
// selectWindowSize.getItems().add(displayMode);
|
||||
// }
|
||||
// selectWindowSize.setOnShowing(event -> {
|
||||
// new EventFlow().addPostEvent(new AudioEvents.clickButton()).asyncPostEvent();
|
||||
// });
|
||||
// selectWindowSize.setOnAction(event -> {
|
||||
// new EventFlow().addPostEvent(new AudioEvents.clickButton()).asyncPostEvent();
|
||||
// int selectedIndex = selectWindowSize.getSelectionModel().getSelectedIndex();
|
||||
// Object selectedItem = selectWindowSize.getSelectionModel().getSelectedItem();
|
||||
//
|
||||
// System.out.println("Selection made: [" + selectedIndex + "] " + selectedItem);
|
||||
// System.out.println(" ChoiceBox.getValue(): " + selectWindowSize.getValue());
|
||||
// });
|
||||
// return selectWindowSize;
|
||||
// }
|
||||
//
|
||||
// private CheckBox selectFullscreenCreation() {
|
||||
// final CheckBox setFullscreen = new CheckBox("Fullscreen");
|
||||
// setFullscreen.setSelected(App.isFullscreen());
|
||||
// setFullscreen.setOnAction(event -> {
|
||||
// new EventFlow().addPostEvent(new AudioEvents.clickButton()).asyncPostEvent();
|
||||
// boolean isSelected = setFullscreen.isSelected();
|
||||
// App.setFullscreen(isSelected);
|
||||
// });
|
||||
// return setFullscreen;
|
||||
// }
|
||||
//
|
||||
// private Slider volumeSelectorCreation() {
|
||||
// Slider volumeSlider = new Slider(0, 100, 50);
|
||||
// new EventFlow()
|
||||
// .addPostEvent(AudioEvents.GetCurrentVolume.class)
|
||||
// .onResponse(AudioEvents.GetCurrentVolumeReponse.class, event -> {
|
||||
// volumeSlider.setValue(event.currentVolume() * 100);
|
||||
// }, true).asyncPostEvent();
|
||||
// volumeSlider.setShowTickLabels(true);
|
||||
// volumeSlider.setShowTickMarks(true);
|
||||
// volumeSlider.setMajorTickUnit(25);
|
||||
// volumeSlider.setMinorTickCount(4);
|
||||
// volumeSlider.setBlockIncrement(5);
|
||||
// volumeSlider.setMaxWidth(225);
|
||||
//
|
||||
// Label valueLabel = new Label(String.valueOf((int) volumeSlider.getValue()));
|
||||
//
|
||||
// final long[] lastPlayed = {0};
|
||||
// final long cooldown = 50;
|
||||
// volumeSlider.valueProperty().addListener((obs, oldVal, newVal) -> {
|
||||
// long now = System.currentTimeMillis();
|
||||
//
|
||||
// if (now - lastPlayed[0] >= cooldown) {
|
||||
// lastPlayed[0] = now;
|
||||
// // new EventFlow().addPostEvent(new AudioEvents.clickButton())
|
||||
// // .asyncPostEvent(); // TODO: creates double sound bug, WHYYY????
|
||||
// }
|
||||
// valueLabel.setText(String.valueOf(newVal.intValue()));
|
||||
// new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(newVal.doubleValue()/100.0))
|
||||
// .asyncPostEvent();
|
||||
// });
|
||||
//
|
||||
// return volumeSlider;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
@@ -1,127 +0,0 @@
|
||||
// package org.toop.app.menu.game;
|
||||
//
|
||||
// import javafx.application.Platform;
|
||||
// import javafx.geometry.Pos;
|
||||
// import javafx.scene.canvas.Canvas;
|
||||
// import javafx.scene.canvas.GraphicsContext;
|
||||
// import javafx.scene.control.Button;
|
||||
// import javafx.scene.layout.HBox;
|
||||
// import javafx.scene.layout.Region;
|
||||
// import javafx.scene.layout.StackPane;
|
||||
// import javafx.scene.layout.VBox;
|
||||
// import javafx.scene.text.Text;
|
||||
// import org.toop.app.App;
|
||||
// import org.toop.app.menu.MainMenu;
|
||||
// import org.toop.app.menu.Menu;
|
||||
// import org.toop.framework.asset.ResourceManager;
|
||||
// import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
// import org.toop.framework.eventbus.EventFlow;
|
||||
// import org.toop.local.AppContext;
|
||||
//
|
||||
// import java.util.Locale;
|
||||
//
|
||||
// public abstract class GameMenu extends Menu {
|
||||
// protected final class Cell {
|
||||
// public float x;
|
||||
// public float y;
|
||||
//
|
||||
// public float width;
|
||||
// public float height;
|
||||
//
|
||||
// public Cell(float x, float y, float width, float height) {
|
||||
// this.x = x;
|
||||
// this.y = y;
|
||||
//
|
||||
// this.width = width;
|
||||
// this.height = height;
|
||||
// }
|
||||
//
|
||||
// public boolean check(float x, float y) {
|
||||
// return x >= this.x && y >= this.y && x <= this.x + width && y <= this.y + height;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// protected final int size;
|
||||
//
|
||||
// protected final Canvas canvas;
|
||||
// protected final GraphicsContext graphics;
|
||||
//
|
||||
// protected final int rows;
|
||||
// protected final int columns;
|
||||
//
|
||||
// protected final int gapSize;
|
||||
//
|
||||
// protected final Cell[] cells;
|
||||
//
|
||||
// private Locale currentLocale = AppContext.getLocale();
|
||||
// private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
// private final Button hint,back;
|
||||
// protected GameMenu(int rows, int columns, int gapSize) {
|
||||
//
|
||||
// final int size = Math.min(App.getWidth(), App.getHeight()) / 5 * 4;
|
||||
//
|
||||
// final Canvas canvas = new Canvas(size, size);
|
||||
//
|
||||
// final GraphicsContext graphics = canvas.getGraphicsContext2D();
|
||||
//
|
||||
// this.size = size;
|
||||
//
|
||||
// this.canvas = canvas;
|
||||
// this.graphics = graphics;
|
||||
//
|
||||
// this.rows = rows;
|
||||
// this.columns = columns;
|
||||
//
|
||||
// this.gapSize = gapSize;
|
||||
//
|
||||
// cells = new Cell[rows * columns];
|
||||
//
|
||||
// final float cellWidth = ((float)size - (rows - 1) * gapSize) / rows;
|
||||
// final float cellHeight = ((float)size - (columns - 1) * gapSize) / rows;
|
||||
//
|
||||
// for (int y = 0; y < columns; y++) {
|
||||
// final float startY = y * cellHeight + y * gapSize;
|
||||
//
|
||||
// for (int x = 0; x < rows; x++) {
|
||||
// final float startX = x * cellWidth + x * gapSize;
|
||||
// cells[y * rows + x] = new Cell(startX, startY, cellWidth, cellHeight);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// final Region background = createBackground();
|
||||
//
|
||||
// final Text player1 = createText("player_1", "Player 1");
|
||||
// final Text player2 = createText("player_2", "Player 2");
|
||||
//
|
||||
// final HBox playersContainer = new HBox(100, player1, player2);
|
||||
// playersContainer.setAlignment(Pos.TOP_CENTER);
|
||||
// playersContainer.setPickOnBounds(false);
|
||||
// playersContainer.setTranslateY(50);
|
||||
//
|
||||
// hint = createButton(loc.getString("gameMenuHint",currentLocale), () -> {});
|
||||
// back = createButton(loc.getString("gameMenuBack",currentLocale), () -> { App.activate(new MainMenu()); });
|
||||
//
|
||||
// final VBox controlContainer = new VBox(hint, back);
|
||||
// StackPane.setAlignment(controlContainer, Pos.BOTTOM_LEFT);
|
||||
// controlContainer.setPickOnBounds(false);
|
||||
//
|
||||
// pane = new StackPane(background, canvas, playersContainer, controlContainer);
|
||||
// try {
|
||||
// new EventFlow()
|
||||
// .listen(this::handleChangeLanguage);
|
||||
//
|
||||
// }catch (Exception e){
|
||||
// System.out.println("Something went wrong while trying to change the language.");
|
||||
// throw e;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
// Platform.runLater(() -> {
|
||||
// currentLocale = AppContext.getLocale();
|
||||
// hint.setText(loc.getString("gameMenuHint",currentLocale));
|
||||
// back.setText(loc.getString("gameMenuBack",currentLocale));
|
||||
// });
|
||||
//
|
||||
// }
|
||||
// }
|
||||
@@ -1,24 +1,28 @@
|
||||
package org.toop.local;
|
||||
|
||||
import org.toop.app.events.AppEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class AppContext {
|
||||
private static Locale currentLocale = Locale.getDefault();
|
||||
private static final LocalizationAsset localization = ResourceManager.get("localization");
|
||||
private static Locale locale = Locale.forLanguageTag("en");
|
||||
|
||||
public static void setLocale(Locale locale) {
|
||||
currentLocale = locale;
|
||||
new EventFlow().addPostEvent(new AppEvents.OnLanguageChange(locale.getLanguage())).asyncPostEvent();
|
||||
}
|
||||
public static LocalizationAsset getLocalization() {
|
||||
return localization;
|
||||
}
|
||||
|
||||
public static void setCurrentLocale(Locale locale) {
|
||||
currentLocale = locale;
|
||||
new EventFlow().addPostEvent(new AppEvents.OnLanguageChange(locale.getLanguage())).asyncPostEvent();
|
||||
}
|
||||
public static void setLocale(Locale locale) {
|
||||
AppContext.locale = locale;
|
||||
}
|
||||
|
||||
public static Locale getLocale() {
|
||||
return currentLocale;
|
||||
}
|
||||
}
|
||||
public static Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public static String getString(String key) {
|
||||
assert localization != null;
|
||||
return localization.getString(key, locale);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user