Skip to content

Commit 3128295

Browse files
committed
Setting space shadow
1 parent d249ba3 commit 3128295

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

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

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ import com.lambda.gui.api.component.core.list.ChildLayer
1010
import com.lambda.gui.api.layer.RenderLayer
1111
import com.lambda.gui.impl.clickgui.buttons.setting.BooleanButton
1212
import com.lambda.gui.impl.clickgui.buttons.setting.NumberSlider
13+
import com.lambda.gui.impl.clickgui.windows.ModuleWindow
1314
import com.lambda.module.Module
1415
import com.lambda.module.modules.client.GuiSettings
1516
import com.lambda.util.Mouse
1617
import com.lambda.util.math.ColorUtils.multAlpha
18+
import com.lambda.util.math.ColorUtils.setAlpha
1719
import com.lambda.util.math.MathUtils.lerp
20+
import com.lambda.util.math.MathUtils.toInt
1821
import com.lambda.util.math.Rect
1922
import com.lambda.util.math.Vec2d
23+
import com.lambda.util.math.transform
24+
import java.awt.Color
2025
import kotlin.math.abs
2126

2227
class ModuleButton(val module: Module, owner: ChildLayer.Drawable<*>) : ListButton(owner) {
@@ -37,16 +42,18 @@ class ModuleButton(val module: Module, owner: ChildLayer.Drawable<*>) : ListButt
3742
private var settingsHeight = 0.0
3843
private var renderHeight by animation.exp(::settingsHeight, 0.6)
3944
private val settingsRect get() = rect
40-
.moveFirst(Vec2d(childShowAnimation * 2.0, size.y + super.listStep))
41-
.moveSecond(Vec2d(0.0, listStep))
45+
.moveFirst(Vec2d(0.0, size.y + super.listStep))
46+
.moveSecond(Vec2d(0.0, renderHeight))
4247

4348
private val settingsRenderer = RenderLayer()
44-
private val settingsLayer = ChildLayer.Drawable(owner.gui, this, settingsRenderer, ::settingsRect, SettingButton<*, *>::visible)
49+
private val settingsLayer = ChildLayer.Drawable<SettingButton<*, *>>(owner.gui, this, settingsRenderer, ::settingsRect) {
50+
it.visible && abs(settingsHeight - renderHeight) <3
51+
}
4552

4653
init {
4754
// Toggle fx
4855
renderer.filled {
49-
val left = rect - Vec2d(rect.size.x, 0.0)
56+
val left = rect - Vec2d(rect.size.x, 0.0)
5057
val right = rect + Vec2d(rect.size.x, 0.0)
5158

5259
position = lerp(left, right, activeAnimation)
@@ -58,23 +65,32 @@ class ModuleButton(val module: Module, owner: ChildLayer.Drawable<*>) : ListButt
5865
val color = GuiSettings.mainColor.multAlpha(alpha * 0.6 * showAnimation)
5966

6067
// "Tail" effect
61-
val leftColor = color.multAlpha(1.0 - toggleFxDirection)
68+
val leftColor = color.multAlpha(1.0 - toggleFxDirection)
6269
val rightColor = color.multAlpha(toggleFxDirection)
6370

6471
shade = GuiSettings.shade
6572
colorH(leftColor, rightColor)
6673
}
6774

68-
// Line
75+
// Shadow
6976
renderer.filled {
70-
val pos1 = Vec2d(rect.left, settingsRect.top)
71-
val pos2 = Vec2d(rect.left + childShowAnimation * 1.0, settingsRect.bottom)
72-
val color = GuiSettings.mainColor.multAlpha(childShowAnimation * 0.6)
77+
position = Rect(
78+
rect.leftTop + Vec2d(0.0, size.y),
79+
rect.rightTop + Vec2d(0.0, size.y + 5.0)
80+
)
81+
val progress = transform(renderHeight, 0.0, 10.0, 0.0, 1.0).coerceIn(0.0, 1.0)
82+
colorV(Color.BLACK.setAlpha(0.2 * progress), Color.BLACK.setAlpha(0.0))
83+
}
7384

74-
position = Rect(pos1, pos2)
85+
// Bottom shadow
86+
renderer.filled {
87+
val show = (owner.owner as? ModuleWindow)?.let {
88+
this@ModuleButton != it.contentComponents.children.lastOrNull()
89+
} ?: false
7590

76-
shade = GuiSettings.shade
77-
color(color)
91+
position = Rect(settingsRect.leftBottom - Vec2d(0.0, 5.0), settingsRect.rightBottom)
92+
val progress = transform(renderHeight, 0.0, 10.0, 0.0, 1.0).coerceIn(0.0, 1.0) * show.toInt()
93+
colorV(Color.BLACK.setAlpha(0.0), Color.BLACK.setAlpha(0.2 * progress))
7894
}
7995

8096
module.settings.mapNotNull {
@@ -126,7 +142,7 @@ class ModuleButton(val module: Module, owner: ChildLayer.Drawable<*>) : ListButt
126142
var lastStep = 0.0
127143
settingsLayer.children
128144
.filter(SettingButton<*, *>::visible)
129-
.sumOf { lastStep = it.listStep; it.size.y + it.listStep } - lastStep + super.listStep
145+
.sumOf { lastStep = it.listStep; it.size.y + it.listStep } - lastStep + super.listStep * 2.0
130146
} else 0.0
131147
}
132148

0 commit comments

Comments
 (0)