Commit 2c1971c7 authored by Matyáš Latner's avatar Matyáš Latner

#1 Preferences menu for manual language change

parent c5e08b00
language_system=Systémový jazyk
language_czech=Čeština
language_slovak=Slovenština
mainmenu_games=Hry
mainmenu_halloffame=Síň slávy
mainmenu_statistics=Statistiky
mainmenu_encyclopedia=Encyklopedie
mainmenu_preferences=Nastavení
mainmenu_about=O aplikaci
mainmenu_logout=Odhlásit
......
language_system=Systémový jazyk
language_czech=Čeština
language_slovak=Slovenčina
mainmenu_games=Hry
mainmenu_halloffame=Sieň slávy
mainmenu_statistics=Štatistiky
mainmenu_encyclopedia=Encyklopédia
mainmenu_preferences=Nastavenie
mainmenu_about=O aplikácií
mainmenu_logout=Odhlásiť
......
......@@ -5,6 +5,7 @@ import com.badlogic.gdx.Preferences;
import java.util.Locale;
import cz.nic.tablexia.loader.ApplicationTextManager;
import cz.nic.tablexia.util.Log;
public class TablexiaSettings {
......@@ -46,18 +47,20 @@ public class TablexiaSettings {
public enum LocaleDefinition {
SYSTEM (null, "system"),
cs_CZ (new Locale("cs", "CZ"), "cs_CZ"),
sk_SK (new Locale("sk", "SK"), "sk_SK");
SYSTEM (null, "system", ApplicationTextManager.LANGUAGE_SYSTEM),
cs_CZ (new Locale("cs", "CZ"), "cs_CZ", ApplicationTextManager.LANGUAGE_CZECH),
sk_SK (new Locale("sk", "SK"), "sk_SK", ApplicationTextManager.LANGUAGE_SLOVAK);
private final static LocaleDefinition FALLBACK_VARIANT = LocaleDefinition.SYSTEM;
private final Locale locale;
private final String localeKey;
private final String descriptionKey;
private LocaleDefinition(Locale locale, String localeKey) {
private LocaleDefinition(Locale locale, String localeKey, String descriptionKey) {
this.locale = locale;
this.localeKey = localeKey;
this.descriptionKey = descriptionKey;
}
public String getLocaleKey() {
......@@ -68,6 +71,15 @@ public class TablexiaSettings {
return locale != null ? locale : instance.systemLocale;
}
@Override
public String toString() {
if (ApplicationTextManager.getInstance().update()) {
return ApplicationTextManager.getInstance().getResult().get(descriptionKey);
} else {
return name();
}
}
public static LocaleDefinition getLocaleDefinitionForKey(String key) {
for(LocaleDefinition localeDefinition: LocaleDefinition.values()) {
if (localeDefinition.localeKey.equals(key)) {
......@@ -157,6 +169,10 @@ public class TablexiaSettings {
preferences.flush();
}
public LocaleDefinition getLocaleDefinition() {
return selectedLocale;
}
public Locale getLocale() {
return selectedLocale.getLocale();
}
......
......@@ -18,14 +18,18 @@ import cz.nic.tablexia.util.Log;
*/
public class ApplicationTextManager extends AbstractDataManager<I18NBundle> implements IApplicationLoader {
private static final String ROBBERY_TEXT = "application/text/application";
private static final String APPLICATION_TEXT_RESOURCE_FILE = "application/text/application";
private static class RobberyTextLoader implements AsyncTask<I18NBundle> {
public static final String LANGUAGE_SYSTEM = "language_system";
public static final String LANGUAGE_CZECH = "language_czech";
public static final String LANGUAGE_SLOVAK = "language_slovak";
private static class ApplicationTextLoader implements AsyncTask<I18NBundle> {
private String textResourceFileName;
private Locale locale;
public RobberyTextLoader(String textResourceFileName, Locale locale) {
public ApplicationTextLoader(String textResourceFileName, Locale locale) {
this.textResourceFileName = textResourceFileName;
this.locale = locale;
}
......@@ -50,7 +54,7 @@ public class ApplicationTextManager extends AbstractDataManager<I18NBundle> impl
public void load(Locale locale) {
Log.info(getClass(), "Loading application texts with locale: " + locale);
setAsyncTask(new RobberyTextLoader(ROBBERY_TEXT, locale));
setAsyncTask(new ApplicationTextLoader(APPLICATION_TEXT_RESOURCE_FILE, locale));
}
@Override
......
......@@ -12,6 +12,7 @@ public enum MainMenuDefinition implements ApplicationEvent, IMenuItem {
HALL_OF_FAME ("mainmenu_halloffame", null, true),
STATISTICS ("mainmenu_statistics", null, true),
ENCYCLOPEDIA ("mainmenu_encyclopedia", null, true),
PREFERENCES ("mainmenu_preferences", null, true),
ABOUT_APPLICATION ("mainmenu_about", null, true),
LOGOUT ("mainmenu_logout", null, true);
......
......@@ -9,6 +9,7 @@ import cz.nic.tablexia.screen.about.AboutScreen;
import cz.nic.tablexia.screen.encyclopedia.EncyclopediaScreen;
import cz.nic.tablexia.screen.gamemenu.GameMenuScreen;
import cz.nic.tablexia.screen.halloffame.HallOfFameScreen;
import cz.nic.tablexia.screen.preferences.PreferencesScreen;
import cz.nic.tablexia.screen.statistics.StatisticsScreen;
public enum ScreenDefinition {
......@@ -17,6 +18,7 @@ public enum ScreenDefinition {
HALL_OF_FAME (HallOfFameScreen.class, MainMenuDefinition.HALL_OF_FAME),
STATISTICS (StatisticsScreen.class, MainMenuDefinition.STATISTICS),
ENCYCLOPEDIA (EncyclopediaScreen.class, MainMenuDefinition.ENCYCLOPEDIA),
PREFERENCES (PreferencesScreen.class, MainMenuDefinition.PREFERENCES),
ABOUT_APPLICATION (AboutScreen.class, MainMenuDefinition.ABOUT_APPLICATION);
private Class<? extends AbstractTablexiaScreen<?>> screenClass;
......
package cz.nic.tablexia.screen.preferences;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.List;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.graphics.ColorTexture;
import cz.nic.tablexia.loader.ApplicationFontManager;
import cz.nic.tablexia.loader.CommonAssets;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
public class PreferencesScreen extends AbstractTablexiaScreen<Void> {
private static final String BACKGROUND_TEXTURE = CommonAssets.WOODEN_BACKGOURND;
public static final String TEXT_RESOURCES_FILE = "application/text/preferences";
public static final String LANGUAGE_LABEL_KEY = "language_label";
private Container<Table> preferencesContainer;
@Override
protected void prepareScreenTextureAssetNames(java.util.List<String> texturesFileNames) {
texturesFileNames.add(BACKGROUND_TEXTURE);
}
@Override
protected String prepareScreenTextResourcesAssetName() {
return TEXT_RESOURCES_FILE;
}
@Override
protected void screenLoaded() {
BitmapFont font = ApplicationFontManager.getInstance().get(ApplicationFontManager.FONT_ROBOTO_REGULAR, BitmapFont.class);
Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE);
preferencesContainer = new Container<Table>();
preferencesContainer.setBackground(new TextureRegionDrawable(new TextureRegion(getTexture(BACKGROUND_TEXTURE))));
getStage().addActor(preferencesContainer);
Table preferencesLayout = new Table();
preferencesContainer.setActor(preferencesLayout);
preferencesContainer.left().top();
preferencesContainer.pad(getStage().getWidth() / 10);
// Languages Label
Label languagesLabel = new Label(getText(LANGUAGE_LABEL_KEY), labelStyle);
preferencesLayout.add(languagesLabel);
// Languages SelectBox
ScrollPane.ScrollPaneStyle scrollPaneStyle = new ScrollPane.ScrollPaneStyle();
scrollPaneStyle.background = new TextureRegionDrawable(new TextureRegion(new ColorTexture(50, 50, Color.GRAY)));
List.ListStyle listStyle = new List.ListStyle();
listStyle.selection = new TextureRegionDrawable(new TextureRegion(new ColorTexture(50, 50, Color.GRAY)));
listStyle.font = font;
SelectBox.SelectBoxStyle selectBoxStyle = new SelectBox.SelectBoxStyle();
selectBoxStyle.font = font;
selectBoxStyle.scrollStyle = scrollPaneStyle;
selectBoxStyle.listStyle = listStyle;
selectBoxStyle.background = new TextureRegionDrawable(new TextureRegion(new ColorTexture(50, 50, Color.GRAY)));
SelectBox<TablexiaSettings.LocaleDefinition> languagesSelectBox = new SelectBox<TablexiaSettings.LocaleDefinition>(selectBoxStyle);
languagesSelectBox.setItems(TablexiaSettings.LocaleDefinition.values());
languagesSelectBox.setSelected(TablexiaSettings.getInstance().getLocaleDefinition());
languagesSelectBox.addCaptureListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
TablexiaSettings.getInstance().setLocale(((SelectBox<TablexiaSettings.LocaleDefinition>) event.getTarget()).getSelected());
}
});
preferencesLayout.add(languagesSelectBox).expandX().left();
}
@Override
public void screenResized(int width, int height) {
preferencesContainer.setBounds(0, 0, getStage().getWidth(), getStage().getHeight());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment