Make ButtonImpl.title open and non-null

This commit is contained in:
Username404 2021-05-19 11:46:00 +02:00
parent 4166418a52
commit 69625d3aef
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
4 changed files with 8 additions and 5 deletions

View File

@ -87,7 +87,7 @@ object Configuration {
enabledFeatures.putAll( enabledFeatures.putAll(
buttons.map { buttons.map {
(it as ButtonImpl).run { (it as ButtonImpl).run {
title.toString() to toggled title to toggled
} }
} }
) )

View File

@ -45,7 +45,7 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
} }
private val info = this::class.findAnnotation<ButtonInfo>() ?: throw Exception("Missing @ButtonInfo annotaton") private val info = this::class.findAnnotation<ButtonInfo>() ?: throw Exception("Missing @ButtonInfo annotaton")
override var color = info.parent.categoryColor 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 protected open fun execAction() = Unit
private var wasWithinBounds: Boolean = false private var wasWithinBounds: Boolean = false
var toggled: Boolean = false; private set(value) { 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() defaultRectFunc()
RenderSystem.enableTexture() RenderSystem.enableTexture()
RenderSystem.disableBlend() RenderSystem.disableBlend()
if (poseStack != null && title != null) { if (poseStack != null) {
FontUtil.drawScaled(poseStack, title, x + 1, y + 1, 0.75F) FontUtil.drawScaled(poseStack, title, x + 1, y + 1, 0.75F)
} }
} }

View File

@ -6,6 +6,9 @@ import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type
@Serializable @Serializable
@ButtonInfo(Category.MACROS, kind = Type.CLICK) @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") override fun execAction() = Minecraft.getInstance().player!!.chat("/$command")
} }

View File

@ -42,7 +42,7 @@ class ForgeInit: Snowy() {
(data!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(data) as Type).className.let { classname -> (data!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(data) as Type).className.let { classname ->
classname.startsWith(FeaturePackage).let { classname.startsWith(FeaturePackage).let {
it && with(Class.forName(classname)) { it && with(Class.forName(classname)) {
!kotlin.isAbstract && !kotlin.isData && declaredAnnotations.any { annotation -> (!kotlin.isAbstract || !kotlin.isData) && declaredAnnotations.any { annotation ->
annotation is ButtonInfo annotation is ButtonInfo
} }
} }