Commit ff19ebf9 authored by deregges's avatar deregges

Fixed last player name not being re-added into EndGameDialog

parent 93307628
......@@ -10,7 +10,6 @@ import io.ender.pathchaser.menu.Highscores
import io.ender.pathchaser.util.Preferences
import io.ender.pathchaser.util.startActivity
import kotlinx.android.synthetic.main.end_game_dialog.*
import splitties.resources.appStr
import splitties.views.design.string
import splitties.views.design.text
......@@ -20,7 +19,7 @@ class EndGameDialog private constructor(a: Activity, private val score: Int) : D
requestWindowFeature(Window.FEATURE_NO_TITLE)
setContentView(R.layout.end_game_dialog)
endGameName.text = Preferences.lastName
endGameName.text = Preferences.lastName.orEmpty()
endGameScore.text = score.toString()
val highscorePosition = Highscores.getPositionForScore(Preferences.difficulty, score)
......@@ -51,15 +50,16 @@ class EndGameDialog private constructor(a: Activity, private val score: Int) : D
writeHighscore()
ownerActivity?.finish()
}
endGameDialog.requestFocus()
}
private fun writeHighscore() {
if (Highscores.getPositionForScore(Preferences.difficulty, score) != null) Highscores.addHighScore(
Highscores.HighScore(
Preferences.difficulty,
score,
endGameName.string.ifBlank { appStr(R.string.anonymousUser) })
)
val highScore = Highscores.HighScore(Preferences.difficulty, score, endGameName.string)
Preferences.lastName = highScore.name
if (Highscores.getPositionForScore(Preferences.difficulty, score) != null) {
Highscores.addHighScore(highScore)
}
}
companion object {
......
......@@ -14,6 +14,7 @@ import io.ender.pathchaser.util.*
import kotlinx.android.synthetic.main.highscores.*
import kotlinx.android.synthetic.main.highscores_entry.view.*
import splitties.init.appCtx
import splitties.resources.appStr
import java.io.File
class Highscores : AppCompatActivity() {
......@@ -100,7 +101,9 @@ class Highscores : AppCompatActivity() {
if (difficulty == null) scores.entries.sumBy { it.value.size } else (scores.getValue(difficulty)).size
}
data class HighScore(val cat: Constants.Difficulty, val score: Int, val name: String) {
class HighScore(val cat: Constants.Difficulty, val score: Int, name: String?) {
val name = if (name.isNullOrBlank()) null else name
constructor(s: String) : this(
Constants.Difficulty.values()[s[0].toString().toInt()],
s.substring(2).substringBefore(':').toInt(),
......@@ -108,5 +111,7 @@ class Highscores : AppCompatActivity() {
)
override fun toString(): String = "${cat.ordinal}:$score:$name"
fun getDisplayName() = name ?: appStr(R.string.anonymousUser)
}
}
\ No newline at end of file
......@@ -10,7 +10,7 @@ object Preferences : DefaultPreferences() {
difficulty0 = value.ordinal
}
var volume by floatPref(50f)
var lastName by stringPref("")
var lastName by stringOrNullPref()
private var inputMethod0 by intPref(Constants.InputMethod.TOUCH.ordinal)
var inputMethod: Constants.InputMethod
get() = Constants.InputMethod.values().getOrElse(inputMethod0) { Constants.InputMethod.TOUCH }
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/endGameDialog"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
......@@ -72,6 +75,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ems="10"
android:selectAllOnFocus="true"
android:hint="@string/endGameName"
android:inputType="text"/>
</com.google.android.material.textfield.TextInputLayout>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment