Add a local function to ConfigScreen.kt, and set the tye of ClickBox.buttons explicitly

This commit is contained in:
Username404 2021-06-02 11:59:03 +02:00
parent 6f40777f99
commit 24df3a12cc
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
2 changed files with 4 additions and 3 deletions

View File

@ -32,6 +32,7 @@ val SnowyConfigScreen: Screen get() {
} as ClickBox
@Suppress("UNCHECKED_CAST")
val macrosButtons = macrosBox.buttons as MutableSet<Macro>
fun Collection<Macro>.getTitleCommand(): MutableList<String> = map { it.run { "$title: $command" } }.toMutableList()
me.shedaniel.clothconfig2.api.ConfigBuilder.create().setParentScreen(configScreenParent).transparentBackground()
.setShouldListSmoothScroll(true)
.setTitle(translationComponent).apply {
@ -51,8 +52,8 @@ val SnowyConfigScreen: Screen get() {
}.setTooltip(Component.nullToEmpty("WARNING: Do not use this on servers or you might get banned.")).build()
).addEntry(startStrList(
TranslatableComponent(Category.MACROS.translationKey),
macrosButtons.map { it.run { "$title: $command" } }
).setInsertInFront(false).setDefaultValue(Configuration.foundMacros.map { "${it.title}: ${it.command}" }).setErrorSupplier { list ->
macrosButtons.getTitleCommand()
).setInsertInFront(false).setDefaultValue(Configuration.foundMacros.getTitleCommand()).setErrorSupplier { list ->
supplyComponent(if (list.size > buttonsMax) "$confPrefix.general.macros.toomuchbuttons" else null)
}.setCellErrorSupplier {
with(it.split(":")) {

View File

@ -26,7 +26,7 @@ class ClickBox(
val name: TranslatableComponent? = null
): ColoredElement(x, y, 80, 10, color, 0.5F) {
fun isCategory(c: Category): Boolean = (name?.key == c.translationKey)
val buttons = if (sortAlphabetically) sortedSetOf<ButtonImpl>(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?) {
hidden = buttons.isEmpty() || hidden
super.display(stack)