From b2181819ca9285cb84343069d65825b06f647b3b Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Fri, 21 Oct 2022 22:45:56 +0700 Subject: [PATCH] Split buttons panel file --- .../mc/otm/client/ClientEventHandler.kt | 2 +- .../client/screen/ExoSuitInventoryScreen.kt | 6 +- .../mc/otm/client/screen/ItemMonitorScreen.kt | 1 + .../otm/client/screen/panels/ButtonPanel.kt | 546 ------------------ .../screen/panels/EntityRendererPanel.kt | 1 + .../client/screen/panels/HeightControls.kt | 2 +- .../buttons/BooleanRectangleButtonPanel.kt | 40 ++ .../screen/panels/buttons/ButtonPanel.kt | 115 ++++ .../buttons/EnumRectangleButtonPanel.kt | 186 ++++++ .../LargeBooleanRectangleButtonPanel.kt | 29 + .../buttons/LargeEnumRectangleButtonPanel.kt | 28 + .../buttons/LargeRectangleButtonPanel.kt | 39 ++ .../panels/buttons/RectangleButtonPanel.kt | 81 +++ .../SmallBooleanRectangleButtonPanel.kt | 28 + .../buttons/SmallEnumRectangleButtonPanel.kt | 28 + .../buttons/SmallRectangleButtonPanel.kt | 39 ++ .../mc/otm/compat/cos/CosmeticArmorCompat.kt | 4 +- 17 files changed, 619 insertions(+), 556 deletions(-) delete mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/ButtonPanel.kt create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/BooleanRectangleButtonPanel.kt create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/ButtonPanel.kt create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/EnumRectangleButtonPanel.kt create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/LargeBooleanRectangleButtonPanel.kt create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/LargeEnumRectangleButtonPanel.kt create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/LargeRectangleButtonPanel.kt create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/RectangleButtonPanel.kt create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/SmallBooleanRectangleButtonPanel.kt create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/SmallEnumRectangleButtonPanel.kt create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/SmallRectangleButtonPanel.kt diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientEventHandler.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientEventHandler.kt index f613b95cd..8c61aaeeb 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientEventHandler.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientEventHandler.kt @@ -18,7 +18,7 @@ import ru.dbotthepony.mc.otm.client.screen.ExoSuitInventoryScreen import ru.dbotthepony.mc.otm.client.screen.MatteryScreen import ru.dbotthepony.mc.otm.client.screen.panels.AbstractSlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.DiscreteScrollBarPanel -import ru.dbotthepony.mc.otm.client.screen.panels.LargeRectangleButtonPanel +import ru.dbotthepony.mc.otm.client.screen.panels.buttons.LargeRectangleButtonPanel import ru.dbotthepony.mc.otm.client.screen.panels.Panel2Widget import ru.dbotthepony.mc.otm.compat.InventoryScrollPacket import ru.dbotthepony.mc.otm.compat.cos.isCosmeticArmorScreen diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExoSuitInventoryScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExoSuitInventoryScreen.kt index fc1cde0af..5fc8f7b66 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExoSuitInventoryScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExoSuitInventoryScreen.kt @@ -1,25 +1,21 @@ 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.screen.panels.buttons.LargeRectangleButtonPanel import ru.dbotthepony.mc.otm.client.setMousePos import ru.dbotthepony.mc.otm.client.shouldOpenVanillaInventory -import ru.dbotthepony.mc.otm.compat.cos.CosmeticToggleButton -import ru.dbotthepony.mc.otm.compat.curios.curiosSlots import ru.dbotthepony.mc.otm.core.maxScrollDivision import ru.dbotthepony.mc.otm.menu.ExoSuitInventoryMenu import ru.dbotthepony.mc.otm.network.ExoSuitMenuOpen import ru.dbotthepony.mc.otm.network.MatteryPlayerNetworkChannel import yalter.mousetweaks.api.MouseTweaksDisableWheelTweak -import kotlin.math.cos @MouseTweaksDisableWheelTweak class ExoSuitInventoryScreen(menu: ExoSuitInventoryMenu) : MatteryScreen(menu, TranslatableComponent("otm.gui.exosuit")) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ItemMonitorScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ItemMonitorScreen.kt index 489fc4ea7..cd31a536b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ItemMonitorScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ItemMonitorScreen.kt @@ -13,6 +13,7 @@ import ru.dbotthepony.mc.otm.block.entity.storage.ItemMonitorPlayerSettings import ru.dbotthepony.mc.otm.client.render.UVWindingOrder import ru.dbotthepony.mc.otm.client.render.Widgets8 import ru.dbotthepony.mc.otm.client.screen.panels.* +import ru.dbotthepony.mc.otm.client.screen.panels.buttons.SmallEnumRectangleButtonPanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel import ru.dbotthepony.mc.otm.core.asGetterSetter diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/ButtonPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/ButtonPanel.kt deleted file mode 100644 index 99271f525..000000000 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/ButtonPanel.kt +++ /dev/null @@ -1,546 +0,0 @@ -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.Screen -import net.minecraft.network.chat.Component -import ru.dbotthepony.mc.otm.client.playGuiClickSound -import ru.dbotthepony.mc.otm.core.TextComponent -import ru.dbotthepony.mc.otm.client.render.* -import ru.dbotthepony.mc.otm.core.GetterSetter -import ru.dbotthepony.mc.otm.core.RGBAColor -import ru.dbotthepony.mc.otm.core.next -import ru.dbotthepony.mc.otm.core.prev -import ru.dbotthepony.mc.otm.core.value -import java.util.* -import kotlin.collections.ArrayList -import kotlin.reflect.KMutableProperty0 - -open class ButtonPanel( - screen: S, - parent: EditablePanel<*>?, - x: Float = 0f, - y: Float = 0f, - width: Float = 40f, - height: Float = HEIGHT, - var label: Component -) : EditablePanel(screen, parent, x, y, width, height) { - constructor(screen: S, parent: EditablePanel<*>?, label: Component) : this(screen, parent, x = 0f, label = label) - - constructor( - screen: S, - parent: EditablePanel<*>?, - x: Float = 0f, - y: Float = 0f, - width: Float = 40f, - height: Float = HEIGHT, - label: Component, - onPress: Runnable - ) : this(screen, parent, x, y, width, height, label) { - this.callback = onPress - } - - 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 - } - - if (!tryToGrabMouseInput()) { - return true - } - - pressed = true - playGuiClickSound() - return true - } - - override fun mouseReleasedInner(x: Double, y: Double, button: Int): Boolean { - if (!pressed) { - return true - } - - grabMouseInput = false - pressed = false - - if (isHovered) { - onClick(button) - } - - return true - } - - fun bind(runnable: Runnable) { - callback = runnable - } - - var textColor = RGBAColor.WHITE - - var isDisabled = false - set(value) { - if (field != value) { - if (!value) { - pressed = false - grabMouseInput = false - } - - field = value - } - } - - override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { - if (isDisabled) { - Widgets18.BUTTON_DISABLED_STRETCHABLE.render(stack, width = width, height = height) - } else if (pressed) { - Widgets18.BUTTON_PRESSED_STRETCHABLE.render(stack, width = width, height = height) - } else if (isHovered) { - Widgets18.BUTTON_HOVERED_STRETCHABLE.render(stack, width = width, height = height) - } else { - Widgets18.BUTTON_IDLE_STRETCHABLE.render(stack, width = width, height = height) - } - - font.drawAligned(stack, label, TextAlign.CENTER_CENTER, width / 2f, height / 2f, textColor.toInt()) - } - - override fun sizeToContents() { - super.sizeToContents() - - height = height.coerceAtLeast(HEIGHT).coerceAtLeast(font.lineHeight.toFloat() + 2f) - width = width.coerceAtLeast(HEIGHT).coerceAtLeast(font.width(label) + 4f) - } - - companion object { - const val HEIGHT = 18f - } -} - -@Suppress("PropertyName") -abstract class RectangleButtonPanel( - screen: S, - parent: EditablePanel<*>?, - x: Float = 0f, - y: Float = 0f, - width: Float, - height: Float, - val onPress: ((clickButton: Int) -> Unit)? = null, -) : EditablePanel(screen, parent, x, y, width, height) { - protected var pressed = false - - protected open fun onClick(clickButton: Int) { - onPress?.invoke(clickButton) - } - - abstract val PRESSED: AbstractSkinElement - abstract val HOVERED: AbstractSkinElement - abstract val IDLE: AbstractSkinElement - abstract val DISABLED: AbstractSkinElement - - var isDisabled = false - set(value) { - if (field != value) { - if (!value) { - pressed = false - grabMouseInput = false - } - - field = value - } - } - - override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { - if (isDisabled) { - DISABLED.render(stack, 0f, 0f, width, height) - } else if (pressed) { - PRESSED.render(stack, 0f, 0f, width, height) - } else if (isHovered) { - HOVERED.render(stack, 0f, 0f, width, height) - } else { - IDLE.render(stack, 0f, 0f, width, height) - } - } - - override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean { - if (!isDisabled) { - if (!pressed) { - playGuiClickSound() - } - - if (tryToGrabMouseInput()) { - pressed = true - } - } - - return true - } - - override fun mouseReleasedInner(x: Double, y: Double, button: Int): Boolean { - if (!isDisabled && pressed) { - pressed = false - - if (isHovered) { - onClick(button) - } - } - - grabMouseInput = false - - return true - } -} - -abstract class EnumRectangleButtonPanel>( - screen: S, - parent: EditablePanel<*>?, - x: Float = 0f, - y: Float = 0f, - width: Float, - height: Float, - val enum: Class, - val prop: GetterSetter, - val defaultValue: T, - val onChange: ((newValue: T) -> Unit)? = null, -) : RectangleButtonPanel(screen, parent, x, y, width, height, null) { - private var building = true - - protected val enumMapping = EnumMap>(enum) - protected val tooltipMapping = EnumMap(enum) - - fun addTooltip(value: T, component: Component): EnumRectangleButtonPanel { - check(tooltipMapping.put(value, component) == null) { "Already has mapping for $value" } - return this - } - - var mainTooltip: Component? = null - set(value) { - if (field != null) { - throw UnsupportedOperationException("Write once only") - } - - field = value - } - - fun isFullyDefined(): Boolean { - for (value in enum.enumConstants) { - if (enumMapping[value] == null) { - return false - } - } - - return true - } - - val missingValues: List get() { - val missing = ArrayList() - - for (value in enum.enumConstants) { - if (enumMapping[value] == null) { - missing.add(value) - } - } - - return missing - } - - fun add(value: T, skinElement: AbstractSkinElement, winding: UVWindingOrder = UVWindingOrder.NORMAL): EnumRectangleButtonPanel { - return add(value, skinElement to winding) - } - - fun add(value: T, skinElement: AbstractSkinElement, component: Component, winding: UVWindingOrder = UVWindingOrder.NORMAL): EnumRectangleButtonPanel { - return add(value, component, skinElement to winding) - } - - fun add(value: T, component: Component, skinElement: AbstractSkinElement, winding: UVWindingOrder = UVWindingOrder.NORMAL): EnumRectangleButtonPanel { - return add(value, component, skinElement to winding) - } - - fun add(value: T, pair: Pair): EnumRectangleButtonPanel { - check(building) { "Not building" } - check(enumMapping.put(value, pair) == null) { "Already has mapping for $value" } - - if (enumMapping.size == enum.enumConstants.size) { - finish() - } - - return this - } - - fun add(value: T, component: Component, pair: Pair): EnumRectangleButtonPanel { - addTooltip(value, component) - return add(value, pair) - } - - fun finish(): EnumRectangleButtonPanel { - check(building) { "Not building" } - check(isFullyDefined()) { - "Not all enums having their mapping defined, missing are: ${missingValues.joinToString(", ")}" - } - - building = false - return this - } - - override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { - check(!building) { "Still building this button!" } - super.innerRender(stack, mouseX, mouseY, partialTick) - val pair = checkNotNull(enumMapping[prop.get()]) { "HOW" } - pair.first.render(stack, 0f, 0f, width, height, pair.second) - } - - override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean { - check(!building) { "Still building this button!" } - return super.mouseClickedInner(x, y, button) - } - - override fun mouseReleasedInner(x: Double, y: Double, button: Int): Boolean { - check(!building) { "Still building this button!" } - return super.mouseReleasedInner(x, y, button) - } - - override fun onClick(clickButton: Int) { - when (clickButton) { - InputConstants.MOUSE_BUTTON_LEFT -> { - prop.value = prop.value.next(enum.enumConstants) - onChange?.invoke(prop.get()) - } - - InputConstants.MOUSE_BUTTON_RIGHT -> { - prop.value = prop.value.prev(enum.enumConstants) - onChange?.invoke(prop.get()) - } - - InputConstants.MOUSE_BUTTON_MIDDLE -> { - if (prop.get() != defaultValue) { - prop.value = defaultValue - onChange?.invoke(prop.get()) - } - } - } - } - - override fun innerRenderTooltips(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float): Boolean { - if (!isHovered && !isGrabbingMouseInput()) { - return super.innerRenderTooltips(stack, mouseX, mouseY, partialTick) - } - - if (mainTooltip == null && tooltipMapping.size == 0) { - return super.innerRenderTooltips(stack, mouseX, mouseY, partialTick) - } - - val listing = ArrayList() - - if (mainTooltip != null) { - listing.add(mainTooltip!!) - listing.add(SPACE) - } - - for ((key, value) in tooltipMapping) { - if (key == prop.get()) { - listing.add(value.copy().withStyle(ChatFormatting.WHITE)) - } else { - listing.add(value.copy().withStyle(ChatFormatting.GRAY)) - } - } - - screen.renderComponentTooltip( - stack, - listing, - mouseX.toInt(), - mouseY.toInt(), - font - ) - - return true - } - - companion object { - private val SPACE = TextComponent("") - } -} - -abstract class BooleanRectangleButtonPanel( - screen: S, - parent: EditablePanel<*>?, - x: Float = 0f, - y: Float = 0f, - width: Float, - height: Float, - val prop: GetterSetter, - val skinElementActive: AbstractSkinElement? = null, - val skinElementInactive: AbstractSkinElement? = null, - val onChange: ((newValue: Boolean) -> Unit)? = null, -) : RectangleButtonPanel(screen, parent, x, y, width, height, null) { - override fun onClick(clickButton: Int) { - if (clickButton == InputConstants.MOUSE_BUTTON_LEFT) { - val newValue = !prop.value - prop.value = newValue - onChange?.invoke(newValue) - } - } - - override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { - super.innerRender(stack, mouseX, mouseY, partialTick) - - if (prop.value) { - skinElementActive?.render(stack, width = width, height = height) - } else { - skinElementInactive?.render(stack, width = width, height = height) - } - } -} - -open class LargeRectangleButtonPanel( - screen: S, - parent: EditablePanel<*>?, - x: Float = 0f, - y: Float = 0f, - width: Float = SIZE, - height: Float = SIZE, - onPress: ((clickButton: Int) -> Unit)? = null, - val skinElement: AbstractSkinElement? = null, - val skinElementWinding: UVWindingOrder? = null, -) : RectangleButtonPanel(screen, parent, x, y, width, height, onPress) { - final override val IDLE = Widgets18.BUTTON_IDLE - final override val HOVERED = Widgets18.BUTTON_HOVERED - final override val PRESSED = Widgets18.BUTTON_PRESSED - final override val DISABLED = Widgets18.BUTTON_DISABLED - - override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { - super.innerRender(stack, mouseX, mouseY, partialTick) - - if (skinElementWinding != null) { - skinElement?.render(stack, width = width, height = height, winding = skinElementWinding) - } else { - skinElement?.render(stack, width = width, height = height) - } - } - - companion object { - const val SIZE = 18f - } -} - -open class LargeEnumRectangleButtonPanel>( - screen: S, - parent: EditablePanel<*>?, - x: Float = 0f, - y: Float = 0f, - width: Float = SIZE, - height: Float = SIZE, - enum: Class, - prop: GetterSetter, - defaultValue: T, - onChange: ((newValue: T) -> Unit)? = null, -) : EnumRectangleButtonPanel(screen, parent, x, y, width, height, enum, prop, defaultValue, onChange) { - final override val IDLE = Widgets18.BUTTON_IDLE - final override val HOVERED = Widgets18.BUTTON_HOVERED - final override val PRESSED = Widgets18.BUTTON_PRESSED - final override val DISABLED = Widgets18.BUTTON_DISABLED - - companion object { - const val SIZE = 18f - } -} - -open class LargeBooleanRectangleButtonPanel( - screen: S, - parent: EditablePanel<*>?, - x: Float = 0f, - y: Float = 0f, - width: Float = SIZE, - height: Float = SIZE, - prop: GetterSetter, - skinElementActive: AbstractSkinElement? = null, - skinElementInactive: AbstractSkinElement? = null, - onChange: ((newValue: Boolean) -> Unit)? = null, -) : BooleanRectangleButtonPanel(screen, parent, x, y, width, height, prop, skinElementActive, skinElementInactive, onChange) { - final override val IDLE = Widgets18.BUTTON_IDLE - final override val HOVERED = Widgets18.BUTTON_HOVERED - final override val PRESSED = Widgets18.BUTTON_PRESSED - final override val DISABLED = Widgets18.BUTTON_DISABLED - - companion object { - const val SIZE = 18f - } -} - -open class SmallRectangleButtonPanel( - screen: S, - parent: EditablePanel<*>?, - x: Float = 0f, - y: Float = 0f, - width: Float = SIZE, - height: Float = SIZE, - onPress: ((clickButton: Int) -> Unit)? = null, - val skinElement: SkinElement? = null, - val skinElementWinding: UVWindingOrder? = null, -) : RectangleButtonPanel(screen, parent, x, y, width, height, onPress) { - final override val IDLE = Widgets8.BUTTON_IDLE - final override val HOVERED = Widgets8.BUTTON_HOVERED - final override val PRESSED = Widgets8.BUTTON_PRESSED - final override val DISABLED = Widgets8.BUTTON_DISABLED - - override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { - super.innerRender(stack, mouseX, mouseY, partialTick) - - if (skinElementWinding != null) { - skinElement?.render(stack, width = width, height = height, winding = skinElementWinding) - } else { - skinElement?.render(stack, width = width, height = height) - } - } - - companion object { - const val SIZE = 8f - } -} - -open class SmallEnumRectangleButtonPanel>( - screen: S, - parent: EditablePanel<*>?, - x: Float = 0f, - y: Float = 0f, - width: Float = SIZE, - height: Float = SIZE, - enum: Class, - prop: GetterSetter, - defaultValue: T, - onChange: ((newValue: T) -> Unit)? = null, -) : EnumRectangleButtonPanel(screen, parent, x, y, width, height, enum, prop, defaultValue, onChange) { - final override val IDLE = Widgets8.BUTTON_IDLE - final override val HOVERED = Widgets8.BUTTON_HOVERED - final override val PRESSED = Widgets8.BUTTON_PRESSED - final override val DISABLED = Widgets8.BUTTON_DISABLED - - companion object { - const val SIZE = 8f - } -} - -open class SmallBooleanRectangleButtonPanel( - screen: S, - parent: EditablePanel<*>?, - x: Float = 0f, - y: Float = 0f, - width: Float = SIZE, - height: Float = SIZE, - prop: GetterSetter, - skinElementActive: AbstractSkinElement? = null, - skinElementInactive: AbstractSkinElement? = null, - onChange: ((newValue: Boolean) -> Unit)? = null, -) : BooleanRectangleButtonPanel(screen, parent, x, y, width, height, prop, skinElementActive, skinElementInactive, onChange) { - final override val IDLE = Widgets8.BUTTON_IDLE - final override val HOVERED = Widgets8.BUTTON_HOVERED - final override val PRESSED = Widgets8.BUTTON_PRESSED - final override val DISABLED = Widgets8.BUTTON_DISABLED - - companion object { - const val SIZE = 8f - } -} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EntityRendererPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EntityRendererPanel.kt index 86db7000e..a3e9ae8ff 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EntityRendererPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EntityRendererPanel.kt @@ -10,6 +10,7 @@ import ru.dbotthepony.mc.otm.capability.matteryPlayer import ru.dbotthepony.mc.otm.client.render.Widgets8 import ru.dbotthepony.mc.otm.client.render.element import ru.dbotthepony.mc.otm.client.screen.ExoSuitInventoryScreen +import ru.dbotthepony.mc.otm.client.screen.panels.buttons.SmallBooleanRectangleButtonPanel import ru.dbotthepony.mc.otm.compat.cos.CosmeticToggleRenderButton import ru.dbotthepony.mc.otm.compat.cos.isCosmeticArmorLoaded import ru.dbotthepony.mc.otm.core.asGetterOnly diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/HeightControls.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/HeightControls.kt index 8b9ad55b3..4ebe6a900 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/HeightControls.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/HeightControls.kt @@ -3,8 +3,8 @@ 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.AbstractSkinElement -import ru.dbotthepony.mc.otm.client.render.SkinElement import ru.dbotthepony.mc.otm.client.render.Widgets +import ru.dbotthepony.mc.otm.client.screen.panels.buttons.RectangleButtonPanel open class HeightControls( screen: S, diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/BooleanRectangleButtonPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/BooleanRectangleButtonPanel.kt new file mode 100644 index 000000000..3fa9707d0 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/BooleanRectangleButtonPanel.kt @@ -0,0 +1,40 @@ +package ru.dbotthepony.mc.otm.client.screen.panels.buttons + +import com.mojang.blaze3d.platform.InputConstants +import com.mojang.blaze3d.vertex.PoseStack +import net.minecraft.client.gui.screens.Screen +import ru.dbotthepony.mc.otm.client.render.AbstractSkinElement +import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel +import ru.dbotthepony.mc.otm.core.GetterSetter +import ru.dbotthepony.mc.otm.core.value + +abstract class BooleanRectangleButtonPanel( + screen: S, + parent: EditablePanel<*>?, + x: Float = 0f, + y: Float = 0f, + width: Float, + height: Float, + val prop: GetterSetter, + val skinElementActive: AbstractSkinElement? = null, + val skinElementInactive: AbstractSkinElement? = null, + val onChange: ((newValue: Boolean) -> Unit)? = null, +) : RectangleButtonPanel(screen, parent, x, y, width, height, null) { + override fun onClick(clickButton: Int) { + if (clickButton == InputConstants.MOUSE_BUTTON_LEFT) { + val newValue = !prop.value + prop.value = newValue + onChange?.invoke(newValue) + } + } + + override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { + super.innerRender(stack, mouseX, mouseY, partialTick) + + if (prop.value) { + skinElementActive?.render(stack, width = width, height = height) + } else { + skinElementInactive?.render(stack, width = width, height = height) + } + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/ButtonPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/ButtonPanel.kt new file mode 100644 index 000000000..1b4b32b51 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/ButtonPanel.kt @@ -0,0 +1,115 @@ +package ru.dbotthepony.mc.otm.client.screen.panels.buttons + +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.playGuiClickSound +import ru.dbotthepony.mc.otm.client.render.TextAlign +import ru.dbotthepony.mc.otm.client.render.Widgets18 +import ru.dbotthepony.mc.otm.client.render.drawAligned +import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel +import ru.dbotthepony.mc.otm.core.RGBAColor + +open class ButtonPanel( + screen: S, + parent: EditablePanel<*>?, + x: Float = 0f, + y: Float = 0f, + width: Float = 40f, + height: Float = HEIGHT, + var label: Component +) : EditablePanel(screen, parent, x, y, width, height) { + constructor(screen: S, parent: EditablePanel<*>?, label: Component) : this(screen, parent, x = 0f, label = label) + + constructor( + screen: S, + parent: EditablePanel<*>?, + x: Float = 0f, + y: Float = 0f, + width: Float = 40f, + height: Float = HEIGHT, + label: Component, + onPress: Runnable + ) : this(screen, parent, x, y, width, height, label) { + this.callback = onPress + } + + 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 + } + + if (!tryToGrabMouseInput()) { + return true + } + + pressed = true + playGuiClickSound() + return true + } + + override fun mouseReleasedInner(x: Double, y: Double, button: Int): Boolean { + if (!pressed) { + return true + } + + grabMouseInput = false + pressed = false + + if (isHovered) { + onClick(button) + } + + return true + } + + fun bind(runnable: Runnable) { + callback = runnable + } + + var textColor = RGBAColor.WHITE + + var isDisabled = false + set(value) { + if (field != value) { + if (!value) { + pressed = false + grabMouseInput = false + } + + field = value + } + } + + override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { + if (isDisabled) { + Widgets18.BUTTON_DISABLED_STRETCHABLE.render(stack, width = width, height = height) + } else if (pressed) { + Widgets18.BUTTON_PRESSED_STRETCHABLE.render(stack, width = width, height = height) + } else if (isHovered) { + Widgets18.BUTTON_HOVERED_STRETCHABLE.render(stack, width = width, height = height) + } else { + Widgets18.BUTTON_IDLE_STRETCHABLE.render(stack, width = width, height = height) + } + + font.drawAligned(stack, label, TextAlign.CENTER_CENTER, width / 2f, height / 2f, textColor.toInt()) + } + + override fun sizeToContents() { + super.sizeToContents() + + height = height.coerceAtLeast(HEIGHT).coerceAtLeast(font.lineHeight.toFloat() + 2f) + width = width.coerceAtLeast(HEIGHT).coerceAtLeast(font.width(label) + 4f) + } + + companion object { + const val HEIGHT = 18f + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/EnumRectangleButtonPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/EnumRectangleButtonPanel.kt new file mode 100644 index 000000000..3649a5e45 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/EnumRectangleButtonPanel.kt @@ -0,0 +1,186 @@ +package ru.dbotthepony.mc.otm.client.screen.panels.buttons + +import com.mojang.blaze3d.platform.InputConstants +import com.mojang.blaze3d.vertex.PoseStack +import net.minecraft.ChatFormatting +import net.minecraft.client.gui.screens.Screen +import net.minecraft.network.chat.Component +import ru.dbotthepony.mc.otm.client.render.AbstractSkinElement +import ru.dbotthepony.mc.otm.client.render.UVWindingOrder +import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel +import ru.dbotthepony.mc.otm.core.GetterSetter +import ru.dbotthepony.mc.otm.core.TextComponent +import ru.dbotthepony.mc.otm.core.next +import ru.dbotthepony.mc.otm.core.prev +import ru.dbotthepony.mc.otm.core.value +import java.util.* +import kotlin.collections.ArrayList + +abstract class EnumRectangleButtonPanel>( + screen: S, + parent: EditablePanel<*>?, + x: Float = 0f, + y: Float = 0f, + width: Float, + height: Float, + val enum: Class, + val prop: GetterSetter, + val defaultValue: T, + val onChange: ((newValue: T) -> Unit)? = null, +) : RectangleButtonPanel(screen, parent, x, y, width, height, null) { + private var building = true + + protected val enumMapping = EnumMap>(enum) + protected val tooltipMapping = EnumMap(enum) + + fun addTooltip(value: T, component: Component): EnumRectangleButtonPanel { + check(tooltipMapping.put(value, component) == null) { "Already has mapping for $value" } + return this + } + + var mainTooltip: Component? = null + set(value) { + if (field != null) { + throw UnsupportedOperationException("Write once only") + } + + field = value + } + + fun isFullyDefined(): Boolean { + for (value in enum.enumConstants) { + if (enumMapping[value] == null) { + return false + } + } + + return true + } + + val missingValues: List get() { + val missing = ArrayList() + + for (value in enum.enumConstants) { + if (enumMapping[value] == null) { + missing.add(value) + } + } + + return missing + } + + fun add(value: T, skinElement: AbstractSkinElement, winding: UVWindingOrder = UVWindingOrder.NORMAL): EnumRectangleButtonPanel { + return add(value, skinElement to winding) + } + + fun add(value: T, skinElement: AbstractSkinElement, component: Component, winding: UVWindingOrder = UVWindingOrder.NORMAL): EnumRectangleButtonPanel { + return add(value, component, skinElement to winding) + } + + fun add(value: T, component: Component, skinElement: AbstractSkinElement, winding: UVWindingOrder = UVWindingOrder.NORMAL): EnumRectangleButtonPanel { + return add(value, component, skinElement to winding) + } + + fun add(value: T, pair: Pair): EnumRectangleButtonPanel { + check(building) { "Not building" } + check(enumMapping.put(value, pair) == null) { "Already has mapping for $value" } + + if (enumMapping.size == enum.enumConstants.size) { + finish() + } + + return this + } + + fun add(value: T, component: Component, pair: Pair): EnumRectangleButtonPanel { + addTooltip(value, component) + return add(value, pair) + } + + fun finish(): EnumRectangleButtonPanel { + check(building) { "Not building" } + check(isFullyDefined()) { + "Not all enums having their mapping defined, missing are: ${missingValues.joinToString(", ")}" + } + + building = false + return this + } + + override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { + check(!building) { "Still building this button!" } + super.innerRender(stack, mouseX, mouseY, partialTick) + val pair = checkNotNull(enumMapping[prop.get()]) { "HOW" } + pair.first.render(stack, 0f, 0f, width, height, pair.second) + } + + override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean { + check(!building) { "Still building this button!" } + return super.mouseClickedInner(x, y, button) + } + + override fun mouseReleasedInner(x: Double, y: Double, button: Int): Boolean { + check(!building) { "Still building this button!" } + return super.mouseReleasedInner(x, y, button) + } + + override fun onClick(clickButton: Int) { + when (clickButton) { + InputConstants.MOUSE_BUTTON_LEFT -> { + prop.value = prop.value.next(enum.enumConstants) + onChange?.invoke(prop.get()) + } + + InputConstants.MOUSE_BUTTON_RIGHT -> { + prop.value = prop.value.prev(enum.enumConstants) + onChange?.invoke(prop.get()) + } + + InputConstants.MOUSE_BUTTON_MIDDLE -> { + if (prop.get() != defaultValue) { + prop.value = defaultValue + onChange?.invoke(prop.get()) + } + } + } + } + + override fun innerRenderTooltips(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float): Boolean { + if (!isHovered && !isGrabbingMouseInput()) { + return super.innerRenderTooltips(stack, mouseX, mouseY, partialTick) + } + + if (mainTooltip == null && tooltipMapping.size == 0) { + return super.innerRenderTooltips(stack, mouseX, mouseY, partialTick) + } + + val listing = ArrayList() + + if (mainTooltip != null) { + listing.add(mainTooltip!!) + listing.add(SPACE) + } + + for ((key, value) in tooltipMapping) { + if (key == prop.get()) { + listing.add(value.copy().withStyle(ChatFormatting.WHITE)) + } else { + listing.add(value.copy().withStyle(ChatFormatting.GRAY)) + } + } + + screen.renderComponentTooltip( + stack, + listing, + mouseX.toInt(), + mouseY.toInt(), + font + ) + + return true + } + + companion object { + private val SPACE = TextComponent("") + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/LargeBooleanRectangleButtonPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/LargeBooleanRectangleButtonPanel.kt new file mode 100644 index 000000000..506bb2f8d --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/LargeBooleanRectangleButtonPanel.kt @@ -0,0 +1,29 @@ +package ru.dbotthepony.mc.otm.client.screen.panels.buttons + +import net.minecraft.client.gui.screens.Screen +import ru.dbotthepony.mc.otm.client.render.AbstractSkinElement +import ru.dbotthepony.mc.otm.client.render.Widgets18 +import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel +import ru.dbotthepony.mc.otm.core.GetterSetter + +open class LargeBooleanRectangleButtonPanel( + screen: S, + parent: EditablePanel<*>?, + x: Float = 0f, + y: Float = 0f, + width: Float = SIZE, + height: Float = SIZE, + prop: GetterSetter, + skinElementActive: AbstractSkinElement? = null, + skinElementInactive: AbstractSkinElement? = null, + onChange: ((newValue: Boolean) -> Unit)? = null, +) : BooleanRectangleButtonPanel(screen, parent, x, y, width, height, prop, skinElementActive, skinElementInactive, onChange) { + final override val IDLE = Widgets18.BUTTON_IDLE + final override val HOVERED = Widgets18.BUTTON_HOVERED + final override val PRESSED = Widgets18.BUTTON_PRESSED + final override val DISABLED = Widgets18.BUTTON_DISABLED + + companion object { + const val SIZE = 18f + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/LargeEnumRectangleButtonPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/LargeEnumRectangleButtonPanel.kt new file mode 100644 index 000000000..c39145854 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/LargeEnumRectangleButtonPanel.kt @@ -0,0 +1,28 @@ +package ru.dbotthepony.mc.otm.client.screen.panels.buttons + +import net.minecraft.client.gui.screens.Screen +import ru.dbotthepony.mc.otm.client.render.Widgets18 +import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel +import ru.dbotthepony.mc.otm.core.GetterSetter + +open class LargeEnumRectangleButtonPanel>( + screen: S, + parent: EditablePanel<*>?, + x: Float = 0f, + y: Float = 0f, + width: Float = SIZE, + height: Float = SIZE, + enum: Class, + prop: GetterSetter, + defaultValue: T, + onChange: ((newValue: T) -> Unit)? = null, +) : EnumRectangleButtonPanel(screen, parent, x, y, width, height, enum, prop, defaultValue, onChange) { + final override val IDLE = Widgets18.BUTTON_IDLE + final override val HOVERED = Widgets18.BUTTON_HOVERED + final override val PRESSED = Widgets18.BUTTON_PRESSED + final override val DISABLED = Widgets18.BUTTON_DISABLED + + companion object { + const val SIZE = 18f + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/LargeRectangleButtonPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/LargeRectangleButtonPanel.kt new file mode 100644 index 000000000..4ebf8e9d9 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/LargeRectangleButtonPanel.kt @@ -0,0 +1,39 @@ +package ru.dbotthepony.mc.otm.client.screen.panels.buttons + +import com.mojang.blaze3d.vertex.PoseStack +import net.minecraft.client.gui.screens.Screen +import ru.dbotthepony.mc.otm.client.render.AbstractSkinElement +import ru.dbotthepony.mc.otm.client.render.UVWindingOrder +import ru.dbotthepony.mc.otm.client.render.Widgets18 +import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel + +open class LargeRectangleButtonPanel( + screen: S, + parent: EditablePanel<*>?, + x: Float = 0f, + y: Float = 0f, + width: Float = SIZE, + height: Float = SIZE, + onPress: ((clickButton: Int) -> Unit)? = null, + val skinElement: AbstractSkinElement? = null, + val skinElementWinding: UVWindingOrder? = null, +) : RectangleButtonPanel(screen, parent, x, y, width, height, onPress) { + final override val IDLE = Widgets18.BUTTON_IDLE + final override val HOVERED = Widgets18.BUTTON_HOVERED + final override val PRESSED = Widgets18.BUTTON_PRESSED + final override val DISABLED = Widgets18.BUTTON_DISABLED + + override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { + super.innerRender(stack, mouseX, mouseY, partialTick) + + if (skinElementWinding != null) { + skinElement?.render(stack, width = width, height = height, winding = skinElementWinding) + } else { + skinElement?.render(stack, width = width, height = height) + } + } + + companion object { + const val SIZE = 18f + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/RectangleButtonPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/RectangleButtonPanel.kt new file mode 100644 index 000000000..fe808675d --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/RectangleButtonPanel.kt @@ -0,0 +1,81 @@ +package ru.dbotthepony.mc.otm.client.screen.panels.buttons + +import com.mojang.blaze3d.vertex.PoseStack +import net.minecraft.client.gui.screens.Screen +import ru.dbotthepony.mc.otm.client.playGuiClickSound +import ru.dbotthepony.mc.otm.client.render.AbstractSkinElement +import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel + +@Suppress("PropertyName") +abstract class RectangleButtonPanel( + screen: S, + parent: EditablePanel<*>?, + x: Float = 0f, + y: Float = 0f, + width: Float, + height: Float, + val onPress: ((clickButton: Int) -> Unit)? = null, +) : EditablePanel(screen, parent, x, y, width, height) { + protected var pressed = false + + protected open fun onClick(clickButton: Int) { + onPress?.invoke(clickButton) + } + + abstract val PRESSED: AbstractSkinElement + abstract val HOVERED: AbstractSkinElement + abstract val IDLE: AbstractSkinElement + abstract val DISABLED: AbstractSkinElement + + var isDisabled = false + set(value) { + if (field != value) { + if (!value) { + pressed = false + grabMouseInput = false + } + + field = value + } + } + + override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { + if (isDisabled) { + DISABLED.render(stack, 0f, 0f, width, height) + } else if (pressed) { + PRESSED.render(stack, 0f, 0f, width, height) + } else if (isHovered) { + HOVERED.render(stack, 0f, 0f, width, height) + } else { + IDLE.render(stack, 0f, 0f, width, height) + } + } + + override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean { + if (!isDisabled) { + if (!pressed) { + playGuiClickSound() + } + + if (tryToGrabMouseInput()) { + pressed = true + } + } + + return true + } + + override fun mouseReleasedInner(x: Double, y: Double, button: Int): Boolean { + if (!isDisabled && pressed) { + pressed = false + + if (isHovered) { + onClick(button) + } + } + + grabMouseInput = false + + return true + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/SmallBooleanRectangleButtonPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/SmallBooleanRectangleButtonPanel.kt new file mode 100644 index 000000000..60babbc23 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/SmallBooleanRectangleButtonPanel.kt @@ -0,0 +1,28 @@ +package ru.dbotthepony.mc.otm.client.screen.panels.buttons + +import net.minecraft.client.gui.screens.Screen +import ru.dbotthepony.mc.otm.client.render.* +import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel +import ru.dbotthepony.mc.otm.core.GetterSetter + +open class SmallBooleanRectangleButtonPanel( + screen: S, + parent: EditablePanel<*>?, + x: Float = 0f, + y: Float = 0f, + width: Float = SIZE, + height: Float = SIZE, + prop: GetterSetter, + skinElementActive: AbstractSkinElement? = null, + skinElementInactive: AbstractSkinElement? = null, + onChange: ((newValue: Boolean) -> Unit)? = null, +) : BooleanRectangleButtonPanel(screen, parent, x, y, width, height, prop, skinElementActive, skinElementInactive, onChange) { + final override val IDLE = Widgets8.BUTTON_IDLE + final override val HOVERED = Widgets8.BUTTON_HOVERED + final override val PRESSED = Widgets8.BUTTON_PRESSED + final override val DISABLED = Widgets8.BUTTON_DISABLED + + companion object { + const val SIZE = 8f + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/SmallEnumRectangleButtonPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/SmallEnumRectangleButtonPanel.kt new file mode 100644 index 000000000..7563207a1 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/SmallEnumRectangleButtonPanel.kt @@ -0,0 +1,28 @@ +package ru.dbotthepony.mc.otm.client.screen.panels.buttons + +import net.minecraft.client.gui.screens.Screen +import ru.dbotthepony.mc.otm.client.render.Widgets8 +import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel +import ru.dbotthepony.mc.otm.core.GetterSetter + +open class SmallEnumRectangleButtonPanel>( + screen: S, + parent: EditablePanel<*>?, + x: Float = 0f, + y: Float = 0f, + width: Float = SIZE, + height: Float = SIZE, + enum: Class, + prop: GetterSetter, + defaultValue: T, + onChange: ((newValue: T) -> Unit)? = null, +) : EnumRectangleButtonPanel(screen, parent, x, y, width, height, enum, prop, defaultValue, onChange) { + final override val IDLE = Widgets8.BUTTON_IDLE + final override val HOVERED = Widgets8.BUTTON_HOVERED + final override val PRESSED = Widgets8.BUTTON_PRESSED + final override val DISABLED = Widgets8.BUTTON_DISABLED + + companion object { + const val SIZE = 8f + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/SmallRectangleButtonPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/SmallRectangleButtonPanel.kt new file mode 100644 index 000000000..55db58e60 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/SmallRectangleButtonPanel.kt @@ -0,0 +1,39 @@ +package ru.dbotthepony.mc.otm.client.screen.panels.buttons + +import com.mojang.blaze3d.vertex.PoseStack +import net.minecraft.client.gui.screens.Screen +import ru.dbotthepony.mc.otm.client.render.SkinElement +import ru.dbotthepony.mc.otm.client.render.UVWindingOrder +import ru.dbotthepony.mc.otm.client.render.Widgets8 +import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel + +open class SmallRectangleButtonPanel( + screen: S, + parent: EditablePanel<*>?, + x: Float = 0f, + y: Float = 0f, + width: Float = SIZE, + height: Float = SIZE, + onPress: ((clickButton: Int) -> Unit)? = null, + val skinElement: SkinElement? = null, + val skinElementWinding: UVWindingOrder? = null, +) : RectangleButtonPanel(screen, parent, x, y, width, height, onPress) { + final override val IDLE = Widgets8.BUTTON_IDLE + final override val HOVERED = Widgets8.BUTTON_HOVERED + final override val PRESSED = Widgets8.BUTTON_PRESSED + final override val DISABLED = Widgets8.BUTTON_DISABLED + + override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { + super.innerRender(stack, mouseX, mouseY, partialTick) + + if (skinElementWinding != null) { + skinElement?.render(stack, width = width, height = height, winding = skinElementWinding) + } else { + skinElement?.render(stack, width = width, height = height) + } + } + + companion object { + const val SIZE = 8f + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/compat/cos/CosmeticArmorCompat.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/compat/cos/CosmeticArmorCompat.kt index 30d41b08a..f3f98b207 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/compat/cos/CosmeticArmorCompat.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/compat/cos/CosmeticArmorCompat.kt @@ -5,7 +5,6 @@ import com.mojang.blaze3d.vertex.PoseStack import lain.mods.cos.impl.ModObjects import lain.mods.cos.impl.client.PlayerRenderHandler import lain.mods.cos.impl.client.gui.GuiCosArmorInventory -import lain.mods.cos.impl.client.gui.GuiCosArmorToggleButton import lain.mods.cos.impl.network.packet.PacketSetSkinArmor import net.minecraft.client.gui.screens.Screen import net.minecraft.resources.ResourceLocation @@ -20,9 +19,8 @@ import net.minecraftforge.fml.ModList import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.client.render.SkinElement import ru.dbotthepony.mc.otm.client.render.element -import ru.dbotthepony.mc.otm.client.screen.panels.AbstractSlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel -import ru.dbotthepony.mc.otm.client.screen.panels.RectangleButtonPanel +import ru.dbotthepony.mc.otm.client.screen.panels.buttons.RectangleButtonPanel import ru.dbotthepony.mc.otm.compat.cos.CosmeticToggleButton.Companion.BUTTON_ACTIVE import ru.dbotthepony.mc.otm.compat.cos.CosmeticToggleButton.Companion.BUTTON_INACTIVE import ru.dbotthepony.mc.otm.container.awareStream