diff --git a/build.gradle.kts b/build.gradle.kts index 9eaecc7..7a6d0da 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,7 +21,7 @@ plugins { } group = "fr.username404" -version = "0.1.0" +version = "0.1.1" val groupAndName = "${rootProject.group}.${rootProject.name.toLowerCase()}" architectury { diff --git a/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt b/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt index 0d89121..801c11d 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt @@ -9,6 +9,7 @@ object ClickGui: SnowyScreen() { private var GuiDragging: Boolean = false override val components = mutableSetOf() + val clickboxes get() = components.filterIsInstance() inline fun boxContext(args: ClickBox.() -> Unit) = components.filterIsInstance().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 } 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 c39ca17..a5e82d7 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt @@ -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 -> diff --git a/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt b/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt index 0de0bd1..b36b6eb 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt @@ -21,14 +21,15 @@ import java.io.File import java.util.function.Supplier object Configuration { - val ModifiableValues = mutableMapOf>( - "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> = mapOf 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(*ClickGui.clickboxes.filter { it.name != null }.map { it.name!!.key to it.color }.toTypedArray())) }, + "sortAlphabetically" to { ConfigValueFactory.fromAnyRef(sortAlphabetically) } + ).mapValues { Supplier(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()) } 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 5b91957..7435fb5 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt @@ -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 { 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 24bb9e7..5fe570e 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,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 = 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>(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 + } + } } 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 1c0ee40..287d6bc 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 @@ -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( 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 83423c5..0bc3095 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 @@ -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() ?: 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 diff --git a/common/src/main/resources/assets/snowygui/lang/en_us.json b/common/src/main/resources/assets/snowygui/lang/en_us.json index ed77706..69b2a23 100644 --- a/common/src/main/resources/assets/snowygui/lang/en_us.json +++ b/common/src/main/resources/assets/snowygui/lang/en_us.json @@ -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", diff --git a/common/src/main/resources/assets/snowygui/lang/fr_fr.json b/common/src/main/resources/assets/snowygui/lang/fr_fr.json index 8cc9d92..f0f4f47 100644 --- a/common/src/main/resources/assets/snowygui/lang/fr_fr.json +++ b/common/src/main/resources/assets/snowygui/lang/fr_fr.json @@ -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",