Wide power gauge

This commit is contained in:
DBotThePony 2022-08-31 13:26:08 +07:00
parent 65c36e44fa
commit 3593dd8bbc
Signed by: DBot
GPG Key ID: DCC23B5715498507
14 changed files with 88 additions and 19 deletions

View File

@ -5,6 +5,7 @@ import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.resources.ResourceLocation import net.minecraft.resources.ResourceLocation
import ru.dbotthepony.mc.otm.client.screen.panels.DockProperty import ru.dbotthepony.mc.otm.client.screen.panels.DockProperty
@Suppress("unused")
class SkinGrid( class SkinGrid(
val texture: ResourceLocation, val texture: ResourceLocation,
val width: Float, val width: Float,
@ -71,6 +72,23 @@ fun ResourceLocation.pixel(
textureHeight: Float = 256f textureHeight: Float = 256f
) = SkinElement(this, x, y, 1f, 1f, textureWidth, textureHeight) ) = SkinElement(this, x, y, 1f, 1f, textureWidth, textureHeight)
fun ResourceLocation.hLine(
x: Float,
y: Float,
width: Float,
textureWidth: Float = 256f,
textureHeight: Float = 256f
) = SkinElement(this, x, y, width, 1f, textureWidth, textureHeight)
fun ResourceLocation.vLine(
x: Float,
y: Float,
height: Float,
textureWidth: Float = 256f,
textureHeight: Float = 256f
) = SkinElement(this, x, y, 1f, height, textureWidth, textureHeight)
@Suppress("unused")
class SkinElement @JvmOverloads constructor( class SkinElement @JvmOverloads constructor(
val texture: ResourceLocation, val texture: ResourceLocation,
val x: Float, val x: Float,
@ -80,6 +98,15 @@ class SkinElement @JvmOverloads constructor(
val imageWidth: Float = 256f, val imageWidth: Float = 256f,
val imageHeight: Float = 256f val imageHeight: Float = 256f
) { ) {
init {
require(x >= 0f) { "Invalid x $x" }
require(y >= 0f) { "Invalid y $y" }
require(w > 0f) { "Invalid width $w" }
require(h > 0f) { "Invalid height $h" }
require(imageWidth > 0f) { "Invalid image width $imageWidth" }
require(imageHeight > 0f) { "Invalid image height $imageHeight" }
}
@JvmOverloads @JvmOverloads
fun render( fun render(
stack: PoseStack, stack: PoseStack,

View File

@ -23,6 +23,7 @@ import ru.dbotthepony.mc.otm.client.render.drawLine
import ru.dbotthepony.mc.otm.client.render.drawRect import ru.dbotthepony.mc.otm.client.render.drawRect
import ru.dbotthepony.mc.otm.client.screen.panels.* import ru.dbotthepony.mc.otm.client.screen.panels.*
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
import ru.dbotthepony.mc.otm.core.RGBAColor import ru.dbotthepony.mc.otm.core.RGBAColor
import ru.dbotthepony.mc.otm.ifPresentK import ru.dbotthepony.mc.otm.ifPresentK
import ru.dbotthepony.mc.otm.menu.AndroidStationMenu import ru.dbotthepony.mc.otm.menu.AndroidStationMenu
@ -477,7 +478,7 @@ class AndroidStationScreen constructor(p_97741_: AndroidStationMenu, p_97742_: I
override fun makeMainFrame(): FramePanel { override fun makeMainFrame(): FramePanel {
val frame = super.makeMainFrame()!! val frame = super.makeMainFrame()!!
PowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) WidePowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT)
SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE)
SlotPanel(this, frame, menu.androidBattery, 38f, 17f) SlotPanel(this, frame, menu.androidBattery, 38f, 17f)

View File

@ -6,6 +6,7 @@ import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
class BatteryBankScreen(menu: BatteryBankMenu, p_97742_: Inventory, p_97743_: Component) : class BatteryBankScreen(menu: BatteryBankMenu, p_97742_: Inventory, p_97743_: Component) :
MatteryScreen<BatteryBankMenu>(menu, p_97742_, p_97743_) { MatteryScreen<BatteryBankMenu>(menu, p_97742_, p_97743_) {
@ -13,7 +14,7 @@ class BatteryBankScreen(menu: BatteryBankMenu, p_97742_: Inventory, p_97743_: Co
override fun makeMainFrame(): FramePanel{ override fun makeMainFrame(): FramePanel{
val frame = super.makeMainFrame()!! val frame = super.makeMainFrame()!!
PowerGaugePanel(this, frame, menu.powerLevel, LEFT_MARGIN, GAUGE_TOP_WITHOUT_SLOT) WidePowerGaugePanel(this, frame, menu.powerLevel, LEFT_MARGIN, GAUGE_TOP_WITHOUT_SLOT)
for (i in 0 .. 5) for (i in 0 .. 5)
SlotPanel(this, frame, menu.storageSlots[i], 44f + 18 * i, 32f) SlotPanel(this, frame, menu.storageSlots[i], 44f + 18 * i, 32f)

View File

@ -6,13 +6,14 @@ import ru.dbotthepony.mc.otm.TranslatableComponent
import ru.dbotthepony.mc.otm.client.screen.panels.* import ru.dbotthepony.mc.otm.client.screen.panels.*
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
import ru.dbotthepony.mc.otm.menu.ChemicalGeneratorMenu import ru.dbotthepony.mc.otm.menu.ChemicalGeneratorMenu
class ChemicalGeneratorScreen(menu: ChemicalGeneratorMenu, inventory: Inventory, title: Component) : MatteryScreen<ChemicalGeneratorMenu>(menu, inventory, title) { class ChemicalGeneratorScreen(menu: ChemicalGeneratorMenu, inventory: Inventory, title: Component) : MatteryScreen<ChemicalGeneratorMenu>(menu, inventory, title) {
override fun makeMainFrame(): FramePanel { override fun makeMainFrame(): FramePanel {
val frame = super.makeMainFrame()!! val frame = super.makeMainFrame()!!
PowerGaugePanel(this, frame, menu.energy, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) WidePowerGaugePanel(this, frame, menu.energy, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT)
SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE)
val self = this val self = this

View File

@ -6,6 +6,7 @@ import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
class DriveRackScreen(menu: DriveRackMenu, inventory: Inventory, title: Component) : class DriveRackScreen(menu: DriveRackMenu, inventory: Inventory, title: Component) :
MatteryScreen<DriveRackMenu>(menu, inventory, title) { MatteryScreen<DriveRackMenu>(menu, inventory, title) {
@ -13,7 +14,7 @@ class DriveRackScreen(menu: DriveRackMenu, inventory: Inventory, title: Componen
override fun makeMainFrame(): FramePanel { override fun makeMainFrame(): FramePanel {
val frame = super.makeMainFrame()!! val frame = super.makeMainFrame()!!
PowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) WidePowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT)
SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE)
SlotPanel(this, frame, menu.storageSlots[0], 71f, 32f) SlotPanel(this, frame, menu.storageSlots[0], 71f, 32f)

View File

@ -6,6 +6,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
import ru.dbotthepony.mc.otm.menu.PlatePressMenu import ru.dbotthepony.mc.otm.menu.PlatePressMenu
class PlatePressScreen(menu: PlatePressMenu, inventory: Inventory, title: Component) : class PlatePressScreen(menu: PlatePressMenu, inventory: Inventory, title: Component) :
@ -13,7 +14,7 @@ class PlatePressScreen(menu: PlatePressMenu, inventory: Inventory, title: Compon
override fun makeMainFrame(): FramePanel { override fun makeMainFrame(): FramePanel {
val frame = super.makeMainFrame()!! val frame = super.makeMainFrame()!!
PowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) WidePowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT)
SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE)
SlotPanel(this, frame, menu.inputSlot, 56f, PROGRESS_SLOT_TOP) SlotPanel(this, frame, menu.inputSlot, 56f, PROGRESS_SLOT_TOP)

View File

@ -8,6 +8,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.FilterSlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
import ru.dbotthepony.mc.otm.menu.StorageBusMenu import ru.dbotthepony.mc.otm.menu.StorageBusMenu
@ -16,7 +17,7 @@ class StorageBusScreen(menu: StorageBusMenu, inventory: Inventory, title: Compon
override fun makeMainFrame(): FramePanel { override fun makeMainFrame(): FramePanel {
val frame = super.makeMainFrame()!! val frame = super.makeMainFrame()!!
PowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) WidePowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT)
SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE)
for (row in 0 .. 2) { for (row in 0 .. 2) {

View File

@ -8,6 +8,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.FilterSlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
import ru.dbotthepony.mc.otm.menu.StorageExporterMenu import ru.dbotthepony.mc.otm.menu.StorageExporterMenu
@ -16,7 +17,7 @@ class StorageExporterScreen(menu: StorageExporterMenu, inventory: Inventory, tit
override fun makeMainFrame(): FramePanel { override fun makeMainFrame(): FramePanel {
val frame = super.makeMainFrame()!! val frame = super.makeMainFrame()!!
PowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) WidePowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT)
SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE)
for (row in 0 .. 2) { for (row in 0 .. 2) {

View File

@ -8,6 +8,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.FilterSlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
import ru.dbotthepony.mc.otm.menu.StorageImporterMenu import ru.dbotthepony.mc.otm.menu.StorageImporterMenu
@ -16,7 +17,7 @@ class StorageImporterScreen(menu: StorageImporterMenu, inventory: Inventory, tit
override fun makeMainFrame(): FramePanel { override fun makeMainFrame(): FramePanel {
val frame = super.makeMainFrame()!! val frame = super.makeMainFrame()!!
PowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) WidePowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT)
SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE)
for (row in 0 .. 2) { for (row in 0 .. 2) {

View File

@ -5,6 +5,7 @@ import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.TranslatableComponent import ru.dbotthepony.mc.otm.TranslatableComponent
import ru.dbotthepony.mc.otm.client.screen.panels.* import ru.dbotthepony.mc.otm.client.screen.panels.*
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
import ru.dbotthepony.mc.otm.core.formatPower import ru.dbotthepony.mc.otm.core.formatPower
import ru.dbotthepony.mc.otm.menu.StoragePowerSupplierMenu import ru.dbotthepony.mc.otm.menu.StoragePowerSupplierMenu
@ -14,7 +15,7 @@ class StoragePowerSupplierScreen(menu: StoragePowerSupplierMenu, inventory: Inve
override fun makeMainFrame(): FramePanel { override fun makeMainFrame(): FramePanel {
val frame = super.makeMainFrame()!! val frame = super.makeMainFrame()!!
PowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) WidePowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT)
SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE)
object : Label(this@StoragePowerSupplierScreen, frame, 28f, 17f, width = 140f) { object : Label(this@StoragePowerSupplierScreen, frame, 28f, 17f, width = 140f) {

View File

@ -17,6 +17,8 @@ data class ScreenPos(val x: Float, val y: Float)
@JvmRecord @JvmRecord
data class DockProperty @JvmOverloads constructor(val left: Float = 0f, val top: Float = 0f, val right: Float = 0f, val bottom: Float = 0f) { data class DockProperty @JvmOverloads constructor(val left: Float = 0f, val top: Float = 0f, val right: Float = 0f, val bottom: Float = 0f) {
val isEmpty get() = left == 0f && right == 0f && top == 0f && bottom == 0f
companion object { companion object {
val EMPTY = DockProperty() val EMPTY = DockProperty()
} }

View File

@ -5,11 +5,8 @@ import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.ChatFormatting import net.minecraft.ChatFormatting
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import ru.dbotthepony.mc.otm.TranslatableComponent import ru.dbotthepony.mc.otm.TranslatableComponent
import ru.dbotthepony.mc.otm.client.render.SkinElement import ru.dbotthepony.mc.otm.client.render.*
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
import ru.dbotthepony.mc.otm.client.render.UVWindingOrder
import ru.dbotthepony.mc.otm.client.render.WidgetLocation
import ru.dbotthepony.mc.otm.client.render.element
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.formatMatterLevel import ru.dbotthepony.mc.otm.core.formatMatterLevel
import ru.dbotthepony.mc.otm.core.formatPowerLevel import ru.dbotthepony.mc.otm.core.formatPowerLevel
@ -21,8 +18,10 @@ open class PowerGaugePanel @JvmOverloads constructor(
parent: EditablePanel? = null, parent: EditablePanel? = null,
val widget: LevelGaugeWidget, val widget: LevelGaugeWidget,
x: Float = 0f, x: Float = 0f,
y: Float = 0f y: Float = 0f,
): EditablePanel(screen, parent, x, y, width = GAUGE_BACKGROUND.w, height = GAUGE_BACKGROUND.h) { width: Float = 9f,
height: Float = 48f
) : EditablePanel(screen, parent, x, y, width, height) {
init { init {
scissor = true scissor = true
} }
@ -35,9 +34,25 @@ open class PowerGaugePanel @JvmOverloads constructor(
} }
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
GAUGE_BACKGROUND.render(stack)
val height = this.height * widget.percentage() val height = this.height * widget.percentage()
GAUGE_FOREGROUND.renderPartial(stack, y = this.height - height, height = height, winding = UVWindingOrder.U0_V1_U1_V0)
if (width >= 18f) {
GAUGE_BACKGROUND_WIDE.render(stack, width = width, height = this.height)
GAUGE_FOREGROUND_WIDE.renderPartial(
stack,
y = this.height - height,
height = height,
width = width,
winding = UVWindingOrder.U0_V1_U1_V0)
} else {
GAUGE_BACKGROUND.render(stack, width = width, height = this.height)
GAUGE_FOREGROUND.renderPartial(
stack,
y = this.height - height,
height = height,
width = width,
winding = UVWindingOrder.U0_V1_U1_V0)
}
} }
override fun innerRenderTooltips(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float): Boolean { override fun innerRenderTooltips(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float): Boolean {
@ -52,9 +67,25 @@ open class PowerGaugePanel @JvmOverloads constructor(
companion object { companion object {
val GAUGE_BACKGROUND = WidgetLocation.WIDGETS.element(x = 0f, y = 48f, w = 9f, h = 48f) val GAUGE_BACKGROUND = WidgetLocation.WIDGETS.element(x = 0f, y = 48f, w = 9f, h = 48f)
val GAUGE_FOREGROUND = WidgetLocation.WIDGETS.element(x = 9f, y = 48f, w = 9f, h = 48f) val GAUGE_FOREGROUND = WidgetLocation.WIDGETS.element(x = 9f, y = 48f, w = 9f, h = 48f)
val GAUGE_BACKGROUND_WIDE = WidgetLocation.WIDGETS.element(x = 238f, y = 0f, w = 18f, h = 48f)
val GAUGE_FOREGROUND_WIDE = WidgetLocation.WIDGETS.element(x = 220f, y = 0f, w = 18f, h = 48f)
} }
} }
/**
* Shortcut to [PowerGaugePanel] with doubled width
*/
fun WidePowerGaugePanel(
screen: MatteryScreen<*>,
parent: EditablePanel? = null,
widget: LevelGaugeWidget,
x: Float = 0f,
y: Float = 0f,
width: Float = 18f,
height: Float = 48f
) = PowerGaugePanel(screen, parent, widget, x, y, width, height)
open class MatterGaugePanel @JvmOverloads constructor( open class MatterGaugePanel @JvmOverloads constructor(
screen: MatteryScreen<*>, screen: MatteryScreen<*>,
parent: EditablePanel? = null, parent: EditablePanel? = null,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB