переключение скейлинга текста в табличке

(и всратая палитра на иконку выбора цвета)
This commit is contained in:
YuRaNnNzZZ 2024-10-23 20:50:31 +03:00
parent 5913f56fb0
commit 84da57719d
Signed by: YuRaNnNzZZ
GPG Key ID: 5F71738C85A6006D
7 changed files with 32 additions and 8 deletions

View File

@ -56,6 +56,11 @@ class HoloSignBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryB
var textBlue by syncher.float(85f / 255f, setter = ::colorSetter).delegate
var textAlpha by syncher.float(1f).delegate
var textAutoScale by syncher.boolean(true, setter = { access, value ->
setChanged()
access.accept(value)
}).delegate
var isLocked = false
init {
@ -67,6 +72,8 @@ class HoloSignBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryB
savetables.float(::textGreen)
savetables.float(::textBlue)
savetables.float(::textAlpha)
savetables.bool(::textAutoScale)
}
override fun createMenu(p_39954_: Int, p_39955_: Inventory, p_39956_: Player): AbstractContainerMenu {

View File

@ -176,4 +176,8 @@ object Widgets18 {
}
val UPGRADES = controlsGrid.next()
val COLOR_PALETTE = controlsGrid.next()
val TEXT_SCALE_DISABLED = controlsGrid.next()
val TEXT_SCALE_ENABLED = controlsGrid.next()
}

View File

@ -35,10 +35,12 @@ class HoloSignRenderer(private val context: BlockEntityRendererProvider.Context)
val totalHeight = lines.size * font.lineHeight + (lines.size - 1) * 2f
var y = -totalHeight / 2f
val totalWidth = lines.maxOf { font.width(it) }.toFloat()
val highest = totalWidth.coerceAtLeast(totalHeight)
val mul = if (highest > 64f) 1f / (highest / 64f) else 64f / highest
poseStack.scale(mul, mul, mul)
if (tile.textAutoScale) {
val totalWidth = lines.maxOf { font.width(it) }.toFloat()
val highest = totalWidth.coerceAtLeast(totalHeight)
val mul = if (highest > 64f) 1f / (highest / 64f) else 64f / highest
poseStack.scale(mul, mul, mul)
}
for (line in lines) {
font.draw(poseStack = poseStack, buffer = bufferSource, text = line, gravity = RenderGravity.TOP_CENTER, y = y, color = RGBAColor(tile.textRed, tile.textGreen, tile.textBlue, tile.textAlpha))

View File

@ -2,8 +2,6 @@ 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
@ -15,8 +13,9 @@ 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.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.client.render.Widgets18
import ru.dbotthepony.mc.otm.client.screen.panels.button.LargeBooleanRectangleButtonPanel
import ru.dbotthepony.mc.otm.menu.decorative.HoloSignMenu
import ru.dbotthepony.mc.otm.registry.MItems
class HoloSignScreen(menu: HoloSignMenu, inventory: Inventory, title: Component) : MatteryScreen<HoloSignMenu>(menu, title) {
override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
@ -51,10 +50,18 @@ class HoloSignScreen(menu: HoloSignMenu, inventory: Inventory, title: Component)
}) {
init {
tooltips.add(TranslatableComponent("otm.gui.change_color"))
icon = ItemStackIcon(ItemStack(MItems.PAINTER)).fixed()
icon = Widgets18.COLOR_PALETTE
}
})
controls.addButton(LargeBooleanRectangleButtonPanel(
this@HoloSignScreen,
frame,
prop = menu.textAutoScale,
iconActive = Widgets18.TEXT_SCALE_ENABLED,
iconInactive = Widgets18.TEXT_SCALE_DISABLED,
))
return frame
}
}

View File

@ -24,6 +24,7 @@ class HoloSignMenu(
val textGreen = FloatInputWithFeedback(this)
val textBlue = FloatInputWithFeedback(this)
val textAlpha = FloatInputWithFeedback(this)
val textAutoScale = BooleanInputWithFeedback(this)
init {
text.filter { it.isCreative || !locked.value }
@ -35,6 +36,8 @@ class HoloSignMenu(
textBlue.filter { it.isCreative || !locked.value }
textAlpha.filter { it.isCreative || !locked.value }
textAutoScale.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)
@ -43,6 +46,7 @@ class HoloSignMenu(
textAlpha.withConsumer { tile.textAlpha = it.coerceIn(0f, 1f) }.withSupplier(tile::textAlpha)
locked.with(tile::isLocked)
redstone.with(tile.redstoneControl::redstoneSetting)
textAutoScale.with(tile::textAutoScale)
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB