Skip to content

Commit 6a8b2bc

Browse files
committed
Slider progress rendering
1 parent 83ce0a6 commit 6a8b2bc

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ModuleButton(val module: Module, owner: ChildLayer.Drawable<*>) : ListButt
2626
override var activeAnimation by animation.exp(0.0, 1.0, 0.15, ::enabled)
2727
private val toggleFxDirection by animation.exp(0.0, 1.0, 0.7, ::enabled)
2828

29-
override val listStep: Double get() = super.listStep * 2.0 + renderHeight
29+
override val listStep: Double get() = super.listStep + renderHeight
3030

3131
private var isOpen = false
3232
override val isActive get() = isOpen
@@ -126,7 +126,7 @@ class ModuleButton(val module: Module, owner: ChildLayer.Drawable<*>) : ListButt
126126
var lastStep = 0.0
127127
settingsLayer.children
128128
.filter(SettingButton<*, *>::visible)
129-
.sumOf { lastStep = it.listStep; it.size.y + it.listStep } - lastStep
129+
.sumOf { lastStep = it.listStep; it.size.y + it.listStep } - lastStep + super.listStep
130130
} else 0.0
131131
}
132132

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package com.lambda.gui.impl.clickgui.buttons.setting
22

33
import com.lambda.config.settings.NumericSetting
4+
import com.lambda.graphics.animation.Animation.Companion.exp
5+
import com.lambda.gui.api.GuiEvent
46
import com.lambda.gui.api.component.core.list.ChildLayer
57
import com.lambda.module.modules.client.ClickGui
68
import com.lambda.util.math.ColorUtils.setAlpha
79
import com.lambda.util.math.MathUtils.lerp
810
import com.lambda.util.math.MathUtils.roundToStep
911
import com.lambda.util.math.MathUtils.typeConvert
1012
import com.lambda.util.math.Vec2d
13+
import com.lambda.util.math.normalize
1114
import java.awt.Color
1215

1316
class NumberSlider <N>(
@@ -16,6 +19,11 @@ class NumberSlider <N>(
1619
) : SliderSetting<N, NumericSetting<N>>(
1720
setting, owner
1821
) where N : Number, N : Comparable<N> {
22+
private val doubleRange get() = setting.range.let { it.start.toDouble()..it.endInclusive.toDouble() }
23+
private val targetProgress get() = doubleRange.normalize(value.toDouble())
24+
private val renderProgress0 by animation.exp(::targetProgress, 0.6)
25+
override val renderProgress get() = lerp(0.0, renderProgress0, showAnimation)
26+
1927
init {
2028
renderer.font {
2129
text = value.let(Number::toString)

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,25 @@ import com.lambda.config.AbstractSetting
44
import com.lambda.gui.api.GuiEvent
55
import com.lambda.gui.api.component.core.list.ChildLayer
66
import com.lambda.gui.impl.clickgui.buttons.SettingButton
7+
import com.lambda.module.modules.client.GuiSettings
8+
import com.lambda.util.math.ColorUtils.multAlpha
9+
import com.lambda.util.math.Vec2d
710
import com.lambda.util.math.transform
811

912
abstract class SliderSetting <V : Any, T : AbstractSetting<V>>(
1013
setting: T, owner: ChildLayer.Drawable<*>
1114
) : SettingButton<V, T>(setting, owner) {
15+
protected abstract val renderProgress: Double
16+
protected abstract fun setValueByProgress(progress: Double)
17+
18+
init {
19+
renderer.filled {
20+
position = rect.moveSecond(Vec2d(-rect.size.x * (1.0 - renderProgress), 0.0)).shrink(interactAnimation)
21+
shade = GuiSettings.shade
22+
color(GuiSettings.mainColor.multAlpha(showAnimation * 0.3))
23+
}
24+
}
25+
1226
override fun onEvent(e: GuiEvent) {
1327
super.onEvent(e)
1428

@@ -17,6 +31,4 @@ abstract class SliderSetting <V : Any, T : AbstractSetting<V>>(
1731
setValueByProgress(p.coerceIn(0.0, 1.0))
1832
}
1933
}
20-
21-
protected abstract fun setValueByProgress(progress: Double)
2234
}

common/src/main/kotlin/com/lambda/module/modules/client/GuiSettings.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ object GuiSettings : Module(
2020
val backgroundColor by setting("Background Color", Color(50, 50, 50), visibility = { page == Page.Colors })
2121
val shade by setting("Shade", true, visibility = { page == Page.Colors })
2222
val shadeBackground by setting("Shade Background", true, visibility = { page == Page.Colors })
23-
val colorWidth by setting("Color Width", 100.0, 1.0..100.0, 1.0, visibility = { page == Page.Colors && shade })
24-
val colorHeight by setting("Color Height", 100.0, 1.0..100.0, 1.0, visibility = { page == Page.Colors && shade })
23+
val colorWidth by setting("Color Width", 400.0, 10.0..1000.0, 10.0, visibility = { page == Page.Colors && shade })
24+
val colorHeight by setting("Color Height", 400.0, 10.0..1000.0, 10.0, visibility = { page == Page.Colors && shade })
2525
val colorSpeed by setting("Color Speed", 1.0, 0.1..10.0, 0.1, visibility = { page == Page.Colors && shade })
2626

2727
val mainColor: Color get() = if (shade) Color.WHITE else primaryColor

0 commit comments

Comments
 (0)