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 ->
|
||||
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(
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 }
|
||||
constructor(translationKey: String, categoryColor: Colors): this(translationKey, categoryColor.hexValue)
|
||||
init {
|
||||
ClickGui.components.add(
|
||||
ClickBox(
|
||||
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(box)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<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()
|
||||
protected open fun execAction() = Unit
|
||||
private var wasWithinBounds: Boolean = false
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue