Commit 58ed076c authored by deregges's avatar deregges

Generalized enums in Preferences

Added slider for rotation sensitivity
Fixed volume slider removal, now also removing title, now in xml
parent 7d8b08bf
......@@ -12,6 +12,7 @@ import android.view.MotionEvent
import android.view.SurfaceView
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import io.ender.pathchaser.menu.Settings
import io.ender.pathchaser.paths.PathManager
import io.ender.pathchaser.util.Constants
import io.ender.pathchaser.util.Preferences
......@@ -20,6 +21,7 @@ import splitties.systemservices.sensorManager
import kotlin.math.PI
class GameActivity : AppCompatActivity(), SensorEventListener {
private val rotationSensitivity = Settings.calcRotationSensitivity()
var ticks = 0
private set
var collectedCoins = 0
......@@ -85,11 +87,11 @@ class GameActivity : AppCompatActivity(), SensorEventListener {
orientation[2] *= 2 / PI.toFloat()
when (Preferences.inputMethod) {
Constants.InputMethod.ROTATION -> {
player.delta.x = orientation[2] * 50
player.delta.y = -orientation[1] * 50
player.delta.x = orientation[2] * rotationSensitivity
player.delta.y = -orientation[1] * rotationSensitivity
}
Constants.InputMethod.ROTATION2D -> {
player.delta.x = orientation[2] * 50
player.delta.x = orientation[2] * rotationSensitivity
}
Constants.InputMethod.TOUCH -> Unit
}
......
......@@ -17,6 +17,7 @@ import kotlinx.android.synthetic.main.settings.*
import splitties.toast.longToast
import splitties.views.textResource
import kotlin.math.max
import kotlin.math.pow
class Settings : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
......@@ -72,20 +73,6 @@ class Settings : AppCompatActivity() {
}
}
volume.visibility = View.GONE //TODO add music
btnClearHighscores.setOnClickListener {
AlertDialog.Builder(this)
.setTitle(R.string.settings_btnClearHighscoresDialogTitle)
.setMessage(R.string.settings_btnClearHighscoresDialogMessage)
.setPositiveButton(android.R.string.yes) { _, _ ->
Highscores.clearScores()
longToast(R.string.settings_highscoresCleared)
}
.setNegativeButton(android.R.string.no) { _, _ -> }
.create().show()
}
inputMethod.adapter = object : ArrayAdapter<Constants.InputMethod>(
this,
android.R.layout.simple_list_item_1,
......@@ -111,6 +98,49 @@ class Settings : AppCompatActivity() {
}
inputMethod.setSelection(max(Constants.InputMethod.validValues().indexOf(Preferences.inputMethod), 0))
rotationSensitivity.configBuilder
.min(0f)
.max(1f)
.sectionCount(2 * Constants.rotationSensitivityRadius)
.progress(Preferences.rotationSensitivity)
.touchToSeek()
.sectionTextPosition(BubbleSeekBar.TextPosition.BELOW_SECTION_MARK)
.showProgressInFloat()
.showSectionMark()
.showSectionText()
.hideBubble()
.build()
rotationSensitivity.setCustomSectionTextArray { _, array ->
array.clear()
for (i in -Constants.rotationSensitivityRadius..Constants.rotationSensitivityRadius) array.put(
i + Constants.rotationSensitivityRadius,
2f.pow(i).toString()
)
array
}
rotationSensitivity.onProgressChangedListener = object : BubbleSeekBar.OnProgressChangedListenerAdapter() {
override fun getProgressOnActionUp(bubbleSeekBar: BubbleSeekBar?, progress: Int, progressFloat: Float) {
Preferences.rotationSensitivity = progressFloat
}
}
btnClearHighscores.setOnClickListener {
AlertDialog.Builder(this)
.setTitle(R.string.settings_btnClearHighscoresDialogTitle)
.setMessage(R.string.settings_btnClearHighscoresDialogMessage)
.setPositiveButton(android.R.string.yes) { _, _ ->
Highscores.clearScores()
longToast(R.string.settings_highscoresCleared)
}
.setNegativeButton(android.R.string.no) { _, _ -> }
.create().show()
}
Utils.animateView(window.decorView, 0, 0.3f, 0.8f, 20_000)
}
companion object {
fun calcRotationSensitivity(): Float =
2f.pow(2 * Constants.rotationSensitivityRadius * Preferences.rotationSensitivity - Constants.rotationSensitivityRadius) * 50
}
}
\ No newline at end of file
......@@ -19,6 +19,7 @@ object Constants {
const val blinkColor = Color.RED
const val maxTrackedHighscoreCount = 30
val playerOffset: PointF = PointF(0f, -40f)
const val rotationSensitivityRadius: Int = 2
object ExtensionPercentages {
const val arc = 0.25
......
package io.ender.pathchaser.util
import splitties.preferences.DefaultPreferences
import splitties.preferences.Preferences
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
object Preferences : DefaultPreferences() {
private var difficulty0 by intPref(Constants.Difficulty.NORMAL.ordinal)
var difficulty: Constants.Difficulty
get() = Constants.Difficulty.values().getOrElse(difficulty0) { Constants.Difficulty.NORMAL }
set(value) {
difficulty0 = value.ordinal
}
var difficulty by enumPref(Constants.Difficulty.NORMAL)
var volume by floatPref(50f)
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 }
set(value) {
inputMethod0 = value.ordinal
var inputMethod by enumPref(Constants.InputMethod.TOUCH)
var rotationSensitivity by floatPref(1f)
private fun <E : Enum<E>> enumPref(default: E) = object : ReadWriteProperty<Preferences, E> {
private val internal = intPref(default.ordinal)
override fun getValue(thisRef: Preferences, property: KProperty<*>): E {
return default.declaringClass.enumConstants[internal.getValue(thisRef, property)]
}
override fun setValue(thisRef: Preferences, property: KProperty<*>, value: E) {
internal.setValue(thisRef, property, value.ordinal)
}
}
}
\ No newline at end of file
......@@ -18,7 +18,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!-- TODO add music -->
<TextView
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
......@@ -26,7 +28,9 @@
android:text="@string/settings_titleVolume"
android:textSize="25sp"/>
<!-- TODO add music -->
<com.xw.repo.BubbleSeekBar
android:visibility="gone"
android:id="@+id/volume"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
......@@ -44,6 +48,19 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center"
android:text="@string/settings_titleSensitivity"
android:textSize="25sp"/>
<com.xw.repo.BubbleSeekBar
android:id="@+id/rotationSensitivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/btnClearHighscores"
android:layout_width="match_parent"
......
......@@ -31,4 +31,5 @@
<string name="version">Version: %s</string>
<string name="settings_btnClearHighscoresDialogTitle">Highscores entfernen</string>
<string name="settings_btnClearHighscoresDialogMessage">Damit werden alle highscores gelöscht. Fortfahren?</string>
<string name="settings_titleSensitivity">Neigungsempfindlichkeit</string>
</resources>
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