Provide setting to disable confirmation dialog box when overwriting a savegame slot.

This commit is contained in:
Oskar Wiksten
2012-10-21 18:26:43 +02:00
parent 536ffb3791
commit 32be42531b
5 changed files with 54 additions and 10 deletions

View File

@@ -339,7 +339,7 @@
<!-- Added in v0.6.10 -->
<string name="preferences_movement_dpad_position_title">Virtual d-pad</string>
<string name="preferences_movement_dpad_position">Enables a virtual on-screen directional pad to guide movement</string>
<string name="preferences_movement_dpad_position">Enables a virtual on-screen directional pad to guide movement.</string>
<string name="preferences_movement_dpad_minimizeable_title">Minimizable d-pad</string>
<string name="preferences_movement_dpad_minimizeable">If the virtual d-pad is enabled, this setting allows the d-pad to be minimized by pressing its center.</string>
@@ -542,5 +542,18 @@
<string name="iteminfo_effect_decrease_reequip_cost">Lowers AP cost of equipping items in combat by %1$d AP</string>
<string name="loadsave_save_overwrite_confirmation_all">Are you sure you want to overwrite this savegame?</string>
<string-array name="preferences_display_overwrite_savegame_entries">
<item>Always show confirmation dialog box</item>
<item>Only show when overwriting a different playername</item>
<item>Never display confirmation dialog box</item>
</string-array>
<string-array name="preferences_display_overwrite_savegame_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<string name="preferences_dialog_overwrite_savegame_title">Confirm overwriting savegames</string>
<string name="preferences_dialog_overwrite_savegame">Gives a question about whether you want to overwrite when saving to a savegame slot that already contains a savegame.</string>
</resources>

View File

@@ -39,6 +39,13 @@
android:defaultValue="0"
android:entries="@array/preferences_display_loot"
android:entryValues="@array/preferences_display_loot_values" />
<ListPreference
android:title="@string/preferences_dialog_overwrite_savegame_title"
android:summary="@string/preferences_dialog_overwrite_savegame"
android:key="display_overwrite_savegame"
android:defaultValue="0"
android:entries="@array/preferences_display_overwrite_savegame_entries"
android:entryValues="@array/preferences_display_overwrite_savegame_values" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/preferences_combat_category">

View File

