Skip to content

Commit e326092

Browse files
committed
Scale slider fix
1 parent 0c9ad28 commit e326092

File tree

6 files changed

+46
-16
lines changed

6 files changed

+46
-16
lines changed

common/src/main/kotlin/com/lambda/graphics/animation/Animation.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class Animation(initialValue: Double, val update: (Double) -> Double) {
1313
operator fun getValue(thisRef: Any?, property: KProperty<*>) =
1414
lerp(prevValue, currValue, mc.partialTicks)
1515

16-
operator fun setValue(thisRef: Any?, property: KProperty<*>, valueIn: Double) {
16+
operator fun setValue(thisRef: Any?, property: KProperty<*>, valueIn: Double) = setValue(valueIn)
17+
18+
fun setValue(valueIn: Double) {
1719
prevValue = valueIn
1820
currValue = valueIn
1921
}

common/src/main/kotlin/com/lambda/gui/api/LambdaGui.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ abstract class LambdaGui(
2626
private var screenSize = Vec2d.ZERO
2727
override val rect get() = Rect(Vec2d.ZERO, screenSize)
2828

29+
val isOpen get() = mc.currentScreen == this
30+
2931
val animation = AnimationTicker()
3032

3133
private val renderListener = UnsafeListener(0, this, false) { event ->
@@ -45,6 +47,7 @@ abstract class LambdaGui(
4547
* No safe context required (TODO: let user open clickgui via main menu)
4648
*/
4749
fun show() {
50+
if (isOpen) return
4851
mc.currentScreen?.close()
4952

5053
recordRenderCall { // wait for the previous screen to be closed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ abstract class AbstractClickGui(name: String = "ClickGui") : LambdaGui(name, Cli
7171
}
7272

7373
override fun close() {
74+
if (!isOpen) return
7475
closing = true
7576
}
7677
}

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
@@ -101,7 +101,7 @@ class ModuleButton(
101101
)
102102

103103
val progress = transform(renderHeight, 0.0, 10.0, 0.0, 1.0).coerceIn(0.0, 1.0)
104-
val topColor = Color.BLACK.setAlpha(0.2 * progress)
104+
val topColor = Color.BLACK.setAlpha(0.2 * progress * showAnimation)
105105
val bottomColor = Color.BLACK.setAlpha(0.0)
106106

107107
build(rect, 0.0, topColor, topColor, bottomColor, bottomColor)
@@ -119,7 +119,7 @@ class ModuleButton(
119119

120120
val progress = transform(renderHeight, 0.0, 10.0, 0.0, 1.0).coerceIn(0.0, 1.0) * show.toInt()
121121
val topColor = Color.BLACK.setAlpha(0.0)
122-
val bottomColor = Color.BLACK.setAlpha(0.2 * progress)
122+
val bottomColor = Color.BLACK.setAlpha(0.2 * progress * showAnimation)
123123

124124
build(rect, 0.0, topColor, topColor, bottomColor, bottomColor)
125125
}

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,18 @@ object ClickGui : Module(
1818
val windowPadding by setting("Window Padding", 2.0, 0.0..10.0, 0.1)
1919
val buttonHeight by setting("Button Height", 11.0, 8.0..20.0, 0.1)
2020
val buttonStep by setting("Button Step", 0.0, 0.0..5.0, 0.1)
21-
val windowBlur by setting("Window Blur", 30, 0..100, 1)
2221

2322
// Animation
2423
val openSpeed by setting("Open Speed", 0.6, 0.1..1.0, 0.01)
2524
val closeSpeed by setting("Close Speed", 0.7, 0.1..1.0, 0.01)
2625

2726
init {
2827
onEnable {
29-
if (mc.currentScreen != LambdaClickGui) {
30-
LambdaClickGui.show()
31-
}
28+
LambdaClickGui.show()
3229
}
3330

3431
onDisable {
35-
if (mc.currentScreen == LambdaClickGui) {
36-
LambdaClickGui.close()
37-
}
32+
LambdaClickGui.close()
3833
}
3934

4035
unsafeListener<ClientEvent.Shutdown> {

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

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package com.lambda.module.modules.client
22

3+
import com.lambda.event.events.ConnectionEvent
4+
import com.lambda.event.events.TickEvent
5+
import com.lambda.event.listener.UnsafeListener.Companion.unsafeListener
6+
import com.lambda.graphics.animation.Animation.Companion.exp
7+
import com.lambda.graphics.animation.AnimationTicker
8+
import com.lambda.gui.impl.clickgui.LambdaClickGui
39
import com.lambda.module.Module
410
import com.lambda.module.tag.ModuleTag
511
import java.awt.Color
@@ -12,17 +18,21 @@ object GuiSettings : Module(
1218
private val page by setting("Page", Page.General)
1319

1420
// General
15-
private val scaleSetting by setting("Scale", 1.0, 0.5..3.0, 0.01, visibility = { page == Page.General })
21+
private val scaleSetting by setting("Scale", 100, 50..300, 1, visibility = { page == Page.General }).apply {
22+
onValueChangeUnsafe { _, _ ->
23+
lastChange = System.currentTimeMillis()
24+
}
25+
}
1626

1727
// Colors
1828
val primaryColor by setting("Primary Color", Color(130, 200, 255), visibility = { page == Page.Colors })
19-
val secondaryColor by setting("Secondary Color", Color(225, 130, 225), visibility = { page == Page.Colors && shade })
29+
val secondaryColor by setting("Secondary Color", Color(225, 130, 225), visibility = { page == Page.Colors && (shade || shadeBackground) })
2030
val backgroundColor by setting("Background Color", Color(50, 50, 50), visibility = { page == Page.Colors })
2131
val shade by setting("Shade", true, visibility = { page == Page.Colors })
2232
val shadeBackground by setting("Shade Background", true, visibility = { page == Page.Colors })
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 })
25-
val colorSpeed by setting("Color Speed", 1.0, 0.1..10.0, 0.1, visibility = { page == Page.Colors && shade })
33+
val colorWidth by setting("Color Width", 400.0, 10.0..1000.0, 10.0, visibility = { page == Page.Colors && (shade || shadeBackground) })
34+
val colorHeight by setting("Color Height", 400.0, 10.0..1000.0, 10.0, visibility = { page == Page.Colors && (shade || shadeBackground) })
35+
val colorSpeed by setting("Color Speed", 1.0, 0.1..10.0, 0.1, visibility = { page == Page.Colors && (shade || shadeBackground) })
2636

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

@@ -34,5 +44,24 @@ object GuiSettings : Module(
3444
Colors
3545
}
3646

37-
val scale get() = scaleSetting * 2
47+
private var targetScale = 2.0; get() {
48+
val update = System.currentTimeMillis() - lastChange > 1000 || !LambdaClickGui.isOpen
49+
if (update) field = scaleSetting / 100.0 * 2.0
50+
return field
51+
}
52+
53+
private val animation = with(AnimationTicker()) {
54+
unsafeListener<TickEvent.Pre>(alwaysListen = true) {
55+
tick()
56+
}
57+
58+
exp({ targetScale }, 0.5).apply {
59+
unsafeListener<ConnectionEvent.Connect>(alwaysListen = true) {
60+
setValue(targetScale)
61+
}
62+
}
63+
}
64+
65+
private var lastChange = 0L
66+
val scale by animation
3867
}

0 commit comments

Comments
 (0)