From 051b9b34a91dbf257363db2decfdb868c6146c28 Mon Sep 17 00:00:00 2001 From: mems01 <70612656+mems01@users.noreply.github.com> Date: Sat, 8 Feb 2025 22:37:02 +0200 Subject: [PATCH] all styles adapt --- .../client/clickgui/elements/ModuleElement.kt | 7 + .../ui/client/clickgui/style/Style.kt | 2 + .../clickgui/style/styles/BlackStyle.kt | 183 ++++++++++++++++- .../style/styles/LiquidBounceStyle.kt | 184 +++++++++++++++++- .../client/clickgui/style/styles/NullStyle.kt | 183 ++++++++++++++++- .../clickgui/style/styles/SlowlyStyle.kt | 31 ++- 6 files changed, 543 insertions(+), 47 deletions(-) diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/elements/ModuleElement.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/elements/ModuleElement.kt index 4446bac33a5..633fba4a229 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/elements/ModuleElement.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/elements/ModuleElement.kt @@ -71,5 +71,12 @@ class ModuleElement(val module: Module) : ButtonElement(module.name, buttonActio return true } + + fun adjustWidth() { + if (settingsWidth - supposedWidth > 16) { + disableFiltering = true + settingsWidth = supposedWidth + } + } } \ No newline at end of file diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/Style.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/Style.kt index 2729ee2c886..bbd7d3a7c96 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/Style.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/Style.kt @@ -24,6 +24,8 @@ import java.math.BigDecimal import kotlin.math.max abstract class Style : MinecraftInstance { + val rgbaLabels = listOf("R:", "G:", "B:", "A:") + protected var sliderValueHeld: Value<*>? = null get() { if (!Mouse.isButtonDown(0)) field = null diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/BlackStyle.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/BlackStyle.kt index 185d526473c..3eb497c44ec 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/BlackStyle.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/BlackStyle.kt @@ -11,6 +11,7 @@ import net.ccbluex.liquidbounce.ui.client.clickgui.ClickGui.clamp import net.ccbluex.liquidbounce.ui.client.clickgui.Panel import net.ccbluex.liquidbounce.ui.client.clickgui.elements.ButtonElement import net.ccbluex.liquidbounce.ui.client.clickgui.elements.ModuleElement +import net.ccbluex.liquidbounce.ui.client.clickgui.style.EditableText import net.ccbluex.liquidbounce.ui.client.clickgui.style.Style import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolatile import net.ccbluex.liquidbounce.ui.font.Fonts.fontSemibold35 @@ -531,9 +532,11 @@ object BlackStyle : Style() { val spacingBetweenSliders = 5 + val rgbaOptionHeight = if (value.showOptions) fontSemibold35.height * 4 else 0 + val colorPickerStartX = textX.toInt() val colorPickerEndX = colorPickerStartX + colorPickerWidth - val colorPickerStartY = colorPreviewY2 + spacing / 3 + val colorPickerStartY = rgbaOptionHeight + colorPreviewY2 + spacing / 3 val colorPickerEndY = colorPickerStartY + colorPickerHeight val hueSliderStartY = colorPickerStartY @@ -566,14 +569,105 @@ object BlackStyle : Style() { } } - val display = "${value.name}: ${"#%08X".format(currentColor.rgb)}" - val combinedWidth = opacityEndX - colorPickerStartX - val optimalWidth = maxOf(fontSemibold35.getStringWidth(display), combinedWidth) + val startText = "${value.name}: " + val valueText = "#%08X".format(currentColor.rgb) + val combinedText = startText + valueText + val combinedWidth = opacityEndX - colorPickerStartX + val optimalWidth = maxOf(fontSemibold35.getStringWidth(combinedText), combinedWidth) moduleElement.settingsWidth = optimalWidth + spacing * 4 - fontSemibold35.drawString(display, textX, textY, Color.WHITE.rgb) + val valueX = startX + fontSemibold35.getStringWidth(startText) + val valueWidth = fontSemibold35.getStringWidth(valueText) + + if (mouseButton == 1 && mouseX in valueX..valueX + valueWidth && mouseY.toFloat() in textY - 2..textY + fontSemibold35.height - 3F) { + value.showOptions = !value.showOptions + + if (!value.showOptions) { + resetChosenText(value) + } + } + + val widestLabel = rgbaLabels.maxOf { fontSemibold35.getStringWidth(it) } + + var highlightCursor = {} + + chosenText?.let { + if (it.value != value) { + return@let + } + + val startValueX = textX + widestLabel + 3 + val cursorY = textY + value.rgbaIndex * fontSemibold35.height + 10 + + if (it.selectionActive()) { + val start = + startValueX + fontSemibold35.getStringWidth(it.string.take(it.selectionStart!!)) + val end = + startValueX + fontSemibold35.getStringWidth(it.string.take(it.selectionEnd!!)) + drawRect( + start, + cursorY - 3f, + end, + cursorY + fontSemibold35.fontHeight - 2, + Color(7, 152, 252).rgb + ) + } + + highlightCursor = { + val cursorX = startValueX + fontSemibold35.getStringWidth(it.cursorString) + drawRect( + cursorX, + cursorY - 3F, + cursorX + 1F, + cursorY + fontSemibold35.fontHeight - 2, + Color.WHITE.rgb + ) + } + } + + if (value.showOptions) { + val mainColor = value.get() + val rgbaValues = listOf(mainColor.red, mainColor.green, mainColor.blue, mainColor.alpha) + val rgbaYStart = textY + 10 + + var noClickAmount = 0 + + val maxWidth = fontSemibold35.getStringWidth("255") + + rgbaLabels.forEachIndexed { index, label -> + val rgbaValueText = "${rgbaValues[index]}" + val colorX = textX + widestLabel + 4 + val yPosition = rgbaYStart + index * fontSemibold35.height + + val isEmpty = chosenText?.value == value && value.rgbaIndex == index && chosenText?.string.isNullOrEmpty() + + val extraSpacing = if (isEmpty) maxWidth + 4 else 0 + val finalX = colorX + extraSpacing + + val defaultText = if (isEmpty) "($rgbaValueText)" else rgbaValueText + fontSemibold35.drawString(label, textX, yPosition, Color.WHITE.rgb) + fontSemibold35.drawString(defaultText, finalX, yPosition, Color.LIGHT_GRAY.rgb) + + if (mouseButton == 0) { + if (mouseX.toFloat() in finalX..finalX + maxWidth && mouseY.toFloat() in yPosition - 2..yPosition + 6) { + chosenText = EditableText.forRGBA(value, index) + } else { + noClickAmount++ + } + } + } + + // Were none of these labels clicked on? + if (noClickAmount == rgbaLabels.size) { + resetChosenText(value) + } + } + + fontSemibold35.drawString(combinedText, textX, textY, Color.WHITE.rgb) + + highlightCursor() val normalBorderColor = if (rainbow) 0 else Color.BLUE.rgb val rainbowBorderColor = if (rainbow) Color.BLUE.rgb else 0 @@ -809,21 +903,92 @@ object BlackStyle : Style() { ColorUtils.rainbow(alpha = value.opacitySliderY).rgb ) - yPos += spacing + yPos += spacing + rgbaOptionHeight } else -> { - val text = value.name + "§f: " + value.get() + val startText = value.name + "§f: " + var valueText = "${value.get()}" - moduleElement.settingsWidth = fontSemibold35.getStringWidth(text) + 8 + val combinedWidth = fontSemibold35.getStringWidth(startText + valueText) - fontSemibold35.drawString(text, minX + 2, yPos + 4, Color.WHITE.rgb) + moduleElement.settingsWidth = combinedWidth + 8 + + val textY = yPos + 4 + val startX = minX + 2 + var textX = startX + fontSemibold35.getStringWidth(startText) + + if (mouseButton == 0) { + chosenText = + if (mouseX in textX..maxX && mouseY in textY - 2..textY + 6 && value is TextValue) { + EditableText.forTextValue(value) + } else { + null + } + } + + val shouldPushToRight = + value is TextValue && chosenText?.value == value && chosenText?.string != value.get() + + var highlightCursor: (Int) -> Unit = {} + + chosenText?.let { + if (it.value != value) { + return@let + } + + val input = it.string + + if (it.selectionActive()) { + val start = textX - 1 + fontSemibold35.getStringWidth(input.take(it.selectionStart!!)) + val end = textX - 1 + fontSemibold35.getStringWidth(input.take(it.selectionEnd!!)) + drawRect( + start, + textY - 3, + end, + textY + fontSemibold35.fontHeight - 2, + Color(7, 152, 252).rgb + ) + } + + highlightCursor = { textX -> + val cursorX = textX + fontSemibold35.getStringWidth(input.take(it.cursorIndex)) + drawRect( + cursorX, + textY - 3, + cursorX + 1, + textY + fontSemibold35.fontHeight - 2, + Color.WHITE.rgb + ) + } + } + + fontSemibold35.drawString(startText, startX, textY, Color.WHITE.rgb) + + val defaultColor = if (shouldPushToRight) Color.LIGHT_GRAY else Color.WHITE + + val originalX = textX - 1 + + // This usually happens when a value rejects a change and auto-sets it to a default value. + if (shouldPushToRight) { + valueText = "($valueText)" + val valueWidth = fontSemibold35.getStringWidth(valueText) + moduleElement.settingsWidth = combinedWidth + valueWidth + 12 + fontSemibold35.drawString(chosenText!!.string, textX, textY, Color.WHITE.rgb) + textX += valueWidth + 4 + } + + fontSemibold35.drawString(valueText, textX, textY, defaultColor.rgb) + + highlightCursor(originalX) yPos += 12 } } } + moduleElement.adjustWidth() + moduleElement.settingsHeight = yPos - moduleElement.y - 6 if (mouseButton != null && mouseX in minX..maxX && mouseY in moduleElement.y + 6..yPos + 2) return true diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/LiquidBounceStyle.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/LiquidBounceStyle.kt index 079f83f4dfb..c3b8fccec57 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/LiquidBounceStyle.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/LiquidBounceStyle.kt @@ -12,6 +12,7 @@ import net.ccbluex.liquidbounce.ui.client.clickgui.ClickGui.clamp import net.ccbluex.liquidbounce.ui.client.clickgui.Panel import net.ccbluex.liquidbounce.ui.client.clickgui.elements.ButtonElement import net.ccbluex.liquidbounce.ui.client.clickgui.elements.ModuleElement +import net.ccbluex.liquidbounce.ui.client.clickgui.style.EditableText import net.ccbluex.liquidbounce.ui.client.clickgui.style.Style import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolatile import net.ccbluex.liquidbounce.ui.font.Fonts.fontSemibold35 @@ -506,9 +507,11 @@ object LiquidBounceStyle : Style() { val spacingBetweenSliders = 5 + val rgbaOptionHeight = if (value.showOptions) fontSemibold35.height * 4 else 0 + val colorPickerStartX = textX.toInt() val colorPickerEndX = colorPickerStartX + colorPickerWidth - val colorPickerStartY = colorPreviewY2 + spacing / 3 + val colorPickerStartY = rgbaOptionHeight + colorPreviewY2 + spacing / 3 val colorPickerEndY = colorPickerStartY + colorPickerHeight val hueSliderStartY = colorPickerStartY @@ -541,14 +544,106 @@ object LiquidBounceStyle : Style() { } } - val display = "${value.name}: ${"#%08X".format(currentColor.rgb)}" + val startText = "${value.name}: " + val valueText = "#%08X".format(currentColor.rgb) + val combinedText = startText + valueText val combinedWidth = opacityEndX - colorPickerStartX - val optimalWidth = maxOf(fontSemibold35.getStringWidth(display), combinedWidth) - + val optimalWidth = maxOf(fontSemibold35.getStringWidth(combinedText), combinedWidth) moduleElement.settingsWidth = optimalWidth + spacing * 4 - fontSemibold35.drawString(display, textX, textY, Color.WHITE.rgb) + val valueX = startX + fontSemibold35.getStringWidth(startText) + val valueWidth = fontSemibold35.getStringWidth(valueText) + + if (mouseButton == 1 && mouseX in valueX..valueX + valueWidth && mouseY.toFloat() in textY - 2..textY + fontSemibold35.height - 3F) { + value.showOptions = !value.showOptions + + if (!value.showOptions) { + resetChosenText(value) + } + } + + val widestLabel = rgbaLabels.maxOf { fontSemibold35.getStringWidth(it) } + + var highlightCursor = {} + + chosenText?.let { + if (it.value != value) { + return@let + } + + val startValueX = textX + widestLabel + 3 + val cursorY = textY + value.rgbaIndex * fontSemibold35.height + 10 + + if (it.selectionActive()) { + val start = + startValueX + fontSemibold35.getStringWidth(it.string.take(it.selectionStart!!)) + val end = + startValueX + fontSemibold35.getStringWidth(it.string.take(it.selectionEnd!!)) + drawRect( + start, + cursorY - 3f, + end, + cursorY + fontSemibold35.fontHeight - 2, + Color(7, 152, 252).rgb + ) + } + + highlightCursor = { + val cursorX = startValueX + fontSemibold35.getStringWidth(it.cursorString) + drawRect( + cursorX, + cursorY - 3F, + cursorX + 1F, + cursorY + fontSemibold35.fontHeight - 2, + Color.WHITE.rgb + ) + } + } + + if (value.showOptions) { + val mainColor = value.get() + val rgbaValues = listOf(mainColor.red, mainColor.green, mainColor.blue, mainColor.alpha) + val rgbaYStart = textY + 10 + + var noClickAmount = 0 + + val maxWidth = fontSemibold35.getStringWidth("255") + + rgbaLabels.forEachIndexed { index, label -> + val rgbaValueText = "${rgbaValues[index]}" + val colorX = textX + widestLabel + 4 + val yPosition = rgbaYStart + index * fontSemibold35.height + + val isEmpty = chosenText?.value == value && value.rgbaIndex == index && chosenText?.string.isNullOrEmpty() + + val extraSpacing = if (isEmpty) maxWidth + 4 else 0 + val finalX = colorX + extraSpacing + + val defaultColor = if (isEmpty) Color.LIGHT_GRAY else Color.RED + val defaultText = if (isEmpty) "($rgbaValueText)" else rgbaValueText + + fontSemibold35.drawString(label, textX, yPosition, Color.WHITE.rgb) + fontSemibold35.drawString(defaultText, finalX, yPosition, defaultColor.rgb) + + if (mouseButton == 0) { + if (mouseX.toFloat() in finalX..finalX + maxWidth && mouseY.toFloat() in yPosition - 2..yPosition + 6) { + chosenText = EditableText.forRGBA(value, index) + } else { + noClickAmount++ + } + } + } + + // Were none of these labels clicked on? + if (noClickAmount == rgbaLabels.size) { + resetChosenText(value) + } + } + + fontSemibold35.drawString(combinedText, textX, textY, Color.WHITE.rgb) + + highlightCursor() val normalBorderColor = if (rainbow) 0 else Color.BLUE.rgb val rainbowBorderColor = if (rainbow) Color.BLUE.rgb else 0 @@ -784,23 +879,92 @@ object LiquidBounceStyle : Style() { ColorUtils.rainbow(alpha = value.opacitySliderY).rgb ) - yPos += spacing + yPos += spacing + rgbaOptionHeight } else -> { - val text = value.name + "§f: §c" + value.get() + val startText = value.name + "§f: " + var valueText = "${value.get()}" - moduleElement.settingsWidth = fontSemibold35.getStringWidth(text) + 8 + val combinedWidth = fontSemibold35.getStringWidth(startText + valueText) - drawRect(minX, yPos + 2, maxX, yPos + 14, Int.MIN_VALUE) + moduleElement.settingsWidth = combinedWidth + 8 - fontSemibold35.drawString(text, minX + 2, yPos + 4, Color.WHITE.rgb) + val textY = yPos + 4 + val startX = minX + 2 + var textX = startX + fontSemibold35.getStringWidth(startText) + + if (mouseButton == 0) { + chosenText = + if (mouseX in textX..maxX && mouseY in textY - 2..textY + 6 && value is TextValue) { + EditableText.forTextValue(value) + } else { + null + } + } + + val shouldPushToRight = + value is TextValue && chosenText?.value == value && chosenText?.string != value.get() + + var highlightCursor: (Int) -> Unit = {} + + chosenText?.let { + if (it.value != value) { + return@let + } + + val input = it.string + + if (it.selectionActive()) { + val start = textX - 1 + fontSemibold35.getStringWidth(input.take(it.selectionStart!!)) + val end = textX - 1 + fontSemibold35.getStringWidth(input.take(it.selectionEnd!!)) + drawRect( + start, + textY - 3, + end, + textY + fontSemibold35.fontHeight - 2, + Color(7, 152, 252).rgb + ) + } + + highlightCursor = { textX -> + val cursorX = textX + fontSemibold35.getStringWidth(input.take(it.cursorIndex)) + drawRect( + cursorX, + textY - 3, + cursorX + 1, + textY + fontSemibold35.fontHeight - 2, + Color.WHITE.rgb + ) + } + } + + fontSemibold35.drawString(startText, startX, textY, Color.WHITE.rgb) + + val defaultColor = if (shouldPushToRight) Color.LIGHT_GRAY else Color.RED + + val originalX = textX - 1 + + // This usually happens when a value rejects a change and auto-sets it to a default value. + if (shouldPushToRight) { + valueText = "($valueText)" + val valueWidth = fontSemibold35.getStringWidth(valueText) + moduleElement.settingsWidth = combinedWidth + valueWidth + 12 + fontSemibold35.drawString(chosenText!!.string, textX, textY, Color.RED.rgb) + textX += valueWidth + 4 + } + + fontSemibold35.drawString(valueText, textX, textY, defaultColor.rgb) + + highlightCursor(originalX) yPos += 12 } } } + moduleElement.adjustWidth() + moduleElement.settingsHeight = yPos - moduleElement.y - 4 if (moduleElement.settingsWidth > 0 && yPos > moduleElement.y + 4) { diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/NullStyle.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/NullStyle.kt index 78b7b467a2b..e469126f426 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/NullStyle.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/NullStyle.kt @@ -12,6 +12,7 @@ import net.ccbluex.liquidbounce.ui.client.clickgui.ClickGui.clamp import net.ccbluex.liquidbounce.ui.client.clickgui.Panel import net.ccbluex.liquidbounce.ui.client.clickgui.elements.ButtonElement import net.ccbluex.liquidbounce.ui.client.clickgui.elements.ModuleElement +import net.ccbluex.liquidbounce.ui.client.clickgui.style.EditableText import net.ccbluex.liquidbounce.ui.client.clickgui.style.Style import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolatile import net.ccbluex.liquidbounce.ui.font.Fonts.fontSemibold35 @@ -474,9 +475,11 @@ object NullStyle : Style() { val spacingBetweenSliders = 5 + val rgbaOptionHeight = if (value.showOptions) fontSemibold35.height * 4 else 0 + val colorPickerStartX = textX.toInt() val colorPickerEndX = colorPickerStartX + colorPickerWidth - val colorPickerStartY = colorPreviewY2 + spacing / 3 + val colorPickerStartY = rgbaOptionHeight + colorPreviewY2 + spacing / 3 val colorPickerEndY = colorPickerStartY + colorPickerHeight val hueSliderStartY = colorPickerStartY @@ -512,14 +515,106 @@ object NullStyle : Style() { } } - val display = "${value.name}: ${"#%08X".format(currentColor.rgb)}" + val startText = "${value.name}: " + val valueText = "#%08X".format(currentColor.rgb) + val combinedText = startText + valueText val combinedWidth = opacityEndX - colorPickerStartX - val optimalWidth = maxOf(fontSemibold35.getStringWidth(display), combinedWidth) - + val optimalWidth = maxOf(fontSemibold35.getStringWidth(combinedText), combinedWidth) moduleElement.settingsWidth = optimalWidth + spacing * 4 - fontSemibold35.drawString(display, textX, textY, Color.WHITE.rgb) + val valueX = startX + fontSemibold35.getStringWidth(startText) + val valueWidth = fontSemibold35.getStringWidth(valueText) + + if (mouseButton == 1 && mouseX in valueX..valueX + valueWidth && mouseY.toFloat() in textY - 2..textY + fontSemibold35.height - 3F) { + value.showOptions = !value.showOptions + + if (!value.showOptions) { + resetChosenText(value) + } + } + + val widestLabel = rgbaLabels.maxOf { fontSemibold35.getStringWidth(it) } + + var highlightCursor = {} + + chosenText?.let { + if (it.value != value) { + return@let + } + + val startValueX = textX + widestLabel + 3 + val cursorY = textY + value.rgbaIndex * fontSemibold35.height + 10 + + if (it.selectionActive()) { + val start = + startValueX + fontSemibold35.getStringWidth(it.string.take(it.selectionStart!!)) + val end = + startValueX + fontSemibold35.getStringWidth(it.string.take(it.selectionEnd!!)) + drawRect( + start, + cursorY - 3f, + end, + cursorY + fontSemibold35.fontHeight - 2, + Color(7, 152, 252).rgb + ) + } + + highlightCursor = { + val cursorX = startValueX + fontSemibold35.getStringWidth(it.cursorString) + drawRect( + cursorX, + cursorY - 3F, + cursorX + 1F, + cursorY + fontSemibold35.fontHeight - 2, + Color.WHITE.rgb + ) + } + } + + if (value.showOptions) { + val mainColor = value.get() + val rgbaValues = listOf(mainColor.red, mainColor.green, mainColor.blue, mainColor.alpha) + val rgbaYStart = textY + 10 + + var noClickAmount = 0 + + val maxWidth = fontSemibold35.getStringWidth("255") + + rgbaLabels.forEachIndexed { index, label -> + val rgbaValueText = "${rgbaValues[index]}" + val colorX = textX + widestLabel + 4 + val yPosition = rgbaYStart + index * fontSemibold35.height + + val isEmpty = chosenText?.value == value && value.rgbaIndex == index && chosenText?.string.isNullOrEmpty() + + val extraSpacing = if (isEmpty) maxWidth + 4 else 0 + val finalX = colorX + extraSpacing + + val defaultColor = if (isEmpty) Color.LIGHT_GRAY else Color.RED + val defaultText = if (isEmpty) "($rgbaValueText)" else rgbaValueText + + fontSemibold35.drawString(label, textX, yPosition, Color.WHITE.rgb) + fontSemibold35.drawString(defaultText, finalX, yPosition, defaultColor.rgb) + + if (mouseButton == 0) { + if (mouseX.toFloat() in finalX..finalX + maxWidth && mouseY.toFloat() in yPosition - 2..yPosition + 6) { + chosenText = EditableText.forRGBA(value, index) + } else { + noClickAmount++ + } + } + } + + // Were none of these labels clicked on? + if (noClickAmount == rgbaLabels.size) { + resetChosenText(value) + } + } + + fontSemibold35.drawString(combinedText, textX, textY, Color.WHITE.rgb) + + highlightCursor() val normalBorderColor = if (rainbow) 0 else Color.BLUE.rgb val rainbowBorderColor = if (rainbow) Color.BLUE.rgb else 0 @@ -734,23 +829,91 @@ object NullStyle : Style() { ColorUtils.rainbow(alpha = value.opacitySliderY).rgb ) - yPos += spacing + yPos += spacing + rgbaOptionHeight } else -> { - val text = value.name + "§f: §c" + value.get() + val startText = value.name + "§f: " + var valueText = "${value.get()}" - moduleElement.settingsWidth = fontSemibold35.getStringWidth(text) + 8 + val combinedWidth = fontSemibold35.getStringWidth(startText + valueText) - drawRect(minX, yPos + 2, maxX, yPos + 14, Int.MIN_VALUE) + moduleElement.settingsWidth = combinedWidth + 8 - fontSemibold35.drawString(text, minX + 2, yPos + 4, Color.WHITE.rgb) + val textY = yPos + 4 + val startX = minX + 2 + var textX = startX + fontSemibold35.getStringWidth(startText) + + if (mouseButton == 0) { + chosenText = + if (mouseX in textX..maxX && mouseY in textY - 2..textY + 6 && value is TextValue) { + EditableText.forTextValue(value) + } else { + null + } + } + + val shouldPushToRight = + value is TextValue && chosenText?.value == value && chosenText?.string != value.get() + + var highlightCursor: (Int) -> Unit = {} + + chosenText?.let { + if (it.value != value) { + return@let + } + + val input = it.string + + if (it.selectionActive()) { + val start = textX - 1 + fontSemibold35.getStringWidth(input.take(it.selectionStart!!)) + val end = textX - 1 + fontSemibold35.getStringWidth(input.take(it.selectionEnd!!)) + drawRect( + start, + textY - 3, + end, + textY + fontSemibold35.fontHeight - 2, + Color(7, 152, 252).rgb + ) + } + + highlightCursor = { textX -> + val cursorX = textX + fontSemibold35.getStringWidth(input.take(it.cursorIndex)) + drawRect( + cursorX, + textY - 3, + cursorX + 1, + textY + fontSemibold35.fontHeight - 2, + Color.WHITE.rgb + ) + } + } + + fontSemibold35.drawString(startText, startX, textY, Color.WHITE.rgb) + + val defaultColor = if (shouldPushToRight) Color.LIGHT_GRAY else Color.RED + val originalX = textX - 1 + + // This usually happens when a value rejects a change and auto-sets it to a default value. + if (shouldPushToRight) { + valueText = "($valueText)" + val valueWidth = fontSemibold35.getStringWidth(valueText) + moduleElement.settingsWidth = combinedWidth + valueWidth + 12 + fontSemibold35.drawString(chosenText!!.string, textX, textY, Color.RED.rgb) + textX += valueWidth + 4 + } + + fontSemibold35.drawString(valueText, textX, textY, defaultColor.rgb) + + highlightCursor(originalX) yPos += 12 } } } + moduleElement.adjustWidth() + moduleElement.settingsHeight = yPos - moduleElement.y - 4 if (moduleElement.settingsWidth > 0 && yPos > moduleElement.y + 4) { diff --git a/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/SlowlyStyle.kt b/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/SlowlyStyle.kt index 118435058d1..71f9cc7c88e 100644 --- a/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/SlowlyStyle.kt +++ b/src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/SlowlyStyle.kt @@ -591,7 +591,6 @@ object SlowlyStyle : Style() { } } - val rgbaLabels = listOf("R:", "G:", "B:", "A:") val widestLabel = rgbaLabels.maxOf { fontSemibold35.getStringWidth(it) } var highlightCursor = {} @@ -642,22 +641,20 @@ object SlowlyStyle : Style() { rgbaLabels.forEachIndexed { index, label -> val rgbaValueText = "${rgbaValues[index]}" val colorX = textX + widestLabel + 4 - val yPosition = rgbaYStart + (index * fontSemibold35.height) + val yPosition = rgbaYStart + index * fontSemibold35.height - val extraSpacing = - if (chosenText?.value == value && value.rgbaIndex == index && chosenText?.string.isNullOrEmpty()) { - maxWidth - } else 0 + val isEmpty = chosenText?.value == value && value.rgbaIndex == index && chosenText?.string.isNullOrEmpty() + + val extraSpacing = if (isEmpty) maxWidth + 4 else 0 val finalX = colorX + extraSpacing + val defaultText = if (isEmpty) "($rgbaValueText)" else rgbaValueText fontSemibold35.drawString(label, textX, yPosition, Color.WHITE.rgb) - fontSemibold35.drawString(rgbaValueText, finalX, yPosition, Color.LIGHT_GRAY.rgb) + fontSemibold35.drawString(defaultText, finalX, yPosition, Color.LIGHT_GRAY.rgb) if (mouseButton == 0) { if (mouseX.toFloat() in finalX..finalX + maxWidth && mouseY.toFloat() in yPosition - 2..yPosition + 6) { chosenText = EditableText.forRGBA(value, index) - - value.rgbaIndex = index } else { noClickAmount++ } @@ -890,10 +887,9 @@ object SlowlyStyle : Style() { else -> { val startText = value.name + "§f: " - val valueText = "${value.get()}" + var valueText = "${value.get()}" val combinedWidth = fontSemibold35.getStringWidth(startText + valueText) - val valueWidth = fontSemibold35.getStringWidth(valueText) moduleElement.settingsWidth = combinedWidth + 8 @@ -923,8 +919,8 @@ object SlowlyStyle : Style() { val input = it.string if (it.selectionActive()) { - val start = textX + fontSemibold35.getStringWidth(input.take(it.selectionStart!!)) - val end = textX + fontSemibold35.getStringWidth(input.take(it.selectionEnd!!)) + val start = textX - 1 + fontSemibold35.getStringWidth(input.take(it.selectionStart!!)) + val end = textX - 1 + fontSemibold35.getStringWidth(input.take(it.selectionEnd!!)) drawRect( start, textY - 3, @@ -954,7 +950,9 @@ object SlowlyStyle : Style() { // This usually happens when a value rejects a change and auto-sets it to a default value. if (shouldPushToRight) { - moduleElement.settingsWidth = combinedWidth + valueWidth + 12 + valueText = "($valueText)" + val valueWidth = fontSemibold35.getStringWidth(valueText) + moduleElement.settingsWidth = combinedWidth + valueWidth + 16 fontSemibold35.drawString(chosenText!!.string, textX, textY, Color.WHITE.rgb) textX += valueWidth + 4 } @@ -968,10 +966,7 @@ object SlowlyStyle : Style() { } } - if (moduleElement.settingsWidth - moduleElement.supposedWidth > 16) { - moduleElement.disableFiltering = true - moduleElement.settingsWidth = moduleElement.supposedWidth - } + moduleElement.adjustWidth() moduleElement.settingsHeight = yPos - moduleElement.y - 6