diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/SubSkinGrid.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/SubSkinGrid.kt index 9b82bdedb..65cabcfec 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/SubSkinGrid.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/SubSkinGrid.kt @@ -5,8 +5,8 @@ data class SubSkinGrid( val parent: AbstractSkinElement, val width: Float, val height: Float, - val rows: Int = 16, val columns: Int = 16, + val rows: Int = 16, ) { var row = 0 var column = 0 @@ -51,3 +51,10 @@ data class SubSkinGrid( operator fun get(column: Int, row: Int) = 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) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/WidgetLocation.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/WidgetLocation.kt index abd4f14e0..e49f0e87d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/WidgetLocation.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/WidgetLocation.kt @@ -10,7 +10,7 @@ object WidgetLocation { 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 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 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) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/CheckBox.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/CheckBox.kt index a50e2f453..0cdf82698 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/CheckBox.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/CheckBox.kt @@ -1,13 +1,14 @@ package ru.dbotthepony.mc.otm.client.screen.panels +import com.mojang.blaze3d.platform.InputConstants import com.mojang.blaze3d.vertex.PoseStack import net.minecraft.client.gui.screens.Screen import net.minecraft.network.chat.Component import ru.dbotthepony.mc.otm.client.minecraft 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.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.menu.widget.BooleanPlayerInputWidget @@ -21,29 +22,89 @@ open class CheckBoxPanel @JvmOverloads constructor( ) : EditablePanel(screen, parent, x, y, width, height) { open var checked = false open var isDisabled = false + protected var isPressed = false override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { - if (checked) { - CHECKBOX_CHECKED.render(stack) + if (isDisabled) { + if (checked) { + DISABLED_CHECKED.render(stack, width = width, height = height) + } else { + DISABLED_UNCHECKED.render(stack, width = width, height = height) + } } else { - CHECKBOX_UNCHECKED.render(stack) + 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 { - if (!isDisabled) { - checked = !checked + if (!isDisabled && button == InputConstants.MOUSE_BUTTON_LEFT) { + grabMouseInput = true + isPressed = true playGuiClickSound() } 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 { const val REGULAR_DIMENSIONS = 15f - val CHECKBOX_UNCHECKED = WidgetLocation.CHECKBOX.subElement(width = REGULAR_DIMENSIONS, height = REGULAR_DIMENSIONS) - val CHECKBOX_CHECKED = WidgetLocation.CHECKBOX.subElement(x = REGULAR_DIMENSIONS, width = REGULAR_DIMENSIONS, height = REGULAR_DIMENSIONS) + val IDLE_UNCHECKED: AbstractSkinElement + 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,14 +125,8 @@ open class CheckBoxInputPanel @JvmOverloads constructor( get() = !widget.ignoreSpectators || minecraft.player?.isSpectator == true set(value) {} - override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean { - super.mouseClickedInner(x, y, button) - - if (!isDisabled) { - widget.userInput(!checked, minecraft.player) - } - - return true + override fun onClick() { + widget.userInput(!checked, minecraft.player) } } diff --git a/src/main/resources/assets/overdrive_that_matters/textures/gui/widgets/checkbox.png b/src/main/resources/assets/overdrive_that_matters/textures/gui/widgets/checkbox.png index e91224c79..740496b5a 100644 Binary files a/src/main/resources/assets/overdrive_that_matters/textures/gui/widgets/checkbox.png and b/src/main/resources/assets/overdrive_that_matters/textures/gui/widgets/checkbox.png differ