From f1fd7aa703e75554d95013e985da31e7c5f74880 Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Fri, 4 Jun 2021 15:34:27 +0200 Subject: [PATCH] Improve the colors configuration, the category enum and make ColoredElement.color a value --- .../fr/username404/snowygui/config/ConfigScreen.kt | 4 +++- .../kotlin/fr/username404/snowygui/gui/Element.kt | 3 +-- .../username404/snowygui/gui/elements/ClickBox.kt | 10 +++++----- .../snowygui/gui/feature/ButtonAnnotations.kt | 14 ++++++-------- .../username404/snowygui/gui/feature/ButtonImpl.kt | 9 ++++++--- .../fr/username404/snowygui/gui/feature/Colors.kt | 1 + 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt b/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt index a5e82d7..d4df90a 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt @@ -55,7 +55,9 @@ val SnowyConfigScreen: Screen get() { ClickGui.clickboxes.filterNot { it.hidden }.map { box -> startColorField(box.name, box.color).setSaveConsumer { box.color = it - }.build() + }.setDefaultValue(Category.values().find { + it.translationKey == box.name?.key + }?.categoryColor ?: box.color).build() } ) }.build()).addEntry(startStrList( diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt index 7435fb5..98f5986 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt @@ -57,9 +57,8 @@ abstract class Element( abstract class ColoredElement( x: Double, y: Double, width: Int, height: Int, - color: Int = Colors.TRANSPARENT.hexValue, protected var opacity: Float, + open val color: Int = Colors.TRANSPARENT.hexValue, protected var opacity: Float, ) : Element(x, y, width, height) { - open var color = color; protected set companion object { @JvmStatic protected fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer { with(hextoRGB(color)) { diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt index 5fe570e..767c65e 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt @@ -22,7 +22,7 @@ import org.lwjgl.opengl.GL20 @ApiStatus.Internal class ClickBox( x: Double, y: Double, - color: Int = Colors.BLUE.hexValue, + override var color: Int = Colors.BLUE.hexValue, val name: TranslatableComponent? = null ): ColoredElement(x, y, 80, 10, color, 0.5F) { constructor(x: Double, y: Double, color: Colors, name: TranslatableComponent? = null): this(x, y, color.hexValue, name) @@ -33,14 +33,14 @@ class ClickBox( hidden = buttons.isEmpty() || hidden super.display(stack) } - override var color: Int = super.color; public set @JvmField val buttonsProgressBar: ColoredElement = object: ColoredElement( (x + width), y + height + 3, - color = color, width = 3, height = clickboxHeightOffset - 6, + width = 3, height = clickboxHeightOffset - 6, opacity = 0.75F ) { + override val color: Int get() = this@ClickBox.color override fun render(poseStack: PoseStack?) { RenderSystem.disableTexture() RenderSystem.enableBlend() @@ -95,8 +95,8 @@ class ClickBox( tessellator.end() begin(GL20.GL_LINES, DefaultVertexFormat.POSITION_COLOR) - vertex(x + inclination, y + height, 0.0).colorEnd(0xF2F2FC) - vertex(x + width, y + height, 0.0).colorEnd(0xF2F2FC) + vertex(x + inclination, y + height, 0.0).colorEnd(Colors.WHITE_LINES.hexValue) + vertex(x + width, y + height, 0.0).colorEnd(Colors.WHITE_LINES.hexValue) tessellator.end() } RenderSystem.enableTexture() diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonAnnotations.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonAnnotations.kt index 287d6bc..a40348d 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonAnnotations.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonAnnotations.kt @@ -24,16 +24,14 @@ annotation class ButtonInfo( MISC("snowy.clickbox.misc", Colors.BLUE), RISKY("snowy.clickbox.risky", Colors.RED), MACROS("snowy.clickbox.macros", Colors.GREEN); - fun getBox() = ClickGui.clickboxes.find { it.name?.key == translationKey } + val box = ClickBox( + x = 4.0 + (if (ordinal >= 1 && !riskyCheatsEnabled) ordinal - 1 else ordinal) * 86, y = 4.0, + name = TranslatableComponent(translationKey), + color = categoryColor + ) constructor(translationKey: String, categoryColor: Colors): this(translationKey, categoryColor.hexValue) init { - ClickGui.components.add( - ClickBox( - x = 4.0 + (if (ordinal >= 1 && !riskyCheatsEnabled) ordinal - 1 else ordinal) * 86, y = 4.0, - name = TranslatableComponent(translationKey), - color = categoryColor - ) - ) + ClickGui.components.add(box) } } diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt index 0bc3095..97c1ca6 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt @@ -48,8 +48,7 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { } catch (e: NoSuchMethodException) { try { it.getDeclaredField("INSTANCE").get(null) - } catch (e: NoSuchFieldException) { - } + } catch (e: NoSuchFieldException) {} }) as? ButtonImpl) }.filterNot { (it.info.parent == Category.RISKY) && !riskyCheatsEnabled @@ -62,7 +61,11 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { hidden = value } private val info = this::class.findAnnotation() ?: throw Exception("Missing @ButtonInfo annotaton") - override var color = info.parent.categoryColor; get() = info.parent.getBox()?.color ?: field + override var color = info.parent.categoryColor; get() { + return info.parent.box.color.let { + if (field == it) field else it + } + } open val title: String = this@ButtonImpl::class.simpleName.toString() protected open fun execAction() = Unit private var wasWithinBounds: Boolean = false diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Colors.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Colors.kt index 9e11a6e..2ca5b52 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Colors.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Colors.kt @@ -4,6 +4,7 @@ enum class Colors(val hexValue: Int) { TRANSPARENT(-0x1), BLACK(0x000000), WHITE(0xFFFFFF), + WHITE_LINES(0xF2F2FC), GOLD(0xe69500), BLUE(0x6C9E9D), RED(0x660000),