diff --git a/android/assets/application/text/application.properties b/android/assets/application/text/application.properties index c65c60307a85f73b500ff35c059ab965e147bd3d..d3016242104c612d05aa580d69357ecb1572e4fb 100644 --- a/android/assets/application/text/application.properties +++ b/android/assets/application/text/application.properties @@ -1,7 +1,12 @@ +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 diff --git a/android/assets/application/text/application_sk_SK.properties b/android/assets/application/text/application_sk_SK.properties index 8c89dbd16385067a6d4ac26c1a92103d8a238eb3..ecb2169abcc2e2371b1cf0fbe6c8900acd14bf95 100644 --- a/android/assets/application/text/application_sk_SK.properties +++ b/android/assets/application/text/application_sk_SK.properties @@ -1,7 +1,12 @@ +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ĹĄ diff --git a/android/assets/application/text/language_sk_SK.properties b/android/assets/application/text/language_sk_SK.properties new file mode 100644 index 0000000000000000000000000000000000000000..762cf76c925a09e817cf0ccc7297b66b0912caa3 --- /dev/null +++ b/android/assets/application/text/language_sk_SK.properties @@ -0,0 +1 @@ +language_label=Jazyk: diff --git a/android/assets/application/text/preferences.properties b/android/assets/application/text/preferences.properties new file mode 100644 index 0000000000000000000000000000000000000000..762cf76c925a09e817cf0ccc7297b66b0912caa3 --- /dev/null +++ b/android/assets/application/text/preferences.properties @@ -0,0 +1 @@ +language_label=Jazyk: diff --git a/core/src/cz/nic/tablexia/TablexiaSettings.java b/core/src/cz/nic/tablexia/TablexiaSettings.java index 2b492a467afa378f17b0ec0b5e26bd077c868e43..c72b372c07837a693343d8d561a2ccbb2cc10681 100644 --- a/core/src/cz/nic/tablexia/TablexiaSettings.java +++ b/core/src/cz/nic/tablexia/TablexiaSettings.java @@ -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(); } diff --git a/core/src/cz/nic/tablexia/loader/ApplicationTextManager.java b/core/src/cz/nic/tablexia/loader/ApplicationTextManager.java index 2664ca5342df26badd024395e52db6e8ef130b65..9c7d45da0c03e1009ff6770949949dc92122554b 100644 --- a/core/src/cz/nic/tablexia/loader/ApplicationTextManager.java +++ b/core/src/cz/nic/tablexia/loader/ApplicationTextManager.java @@ -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 diff --git a/core/src/cz/nic/tablexia/menu/MainMenuDefinition.java b/core/src/cz/nic/tablexia/menu/MainMenuDefinition.java index c5695088a22ad38299c2080dcd6da7f8c1ed4557..7573f42eb370f843d6e9297824538c00aa60beb6 100644 --- a/core/src/cz/nic/tablexia/menu/MainMenuDefinition.java +++ b/core/src/cz/nic/tablexia/menu/MainMenuDefinition.java @@ -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); diff --git a/core/src/cz/nic/tablexia/screen/ScreenDefinition.java b/core/src/cz/nic/tablexia/screen/ScreenDefinition.java index 3b8fd6aadc82fbf96952827b92a1dbb05340fecc..aedb419736ec0613322a59910585e26e838adf20 100644 --- a/core/src/cz/nic/tablexia/screen/ScreenDefinition.java +++ b/core/src/cz/nic/tablexia/screen/ScreenDefinition.java @@ -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; diff --git a/core/src/cz/nic/tablexia/screen/preferences/PreferencesScreen.java b/core/src/cz/nic/tablexia/screen/preferences/PreferencesScreen.java new file mode 100644 index 0000000000000000000000000000000000000000..07247deb2a4b0fc55d530c1b86bc5c11aa830ae7 --- /dev/null +++ b/core/src/cz/nic/tablexia/screen/preferences/PreferencesScreen.java @@ -0,0 +1,86 @@ +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()); + } +}