Skip to content

Commit 83ce0a6

Browse files
committed
Sexy animations & many fixes
1 parent 9babf6f commit 83ce0a6

File tree

17 files changed

+115
-39
lines changed

17 files changed

+115
-39
lines changed

common/src/main/kotlin/com/lambda/config/settings/NumericSetting.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ abstract class NumericSetting<T>(
3131
override fun toString() = "$value$unit"
3232

3333
override operator fun setValue(thisRef: Any?, property: KProperty<*>, valueIn: T) {
34-
value = valueIn.coerceIn(range).roundToStep(step)
34+
value = valueIn.coerceIn(range)
3535
}
3636
}

common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/FontEntry.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class FontEntry(
3737
return width * actualScale
3838
}
3939

40-
override val height: Double
40+
override val stringHeight: Double
4141
get() = font.glyphs.fontHeight * actualScale * 0.7
4242

4343
override fun build(ctx: IRenderContext) = ctx.use {
@@ -46,7 +46,7 @@ class FontEntry(
4646
val shadowColor = getShadowColor(color)
4747

4848
var posX = 0.0
49-
val posY = height * -0.5 + baselineOffset * actualScale
49+
val posY = stringHeight * -0.5 + baselineOffset * actualScale
5050

5151
text.toCharArray().forEach { char ->
5252
val charInfo = font[char] ?: return@forEach
@@ -109,9 +109,9 @@ interface IFontEntry : IRenderEntry<IFontEntry> {
109109

110110
fun getWidth(text: String): Double
111111

112-
val width get() = getWidth(text)
113-
val height: Double
112+
val stringWidth get() = getWidth(text)
113+
val stringHeight: Double
114114

115-
val widthVec get() = Vec2d(width, 0.0)
116-
val heightVec get() = Vec2d(0.0, height)
115+
val widthVec get() = Vec2d(stringWidth, 0.0)
116+
val heightVec get() = Vec2d(0.0, stringHeight)
117117
}

common/src/main/kotlin/com/lambda/graphics/renderer/gui/rect/AbstractRectRenderer.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.lambda.graphics.renderer.gui.rect
22

3+
import com.lambda.Lambda.mc
34
import com.lambda.graphics.buffer.vao.vertex.VertexAttrib
45
import com.lambda.graphics.renderer.IRenderEntry
56
import com.lambda.graphics.renderer.gui.AbstractGuiRenderer
@@ -16,6 +17,9 @@ abstract class AbstractRectRenderer <T : IRenderEntry<T>> (
1617
shader["u_Time"] = glfwGetTime() * GuiSettings.colorSpeed * 5.0
1718
shader["u_Color1"] = GuiSettings.shadeColor1
1819
shader["u_Color2"] = GuiSettings.shadeColor2
19-
shader["u_Size"] = Vec2d.ONE / Vec2d(GuiSettings.colorWidth, GuiSettings.colorHeight)
20+
21+
val screen = Vec2d(mc.window.framebufferWidth, mc.window.framebufferHeight)
22+
val size = Vec2d(GuiSettings.colorWidth, GuiSettings.colorHeight)
23+
shader["u_Size"] = screen / size
2024
}
2125
}

common/src/main/kotlin/com/lambda/gui/api/component/InteractiveComponent.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ abstract class InteractiveComponent : IComponent {
2424
}
2525

2626
is GuiEvent.MouseClick -> {
27+
hovered = rect.contains(e.mouse)
28+
2729
val prevPressed = pressed
2830
pressed = hovered && e.button.isMainButton && e.action == Mouse.Action.Click
2931

common/src/main/kotlin/com/lambda/gui/api/component/WindowComponent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ abstract class WindowComponent <T : ChildComponent> (
4040
private val contentRect get() = rect.shrink(padding).moveFirst(Vec2d(0.0, titleBarHeight - padding))
4141

4242
private val titleBar get() = Rect.basedOn(rect.leftTop, rect.size.x, titleBarHeight)
43-
private val titleBarHeight get() = ClickGui.buttonHeight + padding * 2
43+
private val titleBarHeight get() = ClickGui.buttonHeight * 1.25
4444
private val titleFont: IFontEntry
4545

4646
private val layer = RenderLayer()

common/src/main/kotlin/com/lambda/gui/api/component/button/ButtonComponent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ abstract class ButtonComponent(
6767
}
6868
}
6969

70-
abstract fun performClickAction(e: GuiEvent.MouseClick)
70+
open fun performClickAction(e: GuiEvent.MouseClick) {}
7171

7272
override fun onEvent(e: GuiEvent) {
7373
super.onEvent(e)

common/src/main/kotlin/com/lambda/gui/api/component/button/ListButton.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ abstract class ListButton(owner: ChildLayer.Drawable<*>) : ButtonComponent(owner
1414
open val listStep get() = ClickGui.buttonStep
1515

1616
var heightOffset = 0.0
17-
protected open var renderHeightOffset by animation.exp(::heightOffset, 0.9)
17+
18+
protected var renderHeightAnimation by animation.exp(::heightOffset, 0.8)
19+
protected open val renderHeightOffset get() = renderHeightAnimation
1820

1921
override fun onEvent(e: GuiEvent) {
2022
if (e is GuiEvent.Show) {
2123
heightOffset = 0.0
22-
renderHeightOffset = 0.0
24+
renderHeightAnimation = 0.0
2325
}
2426
super.onEvent(e)
2527
}

common/src/main/kotlin/com/lambda/gui/api/component/core/list/ChildComponent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract class ChildComponent(open val owner: IComponent) : InteractiveComponent
99

1010
override fun onEvent(e: GuiEvent) {
1111
super.onEvent(e)
12-
if (e is GuiEvent.MouseMove) hovered = hovered && accessible
12+
if (e is GuiEvent.MouseMove || e is GuiEvent.MouseClick) hovered = hovered && accessible
1313
}
1414

1515
open fun onAdd() {}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.lambda.gui.impl.clickgui.buttons
22

3+
import com.lambda.config.settings.NumericSetting
34
import com.lambda.config.settings.comparable.BooleanSetting
45
import com.lambda.graphics.animation.Animation.Companion.exp
56
import com.lambda.graphics.gl.Scissor.scissor
@@ -8,6 +9,7 @@ import com.lambda.gui.api.component.button.ListButton
89
import com.lambda.gui.api.component.core.list.ChildLayer
910
import com.lambda.gui.api.layer.RenderLayer
1011
import com.lambda.gui.impl.clickgui.buttons.setting.BooleanButton
12+
import com.lambda.gui.impl.clickgui.buttons.setting.NumberSlider
1113
import com.lambda.module.Module
1214
import com.lambda.module.modules.client.GuiSettings
1315
import com.lambda.util.Mouse
@@ -78,6 +80,7 @@ class ModuleButton(val module: Module, owner: ChildLayer.Drawable<*>) : ListButt
7880
module.settings.mapNotNull {
7981
when (it) {
8082
is BooleanSetting -> BooleanButton(it, settingsLayer)
83+
is NumericSetting<*> -> NumberSlider(it, settingsLayer)
8184
else -> null
8285
}
8386
}.forEach(settingsLayer::addChild)
@@ -87,22 +90,22 @@ class ModuleButton(val module: Module, owner: ChildLayer.Drawable<*>) : ListButt
8790
when (e) {
8891
is GuiEvent.Show -> {
8992
isOpen = false
90-
updateHeight(true)
93+
updateHeight()
94+
renderHeight = settingsHeight
9195
}
9296

9397
is GuiEvent.Tick -> {
94-
if (renderHeight > 0.5) {
95-
updateHeight()
96-
}
97-
}
98+
if (renderHeight < 0.5) return
99+
updateHeight()
98100

99-
is GuiEvent.Render -> {
100101
var y = 0.0
101102
settingsLayer.children.filter(SettingButton<*, *>::visible).forEach { button ->
102103
button.heightOffset = y
103104
y += button.size.y + button.listStep
104105
}
106+
}
105107

108+
is GuiEvent.Render -> {
106109
if (renderHeight > 0.5) {
107110
scissor(settingsRect) {
108111
settingsLayer.onEvent(e)
@@ -118,16 +121,13 @@ class ModuleButton(val module: Module, owner: ChildLayer.Drawable<*>) : ListButt
118121
settingsLayer.onEvent(e)
119122
}
120123

121-
private fun updateHeight(forceAnimation: Boolean = false) {
124+
private fun updateHeight() {
122125
settingsHeight = if (isOpen) {
123126
var lastStep = 0.0
124127
settingsLayer.children
125128
.filter(SettingButton<*, *>::visible)
126129
.sumOf { lastStep = it.listStep; it.size.y + it.listStep } - lastStep
127-
}
128-
else 0.0
129-
130-
if (forceAnimation) renderHeight = settingsHeight
130+
} else 0.0
131131
}
132132

133133
override fun performClickAction(e: GuiEvent.MouseClick) {

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.lambda.gui.impl.clickgui.buttons
22

33
import com.lambda.config.AbstractSetting
44
import com.lambda.graphics.animation.Animation.Companion.exp
5+
import com.lambda.gui.api.GuiEvent
56
import com.lambda.gui.api.component.button.ListButton
67
import com.lambda.gui.api.component.core.list.ChildLayer
78
import com.lambda.util.math.MathUtils.lerp
@@ -10,15 +11,25 @@ abstract class SettingButton <V : Any, T : AbstractSetting<V>> (
1011
val setting: T,
1112
owner: ChildLayer.Drawable<*>
1213
): ListButton(owner) {
14+
override val text = setting.name
1315
protected var value by setting
1416

1517
val visible; get() = setting.visibility()
18+
private var prevTickVisible = false
1619

17-
private var visibilityAnimation by animation.exp(0.0, 1.0, 0.7, ::visible)
20+
private var visibilityAnimation by animation.exp(0.0, 1.0, 0.6, ::visible)
1821
override val showAnimation get() = lerp(0.0, super.showAnimation, visibilityAnimation)
1922
override var activeAnimation = 0.0
23+
override val renderHeightOffset get() = renderHeightAnimation + lerp(-size.y, 0.0, visibilityAnimation)
2024

21-
override var renderHeightOffset
22-
get() = heightOffset + lerp(-size.y, 0.0, visibilityAnimation)
23-
set(value) { heightOffset = value }
25+
override fun onEvent(e: GuiEvent) {
26+
super.onEvent(e)
27+
28+
when (e) {
29+
is GuiEvent.Tick -> {
30+
if (!prevTickVisible && visible) renderHeightAnimation = heightOffset
31+
prevTickVisible = visible
32+
}
33+
}
34+
}
2435
}

0 commit comments

Comments
 (0)