Skip to content

Commit ba9ecad

Browse files
authored
Merge pull request #564 from rfresh2/hud-elements-update
Hud elements update
2 parents 734ac8c + 9460fbf commit ba9ecad

File tree

11 files changed

+100
-28
lines changed

11 files changed

+100
-28
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ abstract class AbstractHudElement(
159159

160160
default.valueListeners.add { _, it ->
161161
if (it) {
162-
settingList.filter { it != visibleSetting && it != default }.forEach { it.resetValue() }
162+
settingList.filter { it != visibleSetting && it != default }.forEach {
163+
it.resetValue()
164+
updatePreDrag(null)
165+
}
163166
default.value = false
164167
MessageSendHelper.sendChatMessage("$name Set to defaults!")
165168
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.lambda.client.gui.hudgui
22

33
import com.lambda.client.commons.interfaces.Nameable
44
import com.lambda.client.event.SafeClientEvent
5+
import com.lambda.client.module.modules.client.Hud
56
import com.lambda.client.module.modules.client.HudEditor
67
import com.lambda.client.setting.configs.AbstractConfig
78
import com.lambda.client.util.graphics.VertexHelper
@@ -23,7 +24,6 @@ abstract class AbstractLabelHud(
2324

2425
override val hudWidth: Float get() = displayText.getWidth() + 2.0f
2526
override val hudHeight: Float get() = displayText.getHeight(2)
26-
2727
protected val displayText = TextComponent(separator)
2828

2929
init {
@@ -47,7 +47,8 @@ abstract class AbstractLabelHud(
4747
displayText.draw(
4848
Vec2d(textPosX.toDouble(), textPosY.toDouble()),
4949
horizontalAlign = dockingH,
50-
verticalAlign = dockingV
50+
verticalAlign = dockingV,
51+
drawShadow = Hud.textShadow
5152
)
5253
}
5354

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.lambda.client.gui.hudgui.elements.misc
2+
3+
import com.lambda.client.event.SafeClientEvent
4+
import com.lambda.client.gui.hudgui.LabelHud
5+
import com.lambda.client.manager.managers.OnlineTimeManager
6+
import kotlin.math.roundToInt
7+
import kotlin.time.DurationUnit
8+
import kotlin.time.toDuration
9+
10+
internal object OnlineTime: LabelHud(
11+
name = "OnlineTime",
12+
category = Category.MISC,
13+
description = "Displays how long you have been online"
14+
) {
15+
override fun SafeClientEvent.updateText() {
16+
val onlineTime = OnlineTimeManager.getOnlineTime().toDouble(DurationUnit.SECONDS).roundToInt()
17+
displayText.add("Online:", secondaryColor)
18+
displayText.add(onlineTime.toDuration(DurationUnit.SECONDS).toString(), primaryColor)
19+
}
20+
}

src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/Time.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ internal object Time : LabelHud(
1515
private val showTime = setting("Show Time", true)
1616
private val dateFormat = setting("Date Format", TimeUtils.DateFormat.DDMMYY, { showDate.value })
1717
private val timeFormat = setting("Time Format", TimeUtils.TimeFormat.HHMM, { showTime.value })
18+
private val cutoffTimeLeadingZero = setting("Cutoff Time Leading Zero", true, { showTime.value })
1819
private val timeUnit = setting("Time Unit", TimeUtils.TimeUnit.H12, { showTime.value })
1920

2021
override fun SafeClientEvent.updateText() {
@@ -24,7 +25,8 @@ internal object Time : LabelHud(
2425
displayText.addLine("")
2526
}
2627
if (showTime.value) {
27-
val time = TimeUtils.getTime(timeFormat.value, timeUnit.value)
28+
var time = TimeUtils.getTime(timeFormat.value, timeUnit.value)
29+
if (cutoffTimeLeadingZero.value && time.isNotEmpty() && time[0] == '0') time = time.removeRange(0, 1)
2830
time.forEach { displayText.add(it.toString(), if (it.isDigit()) primaryColor else secondaryColor) }
2931
}
3032
}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
package com.lambda.client.gui.hudgui.elements.player
22

3+
import com.lambda.client.commons.interfaces.DisplayEnum
34
import com.lambda.client.event.SafeClientEvent
45
import com.lambda.client.gui.hudgui.LabelHud
56
import com.lambda.client.util.math.Direction
67

78
internal object Direction : LabelHud(
89
name = "Direction",
910
category = Category.PLAYER,
10-
description = "Direction of player facing to"
11+
description = "Displays the direction you are facing"
1112
) {
13+
private val directionDisplayMode by setting("Direction Format", DirectionFormat.XZ)
14+
15+
enum class DirectionFormat(override val displayName: String): DisplayEnum {
16+
NAME("Name"), XZ("XZ"), BOTH("Both")
17+
}
1218

1319
override fun SafeClientEvent.updateText() {
1420
val entity = mc.renderViewEntity ?: player
1521
val direction = Direction.fromEntity(entity)
16-
displayText.add(direction.displayName, secondaryColor)
17-
displayText.add("(${direction.displayNameXY})", primaryColor)
22+
if (directionDisplayMode == DirectionFormat.NAME || directionDisplayMode == DirectionFormat.BOTH)
23+
displayText.add(direction.displayName, secondaryColor)
24+
if (directionDisplayMode == DirectionFormat.XZ || directionDisplayMode == DirectionFormat.BOTH)
25+
displayText.add("(${direction.displayNameXY})", primaryColor)
1826
}
1927

2028
}

src/main/kotlin/com/lambda/client/gui/hudgui/elements/player/Rotation.kt

+12-7
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,20 @@ internal object Rotation : LabelHud(
1010
category = Category.PLAYER,
1111
description = "Player rotation"
1212
) {
13+
private val yaw by setting("Yaw", true)
14+
private val pitch by setting("Pitch", true)
1315

1416
override fun SafeClientEvent.updateText() {
15-
val yaw = MathUtils.round(RotationUtils.normalizeAngle(mc.player?.rotationYaw ?: 0.0f), 1)
16-
val pitch = MathUtils.round(mc.player?.rotationPitch ?: 0.0f, 1)
17-
18-
displayText.add("Yaw", secondaryColor)
19-
displayText.add(yaw.toString(), primaryColor)
20-
displayText.add("Pitch", secondaryColor)
21-
displayText.add(pitch.toString(), primaryColor)
17+
if (yaw) {
18+
val yawVal = MathUtils.round(RotationUtils.normalizeAngle(mc.player?.rotationYaw ?: 0.0f), 1)
19+
displayText.add("Yaw", secondaryColor)
20+
displayText.add(yawVal.toString(), primaryColor)
21+
}
22+
if (pitch) {
23+
val pitchVal = MathUtils.round(mc.player?.rotationPitch ?: 0.0f, 1)
24+
displayText.add("Pitch", secondaryColor)
25+
displayText.add(pitchVal.toString(), primaryColor)
26+
}
2227
}
2328

2429
}

src/main/kotlin/com/lambda/client/gui/hudgui/elements/world/Coordinates.kt

+21-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ internal object Coordinates : LabelHud(
1515
private val showX by setting("Show X", true)
1616
private val showY by setting("Show Y", true)
1717
private val showZ by setting("Show Z", true)
18+
private val showXYZText by setting("Show XYZ Text", true)
1819
private val showNetherOverworld by setting("Show Nether/Overworld", true)
20+
private val printDimensionName by setting("Print Dimension Name", false)
21+
private val showNetherOverworldMultiline by setting("Show Nether/Overworld Multiline", false, { showNetherOverworld })
1922
private val decimalPlaces by setting("Decimal Places", 1, 0..4, 1)
2023
private val thousandsSeparator by setting("Thousands Separator", false)
2124

@@ -24,42 +27,48 @@ internal object Coordinates : LabelHud(
2427

2528
override fun SafeClientEvent.updateText() {
2629
val entity = mc.renderViewEntity ?: player
27-
28-
displayText.add("XYZ", secondaryColor)
29-
displayText.addLine(getFormattedCoords(entity.positionVector))
30-
30+
if (showXYZText) {
31+
displayText.add("XYZ", secondaryColor)
32+
}
33+
if (showNetherOverworldMultiline)
34+
displayText.addLine(getFormattedCoords(entity.positionVector))
35+
else
36+
displayText.add(getFormattedCoords(entity.positionVector))
3137
if (showNetherOverworld) {
32-
when (entity.dimension) {
38+
when (world.provider.dimension) {
3339
-1 -> { // Nether
34-
displayText.add("Overworld", secondaryColor)
35-
displayText.addLine(getFormattedCoords(entity.positionVector * netherToOverworld))
40+
if (printDimensionName) displayText.add("Nether", secondaryColor)
41+
displayText.add(getFormattedCoords(entity.positionVector * netherToOverworld, true))
3642
}
3743
0 -> { // Overworld
38-
displayText.add("Nether", secondaryColor)
39-
displayText.addLine(getFormattedCoords(entity.positionVector * overworldToNether))
44+
if (printDimensionName)
45+
displayText.add("Overworld", secondaryColor)
46+
displayText.add(getFormattedCoords(entity.positionVector * overworldToNether, true))
4047
}
4148
}
4249
}
4350
}
4451

45-
private fun getFormattedCoords(pos: Vec3d): TextComponent.TextElement {
52+
private fun getFormattedCoords(pos: Vec3d, brackets: Boolean = false): TextComponent.TextElement {
53+
if (!showX && !showY && !showZ) return TextComponent.TextElement("", primaryColor)
4654
val x = roundOrInt(pos.x)
4755
val y = roundOrInt(pos.y)
4856
val z = roundOrInt(pos.z)
4957
return StringBuilder().run {
58+
if (brackets) append("[")
5059
if (showX) append(x)
5160
if (showY) appendWithComma(y)
5261
if (showZ) appendWithComma(z)
62+
if (brackets) append("]")
5363
TextComponent.TextElement(toString(), primaryColor)
5464
}
5565
}
5666

5767
private fun roundOrInt(input: Double): String {
5868
val separatorFormat = if (thousandsSeparator) "," else ""
59-
6069
return "%$separatorFormat.${decimalPlaces}f".format(input)
6170
}
6271

63-
private fun StringBuilder.appendWithComma(string: String) = append(if (length > 0) ", $string" else string)
72+
private fun StringBuilder.appendWithComma(string: String) = append(if (isNotEmpty()) ", $string" else string)
6473

6574
}

src/main/kotlin/com/lambda/client/gui/hudgui/elements/world/Radar.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ internal object Radar : HudElement(
3535
private val neutral = setting("Neutral Mobs", true)
3636
private val hostile = setting("Hostile Mobs", true)
3737
private val invisible = setting("Invisible Entities", true)
38+
private val rotation by setting("Rotation", true)
3839

3940
override val hudWidth: Float = 130.0f
4041
override val hudHeight: Float = 130.0f
@@ -56,7 +57,7 @@ internal object Radar : HudElement(
5657
glTranslated(radius.toDouble(), radius.toDouble(), 0.0)
5758
drawCircleFilled(vertexHelper, radius = radius.toDouble(), color = GuiColors.backGround)
5859
drawCircleOutline(vertexHelper, radius = radius.toDouble(), lineWidth = 1.8f, color = primaryColor)
59-
glRotatef(player.rotationYaw + 180, 0f, 0f, -1f)
60+
if (rotation) glRotatef(player.rotationYaw + 180, 0f, 0f, -1f)
6061
}
6162

6263
private fun SafeClientEvent.drawEntities(vertexHelper: VertexHelper) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ open class WindowComponent(
8989
if (mouseState != MouseState.DRAG) updatePreDrag(mousePos.minus(posX, posY))
9090
}
9191

92-
private fun updatePreDrag(mousePos: Vec2f?) {
92+
protected fun updatePreDrag(mousePos: Vec2f?) {
9393
mousePos?.let { preDragMousePos = it }
9494
preDragPos = Vec2f(posX, posY)
9595
preDragSize = Vec2f(width, height)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.lambda.client.manager.managers
2+
3+
import com.lambda.client.event.events.ConnectionEvent
4+
import com.lambda.client.event.listener.listener
5+
import com.lambda.client.manager.Manager
6+
import kotlin.time.Duration
7+
import kotlin.time.TimeSource
8+
9+
object OnlineTimeManager: Manager {
10+
11+
private var connectTime = TimeSource.Monotonic.markNow()
12+
13+
init {
14+
listener<ConnectionEvent.Connect> {
15+
connectTime = TimeSource.Monotonic.markNow()
16+
}
17+
}
18+
19+
fun getOnlineTime(): Duration {
20+
return connectTime.elapsedNow()
21+
}
22+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ 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 textShadow by setting("Text Shadow", true)
1718
val chatSnap by setting("Chat Snap", true)
1819
val collisionSnapping by setting("Collision Snapping", true)
1920
}

0 commit comments

Comments
 (0)