Sort buttons alphabetically
This commit is contained in:
parent
6552adbf70
commit
b1852f743e
|
@ -4,6 +4,7 @@ import com.google.gson.Gson
|
||||||
import com.google.gson.GsonBuilder
|
import com.google.gson.GsonBuilder
|
||||||
import fr.username404.snowygui.EventSnowy.Companion.useKey
|
import fr.username404.snowygui.EventSnowy.Companion.useKey
|
||||||
import fr.username404.snowygui.config.Configuration.obtained
|
import fr.username404.snowygui.config.Configuration.obtained
|
||||||
|
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 io.github.config4k.getValue
|
import io.github.config4k.getValue
|
||||||
|
@ -18,7 +19,7 @@ abstract class Snowy {
|
||||||
val Gson: Gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()
|
val Gson: Gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()
|
||||||
@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<*>>
|
lateinit var annotatedButtons: Set<Class<ButtonImpl>>
|
||||||
fun onEvent(e: String, lambda: argsLambda) = useKey(e).add(lambda)
|
fun onEvent(e: String, lambda: argsLambda) = useKey(e).add(lambda)
|
||||||
@JvmField
|
@JvmField
|
||||||
val logs: Logger = LogManager.getLogger()
|
val logs: Logger = LogManager.getLogger()
|
||||||
|
|
|
@ -17,30 +17,39 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
|
||||||
var done: Boolean = false; private set
|
var done: Boolean = false; private set
|
||||||
fun initialize() {
|
fun initialize() {
|
||||||
done = true
|
done = true
|
||||||
Snowy.annotatedButtons.forEach { // Initializes every button
|
fun addToButtons(buttons: Collection<ButtonImpl>) {
|
||||||
fun addToButtons(buttonImpl: ButtonImpl) {
|
buttons.groupBy {
|
||||||
ClickGui.components.filterIsInstance<ClickBox>().find { box ->
|
ClickGui.components.filterIsInstance<ClickBox>().find { box ->
|
||||||
box.name!!.key == buttonImpl.info.parent.translationKey
|
it.let { impl ->
|
||||||
}?.buttons!!.add(buttonImpl)
|
|
||||||
}
|
|
||||||
((try {
|
|
||||||
it.getConstructor().newInstance()
|
|
||||||
} catch (e: NoSuchMethodException) {
|
|
||||||
it.getDeclaredField("INSTANCE").get(null)
|
|
||||||
}) as ButtonImpl).let { impl ->
|
|
||||||
with(impl) {
|
with(impl) {
|
||||||
if (info.kind == ButtonInfo.Companion.Type.TOGGLE) {
|
if (info.kind == Type.TOGGLE) {
|
||||||
Configuration.enabledFeatures[title]?.let { bool ->
|
Configuration.enabledFeatures[title]?.let { bool ->
|
||||||
toggled = bool
|
toggled = bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addToButtons(impl)
|
box.name!!.key == impl.info.parent.translationKey
|
||||||
}
|
|
||||||
Configuration.macros.forEach { macro ->
|
|
||||||
addToButtons(macro)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}.entries.forEach { entry ->
|
||||||
|
with(entry) {
|
||||||
|
entry.value.sortedBy {
|
||||||
|
it.title
|
||||||
|
}.forEach {
|
||||||
|
key?.buttons!!.add(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addToButtons(
|
||||||
|
Snowy.annotatedButtons.map {
|
||||||
|
((try {
|
||||||
|
it.getConstructor().newInstance()
|
||||||
|
} catch (e: NoSuchMethodException) {
|
||||||
|
it.getDeclaredField("INSTANCE").get(null)
|
||||||
|
}) as ButtonImpl)
|
||||||
|
}.plus(Configuration.macros)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private val info = this::class.findAnnotation<ButtonInfo>() ?: throw Exception("Missing @ButtonInfo annotaton")
|
private val info = this::class.findAnnotation<ButtonInfo>() ?: throw Exception("Missing @ButtonInfo annotaton")
|
||||||
|
|
|
@ -3,6 +3,7 @@ package fr.username404.snowygui.fabric
|
||||||
import com.mojang.blaze3d.vertex.PoseStack
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
import fr.username404.snowygui.EventSnowy
|
import fr.username404.snowygui.EventSnowy
|
||||||
import fr.username404.snowygui.Snowy
|
import fr.username404.snowygui.Snowy
|
||||||
|
import fr.username404.snowygui.gui.feature.ButtonImpl
|
||||||
import fr.username404.snowygui.gui.feature.ButtonInfo
|
import fr.username404.snowygui.gui.feature.ButtonInfo
|
||||||
import net.fabricmc.api.ClientModInitializer
|
import net.fabricmc.api.ClientModInitializer
|
||||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback
|
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback
|
||||||
|
@ -29,6 +30,6 @@ class FabricInit: Snowy(), ClientModInitializer {
|
||||||
.setUrls(ClasspathHelper.forPackage(FeaturePackage))
|
.setUrls(ClasspathHelper.forPackage(FeaturePackage))
|
||||||
.setScanners(SubTypesScanner(false), TypeAnnotationsScanner())
|
.setScanners(SubTypesScanner(false), TypeAnnotationsScanner())
|
||||||
.useParallelExecutor()
|
.useParallelExecutor()
|
||||||
).getTypesAnnotatedWith(ButtonInfo::class.java).filter { it.isValidForButtonCollection() }.toSet()
|
).getTypesAnnotatedWith(ButtonInfo::class.java).filter { it.isValidForButtonCollection() }.toSet() as Set<Class<ButtonImpl>>
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@ package fr.username404.snowygui.forge
|
||||||
|
|
||||||
import fr.username404.snowygui.Snowy
|
import fr.username404.snowygui.Snowy
|
||||||
import fr.username404.snowygui.config.SnowyConfigScreen
|
import fr.username404.snowygui.config.SnowyConfigScreen
|
||||||
|
import fr.username404.snowygui.gui.feature.ButtonImpl
|
||||||
import fr.username404.snowygui.gui.feature.ButtonInfo
|
import fr.username404.snowygui.gui.feature.ButtonInfo
|
||||||
import net.minecraftforge.fml.ExtensionPoint
|
import net.minecraftforge.fml.ExtensionPoint
|
||||||
import net.minecraftforge.fml.ModList
|
import net.minecraftforge.fml.ModList
|
||||||
|
@ -49,7 +50,7 @@ class ForgeInit: Snowy() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.map { Class.forName((it!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(it) as Type).className) }
|
.map { Class.forName((it!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(it) as Type).className) as Class<ButtonImpl> }
|
||||||
.collect(Collectors.toSet())
|
.collect(Collectors.toSet())
|
||||||
with(MOD_BUS) {
|
with(MOD_BUS) {
|
||||||
addListener(this@ForgeInit::initSetup)
|
addListener(this@ForgeInit::initSetup)
|
||||||
|
|
Loading…
Reference in New Issue