Improve the Category enum class, use kotlinx-coroutines-jdk8 & add a compiler flag, and make ClickBox.name not null by introducing Snowy.MissingComponent
This commit is contained in:
parent
1b4037be02
commit
bd9b4eab67
|
@ -51,7 +51,7 @@ subprojects {
|
|||
val shadowC by configurations.creating
|
||||
repositories { maven(url = "https://jitpack.io"); mavenCentral() }
|
||||
dependencies {
|
||||
implementation("$kotlinX:kotlinx-coroutines-core:${rootProject.property("kotlin_coroutines_version")}")
|
||||
implementation("$kotlinX:kotlinx-coroutines-jdk8:${rootProject.property("kotlin_coroutines_version")}")
|
||||
implementation("$kotlinX:kotlinx-serialization-core:$serializationVer")
|
||||
implementation("$kotlinX:kotlinx-serialization-json:$serializationVer")
|
||||
listOf(
|
||||
|
@ -176,7 +176,7 @@ allprojects {
|
|||
tasks {
|
||||
withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class) {
|
||||
with(kotlinOptions) {
|
||||
freeCompilerArgs = listOf("-Xjvm-default=all", "-Xlambdas=indy", "-progressive")
|
||||
freeCompilerArgs = listOf("-Xjvm-default=all", "-Xlambdas=indy", "-Xopt-in=kotlin.RequiresOptIn", "-progressive")
|
||||
jvmTarget = if (javaVer.toInt() < 9) "1.$javaVer" else javaVer
|
||||
languageVersion = (kotlinBaseVer.toDouble() + 0.1).toString()
|
||||
apiVersion = kotlinBaseVer
|
||||
|
|
|
@ -10,9 +10,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
|
||||
@Mixin(TitleScreen.class)
|
||||
public class TitleScreenMixin {
|
||||
@Inject(method = "createNormalMenuOptions", at = @At("RETURN"))
|
||||
private static boolean buttonsInitialized = false;
|
||||
private static synchronized void setButtonsInitialized() { buttonsInitialized = true; }
|
||||
@Inject(method = "createNormalMenuOptions", at = @At(value = "RETURN"))
|
||||
public void createNormalMenuOptions(int i, int j, CallbackInfo ci) {
|
||||
ClickGui.INSTANCE.tick();
|
||||
if (!ButtonImpl.Companion.getDone()) ButtonImpl.Companion.initialize();
|
||||
if (!buttonsInitialized) {
|
||||
ClickGui.INSTANCE.tick();
|
||||
ButtonImpl.initButtons();
|
||||
setButtonsInitialized();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import fr.username404.snowygui.config.Configuration
|
|||
import fr.username404.snowygui.gui.feature.ButtonImpl
|
||||
import fr.username404.snowygui.gui.feature.Ignored
|
||||
import fr.username404.snowygui.misc.AddKeyMaps
|
||||
import net.minecraft.network.chat.TranslatableComponent
|
||||
import org.apache.logging.log4j.LogManager
|
||||
import org.apache.logging.log4j.Logger
|
||||
import java.lang.reflect.Modifier
|
||||
|
@ -13,6 +14,7 @@ abstract class Snowy {
|
|||
protected fun Class<*>.isValidForButtonCollection(): Boolean = (!((Modifier.isAbstract(javaClass.modifiers)) || javaClass.isAnnotationPresent(Ignored::class.java)))
|
||||
private val displayInitMessage: Boolean by Configuration
|
||||
companion object {
|
||||
val MissingComponent: TranslatableComponent = object: TranslatableComponent(null) { override fun getString(): String = "MISSING_COMPONENT" }
|
||||
@JvmStatic
|
||||
protected val FeaturePackage: String = "fr.username404.snowygui.gui.feature"
|
||||
lateinit var annotatedButtons: Set<Class<out ButtonImpl>>
|
||||
|
|
|
@ -55,9 +55,7 @@ val SnowyConfigScreen: Screen get() {
|
|||
ClickGui.clickBoxes.map { box ->
|
||||
startColorField(box.name, box.color).setSaveConsumer {
|
||||
box.color = it
|
||||
}.setDefaultValue(Category.values().find {
|
||||
it.translationKey == box.name?.key
|
||||
}?.categoryColor ?: box.color).build()
|
||||
}.setDefaultValue(Category.fromBox(box)?.categoryColor ?: box.color).build()
|
||||
}
|
||||
)
|
||||
}.build()).addEntry(startStrList(
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.typesafe.config.ConfigRenderOptions
|
|||
import com.typesafe.config.ConfigValueFactory
|
||||
import fr.username404.snowygui.ClickGui
|
||||
import fr.username404.snowygui.Snowy
|
||||
import fr.username404.snowygui.Snowy.Companion.MissingComponent
|
||||
import fr.username404.snowygui.gui.elements.ClickBox
|
||||
import fr.username404.snowygui.gui.feature.Category
|
||||
import fr.username404.snowygui.gui.feature.Macro
|
||||
|
@ -35,9 +36,9 @@ object Configuration {
|
|||
}
|
||||
},
|
||||
"box_colors" to mapOf<String, Int>(*ClickGui.clickBoxes.filter { box ->
|
||||
box.name != null && Category.values().find { category -> box.name.key == category.translationKey }?.categoryColor != box.color
|
||||
(box.name.key != MissingComponent.key) && Category.fromBox(box)?.categoryColor != box.color
|
||||
}.map {
|
||||
it.name!!.key to it.color
|
||||
it.name.key to it.color
|
||||
}.toTypedArray()),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package fr.username404.snowygui.gui.elements
|
|||
import com.mojang.blaze3d.systems.RenderSystem
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
import fr.username404.snowygui.Snowy.Companion.MissingComponent
|
||||
import fr.username404.snowygui.config.Configuration
|
||||
import fr.username404.snowygui.gui.ColoredElement
|
||||
import fr.username404.snowygui.gui.Renderable.Rendering.buffer
|
||||
|
@ -24,11 +25,9 @@ import org.lwjgl.opengl.GL20
|
|||
class ClickBox(
|
||||
x: Double, y: Double,
|
||||
override var color: Int = Colors.BLUE.hexValue,
|
||||
val name: TranslatableComponent? = null
|
||||
val name: TranslatableComponent = MissingComponent
|
||||
): 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)
|
||||
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
|
||||
|
@ -119,14 +118,14 @@ class ClickBox(
|
|||
}.display(poseStack)
|
||||
}
|
||||
} else null
|
||||
if ((name != null) && (poseStack != null)) {
|
||||
if (poseStack != null) {
|
||||
Minecraft.getInstance().font.draw(poseStack, name.string, x.toFloat() + 5, y.toFloat() + 1.5F, Colors.TRANSPARENT.hexValue)
|
||||
renderButtons?.join()
|
||||
}
|
||||
}
|
||||
}
|
||||
init {
|
||||
savedColors?.get(name?.key)?.let {
|
||||
savedColors?.get(name.key)?.let {
|
||||
this.color = it
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,12 +24,20 @@ annotation class ButtonInfo(
|
|||
MISC("snowy.clickbox.misc", Colors.BLUE),
|
||||
RISKY("snowy.clickbox.risky", Colors.RED),
|
||||
MACROS("snowy.clickbox.macros", Colors.GREEN);
|
||||
val box = ClickBox(
|
||||
x = 4.0 + (if (ordinal >= 1 && !riskyCheats) ordinal - 1 else ordinal) * 86, y = 4.0,
|
||||
companion object {
|
||||
fun fromBox(box: ClickBox): Category? = values().find {
|
||||
box.isCategory(it)
|
||||
}
|
||||
}
|
||||
var box: ClickBox = ClickBox(
|
||||
x = 4.0 + (ordinal - ClickGui.clickBoxes.count { category ->
|
||||
category.hidden
|
||||
}) * 86, y = 4.0,
|
||||
name = TranslatableComponent(translationKey),
|
||||
color = categoryColor
|
||||
)
|
||||
); private set
|
||||
constructor(translationKey: String, categoryColor: Colors): this(translationKey, categoryColor.hexValue)
|
||||
constructor(box: ClickBox): this(translationKey = box.name.key, categoryColor = box.color) { this.box = box }
|
||||
init {
|
||||
ClickGui.components.add(box)
|
||||
}
|
||||
|
|
|
@ -8,53 +8,50 @@ import fr.username404.snowygui.config.Configuration
|
|||
import fr.username404.snowygui.gui.ColoredElement
|
||||
import fr.username404.snowygui.gui.FontUtil
|
||||
import fr.username404.snowygui.gui.Renderable.Rendering.defaultRectFunc
|
||||
import fr.username404.snowygui.gui.elements.ClickBox
|
||||
import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type
|
||||
import kotlin.reflect.full.findAnnotation
|
||||
|
||||
sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
|
||||
companion object {
|
||||
var done: Boolean = false; private set
|
||||
fun initialize() {
|
||||
done = true
|
||||
fun addToButtons(buttons: Collection<ButtonImpl>) {
|
||||
buttons.groupBy {
|
||||
ClickGui.components.filterIsInstance<ClickBox>().find { box ->
|
||||
it.let { impl ->
|
||||
with(impl) {
|
||||
if (info.kind == Type.TOGGLE) {
|
||||
Configuration.enabledFeatures[title]?.let { bool ->
|
||||
toggled = bool
|
||||
}
|
||||
internal companion object {
|
||||
private fun addButtons(vararg buttons: ButtonImpl) {
|
||||
buttons.groupBy {
|
||||
ClickGui.clickBoxes.find { box ->
|
||||
it.let { impl ->
|
||||
with(impl) {
|
||||
if (info.kind == Type.TOGGLE) {
|
||||
Configuration.enabledFeatures[title]?.let { bool ->
|
||||
toggled = bool
|
||||
}
|
||||
}
|
||||
box.name?.key ?: box.name.toString() == impl.info.parent.translationKey
|
||||
}
|
||||
box.isCategory(impl.info.parent)
|
||||
}
|
||||
}.entries.forEach { entry ->
|
||||
with(entry) {
|
||||
value.forEach {
|
||||
if (!it.isDisabled) {
|
||||
key?.buttons!!.add(it)
|
||||
}
|
||||
}
|
||||
}.entries.forEach { entry ->
|
||||
with(entry) {
|
||||
key?.buttons?.clear()
|
||||
value.forEach {
|
||||
if (!it.isDisabled) {
|
||||
key?.buttons?.add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
addToButtons(
|
||||
Snowy.annotatedButtons.mapNotNull {
|
||||
((try {
|
||||
it.getConstructor().newInstance()
|
||||
} catch (e: NoSuchMethodException) {
|
||||
try {
|
||||
it.getDeclaredField("INSTANCE").get(null)
|
||||
} catch (e: NoSuchFieldException) {}
|
||||
}) as? ButtonImpl)
|
||||
}.filterNot {
|
||||
(it.info.parent == Category.RISKY) && !riskyCheats
|
||||
}.plus(Configuration.foundMacros)
|
||||
)
|
||||
}
|
||||
@JvmStatic
|
||||
fun initButtons() = addButtons(
|
||||
*Snowy.annotatedButtons.mapNotNull {
|
||||
((try {
|
||||
it.getConstructor().newInstance()
|
||||
} catch (e: NoSuchMethodException) {
|
||||
try {
|
||||
it.getDeclaredField("INSTANCE").get(null)
|
||||
} catch (e: NoSuchFieldException) {}
|
||||
}) as? ButtonImpl)
|
||||
}.filterNot {
|
||||
(it.info.parent == Category.RISKY) && !riskyCheats
|
||||
}.plus(Configuration.foundMacros).toTypedArray()
|
||||
)
|
||||
}
|
||||
var isDisabled: Boolean = false; set(value) {
|
||||
field = value
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"snowy.missing.key": "MISSING_KEY",
|
||||
"screen.snowy.gui": "Snowy Interface",
|
||||
"screen.snowy.config": "Snowy configuration screen",
|
||||
"screen.snowy.config.general": "General",
|
||||
|
|
Loading…
Reference in New Issue