Skip to content

Commit

Permalink
fix(legacy/Colors): Its sliders not synchronizing when loading the cl…
Browse files Browse the repository at this point in the history
…ient. (#5309)
  • Loading branch information
mems01 authored Jan 13, 2025
1 parent e0fdccf commit f1f1c4f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
24 changes: 15 additions & 9 deletions src/main/java/net/ccbluex/liquidbounce/config/Value.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import net.ccbluex.liquidbounce.utils.client.ClientUtils.LOGGER
import net.ccbluex.liquidbounce.utils.kotlin.RandomUtils.nextFloat
import net.ccbluex.liquidbounce.utils.kotlin.RandomUtils.nextInt
import net.ccbluex.liquidbounce.utils.render.ColorUtils
import net.ccbluex.liquidbounce.utils.render.ColorUtils.withAlpha
import net.minecraft.client.gui.FontRenderer
import org.lwjgl.input.Mouse
import java.awt.Color
import javax.vecmath.Vector2f
import kotlin.math.roundToInt
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

Expand Down Expand Up @@ -400,10 +402,10 @@ open class ColorValue(
}

init {
initializeSliderValues(defaultColor)
setupSliders(defaultColor)
}

fun initializeSliderValues(color: Color) {
fun setupSliders(color: Color) {
Color.RGBtoHSB(color.red, color.green, color.blue, null).also {
hueSliderY = it[0]
opacitySliderY = color.alpha / 255f
Expand All @@ -419,7 +421,7 @@ open class ColorValue(

override fun toJsonF(): JsonElement {
val pos = colorPickerPos
return JsonPrimitive("colorpicker: [${pos.x}, ${pos.y}], hueslider: ${hueSliderY}, opacity:${opacitySliderY}, rainbow: $rainbow")
return JsonPrimitive("colorpicker: [${pos.x}, ${pos.y}], hueslider: ${hueSliderY}, opacity: ${opacitySliderY}, rainbow: $rainbow")
}

override fun fromJsonF(element: JsonElement): Color? {
Expand All @@ -443,7 +445,10 @@ open class ColorValue(
this.opacitySliderY = opacitySliderY
this.rainbow = rainbowString

return value
// Change the current color based on the data from values.json
return Color(
Color.HSBtoRGB(this.hueSliderY, colorPickerX, 1 - colorPickerY), true
).withAlpha((opacitySliderY * 255).roundToInt())
}
}
}
Expand All @@ -457,16 +462,17 @@ open class ColorValue(
return selectedColor()
}

// Every change that is not coming from any ClickGUI styles should modify the sliders to synchronize with the new color.
override fun onChanged(oldValue: Color, newValue: Color) {
setupSliders(newValue)
}

fun readColorFromConfig(str: String): List<String>? {
val regex =
"""Color\[picker=\[\s*(-?\d*\.?\d+),\s*(-?\d*\.?\d+)],\s*hueslider=\s*(-?\d*\.?\d+),\s*opacity=\s*(-?\d*\.?\d+),\s*rainbow=(true|false)]""".toRegex()
val matchResult = regex.find(str)

return matchResult?.let {
listOf(
it.groupValues[1], it.groupValues[2], it.groupValues[3], it.groupValues[4], it.groupValues[5]
)
}
return matchResult?.groupValues?.drop(1)
}

enum class SliderType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package net.ccbluex.liquidbounce.ui.client.clickgui.style

import net.ccbluex.liquidbounce.config.ColorValue
import net.ccbluex.liquidbounce.config.Value
import net.ccbluex.liquidbounce.file.FileManager.saveConfig
import net.ccbluex.liquidbounce.file.FileManager.valuesConfig
Expand Down Expand Up @@ -56,7 +57,11 @@ abstract class Style : MinecraftInstance {
}

fun <T> Value<T>.setAndSaveValueOnButtonRelease(new: T) {
set(new, false)
if (this is ColorValue) {
changeValue(new)
} else {
set(new, false)
}

with(WaitTickUtils) {
if (!hasScheduled(this)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import net.ccbluex.liquidbounce.ui.client.hud.element.Side
import net.ccbluex.liquidbounce.ui.font.Fonts
import net.ccbluex.liquidbounce.ui.font.Fonts.font35
import net.ccbluex.liquidbounce.utils.client.MinecraftInstance
import net.ccbluex.liquidbounce.utils.client.chat
import net.ccbluex.liquidbounce.utils.extensions.lerpWith
import net.ccbluex.liquidbounce.utils.render.ColorUtils
import net.ccbluex.liquidbounce.utils.render.ColorUtils.blendColors
Expand Down Expand Up @@ -538,7 +537,6 @@ class EditorPanel(private val hudDesigner: GuiHudDesigner, var x: Int, var y: In
val rainbow = value.rainbow

if (leftClickPressed || rightClickPressed) {
chat("${mouseX}, ${colorPreviewX1..colorPreviewX2}, $mouseY, ${colorPreviewY1..colorPreviewY2}")
val isColorPreview =
mouseX in colorPreviewX1..colorPreviewX2 && mouseY in colorPreviewY1..colorPreviewY2
val isRainbowPreview =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ class Target : Element() {
private val borderStrength by float("Border-Strength", 3F, 1F..5F)

private val backgroundMode by choices("Background-Color", arrayOf("Custom", "Rainbow"), "Custom")
private val backgroundColor by color("Background", Color.BLACK) { backgroundMode == "Custom" }
private val backgroundColor by color("Background", Color.BLACK.withAlpha(150)) { backgroundMode == "Custom" }

private val borderMode by choices("Border-Color", arrayOf("Custom", "Rainbow"), "Custom")
private val borderColor by color("Border", Color.BLACK) { borderMode == "Custom" }

private val textColor by color("Text", Color.BLACK)
private val textColor by color("Text", Color.WHITE)

private val rainbowX by float("Rainbow-X", -1000F, -2000F..2000F) { backgroundMode == "Rainbow" }
private val rainbowY by float("Rainbow-Y", -1000F, -2000F..2000F) { backgroundMode == "Rainbow" }
Expand Down Expand Up @@ -93,7 +93,7 @@ class Target : Element() {
val target = KillAura.target ?: if (delayCounter >= vanishDelay) mc.thePlayer else lastTarget ?: mc.thePlayer

assumeNonVolatile {
val shouldRender = (KillAura.handleEvents() && KillAura.target != null || mc.currentScreen is GuiChat)
val shouldRender = KillAura.handleEvents() && KillAura.target != null || mc.currentScreen is GuiChat
val smoothMode = animation == "Smooth"
val fadeMode = animation == "Fade"

Expand Down Expand Up @@ -176,16 +176,12 @@ class Target : Element() {
borderAlpha
} else if (delayCounter >= vanishDelay) {
0f
} else {
alphaBorder
}
} else alphaBorder

alphaBorder =
AnimationUtil.base(alphaBorder.toDouble(), targetBorder.toDouble(), animationSpeed.toDouble())
.roundToInt()
}

if (fadeMode) {
borderAlpha = alphaBorder
textAlpha = alphaText
}
Expand All @@ -204,7 +200,7 @@ class Target : Element() {
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

if (fadeMode && shouldRender || smoothMode && shouldRender && width == width || delayCounter < vanishDelay) {
if (fadeMode && shouldRender || smoothMode && shouldRender || delayCounter < vanishDelay) {
// Draw rect box
RainbowShader.begin(backgroundMode == "Rainbow", rainbowX, rainbowY, rainbowOffset).use {
drawRoundedBorderRect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ColorSettingsInteger(
): ColorSettingsInteger {
Color(r, g, b, a).let {
colors.setAndUpdateDefault(it)
colors.initializeSliderValues(it)
colors.setupSliders(it)
}
return this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ object RotationUtils : MinecraftInstance, Listenable {
return
}

val lastTick1 = angleDifferences(lastRotations[1], lastRotations[2]).let { diffs ->
val lastTick1 = angleDifferences(serverRotation, lastRotations[1]).let { diffs ->
if (yaw) diffs.x else diffs.y
}

Expand Down

0 comments on commit f1f1c4f

Please sign in to comment.