Skip to content

Commit

Permalink
all styles adapt
Browse files Browse the repository at this point in the history
  • Loading branch information
mems01 committed Feb 8, 2025
1 parent 62e1d3f commit 051b9b3
Show file tree
Hide file tree
Showing 6 changed files with 543 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 051b9b3

Please sign in to comment.