Shorten SnowyConfigScreen in ConfigScreen.kt

This commit is contained in:
Username404-59 2021-06-24 13:59:26 +02:00
parent cd4d25951c
commit 34de53beee
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1

View File

@ -24,86 +24,83 @@ private fun supplyComponent(string: String?): Optional<Component> = string?.run
Optional.of(TranslatableComponent(string)) Optional.of(TranslatableComponent(string))
} ?: Optional.empty() } ?: Optional.empty()
val SnowyConfigScreen: Screen get() { val SnowyConfigScreen: Screen = object: Screen(translationComponent) {
return try { override fun isPauseScreen(): Boolean = false
Class.forName("me.shedaniel.clothconfig2.api.ConfigBuilder") override fun render(poseStack: PoseStack, i: Int, j: Int, f: Float) {
val macrosBox: ClickBox = ClickGui.components.find { super.renderBackground(poseStack)
(it is ClickBox) && it.isCategory(Category.MACROS) FontUtil.drawScaled(poseStack,
} as ClickBox text = "An appropriate version of the Cloth Config mod is required for the configuration of snowygui.", 16.0, 16.0,
@Suppress("UNCHECKED_CAST") color = Colors.WHITE, scaleFactor = 0.85F
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() override fun onClose() { minecraft?.screen = configScreenParent }
.setShouldListSmoothScroll(true) }; get() = try {
.setTitle(translationComponent).apply { Class.forName("me.shedaniel.clothconfig2.api.ConfigBuilder")
with(entryBuilder()) { val macrosBox: ClickBox = ClickGui.components.find {
getOrCreateCategory(TranslatableComponent("$confPrefix.general")).addEntry(startSubCategory(TranslatableComponent("$confPrefix.behavior")).apply { (it is ClickBox) && it.isCategory(Category.MACROS)
add(startBooleanToggle(TranslatableComponent("$confPrefix.behavior.sortalphabetically"), sortAlphabetically) } as ClickBox
.setDefaultValue(true).requireRestart() @Suppress("UNCHECKED_CAST")
.setSaveConsumer { sortAlphabetically = it }.build() 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 {
with(entryBuilder()) {
getOrCreateCategory(TranslatableComponent("$confPrefix.general")).addEntry(startSubCategory(TranslatableComponent("$confPrefix.behavior")).apply {
add(startBooleanToggle(TranslatableComponent("$confPrefix.behavior.sortalphabetically"), sortAlphabetically)
.setDefaultValue(true).requireRestart()
.setSaveConsumer { sortAlphabetically = it }.build()
)
}.build())
.addEntry(
startBooleanToggle(Component.nullToEmpty("Risky Cheats"), riskyCheats)
.setDefaultValue(false)
.requireRestart()
.setSaveConsumer {
riskyCheats = it
}.setTooltip(Component.nullToEmpty("WARNING: Do not use this on servers or you might get banned.")).build()
).addEntry(startSubCategory(TranslatableComponent("$confPrefix.colors")).also { builder ->
builder.addAll(
ClickGui.clickBoxes.map { box ->
startColorField(box.name, box.color).setSaveConsumer {
box.color = it
}.setDefaultValue(Category.fromBox(box)?.categoryColor ?: box.color).build()
}
) )
}.build()) }.build()).addEntry(startStrList(
.addEntry( TranslatableComponent(Category.MACROS.translationKey),
startBooleanToggle(Component.nullToEmpty("Risky Cheats"), riskyCheats) macrosButtons.getTitleCommand()
.setDefaultValue(false) ).setInsertInFront(false).setDefaultValue(Configuration.foundMacros.getTitleCommand()).setErrorSupplier { list ->
.requireRestart() supplyComponent(if (list.size > buttonsMax) "$confPrefix.general.macros.toomuchbuttons" else null)
.setSaveConsumer { }.setCellErrorSupplier { cell ->
riskyCheats = it with(cell.split(":")) {
}.setTooltip(Component.nullToEmpty("WARNING: Do not use this on servers or you might get banned.")).build() supplyComponent(
).addEntry(startSubCategory(TranslatableComponent("$confPrefix.colors")).also { builder -> when {
builder.addAll( isEmpty() || !cell.contains(":") -> "$confPrefix.general.macros.missingdelimiter"
ClickGui.clickBoxes.map { box -> size < 2 -> "$confPrefix.general.macros.missingelement"
startColorField(box.name, box.color).setSaveConsumer { size > 2 -> "$confPrefix.general.macros.toomuchdelimiters"
box.color = it first().count() > 16 -> "$confPrefix.general.macros.toomuchcharacters"
}.setDefaultValue(Category.fromBox(box)?.categoryColor ?: box.color).build() else -> null
} }
) )
}.build()).addEntry(startStrList( }
TranslatableComponent(Category.MACROS.translationKey), }.setTooltip(TranslatableComponent("$confPrefix.general.macros.tooltip")).setSaveConsumer { it.forEach { string ->
macrosButtons.getTitleCommand() val splitString: Pair<String, String>? = string.split(":").map { toTrim -> toTrim.trimStart() }.let { element ->
).setInsertInFront(false).setDefaultValue(Configuration.foundMacros.getTitleCommand()).setErrorSupplier { list -> if (element.size == 2) element.component1() to element.component2() else null
supplyComponent(if (list.size > buttonsMax) "$confPrefix.general.macros.toomuchbuttons" else null) }; if (splitString != null) {
}.setCellErrorSupplier { cell -> Macro(title = splitString.first, command = splitString.second).let { newMacro ->
with(cell.split(":")) { macrosButtons.removeIf { existingMacro ->
supplyComponent( (existingMacro.title == newMacro.title)
when { || (existingMacro.command == newMacro.command)
isEmpty() || !cell.contains(":") -> "$confPrefix.general.macros.missingdelimiter" || !it.any { currentString -> currentString.startsWith(existingMacro.title) } // Needed to remove duplicates from the config screen
size < 2 -> "$confPrefix.general.macros.missingelement"
size > 2 -> "$confPrefix.general.macros.toomuchdelimiters"
first().count() > 16 -> "$confPrefix.general.macros.toomuchcharacters"
else -> null
}
)
}
}.setTooltip(TranslatableComponent("$confPrefix.general.macros.tooltip")).setSaveConsumer { it.forEach { string ->
val splitString: Pair<String, String>? = string.split(":").map { toTrim -> toTrim.trimStart() }.let { element ->
if (element.size == 2) element.component1() to element.component2() else null
}; if (splitString != null) {
Macro(title = splitString.first, command = splitString.second).let { newMacro ->
macrosButtons.removeIf { existingMacro ->
(existingMacro.title == newMacro.title)
|| (existingMacro.command == newMacro.command)
|| !it.any { currentString -> currentString.startsWith(existingMacro.title) } // Needed to remove duplicates from the config screen
}
macrosButtons.add(newMacro)
} }
macrosButtons.add(newMacro)
} }
} }
if (it.isEmpty().also { empty -> macrosBox.hidden = empty }) macrosButtons.clear() }; if (it.isEmpty().also { empty -> macrosBox.hidden = empty })
}.build()) macrosButtons.clear()
} }.build()
}.build()
} catch (e: ClassNotFoundException) {
object: Screen(translationComponent) {
override fun isPauseScreen(): Boolean = false
override fun render(poseStack: PoseStack, i: Int, j: Int, f: Float) {
super.renderBackground(poseStack)
FontUtil.drawScaled(poseStack,
text = "An appropriate version of the Cloth Config mod is required for the configuration of snowygui.", 16.0, 16.0,
color = Colors.WHITE, scaleFactor = 0.85F
) )
} }
override fun onClose() { minecraft?.screen = configScreenParent } }.build()
} } catch (e: ClassNotFoundException) { field }
}
}