diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxInputPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxInputPanel.kt index ff562de31..7d266e86b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxInputPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxInputPanel.kt @@ -8,7 +8,7 @@ import ru.dbotthepony.mc.otm.core.GetterSetter import ru.dbotthepony.mc.otm.core.value import ru.dbotthepony.mc.otm.menu.input.IPlayerInputWithFeedback -open class CheckBoxInputPanel @JvmOverloads constructor( +open class CheckBoxInputPanel( screen: S, parent: EditablePanel<*>?, val widget: IPlayerInputWithFeedback, @@ -16,16 +16,8 @@ open class CheckBoxInputPanel @JvmOverloads constructor( y: Float = 0f, width: Float = REGULAR_DIMENSIONS + 120f, height: Float = REGULAR_DIMENSIONS -) : CheckBoxPanel(screen, parent, x, y, width, height) { - override var isChecked: Boolean - get() = widget.value - set(value) {} - +) : CheckBoxPanel(screen, parent, x, y, width, height, isChecked = widget) { override var isDisabled: Boolean get() = !widget.test(minecraft.player) set(value) {} - - override fun onClick(mouseButton: Int) { - widget.accept(!isChecked) - } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelInputPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelInputPanel.kt index 905bfff6a..ac46a9b5a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelInputPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelInputPanel.kt @@ -9,17 +9,16 @@ import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback import ru.dbotthepony.mc.otm.menu.input.IPlayerInputWithFeedback import kotlin.math.roundToInt -open class CheckBoxLabelInputPanel @JvmOverloads constructor( +open class CheckBoxLabelInputPanel( screen: S, parent: EditablePanel<*>?, - widget: IPlayerInputWithFeedback, + val widget: IPlayerInputWithFeedback, text: Component, x: Float = 0f, y: Float = 0f, width: Float = CheckBoxPanel.REGULAR_DIMENSIONS + 120f, height: Float = CheckBoxPanel.REGULAR_DIMENSIONS ) : AbstractCheckBoxLabelPanel(screen, parent, x, y, width, height) { - val widget get() = checkbox.widget override val checkbox = CheckBoxInputPanel(screen = screen, parent = this, widget = widget, x = 0f, y = 0f, width = CheckBoxPanel.REGULAR_DIMENSIONS, height = CheckBoxPanel.REGULAR_DIMENSIONS) override val label = Label(screen, this, CheckBoxPanel.REGULAR_DIMENSIONS + 4f, 4f, text = text) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelPanel.kt index e9dd03780..19893eb3f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelPanel.kt @@ -4,17 +4,18 @@ import net.minecraft.client.gui.screens.Screen import net.minecraft.network.chat.Component import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.Label -import kotlin.math.roundToInt +import ru.dbotthepony.mc.otm.core.GetterSetter -open class CheckBoxLabelPanel @JvmOverloads constructor( +open class CheckBoxLabelPanel( screen: S, parent: EditablePanel<*>?, text: Component, x: Float = 0f, y: Float = 0f, width: Float = CheckBoxPanel.REGULAR_DIMENSIONS + 120f, - height: Float = CheckBoxPanel.REGULAR_DIMENSIONS + height: Float = CheckBoxPanel.REGULAR_DIMENSIONS, + isChecked: GetterSetter = GetterSetter.box(false) ) : AbstractCheckBoxLabelPanel(screen, parent, x, y, width, height) { - override val checkbox = CheckBoxPanel(screen, this, 0f, 0f, CheckBoxPanel.REGULAR_DIMENSIONS, CheckBoxPanel.REGULAR_DIMENSIONS) + override val checkbox = CheckBoxPanel(screen, this, 0f, 0f, isChecked = isChecked) override val label = Label(screen, this, CheckBoxPanel.REGULAR_DIMENSIONS + 4f, 4f, text = text) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxPanel.kt index 8cb9bc42b..361e04a48 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxPanel.kt @@ -1,27 +1,21 @@ package ru.dbotthepony.mc.otm.client.screen.panels.button -import com.mojang.blaze3d.platform.InputConstants -import com.mojang.blaze3d.vertex.PoseStack -import it.unimi.dsi.fastutil.booleans.BooleanConsumer import net.minecraft.client.gui.GuiGraphics import net.minecraft.client.gui.screens.Screen -import ru.dbotthepony.mc.otm.client.playGuiClickSound import ru.dbotthepony.mc.otm.client.render.AbstractMatterySprite import ru.dbotthepony.mc.otm.client.render.WidgetLocation import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel -import ru.dbotthepony.mc.otm.core.TextComponent +import ru.dbotthepony.mc.otm.core.GetterSetter -open class CheckBoxPanel @JvmOverloads constructor( +open class CheckBoxPanel( screen: S, parent: EditablePanel<*>?, x: Float = 0f, y: Float = 0f, width: Float = REGULAR_DIMENSIONS, height: Float = REGULAR_DIMENSIONS, - var onPress: BooleanConsumer? = null + open val isChecked: GetterSetter = GetterSetter.box(false) ) : AbstractButtonPanel(screen, parent, x, y, width, height) { - open var isChecked = false - open val IDLE_UNCHECKED: AbstractMatterySprite = Companion.IDLE_UNCHECKED open val IDLE_CHECKED: AbstractMatterySprite = Companion.IDLE_CHECKED open val HOVERED_UNCHECKED: AbstractMatterySprite = Companion.HOVERED_UNCHECKED @@ -33,26 +27,26 @@ open class CheckBoxPanel @JvmOverloads constructor( protected fun renderCheckboxBackground(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) { if (isDisabled) { - if (isChecked) { + if (isChecked.get()) { DISABLED_CHECKED.render(graphics, width = width, height = height) } else { DISABLED_UNCHECKED.render(graphics, width = width, height = height) } } else { if (isPressed) { - if (isChecked) { + if (isChecked.get()) { PRESSED_CHECKED.render(graphics, width = width, height = height) } else { PRESSED_UNCHECKED.render(graphics, width = width, height = height) } } else if (isHovered) { - if (isChecked) { + if (isChecked.get()) { HOVERED_CHECKED.render(graphics, width = width, height = height) } else { HOVERED_UNCHECKED.render(graphics, width = width, height = height) } } else { - if (isChecked) { + if (isChecked.get()) { IDLE_CHECKED.render(graphics, width = width, height = height) } else { IDLE_UNCHECKED.render(graphics, width = width, height = height) @@ -66,8 +60,7 @@ open class CheckBoxPanel @JvmOverloads constructor( } override fun onClick(mouseButton: Int) { - isChecked = !isChecked - onPress?.accept(isChecked) + isChecked.accept(!isChecked.get()) } companion object {