Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hud elements update #564

Merged
merged 11 commits into from
Jul 15, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ abstract class AbstractHudElement(

default.valueListeners.add { _, it ->
if (it) {
settingList.filter { it != visibleSetting && it != default }.forEach { it.resetValue() }
settingList.filter { it != visibleSetting && it != default }.forEach {
it.resetValue()
updatePreDrag(null)
}
default.value = false
MessageSendHelper.sendChatMessage("$name Set to defaults!")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.lambda.client.gui.hudgui

import com.lambda.client.commons.interfaces.Nameable
import com.lambda.client.event.SafeClientEvent
import com.lambda.client.module.modules.client.Hud
import com.lambda.client.module.modules.client.HudEditor
import com.lambda.client.setting.configs.AbstractConfig
import com.lambda.client.util.graphics.VertexHelper
Expand All @@ -23,7 +24,6 @@ abstract class AbstractLabelHud(

override val hudWidth: Float get() = displayText.getWidth() + 2.0f
override val hudHeight: Float get() = displayText.getHeight(2)

protected val displayText = TextComponent(separator)

init {
Expand All @@ -47,7 +47,8 @@ abstract class AbstractLabelHud(
displayText.draw(
Vec2d(textPosX.toDouble(), textPosY.toDouble()),
horizontalAlign = dockingH,
verticalAlign = dockingV
verticalAlign = dockingV,
drawShadow = Hud.textShadow
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.lambda.client.gui.hudgui.elements.misc

import com.lambda.client.event.SafeClientEvent
import com.lambda.client.gui.hudgui.LabelHud
import com.lambda.client.manager.managers.OnlineTimeManager
import kotlin.math.roundToInt
import kotlin.time.DurationUnit
import kotlin.time.toDuration

internal object OnlineTime: LabelHud(
name = "OnlineTime",
category = Category.MISC,
description = "Displays how long you have been online"
) {
override fun SafeClientEvent.updateText() {
val onlineTime = OnlineTimeManager.getOnlineTime().toDouble(DurationUnit.SECONDS).roundToInt()
displayText.add("Online:", secondaryColor)
displayText.add(onlineTime.toDuration(DurationUnit.SECONDS).toString(), primaryColor)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ internal object Time : LabelHud(
private val showTime = setting("Show Time", true)
private val dateFormat = setting("Date Format", TimeUtils.DateFormat.DDMMYY, { showDate.value })
private val timeFormat = setting("Time Format", TimeUtils.TimeFormat.HHMM, { showTime.value })
private val cutoffTimeLeadingZero = setting("Cutoff Time Leading Zero", true, { showTime.value })
private val timeUnit = setting("Time Unit", TimeUtils.TimeUnit.H12, { showTime.value })

override fun SafeClientEvent.updateText() {
Expand All @@ -24,7 +25,8 @@ internal object Time : LabelHud(
displayText.addLine("")
}
if (showTime.value) {
val time = TimeUtils.getTime(timeFormat.value, timeUnit.value)
var time = TimeUtils.getTime(timeFormat.value, timeUnit.value)
if (cutoffTimeLeadingZero.value && time.isNotEmpty() && time[0] == '0') time = time.removeRange(0, 1)
time.forEach { displayText.add(it.toString(), if (it.isDigit()) primaryColor else secondaryColor) }
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package com.lambda.client.gui.hudgui.elements.player

import com.lambda.client.commons.interfaces.DisplayEnum
import com.lambda.client.event.SafeClientEvent
import com.lambda.client.gui.hudgui.LabelHud
import com.lambda.client.util.math.Direction

internal object Direction : LabelHud(
name = "Direction",
category = Category.PLAYER,
description = "Direction of player facing to"
description = "Displays the direction you are facing"
) {
private val directionDisplayMode by setting("Direction Format", DirectionFormat.XZ)

enum class DirectionFormat(override val displayName: String): DisplayEnum {
NAME("Name"), XZ("XZ"), BOTH("Both")
}

override fun SafeClientEvent.updateText() {
val entity = mc.renderViewEntity ?: player
val direction = Direction.fromEntity(entity)
displayText.add(direction.displayName, secondaryColor)
displayText.add("(${direction.displayNameXY})", primaryColor)
if (directionDisplayMode == DirectionFormat.NAME || directionDisplayMode == DirectionFormat.BOTH)
displayText.add(direction.displayName, secondaryColor)
if (directionDisplayMode == DirectionFormat.XZ || directionDisplayMode == DirectionFormat.BOTH)
displayText.add("(${direction.displayNameXY})", primaryColor)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ internal object Rotation : LabelHud(
category = Category.PLAYER,
description = "Player rotation"
) {
private val yaw by setting("Yaw", true)
private val pitch by setting("Pitch", true)

override fun SafeClientEvent.updateText() {
val yaw = MathUtils.round(RotationUtils.normalizeAngle(mc.player?.rotationYaw ?: 0.0f), 1)
val pitch = MathUtils.round(mc.player?.rotationPitch ?: 0.0f, 1)

displayText.add("Yaw", secondaryColor)
displayText.add(yaw.toString(), primaryColor)
displayText.add("Pitch", secondaryColor)
displayText.add(pitch.toString(), primaryColor)
if (yaw) {
val yawVal = MathUtils.round(RotationUtils.normalizeAngle(mc.player?.rotationYaw ?: 0.0f), 1)
displayText.add("Yaw", secondaryColor)
displayText.add(yawVal.toString(), primaryColor)
}
if (pitch) {
val pitchVal = MathUtils.round(mc.player?.rotationPitch ?: 0.0f, 1)
displayText.add("Pitch", secondaryColor)
displayText.add(pitchVal.toString(), primaryColor)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ internal object Coordinates : LabelHud(
private val showX by setting("Show X", true)
private val showY by setting("Show Y", true)
private val showZ by setting("Show Z", true)
private val showXYZText by setting("Show XYZ Text", true)
private val showNetherOverworld by setting("Show Nether/Overworld", true)
private val printDimensionName by setting("Print Dimension Name", false)
private val showNetherOverworldMultiline by setting("Show Nether/Overworld Multiline", false, { showNetherOverworld })
private val decimalPlaces by setting("Decimal Places", 1, 0..4, 1)
private val thousandsSeparator by setting("Thousands Separator", false)

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

override fun SafeClientEvent.updateText() {
val entity = mc.renderViewEntity ?: player

displayText.add("XYZ", secondaryColor)
displayText.addLine(getFormattedCoords(entity.positionVector))

if (showXYZText) {
displayText.add("XYZ", secondaryColor)
}
if (showNetherOverworldMultiline)
displayText.addLine(getFormattedCoords(entity.positionVector))
else
displayText.add(getFormattedCoords(entity.positionVector))
if (showNetherOverworld) {
when (entity.dimension) {
when (world.provider.dimension) {
-1 -> { // Nether
displayText.add("Overworld", secondaryColor)
displayText.addLine(getFormattedCoords(entity.positionVector * netherToOverworld))
if (printDimensionName) displayText.add("Nether", secondaryColor)
displayText.add(getFormattedCoords(entity.positionVector * netherToOverworld, true))
}
0 -> { // Overworld
displayText.add("Nether", secondaryColor)
displayText.addLine(getFormattedCoords(entity.positionVector * overworldToNether))
if (printDimensionName)
displayText.add("Overworld", secondaryColor)
displayText.add(getFormattedCoords(entity.positionVector * overworldToNether, true))
}
}
}
}

private fun getFormattedCoords(pos: Vec3d): TextComponent.TextElement {
private fun getFormattedCoords(pos: Vec3d, brackets: Boolean = false): TextComponent.TextElement {
if (!showX && !showY && !showZ) return TextComponent.TextElement("", primaryColor)
val x = roundOrInt(pos.x)
val y = roundOrInt(pos.y)
val z = roundOrInt(pos.z)
return StringBuilder().run {
if (brackets) append("[")
if (showX) append(x)
if (showY) appendWithComma(y)
if (showZ) appendWithComma(z)
if (brackets) append("]")
TextComponent.TextElement(toString(), primaryColor)
}
}

private fun roundOrInt(input: Double): String {
val separatorFormat = if (thousandsSeparator) "," else ""

return "%$separatorFormat.${decimalPlaces}f".format(input)
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal object Radar : HudElement(
private val neutral = setting("Neutral Mobs", true)
private val hostile = setting("Hostile Mobs", true)
private val invisible = setting("Invisible Entities", true)
private val rotation by setting("Rotation", true)

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

private fun SafeClientEvent.drawEntities(vertexHelper: VertexHelper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ open class WindowComponent(
if (mouseState != MouseState.DRAG) updatePreDrag(mousePos.minus(posX, posY))
}

private fun updatePreDrag(mousePos: Vec2f?) {
protected fun updatePreDrag(mousePos: Vec2f?) {
mousePos?.let { preDragMousePos = it }
preDragPos = Vec2f(posX, posY)
preDragSize = Vec2f(width, height)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.lambda.client.manager.managers

import com.lambda.client.event.events.ConnectionEvent
import com.lambda.client.event.listener.listener
import com.lambda.client.manager.Manager
import kotlin.time.Duration
import kotlin.time.TimeSource

object OnlineTimeManager: Manager {

private var connectTime = TimeSource.Monotonic.markNow()

init {
listener<ConnectionEvent.Connect> {
connectTime = TimeSource.Monotonic.markNow()
}
}

fun getOnlineTime(): Duration {
return connectTime.elapsedNow()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ object Hud : Module(
val hudFrame by setting("Hud Frame", false)
val primaryColor by setting("Primary Color", ColorHolder(255, 240, 246), false)
val secondaryColor by setting("Secondary Color", ColorHolder(108, 0, 43), false)
val textShadow by setting("Text Shadow", true)
val chatSnap by setting("Chat Snap", true)
val collisionSnapping by setting("Collision Snapping", true)
}