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 f182df1d4..f13c8649d 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 @@ -4,6 +4,7 @@ import net.minecraft.network.chat.Component import net.minecraft.world.entity.player.Inventory import ru.dbotthepony.mc.otm.client.screen.MatteryScreen 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.input.NetworkedStringInputPanel @@ -20,6 +21,7 @@ class HoloSignScreen(menu: HoloSignMenu, inventory: Inventory, title: Component) val lock = CheckBoxLabelInputPanel(this, frame, menu.locked, TranslatableComponent("otm.gui.lock_holo_screen")) lock.dock = Dock.BOTTOM + lock.dockMargin = DockProperty(2f, 2f, 2f, 2f) return frame } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/AbstractCheckBoxLabelPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/AbstractCheckBoxLabelPanel.kt new file mode 100644 index 000000000..3e6384b24 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/AbstractCheckBoxLabelPanel.kt @@ -0,0 +1,29 @@ +package ru.dbotthepony.mc.otm.client.screen.panels.button + +import net.minecraft.client.gui.screens.Screen +import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel +import ru.dbotthepony.mc.otm.client.screen.panels.Label +import kotlin.math.roundToInt + +abstract class AbstractCheckBoxLabelPanel @JvmOverloads constructor( + screen: S, + parent: EditablePanel<*>?, + x: Float = 0f, + y: Float = 0f, + width: Float = CheckBoxPanel.REGULAR_DIMENSIONS + 120f, + height: Float = CheckBoxPanel.REGULAR_DIMENSIONS +) : EditablePanel(screen, parent, x, y, width, height) { + abstract val checkbox: CheckBoxPanel + abstract val label: Label + + override fun performLayout() { + super.performLayout() + + checkbox.x = dockPadding.left + checkbox.y = dockPadding.top + (height / 2f - checkbox.height / 2f).roundToInt().toFloat() + + label.x = checkbox.x + checkbox.width + 4f + label.y = ((height - dockPadding.top - dockPadding.bottom) / 2f - font.lineHeight / 2f).roundToInt().toFloat() + label.width = width - checkbox.width - dockPadding.right + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelInputPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelInputPanel.kt index 3b4a5e241..905bfff6a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelInputPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelInputPanel.kt @@ -2,10 +2,12 @@ package ru.dbotthepony.mc.otm.client.screen.panels.button import net.minecraft.client.gui.screens.Screen import net.minecraft.network.chat.Component +import ru.dbotthepony.mc.otm.client.screen.panels.Dock import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.Label import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback import ru.dbotthepony.mc.otm.menu.input.IPlayerInputWithFeedback +import kotlin.math.roundToInt open class CheckBoxLabelInputPanel @JvmOverloads constructor( screen: S, @@ -16,8 +18,8 @@ open class CheckBoxLabelInputPanel @JvmOverloads constructor( y: Float = 0f, width: Float = CheckBoxPanel.REGULAR_DIMENSIONS + 120f, height: Float = CheckBoxPanel.REGULAR_DIMENSIONS -) : EditablePanel(screen, parent, x, y, width, height) { +) : AbstractCheckBoxLabelPanel(screen, parent, x, y, width, height) { val widget get() = checkbox.widget - val checkbox = CheckBoxInputPanel(screen = screen, parent = this, widget = widget, x = 0f, y = 0f, width = CheckBoxPanel.REGULAR_DIMENSIONS, height = CheckBoxPanel.REGULAR_DIMENSIONS) - val label = Label(screen, this, CheckBoxPanel.REGULAR_DIMENSIONS + 4f, 4f, text = text) + override val checkbox = CheckBoxInputPanel(screen = screen, parent = this, widget = widget, x = 0f, y = 0f, width = CheckBoxPanel.REGULAR_DIMENSIONS, height = CheckBoxPanel.REGULAR_DIMENSIONS) + override val label = Label(screen, this, CheckBoxPanel.REGULAR_DIMENSIONS + 4f, 4f, text = text) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelPanel.kt index 301ecb901..e9dd03780 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/button/CheckBoxLabelPanel.kt @@ -4,6 +4,7 @@ import net.minecraft.client.gui.screens.Screen import net.minecraft.network.chat.Component import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.Label +import kotlin.math.roundToInt open class CheckBoxLabelPanel @JvmOverloads constructor( screen: S, @@ -13,8 +14,7 @@ open class CheckBoxLabelPanel @JvmOverloads constructor( y: Float = 0f, width: Float = CheckBoxPanel.REGULAR_DIMENSIONS + 120f, height: Float = CheckBoxPanel.REGULAR_DIMENSIONS -) : EditablePanel(screen, parent, x, y, width, height) { - val checkbox = - CheckBoxPanel(screen, this, 0f, 0f, CheckBoxPanel.REGULAR_DIMENSIONS, CheckBoxPanel.REGULAR_DIMENSIONS) - val label = Label(screen, this, CheckBoxPanel.REGULAR_DIMENSIONS + 4f, 4f, text = text) +) : AbstractCheckBoxLabelPanel(screen, parent, x, y, width, height) { + override val checkbox = CheckBoxPanel(screen, this, 0f, 0f, CheckBoxPanel.REGULAR_DIMENSIONS, CheckBoxPanel.REGULAR_DIMENSIONS) + override val label = Label(screen, this, CheckBoxPanel.REGULAR_DIMENSIONS + 4f, 4f, text = text) }