From d800fbd7dfd97cae139cab67d26781fd96ce9d1b Mon Sep 17 00:00:00 2001 From: Baitinq Date: Mon, 16 Jan 2023 18:19:39 +0100 Subject: [PATCH 1/2] Allow for custom separators in the TextComponent --- .../kotlin/com/lambda/client/gui/hudgui/AbstractLabelHud.kt | 3 ++- src/main/kotlin/com/lambda/client/gui/hudgui/LabelHud.kt | 5 +++-- .../com/lambda/client/util/graphics/font/TextComponent.kt | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/AbstractLabelHud.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/AbstractLabelHud.kt index 486c7655e..c3659ea21 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/AbstractLabelHud.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/AbstractLabelHud.kt @@ -18,12 +18,13 @@ abstract class AbstractLabelHud( alwaysListening: Boolean, enabledByDefault: Boolean, config: AbstractConfig, + 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 { diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/LabelHud.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/LabelHud.kt index f0346ebdd..0af258316 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/LabelHud.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/LabelHud.kt @@ -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 by GuiConfig \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/util/graphics/font/TextComponent.kt b/src/main/kotlin/com/lambda/client/util/graphics/font/TextComponent.kt index 521af6eac..03728517c 100644 --- a/src/main/kotlin/com/lambda/client/util/graphics/font/TextComponent.kt +++ b/src/main/kotlin/com/lambda/client/util/graphics/font/TextComponent.kt @@ -147,7 +147,7 @@ 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) } @@ -155,7 +155,7 @@ class TextComponent(private val separator: String = " ") { } 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) } From 3bb5d7d04cc1195a4a7e2e387dce2df086325c5a Mon Sep 17 00:00:00 2001 From: Baitinq Date: Mon, 16 Jan 2023 19:39:05 +0100 Subject: [PATCH 2/2] HUD: Show time using primary and secondary colors Before this patch the time was always shown as white. Now we show the time/date's numeric characters in the primary color and the non numeric characters in the secondary color :) --- .../lambda/client/gui/hudgui/elements/misc/Time.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/Time.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/Time.kt index c8253a905..3ee127185 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/Time.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/Time.kt @@ -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) @@ -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) } + } } } \ No newline at end of file