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