Make checkboxes accept GetterSetter as checking property
This commit is contained in:
parent
687b5c9726
commit
0e9a480dd8
@ -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<out S : Screen> @JvmOverloads constructor(
|
||||
open class CheckBoxInputPanel<out S : Screen>(
|
||||
screen: S,
|
||||
parent: EditablePanel<*>?,
|
||||
val widget: IPlayerInputWithFeedback<Boolean>,
|
||||
@ -16,16 +16,8 @@ open class CheckBoxInputPanel<out S : Screen> @JvmOverloads constructor(
|
||||
y: Float = 0f,
|
||||
width: Float = REGULAR_DIMENSIONS + 120f,
|
||||
height: Float = REGULAR_DIMENSIONS
|
||||
) : CheckBoxPanel<S>(screen, parent, x, y, width, height) {
|
||||
override var isChecked: Boolean
|
||||
get() = widget.value
|
||||
set(value) {}
|
||||
|
||||
) : CheckBoxPanel<S>(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)
|
||||
}
|
||||
}
|
||||
|
@ -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<out S : Screen> @JvmOverloads constructor(
|
||||
open class CheckBoxLabelInputPanel<out S : Screen>(
|
||||
screen: S,
|
||||
parent: EditablePanel<*>?,
|
||||
widget: IPlayerInputWithFeedback<Boolean>,
|
||||
val widget: IPlayerInputWithFeedback<Boolean>,
|
||||
text: Component,
|
||||
x: Float = 0f,
|
||||
y: Float = 0f,
|
||||
width: Float = CheckBoxPanel.REGULAR_DIMENSIONS + 120f,
|
||||
height: Float = CheckBoxPanel.REGULAR_DIMENSIONS
|
||||
) : AbstractCheckBoxLabelPanel<S>(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)
|
||||
}
|
||||
|
@ -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<out S : Screen> @JvmOverloads constructor(
|
||||
open class CheckBoxLabelPanel<out S : Screen>(
|
||||
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<Boolean> = GetterSetter.box(false)
|
||||
) : AbstractCheckBoxLabelPanel<S>(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)
|
||||
}
|
||||
|
@ -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<out S : Screen> @JvmOverloads constructor(
|
||||
open class CheckBoxPanel<out S : Screen>(
|
||||
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<Boolean> = GetterSetter.box(false)
|
||||
) : AbstractButtonPanel<S>(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<out S : Screen> @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<out S : Screen> @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
override fun onClick(mouseButton: Int) {
|
||||
isChecked = !isChecked
|
||||
onPress?.accept(isChecked)
|
||||
isChecked.accept(!isChecked.get())
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
Loading…
Reference in New Issue
Block a user