Skip to content

Commit 800f3b4

Browse files
authored
Merge pull request #544 from rfresh2/hud-update
Hud: Chat and Collision snapping + Color overrides
2 parents b4796fb + 108d766 commit 800f3b4

File tree

3 files changed

+68
-8
lines changed

3 files changed

+68
-8
lines changed

src/main/kotlin/com/lambda/client/gui/hudgui/AbstractHudElement.kt

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.lambda.client.commons.interfaces.Alias
44
import com.lambda.client.commons.interfaces.DisplayEnum
55
import com.lambda.client.commons.interfaces.Nameable
66
import com.lambda.client.event.LambdaEventBus
7+
import com.lambda.client.gui.GuiManager
78
import com.lambda.client.gui.rgui.windows.BasicWindow
89
import com.lambda.client.module.modules.client.GuiColors
910
import com.lambda.client.module.modules.client.Hud
@@ -18,6 +19,7 @@ import com.lambda.client.util.math.Vec2d
1819
import com.lambda.client.util.math.Vec2f
1920
import com.lambda.client.util.text.MessageSendHelper
2021
import com.lambda.client.util.threads.safeListener
22+
import net.minecraft.client.gui.GuiChat
2123
import net.minecraftforge.fml.common.gameevent.TickEvent
2224
import org.lwjgl.opengl.GL11.glScalef
2325

@@ -34,7 +36,13 @@ abstract class AbstractHudElement(
3436
val bind by setting("Bind", Bind())
3537
val scale by setting("Scale", 1.0f, 0.1f..4.0f, 0.05f)
3638
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 })
3743

44+
val primaryColor get() = if (overridePrimaryColor) overridePrimaryColorValue else Hud.primaryColor
45+
val secondaryColor get() = if (overrideSecondaryColor) overrideSecondaryColorValue else Hud.secondaryColor
3846
override val resizable = false
3947

4048
final override val minWidth: Float get() = FontRenderAdapter.getFontHeight() * scale * 2.0f
@@ -47,12 +55,66 @@ abstract class AbstractHudElement(
4755
open val hudHeight: Float get() = 10f
4856

4957
val settingList get() = GuiConfig.getSettings(this)
58+
private var chatSnapping = false
59+
private val snappedElements = mutableListOf<AbstractHudElement>()
60+
private val chatSnapY = 15f
5061

5162
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
5465
width = maxWidth
5566
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+
}
56118
}
57119
}
58120

@@ -112,9 +174,4 @@ abstract class AbstractHudElement(
112174
MISC("Misc")
113175
}
114176

115-
protected companion object {
116-
val primaryColor get() = Hud.primaryColor
117-
val secondaryColor get() = Hud.secondaryColor
118-
}
119-
120177
}

src/main/kotlin/com/lambda/client/gui/rgui/Component.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ open class Component(
4545
var relativePosY by relativePosYSetting
4646
var dockingH by dockingHSetting
4747
var dockingV by dockingVSetting
48+
var yShift = 0.0f
4849

4950
var posX: Float
5051
get() {
@@ -57,7 +58,7 @@ open class Component(
5758

5859
var posY: Float
5960
get() {
60-
return relativeToAbsY(relativePosY)
61+
return relativeToAbsY(relativePosY) + yShift
6162
}
6263
set(value) {
6364
if (!LambdaMod.ready) return

src/main/kotlin/com/lambda/client/module/modules/client/Hud.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ object Hud : Module(
1414
val hudFrame by setting("Hud Frame", false)
1515
val primaryColor by setting("Primary Color", ColorHolder(255, 240, 246), false)
1616
val secondaryColor by setting("Secondary Color", ColorHolder(108, 0, 43), false)
17+
val chatSnap by setting("Chat Snap", true)
18+
val collisionSnapping by setting("Collision Snapping", true)
1719
}

0 commit comments

Comments
 (0)