Skip to content

Commit

Permalink
Reimplement save/load functionality
Browse files Browse the repository at this point in the history
- The previous game save database has been rewritten using Room. The old
database is not migrated, so existing saves may not longer be discoverable.
That's not a huge concern though, as they're so out of date that they won't
be usable with the new CTH engine anyway, and there's no plans to support
them.
- Save games can be deleted by swiping left on either the save or load
views. There is a grace period during which the deletion can be undone.
- Add screenshots and save game locations to the configuration. These are
both stored in the app's file storage, and may be backed up.
- Autosave games appear when loading a game but do not appear when saving,
to prevent them from being overwritten.
- A confirmation is presented when attempting to overwrite an existing
save game.
  • Loading branch information
alanwoolley committed Aug 2, 2023
1 parent 1a4dda1 commit 6093e07
Show file tree
Hide file tree
Showing 26 changed files with 1,048 additions and 114 deletions.
8 changes: 7 additions & 1 deletion AndroidManifest.xml
Expand Up @@ -21,8 +21,8 @@
<activity
android:name="uk.co.armedpineapple.cth.GameActivity"
android:configChanges="layoutDirection|locale|orientation|uiMode|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
android:immersive="true"
android:exported="true"
android:immersive="true"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:preferMinimalPostProcessing="true"
Expand All @@ -45,5 +45,11 @@
android:label="@string/title_activity_settings"
android:theme="@style/Theme.SettingsTheme" />

<activity
android:name="uk.co.armedpineapple.cth.files.SaveActivity"
android:exported="false"
android:theme="@style/Theme.SaveTheme"
android:label="Save"/>

