From 2dcd79fdbd0b596da9dfd3ea07bac4e04ca67596 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Fri, 23 Sep 2022 00:19:24 -0700 Subject: [PATCH 1/4] Bindings list HUD element (cherry picked from commit ccc4cade1b1d046c7fc9092daa866b4bed0f2901) --- .../gui/hudgui/elements/client/Bindings.kt | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/Bindings.kt diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/Bindings.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/Bindings.kt new file mode 100644 index 000000000..471b29004 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/Bindings.kt @@ -0,0 +1,111 @@ +package com.lambda.client.gui.hudgui.elements.client + +import com.lambda.client.commons.extension.sumByFloat +import com.lambda.client.commons.interfaces.DisplayEnum +import com.lambda.client.gui.hudgui.HudElement +import com.lambda.client.module.AbstractModule +import com.lambda.client.module.ModuleManager +import com.lambda.client.util.AsyncCachedValue +import com.lambda.client.util.TimeUnit +import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.graphics.VertexHelper +import com.lambda.client.util.graphics.font.FontRenderAdapter +import com.lambda.client.util.graphics.font.HAlign +import com.lambda.client.util.graphics.font.TextComponent +import com.lambda.client.util.graphics.font.VAlign +import com.lambda.client.util.threads.safeAsyncListener +import net.minecraft.client.renderer.GlStateManager +import net.minecraftforge.fml.common.gameevent.TickEvent +import kotlin.math.max + +internal object Bindings : HudElement( + name = "Bindings", + category = Category.CLIENT, + description = "Display current module keybindings", + enabledByDefault = false +) { + private val sortingMode by setting("Sorting Mode", SortingMode.LENGTH) + private val disabledColor by setting("Disabled Color", ColorHolder(255, 255, 255), false) + private val enabledColor by setting("Enabled Color", ColorHolder(0, 255, 0), false) + + private var cacheWidth = 20.0f + private var cacheHeight = 20.0f + override val hudWidth: Float get() = cacheWidth + override val hudHeight: Float get() = cacheHeight + + @Suppress("UNUSED") + private enum class SortingMode( + override val displayName: String, + val comparator: Comparator + ) : DisplayEnum { + LENGTH("Length", compareByDescending { it.textLine.getWidth() }), + ALPHABET("Alphabet", compareBy { it.name }), + CATEGORY("Category", compareBy { it.category.ordinal }) + } + + private var modulesWithBindings: List = emptyList() + private val lineHeight = FontRenderAdapter.getFontHeight() + 2.0f + + init { + relativePosX = -2.0f + relativePosY = 2.0f + dockingH = HAlign.RIGHT + + safeAsyncListener {event -> + if (event.phase != TickEvent.Phase.END) return@safeAsyncListener + // this isn't terribly efficient, consider creating events for editing bindings and module toggle state + modulesWithBindings = sortedModuleList + .filter { it.bind.value.isEmpty.not() } + cacheWidth = modulesWithBindings.maxOfOrNull { + it.textLine.getWidth() + 4.0f + } ?: 20.0f + cacheHeight = max(modulesWithBindings.sumByFloat { lineHeight }, 20.0f) + } + } + + override fun renderHud(vertexHelper: VertexHelper) { + super.renderHud(vertexHelper) + GlStateManager.pushMatrix() + GlStateManager.translate(width / scale * dockingH.multiplier, 0.0f, 0.0f) + if (dockingV == VAlign.BOTTOM) { + GlStateManager.translate(0.0f, height / scale - (FontRenderAdapter.getFontHeight() + 2.0f), 0.0f) + } + + drawModuleList() + + GlStateManager.popMatrix() + } + + private fun drawModuleList() { + for (module in modulesWithBindings) { + GlStateManager.pushMatrix() + val textLine = module.textLine + val textWidth = textLine.getWidth() + val stringPosX = textWidth * dockingH.multiplier + val margin = 2.0f * dockingH.offset + GlStateManager.translate(-stringPosX - margin, 0.0f, 0.0f) + textLine.drawLine(1.0f, true, HAlign.LEFT, FontRenderAdapter.useCustomFont) + GlStateManager.popMatrix() + var yOffset = lineHeight + if (dockingV == VAlign.BOTTOM) yOffset *= -1.0f + GlStateManager.translate(0.0f, yOffset, 0.0f) + } + } + + private val AbstractModule.textLine get() = this.newTextLine() + + private val sortedModuleList: List by AsyncCachedValue(1L, TimeUnit.SECONDS) { + ModuleManager.modules + .filter { it.category != com.lambda.client.module.Category.CLIENT} + .sortedWith(this.sortingMode.comparator) + } + + private fun AbstractModule.newTextLine() = + TextComponent.TextLine(" ").apply { + val lineColor: ColorHolder = if (isEnabled) enabledColor else disabledColor + add(TextComponent.TextElement(name, lineColor)) + add(TextComponent.TextElement("[" + bind.value.toString() + "]", lineColor)) + if (dockingH == HAlign.RIGHT) reverse() + } + +} \ No newline at end of file From 821a08df15fe3f198cc68e9f73b826d8c389dc05 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Fri, 23 Sep 2022 21:05:57 -0700 Subject: [PATCH 2/4] settings for text shadow and line v spacing --- .../gui/hudgui/elements/client/Bindings.kt | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/Bindings.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/Bindings.kt index 471b29004..9dbbda3e9 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/Bindings.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/Bindings.kt @@ -22,16 +22,23 @@ internal object Bindings : HudElement( name = "Bindings", category = Category.CLIENT, description = "Display current module keybindings", - enabledByDefault = false + enabledByDefault = true ) { private val sortingMode by setting("Sorting Mode", SortingMode.LENGTH) private val disabledColor by setting("Disabled Color", ColorHolder(255, 255, 255), false) private val enabledColor by setting("Enabled Color", ColorHolder(0, 255, 0), false) + private val textShadow by setting("Text Shadow", true) + private val textVSpacing by setting("Line Vert. Spacing", 2.0f, 0.0f..5.0f, 0.01f, + consumer = { prev, value -> + lineHeight = FontRenderAdapter.getFontHeight() + value + return@setting value + }) - private var cacheWidth = 20.0f - private var cacheHeight = 20.0f - override val hudWidth: Float get() = cacheWidth - override val hudHeight: Float get() = cacheHeight + private const val defaultSize = 20.0f // width or height + private var hudElementWidth = defaultSize + private var hudElementHeight = defaultSize + override val hudWidth: Float get() = hudElementWidth + override val hudHeight: Float get() = hudElementHeight @Suppress("UNUSED") private enum class SortingMode( @@ -44,22 +51,19 @@ internal object Bindings : HudElement( } private var modulesWithBindings: List = emptyList() - private val lineHeight = FontRenderAdapter.getFontHeight() + 2.0f + private var lineHeight: Float = FontRenderAdapter.getFontHeight() + 2.0f init { - relativePosX = -2.0f - relativePosY = 2.0f dockingH = HAlign.RIGHT - safeAsyncListener {event -> if (event.phase != TickEvent.Phase.END) return@safeAsyncListener // this isn't terribly efficient, consider creating events for editing bindings and module toggle state modulesWithBindings = sortedModuleList - .filter { it.bind.value.isEmpty.not() } - cacheWidth = modulesWithBindings.maxOfOrNull { + .filterNot { it.bind.value.isEmpty } + hudElementWidth = modulesWithBindings.maxOfOrNull { it.textLine.getWidth() + 4.0f - } ?: 20.0f - cacheHeight = max(modulesWithBindings.sumByFloat { lineHeight }, 20.0f) + } ?: defaultSize + hudElementHeight = max(modulesWithBindings.sumByFloat { lineHeight }, defaultSize) } } @@ -68,7 +72,7 @@ internal object Bindings : HudElement( GlStateManager.pushMatrix() GlStateManager.translate(width / scale * dockingH.multiplier, 0.0f, 0.0f) if (dockingV == VAlign.BOTTOM) { - GlStateManager.translate(0.0f, height / scale - (FontRenderAdapter.getFontHeight() + 2.0f), 0.0f) + GlStateManager.translate(0.0f, height / scale - lineHeight, 0.0f) } drawModuleList() @@ -81,10 +85,10 @@ internal object Bindings : HudElement( GlStateManager.pushMatrix() val textLine = module.textLine val textWidth = textLine.getWidth() - val stringPosX = textWidth * dockingH.multiplier + val stringPosX = textWidth * -dockingH.multiplier val margin = 2.0f * dockingH.offset - GlStateManager.translate(-stringPosX - margin, 0.0f, 0.0f) - textLine.drawLine(1.0f, true, HAlign.LEFT, FontRenderAdapter.useCustomFont) + GlStateManager.translate(stringPosX - margin, 0.0f, 0.0f) + textLine.drawLine(1.0f, textShadow, HAlign.LEFT, FontRenderAdapter.useCustomFont) GlStateManager.popMatrix() var yOffset = lineHeight if (dockingV == VAlign.BOTTOM) yOffset *= -1.0f From b32808b3eaf6ab14b6a11e3de0645962f78a42d2 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Fri, 23 Sep 2022 21:18:53 -0700 Subject: [PATCH 3/4] ignore client bindings setting --- .../gui/hudgui/elements/client/Bindings.kt | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/Bindings.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/Bindings.kt index 9dbbda3e9..f500cec0b 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/Bindings.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/Bindings.kt @@ -22,17 +22,19 @@ internal object Bindings : HudElement( name = "Bindings", category = Category.CLIENT, description = "Display current module keybindings", - enabledByDefault = true + enabledByDefault = false ) { private val sortingMode by setting("Sorting Mode", SortingMode.LENGTH) private val disabledColor by setting("Disabled Color", ColorHolder(255, 255, 255), false) private val enabledColor by setting("Enabled Color", ColorHolder(0, 255, 0), false) private val textShadow by setting("Text Shadow", true) - private val textVSpacing by setting("Line Vert. Spacing", 2.0f, 0.0f..5.0f, 0.01f, - consumer = { prev, value -> - lineHeight = FontRenderAdapter.getFontHeight() + value + private val textVSpacing by setting("Line V Spacing", 2.0f, 0.0f..5.0f, 0.01f, + consumer = { _, value -> + this.lineHeight = FontRenderAdapter.getFontHeight() + value return@setting value }) + private val ignoreClientBindings by setting("Ignore Client Category", true, + description = "Ignore bindings for client specific bindings like the ClickGUI") private const val defaultSize = 20.0f // width or height private var hudElementWidth = defaultSize @@ -58,7 +60,9 @@ internal object Bindings : HudElement( safeAsyncListener {event -> if (event.phase != TickEvent.Phase.END) return@safeAsyncListener // this isn't terribly efficient, consider creating events for editing bindings and module toggle state - modulesWithBindings = sortedModuleList + modulesWithBindings = ModuleManager.modules + .sortedWith(sortingMode.comparator) + .filter { if (ignoreClientBindings) it.category != com.lambda.client.module.Category.CLIENT else true} .filterNot { it.bind.value.isEmpty } hudElementWidth = modulesWithBindings.maxOfOrNull { it.textLine.getWidth() + 4.0f @@ -98,12 +102,6 @@ internal object Bindings : HudElement( private val AbstractModule.textLine get() = this.newTextLine() - private val sortedModuleList: List by AsyncCachedValue(1L, TimeUnit.SECONDS) { - ModuleManager.modules - .filter { it.category != com.lambda.client.module.Category.CLIENT} - .sortedWith(this.sortingMode.comparator) - } - private fun AbstractModule.newTextLine() = TextComponent.TextLine(" ").apply { val lineColor: ColorHolder = if (isEnabled) enabledColor else disabledColor From de865c62cb9a7a16ec57a64c616c943a2fbf7711 Mon Sep 17 00:00:00 2001 From: Constructor Date: Tue, 4 Oct 2022 01:31:03 +0200 Subject: [PATCH 4/4] Changed to LabelHud sry but is way less code and same features --- .../gui/hudgui/elements/client/Bindings.kt | 86 +++---------------- 1 file changed, 14 insertions(+), 72 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/Bindings.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/Bindings.kt index f500cec0b..188752379 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/Bindings.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/Bindings.kt @@ -1,113 +1,55 @@ package com.lambda.client.gui.hudgui.elements.client -import com.lambda.client.commons.extension.sumByFloat import com.lambda.client.commons.interfaces.DisplayEnum -import com.lambda.client.gui.hudgui.HudElement +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.gui.hudgui.LabelHud import com.lambda.client.module.AbstractModule import com.lambda.client.module.ModuleManager -import com.lambda.client.util.AsyncCachedValue -import com.lambda.client.util.TimeUnit import com.lambda.client.util.color.ColorHolder -import com.lambda.client.util.graphics.VertexHelper -import com.lambda.client.util.graphics.font.FontRenderAdapter import com.lambda.client.util.graphics.font.HAlign -import com.lambda.client.util.graphics.font.TextComponent -import com.lambda.client.util.graphics.font.VAlign import com.lambda.client.util.threads.safeAsyncListener -import net.minecraft.client.renderer.GlStateManager import net.minecraftforge.fml.common.gameevent.TickEvent -import kotlin.math.max -internal object Bindings : HudElement( +internal object Bindings : LabelHud( name = "Bindings", category = Category.CLIENT, - description = "Display current module keybindings", - enabledByDefault = false + description = "Display current module keybindings" ) { + private val sortingMode by setting("Sorting Mode", SortingMode.LENGTH) - private val disabledColor by setting("Disabled Color", ColorHolder(255, 255, 255), false) - private val enabledColor by setting("Enabled Color", ColorHolder(0, 255, 0), false) - private val textShadow by setting("Text Shadow", true) - private val textVSpacing by setting("Line V Spacing", 2.0f, 0.0f..5.0f, 0.01f, - consumer = { _, value -> - this.lineHeight = FontRenderAdapter.getFontHeight() + value - return@setting value - }) private val ignoreClientBindings by setting("Ignore Client Category", true, description = "Ignore bindings for client specific bindings like the ClickGUI") - private const val defaultSize = 20.0f // width or height - private var hudElementWidth = defaultSize - private var hudElementHeight = defaultSize - override val hudWidth: Float get() = hudElementWidth - override val hudHeight: Float get() = hudElementHeight - @Suppress("UNUSED") private enum class SortingMode( override val displayName: String, val comparator: Comparator ) : DisplayEnum { - LENGTH("Length", compareByDescending { it.textLine.getWidth() }), + LENGTH("Length", compareByDescending { it.name.length }), ALPHABET("Alphabet", compareBy { it.name }), CATEGORY("Category", compareBy { it.category.ordinal }) } private var modulesWithBindings: List = emptyList() - private var lineHeight: Float = FontRenderAdapter.getFontHeight() + 2.0f init { dockingH = HAlign.RIGHT - safeAsyncListener {event -> + + safeAsyncListener { event -> if (event.phase != TickEvent.Phase.END) return@safeAsyncListener + // this isn't terribly efficient, consider creating events for editing bindings and module toggle state modulesWithBindings = ModuleManager.modules .sortedWith(sortingMode.comparator) - .filter { if (ignoreClientBindings) it.category != com.lambda.client.module.Category.CLIENT else true} + .filter { if (ignoreClientBindings) it.category != com.lambda.client.module.Category.CLIENT else true } .filterNot { it.bind.value.isEmpty } - hudElementWidth = modulesWithBindings.maxOfOrNull { - it.textLine.getWidth() + 4.0f - } ?: defaultSize - hudElementHeight = max(modulesWithBindings.sumByFloat { lineHeight }, defaultSize) } } - override fun renderHud(vertexHelper: VertexHelper) { - super.renderHud(vertexHelper) - GlStateManager.pushMatrix() - GlStateManager.translate(width / scale * dockingH.multiplier, 0.0f, 0.0f) - if (dockingV == VAlign.BOTTOM) { - GlStateManager.translate(0.0f, height / scale - lineHeight, 0.0f) + override fun SafeClientEvent.updateText() { + modulesWithBindings.forEach { + displayText.add(it.name, if (it.isEnabled) ColorHolder(0, 255, 0) else primaryColor) + displayText.addLine(it.bind.toString(), secondaryColor) } - - drawModuleList() - - GlStateManager.popMatrix() } - - private fun drawModuleList() { - for (module in modulesWithBindings) { - GlStateManager.pushMatrix() - val textLine = module.textLine - val textWidth = textLine.getWidth() - val stringPosX = textWidth * -dockingH.multiplier - val margin = 2.0f * dockingH.offset - GlStateManager.translate(stringPosX - margin, 0.0f, 0.0f) - textLine.drawLine(1.0f, textShadow, HAlign.LEFT, FontRenderAdapter.useCustomFont) - GlStateManager.popMatrix() - var yOffset = lineHeight - if (dockingV == VAlign.BOTTOM) yOffset *= -1.0f - GlStateManager.translate(0.0f, yOffset, 0.0f) - } - } - - private val AbstractModule.textLine get() = this.newTextLine() - - private fun AbstractModule.newTextLine() = - TextComponent.TextLine(" ").apply { - val lineColor: ColorHolder = if (isEnabled) enabledColor else disabledColor - add(TextComponent.TextElement(name, lineColor)) - add(TextComponent.TextElement("[" + bind.value.toString() + "]", lineColor)) - if (dockingH == HAlign.RIGHT) reverse() - } - } \ No newline at end of file