mirror of
https://github.com/AndorsTrailRelease/andors-trail.git
synced 2025-12-28 07:17:47 +01:00
Compare commits
1 Commits
master
...
production
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff161a0609 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +0,0 @@
|
||||
/AndorsTrail/.idea/workspace.xml
|
||||
14
.travis.yml
14
.travis.yml
@@ -1,14 +0,0 @@
|
||||
dist: bionic
|
||||
sudo: required
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/pbuilder-bases
|
||||
matrix:
|
||||
include:
|
||||
- env: TARGET_OS=stretch
|
||||
before_install:
|
||||
- "$TRAVIS_BUILD_DIR/travis/$TRAVIS_OS_NAME.$TARGET_OS.before_install"
|
||||
install:
|
||||
- "$TRAVIS_BUILD_DIR/travis/$TRAVIS_OS_NAME.$TARGET_OS.install"
|
||||
script:
|
||||
- "$TRAVIS_BUILD_DIR/travis/$TRAVIS_OS_NAME.$TARGET_OS.script"
|
||||
9
AndorsTrail/.classpath
Normal file
9
AndorsTrail/.classpath
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
||||
41
AndorsTrail/.gitignore
vendored
41
AndorsTrail/.gitignore
vendored
@@ -1,13 +1,8 @@
|
||||
# Android ignores
|
||||
gen/
|
||||
bin/
|
||||
target/
|
||||
local.properties
|
||||
app/build/intermediates/
|
||||
build/
|
||||
debug/
|
||||
beta/
|
||||
release/
|
||||
.gradle/
|
||||
|
||||
#IntelliJ
|
||||
.idea/
|
||||
@@ -19,37 +14,3 @@ out/test/
|
||||
# Other
|
||||
.metadata
|
||||
.svn/
|
||||
|
||||
|
||||
#copied from https://github.com/github/gitignore/blob/main/Gradle.gitignore
|
||||
.gradle
|
||||
**/build/
|
||||
!src/**/build/
|
||||
|
||||
# Ignore Gradle GUI config
|
||||
gradle-app.setting
|
||||
|
||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||
!gradle-wrapper.jar
|
||||
|
||||
# Avoid ignore Gradle wrappper properties
|
||||
!gradle-wrapper.properties
|
||||
|
||||
# Cache of project
|
||||
.gradletasknamecache
|
||||
|
||||
# Eclipse Gradle plugin generated files
|
||||
# Eclipse Core
|
||||
.project
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
#copied from https://github.com/github/gitignore/blob/main/Gradle.gitignore
|
||||
|
||||
|
||||
/AndorsTrail/.gradle
|
||||
/AndorsTrail/gradle/wrapper
|
||||
/AndorsTrail/app/build/
|
||||
/AndorsTrail/app/debug/
|
||||
/AndorsTrail/app/beta/
|
||||
/AndorsTrail/app/release/
|
||||
/AndorsTrail/app/beta/
|
||||
|
||||
33
AndorsTrail/.project
Normal file
33
AndorsTrail/.project
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>AndorsTrail</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
36
AndorsTrail/AndorsTrail.iml
Normal file
36
AndorsTrail/AndorsTrail.iml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="EclipseModuleManager" forced_jdk="true">
|
||||
<conelement value="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK" />
|
||||
<conelement value="com.android.ide.eclipse.adt.LIBRARIES" />
|
||||
<src_description expected_position="1">
|
||||
<src_folder value="file://$MODULE_DIR$/src" expected_position="0" />
|
||||
<src_folder value="file://$MODULE_DIR$/gen" expected_position="1" />
|
||||
</src_description>
|
||||
</component>
|
||||
<component name="FacetManager">
|
||||
<facet type="android" name="Android">
|
||||
<configuration />
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/bin/classes" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/libs/android-support-v4.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
||||
|
||||
68
AndorsTrail/AndroidManifest.xml
Normal file
68
AndorsTrail/AndroidManifest.xml
Normal file
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.gpl.rpg.AndorsTrail"
|
||||
android:versionCode="46"
|
||||
android:versionName="0.7.5"
|
||||
android:installLocation="auto"
|
||||
>
|
||||
<uses-sdk
|
||||
android:minSdkVersion="4"
|
||||
android:targetSdkVersion="28"
|
||||
/>
|
||||
|
||||
<supports-screens
|
||||
android:smallScreens="true"
|
||||
android:normalScreens="true"
|
||||
android:largeScreens="true"
|
||||
android:xlargeScreens="true"
|
||||
android:anyDensity="true"
|
||||
/>
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
|
||||
<uses-permission android:name="android.permission.READ_LOGS"/>
|
||||
|
||||
|
||||
<application
|
||||
android:name=".AndorsTrailApplication"
|
||||
android:label="@string/app_name"
|
||||
android:icon="@drawable/icon"
|
||||
android:description="@string/app_description"
|
||||
android:allowBackup="true"
|
||||
android:theme="@style/AndorsTrailTheme_Blue"
|
||||
>
|
||||
<activity
|
||||
android:name=".activity.StartScreenActivity"
|
||||
android:clearTaskOnLaunch="true"
|
||||
>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AndorsTrailTheme_Blue.NoBackground"
|
||||
/>
|
||||
<activity android:name=".activity.HeroinfoActivity" />
|
||||
<activity android:name=".activity.MonsterInfoActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name=".activity.ItemInfoActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name=".activity.LevelUpActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name=".activity.MonsterEncounterActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name=".activity.ConversationActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name=".activity.ShopActivity" />
|
||||
<activity android:name=".activity.AboutActivity" />
|
||||
<activity android:name=".activity.LoadingActivity" />
|
||||
<activity android:name=".activity.Preferences" />
|
||||
<activity android:name=".activity.LoadSaveActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name=".activity.ActorConditionInfoActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name=".activity.BulkSelectionInterface" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name=".activity.SkillInfoActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name=".activity.DisplayWorldMapActivity" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -1,91 +0,0 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
|
||||
compileSdkVersion 35
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.gpl.rpg.AndorsTrail"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 35
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
manifestPlaceholders icon_name: 'icon', fileproviderPath: 'AndorsTrail'
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||
}
|
||||
debug {
|
||||
manifestPlaceholders icon_name: 'icon_beta', fileproviderPath: 'AndorsTrail.beta2'
|
||||
applicationIdSuffix 'beta2'
|
||||
versionNameSuffix = "dev"
|
||||
signingConfig signingConfigs.debug
|
||||
}
|
||||
beta {
|
||||
manifestPlaceholders icon_name: 'icon_beta', fileproviderPath: 'AndorsTrail.beta2'
|
||||
applicationIdSuffix 'beta2'
|
||||
versionNameSuffix = "beta"
|
||||
signingConfig signingConfigs.debug
|
||||
}
|
||||
}
|
||||
namespace 'com.gpl.rpg.AndorsTrail'
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
res.srcDirs = ['build/gen-res', 'src/main/res']
|
||||
assets.srcDirs = ['build/gen-assets', 'src/main/assets']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
}
|
||||
|
||||
task copyRes(type: Copy) {
|
||||
description "Copies the res folder to the modules res folder (& renames .tmx to .xml)"
|
||||
from "${rootDir}/res"
|
||||
into "${projectDir}/build/gen-res"
|
||||
rename "(.*)\\.tmx", "\$1.xml"
|
||||
}
|
||||
|
||||
task copyResValuesIn(type: Copy) {
|
||||
description "Exception Indonesian language code (Old IN was renamed to now ID)"
|
||||
from "${rootDir}/res/values-id/"
|
||||
into "${projectDir}/build/gen-res/values-in/"
|
||||
}
|
||||
|
||||
task copyTranslation(type: Copy) {
|
||||
description("Copies the translation files to the modules translations folder")
|
||||
from "${rootDir}/assets/translation"
|
||||
into "${projectDir}/build/gen-assets/translation"
|
||||
}
|
||||
|
||||
task cleanup(type: Delete) {
|
||||
description("Deletes the assets/translation and the res folder from the modules folder")
|
||||
delete "${projectDir}/build/gen-res", "${projectDir}/build/gen-assets/translation"
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
project.tasks.copyRes.dependsOn project.tasks.copyResValuesIn
|
||||
|
||||
mapReleaseSourceSetPaths.dependsOn project.tasks.copyRes
|
||||
generateReleaseResources.dependsOn project.tasks.copyRes
|
||||
|
||||
generateDebugResources.dependsOn project.tasks.copyRes
|
||||
mapDebugSourceSetPaths.dependsOn project.tasks.copyRes
|
||||
mergeDebugResources.dependsOn project.tasks.copyRes
|
||||
extractDeepLinksDebug.dependsOn project.tasks.copyRes
|
||||
mergeReleaseResources.dependsOn project.tasks.copyRes
|
||||
extractDeepLinksRelease.dependsOn project.tasks.copyRes
|
||||
|
||||
generateDebugResources.dependsOn project.tasks.copyTranslation
|
||||
mapDebugSourceSetPaths.dependsOn project.tasks.copyTranslation
|
||||
mergeDebugAssets.dependsOn project.tasks.copyTranslation
|
||||
mergeReleaseAssets.dependsOn project.tasks.copyTranslation
|
||||
extractDeepLinksDebug.dependsOn project.tasks.copyTranslation
|
||||
extractDeepLinksRelease.dependsOn project.tasks.copyTranslation
|
||||
|
||||
clean.dependsOn project.tasks.cleanup
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.gpl.rpg.AndorsTrail"
|
||||
android:versionCode="82"
|
||||
android:versionName="0.8.15"
|
||||
android:installLocation="auto"
|
||||
>
|
||||
|
||||
<supports-screens
|
||||
android:smallScreens="true"
|
||||
android:normalScreens="true"
|
||||
android:largeScreens="true"
|
||||
android:xlargeScreens="true"
|
||||
android:anyDensity="true"
|
||||
/>
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
|
||||
|
||||
<application
|
||||
android:name="com.gpl.rpg.AndorsTrail.AndorsTrailApplication"
|
||||
android:label="@string/app_name"
|
||||
android:icon="@drawable/${icon_name}"
|
||||
android:description="@string/app_description"
|
||||
android:allowBackup="true"
|
||||
android:theme="@style/AndorsTrailTheme_Blue"
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:hasFragileUserData="true"
|
||||
android:preserveLegacyExternalStorage="true"
|
||||
>
|
||||
<activity
|
||||
android:exported="true"
|
||||
android:name="com.gpl.rpg.AndorsTrail.activity.StartScreenActivity"
|
||||
android:clearTaskOnLaunch="true"
|
||||
>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.gpl.rpg.AndorsTrail.activity.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AndorsTrailTheme_Blue.NoBackground"
|
||||
/>
|
||||
<activity android:name="com.gpl.rpg.AndorsTrail.activity.HeroinfoActivity" />
|
||||
<activity android:name="com.gpl.rpg.AndorsTrail.activity.MonsterInfoActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name="com.gpl.rpg.AndorsTrail.activity.ItemInfoActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name="com.gpl.rpg.AndorsTrail.activity.LevelUpActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name="com.gpl.rpg.AndorsTrail.activity.MonsterEncounterActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name="com.gpl.rpg.AndorsTrail.activity.ConversationActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name="com.gpl.rpg.AndorsTrail.activity.ShopActivity" />
|
||||
<activity android:name="com.gpl.rpg.AndorsTrail.activity.AboutActivity" />
|
||||
<activity android:name="com.gpl.rpg.AndorsTrail.activity.LoadingActivity" />
|
||||
<activity android:name="com.gpl.rpg.AndorsTrail.activity.Preferences" />
|
||||
<activity android:name="com.gpl.rpg.AndorsTrail.activity.LoadSaveActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name="com.gpl.rpg.AndorsTrail.activity.ActorConditionInfoActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name="com.gpl.rpg.AndorsTrail.activity.BulkSelectionInterface" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name="com.gpl.rpg.AndorsTrail.activity.SkillInfoActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
|
||||
<activity android:name="com.gpl.rpg.AndorsTrail.activity.DisplayWorldMapActivity" />
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
android:grantUriPermissions="true"
|
||||
android:exported="false">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/fileprovider" />
|
||||
</provider>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.gpl.rpg.AndorsTrail.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.IdRes;
|
||||
import androidx.annotation.LayoutRes;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
|
||||
|
||||
public abstract class AndorsTrailBaseActivity extends Activity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
|
||||
app.setLocale(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
|
||||
app.setLocale(this);
|
||||
}
|
||||
protected void initializeView(Activity activity, @LayoutRes int layoutId, @IdRes int rootViewId) {
|
||||
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(activity);
|
||||
app.setWindowParameters(activity);
|
||||
activity.setContentView(layoutId);
|
||||
View root = activity.findViewById(rootViewId);
|
||||
app.setUsablePadding(root);
|
||||
app.setFullscreenMode(activity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.gpl.rpg.AndorsTrail.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.IdRes;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
|
||||
|
||||
public abstract class AndorsTrailBaseFragmentActivity extends FragmentActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
|
||||
app.setLocale(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
|
||||
app.setLocale(this);
|
||||
}
|
||||
|
||||
protected void initializeView(Activity activity, @LayoutRes int layoutId, @IdRes int rootViewId) {
|
||||
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(activity);
|
||||
app.setWindowParameters(activity);
|
||||
activity.setContentView(layoutId);
|
||||
View root = activity.findViewById(rootViewId);
|
||||
app.setUsablePadding(root);
|
||||
app.setFullscreenMode(activity);
|
||||
}
|
||||
}
|
||||
@@ -1,515 +0,0 @@
|
||||
package com.gpl.rpg.AndorsTrail.activity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
|
||||
import com.gpl.rpg.AndorsTrail.R;
|
||||
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
|
||||
import com.gpl.rpg.AndorsTrail.context.WorldContext;
|
||||
import com.gpl.rpg.AndorsTrail.controller.Constants;
|
||||
import com.gpl.rpg.AndorsTrail.model.item.ItemType;
|
||||
import com.gpl.rpg.AndorsTrail.model.map.MapObject;
|
||||
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
|
||||
import com.gpl.rpg.AndorsTrail.view.MainView;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
public final class DebugInterface {
|
||||
private final ControllerContext controllerContext;
|
||||
private final MainActivity mainActivity;
|
||||
private final Resources res;
|
||||
private final WorldContext world;
|
||||
|
||||
private DebugButton[] buttons;
|
||||
private List<DebugButton> tpButtons = new ArrayList<DebugButton>();
|
||||
private List<DebugButton> tpButtons2 = new ArrayList<DebugButton>();
|
||||
private List<DebugButton> tpButtons3 = new ArrayList<DebugButton>();
|
||||
|
||||
public DebugInterface(ControllerContext controllers, WorldContext world, MainActivity mainActivity) {
|
||||
this.controllerContext = controllers;
|
||||
this.world = world;
|
||||
this.res = mainActivity.getResources();
|
||||
this.mainActivity = mainActivity;
|
||||
}
|
||||
|
||||
public void addDebugButtons() {
|
||||
if (!AndorsTrailApplication.DEVELOPMENT_DEBUGBUTTONS) return;
|
||||
|
||||
List<DebugButton> buttonList = new ArrayList<DebugButton>();
|
||||
buttonList.addAll(Arrays.asList(new DebugButton[] {
|
||||
new DebugButton("dbg", new OnClickListener() {
|
||||
boolean hidden = false;
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
hidden = !hidden;
|
||||
for (int i = 1; i < buttons.length; i++) {
|
||||
buttons[i].b.setVisibility(hidden ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
for (DebugButton b : tpButtons) {
|
||||
b.b.setVisibility(View.GONE);
|
||||
}
|
||||
for (DebugButton b : tpButtons2) {
|
||||
b.b.setVisibility(View.GONE);
|
||||
}
|
||||
for (DebugButton b : tpButtons3) {
|
||||
b.b.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
})
|
||||
,new DebugButton("teleport", new OnClickListener() {
|
||||
public void onClick(View arg0) {
|
||||
for (int i = 0; i < buttons.length; i++) {
|
||||
buttons[i].b.setVisibility(View.GONE);
|
||||
}
|
||||
for (DebugButton tpButton : tpButtons) {
|
||||
tpButton.b.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
})
|
||||
,new DebugButton("dmg", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
world.model.player.damagePotential.set(500, 500);
|
||||
world.model.player.attackChance = 500;
|
||||
world.model.player.attackCost = 1;
|
||||
showToast(mainActivity, "DEBUG: damagePotential=500, chance=500%, cost=1", Toast.LENGTH_SHORT);
|
||||
}
|
||||
})
|
||||
/*,new DebugButton("dmg=1", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
world.model.player.damagePotential.set(1, 1);
|
||||
showToast(mainActivity, "DEBUG: damagePotential=1", Toast.LENGTH_SHORT);
|
||||
}
|
||||
})*/
|
||||
,new DebugButton("itm", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
for (ItemType item : world.itemTypes.UNITTEST_getAllItemTypes().values()) {
|
||||
world.model.player.inventory.addItem(item, 10);
|
||||
}
|
||||
world.model.player.inventory.gold += 50000;
|
||||
showToast(mainActivity, "DEBUG: added items", Toast.LENGTH_SHORT);
|
||||
}
|
||||
})
|
||||
,new DebugButton("xp", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.actorStatsController.addExperience(10000);
|
||||
showToast(mainActivity, "DEBUG: given 10000 exp", Toast.LENGTH_SHORT);
|
||||
}
|
||||
})
|
||||
,new DebugButton("rst", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
for(PredefinedMap map : world.maps.getAllMaps()) {
|
||||
map.resetTemporaryData();
|
||||
}
|
||||
showToast(mainActivity, "DEBUG: maps respawned", Toast.LENGTH_SHORT);
|
||||
}
|
||||
})
|
||||
,new DebugButton("hp", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
world.model.player.baseTraits.maxHP = 500;
|
||||
world.model.player.health.max = world.model.player.baseTraits.maxHP;
|
||||
controllerContext.actorStatsController.setActorMaxHealth(world.model.player);
|
||||
world.model.player.conditions.clear();
|
||||
showToast(mainActivity, "DEBUG: hp set to max", Toast.LENGTH_SHORT);
|
||||
}
|
||||
})
|
||||
,new DebugButton("skl", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
world.model.player.availableSkillIncreases += 10;
|
||||
showToast(mainActivity, "DEBUG: 10 skill points", Toast.LENGTH_SHORT);
|
||||
}
|
||||
})
|
||||
,new DebugButton("spd", new OnClickListener() {
|
||||
boolean fast = Constants.MINIMUM_INPUT_INTERVAL == Constants.MINIMUM_INPUT_INTERVAL_FAST;
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
fast = !fast;
|
||||
if (fast) {
|
||||
Constants.MINIMUM_INPUT_INTERVAL = Constants.MINIMUM_INPUT_INTERVAL_FAST;
|
||||
} else {
|
||||
Constants.MINIMUM_INPUT_INTERVAL = Constants.MINIMUM_INPUT_INTERVAL_STD;
|
||||
}
|
||||
MainView.SCROLL_DURATION = Constants.MINIMUM_INPUT_INTERVAL;
|
||||
AndorsTrailApplication.getApplicationFromActivity(mainActivity).getControllerContext().movementController.resetMovementHandler();
|
||||
}
|
||||
})
|
||||
,new DebugButton("map", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
showToast(mainActivity, "DEBUG: map=" + world.model.currentMaps.map.name , Toast.LENGTH_SHORT);
|
||||
}
|
||||
})
|
||||
,new DebugButton("tim", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
world.model.worldData.tickWorldTime(10);
|
||||
}
|
||||
})
|
||||
}));
|
||||
|
||||
tpButtons.addAll(Arrays.asList(new DebugButton[] {
|
||||
new DebugButton("teleport", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
for (DebugButton tpButton : tpButtons2) {
|
||||
tpButton.b.setVisibility(View.VISIBLE);
|
||||
}
|
||||
for (DebugButton tpButton : tpButtons) {
|
||||
tpButton.b.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
})
|
||||
,new DebugButton("cg", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "crossglen", "hall", 0, 0);
|
||||
}
|
||||
})
|
||||
,new DebugButton("vg", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "vilegard_s", "tavern", 0, 0);
|
||||
}
|
||||
})
|
||||
,new DebugButton("cr", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "crossroads", "middle", 0, 0);
|
||||
}
|
||||
})
|
||||
,new DebugButton("lf", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "loneford9", "south", 0, 0);
|
||||
}
|
||||
})
|
||||
,new DebugButton("fh", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "fallhaven_ne", "clothes", 0, 0);
|
||||
}
|
||||
})
|
||||
,new DebugButton("prm", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "blackwater_mountain29", "south", 0, 0);
|
||||
}
|
||||
})
|
||||
,new DebugButton("bwm", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "blackwater_mountain43", "south", 0, 0);
|
||||
}
|
||||
})
|
||||
,new DebugButton("rmg", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "remgard0", "east", 0, 0);
|
||||
}
|
||||
})
|
||||
,new DebugButton("chr", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "waytolostmine2", "minerhouse4", 0, 0);
|
||||
}
|
||||
})
|
||||
,new DebugButton("ldr", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "lodarhouse0", "lodarhouse", 0, 0);
|
||||
}
|
||||
})
|
||||
,new DebugButton("sf", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "wild20", "south2", 0, 0);
|
||||
}
|
||||
})
|
||||
,new DebugButton("gm", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "guynmart_wood_1", "farmhouse", 0, 0);
|
||||
}
|
||||
})
|
||||
}));
|
||||
buttonList.addAll(tpButtons);
|
||||
|
||||
tpButtons2.addAll(Arrays.asList(new DebugButton[] {
|
||||
new DebugButton("teleport", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
for (DebugButton tpButton : tpButtons3) {
|
||||
tpButton.b.setVisibility(View.VISIBLE);
|
||||
}
|
||||
for (DebugButton tpButton : tpButtons2) {
|
||||
tpButton.b.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
})
|
||||
,new DebugButton("brv", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "brimhaven4", "south2", 0, 0);
|
||||
}
|
||||
})
|
||||
,new DebugButton("aru", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "mountainlake5", "north", 0, 0);
|
||||
}
|
||||
})
|
||||
,new DebugButton("ws", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "woodsettlement0", "east", 0, 0);
|
||||
}
|
||||
})
|
||||
,new DebugButton("sul", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "sullengard2", "south", 0, 0);
|
||||
}
|
||||
})
|
||||
,new DebugButton("gal", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "galmore_19", "south", 0, 0);
|
||||
}
|
||||
})
|
||||
|
||||
,new DebugButton("apl", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "sullengard_apple_farm_east", "house", 0, 0);
|
||||
}
|
||||
})
|
||||
|
||||
,new DebugButton("wch", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "lake_shore_road_0", "west", 0, 0);
|
||||
}
|
||||
})
|
||||
|
||||
,new DebugButton("la1", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "laerothisland2", "south2", 0, 0);
|
||||
}
|
||||
})
|
||||
|
||||
,new DebugButton("la2", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "island3", "cave", 0, 0);
|
||||
}
|
||||
})
|
||||
|
||||
,new DebugButton("wx", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "wexlow_village", "north", 0, 0);
|
||||
}
|
||||
})
|
||||
|
||||
,new DebugButton("fey", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "guynmart_wood_17", "north", 0, 0);
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
}));
|
||||
buttonList.addAll(tpButtons2);
|
||||
|
||||
tpButtons3.addAll(Arrays.asList(new DebugButton[] {
|
||||
new DebugButton("teleport", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
for (int i = 0; i < buttons.length; i++) {
|
||||
buttons[i].b.setVisibility(View.VISIBLE);
|
||||
}
|
||||
for (DebugButton tpButton : tpButtons) {
|
||||
tpButton.b.setVisibility(View.GONE);
|
||||
}
|
||||
for (DebugButton tpButton : tpButtons2) {
|
||||
tpButton.b.setVisibility(View.GONE);
|
||||
}
|
||||
for (DebugButton tpButton : tpButtons3) {
|
||||
tpButton.b.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
})
|
||||
,new DebugButton("#1", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "lake_shore_road_9", "north", 5, 0);
|
||||
}
|
||||
})
|
||||
|
||||
,new DebugButton("#2", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "undertell_3_lava_01", "west", 0, 0);
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
,new DebugButton("#3", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "galmore_cavea", "up", 0, 0);
|
||||
}
|
||||
})
|
||||
|
||||
,new DebugButton("#4", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "galmore_35", "south", 11, 0);
|
||||
}
|
||||
})
|
||||
|
||||
,new DebugButton("#5", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "way_to_sullengard_west_5", "east", 0, 5);
|
||||
}
|
||||
})
|
||||
|
||||
,new DebugButton("#6", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "galmore_32", "south", 19, 0);
|
||||
}
|
||||
})
|
||||
|
||||
,new DebugButton("#7", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "cabin_norcity_road1", "north", 5, 0);
|
||||
}
|
||||
})
|
||||
|
||||
,new DebugButton("#8", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "wayto_feygard_duleian_2", "south", 0, 5);
|
||||
}
|
||||
})
|
||||
|
||||
,new DebugButton("#9", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "galmore_58", "north", 0, 0);
|
||||
}
|
||||
})
|
||||
|
||||
,new DebugButton("#10", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "moesforest_03", "north1", 0, 0);
|
||||
}
|
||||
})
|
||||
|
||||
,new DebugButton("#11", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "galmore_17", "outside", 0, 0);
|
||||
}
|
||||
})
|
||||
|
||||
,new DebugButton("#12", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "galmore_48", "west", 0, 10);
|
||||
}
|
||||
})
|
||||
|
||||
,new DebugButton("#13", new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "feygard_outside1", "south", 6, 0);
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
}));
|
||||
buttonList.addAll(tpButtons3);
|
||||
|
||||
buttons = buttonList.toArray(new DebugButton[buttonList.size()]);
|
||||
addDebugButtons(buttons);
|
||||
|
||||
for (DebugButton b : tpButtons) {
|
||||
b.b.setVisibility(View.GONE);
|
||||
}
|
||||
for (DebugButton b : tpButtons2) {
|
||||
b.b.setVisibility(View.GONE);
|
||||
}
|
||||
for (DebugButton b : tpButtons3) {
|
||||
b.b.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void showToast(Context context, String msg, int duration) {
|
||||
Toast.makeText(context, msg, duration).show();
|
||||
}
|
||||
|
||||
private static class DebugButton {
|
||||
public final String text;
|
||||
public final OnClickListener listener;
|
||||
public Button b = null;
|
||||
public DebugButton(String text, OnClickListener listener) {
|
||||
this.text = text;
|
||||
this.listener = listener;
|
||||
}
|
||||
public void makeButton(Context c, int id) {
|
||||
b = new Button(c);
|
||||
b.setText(text);
|
||||
b.setTextSize(10);//res.getDimension(R.dimen.actionbar_text));
|
||||
b.setId(id);
|
||||
b.setOnClickListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
private void addDebugButton(DebugButton button, int id, RelativeLayout layout) {
|
||||
if (!AndorsTrailApplication.DEVELOPMENT_DEBUGBUTTONS) return;
|
||||
|
||||
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, res.getDimensionPixelSize(R.dimen.smalltext_buttonheight));
|
||||
if (id == 1)
|
||||
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
|
||||
else
|
||||
lp.addRule(RelativeLayout.RIGHT_OF, id - 1);
|
||||
lp.addRule(RelativeLayout.ABOVE, R.id.main_statusview);
|
||||
button.makeButton(mainActivity, id);
|
||||
button.b.setLayoutParams(lp);
|
||||
layout.addView(button.b);
|
||||
}
|
||||
|
||||
private void addDebugButtons(DebugButton[] buttons) {
|
||||
if (!AndorsTrailApplication.DEVELOPMENT_DEBUGBUTTONS) return;
|
||||
|
||||
if (buttons == null || buttons.length <= 0) return;
|
||||
RelativeLayout layout = (RelativeLayout) mainActivity.findViewById(R.id.main_container);
|
||||
|
||||
int id = 1;
|
||||
for (DebugButton b : buttons) {
|
||||
addDebugButton(b, id, layout);
|
||||
++id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,876 +0,0 @@
|
||||
package com.gpl.rpg.AndorsTrail.activity;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.ClipData;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.documentfile.provider.DocumentFile;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
|
||||
import com.gpl.rpg.AndorsTrail.AndorsTrailPreferences;
|
||||
import com.gpl.rpg.AndorsTrail.R;
|
||||
import com.gpl.rpg.AndorsTrail.controller.Constants;
|
||||
import com.gpl.rpg.AndorsTrail.model.ModelContainer;
|
||||
import com.gpl.rpg.AndorsTrail.resource.tiles.TileManager;
|
||||
import com.gpl.rpg.AndorsTrail.savegames.Savegames;
|
||||
import com.gpl.rpg.AndorsTrail.savegames.Savegames.FileHeader;
|
||||
import com.gpl.rpg.AndorsTrail.util.AndroidStorage;
|
||||
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
|
||||
import com.gpl.rpg.AndorsTrail.view.CustomDialogFactory;
|
||||
import com.gpl.rpg.AndorsTrail.view.CustomDialogFactory.CustomDialog;
|
||||
|
||||
public final class LoadSaveActivity extends AndorsTrailBaseActivity implements OnClickListener {
|
||||
private boolean isLoading = true;
|
||||
//region special slot numbers
|
||||
private static final int SLOT_NUMBER_CREATE_NEW_SLOT = -1;
|
||||
public static final int SLOT_NUMBER_EXPORT_SAVEGAMES = -2;
|
||||
public static final int SLOT_NUMBER_IMPORT_SAVEGAMES = -3;
|
||||
public static final int SLOT_NUMBER_IMPORT_WORLDMAP = -4;
|
||||
private static final int SLOT_NUMBER_FIRST_SLOT = 1;
|
||||
//endregion
|
||||
private ModelContainer model;
|
||||
private TileManager tileManager;
|
||||
private AndorsTrailPreferences preferences;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
setTheme(ThemeHelper.getDialogTheme());
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
final AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
|
||||
app.setWindowParameters(this);
|
||||
this.model = app.getWorld().model;
|
||||
this.preferences = app.getPreferences();
|
||||
this.tileManager = app.getWorld().tileManager;
|
||||
|
||||
String loadsave = getIntent().getData().getLastPathSegment();
|
||||
isLoading = (loadsave.equalsIgnoreCase("load"));
|
||||
|
||||
initializeView(this, R.layout.loadsave, R.id.loadsave_root);
|
||||
|
||||
TextView tv = (TextView) findViewById(R.id.loadsave_title);
|
||||
if (isLoading) {
|
||||
tv.setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.ic_menu_search, 0, 0, 0);
|
||||
tv.setText(R.string.loadsave_title_load);
|
||||
} else {
|
||||
tv.setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.ic_menu_save, 0, 0, 0);
|
||||
tv.setText(R.string.loadsave_title_save);
|
||||
}
|
||||
|
||||
ViewGroup slotList = (ViewGroup) findViewById(R.id.loadsave_slot_list);
|
||||
Button slotTemplateButton = (Button) findViewById(R.id.loadsave_slot_n);
|
||||
LayoutParams params = slotTemplateButton.getLayoutParams();
|
||||
slotList.removeView(slotTemplateButton);
|
||||
|
||||
ViewGroup newSlotContainer = (ViewGroup) findViewById(R.id.loadsave_save_to_new_slot_container);
|
||||
Button createNewSlot = (Button) findViewById(R.id.loadsave_save_to_new_slot);
|
||||
|
||||
Button exportSaves = (Button) findViewById(R.id.loadsave_export_save);
|
||||
Button importSaves = (Button) findViewById(R.id.loadsave_import_save);
|
||||
Button importWorldmap = (Button) findViewById(R.id.loadsave_import_worldmap);
|
||||
|
||||
exportSaves.setTag(SLOT_NUMBER_EXPORT_SAVEGAMES);
|
||||
importSaves.setTag(SLOT_NUMBER_IMPORT_SAVEGAMES);
|
||||
importWorldmap.setTag(SLOT_NUMBER_IMPORT_WORLDMAP);
|
||||
|
||||
ViewGroup exportImportContainer = (ViewGroup) findViewById(R.id.loadsave_export_import_save_container);
|
||||
|
||||
|
||||
addSavegameSlotButtons(slotList, params, Savegames.getUsedSavegameSlots(this));
|
||||
|
||||
checkAndRequestPermissions();
|
||||
|
||||
if (!isLoading) {
|
||||
createNewSlot.setTag(SLOT_NUMBER_CREATE_NEW_SLOT);
|
||||
createNewSlot.setOnClickListener(this);
|
||||
newSlotContainer.setVisibility(View.VISIBLE);
|
||||
exportImportContainer.setVisibility(View.GONE);
|
||||
} else {
|
||||
newSlotContainer.setVisibility(View.GONE);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
exportSaves.setOnClickListener(this);
|
||||
importSaves.setOnClickListener(this);
|
||||
importWorldmap.setOnClickListener(this);
|
||||
exportImportContainer.setVisibility(View.VISIBLE);
|
||||
|
||||
boolean hasSavegames = !Savegames.getUsedSavegameSlots(this).isEmpty();
|
||||
exportSaves.setEnabled(hasSavegames);
|
||||
} else {
|
||||
exportImportContainer.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final int READ_EXTERNAL_STORAGE_REQUEST = 1;
|
||||
private static final int WRITE_EXTERNAL_STORAGE_REQUEST = 2;
|
||||
|
||||
private void checkAndRequestPermissions() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||
&& Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
|
||||
if (getApplicationContext().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
this.requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
||||
READ_EXTERNAL_STORAGE_REQUEST);
|
||||
}
|
||||
if (getApplicationContext().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
this.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
|
||||
WRITE_EXTERNAL_STORAGE_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
if (grantResults.length > 0 && grantResults[0] != PackageManager.PERMISSION_GRANTED) {
|
||||
Toast.makeText(this, R.string.storage_permissions_mandatory, Toast.LENGTH_LONG).show();
|
||||
((AndorsTrailApplication) getApplication()).discardWorld();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void addSavegameSlotButtons(ViewGroup parent,
|
||||
LayoutParams params,
|
||||
List<Integer> usedSavegameSlots) {
|
||||
int unused = 1;
|
||||
for (int slot : usedSavegameSlots) {
|
||||
final FileHeader header = Savegames.quickload(this, slot);
|
||||
if (header == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
while (unused < slot) {
|
||||
Button b = new Button(this);
|
||||
b.setLayoutParams(params);
|
||||
b.setTag(unused);
|
||||
b.setOnClickListener(this);
|
||||
b.setText(getString(R.string.loadsave_empty_slot, unused));
|
||||
tileManager.setImageViewTileForPlayer(getResources(), b, header.iconID);
|
||||
parent.addView(b, params);
|
||||
unused++;
|
||||
}
|
||||
unused++;
|
||||
|
||||
Button b = new Button(this);
|
||||
b.setLayoutParams(params);
|
||||
b.setTag(slot);
|
||||
b.setOnClickListener(this);
|
||||
b.setText(slot + ". " + header.describe());
|
||||
tileManager.setImageViewTileForPlayer(getResources(), b, header.iconID);
|
||||
parent.addView(b, params);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
} else if (slot == SLOT_NUMBER_EXPORT_SAVEGAMES
|
||||
|| 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);
|
||||
if (success) {
|
||||
setResult(Activity.RESULT_OK, i);
|
||||
} else {
|
||||
setResult(Activity.RESULT_CANCELED, i);
|
||||
}
|
||||
LoadSaveActivity.this.finish();
|
||||
}
|
||||
|
||||
private int getFirstFreeSlot() {
|
||||
int slot;
|
||||
List<Integer> usedSlots = Savegames.getUsedSavegameSlots(this);
|
||||
if (usedSlots.isEmpty()) {
|
||||
slot = SLOT_NUMBER_FIRST_SLOT;
|
||||
} else {
|
||||
slot = Collections.max(usedSlots) + 1;
|
||||
}
|
||||
return slot;
|
||||
}
|
||||
|
||||
private String getConfirmOverwriteQuestion(int slot) {
|
||||
if (isLoading) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getConfirmOverwriteQuestionIgnoringLoading(slot);
|
||||
}
|
||||
|
||||
private String getConfirmOverwriteQuestionIgnoringLoading(int slot) {
|
||||
if (slot == SLOT_NUMBER_CREATE_NEW_SLOT) {
|
||||
return null;//creating a new savegame
|
||||
}
|
||||
|
||||
if (!Savegames.getSlotFile(slot, this).exists()) {
|
||||
return null;//nothing in slot to overwrite
|
||||
}
|
||||
|
||||
if (preferences.displayOverwriteSavegame
|
||||
== AndorsTrailPreferences.CONFIRM_OVERWRITE_SAVEGAME_ALWAYS) {
|
||||
return getString(R.string.loadsave_save_overwrite_confirmation_all);
|
||||
}
|
||||
if (preferences.displayOverwriteSavegame == AndorsTrailPreferences.CONFIRM_OVERWRITE_SAVEGAME_NEVER) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String currentPlayerName = model.player.getName();
|
||||
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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
switch (slot) {
|
||||
case SLOT_NUMBER_IMPORT_WORLDMAP:
|
||||
clickImportWorldmap();
|
||||
return;
|
||||
case SLOT_NUMBER_IMPORT_SAVEGAMES:
|
||||
clickImportSaveGames();
|
||||
return;
|
||||
case SLOT_NUMBER_EXPORT_SAVEGAMES:
|
||||
clickExportSaveGames();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!isLoading
|
||||
&& slot != SLOT_NUMBER_CREATE_NEW_SLOT
|
||||
&& AndorsTrailApplication.CURRENT_VERSION
|
||||
== AndorsTrailApplication.DEVELOPMENT_INCOMPATIBLE_SAVEGAME_VERSION) {
|
||||
if (!isOverwriteTargetInIncompatibleVersion(slot)) {
|
||||
saveOrOverwriteSavegame(slot);
|
||||
}
|
||||
} else if (isLoading) {
|
||||
loadSaveGame(slot);
|
||||
} else {
|
||||
saveOrOverwriteSavegame(slot);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveOrOverwriteSavegame(int slot) {
|
||||
final String message = getConfirmOverwriteQuestion(slot);
|
||||
if (message != null) {
|
||||
showConfirmOverwriteQuestion(slot, message);
|
||||
} else {
|
||||
completeLoadSaveActivity(slot);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOverwriteTargetInIncompatibleVersion(int slot) {
|
||||
final FileHeader header = Savegames.quickload(this, slot);
|
||||
if (header != null
|
||||
&& header.fileversion != AndorsTrailApplication.DEVELOPMENT_INCOMPATIBLE_SAVEGAME_VERSION) {
|
||||
final CustomDialog d = CustomDialogFactory.createErrorDialog(this,
|
||||
"Overwriting not allowed",
|
||||
"You are currently using a development version of Andor's trail. Overwriting a regular savegame is not allowed in development mode.");
|
||||
CustomDialogFactory.show(d);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//region Imports/Exports
|
||||
|
||||
//region Export
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void exportSaveGames(Intent data) {
|
||||
Uri uri = data.getData();
|
||||
|
||||
Context context = getApplicationContext();
|
||||
ContentResolver resolver = AndorsTrailApplication.getApplicationFromActivity(this)
|
||||
.getContentResolver();
|
||||
|
||||
File storageDir = AndroidStorage.getStorageDirectory(context,
|
||||
Constants.FILENAME_SAVEGAME_DIRECTORY);
|
||||
DocumentFile target = DocumentFile.fromTreeUri(context, uri);
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
File[] files = storageDir.listFiles();
|
||||
if (files == null) {
|
||||
showErrorExportingSaveGamesUnknown();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean hasExistingFiles = false;
|
||||
for (File file : files) {
|
||||
String fileName = file.getName();
|
||||
|
||||
DocumentFile existingFile = target.findFile(fileName);
|
||||
if (existingFile != null) {
|
||||
hasExistingFiles = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasExistingFiles) {
|
||||
showConfirmOverwriteByExportQuestion(resolver, target, files);
|
||||
} else {
|
||||
exportSaveGamesFolderContentToFolder(target, files);
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void exportSaveGamesFolderContentToFolder(DocumentFile target, File[] files) {
|
||||
DocumentFile[] sourceFiles = new DocumentFile[files.length];
|
||||
|
||||
File[] worldmapFiles = null;
|
||||
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
File file = files[i];
|
||||
if (file.isFile()) {
|
||||
sourceFiles[i] = DocumentFile.fromFile(file);
|
||||
} else if (file.isDirectory() && Objects.equals(file.getName(),
|
||||
Constants.FILENAME_WORLDMAP_DIRECTORY)) {
|
||||
worldmapFiles = file.listFiles();
|
||||
}
|
||||
}
|
||||
Context context = this;
|
||||
File[] finalWorldmapFiles = worldmapFiles;
|
||||
CopyFilesToExternalFolder(target, sourceFiles, context, finalWorldmapFiles);
|
||||
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void CopyFilesToExternalFolder(DocumentFile target,
|
||||
DocumentFile[] sourceFiles,
|
||||
Context context,
|
||||
File[] finalWorldmapFiles) {
|
||||
AndroidStorage.copyDocumentFilesToDirAsync(sourceFiles,
|
||||
context,
|
||||
target,
|
||||
getString(R.string.loadsave_exporting_savegames),
|
||||
(success) -> {
|
||||
if (success) {
|
||||
CopyWorldmapFilesAsZip(target,
|
||||
context,
|
||||
finalWorldmapFiles);
|
||||
} else {
|
||||
completeLoadSaveActivity(
|
||||
SLOT_NUMBER_EXPORT_SAVEGAMES,
|
||||
false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void CopyWorldmapFilesAsZip(DocumentFile target,
|
||||
Context context,
|
||||
File[] finalWorldmapFiles) {
|
||||
AndroidStorage.createZipDocumentFileFromFilesAsync(finalWorldmapFiles,
|
||||
context,
|
||||
target,
|
||||
Constants.FILENAME_WORLDMAP_DIRECTORY,
|
||||
getString(R.string.loadsave_exporting_worldmap),
|
||||
(successWorldmap) -> completeLoadSaveActivity(
|
||||
SLOT_NUMBER_EXPORT_SAVEGAMES,
|
||||
successWorldmap));
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void importSaveGames(Intent data) {
|
||||
Uri uri = data.getData();
|
||||
ClipData uris = data.getClipData();
|
||||
|
||||
if (uri == null && uris == null) {
|
||||
//no file was selected
|
||||
return;
|
||||
}
|
||||
|
||||
Context context = getApplicationContext();
|
||||
ContentResolver resolver = AndorsTrailApplication.getApplicationFromActivity(this)
|
||||
.getContentResolver();
|
||||
|
||||
File storageDir = AndroidStorage.getStorageDirectory(context, Constants.FILENAME_SAVEGAME_DIRECTORY);
|
||||
DocumentFile appSavegameFolder = DocumentFile.fromFile(storageDir);
|
||||
|
||||
List<Uri> uriList = new ArrayList<>();
|
||||
if (uri != null) {
|
||||
uriList.add(uri);
|
||||
} else {
|
||||
for (int i = 0; i < uris.getItemCount(); i++) {
|
||||
uriList.add(uris.getItemAt(i).getUri());
|
||||
}
|
||||
}
|
||||
importSaveGamesFromUris(context, resolver, appSavegameFolder, uriList);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void importSaveGamesFromUris(Context context,
|
||||
ContentResolver resolver,
|
||||
DocumentFile appSavegameFolder,
|
||||
List<Uri> uriList) {
|
||||
int count = uriList.size();
|
||||
|
||||
ArrayList<DocumentFile> alreadyExistingFiles = new ArrayList<>();
|
||||
ArrayList<DocumentFile> newFiles = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
Uri item = uriList.get(i);
|
||||
DocumentFile itemFile = DocumentFile.fromSingleUri(context, item);
|
||||
boolean fileAlreadyExists = getExistsSavegameInOwnFiles(itemFile, appSavegameFolder);
|
||||
if (fileAlreadyExists) {
|
||||
alreadyExistingFiles.add(itemFile);
|
||||
} else {
|
||||
newFiles.add(itemFile);
|
||||
}
|
||||
}
|
||||
|
||||
if (alreadyExistingFiles.size() > 0) {
|
||||
showConfirmOverwriteByImportQuestion(resolver, appSavegameFolder, alreadyExistingFiles, newFiles);
|
||||
} else {
|
||||
importSaveGames(resolver, appSavegameFolder, newFiles);
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void importSaveGames(ContentResolver resolver,
|
||||
DocumentFile appSavegameFolder,
|
||||
List<DocumentFile> saveFiles) {
|
||||
int size = saveFiles.size();
|
||||
DocumentFile[] sources = new DocumentFile[size];
|
||||
DocumentFile[] targets = new DocumentFile[size];
|
||||
|
||||
boolean saveAsNew = false;
|
||||
for (int i = 0; i < size; i++) {
|
||||
DocumentFile file = saveFiles.get(i);
|
||||
if (file == null) {//null is value a marker that the next should be saved as new
|
||||
saveAsNew = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
int slot = getSlotFromSavegameFileName(file.getName());
|
||||
if (slot == -1) {
|
||||
//invalid file name
|
||||
continue;
|
||||
}
|
||||
|
||||
if (saveAsNew) {
|
||||
slot = getFirstFreeSlot();
|
||||
saveAsNew = false;
|
||||
}
|
||||
|
||||
String targetName = Savegames.getSlotFileName(slot);
|
||||
sources[i] = file;
|
||||
targets[i] = getOrCreateDocumentFile(appSavegameFolder, targetName);
|
||||
}
|
||||
|
||||
AndroidStorage.copyDocumentFilesFromToAsync(sources,
|
||||
this,
|
||||
targets,
|
||||
getString(R.string.loadsave_importing_savegames),
|
||||
(sucess) -> completeLoadSaveActivity(
|
||||
SLOT_NUMBER_IMPORT_SAVEGAMES,
|
||||
sucess));
|
||||
}
|
||||
|
||||
private boolean getExistsSavegameInOwnFiles(DocumentFile savegameFile, DocumentFile appSavegameFolder) {
|
||||
if (savegameFile == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DocumentFile foundFile = appSavegameFolder.findFile(Objects.requireNonNull(savegameFile.getName()));
|
||||
return foundFile != null && foundFile.exists();
|
||||
}
|
||||
|
||||
private int getSlotFromSavegameFileName(String fileName) {
|
||||
if (fileName == null || !fileName.startsWith(Constants.FILENAME_SAVEGAME_FILENAME_PREFIX)) {
|
||||
return -1;
|
||||
}
|
||||
String slotStr = fileName.substring(Constants.FILENAME_SAVEGAME_FILENAME_PREFIX.length());
|
||||
|
||||
int slot;
|
||||
try {
|
||||
slot = Integer.parseInt(slotStr);
|
||||
return slot;
|
||||
} catch (NumberFormatException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private DocumentFile getOrCreateDocumentFile(DocumentFile folder, String targetName) {
|
||||
DocumentFile targetFile = folder.findFile(targetName);//try finding the file
|
||||
if (targetFile == null)//no file found, creating new one
|
||||
{
|
||||
targetFile = folder.createFile(Constants.NO_FILE_EXTENSION_MIME_TYPE, targetName);
|
||||
}
|
||||
return targetFile;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void importWorldmap(Intent data) {
|
||||
Uri uri = data.getData();
|
||||
|
||||
Context context = AndorsTrailApplication.getApplicationFromActivity(this).getApplicationContext();
|
||||
|
||||
DocumentFile chosenZip = DocumentFile.fromSingleUri(context, uri);
|
||||
if (chosenZip == null || !chosenZip.isFile()) {
|
||||
showErrorImportingWorldmapWrongDirectory();
|
||||
return;
|
||||
}
|
||||
String chosenZipName = chosenZip.getName();
|
||||
if (!chosenZipName.startsWith(Constants.FILENAME_WORLDMAP_DIRECTORY)) {
|
||||
showErrorImportingWorldmapWrongDirectory();
|
||||
return;
|
||||
}
|
||||
|
||||
File ownWorldmapFolder = getOwnWorldmapFolder(context);
|
||||
|
||||
|
||||
AndroidStorage.unzipDocumentFileToDirectoryAsync(chosenZip,
|
||||
this,
|
||||
ownWorldmapFolder,
|
||||
false,
|
||||
getString(R.string.loadsave_importing_worldmap),
|
||||
(success) -> completeLoadSaveActivity(
|
||||
SLOT_NUMBER_IMPORT_WORLDMAP,
|
||||
success));
|
||||
}
|
||||
|
||||
private File getOwnWorldmapFolder(Context context) {
|
||||
File storageDir = AndroidStorage.getStorageDirectory(context, Constants.FILENAME_SAVEGAME_DIRECTORY);
|
||||
File ownWorldmapFolder = null;
|
||||
for (File f : storageDir.listFiles()) {
|
||||
if (f.getName().equals(Constants.FILENAME_WORLDMAP_DIRECTORY)) {
|
||||
ownWorldmapFolder = f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ownWorldmapFolder == null) {
|
||||
ownWorldmapFolder = new File(storageDir, Constants.FILENAME_WORLDMAP_DIRECTORY);
|
||||
ownWorldmapFolder.mkdir();
|
||||
}
|
||||
return ownWorldmapFolder;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void clickExportSaveGames() {
|
||||
showStartExportInfo(view -> startActivityForResult(AndroidStorage.getNewOpenDirectoryIntent(),
|
||||
-SLOT_NUMBER_EXPORT_SAVEGAMES));
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void clickImportSaveGames() {
|
||||
showStartImportSavesInfo(view -> startActivityForResult(AndroidStorage.getNewSelectMultipleSavegameFilesIntent(),
|
||||
-SLOT_NUMBER_IMPORT_SAVEGAMES));
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void clickImportWorldmap() {
|
||||
showStartImportWorldmapInfo(view -> startActivityForResult(AndroidStorage.getNewSelectZipIntent(),
|
||||
-SLOT_NUMBER_IMPORT_WORLDMAP));
|
||||
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void showConfirmOverwriteByExportQuestion(ContentResolver resolver,
|
||||
DocumentFile targetFolder,
|
||||
File[] files) {
|
||||
final CustomDialog d = CustomDialogFactory.createDialog(this,
|
||||
getString(R.string.loadsave_export_overwrite_confirmation_title),
|
||||
getResources().getDrawable(android.R.drawable.ic_dialog_alert),
|
||||
getString(R.string.loadsave_export_overwrite_confirmation),
|
||||
null,
|
||||
true);
|
||||
|
||||
CustomDialogFactory.addButton(d,
|
||||
android.R.string.yes,
|
||||
v -> exportSaveGamesFolderContentToFolder(targetFolder, files));
|
||||
CustomDialogFactory.addDismissButton(d, android.R.string.no);
|
||||
|
||||
CustomDialogFactory.show(d);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void showConfirmOverwriteByImportQuestion(ContentResolver resolver,
|
||||
DocumentFile appSavegameFolder,
|
||||
List<DocumentFile> alreadyExistingFiles,
|
||||
List<DocumentFile> newFiles) {
|
||||
final String title = getString(R.string.loadsave_import_overwrite_confirmation_title);
|
||||
String message = getString(R.string.loadsave_import_file_exists_question);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('\n');
|
||||
int amount = alreadyExistingFiles.size();
|
||||
|
||||
Context context = AndorsTrailApplication.getApplicationFromActivity(this).getApplicationContext();
|
||||
|
||||
ArrayList<CustomDialog> dialogs = new ArrayList<>(amount);
|
||||
|
||||
for (int i = 0; i < amount; i++) {
|
||||
DocumentFile alreadyExistingFile = alreadyExistingFiles.get(i);
|
||||
int slot = getSlotFromSavegameFileName(alreadyExistingFile.getName());
|
||||
FileHeader existingFileHeader = Savegames.quickload(context, slot);
|
||||
FileHeader importedFileHeader = null;
|
||||
try (InputStream stream = resolver.openInputStream(alreadyExistingFile.getUri());
|
||||
DataInputStream dataStream = new DataInputStream(stream)) {
|
||||
importedFileHeader = new FileHeader(dataStream, true);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
|
||||
StringBuilder messageSb = new StringBuilder();
|
||||
String existingFileDescription = getString(R.string.loadsave_import_existing_description,
|
||||
Integer.toString(slot),
|
||||
existingFileHeader.describe());
|
||||
String importedFileDescription = getString(R.string.loadsave_import_imported_description,
|
||||
Integer.toString(slot),
|
||||
importedFileHeader.describe());
|
||||
messageSb.append(getString(R.string.loadsave_import_file_exists_question,
|
||||
existingFileDescription,
|
||||
importedFileDescription));
|
||||
|
||||
|
||||
String m = messageSb.toString();
|
||||
CustomDialog dialog = CustomDialogFactory.createDialog(this,
|
||||
title,
|
||||
getResources().getDrawable(android.R.drawable.ic_dialog_alert),
|
||||
m,
|
||||
null,
|
||||
true,
|
||||
false,
|
||||
true);
|
||||
|
||||
CustomDialogFactory.addButton(dialog, R.string.loadsave_import_option_keep_existing, v -> {
|
||||
//do nothing
|
||||
GoToNextConflictOrFinish(resolver, appSavegameFolder, newFiles, dialogs);
|
||||
});
|
||||
|
||||
CustomDialogFactory.addButton(dialog, R.string.loadsave_import_option_keep_imported, v -> {
|
||||
newFiles.add(alreadyExistingFile);
|
||||
GoToNextConflictOrFinish(resolver, appSavegameFolder, newFiles, dialogs);
|
||||
});
|
||||
|
||||
CustomDialogFactory.addButton(dialog, R.string.loadsave_import_option_add_as_new, v -> {
|
||||
newFiles.add(null);//add a null element as marker to know later if the next file
|
||||
// should be imported as new or overwrite the existing one
|
||||
newFiles.add(alreadyExistingFile);
|
||||
GoToNextConflictOrFinish(resolver, appSavegameFolder, newFiles, dialogs);
|
||||
});
|
||||
|
||||
CustomDialogFactory.addCancelButton(dialog, android.R.string.cancel);
|
||||
CustomDialogFactory.setCancelListener(dialog, v -> {
|
||||
completeLoadSaveActivity(SLOT_NUMBER_IMPORT_SAVEGAMES, false);
|
||||
});
|
||||
|
||||
dialogs.add(dialog);
|
||||
}
|
||||
|
||||
GoToNextConflictOrFinish(resolver, appSavegameFolder, newFiles, dialogs);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void GoToNextConflictOrFinish(ContentResolver resolver,
|
||||
DocumentFile appSavegameFolder,
|
||||
List<DocumentFile> newFiles,
|
||||
ArrayList<CustomDialog> dialogs) {
|
||||
if (dialogs.stream().count() > 0) {
|
||||
CustomDialog d = dialogs.remove(0);
|
||||
CustomDialogFactory.show(d);
|
||||
} else {
|
||||
importSaveGames(resolver, appSavegameFolder, newFiles);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (resultCode != Activity.RESULT_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
switch (-requestCode) {
|
||||
case SLOT_NUMBER_EXPORT_SAVEGAMES:
|
||||
exportSaveGames(data);
|
||||
return;
|
||||
case SLOT_NUMBER_IMPORT_SAVEGAMES:
|
||||
importSaveGames(data);
|
||||
return;
|
||||
case SLOT_NUMBER_IMPORT_WORLDMAP:
|
||||
importWorldmap(data);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
private void loadSaveGame(int slot) {
|
||||
if (!Savegames.getSlotFile(slot, this).exists()) {
|
||||
showErrorLoadingEmptySlot();
|
||||
} else {
|
||||
final FileHeader header = Savegames.quickload(this, slot);
|
||||
if (header != null && !header.hasUnlimitedSaves) {
|
||||
showSlotGetsDeletedOnLoadWarning(slot);
|
||||
} else {
|
||||
completeLoadSaveActivity(slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//region show Dialogs
|
||||
|
||||
//region Import/Export
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void showStartExportInfo(OnClickListener onOk) {
|
||||
final CustomDialog d = CustomDialogFactory.createDialog(this,
|
||||
getString(R.string.loadsave_export),
|
||||
getResources().getDrawable(android.R.drawable.ic_dialog_info),
|
||||
getString(R.string.loadsave_export_info),
|
||||
null,
|
||||
true);
|
||||
CustomDialogFactory.addButton(d, android.R.string.yes, onOk);
|
||||
CustomDialogFactory.addDismissButton(d, android.R.string.no);
|
||||
CustomDialogFactory.show(d);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void showStartImportSavesInfo(OnClickListener onOk) {
|
||||
final CustomDialog d = CustomDialogFactory.createDialog(this,
|
||||
getString(R.string.loadsave_import_save),
|
||||
getResources().getDrawable(android.R.drawable.ic_dialog_info),
|
||||
getString(R.string.loadsave_import_save_info),
|
||||
null,
|
||||
true);
|
||||
CustomDialogFactory.addButton(d, android.R.string.yes, onOk);
|
||||
CustomDialogFactory.addDismissButton(d, android.R.string.no);
|
||||
CustomDialogFactory.show(d);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
private void showStartImportWorldmapInfo(OnClickListener onOk) {
|
||||
final CustomDialog d = CustomDialogFactory.createDialog(this,
|
||||
getString(R.string.loadsave_import_worldmap),
|
||||
getResources().getDrawable(android.R.drawable.ic_dialog_info),
|
||||
getString(R.string.loadsave_import_worldmap_info),
|
||||
null,
|
||||
true);
|
||||
CustomDialogFactory.addButton(d, android.R.string.yes, onOk);
|
||||
CustomDialogFactory.addDismissButton(d, android.R.string.no);
|
||||
CustomDialogFactory.show(d);
|
||||
}
|
||||
|
||||
private void showErrorImportingWorldmapWrongDirectory() {
|
||||
final CustomDialog d = CustomDialogFactory.createErrorDialog(this,
|
||||
getString(R.string.loadsave_import_worldmap_unsuccessfull),
|
||||
getString(R.string.loadsave_import_worldmap_wrong_file));
|
||||
CustomDialogFactory.show(d);
|
||||
}
|
||||
|
||||
private void showErrorExportingSaveGamesUnknown() {
|
||||
final CustomDialog d = CustomDialogFactory.createErrorDialog(this,
|
||||
getString(R.string.loadsave_export_unsuccessfull),
|
||||
getString(R.string.loadsave_export_error_unknown));
|
||||
CustomDialogFactory.show(d);
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
private void showErrorLoadingEmptySlot() {
|
||||
final CustomDialog d = CustomDialogFactory.createErrorDialog(this,
|
||||
getString(R.string.startscreen_error_loading_game),
|
||||
getString(R.string.startscreen_error_loading_empty_slot));
|
||||
CustomDialogFactory.show(d);
|
||||
}
|
||||
|
||||
private void showSlotGetsDeletedOnLoadWarning(final int slot) {
|
||||
final CustomDialog d = CustomDialogFactory.createDialog(this,
|
||||
getString(R.string.startscreen_attention_slot_gets_delete_on_load),
|
||||
getResources().getDrawable(android.R.drawable.ic_dialog_alert),
|
||||
getString(R.string.startscreen_attention_message_slot_gets_delete_on_load),
|
||||
null,
|
||||
true);
|
||||
CustomDialogFactory.addButton(d, android.R.string.ok, v -> completeLoadSaveActivity(slot));
|
||||
CustomDialogFactory.show(d);
|
||||
}
|
||||
|
||||
private void showConfirmOverwriteQuestion(final int slot, String message) {
|
||||
final String title = getString(R.string.loadsave_save_overwrite_confirmation_title) + ' '
|
||||
+ getString(R.string.loadsave_save_overwrite_confirmation_slot, slot);
|
||||
final CustomDialog d = CustomDialogFactory.createDialog(this,
|
||||
title,
|
||||
getResources().getDrawable(android.R.drawable.ic_dialog_alert),
|
||||
message,
|
||||
null,
|
||||
true);
|
||||
|
||||
CustomDialogFactory.addButton(d, android.R.string.yes, v -> completeLoadSaveActivity(slot));
|
||||
CustomDialogFactory.addDismissButton(d, android.R.string.no);
|
||||
CustomDialogFactory.show(d);
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
}
|
||||
@@ -1,413 +0,0 @@
|
||||
package com.gpl.rpg.AndorsTrail.activity.fragment;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
|
||||
import com.gpl.rpg.AndorsTrail.AndorsTrailPreferences;
|
||||
import com.gpl.rpg.AndorsTrail.Dialogs;
|
||||
import com.gpl.rpg.AndorsTrail.R;
|
||||
import com.gpl.rpg.AndorsTrail.WorldSetup;
|
||||
import com.gpl.rpg.AndorsTrail.activity.AboutActivity;
|
||||
import com.gpl.rpg.AndorsTrail.activity.LoadingActivity;
|
||||
import com.gpl.rpg.AndorsTrail.activity.Preferences;
|
||||
import com.gpl.rpg.AndorsTrail.controller.Constants;
|
||||
import com.gpl.rpg.AndorsTrail.resource.tiles.TileManager;
|
||||
import com.gpl.rpg.AndorsTrail.savegames.Savegames;
|
||||
import com.gpl.rpg.AndorsTrail.savegames.Savegames.FileHeader;
|
||||
import com.gpl.rpg.AndorsTrail.util.AndroidStorage;
|
||||
import com.gpl.rpg.AndorsTrail.util.L;
|
||||
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
|
||||
import com.gpl.rpg.AndorsTrail.view.CustomDialogFactory;
|
||||
import com.gpl.rpg.AndorsTrail.view.CustomDialogFactory.CustomDialog;
|
||||
|
||||
public class StartScreenActivity_MainMenu extends Fragment {
|
||||
|
||||
private static final int INTENTREQUEST_PREFERENCES = 7;
|
||||
public static final int INTENTREQUEST_LOADGAME = 9;
|
||||
|
||||
private boolean hasExistingGame = false;
|
||||
private Button startscreen_continue;
|
||||
private Button startscreen_newgame;
|
||||
private Button startscreen_load;
|
||||
private ViewGroup save_preview_holder;
|
||||
private ImageView save_preview_hero_icon;
|
||||
private TextView save_preview_hero_desc;
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
updatePreferences(false);
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
if (container != null) {
|
||||
container.removeAllViews();
|
||||
}
|
||||
|
||||
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() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
continueGame(false, Savegames.SLOT_QUICKSAVE, null);
|
||||
}
|
||||
});
|
||||
|
||||
startscreen_newgame = (Button) root.findViewById(R.id.startscreen_newgame);
|
||||
startscreen_newgame.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
if (hasExistingGame) {
|
||||
comfirmNewGame();
|
||||
} else {
|
||||
createNewGame();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Button b = (Button) root.findViewById(R.id.startscreen_about);
|
||||
b.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
startActivity(new Intent(getActivity(), AboutActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
b = (Button) root.findViewById(R.id.startscreen_preferences);
|
||||
b.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
Intent intent = new Intent(getActivity(), Preferences.class);
|
||||
StartScreenActivity_MainMenu.this.startActivityForResult(intent, INTENTREQUEST_PREFERENCES);
|
||||
}
|
||||
});
|
||||
|
||||
startscreen_load = (Button) root.findViewById(R.id.startscreen_load);
|
||||
startscreen_load.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(getActivity());
|
||||
if (hasExistingGame && app != null && app.getWorld() != null && app.getWorld().model != null
|
||||
&& app.getWorld().model.statistics != null && !app.getWorld().model.statistics.hasUnlimitedSaves()) {
|
||||
final CustomDialog d = CustomDialogFactory.createDialog(getActivity(),
|
||||
getString(R.string.startscreen_load_game),
|
||||
getResources().getDrawable(android.R.drawable.ic_delete),
|
||||
getString(R.string.startscreen_load_game_confirm),
|
||||
null,
|
||||
true);
|
||||
CustomDialogFactory.addButton(d, android.R.string.ok, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Dialogs.showLoad(StartScreenActivity_MainMenu.this);
|
||||
}
|
||||
});
|
||||
CustomDialogFactory.addDismissButton(d, android.R.string.cancel);
|
||||
CustomDialogFactory.show(d);
|
||||
|
||||
} else {
|
||||
Dialogs.showLoad(StartScreenActivity_MainMenu.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (AndorsTrailApplication.DEVELOPMENT_FORCE_STARTNEWGAME) {
|
||||
if (AndorsTrailApplication.DEVELOPMENT_DEBUGRESOURCES) {
|
||||
continueGame(true, 0, "Debug player");
|
||||
} else {
|
||||
continueGame(true, 0, "Player");
|
||||
}
|
||||
} else if (AndorsTrailApplication.DEVELOPMENT_FORCE_CONTINUEGAME) {
|
||||
continueGame(false, Savegames.SLOT_QUICKSAVE, null);
|
||||
}
|
||||
|
||||
// if it is a new version we first fire a welcome screen in onResume
|
||||
// and afterwards check the permissions
|
||||
if (!isNewVersion()) {
|
||||
checkAndRequestPermissions(getActivity());
|
||||
migrateDataOnDemand(getActivity());
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
String playerName;
|
||||
String displayInfo = null;
|
||||
int iconID = TileManager.CHAR_HERO;
|
||||
boolean isDead = false;
|
||||
|
||||
FileHeader header = Savegames.quickload(getActivity(), Savegames.SLOT_QUICKSAVE);
|
||||
if (header != null && header.playerName != null) {
|
||||
playerName = header.playerName;
|
||||
displayInfo = header.displayInfo;
|
||||
iconID = header.iconID;
|
||||
isDead = header.isDead;
|
||||
} else {
|
||||
// Before fileversion 14 (v0.6.7), quicksave was stored in Shared preferences
|
||||
SharedPreferences p = getActivity().getSharedPreferences("quicksave", Activity.MODE_PRIVATE);
|
||||
playerName = p.getString("playername", null);
|
||||
if (playerName != null) {
|
||||
displayInfo = "level " + p.getInt("level", -1);
|
||||
}
|
||||
}
|
||||
hasExistingGame = (playerName != null);
|
||||
setButtonState(playerName, displayInfo, iconID, isDead);
|
||||
|
||||
if (isNewVersion()) {
|
||||
Dialogs.showNewVersion(getActivity(), new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface arg0) {
|
||||
setCurrentVersionForVersionCheck();
|
||||
checkAndRequestPermissions(getActivity());
|
||||
migrateDataOnDemand(getActivity());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void migrateDataOnDemand(final Activity activity) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
if (activity.getApplicationContext().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
||||
if (AndroidStorage.shouldMigrateToInternalStorage(activity.getApplicationContext())) {
|
||||
final CustomDialog d = CustomDialogFactory.createDialog(activity,
|
||||
getString(R.string.startscreen_migration_title),
|
||||
activity.getResources().getDrawable(android.R.drawable.ic_dialog_alert),
|
||||
getString(R.string.startscreen_migration_text),
|
||||
null,
|
||||
true);
|
||||
CustomDialogFactory.addDismissButton(d, android.R.string.ok);
|
||||
CustomDialogFactory.show(d);
|
||||
if (!AndroidStorage.migrateToInternalStorage(activity.getApplicationContext())) {
|
||||
final CustomDialog errorDlg = CustomDialogFactory.createDialog(activity,
|
||||
getString(R.string.startscreen_migration_title),
|
||||
activity.getResources().getDrawable(android.R.drawable.ic_dialog_alert),
|
||||
getString(R.string.startscreen_migration_failure),
|
||||
null,
|
||||
true);
|
||||
CustomDialogFactory.addDismissButton(errorDlg, android.R.string.ok);
|
||||
d.cancel();
|
||||
CustomDialogFactory.show(errorDlg);
|
||||
}
|
||||
} else {
|
||||
L.log("INFO: No external files or destination folder ist not empty. No data migration.");
|
||||
}
|
||||
} else {
|
||||
L.log("INFO: No read permission on external folder. No data migration.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final int READ_EXTERNAL_STORAGE_REQUEST=1;
|
||||
private static final int WRITE_EXTERNAL_STORAGE_REQUEST=2;
|
||||
|
||||
public static void checkAndRequestPermissions(final Activity activity) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
|
||||
if (activity.getApplicationContext().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
activity.requestPermissions(new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, READ_EXTERNAL_STORAGE_REQUEST);
|
||||
}
|
||||
if (activity.getApplicationContext().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
activity.requestPermissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_EXTERNAL_STORAGE_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
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);
|
||||
if (hasExistingGame) {
|
||||
TileManager tm = AndorsTrailApplication.getApplicationFromActivity(getActivity()).getWorld().tileManager;
|
||||
tm.setImageViewTileForPlayer(getResources(), save_preview_hero_icon, iconID);
|
||||
save_preview_hero_desc.setText((isDead ? getString(R.string.rip_startscreen) : "") + playerName + ", " + displayInfo);
|
||||
save_preview_holder.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
save_preview_holder.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void continueGame(boolean createNewCharacter, int loadFromSlot, String name) {
|
||||
final WorldSetup setup = AndorsTrailApplication.getApplicationFromActivity(getActivity()).getWorldSetup();
|
||||
setup.createNewCharacter = createNewCharacter;
|
||||
setup.loadFromSlot = loadFromSlot;
|
||||
setup.newHeroName = name;
|
||||
startActivity(new Intent(getActivity(), LoadingActivity.class));
|
||||
}
|
||||
|
||||
private void comfirmNewGame() {
|
||||
// new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.AndorsTrailStyle_Dialog))
|
||||
// .setTitle(R.string.startscreen_newgame)
|
||||
// .setMessage(R.string.startscreen_newgame_confirm)
|
||||
// .setIcon(android.R.drawable.ic_delete)
|
||||
// .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// //continueGame(true);
|
||||
//// hasExistingGame = false;
|
||||
//// setButtonState(null, null, 0);
|
||||
// createNewGame();
|
||||
// }
|
||||
// })
|
||||
// .setNegativeButton(android.R.string.cancel, null)
|
||||
// .create().show();
|
||||
//
|
||||
//
|
||||
final CustomDialog d = CustomDialogFactory.createDialog(getActivity(),
|
||||
getString(R.string.startscreen_newgame),
|
||||
getResources().getDrawable(android.R.drawable.ic_delete),
|
||||
getResources().getString(R.string.startscreen_newgame_confirm),
|
||||
null,
|
||||
true);
|
||||
CustomDialogFactory.addButton(d, android.R.string.ok, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
createNewGame();
|
||||
}
|
||||
});
|
||||
CustomDialogFactory.addDismissButton(d, android.R.string.cancel);
|
||||
|
||||
CustomDialogFactory.show(d);
|
||||
|
||||
}
|
||||
|
||||
private static final String versionCheck = "lastversion";
|
||||
private boolean isNewVersion() {
|
||||
SharedPreferences s = getActivity().getSharedPreferences(Constants.PREFERENCE_MODEL_LASTRUNVERSION, Activity.MODE_PRIVATE);
|
||||
int lastversion = s.getInt(versionCheck, 0);
|
||||
if (lastversion >= AndorsTrailApplication.CURRENT_VERSION) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void setCurrentVersionForVersionCheck() {
|
||||
SharedPreferences s = getActivity().getSharedPreferences(Constants.PREFERENCE_MODEL_LASTRUNVERSION, Activity.MODE_PRIVATE);
|
||||
Editor e = s.edit();
|
||||
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:
|
||||
boolean unsuccessful = resultCode != Activity.RESULT_OK;
|
||||
if(data == null) break;
|
||||
|
||||
final boolean wasImportOrExport = data.getBooleanExtra("import_export", false);
|
||||
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;
|
||||
case INTENTREQUEST_PREFERENCES:
|
||||
updatePreferences(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
if (app.setLocale(getActivity())) {
|
||||
if (alreadyStartedLoadingResources) {
|
||||
// Changing the locale after having loaded the game requires resources to
|
||||
// be re-loaded. Therefore, we just exit here.
|
||||
Toast.makeText(getActivity(), R.string.change_locale_requires_restart, Toast.LENGTH_LONG).show();
|
||||
doFinish();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (ThemeHelper.changeTheme(preferences.selectedTheme)) {
|
||||
// Changing the theme requires a restart to re-create all activities.
|
||||
Toast.makeText(getActivity(), R.string.change_theme_requires_restart, Toast.LENGTH_LONG).show();
|
||||
doFinish();
|
||||
return;
|
||||
}
|
||||
app.getWorld().tileManager.updatePreferences(preferences);
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private void doFinish() {
|
||||
//For Lollipop and above
|
||||
((AndorsTrailApplication) getActivity().getApplication()).discardWorld();
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
|
||||
public interface OnNewGameRequestedListener {
|
||||
public void onNewGameRequested();
|
||||
}
|
||||
|
||||
private OnNewGameRequestedListener listener = null;
|
||||
|
||||
private void createNewGame() {
|
||||
if (listener != null) {
|
||||
listener.onNewGameRequested();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,342 +0,0 @@
|
||||
package com.gpl.rpg.AndorsTrail.controller;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.View.OnLongClickListener;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.activity.HeroinfoActivity;
|
||||
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
|
||||
import com.gpl.rpg.AndorsTrail.context.WorldContext;
|
||||
import com.gpl.rpg.AndorsTrail.util.Coord;
|
||||
import com.gpl.rpg.AndorsTrail.util.L;
|
||||
|
||||
public final class InputController implements OnClickListener, OnLongClickListener{
|
||||
private final ControllerContext controllers;
|
||||
private final WorldContext world;
|
||||
|
||||
private final Coord lastTouchPosition_tileCoords = new Coord();
|
||||
private int lastTouchPosition_dx = 0;
|
||||
private int lastTouchPosition_dy = 0;
|
||||
private long lastTouchEventTime = 0;
|
||||
private boolean isDpadActive = false;
|
||||
|
||||
private int keyState_dx = 0;
|
||||
private int keyState_dy = 0;
|
||||
private boolean keyState_attack = false;
|
||||
private boolean keyState_flee = false;
|
||||
private boolean keyState_endturn = false;
|
||||
|
||||
final private int KEY_UNHANDLED = 0; // Default, for unhandled keycodes
|
||||
final private int KEY_MOVE_UP = 1;
|
||||
final private int KEY_MOVE_DOWN = 2;
|
||||
final private int KEY_MOVE_LEFT = 3;
|
||||
final private int KEY_MOVE_RIGHT = 4;
|
||||
final private int KEY_MOVE_UP_LEFT = 5;
|
||||
final private int KEY_MOVE_UP_RIGHT = 6;
|
||||
final private int KEY_MOVE_DOWN_LEFT = 7;
|
||||
final private int KEY_MOVE_DOWN_RIGHT = 8;
|
||||
final private int KEY_ATTACK = 9;
|
||||
final private int KEY_FLEE = 10;
|
||||
final private int KEY_END_TURN = 11;
|
||||
final private int KEY_HERO_INFO = 12;
|
||||
final private int KEY_TOOLBOX = 13;
|
||||
|
||||
private SparseIntArray keyMap = new SparseIntArray(); // Android keycode to internal key event mapping. TODO: Configure via preferences
|
||||
|
||||
public InputController(ControllerContext controllers, WorldContext world) {
|
||||
this.controllers = controllers;
|
||||
this.world = world;
|
||||
initializeKeyMap();
|
||||
|
||||
}
|
||||
|
||||
/* New keyboard handler. Both Key Down and Key Up events handled here to allow conditional behaviours.
|
||||
On 4-way dpad controllers, cursor keys, and WASD, diagonals are generated by chording two keys.
|
||||
Single-key diagonals are supported on numeric keypad and 8-way dpads (not seen/tested in the wild).
|
||||
|
||||
Because two-key combos initially generate a ordinal movement (one key comes in first), which can
|
||||
be dangerous in tight spaces, modifiers are provided to "lock" the input until both keys are down.
|
||||
TODO: Use delay timer to enable chorded diagonals on first move without locking kludge?
|
||||
*/
|
||||
|
||||
// Map key codes to spectic internal actions
|
||||
// TODO: Move mapping out of code to JSON/XML file, or maybe player prefs
|
||||
private void initializeKeyMap() {
|
||||
int key;
|
||||
|
||||
// Keys mapping to UP
|
||||
key = KEY_MOVE_UP;
|
||||
keyMap.put(KeyEvent.KEYCODE_DPAD_UP, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_NUMPAD_8, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_8, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_W, key);
|
||||
|
||||
// Keys mapping to DOWN
|
||||
key = KEY_MOVE_DOWN;
|
||||
keyMap.put(KeyEvent.KEYCODE_DPAD_DOWN, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_NUMPAD_2, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_2, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_S, key);
|
||||
|
||||
// Keys mapping to LEFT
|
||||
key = KEY_MOVE_LEFT;
|
||||
keyMap.put(KeyEvent.KEYCODE_DPAD_LEFT, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_NUMPAD_4, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_4, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_A, key);
|
||||
|
||||
// Keys mapping to RIGHT
|
||||
key = KEY_MOVE_RIGHT;
|
||||
keyMap.put(KeyEvent.KEYCODE_DPAD_RIGHT, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_NUMPAD_6, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_6, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_D, key);
|
||||
|
||||
// Keys mapping to UP_LEFT
|
||||
key = KEY_MOVE_UP_LEFT;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
keyMap.put(KeyEvent.KEYCODE_DPAD_UP_LEFT, key);
|
||||
}
|
||||
keyMap.put(KeyEvent.KEYCODE_NUMPAD_7, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_7, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_MOVE_HOME, key);
|
||||
|
||||
// Keys mapping to UP_RIGHT
|
||||
key = KEY_MOVE_UP_RIGHT;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
keyMap.put(KeyEvent.KEYCODE_DPAD_UP_RIGHT, key);
|
||||
}
|
||||
keyMap.put(KeyEvent.KEYCODE_NUMPAD_9, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_9, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_PAGE_UP, key);
|
||||
|
||||
// Keys mapping to DOWN_LEFT
|
||||
key = KEY_MOVE_DOWN_LEFT;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
keyMap.put(KeyEvent.KEYCODE_DPAD_DOWN_LEFT, key);
|
||||
}
|
||||
keyMap.put(KeyEvent.KEYCODE_NUMPAD_1, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_1, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_MOVE_END, key);
|
||||
|
||||
// Keys mapping to DOWN_RIGHT
|
||||
key = KEY_MOVE_DOWN_RIGHT;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
keyMap.put(KeyEvent.KEYCODE_DPAD_DOWN_RIGHT, key);
|
||||
}
|
||||
keyMap.put(KeyEvent.KEYCODE_NUMPAD_3, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_3, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_PAGE_DOWN, key);
|
||||
|
||||
// Keys mapping to ATTACK
|
||||
key = KEY_ATTACK;
|
||||
keyMap.put(KeyEvent.KEYCODE_DPAD_CENTER, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_BUTTON_A, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_SPACE, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_NUMPAD_5, key);
|
||||
|
||||
// Keys mapping to FLEE
|
||||
key = KEY_FLEE;
|
||||
keyMap.put(KeyEvent.KEYCODE_BUTTON_X, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_F, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_NUMPAD_ENTER, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_ENTER, key);
|
||||
|
||||
// Keys mapping to END_TURN
|
||||
key = KEY_END_TURN;
|
||||
keyMap.put(KeyEvent.KEYCODE_BUTTON_Y, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_E, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_FORWARD_DEL, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_NUMPAD_DOT, key);
|
||||
|
||||
// Keys mapping to HERO_INFO
|
||||
key = KEY_HERO_INFO;
|
||||
//keyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_BUTTON_L1, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_NUM_LOCK, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_C, key);
|
||||
|
||||
// Keys mapping to TOOLBOX
|
||||
key = KEY_TOOLBOX;
|
||||
keyMap.put(KeyEvent.KEYCODE_BUTTON_R1, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_NUMPAD_DIVIDE, key);
|
||||
keyMap.put(KeyEvent.KEYCODE_B, key);
|
||||
}
|
||||
|
||||
// Generate game actions based on mapped keys
|
||||
public boolean onKeyboardAction(Context context, KeyEvent event, boolean acceptInput) {
|
||||
//L.log("onKeyboardAction(): Processing action " + event.getAction() + " for keyCode " + event.getKeyCode());
|
||||
|
||||
if (event.getAction() != KeyEvent.ACTION_DOWN && event.getAction() != KeyEvent.ACTION_UP) return false; // don't handle other actions
|
||||
boolean keydown = (event.getAction() == KeyEvent.ACTION_DOWN);
|
||||
boolean inihbit = (keyState_attack || keyState_flee); // used to inhibit movement if an action key is held down
|
||||
|
||||
switch (keyMap.get(event.getKeyCode())) {
|
||||
|
||||
// Ordinal directional keys - only modify one direction register; registers are combined when
|
||||
// keys used simultaneously to create synthetic diagonals
|
||||
case KEY_MOVE_UP:
|
||||
keyState_dy = keydown ? -1 : 0;
|
||||
if (acceptInput && !inihbit) onRelativeMovement(keyState_dx, keyState_dy);
|
||||
break;
|
||||
case KEY_MOVE_DOWN:
|
||||
keyState_dy = keydown ? 1 : 0;
|
||||
if (acceptInput && !inihbit) onRelativeMovement(keyState_dx, keyState_dy);
|
||||
break;
|
||||
case KEY_MOVE_LEFT:
|
||||
keyState_dx = keydown ? -1 : 0;
|
||||
if (acceptInput && !inihbit) onRelativeMovement(keyState_dx, keyState_dy);
|
||||
break;
|
||||
case KEY_MOVE_RIGHT:
|
||||
keyState_dx = keydown ? 1 : 0;
|
||||
if (acceptInput && !inihbit) onRelativeMovement(keyState_dx, keyState_dy);
|
||||
break;
|
||||
|
||||
// Diagonal directional keys. Modify both direction registers, can't be combined
|
||||
// TODO: store individual key position to allow combinations. May not be worth the trouble.
|
||||
case KEY_MOVE_UP_LEFT:
|
||||
keyState_dx = keydown ? -1 : 0;
|
||||
keyState_dy = keydown ? -1 : 0;
|
||||
if (acceptInput && !inihbit) onRelativeMovement(keyState_dx, keyState_dy);
|
||||
break;
|
||||
case KEY_MOVE_UP_RIGHT:
|
||||
keyState_dx = keydown ? 1 : 0;
|
||||
keyState_dy = keydown ? -1 : 0;
|
||||
if (acceptInput && !inihbit) onRelativeMovement(keyState_dx, keyState_dy);
|
||||
break;
|
||||
case KEY_MOVE_DOWN_LEFT:
|
||||
keyState_dx = keydown ? -1 : 0;
|
||||
keyState_dy = keydown ? 1 : 0;
|
||||
if (acceptInput && !inihbit) onRelativeMovement(keyState_dx, keyState_dy);
|
||||
break;
|
||||
case KEY_MOVE_DOWN_RIGHT:
|
||||
keyState_dx = keydown ? 1 : 0;
|
||||
keyState_dy = keydown ? 1 : 0;
|
||||
if (acceptInput && !inihbit) onRelativeMovement(keyState_dx, keyState_dy);
|
||||
break;
|
||||
|
||||
// Special key handling below - some combat/movement stuff done here because it's too
|
||||
// specific for logic in onRelativeMovement
|
||||
|
||||
// "Attack" shortcut - freeze movement to allow chorded direction when key is released.
|
||||
// if in combat, executes an attack on key release
|
||||
case KEY_ATTACK:
|
||||
if (keydown && !keyState_attack) { // key pressed - pause any movement
|
||||
if(!world.model.uiSelections.isInCombat) controllers.movementController.stopMovement();
|
||||
} else if (!keydown && keyState_attack) { // key released - execute attack / move in direction
|
||||
if (acceptInput) onRelativeMovement(keyState_dx, keyState_dy);
|
||||
}
|
||||
keyState_attack = keydown;
|
||||
break;
|
||||
|
||||
// "Flee" shortcut. Intitiates flee when pressed. If a direction is held, moves in chosen direction when released
|
||||
case KEY_FLEE:
|
||||
if (world.model.uiSelections.isInCombat) {
|
||||
if (keydown && !keyState_flee) { // button pressed - set flee; movement locked while pressed
|
||||
if(acceptInput) controllers.combatController.startFlee();
|
||||
} else if (!keydown && keyState_flee) { // button released - move flee direction, if held
|
||||
// We need to do a special call because the movement key may already be down, and if the device
|
||||
// doesn't generate repeat keystrokes, this handler won't get another event
|
||||
if ((keyState_dx != 0 || keyState_dy != 0) && allowInputInterval()) {
|
||||
if(acceptInput) controllers.combatController.executeMoveAttack(keyState_dx, keyState_dy);
|
||||
}
|
||||
}
|
||||
}
|
||||
keyState_flee = keydown;
|
||||
break;
|
||||
|
||||
// "End Turn" shortcut. Flag prevents repeated end turn if key is held down.
|
||||
case KEY_END_TURN:
|
||||
if (acceptInput && keydown && !keyState_endturn) {
|
||||
if (world.model.uiSelections.isInCombat) controllers.combatController.endPlayerTurn();
|
||||
}
|
||||
keyState_endturn = keydown;
|
||||
break;
|
||||
|
||||
// "Hero Info" screen shortcut. New activity takes focus, so we don't need to worry about repeats.
|
||||
case KEY_HERO_INFO:
|
||||
if (acceptInput && keydown) context.startActivity(new Intent(context, HeroinfoActivity.class));
|
||||
break;
|
||||
|
||||
case KEY_TOOLBOX:
|
||||
// ??? ToolboxView toolboxview = context.getApplicationContext(). findViewById(R.id.main_toolboxview);
|
||||
|
||||
break;
|
||||
|
||||
case KEY_UNHANDLED: // Unhandled keycode
|
||||
return false;
|
||||
|
||||
default: // unhandled keymap code entry (should not happen)
|
||||
L.log("onKeyboardAction(): Unhandled keyMap code constant " + keyMap.get(event.getKeyCode()) + " for keyCode " + event.getKeyCode());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onRelativeMovement(int dx, int dy) {
|
||||
//L.log("onRelativeMovement(): dx=" + dx + " dy=" + dy + " combat: " + world.model.uiSelections.isInCombat);
|
||||
if (world.model.uiSelections.isInCombat) {
|
||||
if (allowInputInterval()) controllers.combatController.executeMoveAttack(dx, dy);
|
||||
} else if (dx == 0 && dy == 0) {
|
||||
controllers.movementController.stopMovement();
|
||||
} else {
|
||||
controllers.movementController.startMovement(dx, dy, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void onKeyboardCancel() {
|
||||
controllers.movementController.stopMovement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
if (!world.model.uiSelections.isInCombat) return;
|
||||
onRelativeMovement(lastTouchPosition_dx, lastTouchPosition_dy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View arg0) {
|
||||
if (world.model.uiSelections.isInCombat) {
|
||||
//TODO: Should be able to mark positions far away (mapwalk / ranged combat)
|
||||
if (lastTouchPosition_dx == 0 && lastTouchPosition_dy == 0) return false;
|
||||
if (Math.abs(lastTouchPosition_dx) > 1) return false;
|
||||
if (Math.abs(lastTouchPosition_dy) > 1) return false;
|
||||
|
||||
controllers.combatController.setCombatSelection(lastTouchPosition_tileCoords);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean allowInputInterval() {
|
||||
final long now = System.currentTimeMillis();
|
||||
if ((now - lastTouchEventTime) < Constants.MINIMUM_INPUT_INTERVAL) return false;
|
||||
lastTouchEventTime = now;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setDpadActive(boolean isDpadActive) {
|
||||
this.isDpadActive = isDpadActive;
|
||||
}
|
||||
|
||||
public void onTouchCancel() {
|
||||
controllers.movementController.stopMovement();
|
||||
}
|
||||
|
||||
public boolean onTouchedTile(int tile_x, int tile_y) {
|
||||
lastTouchPosition_tileCoords.set(tile_x, tile_y);
|
||||
lastTouchPosition_dx = tile_x - world.model.player.position.x;
|
||||
lastTouchPosition_dy = tile_y - world.model.player.position.y;
|
||||
|
||||
if (world.model.uiSelections.isInCombat || isDpadActive) return false;
|
||||
|
||||
controllers.movementController.startMovement(lastTouchPosition_dx, lastTouchPosition_dy, lastTouchPosition_tileCoords);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package com.gpl.rpg.AndorsTrail.model;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.util.L;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.DigestException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class ChecksumBuilder {
|
||||
|
||||
public static final int CHECKSUM_LENGTH = 32;// 256 bits (depends on the hash algorithm)
|
||||
public static final String CHECKSUM_ALGORITHM = "SHA-256"; //Should be available in all Android versions
|
||||
private ByteBuffer buffer;
|
||||
private final MessageDigest digest;
|
||||
|
||||
private ChecksumBuilder(int initialCapacity, ByteOrder byteOrder) {
|
||||
buffer = ByteBuffer.allocate(initialCapacity);
|
||||
buffer.order(byteOrder);
|
||||
try {
|
||||
digest = MessageDigest.getInstance(CHECKSUM_ALGORITHM); // Or SHA-512 for even stronger hash
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException("Hash algorithm not found", e);
|
||||
}
|
||||
}
|
||||
|
||||
private ChecksumBuilder(int initialCapacity) {
|
||||
this(initialCapacity, ByteOrder.BIG_ENDIAN); // Default to big-endian
|
||||
}
|
||||
|
||||
public ChecksumBuilder() {
|
||||
this(1024*10); // A reasonable default initial capacity
|
||||
}
|
||||
|
||||
// --- Methods for adding different data types ---
|
||||
|
||||
public ChecksumBuilder add(String value) {
|
||||
if (value != null) {
|
||||
byte[] bytes;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
bytes = value.getBytes(StandardCharsets.UTF_8);
|
||||
} else {
|
||||
bytes = value.getBytes();
|
||||
}
|
||||
add(bytes);
|
||||
} else {
|
||||
add(-1); // Use -1 to represent a null string
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChecksumBuilder add(byte[] bytes) {
|
||||
add(bytes.length); // Add length prefix
|
||||
ensureCapacity(bytes.length + 4); // +4 for length prefix (int)
|
||||
buffer.put(bytes);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChecksumBuilder add(boolean value) {
|
||||
ensureCapacity(1);
|
||||
buffer.put(value ? (byte) 1 : (byte) 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChecksumBuilder add(long value) {
|
||||
ensureCapacity(8);
|
||||
buffer.putLong(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChecksumBuilder add(int value) {
|
||||
ensureCapacity(4);
|
||||
buffer.putInt(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChecksumBuilder add(float value) {
|
||||
ensureCapacity(8);
|
||||
buffer.putFloat(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChecksumBuilder add(double value) {
|
||||
ensureCapacity(4);
|
||||
buffer.putDouble(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
// --- Method to finalize and get the checksum ---
|
||||
|
||||
public byte[] build() throws DigestException {
|
||||
buffer.flip(); // Prepare for reading
|
||||
digest.update(buffer);// Only use the actually used part of the buffer
|
||||
buffer.flip(); // Prepare for further writing
|
||||
return digest.digest();
|
||||
}
|
||||
|
||||
|
||||
// --- Utility method to ensure sufficient capacity ---
|
||||
private void ensureCapacity(int required) {
|
||||
if (buffer.remaining() < required) {
|
||||
int newCapacity = Math.max(buffer.capacity() * 2, buffer.capacity() + required);
|
||||
ByteBuffer newBuffer = ByteBuffer.allocate(newCapacity);
|
||||
newBuffer.order(buffer.order());
|
||||
buffer.flip(); // Prepare for reading
|
||||
newBuffer.put(buffer); // Copy existing data
|
||||
buffer = newBuffer; // Assign the new buffer to the field
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.gpl.rpg.AndorsTrail.model;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.model.map.LayeredTileMap;
|
||||
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
|
||||
import com.gpl.rpg.AndorsTrail.resource.tiles.TileCollection;
|
||||
|
||||
public final class MapBundle {
|
||||
public PredefinedMap map;
|
||||
public LayeredTileMap tileMap;
|
||||
public TileCollection tiles;
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
package com.gpl.rpg.AndorsTrail.model;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
public final class WorldData {
|
||||
private long worldTime = 0; // Measured in number of game rounds
|
||||
private final HashMap<String, Long> timers = new HashMap<String, Long>();
|
||||
|
||||
public WorldData() {}
|
||||
|
||||
public void tickWorldTime() {
|
||||
++worldTime;
|
||||
}
|
||||
public void tickWorldTime(int ticks) {
|
||||
worldTime += ticks;
|
||||
}
|
||||
public long getWorldTime() {
|
||||
return worldTime;
|
||||
}
|
||||
|
||||
public void createTimer(String name) {
|
||||
timers.put(name, worldTime);
|
||||
}
|
||||
|
||||
public void removeTimer(String name) {
|
||||
timers.remove(name);
|
||||
}
|
||||
|
||||
public boolean hasTimerElapsed(String name, long duration) {
|
||||
Long v = timers.get(name);
|
||||
if (v == null) return false;
|
||||
return v + duration <= worldTime;
|
||||
}
|
||||
|
||||
public int getDate(String format) {
|
||||
Calendar now = Calendar.getInstance();
|
||||
int ret;
|
||||
switch (format) {
|
||||
case "YYYYMMDD":
|
||||
ret = now.get(Calendar.YEAR)*10000 + (now.get(Calendar.MONTH) + 1)*100 + now.get(Calendar.DAY_OF_MONTH);
|
||||
break;
|
||||
case "YYYYMM":
|
||||
ret = now.get(Calendar.YEAR)*100 + (now.get(Calendar.MONTH) + 1);
|
||||
break;
|
||||
case "YYYY":
|
||||
ret = now.get(Calendar.YEAR);
|
||||
break;
|
||||
case "MMDD":
|
||||
ret = (now.get(Calendar.MONTH) + 1)*100 + now.get(Calendar.DAY_OF_MONTH);
|
||||
break;
|
||||
case "MM":
|
||||
ret = (now.get(Calendar.MONTH) + 1);
|
||||
break;
|
||||
case "DD":
|
||||
ret = now.get(Calendar.DAY_OF_MONTH);
|
||||
break;
|
||||
default:
|
||||
ret = 99999999; //never true
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int getTime(String format) {
|
||||
Calendar now = Calendar.getInstance();
|
||||
int ret;
|
||||
switch (format) {
|
||||
case "HHMMSS":
|
||||
ret = now.get(Calendar.HOUR_OF_DAY)*10000 + now.get(Calendar.MINUTE)*100 + now.get(Calendar.SECOND);
|
||||
break;
|
||||
case "HHMM":
|
||||
ret = now.get(Calendar.HOUR_OF_DAY)*100 + now.get(Calendar.MINUTE);
|
||||
break;
|
||||
case "HH":
|
||||
ret = now.get(Calendar.HOUR_OF_DAY);
|
||||
break;
|
||||
case "MMSS":
|
||||
ret = now.get(Calendar.MINUTE)*100 + now.get(Calendar.SECOND);
|
||||
break;
|
||||
case "MM":
|
||||
ret = now.get(Calendar.MINUTE);
|
||||
break;
|
||||
case "SS":
|
||||
ret = now.get(Calendar.SECOND);
|
||||
break;
|
||||
default:
|
||||
ret = 99999999; //never true
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ====== PARCELABLE ===================================================================
|
||||
|
||||
public WorldData(DataInputStream src, int fileversion) throws IOException {
|
||||
worldTime = src.readLong();
|
||||
final int numTimers = src.readInt();
|
||||
for(int i = 0; i < numTimers; ++i) {
|
||||
final String timerName = src.readUTF();
|
||||
final long value = src.readLong();
|
||||
this.timers.put(timerName, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToParcel(DataOutputStream dest) throws IOException {
|
||||
dest.writeLong(worldTime);
|
||||
dest.writeInt(timers.size());
|
||||
for(Map.Entry<String, Long> e : timers.entrySet()) {
|
||||
dest.writeUTF(e.getKey());
|
||||
dest.writeLong(e.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void addToChecksum(ChecksumBuilder builder) {
|
||||
builder.add(worldTime);
|
||||
builder.add(timers.size());
|
||||
for(Map.Entry<String, Long> e : timers.entrySet()) {
|
||||
builder.add(e.getKey());
|
||||
builder.add(e.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package com.gpl.rpg.AndorsTrail.resource.tiles;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class TileCollection {
|
||||
private final Bitmap[] bitmaps;
|
||||
private final Map<Integer, Bitmap> flippedBitmaps;
|
||||
public final int maxTileID;
|
||||
|
||||
public TileCollection(int maxTileID) {
|
||||
this.bitmaps = new Bitmap[maxTileID+1];
|
||||
this.flippedBitmaps = new HashMap<>();
|
||||
this.maxTileID = maxTileID;
|
||||
}
|
||||
|
||||
public Bitmap getBitmap(int tileID) {
|
||||
return bitmaps[tileID];
|
||||
}
|
||||
|
||||
public void setBitmap(int tileID, Bitmap bitmap) {
|
||||
bitmaps[tileID] = bitmap;
|
||||
flippedBitmaps.remove(tileID); // Remove cached flipped version if it exists
|
||||
}
|
||||
|
||||
public void drawTile(Canvas canvas, int tile, int px, int py, Paint mPaint) {
|
||||
drawTile(canvas, tile, px, py, mPaint, false);
|
||||
}
|
||||
public void drawTile(Canvas canvas, int tile, int px, int py, Paint mPaint, boolean isFlippedX) {
|
||||
if (isFlippedX) {
|
||||
canvas.drawBitmap(getFlippedBitmap(tile), px, py, mPaint);
|
||||
} else canvas.drawBitmap(bitmaps[tile], px, py, mPaint);
|
||||
}
|
||||
|
||||
private Bitmap getFlippedBitmap(int tile) {
|
||||
if (flippedBitmaps.containsKey(tile)) {
|
||||
return flippedBitmaps.get(tile);
|
||||
}
|
||||
Bitmap flipped = flipBitmapX(bitmaps[tile]);
|
||||
flippedBitmaps.put(tile, flipped);
|
||||
return flipped;
|
||||
}
|
||||
|
||||
private static Bitmap flipBitmapX(Bitmap source) {
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postScale(-1, 1, source.getWidth() / 2f, source.getHeight() / 2f);
|
||||
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
|
||||
}
|
||||
}
|
||||
@@ -1,419 +0,0 @@
|
||||
package com.gpl.rpg.AndorsTrail.savegames;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.security.DigestException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
|
||||
import com.gpl.rpg.AndorsTrail.R;
|
||||
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
|
||||
import com.gpl.rpg.AndorsTrail.context.WorldContext;
|
||||
import com.gpl.rpg.AndorsTrail.controller.Constants;
|
||||
import com.gpl.rpg.AndorsTrail.controller.WorldMapController;
|
||||
import com.gpl.rpg.AndorsTrail.model.ModelContainer;
|
||||
import com.gpl.rpg.AndorsTrail.resource.tiles.TileManager;
|
||||
import com.gpl.rpg.AndorsTrail.util.AndroidStorage;
|
||||
import com.gpl.rpg.AndorsTrail.util.L;
|
||||
|
||||
public final class Savegames {
|
||||
public static final int SLOT_QUICKSAVE = 0;
|
||||
public static final long DENY_LOADING_BECAUSE_GAME_IS_CURRENTLY_PLAYED = -1;
|
||||
|
||||
private static long lastBackup = 0;
|
||||
|
||||
|
||||
|
||||
public static enum LoadSavegameResult {
|
||||
success
|
||||
, unknownError
|
||||
, savegameIsFromAFutureVersion
|
||||
, cheatingDetected
|
||||
}
|
||||
|
||||
public static boolean saveWorld(WorldContext world, Context androidContext, int slot) {
|
||||
try {
|
||||
final String displayInfo = androidContext.getString(R.string.savegame_currenthero_displayinfo, world.model.player.getLevel(), world.model.player.getTotalExperience(), world.model.player.getGold());
|
||||
if (slot != SLOT_QUICKSAVE && !world.model.statistics.hasUnlimitedSaves()) {
|
||||
world.model.player.savedVersion++;
|
||||
}
|
||||
String id = world.model.player.id;
|
||||
long savedVersion = world.model.player.savedVersion;
|
||||
|
||||
// Create the savegame in a temporary memorystream first to ensure that the savegame can
|
||||
// be created correctly. We don't want to trash the user's file unneccessarily if there is an error.
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
saveWorld(world, bos, displayInfo);
|
||||
byte[] savegame = bos.toByteArray();
|
||||
bos.close();
|
||||
|
||||
FileOutputStream fos = getOutputFile(androidContext, slot);
|
||||
fos.write(savegame);
|
||||
fos.close();
|
||||
|
||||
if (!world.model.statistics.hasUnlimitedSaves()) {
|
||||
if (slot != SLOT_QUICKSAVE) {
|
||||
androidContext.deleteFile(Constants.FILENAME_SAVEGAME_QUICKSAVE);
|
||||
writeCheatCheck(androidContext, savedVersion, id);
|
||||
} else if (SystemClock.uptimeMillis() > lastBackup + 120000) {
|
||||
writeBackup(androidContext, savegame, id);
|
||||
lastBackup = SystemClock.uptimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (IOException | DigestException e) {
|
||||
L.log("Error saving world: " + e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeBackup(Context androidContext, byte[] savegame, String playerId) throws IOException {
|
||||
File cheatDetectionFolder = AndroidStorage.getStorageDirectory(androidContext, Constants.CHEAT_DETECTION_FOLDER);
|
||||
ensureDirExists(cheatDetectionFolder);
|
||||
File backupFile = new File(cheatDetectionFolder, playerId + "X");
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(backupFile);
|
||||
fileOutputStream.write(savegame);
|
||||
fileOutputStream.close();
|
||||
}
|
||||
|
||||
public static LoadSavegameResult loadWorld(WorldContext world, ControllerContext controllers, Context androidContext, int slot) {
|
||||
try {
|
||||
FileHeader fh = quickload(androidContext, slot);
|
||||
if(fh == null) {
|
||||
return LoadSavegameResult.unknownError;
|
||||
}
|
||||
if (!fh.hasUnlimitedSaves && slot != SLOT_QUICKSAVE && triedToCheat(androidContext, fh)) {
|
||||
return LoadSavegameResult.cheatingDetected;
|
||||
}
|
||||
|
||||
FileInputStream fos = getInputFile(androidContext, slot);
|
||||
LoadSavegameResult result = loadWorld(androidContext.getResources(), world, controllers, androidContext, fos, fh);
|
||||
fos.close();
|
||||
if (result == LoadSavegameResult.success && slot != SLOT_QUICKSAVE && !world.model.statistics.hasUnlimitedSaves()) {
|
||||
// save to the quicksave slot before deleting the file
|
||||
if (!saveWorld(world, androidContext, SLOT_QUICKSAVE)) {
|
||||
return LoadSavegameResult.unknownError;
|
||||
}
|
||||
getSlotFile(slot, androidContext).delete();
|
||||
writeCheatCheck(androidContext, DENY_LOADING_BECAUSE_GAME_IS_CURRENTLY_PLAYED, fh.playerId);
|
||||
}
|
||||
return result;
|
||||
} catch (IOException | DigestException e) {
|
||||
if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) {
|
||||
L.log("Error loading world: " + e.toString());
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
L.log("Load error: " + sw.toString());
|
||||
}
|
||||
return LoadSavegameResult.unknownError;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean triedToCheat(Context androidContext, FileHeader fh) throws IOException {
|
||||
long savedVersionToCheck = 0;
|
||||
File cheatDetectionFolder = AndroidStorage.getStorageDirectory(androidContext, Constants.CHEAT_DETECTION_FOLDER);
|
||||
ensureDirExists(cheatDetectionFolder);
|
||||
File cheatDetectionFile = new File(cheatDetectionFolder, fh.playerId);
|
||||
if (cheatDetectionFile.exists()) {
|
||||
FileInputStream fileInputStream = new FileInputStream(cheatDetectionFile);
|
||||
DataInputStream dataInputStream = new DataInputStream(fileInputStream);
|
||||
final CheatDetection cheatDetection = new CheatDetection(dataInputStream);
|
||||
savedVersionToCheck = cheatDetection.savedVersion;
|
||||
dataInputStream.close();
|
||||
fileInputStream.close();
|
||||
}
|
||||
|
||||
if (savedVersionToCheck == DENY_LOADING_BECAUSE_GAME_IS_CURRENTLY_PLAYED) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (androidContext.getFileStreamPath(fh.playerId).exists()) {
|
||||
FileInputStream fileInputStream = androidContext.openFileInput(fh.playerId);
|
||||
DataInputStream dataInputStream = new DataInputStream(fileInputStream);
|
||||
final CheatDetection cheatDetection = new CheatDetection(dataInputStream);
|
||||
if (cheatDetection.savedVersion == DENY_LOADING_BECAUSE_GAME_IS_CURRENTLY_PLAYED) {
|
||||
savedVersionToCheck = DENY_LOADING_BECAUSE_GAME_IS_CURRENTLY_PLAYED;
|
||||
} else if (cheatDetection.savedVersion > savedVersionToCheck) {
|
||||
savedVersionToCheck = cheatDetection.savedVersion;
|
||||
}
|
||||
|
||||
if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) {
|
||||
L.log("Internal cheatcheck file savedVersion: " + cheatDetection.savedVersion);
|
||||
}
|
||||
|
||||
dataInputStream.close();
|
||||
fileInputStream.close();
|
||||
}
|
||||
|
||||
return (savedVersionToCheck == DENY_LOADING_BECAUSE_GAME_IS_CURRENTLY_PLAYED || fh.savedVersion < savedVersionToCheck);
|
||||
}
|
||||
|
||||
private static FileOutputStream getOutputFile(Context androidContext, int slot) throws IOException {
|
||||
if (slot == SLOT_QUICKSAVE) {
|
||||
return androidContext.openFileOutput(Constants.FILENAME_SAVEGAME_QUICKSAVE, Context.MODE_PRIVATE);
|
||||
} else {
|
||||
ensureSavegameDirectoryExists(androidContext);
|
||||
return new FileOutputStream(getSlotFile(slot, androidContext));
|
||||
}
|
||||
}
|
||||
|
||||
private static void ensureSavegameDirectoryExists(Context context) {
|
||||
File dir = AndroidStorage.getStorageDirectory(context, Constants.FILENAME_SAVEGAME_DIRECTORY);
|
||||
ensureDirExists(dir);
|
||||
}
|
||||
|
||||
public static boolean ensureDirExists(File dir) {
|
||||
if (!dir.exists()) {
|
||||
boolean worked = dir.mkdir();
|
||||
return worked;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static FileInputStream getInputFile(Context androidContext, int slot) throws IOException {
|
||||
if (slot == SLOT_QUICKSAVE) {
|
||||
return androidContext.openFileInput(Constants.FILENAME_SAVEGAME_QUICKSAVE);
|
||||
} else {
|
||||
return new FileInputStream(getSlotFile(slot, androidContext));
|
||||
}
|
||||
}
|
||||
|
||||
public static File getSlotFile(int slot, Context context) {
|
||||
File root = AndroidStorage.getStorageDirectory(context, Constants.FILENAME_SAVEGAME_DIRECTORY);
|
||||
return getSlotFile(slot, root);
|
||||
}
|
||||
|
||||
public static File getSlotFile(int slot, File directory) {
|
||||
return new File(directory, getSlotFileName(slot));
|
||||
}
|
||||
|
||||
public static String getSlotFileName(int slot) {
|
||||
return Constants.FILENAME_SAVEGAME_FILENAME_PREFIX + slot;
|
||||
}
|
||||
|
||||
|
||||
public static void saveWorld(WorldContext world, OutputStream outStream, String displayInfo) throws IOException, DigestException {
|
||||
DataOutputStream dest = new DataOutputStream(outStream);
|
||||
FileHeader.writeToParcel(dest, world.model.player.getName(),
|
||||
displayInfo, world.model.player.iconID,
|
||||
world.model.statistics.isDead(),
|
||||
world.model.statistics.hasUnlimitedSaves(),
|
||||
world.model.player.id,
|
||||
world.model.player.savedVersion,
|
||||
world.model.statistics.getIsAlteredSavegame());
|
||||
|
||||
byte[] checksum = world.getChecksum();
|
||||
world.model.statistics.setChecksum(checksum);
|
||||
|
||||
world.maps.writeToParcel(dest, world);
|
||||
world.model.writeToParcel(dest);
|
||||
dest.close();
|
||||
}
|
||||
|
||||
public static LoadSavegameResult loadWorld(Resources res, WorldContext world, ControllerContext controllers, Context androidContext, InputStream inState, FileHeader fh) throws IOException, DigestException {
|
||||
DataInputStream src = new DataInputStream(inState);
|
||||
final FileHeader header = new FileHeader(src, fh.skipIcon);
|
||||
if (header.fileversion > AndorsTrailApplication.CURRENT_VERSION)
|
||||
return LoadSavegameResult.savegameIsFromAFutureVersion;
|
||||
|
||||
world.maps.readFromParcel(src, world, controllers, header.fileversion);
|
||||
world.model = new ModelContainer(src, world, controllers, header.fileversion);
|
||||
src.close();
|
||||
if (header.fileversion >= 81) {
|
||||
checkChecksum(world);
|
||||
}
|
||||
WorldMapController.populateWorldMap(androidContext, world, controllers.getResources());
|
||||
|
||||
if (header.fileversion < 45) {
|
||||
LegacySavegamesContentAdaptations.adaptToNewContentForVersion45(world, controllers, res);
|
||||
}
|
||||
|
||||
onWorldLoaded(res, world, controllers);
|
||||
|
||||
return LoadSavegameResult.success;
|
||||
}
|
||||
|
||||
private static void checkChecksum(WorldContext world) throws DigestException {
|
||||
byte[] checksum = world.getChecksum();
|
||||
if (!world.model.statistics.compareChecksum(checksum)) {
|
||||
world.model.statistics.markAsAlteredSavegame();
|
||||
}
|
||||
}
|
||||
|
||||
private static void onWorldLoaded(Resources res, WorldContext world, ControllerContext controllers) {
|
||||
controllers.actorStatsController.recalculatePlayerStats(world.model.player);
|
||||
controllers.mapController.resetMapsNotRecentlyVisited();
|
||||
controllers.movementController.prepareMapAsCurrentMap(world.model.currentMaps.map, res, false);
|
||||
controllers.gameRoundController.resetRoundTimers();
|
||||
}
|
||||
|
||||
public static FileHeader quickload(Context androidContext, int slot) {
|
||||
try {
|
||||
if (slot != SLOT_QUICKSAVE) {
|
||||
File f = getSlotFile(slot, androidContext);
|
||||
if (!f.exists()) return null;
|
||||
}
|
||||
FileInputStream fos = getInputFile(androidContext, slot);
|
||||
DataInputStream src = new DataInputStream(fos);
|
||||
final FileHeader header = new FileHeader(src, false);
|
||||
src.close();
|
||||
fos.close();
|
||||
return header;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeCheatCheck(Context androidContext, long savedVersion, String playerId) throws IOException {
|
||||
File cheatDetectionFolder = AndroidStorage.getStorageDirectory(androidContext, Constants.CHEAT_DETECTION_FOLDER);
|
||||
ensureDirExists(cheatDetectionFolder);
|
||||
File cheatDetectionFile = new File(cheatDetectionFolder, playerId);
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(cheatDetectionFile);
|
||||
DataOutputStream dataOutputStream = new DataOutputStream(fileOutputStream);
|
||||
CheatDetection.writeToParcel(dataOutputStream, savedVersion);
|
||||
dataOutputStream.close();
|
||||
fileOutputStream.close();
|
||||
|
||||
fileOutputStream = androidContext.openFileOutput(playerId, Context.MODE_PRIVATE);
|
||||
dataOutputStream = new DataOutputStream(fileOutputStream);
|
||||
CheatDetection.writeToParcel(dataOutputStream, savedVersion);
|
||||
dataOutputStream.close();
|
||||
fileOutputStream.close();
|
||||
}
|
||||
|
||||
private static final Pattern savegameFilenamePattern = Pattern.compile(Constants.FILENAME_SAVEGAME_FILENAME_PREFIX + "(\\d+)");
|
||||
|
||||
public static List<Integer> getUsedSavegameSlots(Context context) {
|
||||
try {
|
||||
final List<Integer> result = new ArrayList<Integer>();
|
||||
AndroidStorage.getStorageDirectory(context, Constants.FILENAME_SAVEGAME_DIRECTORY).listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File f, String filename) {
|
||||
Matcher m = savegameFilenamePattern.matcher(filename);
|
||||
if (m != null && m.matches()) {
|
||||
result.add(Integer.parseInt(m.group(1)));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
Collections.sort(result);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
return new ArrayList<Integer>();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class CheatDetection {
|
||||
public final int fileversion;
|
||||
public final long savedVersion;
|
||||
|
||||
// ====== PARCELABLE ===================================================================
|
||||
|
||||
public CheatDetection(DataInputStream src) throws IOException {
|
||||
this.fileversion = src.readInt();
|
||||
this.savedVersion = src.readLong();
|
||||
}
|
||||
|
||||
public static void writeToParcel(DataOutputStream dest, long savedVersion) throws IOException {
|
||||
dest.writeInt(AndorsTrailApplication.CURRENT_VERSION);
|
||||
dest.writeLong(savedVersion);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final class FileHeader {
|
||||
public final int fileversion;
|
||||
public final String playerName;
|
||||
public final String displayInfo;
|
||||
public final int iconID;
|
||||
public final boolean isAlteredSavegame;
|
||||
public boolean skipIcon = false;
|
||||
public final boolean isDead;
|
||||
public final boolean hasUnlimitedSaves;
|
||||
public final String playerId;
|
||||
public final long savedVersion;
|
||||
|
||||
public String describe() {
|
||||
return (fileversion == AndorsTrailApplication.DEVELOPMENT_INCOMPATIBLE_SAVEGAME_VERSION ? "(D) " : "") + playerName + ", " + displayInfo;
|
||||
}
|
||||
|
||||
|
||||
// ====== PARCELABLE ===================================================================
|
||||
|
||||
public FileHeader(DataInputStream src, boolean skipIcon) throws IOException {
|
||||
int fileversion = src.readInt();
|
||||
if (fileversion == 11)
|
||||
fileversion = 5; // Fileversion 5 had no version identifier, but the first byte was 11.
|
||||
this.fileversion = fileversion;
|
||||
if (fileversion >= 14) { // Before fileversion 14 (0.6.7), we had no file header.
|
||||
this.playerName = src.readUTF();
|
||||
this.displayInfo = src.readUTF();
|
||||
} else {
|
||||
this.playerName = null;
|
||||
this.displayInfo = null;
|
||||
}
|
||||
|
||||
if (fileversion >= 43) {
|
||||
int id = src.readInt();
|
||||
if (skipIcon || id > TileManager.LAST_HERO) {
|
||||
this.iconID = TileManager.CHAR_HERO_0;
|
||||
this.skipIcon = true;
|
||||
} else {
|
||||
this.iconID = id;
|
||||
}
|
||||
} else {
|
||||
this.iconID = TileManager.CHAR_HERO_0;
|
||||
}
|
||||
|
||||
if (fileversion >= 49) {
|
||||
this.isDead = src.readBoolean();
|
||||
this.hasUnlimitedSaves = src.readBoolean();
|
||||
this.playerId = src.readUTF();
|
||||
this.savedVersion = src.readLong();
|
||||
} else {
|
||||
this.isDead = false;
|
||||
this.hasUnlimitedSaves = true;
|
||||
this.playerId = "";
|
||||
this.savedVersion = 0;
|
||||
}
|
||||
if(fileversion >= 81){
|
||||
this.isAlteredSavegame = src.readBoolean();
|
||||
}else{
|
||||
this.isAlteredSavegame = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeToParcel(DataOutputStream dest, String playerName, String displayInfo, int iconID, boolean isDead, boolean hasUnlimitedSaves, String playerId, long savedVersion, boolean isAlteredSavegame) throws IOException {
|
||||
dest.writeInt(AndorsTrailApplication.CURRENT_VERSION);
|
||||
dest.writeUTF(playerName);
|
||||
dest.writeUTF(displayInfo);
|
||||
dest.writeInt(iconID);
|
||||
dest.writeBoolean(isDead);
|
||||
dest.writeBoolean(hasUnlimitedSaves);
|
||||
dest.writeUTF(playerId);
|
||||
dest.writeLong(savedVersion);
|
||||
dest.writeBoolean(isAlteredSavegame);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,472 +0,0 @@
|
||||
package com.gpl.rpg.AndorsTrail.util;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.documentfile.provider.DocumentFile;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.R;
|
||||
import com.gpl.rpg.AndorsTrail.controller.Constants;
|
||||
import com.gpl.rpg.AndorsTrail.util.BackgroundWorker.BackgroundWorkerCallback;
|
||||
import com.gpl.rpg.AndorsTrail.view.CustomDialogFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
public final class AndroidStorage {
|
||||
public static File getStorageDirectory(Context context, String name) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
return context.getExternalFilesDir(name);
|
||||
} else {
|
||||
File root = Environment.getExternalStorageDirectory();
|
||||
return new File(root, name);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean shouldMigrateToInternalStorage(Context context) {
|
||||
boolean ret = false;
|
||||
File externalSaveGameDirectory = new File(Environment.getExternalStorageDirectory(),
|
||||
Constants.FILENAME_SAVEGAME_DIRECTORY);
|
||||
File internalSaveGameDirectory = getStorageDirectory(context, Constants.FILENAME_SAVEGAME_DIRECTORY);
|
||||
|
||||
if (externalSaveGameDirectory.exists()
|
||||
&& externalSaveGameDirectory.isDirectory()
|
||||
&& externalSaveGameDirectory.listFiles().length > 0
|
||||
&& (!internalSaveGameDirectory.exists()
|
||||
|| internalSaveGameDirectory.isDirectory()
|
||||
&& internalSaveGameDirectory.listFiles().length < 2)) {
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static boolean migrateToInternalStorage(Context context) {
|
||||
try {
|
||||
copy(new File(Environment.getExternalStorageDirectory(), Constants.CHEAT_DETECTION_FOLDER),
|
||||
getStorageDirectory(context, Constants.CHEAT_DETECTION_FOLDER));
|
||||
copy(new File(Environment.getExternalStorageDirectory(), Constants.FILENAME_SAVEGAME_DIRECTORY),
|
||||
getStorageDirectory(context, Constants.FILENAME_SAVEGAME_DIRECTORY));
|
||||
} catch (IOException e) {
|
||||
L.log("Error migrating data: " + e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void copy(File sourceLocation, File targetLocation) throws IOException {
|
||||
if (!sourceLocation.exists()) {
|
||||
return;
|
||||
}
|
||||
if (sourceLocation.isDirectory()) {
|
||||
copyDirectory(sourceLocation, targetLocation);
|
||||
} else {
|
||||
copyFile(sourceLocation, targetLocation);
|
||||
}
|
||||
}
|
||||
|
||||
private static void copyDirectory(File source, File target) throws IOException {
|
||||
if (!target.exists()) {
|
||||
target.mkdir();
|
||||
}
|
||||
|
||||
for (String f : source.list()) {
|
||||
copy(new File(source, f), new File(target, f));
|
||||
}
|
||||
}
|
||||
|
||||
public static void copyFile(File source, File target) throws IOException {
|
||||
try (InputStream in = new FileInputStream(source); OutputStream out = new FileOutputStream(target)) {
|
||||
copyStream(in, out);
|
||||
}
|
||||
}
|
||||
|
||||
public static void copyStream(InputStream in, OutputStream out) throws IOException {
|
||||
byte[] buf = new byte[1024];
|
||||
int length;
|
||||
while ((length = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, length);
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
public static void createZipDocumentFileFromFilesAsync(File[] files,
|
||||
Context context,
|
||||
DocumentFile targetDirectory,
|
||||
String fileName,
|
||||
String loadingMessage,
|
||||
Consumer<Boolean> callback) {
|
||||
|
||||
BackgroundWorker<Boolean> worker = new BackgroundWorker<>();
|
||||
CustomDialogFactory.CustomDialog progressDialog = getLoadingDialog(context, loadingMessage);
|
||||
progressDialog.setOnCancelListener(dialog -> worker.cancel());
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
Handler handler = Handler.createAsync(Looper.getMainLooper());
|
||||
|
||||
|
||||
worker.setTask(workerCallback -> {
|
||||
try {
|
||||
workerCallback.onInitialize();
|
||||
|
||||
//region create zip file
|
||||
File zip = File.createTempFile("temp_worldmap", ".zip");
|
||||
try (OutputStream out = new FileOutputStream(zip)) {
|
||||
ZipOutputStream zipOut = new ZipOutputStream(out);
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
File file = files[i];
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
workerCallback.onProgress((float) i / files.length);
|
||||
zipOut.putNextEntry(new ZipEntry(file.getName()));
|
||||
copyStream(fis, zipOut);
|
||||
zipOut.closeEntry();
|
||||
}
|
||||
}
|
||||
zipOut.close();
|
||||
}
|
||||
//endregion
|
||||
|
||||
DocumentFile worldmapZip = DocumentFile.fromFile(zip);
|
||||
DocumentFile worldmapTarget = targetDirectory.createFile("application/zip", fileName);
|
||||
if (worldmapTarget != null && worldmapTarget.exists()) {
|
||||
AndroidStorage.copyDocumentFile(worldmapZip, resolver, worldmapTarget);
|
||||
workerCallback.onComplete(true);
|
||||
} else {
|
||||
throw new FileNotFoundException("Could not create File");
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
if (worker.isCancelled()) {
|
||||
workerCallback.onFailure(new CancellationException("Cancelled"));
|
||||
} else {
|
||||
workerCallback.onFailure(e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
workerCallback.onFailure(e);
|
||||
}
|
||||
});
|
||||
|
||||
worker.setCallback(getDefaultBackgroundWorkerCallback(handler, progressDialog, callback));
|
||||
worker.run();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void unzipToDirectory(File zipFile,
|
||||
File targetDirectory,
|
||||
boolean overwriteNotSkip) throws IOException {
|
||||
|
||||
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile))) {
|
||||
unzipStreamToDirectory(targetDirectory, overwriteNotSkip, zis);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
public static void unzipDocumentFileToDirectoryAsync(DocumentFile zipFile,
|
||||
Context context,
|
||||
File targetDirectory,
|
||||
boolean overwriteNotSkip,
|
||||
String loadingMessage,
|
||||
Consumer<Boolean> callback) {
|
||||
|
||||
BackgroundWorker<Boolean> worker = new BackgroundWorker<>();
|
||||
CustomDialogFactory.CustomDialog progressDialog = getLoadingDialog(context, loadingMessage);
|
||||
progressDialog.setOnCancelListener(dialog -> worker.cancel());
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
Handler handler = Handler.createAsync(Looper.getMainLooper());
|
||||
|
||||
worker.setTask(workerCallback -> {
|
||||
try {
|
||||
workerCallback.onInitialize();
|
||||
workerCallback.onProgress(-1);//set dummy progress since we don't know the
|
||||
// progress of the unzip
|
||||
unzipDocumentFileToDirectory(zipFile, resolver, targetDirectory, overwriteNotSkip);
|
||||
workerCallback.onComplete(true);
|
||||
} catch (IOException e) {
|
||||
workerCallback.onFailure(e);
|
||||
}
|
||||
});
|
||||
|
||||
worker.setCallback(getDefaultBackgroundWorkerCallback(handler, progressDialog, callback));
|
||||
worker.run();
|
||||
|
||||
}
|
||||
|
||||
public static void unzipDocumentFileToDirectory(DocumentFile zipFile,
|
||||
ContentResolver resolver,
|
||||
File targetDirectory,
|
||||
boolean overwriteNotSkip) throws IOException {
|
||||
try (ZipInputStream zis = new ZipInputStream(resolver.openInputStream(zipFile.getUri()))) {
|
||||
unzipStreamToDirectory(targetDirectory, overwriteNotSkip, zis);
|
||||
}
|
||||
}
|
||||
|
||||
private static void unzipStreamToDirectory(File targetDirectory,
|
||||
boolean overwriteNotSkip,
|
||||
ZipInputStream zis) throws IOException {
|
||||
ZipEntry entry;
|
||||
while ((entry = zis.getNextEntry()) != null) {
|
||||
File file = new File(targetDirectory, entry.getName());
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
file.mkdirs();
|
||||
} else {
|
||||
file.getParentFile().mkdirs();
|
||||
if (file.exists() && !overwriteNotSkip) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
copyStream(zis, fos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void copyDocumentFileToNewOrExistingFile(DocumentFile sourceFile,
|
||||
ContentResolver resolver,
|
||||
DocumentFile targetFolder) throws IOException {
|
||||
copyDocumentFileToNewOrExistingFile(sourceFile,
|
||||
resolver,
|
||||
targetFolder,
|
||||
Constants.NO_FILE_EXTENSION_MIME_TYPE);
|
||||
}
|
||||
|
||||
|
||||
public static void copyDocumentFileToNewOrExistingFile(DocumentFile sourceFile,
|
||||
ContentResolver resolver,
|
||||
DocumentFile targetFolder,
|
||||
String mimeType) throws IOException {
|
||||
String fileName = sourceFile.getName();
|
||||
DocumentFile file = targetFolder.findFile(fileName);
|
||||
if (file == null) {
|
||||
file = targetFolder.createFile(mimeType, fileName);
|
||||
}
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AndroidStorage.copyDocumentFile(sourceFile, resolver, file);
|
||||
}
|
||||
|
||||
public static void copyDocumentFile(DocumentFile sourceFile,
|
||||
ContentResolver resolver,
|
||||
DocumentFile targetFile) throws IOException {
|
||||
try (OutputStream outputStream = resolver.openOutputStream(targetFile.getUri());
|
||||
InputStream inputStream = resolver.openInputStream(sourceFile.getUri())) {
|
||||
copyStream(inputStream, outputStream);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getUrlForFile(Context context, File worldmap) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
String applicationId = context.getPackageName();
|
||||
Uri uri = FileProvider.getUriForFile(context, applicationId + ".fileprovider", worldmap);
|
||||
return uri.toString();
|
||||
} else {
|
||||
return "file://" + worldmap.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public static Intent getNewOpenDirectoryIntent() {
|
||||
return new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public static Intent getNewSelectMultipleSavegameFilesIntent() {
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
|
||||
intent.setType(Constants.SAVEGAME_FILE_MIME_TYPE);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public static Intent getNewSelectZipIntent() {
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("application/zip");
|
||||
return intent;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
public static void copyDocumentFilesFromToAsync(DocumentFile[] sources,
|
||||
Context context,
|
||||
DocumentFile[] targets,
|
||||
String loadingMessage,
|
||||
Consumer<Boolean> callback) {
|
||||
if (sources.length != targets.length) {
|
||||
throw new IllegalArgumentException("Both arrays, target & source have to have the same size");
|
||||
}
|
||||
|
||||
BackgroundWorker<Boolean> worker = new BackgroundWorker<>();
|
||||
|
||||
CustomDialogFactory.CustomDialog progressDialog = getLoadingDialog(context, loadingMessage);
|
||||
progressDialog.setOnCancelListener(dialog -> worker.cancel());
|
||||
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
Handler handler = Handler.createAsync(Looper.getMainLooper());
|
||||
|
||||
worker.setTask(workerCallback -> {
|
||||
try {
|
||||
workerCallback.onInitialize();
|
||||
for (int i = 0; i < sources.length; i++) {
|
||||
if (worker.isCancelled()) {
|
||||
workerCallback.onFailure(new CancellationException("Cancelled"));
|
||||
return;
|
||||
}
|
||||
DocumentFile source = sources[i];
|
||||
DocumentFile target = targets[i];
|
||||
|
||||
if (source == null || target == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
copyDocumentFile(source, resolver, target);
|
||||
float progress = i / (float) sources.length;
|
||||
workerCallback.onProgress(progress);
|
||||
}
|
||||
workerCallback.onComplete(true);
|
||||
} catch (NullPointerException e) {
|
||||
if (worker.isCancelled()) {
|
||||
workerCallback.onFailure(new CancellationException("Cancelled"));
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
workerCallback.onFailure(e);
|
||||
}
|
||||
});
|
||||
worker.setCallback(getDefaultBackgroundWorkerCallback(handler, progressDialog, callback));
|
||||
worker.run();
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
public static void copyDocumentFilesToDirAsync(DocumentFile[] files,
|
||||
Context context,
|
||||
DocumentFile targetDirectory,
|
||||
String loadingMessage,
|
||||
Consumer<Boolean> callback) {
|
||||
BackgroundWorker<Boolean> worker = new BackgroundWorker<>();
|
||||
CustomDialogFactory.CustomDialog progressDialog = getLoadingDialog(context, loadingMessage);
|
||||
progressDialog.setOnCancelListener(dialog -> worker.cancel());
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
Handler handler = Handler.createAsync(Looper.getMainLooper());
|
||||
|
||||
worker.setTask(workerCallback -> {
|
||||
try {
|
||||
workerCallback.onInitialize();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (worker.isCancelled()) {
|
||||
workerCallback.onFailure(new CancellationException("Cancelled"));
|
||||
return;
|
||||
}
|
||||
DocumentFile file = files[i];
|
||||
if (file == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
copyDocumentFileToNewOrExistingFile(file, resolver, targetDirectory);
|
||||
float progress = i / (float) files.length;
|
||||
workerCallback.onProgress(progress);
|
||||
}
|
||||
workerCallback.onComplete(true);
|
||||
} catch (NullPointerException e) {
|
||||
if (worker.isCancelled()) {
|
||||
workerCallback.onFailure(new CancellationException("Cancelled"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
workerCallback.onFailure(e);
|
||||
}
|
||||
});
|
||||
worker.setCallback(getDefaultBackgroundWorkerCallback(handler, progressDialog, callback));
|
||||
worker.run();
|
||||
}
|
||||
|
||||
private static BackgroundWorkerCallback<Boolean> getDefaultBackgroundWorkerCallback(Handler handler,
|
||||
CustomDialogFactory.CustomDialog progressDialog,
|
||||
Consumer<Boolean> callback) {
|
||||
return new BackgroundWorkerCallback<Boolean>() {
|
||||
private int progress = -1;
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
handler.post(() -> {
|
||||
CustomDialogFactory.show(progressDialog);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(float progress) {
|
||||
handler.post(() -> {
|
||||
int intProgress = (int) (progress * 100);
|
||||
if (this.progress == intProgress) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.progress = intProgress;
|
||||
|
||||
if (progress == -1) {
|
||||
CustomDialogFactory.setDesc(progressDialog, null);
|
||||
return;
|
||||
}
|
||||
|
||||
CustomDialogFactory.setDesc(progressDialog, intProgress + "%");
|
||||
});
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
this.onComplete(false);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
@Override
|
||||
public void onComplete(Boolean result) {
|
||||
handler.post(() -> {
|
||||
progressDialog.dismiss();
|
||||
callback.accept(result);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static CustomDialogFactory.CustomDialog getLoadingDialog(Context context) {
|
||||
return getLoadingDialog(context, null);
|
||||
}
|
||||
|
||||
private static CustomDialogFactory.CustomDialog getLoadingDialog(Context context, String message) {
|
||||
if (message == null) {
|
||||
message = context.getResources().getString(R.string.dialog_loading_message);
|
||||
}
|
||||
|
||||
CustomDialogFactory.CustomDialog dialog = CustomDialogFactory.createDialog(context,
|
||||
message,
|
||||
context.getResources()
|
||||
.getDrawable(R.drawable.loading_anim),
|
||||
null,
|
||||
null,
|
||||
true,
|
||||
false);
|
||||
CustomDialogFactory.addCancelButton(dialog, android.R.string.no);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.gpl.rpg.AndorsTrail.util;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public final class BackgroundWorker<T> {
|
||||
boolean cancelled = false;
|
||||
worker<T> task;
|
||||
BackgroundWorkerCallback<T> callback;
|
||||
|
||||
public void setTask(worker<T> task) {
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
public void setCallback(BackgroundWorkerCallback<T> callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
interface worker<T> {
|
||||
void doWork(BackgroundWorkerCallback<T> callback);
|
||||
}
|
||||
|
||||
interface BackgroundWorkerCallback<T> {
|
||||
void onInitialize();
|
||||
|
||||
default void onProgress(float progress) {
|
||||
}
|
||||
|
||||
void onFailure(Exception e);
|
||||
|
||||
void onComplete(T result);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Executors.newSingleThreadExecutor().execute(() -> {
|
||||
task.doWork(callback);
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.gpl.rpg.AndorsTrail.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public final class HashMapHelper {
|
||||
public static <K,V> V getOrDefault(HashMap<K,V> map, K key, V defaultValue) {
|
||||
V v = map.get(key);
|
||||
return v == null ? defaultValue : v;
|
||||
}
|
||||
public static <K> Integer sumIntegerValues(HashMap<K,Integer> map) {
|
||||
int sum = 0;
|
||||
for (Integer v : map.values()) sum += v;
|
||||
return sum;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.gpl.rpg.AndorsTrail.controller;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.model.actor.Actor;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class CombatControllerTest {
|
||||
@Test
|
||||
public void getAverageDamagePerHit() throws Exception {
|
||||
Actor attacker = new Actor(null, false, false);
|
||||
attacker.attackChance = 100;
|
||||
attacker.damagePotential.set(5, 3);
|
||||
|
||||
Actor target = new Actor(null, false, false);
|
||||
target.damageResistance = 3;
|
||||
target.blockChance = 50;
|
||||
|
||||
float averageDamagePerHit = CombatController.getAverageDamagePerHit(attacker, target);
|
||||
assertEquals(0.5, averageDamagePerHit, 0.01);
|
||||
|
||||
attacker.criticalSkill = 30;
|
||||
attacker.criticalMultiplier = 2.5f;
|
||||
|
||||
averageDamagePerHit = CombatController.getAverageDamagePerHit(attacker, target);
|
||||
assertEquals(1.038, averageDamagePerHit, 0.01);
|
||||
}
|
||||
|
||||
}
|
||||
1
AndorsTrail/assets/translation/.gitignore
vendored
1
AndorsTrail/assets/translation/.gitignore
vendored
@@ -0,0 +1 @@
|
||||
*.mo
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
0
AndorsTrail/assets/translation/createMo.sh
Normal file → Executable file
0
AndorsTrail/assets/translation/createMo.sh
Normal file → Executable file
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
51994
AndorsTrail/assets/translation/fi.po
Normal file → Executable file
51994
AndorsTrail/assets/translation/fi.po
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
51548
AndorsTrail/assets/translation/gl.po
Normal file → Executable file
51548
AndorsTrail/assets/translation/gl.po
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user