</application>
</manifest>
10 changes: 8 additions & 2 deletions build.gradle
Expand Up @@ -41,8 +41,6 @@ dependencies {
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'pub.devrel:easypermissions:3.0.0'
implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation 'com.j256.ormlite:ormlite-android:5.0'
implementation 'com.j256.ormlite:ormlite-core:5.0'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'commons-io:commons-io:2.12.0'
Expand All @@ -61,6 +59,14 @@ dependencies {
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1'
implementation 'uk.co.armedpineapple.innoextract:service:2.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.15.1'

def room_version = "2.5.2"

implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
kapt "androidx.room:room-compiler:$room_version"
}

android {
Expand Down
18 changes: 18 additions & 0 deletions res/layout/dialog_newsave.xml
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<EditText
android:id="@+id/newSaveName"
android:inputType="text|textCapWords"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:hint="@string/new_save_name" />

</LinearLayout>
13 changes: 13 additions & 0 deletions res/layout/fragment_save_load_list.xml
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/list"
android:name="uk.co.armedpineapple.cth.SaveLoadFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"
tools:context=".files.SaveLoadFragment"
tools:listitem="@layout/save_list_item" />
29 changes: 29 additions & 0 deletions res/layout/new_save_list_item.xml
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/saveLayout"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginVertical="4dp" >

<ImageView
android:id="@+id/imageView2"
android:layout_width="120dp"
android:layout_height="80dp"
android:src="@drawable/baseline_add_24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="Plus Icon" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="@string/new_save"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView2"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
9 changes: 9 additions & 0 deletions res/layout/save_activity.xml
@@ -0,0 +1,9 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/save"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
117 changes: 117 additions & 0 deletions res/layout/save_list_item.xml
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/saveLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="4dp">

<ImageView
android:id="@+id/saveImage"
android:layout_width="90dp"
android:layout_height="60dp"
android:contentDescription="@string/screenshot_contentdesc"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars" />

<TextView
android:id="@+id/saveName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:ellipsize="marquee"
android:maxLines="1"
android:textSize="20sp"
app:layout_constraintEnd_toStartOf="@+id/guideline2"
app:layout_constraintStart_toEndOf="@+id/saveImage"
app:layout_constraintTop_toTopOf="parent"
tools:text="SaveGameName" />

<TextView
android:id="@+id/saveDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:ellipsize="marquee"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@+id/saveName"
app:layout_constraintTop_toBottomOf="@+id/saveName"
tools:text="2022/07/06 11:53PM" />

<ImageView
android:id="@+id/moneyImage"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginStart="8dp"
android:layout_marginBottom="4dp"
android:contentDescription="@string/money_contentdesc"
app:layout_constraintBottom_toTopOf="@+id/guideline3"
app:layout_constraintStart_toStartOf="@+id/guideline2"
app:srcCompat="@drawable/baseline_attach_money_24" />

<TextView
android:id="@+id/money"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:ellipsize="end"
android:maxLines="1"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/moneyImage"
app:layout_constraintStart_toEndOf="@+id/moneyImage"
app:layout_constraintTop_toTopOf="@+id/moneyImage"
tools:text="-1.395m" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.76" />

<ImageView
android:id="@+id/repImage"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginTop="4dp"
android:contentDescription="@string/rep_contentdesc"
app:layout_constraintStart_toStartOf="@+id/moneyImage"
app:layout_constraintTop_toTopOf="@+id/guideline3"
app:srcCompat="@drawable/baseline_thumbs_up_down_24" />

<TextView
android:id="@+id/rep"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:ellipsize="end"
android:maxLines="1"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/repImage"
app:layout_constraintEnd_toEndOf="@+id/money"
app:layout_constraintStart_toEndOf="@+id/repImage"
app:layout_constraintTop_toTopOf="@+id/repImage"
tools:text="154" />

<TextView
android:id="@+id/level"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@+id/saveName"
app:layout_constraintTop_toBottomOf="@+id/saveDate"
tools:text="Level 1" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />

</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 4 additions & 0 deletions res/values/dimens.xml
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_margin">16dp</dimen>
</resources>
1 change: 1 addition & 0 deletions res/values/strings.xml
Expand Up @@ -19,4 +19,5 @@
<string name="cancel">Cancel</string>
<string name="s_deleted">%s deleted</string>
<string name="undo">Undo</string>
<string name="new_save_name">New save name</string>
</resources>
19 changes: 12 additions & 7 deletions res/values/styles.xml
@@ -1,11 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

<style name="Theme.AppTheme" parent="Theme.AppCompat.Light.NoActionBar"></style>
<style name="Theme.AppTheme" parent="Theme.AppCompat.Light.NoActionBar" />

<style name="Theme.SettingsTheme" parent="Theme.AppCompat.Light.Dialog">
<style name="Theme.FloatingTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="windowMinWidthMajor">65%</item>
<item name="windowMinWidthMinor">90%</item>"
<item name="windowMinWidthMinor">90%</item>
</style>

<style name="Theme.SettingsTheme" parent="Theme.FloatingTheme" />

<style name="Theme.SaveTheme" parent="Theme.FloatingTheme">
<item name="windowFixedHeightMinor">90%</item>
<item name="windowFixedHeightMajor">65%</item>
</style>

<color name="background">#000000</color>
Expand All @@ -29,9 +36,9 @@
<item name="android:textSize">22sp</item>
</style>

<style name="FilesFontSmall" parent="@android:style/TextAppearance.Small"></style>
<style name="FilesFontSmall" parent="@android:style/TextAppearance.Small" />

<style name="MenuFont" parent="@android:style/TextAppearance.Medium"></style>
<style name="MenuFont" parent="@android:style/TextAppearance.Medium" />

<style name="HelpFont" parent="@android:style/TextAppearance.Medium">

Expand All @@ -49,6 +56,4 @@
<item name="android:background">@color/black_overlay</item>
<item name="android:buttonBarStyle">?android:attr/buttonBarStyle</item>
</style>


</resources>
16 changes: 15 additions & 1 deletion src/Java/uk/co/armedpineapple/cth/CTHApplication.kt
@@ -1,12 +1,24 @@
package uk.co.armedpineapple.cth

import androidx.preference.PreferenceManager
import androidx.room.Room
import org.jetbrains.anko.defaultSharedPreferences
import uk.co.armedpineapple.cth.files.FilesService
import uk.co.armedpineapple.cth.files.persistence.GameDatabase
import uk.co.armedpineapple.cth.localisation.LanguageService

class CTHApplication : android.app.Application() {

lateinit var configuration: GameConfiguration
val database: GameDatabase by lazy {
Room.databaseBuilder(
this, GameDatabase::class.java, "database"
).build()
}

val filesService: FilesService by lazy {
FilesService(this)
}

override fun onCreate() {
super.onCreate()
Expand All @@ -18,7 +30,9 @@ class CTHApplication : android.app.Application() {
val preferences = defaultSharedPreferences

val service = LanguageService(this)
preferences.edit().putString(this.getString(R.string.prefs_language), service.getCthLanguageFromAppConfig()).apply()
preferences.edit().putString(
this.getString(R.string.prefs_language), service.getCthLanguageFromAppConfig()
).apply()

if (!preferences.getBoolean(
PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, false
Expand Down

0 comments on commit 6093e07

Please sign in to comment.