aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/gui/config/IntegerHandler.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-07-01 03:42:51 +0200
committerLinnea Gräf <nea@nea.moe>2024-07-03 21:05:51 +0200
commit5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e (patch)
treea5b0a6fbc8878ae62bb2c3a01dbb255388353fda /src/main/kotlin/moe/nea/firmament/gui/config/IntegerHandler.kt
parentdff1f9c0e2b728dba902d72816104abccc61f511 (diff)
downloadFirmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.tar.gz
Firmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.tar.bz2
Firmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.zip
[WIP] Remove LibGUI
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/gui/config/IntegerHandler.kt')
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/config/IntegerHandler.kt55
1 files changed, 32 insertions, 23 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/gui/config/IntegerHandler.kt b/src/main/kotlin/moe/nea/firmament/gui/config/IntegerHandler.kt
index 77d09cb..bb6f5c4 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/config/IntegerHandler.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/config/IntegerHandler.kt
@@ -6,17 +6,16 @@
package moe.nea.firmament.gui.config
-import io.github.cottonmc.cotton.gui.widget.WBox
-import io.github.cottonmc.cotton.gui.widget.WLabel
-import io.github.cottonmc.cotton.gui.widget.WSlider
-import io.github.cottonmc.cotton.gui.widget.data.Axis
-import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment
-import java.util.function.IntConsumer
+import io.github.notenoughupdates.moulconfig.common.IMinecraft
+import io.github.notenoughupdates.moulconfig.gui.component.RowComponent
+import io.github.notenoughupdates.moulconfig.gui.component.SliderComponent
+import io.github.notenoughupdates.moulconfig.gui.component.TextComponent
+import io.github.notenoughupdates.moulconfig.observer.GetSetter
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.int
import kotlinx.serialization.json.jsonPrimitive
-import net.minecraft.text.Text
+import moe.nea.firmament.util.FirmFormatters
class IntegerHandler(val config: ManagedConfig, val min: Int, val max: Int) : ManagedConfig.OptionHandler<Int> {
override fun toJson(element: Int): JsonElement? {
@@ -28,22 +27,32 @@ class IntegerHandler(val config: ManagedConfig, val min: Int, val max: Int) : Ma
}
override fun emitGuiElements(opt: ManagedOption<Int>, guiAppender: GuiAppender) {
- val label =
- WLabel(Text.literal(opt.value.toString())).setVerticalAlignment(VerticalAlignment.CENTER)
- guiAppender.appendLabeledRow(opt.labelText, WBox(Axis.HORIZONTAL).also {
- it.add(label, 40, 18)
- it.add(WSlider(min, max, Axis.HORIZONTAL).apply {
- valueChangeListener = IntConsumer {
- opt.value = it
- label.text = Text.literal(opt.value.toString())
- config.save()
- }
- guiAppender.onReload {
- value = opt.value
- label.text = Text.literal(opt.value.toString())
- }
- }, 130, 18)
- })
+ guiAppender.appendLabeledRow(
+ opt.labelText,
+ RowComponent(
+ TextComponent(IMinecraft.instance.defaultFontRenderer,
+ { FirmFormatters.formatCommas(opt.value, 0) },
+ 40,
+ TextComponent.TextAlignment.CENTER,
+ true,
+ false),
+ SliderComponent(
+ object : GetSetter<Float> {
+ override fun get(): Float {
+ return opt.value.toFloat()
+ }
+
+ override fun set(newValue: Float) {
+ opt.value = newValue.toInt()
+ }
+ },
+ min.toFloat(),
+ max.toFloat(),
+ 0.1F,
+ 130
+ )
+ ))
+
}
}