mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 12:34:05 +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 {
|
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() {
|
fun playHapticCursorHovered() {
|
||||||
App.playGUIsound(CommonResourcePool.getAs("sound:haptic_bap"), 0.25)
|
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 com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.ui.UIItemAccessibilityUtil.playHapticCursorHovered
|
import net.torvald.terrarum.ui.UIItemAccessibilityUtil.playHapticCursorHovered
|
||||||
|
import net.torvald.terrarum.ui.UIItemAccessibilityUtil.playHapticNudge
|
||||||
import net.torvald.terrarum.ui.UIItemAccessibilityUtil.playHapticPushedDown
|
import net.torvald.terrarum.ui.UIItemAccessibilityUtil.playHapticPushedDown
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
import kotlin.math.roundToInt
|
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 mouseLatched = false // trust me this one needs its own binary latch
|
||||||
|
|
||||||
|
private var oldValue = initialValue
|
||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
super.update(delta)
|
super.update(delta)
|
||||||
|
|
||||||
@@ -54,16 +57,22 @@ class UIItemHorzSlider(
|
|||||||
|
|
||||||
// update handle position and value
|
// update handle position and value
|
||||||
if (mouseUp && Terrarum.mouseDown || mouseLatched) {
|
if (mouseUp && Terrarum.mouseDown || mouseLatched) {
|
||||||
if (!mouseLatched) playHapticPushedDown()
|
|
||||||
mouseLatched = true
|
mouseLatched = true
|
||||||
handlePos = (itemRelativeMouseX - handleWidth/2.0).coerceIn(0.0, handleTravelDist.toDouble())
|
handlePos = (itemRelativeMouseX - handleWidth/2.0).coerceIn(0.0, handleTravelDist.toDouble())
|
||||||
value = interpolateLinear(handlePos / handleTravelDist, min, max)
|
value = interpolateLinear(handlePos / handleTravelDist, min, max)
|
||||||
selectionChangeListener(value)
|
selectionChangeListener(value)
|
||||||
|
if (oldValue != value && (value == min || value == max)) {
|
||||||
|
playHapticNudge()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Terrarum.mouseDown) {
|
if (!Terrarum.mouseDown) {
|
||||||
mouseLatched = false
|
mouseLatched = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suppressHaptic = mouseLatched
|
||||||
|
|
||||||
|
oldValue = value
|
||||||
}
|
}
|
||||||
|
|
||||||
val troughBorderCol: Color; get() = if (mouseUp || mouseLatched) Toolkit.Theme.COL_MOUSE_UP else Toolkit.Theme.COL_INACTIVE
|
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.OrthographicCamera
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.terrarum.*
|
|
||||||
import net.torvald.terrarum.App.printdbg
|
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 net.torvald.terrarum.ui.UIItemAccessibilityUtil.playHapticPushedDown
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
@@ -41,9 +45,7 @@ class UIItemVertSlider(
|
|||||||
|
|
||||||
private var mouseLatched = false // trust me this one needs its own binary latch
|
private var mouseLatched = false // trust me this one needs its own binary latch
|
||||||
|
|
||||||
init {
|
private var oldValue = initialValue
|
||||||
printdbg(this, "slider max=$max")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
super.update(delta)
|
super.update(delta)
|
||||||
@@ -52,16 +54,22 @@ class UIItemVertSlider(
|
|||||||
|
|
||||||
// update handle position and value
|
// update handle position and value
|
||||||
if (mouseUp && Terrarum.mouseDown || mouseLatched) {
|
if (mouseUp && Terrarum.mouseDown || mouseLatched) {
|
||||||
if (!mouseLatched) playHapticPushedDown()
|
|
||||||
mouseLatched = true
|
mouseLatched = true
|
||||||
handlePos = (itemRelativeMouseY - handleHeight/2.0).coerceIn(0.0, handleTravelDist.toDouble())
|
handlePos = (itemRelativeMouseY - handleHeight/2.0).coerceIn(0.0, handleTravelDist.toDouble())
|
||||||
value = interpolateLinear(handlePos / handleTravelDist, min, max)
|
value = interpolateLinear(handlePos / handleTravelDist, min, max)
|
||||||
selectionChangeListener(value)
|
selectionChangeListener(value)
|
||||||
|
if (oldValue != value && (value == min || value == max)) {
|
||||||
|
playHapticNudge()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Terrarum.mouseDown) {
|
if (!Terrarum.mouseDown) {
|
||||||
mouseLatched = false
|
mouseLatched = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suppressHaptic = mouseLatched
|
||||||
|
|
||||||
|
oldValue = value
|
||||||
}
|
}
|
||||||
|
|
||||||
val troughBorderCol: Color; get() = if (mouseUp || mouseLatched) Toolkit.Theme.COL_MOUSE_UP else Toolkit.Theme.COL_INACTIVE
|
val troughBorderCol: Color; get() = if (mouseUp || mouseLatched) Toolkit.Theme.COL_MOUSE_UP else Toolkit.Theme.COL_INACTIVE
|
||||||
|
|||||||
Reference in New Issue
Block a user