mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
more haptic for sliders
This commit is contained in:
@@ -284,7 +284,9 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
||||
}
|
||||
|
||||
object UIItemAccessibilityUtil {
|
||||
// TODO have multiple bop instances (num of copies equal to guiTracks), then play the track with its index according to getFreeGuiTrack()
|
||||
fun playHapticNudge() {
|
||||
App.playGUIsound(CommonResourcePool.getAs("sound:haptic_bup"), 0.25)
|
||||
}
|
||||
fun playHapticCursorHovered() {
|
||||
App.playGUIsound(CommonResourcePool.getAs("sound:haptic_bap"), 0.25)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.ui.UIItemAccessibilityUtil.playHapticCursorHovered
|
||||
import net.torvald.terrarum.ui.UIItemAccessibilityUtil.playHapticNudge
|
||||
import net.torvald.terrarum.ui.UIItemAccessibilityUtil.playHapticPushedDown
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlin.math.roundToInt
|
||||
@@ -47,6 +48,8 @@ class UIItemHorzSlider(
|
||||
|
||||
private var mouseLatched = false // trust me this one needs its own binary latch
|
||||
|
||||
private var oldValue = initialValue
|
||||
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
|
||||
@@ -54,16 +57,22 @@ class UIItemHorzSlider(
|
||||
|
||||
// update handle position and value
|
||||
if (mouseUp && Terrarum.mouseDown || mouseLatched) {
|
||||
if (!mouseLatched) playHapticPushedDown()
|
||||
mouseLatched = true
|
||||
handlePos = (itemRelativeMouseX - handleWidth/2.0).coerceIn(0.0, handleTravelDist.toDouble())
|
||||
value = interpolateLinear(handlePos / handleTravelDist, min, max)
|
||||
selectionChangeListener(value)
|
||||
if (oldValue != value && (value == min || value == max)) {
|
||||
playHapticNudge()
|
||||
}
|
||||
}
|
||||
|
||||
if (!Terrarum.mouseDown) {
|
||||
mouseLatched = false
|
||||
}
|
||||
|
||||
suppressHaptic = mouseLatched
|
||||
|
||||
oldValue = value
|
||||
}
|
||||
|
||||
val troughBorderCol: Color; get() = if (mouseUp || mouseLatched) Toolkit.Theme.COL_MOUSE_UP else Toolkit.Theme.COL_INACTIVE
|
||||
|
||||
@@ -4,8 +4,12 @@ import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blendNormalStraightAlpha
|
||||
import net.torvald.terrarum.interpolateLinear
|
||||
import net.torvald.terrarum.tryDispose
|
||||
import net.torvald.terrarum.ui.UIItemAccessibilityUtil.playHapticNudge
|
||||
import net.torvald.terrarum.ui.UIItemAccessibilityUtil.playHapticPushedDown
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@@ -41,9 +45,7 @@ class UIItemVertSlider(
|
||||
|
||||
private var mouseLatched = false // trust me this one needs its own binary latch
|
||||
|
||||
init {
|
||||
printdbg(this, "slider max=$max")
|
||||
}
|
||||
private var oldValue = initialValue
|
||||
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
@@ -52,16 +54,22 @@ class UIItemVertSlider(
|
||||
|
||||
// update handle position and value
|
||||
if (mouseUp && Terrarum.mouseDown || mouseLatched) {
|
||||
if (!mouseLatched) playHapticPushedDown()
|
||||
mouseLatched = true
|
||||
handlePos = (itemRelativeMouseY - handleHeight/2.0).coerceIn(0.0, handleTravelDist.toDouble())
|
||||
value = interpolateLinear(handlePos / handleTravelDist, min, max)
|
||||
selectionChangeListener(value)
|
||||
if (oldValue != value && (value == min || value == max)) {
|
||||
playHapticNudge()
|
||||
}
|
||||
}
|
||||
|
||||
if (!Terrarum.mouseDown) {
|
||||
mouseLatched = false
|
||||
}
|
||||
|
||||
suppressHaptic = mouseLatched
|
||||
|
||||
oldValue = value
|
||||
}
|
||||
|
||||
val troughBorderCol: Color; get() = if (mouseUp || mouseLatched) Toolkit.Theme.COL_MOUSE_UP else Toolkit.Theme.COL_INACTIVE
|
||||
|
||||
Reference in New Issue
Block a user