From 005c8b03962d519e7111ba4fdbefedd9b17f3e4b Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Thu, 4 Jan 2024 17:48:56 +0700 Subject: [PATCH] Holo sign text coloring --- .../mc/otm/datagen/lang/English.kt | 2 + .../mc/otm/datagen/lang/Russian.kt | 2 + .../entity/decorative/HoloSignBlockEntity.kt | 10 +++ .../render/blockentity/HoloSignRenderer.kt | 2 +- .../screen/decorative/HoloSignScreen.kt | 27 ++++++- .../otm/client/screen/panels/ColorPicker.kt | 78 ++++++++++++------- .../ru/dbotthepony/mc/otm/menu/MatteryMenu.kt | 2 + .../mc/otm/menu/decorative/HoloSignMenu.kt | 17 +++- .../otm/menu/input/FloatInputWithFeedback.kt | 18 +++++ 9 files changed, 126 insertions(+), 32 deletions(-) create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/FloatInputWithFeedback.kt diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt index 50973d88c..54bb3166d 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt @@ -155,6 +155,8 @@ private fun misc(provider: MatteryLanguageProvider) { gui("exopack.change_color2", "Remove color") gui("exopack.go_curios", "Open Curios inventory") + gui("change_color", "Customize color") + gui("exopack.probe1", "This little device feels unnatural to touch, it is almost certainly resilient to any possible attempt to break it open.") gui("exopack.probe2", "There is fingerprint reader built into one of sides which gently glow when touched.") gui("exopack.probe3", "It seems this box will unlock once you strongly press fingerprint reader, and you feel what's inside will affect you without any way back!") diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt index 35dde11db..203d09438 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt @@ -163,6 +163,8 @@ private fun misc(provider: MatteryLanguageProvider) { gui("exopack.change_color2", "Убрать окраску") gui("exopack.go_curios", "Открыть инвентарь Curios") + gui("change_color", "Изменить цвет") + gui("exopack.probe1", "Данное маленькое устройство необычно на ощупь, а так же неприступно для любых попыток вскрыть.") gui("exopack.probe2", "На одной из сторон данного устройства находится сканер отпечатка, который тускло загорается при касании.") gui("exopack.probe3", "Вероятно, устройство откроется если достаточно сильно нажать на сканер отпечатка, и вы чувствуете, что последствия будут необратимы!") diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/HoloSignBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/HoloSignBlockEntity.kt index 3e2884aa4..c349afb9c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/HoloSignBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/HoloSignBlockEntity.kt @@ -25,12 +25,22 @@ class HoloSignBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryB access.write(value) }) + var textRed by synchronizer.float(1f).property + var textGreen by synchronizer.float(1f).property + var textBlue by synchronizer.float(85f / 255f).property + var textAlpha by synchronizer.float(1f).property + var isLocked = false init { savetables.string(::signText) savetablesLevel.bool(::isLocked) savetables.stateful(::redstoneControl) + + savetables.float(::textRed) + savetables.float(::textGreen) + savetables.float(::textBlue) + savetables.float(::textAlpha) } override fun createMenu(p_39954_: Int, p_39955_: Inventory, p_39956_: Player): AbstractContainerMenu { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/blockentity/HoloSignRenderer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/blockentity/HoloSignRenderer.kt index 4e1be4a88..92ed47869 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/blockentity/HoloSignRenderer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/blockentity/HoloSignRenderer.kt @@ -38,7 +38,7 @@ class HoloSignRenderer(private val context: BlockEntityRendererProvider.Context) var y = -totalHeight / 2f for (line in lines) { - font.draw(poseStack = poseStack, buffer = sorse, text = line, gravity = RenderGravity.TOP_CENTER, y = y, color = RGBAColor.YELLOW) + font.draw(poseStack = poseStack, buffer = sorse, text = line, gravity = RenderGravity.TOP_CENTER, y = y, color = RGBAColor(tile.textRed, tile.textGreen, tile.textBlue, tile.textAlpha)) y += font.lineHeight + 2f } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/decorative/HoloSignScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/decorative/HoloSignScreen.kt index 0e041f81e..2f45327b1 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/decorative/HoloSignScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/decorative/HoloSignScreen.kt @@ -2,15 +2,21 @@ package ru.dbotthepony.mc.otm.client.screen.decorative import net.minecraft.network.chat.Component import net.minecraft.world.entity.player.Inventory +import net.minecraft.world.item.ItemStack +import ru.dbotthepony.mc.otm.client.render.ItemStackIcon import ru.dbotthepony.mc.otm.client.screen.MatteryScreen +import ru.dbotthepony.mc.otm.client.screen.panels.ColorPickerPanel import ru.dbotthepony.mc.otm.client.screen.panels.Dock import ru.dbotthepony.mc.otm.client.screen.panels.DockProperty import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel import ru.dbotthepony.mc.otm.client.screen.panels.button.CheckBoxLabelInputPanel +import ru.dbotthepony.mc.otm.client.screen.panels.button.LargeRectangleButtonPanel import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls import ru.dbotthepony.mc.otm.client.screen.panels.input.NetworkedStringInputPanel import ru.dbotthepony.mc.otm.core.TranslatableComponent +import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.mc.otm.menu.decorative.HoloSignMenu +import ru.dbotthepony.mc.otm.registry.MItems class HoloSignScreen(menu: HoloSignMenu, inventory: Inventory, title: Component) : MatteryScreen(menu, title) { override fun makeMainFrame(): FramePanel> { @@ -28,7 +34,26 @@ class HoloSignScreen(menu: HoloSignMenu, inventory: Inventory, title: Component) lock.dockMargin = DockProperty(2f, 2f, 2f, 2f) lock.tooltips.add(TranslatableComponent("otm.gui.lock_holo_screen.tip")) - makeDeviceControls(this, frame, redstoneConfig = menu.redstone) + val controls = makeDeviceControls(this, frame, redstoneConfig = menu.redstone) + + controls.addButton(object : LargeRectangleButtonPanel(this@HoloSignScreen, frame, onPress = { + frame.blockingWindow = ColorPickerPanel.frame( + this@HoloSignScreen, + callback = { + menu.textRed.accept(it.red) + menu.textGreen.accept(it.green) + menu.textBlue.accept(it.blue) + menu.textAlpha.accept(it.alpha) + }, + color = RGBAColor(menu.textRed.value, menu.textGreen.value, menu.textBlue.value, menu.textAlpha.value), + isDisabled = { !menu.textRed.and(menu.textGreen).and(menu.textBlue).and(menu.textAlpha).test(minecraft?.player) }, + title = TranslatableComponent("otm.gui.change_color")) + }) { + init { + tooltips.add(TranslatableComponent("otm.gui.change_color")) + icon = ItemStackIcon(ItemStack(MItems.PAINTER)).fixed() + } + }) return frame } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/ColorPicker.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/ColorPicker.kt index bd2fa0f0c..3c5d8bf4e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/ColorPicker.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/ColorPicker.kt @@ -21,6 +21,7 @@ import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.math.HSVColor import ru.dbotthepony.mc.otm.core.math.RGBAColor import java.util.function.Consumer +import java.util.function.Supplier import kotlin.math.roundToInt open class ColorBoxPanel( @@ -31,6 +32,7 @@ open class ColorBoxPanel( width: Float = 64f, height: Float = 64f, protected val callback: Consumer? = null, + val isDisabled: Supplier = Supplier { false }, ) : EditablePanel(screen, parent, x, y, width, height) { var backgroundColor = RGBAColor.RED private set @@ -66,7 +68,7 @@ open class ColorBoxPanel( override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean { if (button == InputConstants.MOUSE_BUTTON_LEFT) { - if (!isPressed) { + if (!isPressed && !isDisabled.get()) { isPressed = true grabMouseInput = true @@ -81,7 +83,7 @@ open class ColorBoxPanel( } override fun mouseDraggedInner(x: Double, y: Double, button: Int, xDelta: Double, yDelta: Double): Boolean { - if (isPressed && button == InputConstants.MOUSE_BUTTON_LEFT) { + if (isPressed && button == InputConstants.MOUSE_BUTTON_LEFT && !isDisabled.get()) { pickColor(x, y) return true } @@ -135,11 +137,13 @@ abstract class AbstractColorWangPanel( width: Float = 40f, height: Float = 10f, protected val callback: Consumer? = null, + val isDisabled: Supplier = Supplier { false }, ) : EditablePanel(screen, parent, x, y, width, height) { abstract val leftColor: RGBAColor abstract val rightColor: RGBAColor abstract val wangPosition: Float abstract fun setColor(color: Either) + protected abstract fun onWangInput(newPosition: Float) init { @@ -155,7 +159,7 @@ abstract class AbstractColorWangPanel( override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean { if (button == InputConstants.MOUSE_BUTTON_LEFT) { - if (!isPressed) { + if (!isPressed && !isDisabled.get()) { isPressed = true grabMouseInput = true @@ -170,7 +174,7 @@ abstract class AbstractColorWangPanel( } override fun mouseDraggedInner(x: Double, y: Double, button: Int, xDelta: Double, yDelta: Double): Boolean { - if (isPressed && button == InputConstants.MOUSE_BUTTON_LEFT) { + if (isPressed && button == InputConstants.MOUSE_BUTTON_LEFT && !isDisabled.get()) { updateColor(x) return true } @@ -216,7 +220,8 @@ open class RedColorWangPanel( width: Float = 40f, height: Float = 10f, callback: Consumer? = null, -) : AbstractColorWangPanel(screen, parent, x, y, width, height, callback) { + isDisabled: Supplier = Supplier { false }, +) : AbstractColorWangPanel(screen, parent, x, y, width, height, callback, isDisabled) { override var leftColor: RGBAColor = RGBAColor.BLACK protected set override var rightColor: RGBAColor = RGBAColor.RED @@ -247,7 +252,8 @@ open class GreenColorWangPanel( width: Float = 40f, height: Float = 10f, callback: Consumer? = null, -) : AbstractColorWangPanel(screen, parent, x, y, width, height, callback) { + isDisabled: Supplier = Supplier { false }, +) : AbstractColorWangPanel(screen, parent, x, y, width, height, callback, isDisabled) { override var leftColor: RGBAColor = RGBAColor.BLACK protected set override var rightColor: RGBAColor = RGBAColor.GREEN @@ -278,7 +284,8 @@ open class BlueColorWangPanel( width: Float = 40f, height: Float = 10f, callback: Consumer? = null, -) : AbstractColorWangPanel(screen, parent, x, y, width, height, callback) { + isDisabled: Supplier = Supplier { false }, +) : AbstractColorWangPanel(screen, parent, x, y, width, height, callback, isDisabled) { override var leftColor: RGBAColor = RGBAColor.BLACK protected set override var rightColor: RGBAColor = RGBAColor.BLUE @@ -309,7 +316,8 @@ open class HueWangPanel( width: Float = 40f, height: Float = 10f, protected val hueCallback: FloatConsumer? = null, -) : AbstractColorWangPanel(screen, parent, x, y, width, height) { + isDisabled: Supplier = Supplier { false }, +) : AbstractColorWangPanel(screen, parent, x, y, width, height, null, isDisabled) { override val leftColor: RGBAColor get() = RGBAColor.WHITE override val rightColor: RGBAColor get() = RGBAColor.WHITE override var wangPosition: Float = 1f @@ -351,7 +359,8 @@ open class SaturationWangPanel( width: Float = 40f, height: Float = 10f, protected val saturationCallback: FloatConsumer? = null, -) : AbstractColorWangPanel(screen, parent, x, y, width, height) { + isDisabled: Supplier = Supplier { false }, +) : AbstractColorWangPanel(screen, parent, x, y, width, height, null, isDisabled) { override var leftColor: RGBAColor = RGBAColor.WHITE protected set override var rightColor: RGBAColor = RGBAColor.WHITE @@ -396,7 +405,8 @@ open class ValueWangPanel( width: Float = 40f, height: Float = 10f, protected val valueCallback: FloatConsumer? = null, -) : AbstractColorWangPanel(screen, parent, x, y, width, height) { + isDisabled: Supplier = Supplier { false } +) : AbstractColorWangPanel(screen, parent, x, y, width, height, null, isDisabled) { override var leftColor: RGBAColor = RGBAColor.BLACK protected set override var rightColor: RGBAColor = RGBAColor.WHITE @@ -440,7 +450,8 @@ open class ColorPalettePanel( y: Float = 0f, width: Float = 64f, height: Float = 64f, - protected val callback: Consumer? = null + protected val callback: Consumer? = null, + val isDisabled: Supplier = Supplier { false } ) : EditablePanel(screen, parent, x, y, width, height) { open fun onColorChoose(color: RGBAColor) { callback?.accept(color) @@ -452,6 +463,10 @@ open class ColorPalettePanel( tooltips.add(TextComponent(color.toHexStringRGB())) } + override var isDisabled: Boolean + get() = this@ColorPalettePanel.isDisabled.get() + set(value) {} + override fun onClick(mouseButton: Int) { onColorChoose(color) } @@ -499,7 +514,8 @@ open class ColorPickerPanel( y: Float = 0f, width: Float = 164f, height: Float = 118f, - var callback: Consumer? = null + var callback: Consumer? = null, + val isDisabled: Supplier = Supplier { false }, ) : EditablePanel(screen, parent, x, y, width, height) { open fun onColorChanged(color: RGBAColor) { callback?.accept(color) @@ -523,49 +539,53 @@ open class ColorPickerPanel( protected open fun onPaletteChoose(color: RGBAColor) { setColor(Either.left(color)) - onColorChanged(color) + if (!isDisabled.get()) onColorChanged(color) } protected open fun onColorBoxChoose(color: HSVColor) { setColor(Either.right(color)) - onColorChanged(color.toRGBA()) + if (!isDisabled.get()) onColorChanged(color.toRGBA()) } protected open fun onWangChoose(color: RGBAColor) { setColor(Either.left(color)) - onColorChanged(color) + if (!isDisabled.get()) onColorChanged(color) } protected open fun onHueChoose(hue: Float) { val current = currentColor.map({ it.toHSV() }, { it }) val new = current.copy(hue = hue) setColor(Either.right(new)) - onColorChanged(new.toRGBA()) + if (!isDisabled.get()) onColorChanged(new.toRGBA()) } protected open fun onSaturationChoose(saturation: Float) { val current = currentColor.map({ it.toHSV() }, { it }) val new = current.copy(saturation = saturation) setColor(Either.right(new)) - onColorChanged(new.toRGBA()) + if (!isDisabled.get()) onColorChanged(new.toRGBA()) } protected open fun onValueChoose(value: Float) { val current = currentColor.map({ it.toHSV() }, { it }) val new = current.copy(value = value) setColor(Either.right(new)) - onColorChanged(new.toRGBA()) + if (!isDisabled.get()) onColorChanged(new.toRGBA()) } val topStrip = EditablePanel(screen, this, 0f, 0f, width = width, height = 70f) val middleStrip = EditablePanel(screen, this) - val palette = ColorPalettePanel(screen, this, callback = { onPaletteChoose(it) }) + val palette = ColorPalettePanel(screen, this, callback = { onPaletteChoose(it) }, isDisabled = isDisabled) val hexInput = object : TextInputPanel(screen, middleStrip, width = 50f) { init { dock = Dock.RIGHT } + override var isActive: Boolean + get() = !isDisabled.get() + set(value) {} + override fun onFocusChanged() { if (!isFocusedThis) { val newColor = RGBAColor.fromHexStringRGB(text) @@ -574,7 +594,7 @@ open class ColorPickerPanel( text = currentColor.map({ it }, { it.toRGBA() }).toHexStringRGB() } else { setColor(Either.left(newColor)) - onColorChanged(newColor) + if (!isDisabled.get()) onColorChanged(newColor) } } } @@ -596,7 +616,7 @@ open class ColorPickerPanel( } } - val box = ColorBoxPanel(screen, topStrip, 0f, 0f, width = 70f, height = 70f, callback = { onColorBoxChoose(it) }) + val box = ColorBoxPanel(screen, topStrip, 0f, 0f, width = 70f, height = 70f, callback = { onColorBoxChoose(it) }, isDisabled = isDisabled) val wangCanvas = EditablePanel(screen, topStrip, width = 80f) inner class WangLine(label: String, val wang: AbstractColorWangPanel, val text: (color: Either) -> Component?) { @@ -637,13 +657,13 @@ open class ColorPickerPanel( } } - val red = WangLine("red", RedColorWangPanel(screen, wangCanvas, callback = { onWangChoose(it) })) { TextComponent((it.map({ it }, { it.toRGBA() }).red * 255f).roundToInt().toString()) } - val green = WangLine("green", GreenColorWangPanel(screen, wangCanvas, callback = { onWangChoose(it) })) { TextComponent((it.map({ it }, { it.toRGBA() }).green * 255f).roundToInt().toString()) } - val blue = WangLine("blue", BlueColorWangPanel(screen, wangCanvas, callback = { onWangChoose(it) })) { TextComponent((it.map({ it }, { it.toRGBA() }).blue * 255f).roundToInt().toString()) } + val red = WangLine("red", RedColorWangPanel(screen, wangCanvas, callback = { onWangChoose(it) }, isDisabled = isDisabled)) { TextComponent((it.map({ it }, { it.toRGBA() }).red * 255f).roundToInt().toString()) } + val green = WangLine("green", GreenColorWangPanel(screen, wangCanvas, callback = { onWangChoose(it) }, isDisabled = isDisabled)) { TextComponent((it.map({ it }, { it.toRGBA() }).green * 255f).roundToInt().toString()) } + val blue = WangLine("blue", BlueColorWangPanel(screen, wangCanvas, callback = { onWangChoose(it) }, isDisabled = isDisabled)) { TextComponent((it.map({ it }, { it.toRGBA() }).blue * 255f).roundToInt().toString()) } - val hue = WangLine("hue", HueWangPanel(screen, wangCanvas, hueCallback = { onHueChoose(it) })) { it.map({ if (it.canRepresentHue()) it.toHSV() else null }, { it })?.let { TextComponent(it.hue.roundToInt().toString()) } } - val saturation = WangLine("saturation", SaturationWangPanel(screen, wangCanvas, saturationCallback = { onSaturationChoose(it) })) { it.map({ if (it.canRepresentHue()) it.toHSV() else null }, { it })?.let { TextComponent((it.saturation * 100f).roundToInt().toString() + "%") } } - val value = WangLine("value", ValueWangPanel(screen, wangCanvas, valueCallback = { onValueChoose(it) })) { it.map({ if (it.canRepresentHue()) it.toHSV() else null }, { it })?.let { TextComponent((it.value * 100f).roundToInt().toString() + "%") } } + val hue = WangLine("hue", HueWangPanel(screen, wangCanvas, hueCallback = { onHueChoose(it) }, isDisabled = isDisabled)) { it.map({ if (it.canRepresentHue()) it.toHSV() else null }, { it })?.let { TextComponent(it.hue.roundToInt().toString()) } } + val saturation = WangLine("saturation", SaturationWangPanel(screen, wangCanvas, saturationCallback = { onSaturationChoose(it) }, isDisabled = isDisabled)) { it.map({ if (it.canRepresentHue()) it.toHSV() else null }, { it })?.let { TextComponent((it.saturation * 100f).roundToInt().toString() + "%") } } + val value = WangLine("value", ValueWangPanel(screen, wangCanvas, valueCallback = { onValueChoose(it) }, isDisabled = isDisabled)) { it.map({ if (it.canRepresentHue()) it.toHSV() else null }, { it })?.let { TextComponent((it.value * 100f).roundToInt().toString() + "%") } } val wangs = listOf(red, green, blue, hue, saturation, value) @@ -728,9 +748,9 @@ open class ColorPickerPanel( RGBAColor.rgb(0xEE82EEL), // Violet ) - fun > frame(screen: S, callback: Consumer, color: RGBAColor = RGBAColor.RED, title: Component? = TranslatableComponent("otm.gui.color_picker")): FramePanel { + fun > frame(screen: S, callback: Consumer, color: RGBAColor = RGBAColor.RED, title: Component? = TranslatableComponent("otm.gui.color_picker"), isDisabled: Supplier = Supplier { false }): FramePanel { return FramePanel.padded(screen, 164f, 118f, title).also { - ColorPickerPanel(screen, it, 0f, 0f, callback = callback).also { + ColorPickerPanel(screen, it, 0f, 0f, callback = callback, isDisabled = isDisabled).also { it.dock = Dock.FILL it.setColor(Either.left(color)) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatteryMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatteryMenu.kt index 387ace84b..572c30eb7 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatteryMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatteryMenu.kt @@ -47,6 +47,7 @@ import ru.dbotthepony.mc.otm.core.util.BigDecimalValueCodec import ru.dbotthepony.mc.otm.core.util.BinaryStringCodec import ru.dbotthepony.mc.otm.core.util.BooleanValueCodec import ru.dbotthepony.mc.otm.core.util.CollectionStreamCodec +import ru.dbotthepony.mc.otm.core.util.FloatValueCodec import ru.dbotthepony.mc.otm.core.util.IStreamCodec import ru.dbotthepony.mc.otm.core.util.ItemStackValueCodec import ru.dbotthepony.mc.otm.core.util.ItemValueCodec @@ -189,6 +190,7 @@ abstract class MatteryMenu( fun itemStackInput(allowSpectators: Boolean = false, handler: (ItemStack) -> Unit) = PlayerInput(ItemStackValueCodec, allowSpectators, handler) fun nullableItemInput(allowSpectators: Boolean = false, handler: (Item?) -> Unit) = PlayerInput(ItemValueCodec.nullable, allowSpectators, handler) fun stringInput(allowSpectators: Boolean = false, handler: (String) -> Unit) = PlayerInput(BinaryStringCodec, allowSpectators, handler) + fun floatInput(allowSpectators: Boolean = false, handler: (Float) -> Unit) = PlayerInput(FloatValueCodec, allowSpectators, handler) fun intInput(allowSpectators: Boolean = false, handler: (Int) -> Unit) = PlayerInput(VarIntValueCodec, allowSpectators, handler) /** diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/decorative/HoloSignMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/decorative/HoloSignMenu.kt index bc3562c0e..87c55378e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/decorative/HoloSignMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/decorative/HoloSignMenu.kt @@ -7,10 +7,11 @@ import ru.dbotthepony.mc.otm.block.entity.decorative.HoloSignBlockEntity import ru.dbotthepony.mc.otm.menu.MatteryMenu import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback +import ru.dbotthepony.mc.otm.menu.input.FloatInputWithFeedback import ru.dbotthepony.mc.otm.menu.input.StringInputWithFeedback import ru.dbotthepony.mc.otm.registry.MMenus -class HoloSignMenu @JvmOverloads constructor( +class HoloSignMenu( containerId: Int, inventory: Inventory, tile: HoloSignBlockEntity? = null @@ -19,13 +20,27 @@ class HoloSignMenu @JvmOverloads constructor( val locked = BooleanInputWithFeedback(this) val redstone = EnumInputWithFeedback(this, RedstoneSetting::class.java) + val textRed = FloatInputWithFeedback(this) + val textGreen = FloatInputWithFeedback(this) + val textBlue = FloatInputWithFeedback(this) + val textAlpha = FloatInputWithFeedback(this) + init { text.filter { it.isCreative || !locked.value } redstone.filter { it.isCreative || !locked.value } locked.filter { it.isCreative } + textRed.filter { it.isCreative || !locked.value } + textGreen.filter { it.isCreative || !locked.value } + textBlue.filter { it.isCreative || !locked.value } + textAlpha.filter { it.isCreative || !locked.value } + if (tile != null) { text.withConsumer { if (tile.isLocked) tile.signText = it else tile.signText = HoloSignBlockEntity.truncate(it) }.withSupplier(tile::signText) + textRed.withConsumer { tile.textRed = it.coerceIn(0f, 1f) }.withSupplier(tile::textRed) + textGreen.withConsumer { tile.textGreen = it.coerceIn(0f, 1f) }.withSupplier(tile::textGreen) + textBlue.withConsumer { tile.textBlue = it.coerceIn(0f, 1f) }.withSupplier(tile::textBlue) + textAlpha.withConsumer { tile.textAlpha = it.coerceIn(0f, 1f) }.withSupplier(tile::textAlpha) locked.with(tile::isLocked) redstone.with(tile.redstoneControl::redstoneSetting) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/FloatInputWithFeedback.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/FloatInputWithFeedback.kt new file mode 100644 index 000000000..8ebb92db2 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/FloatInputWithFeedback.kt @@ -0,0 +1,18 @@ +package ru.dbotthepony.mc.otm.menu.input + +import ru.dbotthepony.mc.otm.core.GetterSetter +import ru.dbotthepony.mc.otm.menu.MatteryMenu +import kotlin.reflect.KMutableProperty0 + +class FloatInputWithFeedback(menu: MatteryMenu) : AbstractPlayerInputWithFeedback() { + override val input = menu.floatInput { consumer?.invoke(it) } + override val field = menu.mSynchronizer.computedFloat { supplier?.invoke() ?: 0f } + + constructor(menu: MatteryMenu, state: KMutableProperty0) : this(menu) { + with(state) + } + + constructor(menu: MatteryMenu, state: GetterSetter) : this(menu) { + with(state) + } +}