@@ -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,66 @@ 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
- safeListener<TickEvent .ClientTickEvent > {
53
- if (it .phase != TickEvent .Phase .END || ! visible) return @safeListener
63
+ safeListener<TickEvent .ClientTickEvent > { event ->
64
+ if (event .phase != TickEvent .Phase .END || ! visible) return @safeListener
54
65
width = maxWidth
55
66
height = maxHeight
67
+
68
+ if (! Hud .chatSnap) return @safeListener
69
+
70
+ val currentScreen = mc.currentScreen
71
+ if (currentScreen is GuiChat && ! chatSnapping) {
72
+ val screenH = currentScreen.height
73
+ if (posY >= screenH - height - 3 && posX <= 3 && yShift == 0.0f ) {
74
+ val prevPosYSnap = posY
75
+ yShift = - chatSnapY
76
+ snappedElements.clear()
77
+ GuiManager .getHudElementOrNull(componentName)?.let { snappedElements.add(it) }
78
+ chatSnapCheck(componentName, prevPosYSnap)
79
+ chatSnapping = true
80
+ }
81
+ } else if (currentScreen !is GuiChat && chatSnapping) {
82
+ yShift = 0.0f
83
+ snappedElements.forEach {
84
+ it.yShift = 0.0f
85
+ }
86
+ snappedElements.clear()
87
+ chatSnapping = false
88
+ }
89
+ }
90
+ }
91
+
92
+ private fun chatSnapCheck (thisElement : String , prevSnapY : Float ) {
93
+ for (element in GuiManager .hudElements) {
94
+ if (! snappedElements.contains(element)
95
+ && element.componentName != thisElement
96
+ && element.visible
97
+ && element.posY + element.height >= prevSnapY - 3
98
+ && element.posX <= 3 ) {
99
+ snappedElements.add(element)
100
+ chatSnapCheck(element.componentName, element.posY)
101
+ element.yShift = - chatSnapY
102
+ }
103
+ }
104
+ }
105
+
106
+ override fun onReposition () {
107
+ super .onReposition()
108
+ if (Hud .collisionSnapping) {
109
+ for (element in GuiManager .hudElements) {
110
+ if (element.componentName != componentName && element.visible && element.posY + element.height >= posY && element.posY <= posY + height && element.posX + element.width >= posX && element.posX <= posX + width) {
111
+ if (posY + height / 2 <= element.posY + element.height / 2 ) {
112
+ posY = element.posY - height
113
+ } else {
114
+ posY = element.posY + element.height
115
+ }
116
+ }
117
+ }
56
118
}
57
119
}
58
120
@@ -112,9 +174,4 @@ abstract class AbstractHudElement(
112
174
MISC (" Misc" )
113
175
}
114
176
115
- protected companion object {
116
- val primaryColor get() = Hud .primaryColor
117
- val secondaryColor get() = Hud .secondaryColor
118
- }
119
-
120
177
}
0 commit comments