From bc2f250baefa6930f4a2ad40e000ec981ef94f67 Mon Sep 17 00:00:00 2001 From: xtex Date: Tue, 25 Jul 2023 11:18:52 +0800 Subject: [PATCH] fix: int silder --- .../projection/swarm/SwarmProjectionEffect.kt | 2 +- .../quaedam/shell/ProjectionEffectShell.kt | 27 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/common/src/main/kotlin/quaedam/projection/swarm/SwarmProjectionEffect.kt b/common/src/main/kotlin/quaedam/projection/swarm/SwarmProjectionEffect.kt index 214cab5..bf095ae 100644 --- a/common/src/main/kotlin/quaedam/projection/swarm/SwarmProjectionEffect.kt +++ b/common/src/main/kotlin/quaedam/projection/swarm/SwarmProjectionEffect.kt @@ -53,7 +53,7 @@ data class SwarmProjectionEffect( } override fun createShell() = buildProjectionEffectShell(this) { - intSlider("quaedam.shell.swarm.max_count", ::maxCount, 0..180 step 5) + intSlider("quaedam.shell.swarm.max_count", ::maxCount, 0..250 step 5) } } diff --git a/common/src/main/kotlin/quaedam/shell/ProjectionEffectShell.kt b/common/src/main/kotlin/quaedam/shell/ProjectionEffectShell.kt index 987a809..e011177 100644 --- a/common/src/main/kotlin/quaedam/shell/ProjectionEffectShell.kt +++ b/common/src/main/kotlin/quaedam/shell/ProjectionEffectShell.kt @@ -6,7 +6,6 @@ import net.minecraft.client.gui.components.StringWidget import net.minecraft.client.gui.layouts.LayoutElement import net.minecraft.network.chat.Component import quaedam.projection.ProjectionEffect -import kotlin.math.floor import kotlin.reflect.KMutableProperty0 class ProjectionEffectShell(val effect: ProjectionEffect) { @@ -35,15 +34,20 @@ class ProjectionEffectShell(val effect: ProjectionEffect) { row(key) { object : AbstractSliderButton( 0, 0, width, height, - Component.literal(property.get().toString()), (property.get() - range.start).toDouble() / len + Component.literal(property.get().toString()), (property.get() - range.start) / len ) { override fun updateMessage() { - message = Component.literal(value.toString()) + message = Component.literal(property.get().toString()) } override fun applyValue() { - value = floor(value / step) * step - property.set(range.start + floor(value * len)) + val diff = value % step + if (diff < 0.5) { + value -= diff + } else { + value += (step - diff) + } + property.set(range.start + (value * len)) } } } @@ -51,19 +55,24 @@ class ProjectionEffectShell(val effect: ProjectionEffect) { fun intSlider(key: String, property: KMutableProperty0, range: IntProgression) { val len = range.last - range.first - val step = range.step / len + val step = range.step.toDouble() / len row(key) { object : AbstractSliderButton( 0, 0, width, height, Component.literal(property.get().toString()), (property.get() - range.first).toDouble() / len ) { override fun updateMessage() { - message = Component.literal(value.toString()) + message = Component.literal(property.get().toString()) } override fun applyValue() { - value = floor(value / step) * step - property.set((range.first + floor(value * len)).toInt()) + val diff = value % step + if (diff < 0.5) { + value -= diff + } else { + value += (step - diff) + } + property.set(range.first + (value * len).toInt()) } } }