Skip to content

Commit fa467b1

Browse files
committed
EnumSlider: clicksound played only on drag
1 parent 928f976 commit fa467b1

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/EnumSlider.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ class EnumSlider <T : Enum<T>> (
3535
override fun onPress(e: GuiEvent.MouseClick) {}
3636

3737
override fun onRelease(e: GuiEvent.MouseClick) {
38-
if (dragProgress == -1.0) setting.next()
38+
if (dragProgress == -1.0) {
39+
setting.next()
40+
playClickSound()
41+
}
42+
3943
dragProgress = -1.0
4044
}
4145

common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/Slider.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@ abstract class Slider <V : Any, T : AbstractSetting<V>>(
4747
protected open fun slide(mouse: Vec2d) {
4848
if (activeButton != Mouse.Button.Left) return
4949

50-
val p = transform(mouse.x, rect.left, rect.right, 0.0, 1.0).coerceIn(0.0, 1.0)
51-
setValueByProgress(p)
50+
setValueByProgress(transform(mouse.x, rect.left, rect.right, 0.0, 1.0).coerceIn(0.0, 1.0))
51+
playClickSound()
52+
}
5253

54+
protected fun playClickSound() {
5355
val time = System.currentTimeMillis()
5456
if (lastPlayedValue == value || time - lastPlayedTiming < 50) return
5557

5658
lastPlayedValue = value
5759
lastPlayedTiming = time
5860

59-
playSound(LambdaSound.BUTTON_CLICK.event, lerp(0.9, 1.2, p))
61+
playSound(LambdaSound.BUTTON_CLICK.event, lerp(0.9, 1.2, progress))
6062
}
6163
}

0 commit comments

Comments
 (0)