mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
added localization options
//todo add all the strings
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.toop;
|
||||
|
||||
import org.toop.app.gui.LocalServerSelector;
|
||||
import org.toop.framework.networking.NetworkingClientManager;
|
||||
import org.toop.framework.networking.NetworkingInitializationException;
|
||||
|
||||
@@ -7,6 +8,7 @@ import org.toop.framework.networking.NetworkingInitializationException;
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
initSystems();
|
||||
javax.swing.SwingUtilities.invokeLater(LocalServerSelector::new);
|
||||
}
|
||||
|
||||
private static void initSystems() throws NetworkingInitializationException {
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
package org.toop.app.gui;
|
||||
|
||||
import org.toop.events.WindowEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class LocalServerSelector {
|
||||
private JPanel panel1;
|
||||
private JButton serverButton;
|
||||
private JButton localButton;
|
||||
private final JFrame frame;
|
||||
Locale locale = AppContext.getLocale();
|
||||
ResourceBundle resourceBundle = ResourceBundle.getBundle("Localization", locale);
|
||||
|
||||
public LocalServerSelector() {
|
||||
frame = new JFrame("Server Selector");
|
||||
frame = new JFrame(resourceBundle.getString("windowTitleServerSelector"));
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setContentPane(panel1);
|
||||
frame.setSize(1920, 1080);
|
||||
@@ -17,9 +25,15 @@ public class LocalServerSelector {
|
||||
frame.setVisible(true);
|
||||
|
||||
serverButton.addActionListener(e -> onServerClicked());
|
||||
serverButton.setText(resourceBundle.getString("buttonSelectServer"));
|
||||
localButton.addActionListener(e -> onLocalClicked());
|
||||
localButton.setText(resourceBundle.getString("buttonSelectLocal"));
|
||||
new EventFlow().listen(WindowEvents.LanguageChanged.class, this::changeLanguage);
|
||||
}
|
||||
private void changeLanguage(WindowEvents.LanguageChanged event) {
|
||||
locale = AppContext.getLocale();
|
||||
resourceBundle = ResourceBundle.getBundle("Localization", locale);
|
||||
}
|
||||
|
||||
private void onServerClicked() {
|
||||
frame.dispose();
|
||||
new RemoteGameSelector();
|
||||
|
||||
@@ -22,4 +22,7 @@ public class WindowEvents extends EventsBase {
|
||||
|
||||
/** Triggers when the mouse is released within the window. */
|
||||
public record OnMouseRelease(int button) implements EventWithoutSnowflake {}
|
||||
|
||||
/** Triggers when the language is changed. */
|
||||
public record LanguageChanged() implements EventWithoutSnowflake {}
|
||||
}
|
||||
14
app/src/main/java/org/toop/local/AppContext.java
Normal file
14
app/src/main/java/org/toop/local/AppContext.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package org.toop.local;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class AppContext {
|
||||
private static Locale currentLocale = Locale.getDefault();
|
||||
|
||||
public static void setCurrentLocale(Locale locale) {
|
||||
currentLocale = locale;
|
||||
}
|
||||
public static Locale getLocale() {
|
||||
return currentLocale;
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,16 @@ package org.toop.tictactoe.gui;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
import javax.swing.*;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.toop.app.gui.LocalGameSelector;
|
||||
import org.toop.app.gui.RemoteGameSelector;
|
||||
import org.toop.events.WindowEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.local.AppContext;
|
||||
import org.toop.tictactoe.LocalTicTacToe;
|
||||
import org.toop.game.GameBase;
|
||||
|
||||
@@ -26,6 +31,8 @@ public class UIGameBoard {
|
||||
private LocalTicTacToe localTicTacToe;
|
||||
|
||||
private boolean gameOver = false;
|
||||
Locale locale = AppContext.getLocale();
|
||||
ResourceBundle resourceBundle = ResourceBundle.getBundle("Localization", locale);
|
||||
|
||||
public UIGameBoard(LocalTicTacToe lttt, Object parent) {
|
||||
if (!(parent == null)) {
|
||||
@@ -43,7 +50,7 @@ public class UIGameBoard {
|
||||
tttPanel = new JPanel(new BorderLayout());
|
||||
|
||||
// Back button
|
||||
backToMainMenuButton = new JButton("Back to Main Menu");
|
||||
backToMainMenuButton = new JButton(resourceBundle.getString("buttonBackToMainMenu"));
|
||||
tttPanel.add(backToMainMenuButton, BorderLayout.SOUTH);
|
||||
backToMainMenuButton.addActionListener(
|
||||
_ -> {
|
||||
@@ -65,7 +72,11 @@ public class UIGameBoard {
|
||||
// cells[moveIndex].setText(String.valueOf(symbol));
|
||||
// });
|
||||
// });
|
||||
|
||||
new EventFlow().listen(WindowEvents.LanguageChanged.class, this::changeLanguage);
|
||||
}
|
||||
private void changeLanguage(WindowEvents.LanguageChanged event) {
|
||||
locale = AppContext.getLocale();
|
||||
resourceBundle = ResourceBundle.getBundle("Localization", locale);
|
||||
}
|
||||
|
||||
private JPanel createGridPanel(int sizeX, int sizeY) {
|
||||
|
||||
Reference in New Issue
Block a user