Add preference "use localization", to allow disabling partial translations

This commit is contained in:
Oskar Wiksten
2013-09-08 16:56:03 +02:00
parent 787fcc0a65
commit d13cd4c02a
5 changed files with 47 additions and 6 deletions

View File

@@ -605,4 +605,11 @@ Every skill level increases the attack chance of weapons with %1$d %% of their o
<string name="heroinfo_gamestats_fav_monsters">Most commonly killed monsters</string>
<string name="heroinfo_gamestats_name_and_qty">%1$s (%2$d)</string>
<!-- =========================================== -->
<!-- Added in v0.7.1 -->
<string name="preferences_ui_use_localized_resources_title">Use localized resources</string>
<string name="preferences_ui_use_localized_resources">Use translation of interface and content, where available. (requires restart)</string>
<string name="change_locale_requires_restart">Changing locale requires restart. Andor\'s Trail has been closed.</string>
</resources>

View File

@@ -98,5 +98,10 @@
android:defaultValue="false"
android:summary="@string/preferences_ui_show_quickslots_when_toolbox_is_visible"
android:key="showQuickslotsWhenToolboxIsVisible" />
<CheckBoxPreference
android:title="@string/preferences_ui_use_localized_resources_title"
android:defaultValue="true"
android:summary="@string/preferences_ui_use_localized_resources"
android:key="useLocalizedResources" />
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -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;
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}