From 69625d3aef508fc113028b6eccbf39b1861d6e09 Mon Sep 17 00:00:00 2001 From: Username404 Date: Wed, 19 May 2021 11:46:00 +0200 Subject: [PATCH] Make ButtonImpl.title open and non-null --- .../kotlin/fr/username404/snowygui/config/Configuration.kt | 2 +- .../kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt | 4 ++-- .../main/kotlin/fr/username404/snowygui/gui/feature/Macro.kt | 5 ++++- .../main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) 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 062789f..8a3f071 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt @@ -87,7 +87,7 @@ object Configuration { enabledFeatures.putAll( buttons.map { (it as ButtonImpl).run { - title.toString() to toggled + title to toggled } } ) 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 58a5130..4634cbf 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 @@ -45,7 +45,7 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { } private val info = this::class.findAnnotation() ?: throw Exception("Missing @ButtonInfo annotaton") override var color = info.parent.categoryColor - val title = this@ButtonImpl::class.simpleName + open val title: String = this@ButtonImpl::class.simpleName.toString() protected open fun execAction() = Unit private var wasWithinBounds: Boolean = false var toggled: Boolean = false; private set(value) { @@ -77,7 +77,7 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { defaultRectFunc() RenderSystem.enableTexture() RenderSystem.disableBlend() - if (poseStack != null && title != null) { + if (poseStack != null) { FontUtil.drawScaled(poseStack, title, x + 1, y + 1, 0.75F) } } diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Macro.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Macro.kt index 3553984..d27f51a 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Macro.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Macro.kt @@ -6,6 +6,9 @@ import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type @Serializable @ButtonInfo(Category.MACROS, kind = Type.CLICK) -data class Macro(private val command: String): ButtonImpl() { +data class Macro( + private val command: String, + override val title: String = command +): ButtonImpl() { override fun execAction() = Minecraft.getInstance().player!!.chat("/$command") } \ No newline at end of file diff --git a/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt b/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt index 9e2ea0c..bda75b8 100644 --- a/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt +++ b/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt @@ -42,7 +42,7 @@ class ForgeInit: Snowy() { (data!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(data) as Type).className.let { classname -> classname.startsWith(FeaturePackage).let { it && with(Class.forName(classname)) { - !kotlin.isAbstract && !kotlin.isData && declaredAnnotations.any { annotation -> + (!kotlin.isAbstract || !kotlin.isData) && declaredAnnotations.any { annotation -> annotation is ButtonInfo } }