mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-01-24 20:31:07 +01:00
Improved error/success messages & fixed some bugs in 'Add as New'
This commit is contained in:
@@ -116,6 +116,9 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
|
||||
importSaves.setOnClickListener(this);
|
||||
importWorldmap.setOnClickListener(this);
|
||||
exportImportContainer.setVisibility(View.VISIBLE);
|
||||
|
||||
boolean hasSavegames = !Savegames.getUsedSavegameSlots(this).isEmpty();
|
||||
exportSaves.setEnabled(hasSavegames);
|
||||
}
|
||||
else{
|
||||
exportImportContainer.setVisibility(View.GONE);
|
||||
@@ -174,8 +177,14 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelLoadSaveActivity(int slot){
|
||||
completeLoadSaveActivity(slot, false);
|
||||
}
|
||||
|
||||
private void completeLoadSaveActivity(int slot) {
|
||||
completeLoadSaveActivity(slot, true);
|
||||
}
|
||||
private void completeLoadSaveActivity(int slot, boolean success) {
|
||||
Intent i = new Intent();
|
||||
if (slot == SLOT_NUMBER_CREATE_NEW_SLOT) {
|
||||
slot = getFirstFreeSlot();
|
||||
@@ -183,11 +192,23 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
|
||||
|| slot == SLOT_NUMBER_IMPORT_SAVEGAMES
|
||||
|| slot == SLOT_NUMBER_IMPORT_WORLDMAP) {
|
||||
i.putExtra("import_export", true);
|
||||
|
||||
if(slot == SLOT_NUMBER_IMPORT_WORLDMAP){
|
||||
i.putExtra("import_worldmap", true);
|
||||
}
|
||||
if(slot == SLOT_NUMBER_IMPORT_SAVEGAMES){
|
||||
i.putExtra("import_savegames", true);
|
||||
}
|
||||
if(slot == SLOT_NUMBER_EXPORT_SAVEGAMES){
|
||||
i.putExtra("export", true);
|
||||
}
|
||||
|
||||
} else if (slot < SLOT_NUMBER_FIRST_SLOT)
|
||||
slot = SLOT_NUMBER_FIRST_SLOT;
|
||||
|
||||
i.putExtra("slot", slot);
|
||||
setResult(Activity.RESULT_OK, i);
|
||||
if(success) setResult(Activity.RESULT_OK, i);
|
||||
else setResult(Activity.RESULT_CANCELED, i);
|
||||
LoadSaveActivity.this.finish();
|
||||
}
|
||||
|
||||
@@ -409,18 +430,22 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
|
||||
}
|
||||
|
||||
private void importSaveGames(ContentResolver resolver, DocumentFile appSavegameFolder, List<DocumentFile> saveFiles) {
|
||||
importSaveGames(resolver, appSavegameFolder, saveFiles, false);
|
||||
}
|
||||
private void importSaveGames(ContentResolver resolver, DocumentFile appSavegameFolder, List<DocumentFile> saveFiles, boolean addAsNew) {
|
||||
boolean saveAsNew = false;
|
||||
for (DocumentFile file : saveFiles) {
|
||||
int slot;
|
||||
if(addAsNew)
|
||||
if(file == null){
|
||||
saveAsNew = true;
|
||||
continue;
|
||||
}
|
||||
if (saveAsNew)
|
||||
slot = getFirstFreeSlot();
|
||||
else
|
||||
slot = getSlotFromSavegameFileName(file.getName());
|
||||
|
||||
importSaveGameFile(resolver, appSavegameFolder, file, slot);
|
||||
}
|
||||
|
||||
completeLoadSaveActivity(SLOT_NUMBER_IMPORT_SAVEGAMES);
|
||||
}
|
||||
|
||||
|
||||
@@ -599,14 +624,7 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
|
||||
|
||||
CustomDialogFactory.addDismissButton(d, android.R.string.no);
|
||||
CustomDialogFactory.setDismissListener(d, dialog -> {
|
||||
boolean addAsNew = false;
|
||||
if(newFiles.size() > 0 && newFiles.get(0) == null) {
|
||||
newFiles.remove(0);
|
||||
addAsNew = true;
|
||||
}
|
||||
|
||||
importSaveGames(resolver, appSavegameFolder, newFiles, addAsNew);
|
||||
completeLoadSaveActivity(SLOT_NUMBER_IMPORT_SAVEGAMES);
|
||||
importSaveGames(resolver, appSavegameFolder, newFiles);
|
||||
});
|
||||
CustomDialogFactory.show(d);
|
||||
}
|
||||
@@ -654,14 +672,14 @@ public final class LoadSaveActivity extends AndorsTrailBaseActivity implements O
|
||||
private void showErrorImportingWorldmapWrongDirectory() {
|
||||
final CustomDialog d = CustomDialogFactory.createErrorDialog(this,
|
||||
getString(R.string.loadsave_import_worldmap_unsuccessfull),
|
||||
getString(R.string.loadsave_import_worldmap_unsuccessfull_wrong_directory));
|
||||
getString(R.string.loadsave_import_worldmap_wrong_directory));
|
||||
CustomDialogFactory.show(d);
|
||||
}
|
||||
|
||||
private void showErrorImportingSaveGameUnknown() {
|
||||
final CustomDialog d = CustomDialogFactory.createErrorDialog(this,
|
||||
getString(R.string.loadsave_import_save_unsuccessfull),
|
||||
getString(R.string.loadsave_import_save_unsuccessfull_unknown));
|
||||
getString(R.string.loadsave_import_save_error_unknown));
|
||||
CustomDialogFactory.show(d);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,11 +65,11 @@ public class StartScreenActivity_MainMenu extends Fragment {
|
||||
}
|
||||
|
||||
View root = inflater.inflate(R.layout.startscreen_mainmenu, container, false);
|
||||
|
||||
|
||||
save_preview_holder = (ViewGroup) root.findViewById(R.id.save_preview_holder);
|
||||
save_preview_hero_icon = (ImageView) root.findViewById(R.id.save_preview_hero_icon);
|
||||
save_preview_hero_desc = (TextView) root.findViewById(R.id.save_preview_hero_desc);
|
||||
|
||||
|
||||
|
||||
startscreen_continue = (Button) root.findViewById(R.id.startscreen_continue);
|
||||
startscreen_continue.setOnClickListener(new OnClickListener() {
|
||||
@@ -135,7 +135,7 @@ public class StartScreenActivity_MainMenu extends Fragment {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
if (AndorsTrailApplication.DEVELOPMENT_FORCE_STARTNEWGAME) {
|
||||
if (AndorsTrailApplication.DEVELOPMENT_DEBUGRESOURCES) {
|
||||
@@ -153,14 +153,14 @@ public class StartScreenActivity_MainMenu extends Fragment {
|
||||
checkAndRequestPermissions(getActivity());
|
||||
migrateDataOnDemand(getActivity());
|
||||
}
|
||||
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
|
||||
String playerName;
|
||||
String displayInfo = null;
|
||||
int iconID = TileManager.CHAR_HERO;
|
||||
@@ -249,13 +249,13 @@ public class StartScreenActivity_MainMenu extends Fragment {
|
||||
super.onAttach(activity);
|
||||
listener = (OnNewGameRequestedListener) activity;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
listener = null;
|
||||
}
|
||||
|
||||
|
||||
private void setButtonState(final String playerName, final String displayInfo, int iconID, boolean isDead) {
|
||||
startscreen_continue.setEnabled(hasExistingGame && !isDead);
|
||||
startscreen_newgame.setEnabled(true);
|
||||
@@ -296,8 +296,8 @@ public class StartScreenActivity_MainMenu extends Fragment {
|
||||
//
|
||||
//
|
||||
final CustomDialog d = CustomDialogFactory.createDialog(getActivity(),
|
||||
getString(R.string.startscreen_newgame),
|
||||
getResources().getDrawable(android.R.drawable.ic_delete),
|
||||
getString(R.string.startscreen_newgame),
|
||||
getResources().getDrawable(android.R.drawable.ic_delete),
|
||||
getResources().getString(R.string.startscreen_newgame_confirm),
|
||||
null,
|
||||
true);
|
||||
@@ -308,9 +308,9 @@ public class StartScreenActivity_MainMenu extends Fragment {
|
||||
}
|
||||
});
|
||||
CustomDialogFactory.addDismissButton(d, android.R.string.cancel);
|
||||
|
||||
|
||||
CustomDialogFactory.show(d);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static final String versionCheck = "lastversion";
|
||||
@@ -327,16 +327,23 @@ public class StartScreenActivity_MainMenu extends Fragment {
|
||||
e.putInt(versionCheck, AndorsTrailApplication.CURRENT_VERSION);
|
||||
e.commit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
switch (requestCode) {
|
||||
case INTENTREQUEST_LOADGAME:
|
||||
if (resultCode != Activity.RESULT_OK) break;
|
||||
boolean unsuccessful = resultCode != Activity.RESULT_OK;
|
||||
if(data == null) break;
|
||||
|
||||
final boolean wasImportOrExport = data.getBooleanExtra("import_export", false);
|
||||
if (wasImportOrExport) break;
|
||||
if (wasImportOrExport) {
|
||||
String message = getImportExportMessage(!unsuccessful, data);
|
||||
Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
|
||||
break;
|
||||
}
|
||||
if (unsuccessful) break;
|
||||
final int slot = data.getIntExtra("slot", 1);
|
||||
continueGame(false, slot, null);
|
||||
break;
|
||||
@@ -346,7 +353,24 @@ public class StartScreenActivity_MainMenu extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePreferences(boolean alreadyStartedLoadingResources) {
|
||||
private String getImportExportMessage(boolean successful, Intent data) {
|
||||
String message = "";
|
||||
boolean isImportWorldmap = data.getBooleanExtra("import_worldmap", false);
|
||||
boolean isImportSaves = data.getBooleanExtra("import_savegames", false);
|
||||
boolean isExport = data.getBooleanExtra("export", false);
|
||||
|
||||
if(isImportWorldmap) {
|
||||
message = getString(successful ? R.string.loadsave_import_worldmap_successfull : R.string.loadsave_import_worldmap_unsuccessfull);
|
||||
} else if(isImportSaves) {
|
||||
message = getString(successful ? R.string.loadsave_import_save_successfull : R.string.loadsave_import_save_unsuccessfull);
|
||||
} else if(isExport) {
|
||||
message = getString(successful ? R.string.loadsave_export_successfull : R.string.loadsave_export_unsuccessfull);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
private void updatePreferences(boolean alreadyStartedLoadingResources) {
|
||||
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(getActivity());
|
||||
AndorsTrailPreferences preferences = app.getPreferences();
|
||||
preferences.read(getActivity());
|
||||
@@ -375,18 +399,18 @@ public class StartScreenActivity_MainMenu extends Fragment {
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface OnNewGameRequestedListener {
|
||||
public void onNewGameRequested();
|
||||
}
|
||||
|
||||
|
||||
private OnNewGameRequestedListener listener = null;
|
||||
|
||||
|
||||
private void createNewGame() {
|
||||
if (listener != null) {
|
||||
listener.onNewGameRequested();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
android:id="@+id/loadsave_export_save"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/loadsave_export_save"
|
||||
android:text="@string/loadsave_export"
|
||||
/>
|
||||
<Button
|
||||
android:id="@+id/loadsave_import_save"
|
||||
|
||||
@@ -489,8 +489,9 @@
|
||||
<string name="loadsave_save_overwrite_confirmation_title">Overwrite savegame?</string>
|
||||
<string name="loadsave_save_overwrite_confirmation">This savegame contains a different player name (%1$s) than your current player name (%2$s). Are you sure you want to overwrite this savegame?</string>
|
||||
|
||||
<string name="loadsave_export_save">Export savegames</string>
|
||||
<string name="loadsave_export_save_successfull">Export successful</string>
|
||||
<string name="loadsave_export">Export savegames</string>
|
||||
<string name="loadsave_export_successfull">Export successful</string>
|
||||
<string name="loadsave_export_unsuccessfull">Export unsuccessful</string>
|
||||
<string name="loadsave_export_overwrite_confirmation_title">Overwrite Existing Files?</string>
|
||||
<string name="loadsave_export_overwrite_confirmation">The target Folder contains existing files with the same name of some Files that should be exported. Are you sure you want to overwrite those files?</string>
|
||||
<string name="loadsave_import_overwrite_confirmation_title">Overwrite Existing Files?</string>
|
||||
@@ -501,11 +502,11 @@
|
||||
<string name="loadsave_import_save">Import savegames</string>
|
||||
<string name="loadsave_import_save_successfull">Import successful</string>
|
||||
<string name="loadsave_import_save_unsuccessfull">Import unsuccessful</string>
|
||||
<string name="loadsave_import_save_unsuccessfull_unknown">An unknown error occurred.</string>
|
||||
<string name="loadsave_import_save_error_unknown">An unknown error occurred.</string>
|
||||
<string name="loadsave_import_worldmap">Import worldmap</string>
|
||||
<string name="loadsave_import_worldmap_successfull">Import of Worldmap successful</string>
|
||||
<string name="loadsave_import_worldmap_unsuccessfull">Import of Worldmap unsuccessful</string>
|
||||
<string name="loadsave_import_worldmap_unsuccessfull_wrong_directory">Are you sure there is a worldmap in this folder? Please select the folder called worldmap inside your export location.</string>
|
||||
<string name="loadsave_import_worldmap_wrong_directory">Are you sure there is a worldmap in this folder? Please select the folder called worldmap inside your export location.</string>
|
||||
|
||||
<string name="iteminfo_displaytypes_ordinary">Ordinary</string>
|
||||
<string name="iteminfo_displaytypes_quest">Quest item</string>
|
||||
|
||||
Reference in New Issue
Block a user