Add colors to the configuration screen and change the version to 0.1.1
This commit is contained in:
parent
560bcee0f3
commit
483dbc581f
|
@ -21,7 +21,7 @@ plugins {
|
|||
}
|
||||
|
||||
group = "fr.username404"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
val groupAndName = "${rootProject.group}.${rootProject.name.toLowerCase()}"
|
||||
|
||||
architectury {
|
||||
|
|
|
@ -9,6 +9,7 @@ object ClickGui: SnowyScreen() {
|
|||
private var GuiDragging: Boolean = false
|
||||
override val components = mutableSetOf<Element>()
|
||||
|
||||
val clickboxes get() = components.filterIsInstance<ClickBox>()
|
||||
inline fun boxContext(args: ClickBox.() -> Unit) = components.filterIsInstance<ClickBox>().forEach(args)
|
||||
private inline fun buttonsContext(args: ColoredElement.() -> Unit) = boxContext { buttons.forEach(args) }
|
||||
override fun mouseClicked(d: Double, e: Double, i: Int): Boolean { buttonsContext { this.mouseClicked(d, e, i) }; return false }
|
||||
|
|
|
@ -50,7 +50,15 @@ val SnowyConfigScreen: Screen get() {
|
|||
.setSaveConsumer {
|
||||
riskyCheatsEnabled = it
|
||||
}.setTooltip(Component.nullToEmpty("WARNING: Do not use this on servers or you might get banned.")).build()
|
||||
).addEntry(startStrList(
|
||||
).addEntry(startSubCategory(TranslatableComponent("$confPrefix.colors")).also { builder ->
|
||||
builder.addAll(
|
||||
ClickGui.clickboxes.filterNot { it.hidden }.map { box ->
|
||||
startColorField(box.name, box.color).setSaveConsumer {
|
||||
box.color = it
|
||||
}.build()
|
||||
}
|
||||
)
|
||||
}.build()).addEntry(startStrList(
|
||||
TranslatableComponent(Category.MACROS.translationKey),
|
||||
macrosButtons.getTitleCommand()
|
||||
).setInsertInFront(false).setDefaultValue(Configuration.foundMacros.getTitleCommand()).setErrorSupplier { list ->
|
||||
|
|
|
@ -21,14 +21,15 @@ import java.io.File
|
|||
import java.util.function.Supplier
|
||||
|
||||
object Configuration {
|
||||
val ModifiableValues = mutableMapOf<String, Supplier<ConfigValue>>(
|
||||
"enabledFeatures" to Supplier { ConfigValueFactory.fromMap(enabledFeatures) },
|
||||
"riskyCheats" to Supplier { ConfigValueFactory.fromAnyRef(riskyCheatsEnabled) },
|
||||
"macros" to Supplier { ConfigValueFactory.fromIterable((ClickGui.components.find { it is ClickBox && it.isCategory(Category.MACROS) } as ClickBox).buttons.map {
|
||||
val ModifiableValues: MutableMap<String, Supplier<ConfigValue>> = mapOf<String, () -> ConfigValue>(
|
||||
"enabledFeatures" to { ConfigValueFactory.fromMap(enabledFeatures) },
|
||||
"riskyCheats" to { ConfigValueFactory.fromAnyRef(riskyCheatsEnabled)!! },
|
||||
"macros" to { ConfigValueFactory.fromIterable((ClickGui.components.find { it is ClickBox && it.isCategory(Category.MACROS) } as ClickBox).buttons.map {
|
||||
Json.encodeToString(it as Macro)
|
||||
}) },
|
||||
"sortAlphabetically" to Supplier { ConfigValueFactory.fromAnyRef(sortAlphabetically) }
|
||||
); inline fun setConfigValue(s: String, crossinline value: () -> Any) = ModifiableValues.put(s, Supplier { ConfigValueFactory.fromAnyRef(value.invoke()) })
|
||||
"box_colors" to { ConfigValueFactory.fromAnyRef(mapOf<String, Int>(*ClickGui.clickboxes.filter { it.name != null }.map { it.name!!.key to it.color }.toTypedArray())) },
|
||||
"sortAlphabetically" to { ConfigValueFactory.fromAnyRef(sortAlphabetically) }
|
||||
).mapValues { Supplier<ConfigValue>(it.value) }.toMutableMap(); inline fun setConfigValue(s: String, crossinline value: () -> Any) = ModifiableValues.put(s, Supplier { ConfigValueFactory.fromAnyRef(value.invoke()) })
|
||||
private fun Config.withFullModifiableValues() = ModifiableValues.entries.fold(this) { previous, entry ->
|
||||
previous.withValue(entry.key, entry.value.get())
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ abstract class Element(
|
|||
|
||||
abstract class ColoredElement(
|
||||
x: Double, y: Double, width: Int, height: Int,
|
||||
color: Colors = Colors.TRANSPARENT, protected var opacity: Float,
|
||||
color: Int = Colors.TRANSPARENT.hexValue, protected var opacity: Float,
|
||||
) : Element(x, y, width, height) {
|
||||
open var color = color; protected set
|
||||
companion object {
|
||||
|
@ -67,7 +67,7 @@ abstract class ColoredElement(
|
|||
}
|
||||
}
|
||||
}
|
||||
internal fun VertexConsumer.colorEnd(color: Int = this@ColoredElement.color.hexValue) = colorIt(color, opacity).endVertex()
|
||||
internal fun VertexConsumer.colorEnd(color: Int = this@ColoredElement.color) = colorIt(color, opacity).endVertex()
|
||||
}
|
||||
|
||||
fun hextoRGB(hex: Int): MutableList<Float> {
|
||||
|
|
|
@ -22,15 +22,19 @@ import org.lwjgl.opengl.GL20
|
|||
@ApiStatus.Internal
|
||||
class ClickBox(
|
||||
x: Double, y: Double,
|
||||
color: Colors = Colors.BLUE,
|
||||
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)
|
||||
|
||||
fun isCategory(c: Category): Boolean = (name?.key == c.translationKey)
|
||||
val buttons: MutableSet<ButtonImpl> = if (sortAlphabetically) sortedSetOf(compareBy(String.CASE_INSENSITIVE_ORDER) { it.title }) else mutableSetOf()
|
||||
override fun display(stack: PoseStack?) {
|
||||
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,
|
||||
|
@ -62,6 +66,9 @@ class ClickBox(
|
|||
}
|
||||
|
||||
companion object {
|
||||
private val savedColors = "box_colors".let {
|
||||
if (!Configuration.obtained.hasPath(it)) null else Configuration.obtained.extract<Map<String, Int>>(it)
|
||||
}
|
||||
var sortAlphabetically: Boolean = Configuration.obtained.extract("sortAlphabetically")
|
||||
const val buttonsMax: Short = 16 // TODO Remove the buttons limit
|
||||
const val clickboxHeightOffset: Int = 80
|
||||
|
@ -115,4 +122,9 @@ class ClickBox(
|
|||
}
|
||||
}
|
||||
}
|
||||
init {
|
||||
savedColors?.get(name?.key)?.let {
|
||||
this.color = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,10 +20,12 @@ annotation class ButtonInfo(
|
|||
CLICK
|
||||
}
|
||||
}
|
||||
}; enum class Category(val translationKey: String, val categoryColor: Colors) {
|
||||
}; enum class Category(val translationKey: String, val categoryColor: Int) {
|
||||
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(
|
||||
|
|
|
@ -62,7 +62,7 @@ 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
|
||||
override var color = info.parent.categoryColor; get() = info.parent.getBox()?.color ?: field
|
||||
open val title: String = this@ButtonImpl::class.simpleName.toString()
|
||||
protected open fun execAction() = Unit
|
||||
private var wasWithinBounds: Boolean = false
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
"screen.snowy.config.general.macros.toomuchdelimiters": "Too much separators (only one is allowed)",
|
||||
"screen.snowy.config.general.macros.toomuchcharacters": "Too much characters (16 is the maximum)",
|
||||
"screen.snowy.config.general.macros.toomuchbuttons": "Too much entries (16 is the maximum)",
|
||||
"screen.snowy.config.colors": "Box colors",
|
||||
"screen.snowy.config.behavior": "Behavior",
|
||||
"screen.snowy.config.behavior.sortalphabetically": "Sort buttons alphabetically",
|
||||
"category.snowy.keycategory": "SnowyGUI",
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
"screen.snowy.config.general.macros.toomuchdelimiters": "Séparateurs trop nombreux (un seul est autorisé)",
|
||||
"screen.snowy.config.general.macros.toomuchcharacters": "Trop de caractères (le maximum est de 16)",
|
||||
"screen.snowy.config.general.macros.toomuchbuttons": "Trop d'entrées (le maximum est de 16)",
|
||||
"screen.snowy.config.colors": "Couleurs des boîtes",
|
||||
"screen.snowy.config.behavior": "Comportement",
|
||||
"screen.snowy.config.behavior.sortalphabetically": "Trier les boutons alphabétiquement",
|
||||
"category.snowy.keycategory": "SnowyGUI",
|
||||
|
|
Loading…
Reference in New Issue