Inventory rows height test

This commit is contained in:
DBotThePony 2022-09-09 17:53:45 +07:00
parent d42974072b
commit d66f892d9e
Signed by: DBot
GPG Key ID: DCC23B5715498507
9 changed files with 260 additions and 51 deletions

View File

@ -4,6 +4,10 @@ import net.minecraft.client.Minecraft
import net.minecraft.client.gui.Font
import net.minecraft.client.resources.sounds.SimpleSoundInstance
import net.minecraft.sounds.SoundEvents
import org.lwjgl.glfw.GLFW
import java.nio.ByteBuffer
import java.nio.ByteOrder
import java.nio.DoubleBuffer
inline val minecraft: Minecraft get() = Minecraft.getInstance()
inline val font: Font get() = minecraft.font
@ -11,3 +15,64 @@ inline val font: Font get() = minecraft.font
fun playGuiClickSound() {
minecraft.soundManager.play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0f))
}
fun setMousePos(x: Double, y: Double) {
GLFW.glfwSetCursorPos(minecraft.window.window, x, y)
}
private val cursorXPosBuf = ByteBuffer.allocateDirect(8).also { it.order(ByteOrder.LITTLE_ENDIAN) }.asDoubleBuffer()
private val cursorYPosBuf = ByteBuffer.allocateDirect(8).also { it.order(ByteOrder.LITTLE_ENDIAN) }.asDoubleBuffer()
data class MousePos(val x: Double, val y: Double) {
fun set() {
setMousePos(x, y)
}
fun move(x: Double = 0.0, y: Double = 0.0) {
GLFW.glfwSetCursorPos(minecraft.window.window, this.x + x, this.y + y)
}
fun move(x: Float = 0.0f, y: Float = 0.0f) {
GLFW.glfwSetCursorPos(minecraft.window.window, this.x + x, this.y + y)
}
fun moveScaled(x: Double = 0.0, y: Double = 0.0) {
GLFW.glfwSetCursorPos(minecraft.window.window, this.x + x * minecraft.window.guiScale, this.y + y * minecraft.window.guiScale)
}
fun moveScaled(x: Float = 0.0f, y: Float = 0.0f) {
GLFW.glfwSetCursorPos(minecraft.window.window, this.x + x * minecraft.window.guiScale, this.y + y * minecraft.window.guiScale)
}
}
val mousePos: MousePos get() {
cursorXPosBuf.position(0)
cursorYPosBuf.position(0)
GLFW.glfwGetCursorPos(minecraft.window.window, cursorXPosBuf, cursorYPosBuf)
cursorXPosBuf.position(0)
cursorYPosBuf.position(0)
return MousePos(cursorXPosBuf.get(), cursorYPosBuf.get())
}
fun moveMousePos(x: Double = 0.0, y: Double = 0.0) {
val (currentX, currentY) = mousePos
GLFW.glfwSetCursorPos(minecraft.window.window, currentX + x, currentY + y)
}
fun moveMousePos(x: Float = 0.0f, y: Float = 0.0f) {
val (currentX, currentY) = mousePos
GLFW.glfwSetCursorPos(minecraft.window.window, currentX + x, currentY + y)
}
fun moveMousePosScaled(x: Double = 0.0, y: Double = 0.0) {
val (currentX, currentY) = mousePos
GLFW.glfwSetCursorPos(minecraft.window.window, currentX + x * minecraft.window.guiScale, currentY + y * minecraft.window.guiScale)
}
fun moveMousePosScaled(x: Float = 0.0f, y: Float = 0.0f) {
val (currentX, currentY) = mousePos
GLFW.glfwSetCursorPos(minecraft.window.window, currentX + x * minecraft.window.guiScale, currentY + y * minecraft.window.guiScale)
}

View File

