mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-02-23 15:38:29 +01:00
Add preference "use localization", to allow disabling partial translations
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user