mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
Changed bundled resources to use static base name instead.
Added options menu with selectable language. Created checkbox for setting fullscreen. Refactored code to functions
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.toop.app;
|
||||
|
||||
import javafx.stage.Screen;
|
||||
import org.toop.app.canvas.TicTacToeCanvas;
|
||||
import javafx.application.Platform;
|
||||
import org.toop.app.menu.MainMenu;
|
||||
@@ -29,16 +30,17 @@ public final class App extends Application {
|
||||
private static Stage stage;
|
||||
private static StackPane root;
|
||||
|
||||
private static Screen screen; // TODO set screen
|
||||
private static int width;
|
||||
private static int height;
|
||||
|
||||
private static boolean isQuitting;
|
||||
private Locale currentLocale = AppContext.getLocale();
|
||||
private final LocalizationAsset loc = ResourceManager.get("localization.properties");
|
||||
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.properties");
|
||||
private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
public QuitMenu() {
|
||||
final Region background = createBackground("quit_background");
|
||||
|
||||
@@ -118,7 +120,7 @@ public final class App extends Application {
|
||||
private void handleChangeLanguage(LocalizationEvents.LanguageHasChanged event) {
|
||||
Platform.runLater(() -> {
|
||||
currentLocale = AppContext.getLocale();
|
||||
stage.setTitle(loc.getString("windowTitle",currentLocale));
|
||||
stage.setTitle(loc.getString("windowTitle", currentLocale));
|
||||
});
|
||||
|
||||
}
|
||||
@@ -145,4 +147,21 @@ public final class App extends Application {
|
||||
|
||||
public static int getWidth() { return width; }
|
||||
public static int getHeight() { return height; }
|
||||
|
||||
public static void setWidth(int widthSetter) {
|
||||
width = widthSetter;
|
||||
}
|
||||
|
||||
public static void setHeight(int heightSetter) {
|
||||
height = heightSetter;
|
||||
}
|
||||
|
||||
public static boolean isFullscreen() {
|
||||
return stage.isFullScreen();
|
||||
}
|
||||
|
||||
public static void setFullscreen(boolean fullscreen) {
|
||||
stage.setFullScreen(fullscreen);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import java.util.Locale;
|
||||
|
||||
public class GameSelectMenu extends Menu {
|
||||
private Locale currentLocale = AppContext.getLocale();
|
||||
private final LocalizationAsset loc = ResourceManager.get("localization.properties");
|
||||
private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
|
||||
final ComboBox<String> selectedMode, selectedGame;
|
||||
final TextField serverIpField;
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.Locale;
|
||||
|
||||
public final class MainMenu extends Menu {
|
||||
private Locale currentLocale = AppContext.getLocale();
|
||||
private final LocalizationAsset loc = ResourceManager.get("localization.properties");
|
||||
private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
private final Button tictactoe,reversi,credits,options,quit;
|
||||
public MainMenu() {
|
||||
final Region background = createBackground();
|
||||
|
||||
@@ -1,133 +1,116 @@
|
||||
package org.toop.app.menu;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.ChoiceBox;
|
||||
import javafx.scene.control.Label;
|
||||
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.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.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
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 final LocalizationAsset loc = ResourceManager.get("localization.properties");
|
||||
private Text chooseLang;
|
||||
private Button english,dutch,german,french,italian,spanish,chinese;
|
||||
private GraphicsDevice currentScreenDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0];
|
||||
|
||||
public OptionsMenu() {
|
||||
final Region background = createBackground("quit_background");
|
||||
final Label selectLanguageLabel = new Label(
|
||||
loc.getString("optionsMenuLabelSelectLanguage", currentLocale)
|
||||
);
|
||||
|
||||
chooseLang = createText(loc.getString("languageChangeText",currentLocale));
|
||||
english = createButton(loc.getString("languageEnglish",currentLocale), () -> AppContext.setCurrentLocale(Locale.ENGLISH));
|
||||
dutch = createButton(loc.getString("languageDutch",currentLocale), () -> AppContext.setCurrentLocale(Locale.of("nl")));
|
||||
german = createButton(loc.getString("languageGerman",currentLocale), () -> AppContext.setCurrentLocale(Locale.of("de")));
|
||||
french = createButton(loc.getString("languageFrench",currentLocale), () -> AppContext.setCurrentLocale(Locale.of("fr")));
|
||||
italian = createButton(loc.getString("languageItalian",currentLocale), () -> AppContext.setCurrentLocale(Locale.of("it")));
|
||||
spanish = createButton(loc.getString("languageSpanish",currentLocale), () -> AppContext.setCurrentLocale(Locale.of("es")));
|
||||
chinese = createButton(loc.getString("languageChinese",currentLocale), () -> AppContext.setCurrentLocale(Locale.of("zh")));
|
||||
final Button exitOptionsButton = createButton("Exit Options", () -> { App.pop(); } );
|
||||
|
||||
final VBox buttons = new VBox(10, chooseLang, english,dutch,german,french,italian,spanish,chinese);
|
||||
final VBox optionsBox = new VBox(10,
|
||||
selectLanguageLabel,
|
||||
languageSelectorCreation(),
|
||||
screenDeviceSelectorCreation(),
|
||||
displayModeSelectorCreation(),
|
||||
selectFullscreenCreation(),
|
||||
exitOptionsButton);
|
||||
|
||||
buttons.setAlignment(Pos.CENTER);
|
||||
buttons.getStyleClass().add("quit_box");
|
||||
buttons.setMaxWidth(300);
|
||||
buttons.setMaxHeight(600);
|
||||
pane = new StackPane(background, buttons);
|
||||
|
||||
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();
|
||||
chooseLang.setText(loc.getString("languageChangeText",currentLocale));
|
||||
english.setText(loc.getString("languageEnglish",currentLocale));
|
||||
dutch.setText(loc.getString("languageDutch",currentLocale));
|
||||
german.setText(loc.getString("languageGerman",currentLocale));
|
||||
french.setText(loc.getString("languageFrench",currentLocale));
|
||||
italian.setText(loc.getString("languageItalian",currentLocale));
|
||||
spanish.setText(loc.getString("languageSpanish",currentLocale));
|
||||
chinese.setText(loc.getString("languageChinese",currentLocale));
|
||||
});
|
||||
|
||||
}
|
||||
final Region background = createBackground();
|
||||
|
||||
GraphicsDevice currentScreen = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0];
|
||||
|
||||
LocalizationAsset locFiles = ResourceManager.get(LocalizationAsset.class, "localization");
|
||||
final Label selectLanguageLabel = new Label(loc.getString("optionsMenuLabelSelectLanguage", currentLocale));
|
||||
final ChoiceBox<Locale> selectLanguage = new ChoiceBox<>();
|
||||
selectLanguage.setValue(currentLocale);
|
||||
for (Locale locFile : locFiles.getAvailableLocales()) {
|
||||
selectLanguage.getItems().add(locFile);
|
||||
}
|
||||
|
||||
selectLanguage.setOnAction((event) -> {
|
||||
Locale selectedLocale = selectLanguage.getSelectionModel().getSelectedItem();
|
||||
AppContext.setLocale(selectedLocale);
|
||||
App.pop();
|
||||
App.push(new OptionsMenu());
|
||||
});
|
||||
|
||||
// GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
// GraphicsDevice[] devices = ge.getScreenDevices();
|
||||
// final ChoiceBox<GraphicsDevice> selectScreen = new ChoiceBox<>();
|
||||
// for (GraphicsDevice screen : devices) {
|
||||
// selectScreen.getItems().add(screen);
|
||||
// }
|
||||
//
|
||||
// selectScreen.setOnAction((event) -> {
|
||||
// int selectedIndex = selectScreen.getSelectionModel().getSelectedIndex();
|
||||
// Object selectedItem = selectScreen.getSelectionModel().getSelectedItem();
|
||||
//
|
||||
// System.out.println("Selection made: [" + selectedIndex + "] " + selectedItem);
|
||||
// System.out.println(" ChoiceBox.getValue(): " + selectScreen.getValue());
|
||||
// });
|
||||
//
|
||||
// final ChoiceBox<DisplayMode> selectWindowSize = new ChoiceBox<>();
|
||||
// for (DisplayMode displayMode : currentScreen.getDisplayModes()) {
|
||||
// selectWindowSize.getItems().add(displayMode);
|
||||
// }
|
||||
//
|
||||
//// if (currentScreen.isFullScreenSupported()) {}
|
||||
// final CheckBox setFullscreen = new CheckBox("Fullscreen");
|
||||
|
||||
final VBox optionsBox = new VBox(10, selectLanguageLabel, selectLanguage);
|
||||
optionsBox.setAlignment(Pos.CENTER);
|
||||
optionsBox.setPickOnBounds(false);
|
||||
optionsBox.setTranslateY(50);
|
||||
optionsBox.setTranslateX(25);
|
||||
|
||||
final Button credits = createButton("Credits", () -> { App.push(new CreditsMenu()); });
|
||||
final Button options = createButton("Exit Options", () -> { App.push(new MainMenu()); });
|
||||
final Button quit = createButton("Quit", () -> { App.quitPopup(); });
|
||||
pane = new StackPane(optionsBox);
|
||||
|
||||
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, optionsBox, controlBox);
|
||||
}
|
||||
|
||||
private ChoiceBox<Locale> languageSelectorCreation() {
|
||||
final ChoiceBox<Locale> selectLanguage = new ChoiceBox<>();
|
||||
selectLanguage.setValue(currentLocale);
|
||||
|
||||
for (Locale locFile : loc.getAvailableLocales()) {
|
||||
selectLanguage.getItems().add(locFile);
|
||||
}
|
||||
|
||||
selectLanguage.setConverter(new javafx.util.StringConverter<Locale>() {
|
||||
@Override
|
||||
public String toString(Locale locale) {
|
||||
return locale.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale fromString(String string) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
selectLanguage.setOnAction(event -> {
|
||||
Locale selectedLocale = selectLanguage.getSelectionModel().getSelectedItem();
|
||||
if (selectedLocale != null) {
|
||||
AppContext.setLocale(selectedLocale);
|
||||
App.pop();
|
||||
App.push(new OptionsMenu());
|
||||
}
|
||||
});
|
||||
|
||||
return selectLanguage;
|
||||
}
|
||||
|
||||
private ChoiceBox<GraphicsDevice> screenDeviceSelectorCreation() {
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice[] devices = ge.getScreenDevices();
|
||||
final ChoiceBox<GraphicsDevice> selectScreen = new ChoiceBox<>();
|
||||
for (GraphicsDevice screen : devices) {
|
||||
selectScreen.getItems().add(screen);
|
||||
}
|
||||
|
||||
selectScreen.setOnAction(event -> {
|
||||
int selectedIndex = selectScreen.getSelectionModel().getSelectedIndex();
|
||||
Object selectedItem = selectScreen.getSelectionModel().getSelectedItem();
|
||||
|
||||
System.out.println("Selection made: [" + selectedIndex + "] " + selectedItem);
|
||||
System.out.println(" ChoiceBox.getValue(): " + selectScreen.getValue());
|
||||
});
|
||||
return selectScreen;
|
||||
}
|
||||
|
||||
private ChoiceBox<DisplayMode> displayModeSelectorCreation() {
|
||||
final ChoiceBox<DisplayMode> selectWindowSize = new ChoiceBox<>();
|
||||
for (DisplayMode displayMode : currentScreenDevice.getDisplayModes()) {
|
||||
selectWindowSize.getItems().add(displayMode);
|
||||
}
|
||||
return selectWindowSize;
|
||||
}
|
||||
|
||||
private CheckBox selectFullscreenCreation() {
|
||||
final CheckBox setFullscreen = new CheckBox("Fullscreen");
|
||||
setFullscreen.setSelected(App.isFullscreen());
|
||||
setFullscreen.setOnAction(event -> {
|
||||
boolean isSelected = setFullscreen.isSelected();
|
||||
App.setFullscreen(isSelected);
|
||||
});
|
||||
return setFullscreen;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public abstract class GameMenu extends Menu {
|
||||
protected final Cell[] cells;
|
||||
|
||||
private Locale currentLocale = AppContext.getLocale();
|
||||
private final LocalizationAsset loc = ResourceManager.get("localization.properties");
|
||||
private final LocalizationAsset loc = ResourceManager.get("localization");
|
||||
private final Button hint,back;
|
||||
protected GameMenu(int rows, int columns, int gapSize) {
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.toop.local;
|
||||
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Locale;
|
||||
|
||||
public class AppContext {
|
||||
@@ -9,6 +10,7 @@ public class AppContext {
|
||||
|
||||
public static void setLocale(Locale locale) {
|
||||
currentLocale = locale;
|
||||
new EventFlow().addPostEvent(new LocalizationEvents.LanguageHasChanged(locale.getLanguage())).asyncPostEvent();
|
||||
}
|
||||
|
||||
public static void setCurrentLocale(Locale locale) {
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
windowTitle=ISY Games Selector
|
||||
|
||||
# Main Menu buttons
|
||||
mainMenuSelectTicTacToe=Tic Tac Toe\u5426
|
||||
mainMenuSelectReversi=Reversi\u5426
|
||||
mainMenuSelectTicTacToe=Tic Tac Toe
|
||||
mainMenuSelectReversi=Reversi
|
||||
mainMenuSelectSudoku=Sudoku
|
||||
mainMenuSelectBattleship=Battleship
|
||||
mainMenuSelectOther=Other
|
||||
|
||||
Reference in New Issue
Block a user