From b2082d1d6008d943ffa2269cbdddb1b4fc72b8ce Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Sun, 28 Jul 2024 10:00:59 +0200 Subject: Backend: Change colour (UK) to color (US) (#2258) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../java/at/hannibal2/skyhanni/utils/ColorUtils.kt | 10 +-- .../at/hannibal2/skyhanni/utils/GuiRenderUtils.kt | 12 ++-- .../at/hannibal2/skyhanni/utils/LorenzColor.kt | 2 +- .../at/hannibal2/skyhanni/utils/RenderUtils.kt | 24 ++++---- .../at/hannibal2/skyhanni/utils/SpecialColor.java | 72 ++++++++++++++++++++++ .../at/hannibal2/skyhanni/utils/SpecialColour.java | 72 ---------------------- .../at/hannibal2/skyhanni/utils/StringUtils.kt | 4 +- 7 files changed, 98 insertions(+), 98 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/utils/SpecialColor.java delete mode 100644 src/main/java/at/hannibal2/skyhanni/utils/SpecialColour.java (limited to 'src/main/java/at/hannibal2/skyhanni/utils') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ColorUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ColorUtils.kt index 6a0af6cba..b2057d339 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ColorUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ColorUtils.kt @@ -6,17 +6,17 @@ object ColorUtils { /** Transfer string colors from the config to [Color] */ fun String.toChromaColor() = Color(toChromaColorInt(), true) - fun String.toChromaColorInt() = SpecialColour.specialToChromaRGB(this) + fun String.toChromaColorInt() = SpecialColor.specialToChromaRGB(this) fun String.getFirstColorCode() = this.takeIf { it.firstOrNull() == '§' }?.getOrNull(1) - fun getRed(colour: Int) = colour shr 16 and 0xFF + fun getRed(color: Int) = color shr 16 and 0xFF - fun getGreen(colour: Int) = colour shr 8 and 0xFF + fun getGreen(color: Int) = color shr 8 and 0xFF - fun getBlue(colour: Int) = colour and 0xFF + fun getBlue(color: Int) = color and 0xFF - fun getAlpha(colour: Int) = colour shr 24 and 0xFF + fun getAlpha(color: Int) = color shr 24 and 0xFF fun blendRGB(start: Color, end: Color, percent: Double) = Color( (start.red * (1 - percent) + end.red * percent).toInt(), diff --git a/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt index 403484fcd..75eb5087e 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt @@ -28,12 +28,12 @@ import kotlin.math.min // TODO cleanup of redundant functions object GuiRenderUtils { - fun drawStringCentered(str: String?, fr: FontRenderer, x: Float, y: Float, shadow: Boolean, colour: Int) { + fun drawStringCentered(str: String?, fr: FontRenderer, x: Float, y: Float, shadow: Boolean, color: Int) { val strLen = fr.getStringWidth(str) val x2 = x - strLen / 2f val y2 = y - fr.FONT_HEIGHT / 2f GL11.glTranslatef(x2, y2, 0f) - fr.drawString(str, 0f, 0f, colour, shadow) + fr.drawString(str, 0f, 0f, color, shadow) GL11.glTranslatef(-x2, -y2, 0f) } @@ -222,19 +222,19 @@ object GuiRenderUtils { return Color(color.red / 5, color.green / 5, color.blue / 5).rgb } - fun drawScaledRec(left: Int, top: Int, right: Int, bottom: Int, colour: Int, inverseScale: Float) { + fun drawScaledRec(left: Int, top: Int, right: Int, bottom: Int, color: Int, inverseScale: Float) { GuiScreen.drawRect( (left * inverseScale).toInt(), (top * inverseScale).toInt(), (right * inverseScale).toInt(), (bottom * inverseScale).toInt(), - colour + color, ) } - fun renderItemAndBackground(item: ItemStack, x: Int, y: Int, colour: Int) { + fun renderItemAndBackground(item: ItemStack, x: Int, y: Int, color: Int) { renderItemStack(item, x, y) - GuiScreen.drawRect(x, y, x + 16, y + 16, colour) + GuiScreen.drawRect(x, y, x + 16, y + 16, color) } // Taken and edited from NEU <- it's broken diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzColor.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzColor.kt index 9bb2cccd8..9947dd715 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzColor.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzColor.kt @@ -50,7 +50,7 @@ enum class LorenzColor(val chatColorCode: Char, private val color: Color, privat override fun toString(): String = coloredLabel - fun toConfigColour(): String = "0:255:${color.red}:${color.green}:${color.blue}" + fun toConfigColor(): String = "0:255:${color.red}:${color.green}:${color.blue}" fun toDyeColor(): EnumDyeColor = when (this) { WHITE -> EnumDyeColor.WHITE diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index 102013758..d32ff9ea9 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -75,7 +75,7 @@ object RenderUtils { private val beaconBeam = ResourceLocation("textures/entity/beacon_beam.png") private val matrixBuffer: FloatBuffer = GLAllocation.createDirectFloatBuffer(16) - private val colourBuffer: FloatBuffer = GLAllocation.createDirectFloatBuffer(16) + private val colorBuffer: FloatBuffer = GLAllocation.createDirectFloatBuffer(16) private val bezier2Buffer: FloatBuffer = GLAllocation.createDirectFloatBuffer(9) infix fun Slot.highlight(color: LorenzColor) { @@ -1009,12 +1009,12 @@ object RenderUtils { y: Float, shadow: Boolean, len: Int, - colour: Int, + color: Int, ) { val strLen = fr.getStringWidth(str) var factor = len / strLen.toFloat() factor = 1f.coerceAtMost(factor) - TextRenderUtils.drawStringScaled(str, fr, x, y, shadow, colour, factor) + TextRenderUtils.drawStringScaled(str, fr, x, y, shadow, color, factor) } fun LorenzRenderWorldEvent.drawDynamicText( @@ -1608,14 +1608,14 @@ object RenderUtils { fun LorenzRenderWorldEvent.outlineTopFace( boundingBox: AxisAlignedBB, lineWidth: Int, - colour: Color, + color: Color, depth: Boolean, ) { val (cornerOne, cornerTwo, cornerThree, cornerFour) = boundingBox.getCorners(boundingBox.maxY) - this.draw3DLine(cornerOne, cornerTwo, colour, lineWidth, depth) - this.draw3DLine(cornerTwo, cornerThree, colour, lineWidth, depth) - this.draw3DLine(cornerThree, cornerFour, colour, lineWidth, depth) - this.draw3DLine(cornerFour, cornerOne, colour, lineWidth, depth) + this.draw3DLine(cornerOne, cornerTwo, color, lineWidth, depth) + this.draw3DLine(cornerTwo, cornerThree, color, lineWidth, depth) + this.draw3DLine(cornerThree, cornerFour, color, lineWidth, depth) + this.draw3DLine(cornerFour, cornerOne, color, lineWidth, depth) } // TODO nea please merge with 'draw3DLine' @@ -1861,9 +1861,9 @@ object RenderUtils { } fun getAlpha(): Float { - colourBuffer.clear() - GlStateManager.getFloat(GL11.GL_CURRENT_COLOR, colourBuffer) - if (colourBuffer.limit() < 4) return 1f - return colourBuffer.get(3) + colorBuffer.clear() + GlStateManager.getFloat(GL11.GL_CURRENT_COLOR, colorBuffer) + if (colorBuffer.limit() < 4) return 1f + return colorBuffer.get(3) } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SpecialColor.java b/src/main/java/at/hannibal2/skyhanni/utils/SpecialColor.java new file mode 100644 index 000000000..7fc733c2b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/SpecialColor.java @@ -0,0 +1,72 @@ +package at.hannibal2.skyhanni.utils; + +import java.awt.Color; + +/** + * Taken from NotEnoughUpdates + */ +public class SpecialColor { + + private static final int RADIX = 10; + + private static int[] decompose(String csv) { + String[] split = csv.split(":"); + + int[] arr = new int[split.length]; + + for (int i = 0; i < split.length; i++) { + arr[i] = Integer.parseInt(split[split.length - 1 - i], RADIX); + } + return arr; + } + + public static int getSpeed(String special) { + return decompose(special)[4]; + } + + public static float getSecondsForSpeed(int speed) { + return (255 - speed) / 254f * (MAX_CHROMA_SECS - MIN_CHROMA_SECS) + MIN_CHROMA_SECS; + } + + private static final int MIN_CHROMA_SECS = 1; + private static final int MAX_CHROMA_SECS = 60; + + public static long startTime = -1; + + @Deprecated // use String.toChromaColor() + public static int specialToChromaRGB(String special) { + if (startTime < 0) startTime = System.currentTimeMillis(); + + int[] d = decompose(special); + int chr = d[4]; + int a = d[3]; + int r = d[2]; + int g = d[1]; + int b = d[0]; + + float[] hsv = Color.RGBtoHSB(r, g, b, null); + + if (chr > 0) { + float seconds = getSecondsForSpeed(chr); + hsv[0] += (System.currentTimeMillis() - startTime) / 1000f / seconds; + hsv[0] %= 1; + if (hsv[0] < 0) hsv[0] += 1; + } + + return (a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF); + } + + public static int rotateHue(int argb, int degrees) { + int a = (argb >> 24) & 0xFF; + int r = (argb >> 16) & 0xFF; + int g = (argb >> 8) & 0xFF; + int b = (argb) & 0xFF; + + float[] hsv = Color.RGBtoHSB(r, g, b, null); + + hsv[0] += degrees / 360f; + hsv[0] %= 1; + + return (a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF); + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SpecialColour.java b/src/main/java/at/hannibal2/skyhanni/utils/SpecialColour.java deleted file mode 100644 index 010e67e4d..000000000 --- a/src/main/java/at/hannibal2/skyhanni/utils/SpecialColour.java +++ /dev/null @@ -1,72 +0,0 @@ -package at.hannibal2.skyhanni.utils; - -import java.awt.Color; - -/** - * Taken from NotEnoughUpdates - */ -public class SpecialColour { - - private static final int RADIX = 10; - - private static int[] decompose(String csv) { - String[] split = csv.split(":"); - - int[] arr = new int[split.length]; - - for (int i = 0; i < split.length; i++) { - arr[i] = Integer.parseInt(split[split.length - 1 - i], RADIX); - } - return arr; - } - - public static int getSpeed(String special) { - return decompose(special)[4]; - } - - public static float getSecondsForSpeed(int speed) { - return (255 - speed) / 254f * (MAX_CHROMA_SECS - MIN_CHROMA_SECS) + MIN_CHROMA_SECS; - } - - private static final int MIN_CHROMA_SECS = 1; - private static final int MAX_CHROMA_SECS = 60; - - public static long startTime = -1; - - @Deprecated // use String.toChromaColor() - public static int specialToChromaRGB(String special) { - if (startTime < 0) startTime = System.currentTimeMillis(); - - int[] d = decompose(special); - int chr = d[4]; - int a = d[3]; - int r = d[2]; - int g = d[1]; - int b = d[0]; - - float[] hsv = Color.RGBtoHSB(r, g, b, null); - - if (chr > 0) { - float seconds = getSecondsForSpeed(chr); - hsv[0] += (System.currentTimeMillis() - startTime) / 1000f / seconds; - hsv[0] %= 1; - if (hsv[0] < 0) hsv[0] += 1; - } - - return (a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF); - } - - public static int rotateHue(int argb, int degrees) { - int a = (argb >> 24) & 0xFF; - int r = (argb >> 16) & 0xFF; - int g = (argb >> 8) & 0xFF; - int b = (argb) & 0xFF; - - float[] hsv = Color.RGBtoHSB(r, g, b, null); - - hsv[0] += degrees / 360f; - hsv[0] %= 1; - - return (a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF); - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index f180e6bf7..180959658 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -25,7 +25,7 @@ object StringUtils { private val whiteSpacePattern = "^\\s*|\\s*$".toPattern() private val resetPattern = "(?i)§R".toPattern() private val sFormattingPattern = "(?i)§S".toPattern() - private val stringColourPattern = "§[0123456789abcdef].*".toPattern() + private val stringColorPattern = "§[0123456789abcdef].*".toPattern() private val asciiPattern = "[^\\x00-\\x7F]".toPattern() fun String.trimWhiteSpaceAndResets(): String = whiteSpaceResetPattern.matcher(this).replaceAll("") @@ -194,7 +194,7 @@ object StringUtils { } fun getColor(string: String, default: Int, darker: Boolean = true): Int { - val matcher = stringColourPattern.matcher(string) + val matcher = stringColorPattern.matcher(string) if (matcher.matches()) { val colorInt = Minecraft.getMinecraft().fontRendererObj.getColorCode(string[1]) return if (darker) { -- cgit