Shorten SnowyConfigScreen in ConfigScreen.kt
This commit is contained in:
parent
cd4d25951c
commit
34de53beee
|
@ -24,86 +24,83 @@ private fun supplyComponent(string: String?): Optional<Component> = string?.run
|
|||
Optional.of(TranslatableComponent(string))
|
||||
} ?: Optional.empty()
|
||||
|
||||
val SnowyConfigScreen: Screen get() {
|
||||
return try {
|
||||
Class.forName("me.shedaniel.clothconfig2.api.ConfigBuilder")
|
||||
val macrosBox: ClickBox = ClickGui.components.find {
|
||||
(it is ClickBox) && it.isCategory(Category.MACROS)
|
||||
} 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 {
|
||||
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()
|
||||
val SnowyConfigScreen: Screen = 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 }
|
||||
}; get() = try {
|
||||
Class.forName("me.shedaniel.clothconfig2.api.ConfigBuilder")
|
||||
val macrosBox: ClickBox = ClickGui.components.find {
|
||||
(it is ClickBox) && it.isCategory(Category.MACROS)
|
||||
} 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 {
|
||||
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())
|
||||
.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()).addEntry(startStrList(
|
||||
TranslatableComponent(Category.MACROS.translationKey),
|
||||
macrosButtons.getTitleCommand()
|
||||
).setInsertInFront(false).setDefaultValue(Configuration.foundMacros.getTitleCommand()).setErrorSupplier { list ->
|
||||
supplyComponent(if (list.size > buttonsMax) "$confPrefix.general.macros.toomuchbuttons" else null)
|
||||
}.setCellErrorSupplier { cell ->
|
||||
with(cell.split(":")) {
|
||||
supplyComponent(
|
||||
when {
|
||||
isEmpty() || !cell.contains(":") -> "$confPrefix.general.macros.missingdelimiter"
|
||||
size < 2 -> "$confPrefix.general.macros.missingelement"
|
||||
size > 2 -> "$confPrefix.general.macros.toomuchdelimiters"
|
||||
first().count() > 16 -> "$confPrefix.general.macros.toomuchcharacters"
|
||||
else -> null
|
||||
}
|
||||
)
|
||||
}.build()).addEntry(startStrList(
|
||||
TranslatableComponent(Category.MACROS.translationKey),
|
||||
macrosButtons.getTitleCommand()
|
||||
).setInsertInFront(false).setDefaultValue(Configuration.foundMacros.getTitleCommand()).setErrorSupplier { list ->
|
||||
supplyComponent(if (list.size > buttonsMax) "$confPrefix.general.macros.toomuchbuttons" else null)
|
||||
}.setCellErrorSupplier { cell ->
|
||||
with(cell.split(":")) {
|
||||
supplyComponent(
|
||||
when {
|
||||
isEmpty() || !cell.contains(":") -> "$confPrefix.general.macros.missingdelimiter"
|
||||
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)
|
||||
}
|
||||
}.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)
|
||||
}
|
||||
}
|
||||
if (it.isEmpty().also { empty -> macrosBox.hidden = empty }) 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
|
||||
}; if (it.isEmpty().also { empty -> macrosBox.hidden = empty })
|
||||
macrosButtons.clear()
|
||||
}.build()
|
||||
)
|
||||
}
|
||||
override fun onClose() { minecraft?.screen = configScreenParent }
|
||||
}
|
||||
}
|
||||
}
|
||||
}.build()
|
||||
} catch (e: ClassNotFoundException) { field }
|
Loading…
Reference in New Issue