@@ -4,6 +4,7 @@ import com.lambda.client.commons.interfaces.Alias
4
4
import com.lambda.client.commons.interfaces.DisplayEnum
5
5
import com.lambda.client.commons.interfaces.Nameable
6
6
import com.lambda.client.event.LambdaEventBus
7
+ import com.lambda.client.gui.GuiManager
7
8
import com.lambda.client.gui.rgui.windows.BasicWindow
8
9
import com.lambda.client.module.modules.client.GuiColors
9
10
import com.lambda.client.module.modules.client.Hud
@@ -18,6 +19,7 @@ import com.lambda.client.util.math.Vec2d
18
19
import com.lambda.client.util.math.Vec2f
19
20
import com.lambda.client.util.text.MessageSendHelper
20
21
import com.lambda.client.util.threads.safeListener
22
+ import net.minecraft.client.gui.GuiChat
21
23
import net.minecraftforge.fml.common.gameevent.TickEvent
22
24
import org.lwjgl.opengl.GL11.glScalef
23
25
@@ -34,7 +36,13 @@ abstract class AbstractHudElement(
34
36
val bind by setting(" Bind" , Bind ())
35
37
val scale by setting(" Scale" , 1.0f , 0.1f .. 4.0f , 0.05f )
36
38
val default = setting(" Default" , false )
39
+ private val overridePrimaryColor by setting(" Override Primary Color" , false )
40
+ private val overridePrimaryColorValue by setting(" Override Primary Color Value" , Hud .primaryColor, visibility = { overridePrimaryColor })
41
+ private val overrideSecondaryColor by setting(" Override Secondary Color" , false )
42
+ private val overrideSecondaryColorValue by setting(" Override Secondary Color Value" , Hud .secondaryColor, visibility = { overrideSecondaryColor })
37
43
44
+ val primaryColor get() = if (overridePrimaryColor) overridePrimaryColorValue else Hud .primaryColor
45
+ val secondaryColor get() = if (overrideSecondaryColor) overrideSecondaryColorValue else Hud .secondaryColor
38
46
override val resizable = false
39
47
40
48
final override val minWidth: Float get() = FontRenderAdapter .getFontHeight() * scale * 2.0f
@@ -47,12 +55,64 @@ abstract class AbstractHudElement(
47
55
open val hudHeight: Float get() = 10f
48
56
49
57
val settingList get() = GuiConfig .getSettings(this )
58
+ private var chatSnapping = false
59
+ private val snappedElements = mutableListOf<AbstractHudElement >()
60
+ private val chatSnapY = 15f
50
61
51
62
init {
52
63
safeListener<TickEvent .ClientTickEvent > {
53
64
if (it.phase != TickEvent .Phase .END || ! visible) return @safeListener
54
65
width = maxWidth
55
66
height = maxHeight
67
+ if (Hud .chatSnap) {
68
+ if (mc.currentScreen is GuiChat && ! chatSnapping) {
69
+ val screenH = (mc.currentScreen as GuiChat ).height
70
+ if (posY >= screenH - height - 3 && posX <= 3 && yShift == 0.0f ) {
71
+ val prevPosYSnap = posY
72
+ yShift = - chatSnapY
73
+ snappedElements.clear()
74
+ GuiManager .getHudElementOrNull(componentName)?.let { snappedElements.add(it) }
75
+ chatSnapCheck(componentName, prevPosYSnap)
76
+ chatSnapping = true
77
+ }
78
+ } else if (mc.currentScreen !is GuiChat && chatSnapping) {
79
+ yShift = 0.0f
80
+ for (element in snappedElements) {
81
+ element.yShift = 0.0f
82
+ }
83
+ snappedElements.clear()
84
+ chatSnapping = false
85
+ }
86
+ }
87
+ }
88
+ }
89
+
90
+ private fun chatSnapCheck (thisElement : String , prevSnapY : Float ) {
91
+ for (element in GuiManager .hudElements) {
92
+ if (! snappedElements.contains(element)
93
+ && element.componentName != thisElement
94
+ && element.visible
95
+ && element.posY + element.height >= prevSnapY - 3
96
+ && element.posX <= 3 ) {
97
+ snappedElements.add(element)
98
+ chatSnapCheck(element.componentName, element.posY)
99
+ element.yShift = - chatSnapY
100
+ }
101
+ }
102
+ }
103
+
104
+ override fun onReposition () {
105
+ super .onReposition()
106
+ if (Hud .collisionSnapping) {
107
+ for (element in GuiManager .hudElements) {
108
+ if (element.componentName != componentName && element.visible && element.posY + element.height >= posY && element.posY <= posY + height && element.posX + element.width >= posX && element.posX <= posX + width) {
109
+ if (posY + height / 2 <= element.posY + element.height / 2 ) {
110
+ posY = element.posY - height
111
+ } else {
112
+ posY = element.posY + element.height
113
+ }
114
+ }
115
+ }
56
116
}
57
117
}
58
118
@@ -112,9 +172,4 @@ abstract class AbstractHudElement(
112
172
MISC (" Misc" )
113
173
}
114
174
115
- protected companion object {
116
- val primaryColor get() = Hud .primaryColor
117
- val secondaryColor get() = Hud .secondaryColor
118
- }
119
-
120
175
}
0 commit comments