Improve the colors configuration, the category enum and make ColoredElement.color a value
This commit is contained in:
parent
483dbc581f
commit
f1fd7aa703
|
@ -55,7 +55,9 @@ val SnowyConfigScreen: Screen get() {
|
||||||
ClickGui.clickboxes.filterNot { it.hidden }.map { box ->
|
ClickGui.clickboxes.filterNot { it.hidden }.map { box ->
|
||||||
startColorField(box.name, box.color).setSaveConsumer {
|
startColorField(box.name, box.color).setSaveConsumer {
|
||||||
box.color = it
|
box.color = it
|
||||||
}.build()
|
}.setDefaultValue(Category.values().find {
|
||||||
|
it.translationKey == box.name?.key
|
||||||
|
}?.categoryColor ?: box.color).build()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}.build()).addEntry(startStrList(
|
}.build()).addEntry(startStrList(
|
||||||
|
|
|
@ -57,9 +57,8 @@ abstract class Element(
|
||||||
|
|
||||||
abstract class ColoredElement(
|
abstract class ColoredElement(
|
||||||
x: Double, y: Double, width: Int, height: Int,
|
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) {
|
) : Element(x, y, width, height) {
|
||||||
open var color = color; protected set
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic protected fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer {
|
@JvmStatic protected fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer {
|
||||||
with(hextoRGB(color)) {
|
with(hextoRGB(color)) {
|
||||||
|
|
|
@ -22,7 +22,7 @@ import org.lwjgl.opengl.GL20
|
||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
class ClickBox(
|
class ClickBox(
|
||||||
x: Double, y: Double,
|
x: Double, y: Double,
|
||||||
color: Int = Colors.BLUE.hexValue,
|
override var color: Int = Colors.BLUE.hexValue,
|
||||||
val name: TranslatableComponent? = null
|
val name: TranslatableComponent? = null
|
||||||
): ColoredElement(x, y, 80, 10, color, 0.5F) {
|
): ColoredElement(x, y, 80, 10, color, 0.5F) {
|
||||||
constructor(x: Double, y: Double, color: Colors, name: TranslatableComponent? = null): this(x, y, color.hexValue, name)
|
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
|
hidden = buttons.isEmpty() || hidden
|
||||||
super.display(stack)
|
super.display(stack)
|
||||||
}
|
}
|
||||||
override var color: Int = super.color; public set
|
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
val buttonsProgressBar: ColoredElement = object: ColoredElement(
|
val buttonsProgressBar: ColoredElement = object: ColoredElement(
|
||||||
(x + width), y + height + 3,
|
(x + width), y + height + 3,
|
||||||
color = color, width = 3, height = clickboxHeightOffset - 6,
|
width = 3, height = clickboxHeightOffset - 6,
|
||||||
opacity = 0.75F
|
opacity = 0.75F
|
||||||
) {
|
) {
|
||||||
|
override val color: Int get() = this@ClickBox.color
|
||||||
override fun render(poseStack: PoseStack?) {
|
override fun render(poseStack: PoseStack?) {
|
||||||
RenderSystem.disableTexture()
|
RenderSystem.disableTexture()
|
||||||
RenderSystem.enableBlend()
|
RenderSystem.enableBlend()
|
||||||
|
@ -95,8 +95,8 @@ class ClickBox(
|
||||||
tessellator.end()
|
tessellator.end()
|
||||||
|
|
||||||
begin(GL20.GL_LINES, DefaultVertexFormat.POSITION_COLOR)
|
begin(GL20.GL_LINES, DefaultVertexFormat.POSITION_COLOR)
|
||||||
vertex(x + inclination, 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(0xF2F2FC)
|
vertex(x + width, y + height, 0.0).colorEnd(Colors.WHITE_LINES.hexValue)
|
||||||
tessellator.end()
|
tessellator.end()
|
||||||
}
|
}
|
||||||
RenderSystem.enableTexture()
|
RenderSystem.enableTexture()
|
||||||
|
|
|
@ -24,16 +24,14 @@ annotation class ButtonInfo(
|
||||||
MISC("snowy.clickbox.misc", Colors.BLUE),
|
MISC("snowy.clickbox.misc", Colors.BLUE),
|
||||||
RISKY("snowy.clickbox.risky", Colors.RED),
|
RISKY("snowy.clickbox.risky", Colors.RED),
|
||||||
MACROS("snowy.clickbox.macros", Colors.GREEN);
|
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)
|
constructor(translationKey: String, categoryColor: Colors): this(translationKey, categoryColor.hexValue)
|
||||||
init {
|
init {
|
||||||
ClickGui.components.add(
|
ClickGui.components.add(box)
|
||||||
ClickBox(
|
|
||||||
x = 4.0 + (if (ordinal >= 1 && !riskyCheatsEnabled) ordinal - 1 else ordinal) * 86, y = 4.0,
|
|
||||||
name = TranslatableComponent(translationKey),
|
|
||||||
color = categoryColor
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,7 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
|
||||||
} catch (e: NoSuchMethodException) {
|
} catch (e: NoSuchMethodException) {
|
||||||
try {
|
try {
|
||||||
it.getDeclaredField("INSTANCE").get(null)
|
it.getDeclaredField("INSTANCE").get(null)
|
||||||
} catch (e: NoSuchFieldException) {
|
} catch (e: NoSuchFieldException) {}
|
||||||
}
|
|
||||||
}) as? ButtonImpl)
|
}) as? ButtonImpl)
|
||||||
}.filterNot {
|
}.filterNot {
|
||||||
(it.info.parent == Category.RISKY) && !riskyCheatsEnabled
|
(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
|
hidden = value
|
||||||
}
|
}
|
||||||
private val info = this::class.findAnnotation<ButtonInfo>() ?: throw Exception("Missing @ButtonInfo annotaton")
|
private val info = this::class.findAnnotation<ButtonInfo>() ?: 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()
|
open val title: String = this@ButtonImpl::class.simpleName.toString()
|
||||||
protected open fun execAction() = Unit
|
protected open fun execAction() = Unit
|
||||||
private var wasWithinBounds: Boolean = false
|
private var wasWithinBounds: Boolean = false
|
||||||
|
|
|
@ -4,6 +4,7 @@ enum class Colors(val hexValue: Int) {
|
||||||
TRANSPARENT(-0x1),
|
TRANSPARENT(-0x1),
|
||||||
BLACK(0x000000),
|
BLACK(0x000000),
|
||||||
WHITE(0xFFFFFF),
|
WHITE(0xFFFFFF),
|
||||||
|
WHITE_LINES(0xF2F2FC),
|
||||||
GOLD(0xe69500),
|
GOLD(0xe69500),
|
||||||
BLUE(0x6C9E9D),
|
BLUE(0x6C9E9D),
|
||||||
RED(0x660000),
|
RED(0x660000),
|
||||||
|
|
Loading…
Reference in New Issue