diff --git a/AndorsTrail/res/values/strings.xml b/AndorsTrail/res/values/strings.xml index c0a4c828a..d72d14c34 100644 --- a/AndorsTrail/res/values/strings.xml +++ b/AndorsTrail/res/values/strings.xml @@ -605,4 +605,11 @@ Every skill level increases the attack chance of weapons with %1$d %% of their o Most commonly killed monsters %1$s (%2$d) + + + + Use localized resources + Use translation of interface and content, where available. (requires restart) + Changing locale requires restart. Andor\'s Trail has been closed. + diff --git a/AndorsTrail/res/xml/preferences.xml b/AndorsTrail/res/xml/preferences.xml index 42e9301ed..9b9ec599c 100644 --- a/AndorsTrail/res/xml/preferences.xml +++ b/AndorsTrail/res/xml/preferences.xml @@ -98,5 +98,10 @@ android:defaultValue="false" android:summary="@string/preferences_ui_show_quickslots_when_toolbox_is_visible" android:key="showQuickslotsWhenToolboxIsVisible" /> + diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java index 7f0b12ccb..5d16edb2d 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java @@ -3,11 +3,15 @@ package com.gpl.rpg.AndorsTrail; import android.app.Activity; import android.app.Application; import android.content.Context; +import android.content.res.Configuration; +import android.content.res.Resources; import android.view.Window; import android.view.WindowManager; import com.gpl.rpg.AndorsTrail.context.ControllerContext; import com.gpl.rpg.AndorsTrail.context.WorldContext; +import java.util.Locale; + public final class AndorsTrailApplication extends Application { public static final boolean DEVELOPMENT_DEBUGRESOURCES = false; @@ -49,5 +53,18 @@ public final class AndorsTrailApplication extends Application { } else { activity.getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN); } + setLocale(activity); + } + + public boolean setLocale(Activity context) { + Resources res = context.getResources(); + Configuration conf = res.getConfiguration(); + final Locale targetLocale = preferences.useLocalizedResources ? Locale.getDefault() : Locale.US; + if (targetLocale.equals(conf.locale)) return false; + + conf.locale = targetLocale; + res.updateConfiguration(conf, res.getDisplayMetrics()); + this.getResources().updateConfiguration(conf, res.getDisplayMetrics()); + return true; } } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailPreferences.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailPreferences.java index f4f607183..a47f54805 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailPreferences.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailPreferences.java @@ -51,6 +51,7 @@ public final class AndorsTrailPreferences { public int displayOverwriteSavegame = CONFIRM_OVERWRITE_SAVEGAME_ALWAYS; public int quickslotsPosition = QUICKSLOTS_POSITION_HORIZONTAL_CENTER_BOTTOM; public boolean showQuickslotsWhenToolboxIsVisible = false; + public boolean useLocalizedResources = true; public void read(final Context androidContext) { AndorsTrailPreferences dest = this; @@ -70,6 +71,7 @@ public final class AndorsTrailPreferences { dest.displayOverwriteSavegame = Integer.parseInt(prefs.getString("display_overwrite_savegame", Integer.toString(CONFIRM_OVERWRITE_SAVEGAME_ALWAYS))); dest.quickslotsPosition = Integer.parseInt(prefs.getString("quickslots_placement", Integer.toString(QUICKSLOTS_POSITION_HORIZONTAL_CENTER_BOTTOM))); dest.showQuickslotsWhenToolboxIsVisible = prefs.getBoolean("showQuickslotsWhenToolboxIsVisible", false); + dest.useLocalizedResources = prefs.getBoolean("useLocalizedResources", true); // This might be implemented as a skill in the future. //dest.movementAggressiveness = Integer.parseInt(prefs.getString("movementaggressiveness", Integer.toString(MOVEMENTAGGRESSIVENESS_NORMAL))); @@ -89,6 +91,7 @@ public final class AndorsTrailPreferences { dest.displayOverwriteSavegame = CONFIRM_OVERWRITE_SAVEGAME_ALWAYS; dest.quickslotsPosition = QUICKSLOTS_POSITION_HORIZONTAL_CENTER_BOTTOM; dest.showQuickslotsWhenToolboxIsVisible = false; + dest.useLocalizedResources = true; } } } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/StartScreenActivity.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/StartScreenActivity.java index 549e3c242..077e810b9 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/StartScreenActivity.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/StartScreenActivity.java @@ -37,6 +37,10 @@ public final class StartScreenActivity extends Activity { super.onCreate(savedInstanceState); final AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this); + final Resources res = getResources(); + TileManager tileManager = app.getWorld().tileManager; + tileManager.setDensity(res); + updatePreferences(false); app.setWindowParameters(this); setContentView(R.layout.startscreen); @@ -102,10 +106,6 @@ public final class StartScreenActivity extends Activity { development_version.setVisibility(View.VISIBLE); } - final Resources res = getResources(); - TileManager tileManager = app.getWorld().tileManager; - tileManager.setDensity(res); - updatePreferences(); app.getWorldSetup().startResourceLoader(res); if (AndorsTrailApplication.DEVELOPMENT_FORCE_STARTNEWGAME) { @@ -119,10 +119,19 @@ public final class StartScreenActivity extends Activity { } } - private void updatePreferences() { + private void updatePreferences(boolean alreadyStartedLoadingResources) { AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this); AndorsTrailPreferences preferences = app.getPreferences(); preferences.read(this); + if (app.setLocale(this)) { + if (alreadyStartedLoadingResources) { + // Changing the locale after having loaded the game requires resources to + // be re-loaded. Therefore, we just exit here. + Toast.makeText(this, R.string.change_locale_requires_restart, Toast.LENGTH_LONG).show(); + this.finish(); + return; + } + } app.getWorld().tileManager.updatePreferences(preferences); } @@ -166,7 +175,7 @@ public final class StartScreenActivity extends Activity { continueGame(false, slot, null); break; case INTENTREQUEST_PREFERENCES: - updatePreferences(); + updatePreferences(true); break; } }