Skip to content

Commit b476148

Browse files
committed
Massive gc troll fix, rect/outline/font layouts, simple module buttons
1 parent dbbe522 commit b476148

File tree

12 files changed

+511
-228
lines changed

12 files changed

+511
-228
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ class Animation(initialValue: Double, val update: (Double) -> Double) {
1010
private var prevValue = initialValue
1111
private var currValue = initialValue
1212

13-
operator fun getValue(thisRef: Any?, property: KProperty<*>) =
14-
lerp(mc.partialTicks, prevValue, currValue)
15-
13+
operator fun getValue(thisRef: Any?, property: KProperty<*>) = value()
1614
operator fun setValue(thisRef: Any?, property: KProperty<*>, valueIn: Double) = setValue(valueIn)
1715

16+
fun value(): Double = lerp(mc.partialTicks, prevValue, currValue)
17+
1818
fun setValue(valueIn: Double) {
1919
prevValue = valueIn
2020
currValue = valueIn
Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.lambda.module.modules.client
22

33
import com.lambda.module.Module
4+
import com.lambda.module.ModuleRegistry
45
import com.lambda.module.tag.ModuleTag
56
import com.lambda.newgui.LambdaScreen.Companion.gui
67
import com.lambda.newgui.LambdaScreen.Companion.toScreen
8+
import com.lambda.newgui.component.window.Window
79
import com.lambda.newgui.component.window.Window.Companion.window
10+
import com.lambda.newgui.impl.clickgui.ModuleLayout.Companion.moduleLayout
811
import com.lambda.util.math.Vec2d
912
import com.lambda.util.math.setAlpha
1013
import java.awt.Color
@@ -17,33 +20,41 @@ object NewCGui : Module(
1720
val titleBarHeight by setting("Title Bar Height", 18.0, 0.0..25.0, 0.1)
1821
val padding by setting("Padding", 2.0, 1.0..6.0, 0.1)
1922
val listStep by setting("List Step", 2.0, 0.0..6.0, 0.1)
23+
val autoResize by setting("Auto Resize", false)
2024

2125
val roundRadius by setting("Round Radius", 2.0, 0.0..10.0, 0.1)
2226

23-
val backgroundColor by setting("Background Color", Color.WHITE.setAlpha(0.4))
27+
val titleBackgroundColor by setting("Title Background Color", Color.WHITE.setAlpha(0.4))
28+
val backgroundColor by setting("Background Color", Color.WHITE.setAlpha(0.2))
2429
val backgroundShade by setting("Background Shade", true)
2530

2631
val outline by setting("Outline", true)
2732
val outlineWidth by setting("Outline Width", 10.0, 1.0..10.0, 0.1) { outline }
2833
val outlineColor by setting("Outline Color", Color.WHITE.setAlpha(0.6)) { outline }
2934
val outlineShade by setting("Outline Shade", true) { outline }
3035

31-
private val clickGuiLayout =
36+
private val SCREEN by lazy {
3237
gui {
33-
window(position = Vec2d.ONE * 20.0, title = "Test window") {
34-
repeat(6) {
35-
window(Vec2d.ONE * 5.0, Vec2d.ONE * 60.0) {
38+
val tags = ModuleTag.defaults
39+
val modules = ModuleRegistry.modules
3640

41+
tags.forEachIndexed { i, tag ->
42+
val windowPosition = Vec2d.ONE * 20.0 + Vec2d.RIGHT * ((115.0 * i) + (i + 1) * 4)
43+
44+
window(position = windowPosition, title = tag.name, autoResize = Window.AutoResize.ByConfig) {
45+
val tagModules = modules.filter { it.defaultTags.first() == tag }
46+
47+
tagModules.forEach { module ->
48+
moduleLayout(module)
3749
}
3850
}
3951
}
40-
}
41-
42-
val CLICK_GUI = clickGuiLayout.toScreen("New Click Gui")
52+
}.toScreen("New Click Gui")
53+
}
4354

4455
init {
4556
onEnable {
46-
CLICK_GUI.show()
57+
SCREEN.show()
4758
}
4859
}
4960
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.lambda.newgui.component.core
2+
3+
import com.lambda.newgui.component.layout.Layout
4+
import java.awt.Color
5+
6+
class FilledRect(
7+
owner: Layout
8+
) : Layout(owner, true, true) {
9+
var rectangle = owner.rect
10+
11+
var leftTopRadius = 0.0
12+
var rightTopRadius = 0.0
13+
var rightBottomRadius = 0.0
14+
var leftBottomRadius = 0.0
15+
16+
var leftTopColor: Color = Color.WHITE
17+
var rightTopColor: Color = Color.WHITE
18+
var rightBottomColor: Color = Color.WHITE
19+
var leftBottomColor: Color = Color.WHITE
20+
21+
var shade = false
22+
23+
private val updateActions = mutableListOf<FilledRect.() -> Unit>()
24+
25+
fun onUpdate(block: FilledRect.() -> Unit) {
26+
updateActions += block
27+
}
28+
29+
init {
30+
onRender {
31+
updateActions.forEach { action ->
32+
action(this@FilledRect)
33+
}
34+
35+
filled.build(
36+
rectangle,
37+
leftTopRadius,
38+
rightTopRadius,
39+
rightBottomRadius,
40+
leftBottomRadius,
41+
leftTopColor,
42+
rightTopColor,
43+
rightBottomColor,
44+
leftBottomColor,
45+
shade
46+
)
47+
}
48+
}
49+
50+
fun setRadius(radius: Double) {
51+
leftTopRadius = radius
52+
rightTopRadius = radius
53+
rightBottomRadius = radius
54+
leftBottomRadius = radius
55+
}
56+
57+
fun setColor(color: Color) {
58+
leftTopColor = color
59+
rightTopColor = color
60+
rightBottomColor = color
61+
leftBottomColor = color
62+
}
63+
64+
companion object {
65+
/**
66+
* Creates a [FilledRect] component - layout-based rect representation
67+
*/
68+
@UIBuilder
69+
fun Layout.rect(block: FilledRect.() -> Unit = {}) =
70+
FilledRect(this).apply(children::add).apply {
71+
updateActions += block
72+
}
73+
}
74+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.lambda.newgui.component.core
2+
3+
import com.lambda.newgui.component.layout.Layout
4+
import java.awt.Color
5+
6+
class OutlineRect(
7+
owner: Layout
8+
) : Layout(owner, true, true) {
9+
var rectangle = owner.rect
10+
11+
var roundRadius = 0.0
12+
var glowRadius = 0.0
13+
14+
var leftTopColor: Color = Color.WHITE
15+
var rightTopColor: Color = Color.WHITE
16+
var rightBottomColor: Color = Color.WHITE
17+
var leftBottomColor: Color = Color.WHITE
18+
19+
var shade = false
20+
21+
private val updateActions = mutableListOf<OutlineRect.() -> Unit>()
22+
23+
fun onUpdate(block: OutlineRect.() -> Unit) {
24+
updateActions += block
25+
}
26+
27+
init {
28+
onRender {
29+
updateActions.forEach { action ->
30+
action(this@OutlineRect)
31+
}
32+
33+
outline.build(
34+
rectangle,
35+
roundRadius,
36+
glowRadius,
37+
leftTopColor,
38+
rightTopColor,
39+
rightBottomColor,
40+
leftBottomColor,
41+
shade
42+
)
43+
}
44+
}
45+
46+
fun setColor(color: Color) {
47+
leftTopColor = color
48+
rightTopColor = color
49+
rightBottomColor = color
50+
leftBottomColor = color
51+
}
52+
53+
companion object {
54+
/**
55+
* Creates a [OutlineRect] component - layout-based rect representation
56+
*/
57+
@UIBuilder
58+
fun Layout.outline(block: OutlineRect.() -> Unit = {}) =
59+
OutlineRect(this).apply(children::add).apply {
60+
updateActions += block
61+
}
62+
}
63+
}
Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,52 @@
11
package com.lambda.newgui.component.core
22

3-
import com.lambda.newgui.component.HAlign
4-
import com.lambda.newgui.component.VAlign
53
import com.lambda.newgui.component.layout.Layout
64
import com.lambda.util.math.Vec2d
7-
import com.lambda.util.math.lerp
85
import java.awt.Color
96

107
class TextField(
118
owner: Layout,
12-
var text: String,
13-
var color: Color,
14-
var scale: Double,
15-
var bold: Boolean,
16-
var shadow: Boolean,
17-
var offset: Double,
189
) : Layout(owner, true, true) {
10+
var text = ""
11+
var color = Color.WHITE
12+
var scale = 1.0
13+
var bold = false
14+
var shadow = true
15+
1916
val textWidth get() = fr.getWidth(text, scale)
2017
val textHeight get() = fr.getHeight(scale)
2118

2219
private val fr get() = if (bold) renderer.boldFont else renderer.font
2320

21+
private val updateActions = mutableListOf<TextField.() -> Unit>()
22+
23+
fun onUpdate(block: TextField.() -> Unit) {
24+
updateActions += block
25+
}
26+
2427
init {
2528
properties.interactionPassthrough = true
26-
verticalAlignment = VAlign.CENTER
2729

2830
onRender {
29-
position = owner.position
30-
size = owner.size
31-
32-
val x = lerp(
33-
horizontalAlignment.multiplier,
34-
rect.left,
35-
rect.right - textWidth,
36-
) - offset * horizontalAlignment.offset
37-
38-
val y = when {
39-
verticalAlignment == VAlign.CENTER || rect.size.y <= textHeight -> rect.center.y
40-
else -> lerp(
41-
verticalAlignment.multiplier,
42-
rect.top + textHeight * 0.5,
43-
rect.bottom - textHeight * 0.5
44-
)
31+
updateActions.forEach { action ->
32+
action(this@TextField)
4533
}
4634

47-
fr.build(text, Vec2d(x, y), color, scale, shadow)
35+
width = textWidth
36+
height = textHeight
37+
38+
val renderPos = Vec2d(renderPositionX, renderPositionY + renderHeight * 0.5)
39+
fr.build(text, renderPos, color, scale, shadow)
4840
}
4941
}
5042

5143
companion object {
5244
/**
5345
* Creates a [TextField] component
54-
*
55-
* @param text String to draw
56-
*
57-
* @param color Color of the font
58-
*
59-
* @param scale Scale of the font
60-
*
61-
* @param bold Whether to use the bold variant of the font
62-
*
63-
* @param shadow Whether the font should drop a shadow
64-
*
65-
* @param offset Offset from the corner(specified by [horizontalAlignment]) of the text (ignored for [HAlign.CENTER])
6646
*/
6747
@UIBuilder
6848
fun Layout.textField(
69-
text: String,
70-
color: Color = Color.WHITE,
71-
scale: Double = 1.0,
72-
bold: Boolean = false,
73-
shadow: Boolean = true,
74-
offset: Double = 0.0,
7549
block: TextField.() -> Unit = {}
76-
) = TextField(this, text, color, scale, bold, shadow, offset).apply(children::add).apply(block)
50+
) = TextField(this).apply(children::add).apply(block)
7751
}
7852
}

0 commit comments

Comments
 (0)