sound cues for buttons

This commit is contained in:
minjaesong
2024-04-01 03:15:57 +09:00
parent f72ed0f706
commit 576e868996
23 changed files with 193 additions and 41 deletions

View File

@@ -6,6 +6,8 @@ import net.torvald.terrarum.App
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.ceilToInt
import net.torvald.terrarum.ui.UIItemAccessibilityUtil.playHapticCursorHovered
import net.torvald.terrarum.ui.UIItemAccessibilityUtil.playHapticPushedDown
import kotlin.math.absoluteValue
/**
@@ -26,6 +28,8 @@ class UIItemSpinner(
private val numberToTextFunction: (Number) -> String = { "$it" }
) : UIItem(parentUI, initialX, initialY) {
override var suppressHaptic = false
// to alleviate floating point errors adding up as the spinner is being used
private val values = DoubleArray(1 + ((max.toDouble() - min.toDouble()).div(step.toDouble())).ceilToInt()) {
// printdbg(this, "$min..$max step $step; index [$it] = ${min.toDouble() + (step.toDouble() * it)}")
@@ -89,6 +93,8 @@ class UIItemSpinner(
fboUpdateLatch = true
}
private var oldMouseOnButton = 0
override fun update(delta: Float) {
super.update(delta)
@@ -106,7 +112,14 @@ class UIItemSpinner(
changeValueBy((mouseOnButton * 2) - 3)
fboUpdateLatch = true
selectionChangeListener(value)
playHapticPushedDown()
}
if (mouseOnButton > 0 && mouseOnButton != oldMouseOnButton) {
playHapticCursorHovered()
}
oldMouseOnButton = mouseOnButton
}
private var textCache = ""
@@ -199,6 +212,7 @@ class UIItemSpinner(
selectionChangeListener(value)
fboUpdateLatch = true
playHapticPushedDown()
return true
}
else {