Checkboxes now have all button variants, and behave like buttons
Fixes #123
This commit is contained in:
parent
b501efc515
commit
9570511d8a
@ -5,8 +5,8 @@ data class SubSkinGrid(
|
|||||||
val parent: AbstractSkinElement,
|
val parent: AbstractSkinElement,
|
||||||
val width: Float,
|
val width: Float,
|
||||||
val height: Float,
|
val height: Float,
|
||||||
val rows: Int = 16,
|
|
||||||
val columns: Int = 16,
|
val columns: Int = 16,
|
||||||
|
val rows: Int = 16,
|
||||||
) {
|
) {
|
||||||
var row = 0
|
var row = 0
|
||||||
var column = 0
|
var column = 0
|
||||||
@ -51,3 +51,10 @@ data class SubSkinGrid(
|
|||||||
operator fun get(column: Int, row: Int) =
|
operator fun get(column: Int, row: Int) =
|
||||||
parent.subElement(column * width, row * height, width, height)
|
parent.subElement(column * width, row * height, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun AbstractSkinElement.subGrid(
|
||||||
|
width: Float,
|
||||||
|
height: Float,
|
||||||
|
columns: Int = 16,
|
||||||
|
rows: Int = 16,
|
||||||
|
) = SubSkinGrid(this, width, height, columns, rows)
|
||||||
|
@ -10,7 +10,7 @@ object WidgetLocation {
|
|||||||
val MISC = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "widgets/misc"), 64f, 64f)
|
val MISC = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "widgets/misc"), 64f, 64f)
|
||||||
val PATTERN_PANEL_TABS = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "widgets/pattern_panel_tabs"), 64f, 32f)
|
val PATTERN_PANEL_TABS = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "widgets/pattern_panel_tabs"), 64f, 32f)
|
||||||
|
|
||||||
val CHECKBOX = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "widgets/checkbox"), 32f, 16f)
|
val CHECKBOX = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "widgets/checkbox"), 32f, 64f)
|
||||||
val PROGRESS_ARROWS = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "widgets/progress_arrows"), 32f, 32f)
|
val PROGRESS_ARROWS = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "widgets/progress_arrows"), 32f, 32f)
|
||||||
val HORIZONTAL_GAUGES = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "widgets/horizontal_gauges"), 128f, 64f)
|
val HORIZONTAL_GAUGES = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "widgets/horizontal_gauges"), 128f, 64f)
|
||||||
val VERTICAL_GAUGES = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "widgets/vertical_gauges"), 128f, 48f)
|
val VERTICAL_GAUGES = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "widgets/vertical_gauges"), 128f, 48f)
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package ru.dbotthepony.mc.otm.client.screen.panels
|
package ru.dbotthepony.mc.otm.client.screen.panels
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.InputConstants
|
||||||
import com.mojang.blaze3d.vertex.PoseStack
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
import net.minecraft.client.gui.screens.Screen
|
import net.minecraft.client.gui.screens.Screen
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import ru.dbotthepony.mc.otm.client.minecraft
|
import ru.dbotthepony.mc.otm.client.minecraft
|
||||||
import ru.dbotthepony.mc.otm.client.playGuiClickSound
|
import ru.dbotthepony.mc.otm.client.playGuiClickSound
|
||||||
import ru.dbotthepony.mc.otm.client.render.SkinElement
|
import ru.dbotthepony.mc.otm.client.render.AbstractSkinElement
|
||||||
import ru.dbotthepony.mc.otm.client.render.WidgetLocation
|
import ru.dbotthepony.mc.otm.client.render.WidgetLocation
|
||||||
import ru.dbotthepony.mc.otm.client.render.subElement
|
import ru.dbotthepony.mc.otm.client.render.subGrid
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.CheckBoxPanel.Companion.REGULAR_DIMENSIONS
|
import ru.dbotthepony.mc.otm.client.screen.panels.CheckBoxPanel.Companion.REGULAR_DIMENSIONS
|
||||||
import ru.dbotthepony.mc.otm.menu.widget.BooleanPlayerInputWidget
|
import ru.dbotthepony.mc.otm.menu.widget.BooleanPlayerInputWidget
|
||||||
|
|
||||||
@ -21,29 +22,89 @@ open class CheckBoxPanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
) : EditablePanel<S>(screen, parent, x, y, width, height) {
|
) : EditablePanel<S>(screen, parent, x, y, width, height) {
|
||||||
open var checked = false
|
open var checked = false
|
||||||
open var isDisabled = false
|
open var isDisabled = false
|
||||||
|
protected var isPressed = false
|
||||||
|
|
||||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||||
|
if (isDisabled) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
CHECKBOX_CHECKED.render(stack)
|
DISABLED_CHECKED.render(stack, width = width, height = height)
|
||||||
} else {
|
} else {
|
||||||
CHECKBOX_UNCHECKED.render(stack)
|
DISABLED_UNCHECKED.render(stack, width = width, height = height)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (isPressed) {
|
||||||
|
if (checked) {
|
||||||
|
PRESSED_CHECKED.render(stack, width = width, height = height)
|
||||||
|
} else {
|
||||||
|
PRESSED_UNCHECKED.render(stack, width = width, height = height)
|
||||||
|
}
|
||||||
|
} else if (isHovered) {
|
||||||
|
if (checked) {
|
||||||
|
HOVERED_CHECKED.render(stack, width = width, height = height)
|
||||||
|
} else {
|
||||||
|
HOVERED_UNCHECKED.render(stack, width = width, height = height)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (checked) {
|
||||||
|
IDLE_CHECKED.render(stack, width = width, height = height)
|
||||||
|
} else {
|
||||||
|
IDLE_UNCHECKED.render(stack, width = width, height = height)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected open fun onClick() {
|
||||||
|
checked = !checked
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
||||||
if (!isDisabled) {
|
if (!isDisabled && button == InputConstants.MOUSE_BUTTON_LEFT) {
|
||||||
checked = !checked
|
grabMouseInput = true
|
||||||
|
isPressed = true
|
||||||
playGuiClickSound()
|
playGuiClickSound()
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun mouseReleasedInner(x: Double, y: Double, button: Int): Boolean {
|
||||||
|
if (isPressed && button == InputConstants.MOUSE_BUTTON_LEFT) {
|
||||||
|
if (isHovered) {
|
||||||
|
onClick()
|
||||||
|
}
|
||||||
|
|
||||||
|
isPressed = false
|
||||||
|
grabMouseInput = false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val REGULAR_DIMENSIONS = 15f
|
const val REGULAR_DIMENSIONS = 15f
|
||||||
|
|
||||||
val CHECKBOX_UNCHECKED = WidgetLocation.CHECKBOX.subElement(width = REGULAR_DIMENSIONS, height = REGULAR_DIMENSIONS)
|
val IDLE_UNCHECKED: AbstractSkinElement
|
||||||
val CHECKBOX_CHECKED = WidgetLocation.CHECKBOX.subElement(x = REGULAR_DIMENSIONS, width = REGULAR_DIMENSIONS, height = REGULAR_DIMENSIONS)
|
val IDLE_CHECKED: AbstractSkinElement
|
||||||
|
val HOVERED_UNCHECKED: AbstractSkinElement
|
||||||
|
val HOVERED_CHECKED: AbstractSkinElement
|
||||||
|
val PRESSED_UNCHECKED: AbstractSkinElement
|
||||||
|
val PRESSED_CHECKED: AbstractSkinElement
|
||||||
|
val DISABLED_UNCHECKED: AbstractSkinElement
|
||||||
|
val DISABLED_CHECKED: AbstractSkinElement
|
||||||
|
|
||||||
|
init {
|
||||||
|
val grid = WidgetLocation.CHECKBOX.subGrid(REGULAR_DIMENSIONS, REGULAR_DIMENSIONS, 2, 4)
|
||||||
|
|
||||||
|
IDLE_UNCHECKED = grid.next()
|
||||||
|
IDLE_CHECKED = grid.next()
|
||||||
|
HOVERED_UNCHECKED = grid.next()
|
||||||
|
HOVERED_CHECKED = grid.next()
|
||||||
|
PRESSED_UNCHECKED = grid.next()
|
||||||
|
PRESSED_CHECKED = grid.next()
|
||||||
|
DISABLED_UNCHECKED = grid.next()
|
||||||
|
DISABLED_CHECKED = grid.next()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,15 +125,9 @@ open class CheckBoxInputPanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
get() = !widget.ignoreSpectators || minecraft.player?.isSpectator == true
|
get() = !widget.ignoreSpectators || minecraft.player?.isSpectator == true
|
||||||
set(value) {}
|
set(value) {}
|
||||||
|
|
||||||
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
override fun onClick() {
|
||||||
super.mouseClickedInner(x, y, button)
|
|
||||||
|
|
||||||
if (!isDisabled) {
|
|
||||||
widget.userInput(!checked, minecraft.player)
|
widget.userInput(!checked, minecraft.player)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open class CheckBoxLabelPanel<out S : Screen> @JvmOverloads constructor(
|
open class CheckBoxLabelPanel<out S : Screen> @JvmOverloads constructor(
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 224 B After Width: | Height: | Size: 838 B |
Loading…
Reference in New Issue
Block a user