@ -6,7 +6,7 @@ import net.minecraft.resources.ResourceLocation
import ru.dbotthepony.mc.otm.client.screen.panels.DockProperty
@Suppress("unused")
class SkinGrid(
data class SkinGrid(
val texture: ResourceLocation,
val width: Float,
val height: Float,
@ -92,14 +92,15 @@ fun ResourceLocation.vLine(
) = SkinElement(this, x, y, 1f, height, textureWidth, textureHeight)
@Suppress("unused")
class SkinElement @JvmOverloads constructor(
data class SkinElement @JvmOverloads constructor(
val texture: ResourceLocation,
val x: Float,
val y: Float,
val width: Float,
val height: Float,
val imageWidth: Float = 256f,
val imageHeight: Float = 256f
val imageHeight: Float = 256f,
val winding: UVWindingOrder = UVWindingOrder.NORMAL
) {
init {
require(x >= 0f) { "Invalid x $x" }
@ -117,7 +118,7 @@ class SkinElement @JvmOverloads constructor(
y: Float = 0f,
width: Float = this.width,
height: Float = this.height,
winding: UVWindingOrder = UVWindingOrder.U0_V0_U1_V1
winding: UVWindingOrder = this.winding
) {
RenderSystem.setShaderTexture(0, texture)
RenderSystem.enableBlend()
@ -133,7 +134,7 @@ class SkinElement @JvmOverloads constructor(
y: Double = 0.0,
width: Double = this.width.toDouble(),
height: Double = this.height.toDouble(),
winding: UVWindingOrder = UVWindingOrder.U0_V0_U1_V1
winding: UVWindingOrder = this.winding
) = render(stack, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), winding)
@JvmOverloads
@ -143,7 +144,7 @@ class SkinElement @JvmOverloads constructor(
y: Float = 0f,
width: Float = this.width,
height: Float = this.height,
winding: UVWindingOrder = UVWindingOrder.U0_V0_U1_V1
winding: UVWindingOrder = this.winding
) {
RenderSystem.setShaderTexture(0, texture)
RenderSystem.enableBlend()
@ -159,7 +160,7 @@ class SkinElement @JvmOverloads constructor(
y: Double = 0.0,
width: Double = this.width.toDouble(),
height: Double = this.height.toDouble(),
winding: UVWindingOrder = UVWindingOrder.U0_V0_U1_V1
winding: UVWindingOrder = this.winding
) = renderPartial(stack, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), winding)
@JvmOverloads
@ -168,7 +169,7 @@ class SkinElement @JvmOverloads constructor(
x: Float = 0f,
y: Float = 0f,
width: Float = this.width,
winding: UVWindingOrder = UVWindingOrder.U0_V0_U1_V1,
winding: UVWindingOrder = this.winding
) {
render(stack, x, y, width = width, winding = winding)
}
@ -179,7 +180,7 @@ class SkinElement @JvmOverloads constructor(
x: Double,
y: Double = 0.0,
width: Double = this.width.toDouble(),
winding: UVWindingOrder = UVWindingOrder.U0_V0_U1_V1,
winding: UVWindingOrder = this.winding,
) = renderWidth(stack, x.toFloat(), y.toFloat(), width.toFloat(), winding)
@JvmOverloads
@ -188,7 +189,7 @@ class SkinElement @JvmOverloads constructor(
x: Float = 0f,
y: Float = 0f,
height: Float = this.height,
winding: UVWindingOrder = UVWindingOrder.U0_V0_U1_V1,
winding: UVWindingOrder = this.winding,
) {
render(stack, x, y, height = height, winding = winding)
}
@ -199,7 +200,7 @@ class SkinElement @JvmOverloads constructor(
x: Double,
y: Double = 0.0,
height: Double = this.height.toDouble(),
winding: UVWindingOrder = UVWindingOrder.U0_V0_U1_V1,
winding: UVWindingOrder = this.winding,
) = renderHieght(stack, x.toFloat(), y.toFloat(), height.toFloat(), winding)
private val u0 = this.x / imageWidth
@ -214,7 +215,7 @@ class SkinElement @JvmOverloads constructor(
y: Float = 0f,
width: Float = this.width,
height: Float = this.height,
winding: UVWindingOrder = UVWindingOrder.U0_V0_U1_V1
winding: UVWindingOrder = UVWindingOrder.NORMAL
) {
val winded = winding.translate(u0, v0, u1, v1)
@ -235,7 +236,7 @@ class SkinElement @JvmOverloads constructor(
y: Double = 0.0,
width: Double = this.width.toDouble(),
height: Double = this.height.toDouble(),
winding: UVWindingOrder = UVWindingOrder.U0_V0_U1_V1
winding: UVWindingOrder = UVWindingOrder.NORMAL
) = renderRaw(stack, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), winding)
@JvmOverloads
@ -245,7 +246,7 @@ class SkinElement @JvmOverloads constructor(
y: Float = 0f,
width: Float = this.width,
height: Float = this.height,
winding: UVWindingOrder = UVWindingOrder.U0_V0_U1_V1
winding: UVWindingOrder = UVWindingOrder.NORMAL
) {
val u1 = (this.x + width) / imageWidth
val v1 = (this.y + height) / imageHeight
@ -269,11 +270,11 @@ class SkinElement @JvmOverloads constructor(
y: Double = 0.0,
width: Double = this.width.toDouble(),
height: Double = this.height.toDouble(),
winding: UVWindingOrder = UVWindingOrder.U0_V0_U1_V1
winding: UVWindingOrder = UVWindingOrder.NORMAL
) = renderRawPartial(stack, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), winding)
}
class StretchingRectangleElement(
data class StretchingRectangleElement(
val topLeft: SkinElement,
val topRight: SkinElement,
val bottomLeft: SkinElement,

View File

@ -0,0 +1,15 @@
package ru.dbotthepony.mc.otm.client.render
object Widgets {
val SLOT = WidgetLocation.WIDGETS.element(0f, 0f, 18f, 18f)
val ARROW_UP_BUTTON_IDLE = WidgetLocation.WIDGETS.element(0f, 18f, 18f, 6f)
val ARROW_UP_BUTTON_HOVERED = WidgetLocation.WIDGETS.element(0f, 18f + 6f, 18f, 6f)
val ARROW_UP_BUTTON_PRESSED = WidgetLocation.WIDGETS.element(0f, 18f + 6f * 2f, 18f, 6f)
val ARROW_UP_BUTTON_DISABLED = WidgetLocation.WIDGETS.element(0f, 18f + 6f * 3f, 18f, 6f)
val ARROW_DOWN_BUTTON_IDLE = ARROW_UP_BUTTON_IDLE.copy(winding = UVWindingOrder.FLIP)
val ARROW_DOWN_BUTTON_HOVERED = ARROW_UP_BUTTON_HOVERED.copy(winding = UVWindingOrder.FLIP)
val ARROW_DOWN_BUTTON_PRESSED = ARROW_UP_BUTTON_PRESSED.copy(winding = UVWindingOrder.FLIP)
val ARROW_DOWN_BUTTON_DISABLED = ARROW_UP_BUTTON_DISABLED.copy(winding = UVWindingOrder.FLIP)
}

View File

@ -3,10 +3,14 @@ package ru.dbotthepony.mc.otm.client.screen
import com.mojang.blaze3d.platform.InputConstants
import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.client.gui.screens.inventory.InventoryScreen
import ru.dbotthepony.mc.otm.client.mousePos
import ru.dbotthepony.mc.otm.client.moveMousePos
import ru.dbotthepony.mc.otm.client.moveMousePosScaled
import ru.dbotthepony.mc.otm.client.render.Widgets18
import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.client.render.element
import ru.dbotthepony.mc.otm.client.screen.panels.*
import ru.dbotthepony.mc.otm.client.setMousePos
import ru.dbotthepony.mc.otm.client.shouldOpenVanillaInventory
import ru.dbotthepony.mc.otm.menu.ExoSuitInventoryMenu
import ru.dbotthepony.mc.otm.network.ExoSuitMenuOpen
@ -15,25 +19,59 @@ import yalter.mousetweaks.api.MouseTweaksDisableWheelTweak
@MouseTweaksDisableWheelTweak
class ExoSuitInventoryScreen(menu: ExoSuitInventoryMenu) : MatteryScreen<ExoSuitInventoryMenu>(menu, TranslatableComponent("otm.gui.exosuit")) {
var inventoryRows = 3
set(value) {
val newValue = value.coerceAtLeast(3).coerceAtMost(6)
val old = field
if (field != newValue) {
field = newValue
if (mainFrame != null) {
updateInventoryRows(old)
}
}
}
private lateinit var mainInventoryLine: EditablePanel<ExoSuitInventoryScreen>
private lateinit var scrollPanel: DiscreteScrollBarPanel<ExoSuitInventoryScreen>
private fun updateInventoryRows(old: Int) {
mainFrame!!.height = FRAME_BASE_HEIGHT + inventoryRows * AbstractSlotPanel.SIZE
mainInventoryLine.height = AbstractSlotPanel.SIZE * inventoryRows
for (i in scrollPanel.scroll until scrollPanel.scroll + old) {
getInventorySlotsRow(i).visible = false
}
for (i in scrollPanel.scroll until scrollPanel.scroll + inventoryRows) {
getInventorySlotsRow(i).also {
it.parent = mainInventoryLine
it.y = AbstractSlotPanel.SIZE * (i - scrollPanel.scroll)
it.visible = true
}
}
scrollPanel.scroll = scrollPanel.scroll
}
override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
val frame = FramePanel(this, width = 200f, height = 180f, title = this.title)
val frame = FramePanel(this, width = 200f, height = FRAME_BASE_HEIGHT + inventoryRows * AbstractSlotPanel.SIZE, title = this.title)
val toolbeltLine = EditablePanel(this, frame, height = 18f)
toolbeltLine.dock = Dock.BOTTOM
toolbeltLine.setDockMargin(top = 3f)
var mainInventoryLine: EditablePanel<*>? = null
val scrollPanel = DiscreteScrollBarPanel(this, null, maxScroll = { ((menu.playerCombinedInventorySlots.size - 27) + 8) / 9 },
scrollPanel = DiscreteScrollBarPanel(this, null, maxScroll = { ((menu.playerCombinedInventorySlots.size - inventoryRows * 9) + 8) / 9 },
scrollCallback = {
_, old, new ->
for (i in old .. old + 2) {
for (i in old until old + inventoryRows) {
getInventorySlotsRow(i).visible = false
}
for (i in new .. new + 2) {
for (i in new until new + inventoryRows) {
val row = getInventorySlotsRow(i)
row.visible = true
row.y = (i - new) * AbstractSlotPanel.SIZE
@ -43,14 +81,13 @@ class ExoSuitInventoryScreen(menu: ExoSuitInventoryMenu) : MatteryScreen<ExoSuit
menu.lastScroll = new
})
scrollPanel.scroll = menu.lastScroll
mainInventoryLine = object : EditablePanel<ExoSuitInventoryScreen>(this@ExoSuitInventoryScreen, frame, height = 18f * 3f) {
mainInventoryLine = object : EditablePanel<ExoSuitInventoryScreen>(this@ExoSuitInventoryScreen, frame, height = AbstractSlotPanel.SIZE * inventoryRows) {
override fun mouseScrolledInner(x: Double, y: Double, scroll: Double): Boolean {
return scrollPanel.mouseScrolledInner(x, y, scroll)
}
}
scrollPanel.scroll = menu.lastScroll
scrollPanel.parent = mainInventoryLine
mainInventoryLine.dock = Dock.BOTTOM
@ -63,7 +100,7 @@ class ExoSuitInventoryScreen(menu: ExoSuitInventoryMenu) : MatteryScreen<ExoSuit
val offhand = SlotPanel(this, toolbeltLine, menu.offhandSlot)
offhand.dock = Dock.RIGHT
for (i in scrollPanel.scroll .. scrollPanel.scroll + 2) {
for (i in scrollPanel.scroll until scrollPanel.scroll + inventoryRows) {
getInventorySlotsRow(i).also {
it.parent = mainInventoryLine
it.y = AbstractSlotPanel.SIZE * (i - scrollPanel.scroll)
@ -113,7 +150,7 @@ class ExoSuitInventoryScreen(menu: ExoSuitInventoryMenu) : MatteryScreen<ExoSuit
val resultPanel = SlotPanel(this, craftingCanvas, menu.craftingResultSlot, x = craftingCanvas.width - 18f, y = topLine.height / 2f - 9f)
val arrowPanel = object : EditablePanel<ExoSuitInventoryScreen>(
object : EditablePanel<ExoSuitInventoryScreen>(
this@ExoSuitInventoryScreen,
craftingCanvas,
x = craftingSlotsCanvas.width,
@ -132,15 +169,27 @@ class ExoSuitInventoryScreen(menu: ExoSuitInventoryMenu) : MatteryScreen<ExoSuit
shouldOpenVanillaInventory = true
val minecraft = minecraft!!
val mouseX = minecraft.mouseHandler.xpos()
val mouseY = minecraft.mouseHandler.ypos()
val (mouseX, mouseY) = mousePos
onClose()
minecraft.setScreen(InventoryScreen(minecraft.player!!))
InputConstants.grabOrReleaseMouse(minecraft.window.window, 212993, mouseX, mouseY)
setMousePos(mouseX, mouseY)
}).also { it.tooltip = TranslatableComponent("otm.gui.exosuit.go_back") }
HeightControls(this, frame, frame.width + 2f, frame.height.coerceAtMost(95f)) {
inventoryRows += if (it) 1 else -1
val movePixels = if (it) -AbstractSlotPanel.SIZE / 2f else AbstractSlotPanel.SIZE / 2f
frame.y += movePixels
moveMousePosScaled(y = movePixels)
HeightControls.Status.of(inventoryRows < 6, inventoryRows > 3)
}.also {
it.controlStatus = HeightControls.Status.of(inventoryRows < 6, inventoryRows > 3)
}
return frame
}
@ -153,5 +202,7 @@ class ExoSuitInventoryScreen(menu: ExoSuitInventoryMenu) : MatteryScreen<ExoSuit
val ENTITY_RECTANGLE = INVENTORY_LOCATION.element(25f, 7f, 51f, 72f)
val STATUS_EFFECT_BG = INVENTORY_LOCATION.element(0f, 166f, 120f, 32f)
val CRAFT_ARROW = INVENTORY_LOCATION.element(135f, 29f, 16f, 13f)
const val FRAME_BASE_HEIGHT = 126f
}
}

View File

@ -3,7 +3,7 @@ package ru.dbotthepony.mc.otm.client.screen.panels
import com.mojang.blaze3d.platform.InputConstants
import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.ChatFormatting
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
import net.minecraft.client.gui.screens.Screen
import net.minecraft.network.chat.Component
import ru.dbotthepony.mc.otm.client.playGuiClickSound
import ru.dbotthepony.mc.otm.core.TextComponent
@ -15,7 +15,7 @@ import java.util.*
import kotlin.collections.ArrayList
import kotlin.reflect.KMutableProperty0
open class ButtonPanel<out S : AbstractContainerScreen<*>>(
open class ButtonPanel<out S : Screen>(
screen: S,
parent: EditablePanel<*>?,
x: Float = 0f,
@ -42,6 +42,10 @@ open class ButtonPanel<out S : AbstractContainerScreen<*>>(
protected var callback: Runnable? = null
protected var pressed = false
protected open fun onClick(button: Int) {
callback?.run()
}
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
if (isDisabled || pressed) {
return true
@ -62,7 +66,7 @@ open class ButtonPanel<out S : AbstractContainerScreen<*>>(
pressed = false
if (isHovered) {
callback?.run()
onClick(button)
}
return true
@ -113,7 +117,7 @@ open class ButtonPanel<out S : AbstractContainerScreen<*>>(
}
@Suppress("PropertyName")
abstract class RectangleButtonPanel<out S : AbstractContainerScreen<*>>(
abstract class RectangleButtonPanel<out S : Screen>(
screen: S,
parent: EditablePanel<*>?,
x: Float = 0f,
@ -124,7 +128,7 @@ abstract class RectangleButtonPanel<out S : AbstractContainerScreen<*>>(
) : EditablePanel<S>(screen, parent, x, y, width, height) {
protected var pressed = false
protected open fun click(clickButton: Int) {
protected open fun onClick(clickButton: Int) {
onPress?.invoke(clickButton)
}
@ -175,7 +179,7 @@ abstract class RectangleButtonPanel<out S : AbstractContainerScreen<*>>(
pressed = false
if (isHovered) {
click(button)
onClick(button)
}
}
@ -185,7 +189,7 @@ abstract class RectangleButtonPanel<out S : AbstractContainerScreen<*>>(
}
}
abstract class EnumRectangleButtonPanel<out S : AbstractContainerScreen<*>, T : Enum<T>>(
abstract class EnumRectangleButtonPanel<out S : Screen, T : Enum<T>>(
screen: S,
parent: EditablePanel<*>?,
x: Float = 0f,
@ -293,7 +297,7 @@ abstract class EnumRectangleButtonPanel<out S : AbstractContainerScreen<*>, T :
return super.mouseReleasedInner(x, y, button)
}
override fun click(clickButton: Int) {
override fun onClick(clickButton: Int) {
when (clickButton) {
InputConstants.MOUSE_BUTTON_LEFT -> {
prop.set(prop.get().next(enum.enumConstants))
@ -354,7 +358,7 @@ abstract class EnumRectangleButtonPanel<out S : AbstractContainerScreen<*>, T :
}
}
open class LargeRectangleButtonPanel<out S : AbstractContainerScreen<*>>(
open class LargeRectangleButtonPanel<out S : Screen>(
screen: S,
parent: EditablePanel<*>?,
x: Float = 0f,
@ -385,7 +389,7 @@ open class LargeRectangleButtonPanel<out S : AbstractContainerScreen<*>>(
}
}
open class LargeEnumRectangleButtonPanel<out S : AbstractContainerScreen<*>, T : Enum<T>>(
open class LargeEnumRectangleButtonPanel<out S : Screen, T : Enum<T>>(
screen: S,
parent: EditablePanel<*>?,
x: Float = 0f,
@ -407,7 +411,7 @@ open class LargeEnumRectangleButtonPanel<out S : AbstractContainerScreen<*>, T :
}
}
open class SmallRectangleButtonPanel<out S : AbstractContainerScreen<*>>(
open class SmallRectangleButtonPanel<out S : Screen>(
screen: S,
parent: EditablePanel<*>?,
x: Float = 0f,
@ -438,7 +442,7 @@ open class SmallRectangleButtonPanel<out S : AbstractContainerScreen<*>>(
}
}
open class SmallEnumRectangleButtonPanel<out S : AbstractContainerScreen<*>, T : Enum<T>>(
open class SmallEnumRectangleButtonPanel<out S : Screen, T : Enum<T>>(
screen: S,
parent: EditablePanel<*>?,
x: Float = 0f,

View File

@ -95,13 +95,7 @@ open class DiscreteScrollBarPanel<S : Screen> @JvmOverloads constructor(
return
}
val newValue = if (value < 0) {
0
} else if (value > maxScroll.invoke(this)) {
maxScroll.invoke(this)
} else {
value
}
val newValue = value.coerceAtLeast(0).coerceAtMost(maxScroll.invoke(this))
if (newValue != field) {
val old = field

View File

@ -0,0 +1,79 @@
package ru.dbotthepony.mc.otm.client.screen.panels
import com.mojang.blaze3d.platform.InputConstants
import net.minecraft.client.gui.screens.Screen
import ru.dbotthepony.mc.otm.client.render.SkinElement
import ru.dbotthepony.mc.otm.client.render.Widgets
open class HeightControls<out S : Screen>(
screen: S,
parent: EditablePanel<*>?,
x: Float = 0f,
y: Float = 0f,
val callback: (isIncrease: Boolean) -> Status
) : BackgroundPanel<S>(screen, parent, x, y, WIDTH, HEIGHT) {
enum class Status(val canIncrease: Boolean, val canDecrease: Boolean) {
NONE(false, false),
INCREASE(true, false),
DECREASE(false, true),
EITHER(true, true);
companion object {
fun of(canIncrease: Boolean, canDecrease: Boolean): Status {
return if (canIncrease && canDecrease) {
EITHER
} else if (canIncrease) {
INCREASE
} else if (canDecrease) {
DECREASE
} else {
NONE
}
}
}
}
var controlStatus: Status = Status.EITHER
set(value) {
if (field == value)
return
field = value
increase.isDisabled = !value.canIncrease
decrease.isDisabled = !value.canDecrease
}
open inner class Control(val isIncrease: Boolean) : RectangleButtonPanel<S>(screen, this@HeightControls, width = BUTTON_WIDTH, height = BUTTON_HEIGHT) {
override val PRESSED: SkinElement = if (isIncrease) Widgets.ARROW_DOWN_BUTTON_PRESSED else Widgets.ARROW_UP_BUTTON_PRESSED
override val HOVERED: SkinElement = if (isIncrease) Widgets.ARROW_DOWN_BUTTON_HOVERED else Widgets.ARROW_UP_BUTTON_HOVERED
override val IDLE: SkinElement = if (isIncrease) Widgets.ARROW_DOWN_BUTTON_IDLE else Widgets.ARROW_UP_BUTTON_IDLE
override val DISABLED: SkinElement = if (isIncrease) Widgets.ARROW_DOWN_BUTTON_DISABLED else Widgets.ARROW_UP_BUTTON_DISABLED
init {
dock = Dock.TOP
dockBottom = 2f
}
override fun onClick(clickButton: Int) {
if (clickButton == InputConstants.MOUSE_BUTTON_LEFT) {
this@HeightControls.onClick(isIncrease)
} else if (clickButton == InputConstants.MOUSE_BUTTON_RIGHT) {
this@HeightControls.onClick(!isIncrease)
}
}
}
val decrease = Control(false)
val increase = Control(true)
open fun onClick(isIncrease: Boolean) {
controlStatus = callback.invoke(isIncrease)
}
companion object {
const val BUTTON_WIDTH = 18f
const val BUTTON_HEIGHT = 6f
const val WIDTH = BUTTON_WIDTH + 4f
const val HEIGHT = BUTTON_HEIGHT * 2f + 8f
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB