Skip to content

HUD: Show time using primary and secondary colors #463

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

Merged
merged 2 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ abstract class AbstractLabelHud(
alwaysListening: Boolean,
enabledByDefault: Boolean,
config: AbstractConfig<out Nameable>,
separator: String = " ",
) : AbstractHudElement(name, alias, category, description, alwaysListening, enabledByDefault, config) {

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

protected val displayText = TextComponent()
protected val displayText = TextComponent(separator)

init {
safeAsyncListener<TickEvent.ClientTickEvent> {
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/com/lambda/client/gui/hudgui/LabelHud.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal abstract class LabelHud(
category: Category,
description: String,
alwaysListening: Boolean = false,
enabledByDefault: Boolean = false
) : AbstractLabelHud(name, alias, category, description, alwaysListening, enabledByDefault, GuiConfig),
enabledByDefault: Boolean = false,
separator: String = " ",
) : AbstractLabelHud(name, alias, category, description, alwaysListening, enabledByDefault, GuiConfig, separator),
SettingRegister<Component> by GuiConfig
14 changes: 11 additions & 3 deletions src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/Time.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import com.lambda.client.util.TimeUtils
internal object Time : LabelHud(
name = "Time",
category = Category.MISC,
description = "System date and time"
description = "System date and time",
separator = "",
) {

private val showDate = setting("Show Date", true)
Expand All @@ -17,8 +18,15 @@ internal object Time : LabelHud(
private val timeUnit = setting("Time Unit", TimeUtils.TimeUnit.H12, { showTime.value })

override fun SafeClientEvent.updateText() {
if (showDate.value) displayText.addLine(TimeUtils.getDate(dateFormat.value))
if (showTime.value) displayText.addLine(TimeUtils.getTime(timeFormat.value, timeUnit.value))
if (showDate.value) {
val date = TimeUtils.getDate(dateFormat.value)
date.forEach { displayText.add(it.toString(), if (it.isDigit()) primaryColor else secondaryColor) }
displayText.addLine("")
}
if (showTime.value) {
val time = TimeUtils.getTime(timeFormat.value, timeUnit.value)
time.forEach { displayText.add(it.toString(), if (it.isDigit()) primaryColor else secondaryColor) }
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ class TextComponent(private val separator: String = " ") {
val color = textElement.color.clone()
color.a = (color.a * alpha).toInt()
FontRenderAdapter.drawString(textElement.text, drawShadow = drawShadow, color = color, customFont = customFont, scale = textElement.scale)
val adjustedSeparator = if (separator == " " && customFont) " " else " "
val adjustedSeparator = " ".repeat(if (customFont && separator != "") max(separator.length * 1, 1) else separator.length)
glTranslatef(FontRenderAdapter.getStringWidth(textElement.text + adjustedSeparator, customFont = customFont), 0f, 0f)
}

glPopMatrix()
}

fun getWidth(customFont: Boolean = FontRenderAdapter.useCustomFont): Float {
val adjustedSeparator = if (separator == " " && customFont) " " else " "
val adjustedSeparator = " ".repeat(if (customFont && separator != "") max(separator.length * 1, 1) else separator.length)
val string = textElementList.joinToString(separator = adjustedSeparator)
return FontRenderAdapter.getStringWidth(string, customFont = customFont)
}
Expand Down