@@ -16,7 +16,7 @@ public final class AndorsTrailApplication extends Application {
public static final boolean DEVELOPMENT_DEBUGRESOURCES = false;
public static final boolean DEVELOPMENT_FORCE_STARTNEWGAME = false;
public static final boolean DEVELOPMENT_FORCE_CONTINUEGAME = false;
public static final boolean DEVELOPMENT_DEBUGBUTTONS = true;
public static final boolean DEVELOPMENT_DEBUGBUTTONS = false;
public static final boolean DEVELOPMENT_VALIDATEDATA = false;
public static final boolean DEVELOPMENT_DEBUGMESSAGES = false;
public static final boolean DEVELOPMENT_INCOMPATIBLE_SAVEGAMES = DEVELOPMENT_DEBUGRESOURCES;

View File

@@ -22,6 +22,9 @@ public class AndorsTrailPreferences {
public static final int DPAD_POSITION_UPPER_LEFT = 6;
public static final int DPAD_POSITION_UPPER_RIGHT = 7;
public static final int DPAD_POSITION_UPPER_CENTER = 8;
public static final int CONFIRM_OVERWRITE_SAVEGAME_ALWAYS = 0;
public static final int CONFIRM_OVERWRITE_SAVEGAME_WHEN_PLAYERNAME_DIFFERS = 1;
public static final int CONFIRM_OVERWRITE_SAVEGAME_NEVER = 2;
public boolean confirmRest = true;
public boolean confirmAttack = true;
@@ -35,6 +38,7 @@ public class AndorsTrailPreferences {
public boolean dpadMinimizeable = true;
public boolean optimizedDrawing = false;
public boolean enableUiAnimations = true;
public int displayOverwriteSavegame = CONFIRM_OVERWRITE_SAVEGAME_ALWAYS;
public static void read(final Context androidContext, AndorsTrailPreferences dest) {
try {
@@ -50,6 +54,7 @@ public class AndorsTrailPreferences {
dest.dpadMinimizeable = prefs.getBoolean("dpadMinimizeable", true);
dest.optimizedDrawing = prefs.getBoolean("optimized_drawing", false);
dest.enableUiAnimations = prefs.getBoolean("enableUiAnimations", true);
dest.displayOverwriteSavegame = Integer.parseInt(prefs.getString("display_overwrite_savegame", Integer.toString(CONFIRM_OVERWRITE_SAVEGAME_ALWAYS)));
// This might be implemented as a skill in the future.
//dest.movementAggressiveness = Integer.parseInt(prefs.getString("movementaggressiveness", Integer.toString(MOVEMENTAGGRESSIVENESS_NORMAL)));
@@ -66,6 +71,7 @@ public class AndorsTrailPreferences {
dest.dpadMinimizeable = true;
dest.optimizedDrawing = false;
dest.enableUiAnimations = true;
dest.displayOverwriteSavegame = CONFIRM_OVERWRITE_SAVEGAME_ALWAYS;
}
}

View File

@@ -16,6 +16,7 @@ import android.widget.Button;
import android.widget.TextView;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.Savegames;
import com.gpl.rpg.AndorsTrail.Savegames.FileHeader;
@@ -26,7 +27,7 @@ public final class LoadSaveActivity extends Activity implements OnClickListener
private static final int SLOT_NUMBER_CREATE_NEW_SLOT = -1;
private static final int SLOT_NUMBER_FIRST_SLOT = 1;
private ModelContainer model;
private AndorsTrailPreferences preferences;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -35,6 +36,7 @@ public final class LoadSaveActivity extends Activity implements OnClickListener
final AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
AndorsTrailApplication.setWindowParameters(this, app.preferences);
this.model = app.world.model;
this.preferences = app.preferences;
String loadsave = getIntent().getData().getLastPathSegment().toString();
isLoading = (loadsave.equalsIgnoreCase("load"));
@@ -97,20 +99,36 @@ public final class LoadSaveActivity extends Activity implements OnClickListener
LoadSaveActivity.this.finish();
}
private boolean requiresConfirmation(int slot) {
if (isLoading) return false;
if (slot == SLOT_NUMBER_CREATE_NEW_SLOT) return false; // if we're creating a new slot
return true;
private String getConfirmOverwriteQuestion(int slot) {
if (isLoading) return null;
if (slot == SLOT_NUMBER_CREATE_NEW_SLOT) return null; // if we're creating a new slot
if (preferences.displayOverwriteSavegame == AndorsTrailPreferences.CONFIRM_OVERWRITE_SAVEGAME_ALWAYS) {
return getString(R.string.loadsave_save_overwrite_confirmation_all);
} else if (preferences.displayOverwriteSavegame == AndorsTrailPreferences.CONFIRM_OVERWRITE_SAVEGAME_NEVER) {
return null;
}
final String currentPlayerName = model.player.actorTraits.name;
final FileHeader header = Savegames.quickload(this, slot);
if (header == null) return null;
final String savedPlayerName = header.playerName;
if (currentPlayerName.equals(savedPlayerName)) return null; // if the names match
return getString(R.string.loadsave_save_overwrite_confirmation, savedPlayerName, currentPlayerName);
}
@Override
public void onClick(View view) {
final int slot = (Integer) view.getTag();
if (requiresConfirmation(slot)) {
final String message = getConfirmOverwriteQuestion(slot);
if (message != null) {
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(R.string.loadsave_save_overwrite_confirmation_title)
.setMessage(getString(R.string.loadsave_save_overwrite_confirmation_all))
.setMessage(message)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {