Improve power supplier menu

This commit is contained in:
DBotThePony 2022-09-02 18:04:24 +07:00
parent 8df7cf76a8
commit bc68b9b9ef
Signed by: DBot
GPG Key ID: DCC23B5715498507
7 changed files with 118 additions and 15 deletions

View File

@ -53,6 +53,8 @@ private fun misc(provider: MatteryLanguageProvider) {
gui("exosuit.already_activated", "You already have exosuit following you") gui("exosuit.already_activated", "You already have exosuit following you")
gui("power_supplier.active_nodes", "Currently demanding nodes: %s")
misc("battery.single_use", "Single use battery, can not be recharged.") misc("battery.single_use", "Single use battery, can not be recharged.")
misc("exosuit.granted1", "As you keep pressing fingerprint reader, you are getting hurt in finger.") misc("exosuit.granted1", "As you keep pressing fingerprint reader, you are getting hurt in finger.")

View File

@ -4,7 +4,7 @@ import net.minecraft.network.chat.Component
import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.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.WidePowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.HorizontalPowerGaugePanel
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
@ -12,12 +12,32 @@ import ru.dbotthepony.mc.otm.menu.StoragePowerSupplierMenu
class StoragePowerSupplierScreen(menu: StoragePowerSupplierMenu, inventory: Inventory, title: Component) : class StoragePowerSupplierScreen(menu: StoragePowerSupplierMenu, inventory: Inventory, title: Component) :
MatteryScreen<StoragePowerSupplierMenu>(menu, inventory, title) { MatteryScreen<StoragePowerSupplierMenu>(menu, inventory, title) {
override fun makeMainFrame(): FramePanel { override fun makeMainFrame(): FramePanel {
val frame = super.makeMainFrame()!! val frame = FramePanel(this, width = 200f, height = 60f, title)
WidePowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) HorizontalPowerGaugePanel(this, frame, menu.powerWidget).also {
BatterySlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) it.dock = Dock.BOTTOM
it.dockResize = DockResizeMode.NONE
}
val topStrip = EditablePanel(this, frame, height = AbstractSlotPanel.SIZE)
topStrip.dock = Dock.TOP
topStrip.dockTop = 3f
BatterySlotPanel(this, topStrip, menu.batterySlot).also {
it.dock = Dock.LEFT
it.dockRight = 3f
}
val labels = EditablePanel(this, topStrip)
labels.dock = Dock.FILL
object : Label(this@StoragePowerSupplierScreen, labels) {
init {
dock = Dock.TOP
}
object : Label(this@StoragePowerSupplierScreen, frame, 28f, 17f, width = 140f) {
override fun tick() { override fun tick() {
super.tick() super.tick()
@ -28,6 +48,21 @@ class StoragePowerSupplierScreen(menu: StoragePowerSupplierMenu, inventory: Inve
} }
} }
object : Label(this@StoragePowerSupplierScreen, labels) {
init {
dock = Dock.TOP
}
override fun tick() {
super.tick()
text = TranslatableComponent(
"otm.gui.power_supplier.active_nodes",
menu.activeNodes
)
}
}
return frame return frame
} }
} }

View File

@ -116,7 +116,7 @@ open class FramePanel(
onClose?.run() onClose?.run()
} }
override fun mouseClickedInner(x: Double, y: Double, flag: Int): Boolean { override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
if (isActive) { if (isActive) {
return true return true
} }

View File

@ -0,0 +1,66 @@
package ru.dbotthepony.mc.otm.client.screen.widget
import com.mojang.blaze3d.vertex.PoseStack
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.MatteryScreen
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
open class HorizontalPowerGaugePanel(
screen: MatteryScreen<*>,
parent: EditablePanel? = null,
widget: LevelGaugeWidget,
x: Float = 0f,
y: Float = 0f,
width: Float = GAUGE_BACKGROUND.w,
height: Float = GAUGE_BACKGROUND.h
) : PowerGaugePanel(screen, parent, widget, x, y, width, height) {
var flop = false
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
if (height >= 18f) {
if (flop) {
GAUGE_BACKGROUND_TALL.render(stack, height = height, width = this.width, winding = UVWindingOrder.U1_V0_U0_V1)
val width = this.width * widget.percentage()
GAUGE_FOREGROUND_TALL.renderPartial(stack, x = this.width - width, height = height, width = width, winding = UVWindingOrder.U1_V0_U0_V1)
} else {
GAUGE_BACKGROUND_TALL.render(stack, height = height, width = this.width)
val width = this.width * widget.percentage()
GAUGE_FOREGROUND_TALL.renderPartial(stack, height = height, width = width)
}
} else {
if (flop) {
GAUGE_BACKGROUND.render(stack, height = height, width = this.width, winding = UVWindingOrder.U1_V0_U0_V1)
val width = this.width * widget.percentage()
GAUGE_FOREGROUND.renderPartial(stack, x = this.width - width, height = height, width = width, winding = UVWindingOrder.U1_V0_U0_V1)
} else {
GAUGE_BACKGROUND.render(stack, height = height, width = this.width)
val width = this.width * widget.percentage()
GAUGE_FOREGROUND.renderPartial(stack, height = height, width = width)
}
}
}
companion object {
val GAUGE_BACKGROUND = WidgetLocation.WIDGETS.element(x = 160f, y = 238f, w = 96f, h = 9f)
val GAUGE_FOREGROUND = WidgetLocation.WIDGETS.element(x = 160f, y = 247f, w = 96f, h = 9f)
val GAUGE_BACKGROUND_TALL = WidgetLocation.WIDGETS.element(x = 160f, y = 202f, w = 96f, h = 18f)
val GAUGE_FOREGROUND_TALL = WidgetLocation.WIDGETS.element(x = 160f, y = 220f, w = 96f, h = 18f)
}
}
/**
* Shortcut to [HorizontalPowerGaugePanel] with doubled height
*/
fun TallHorizontalPowerGaugePanel(
screen: MatteryScreen<*>,
parent: EditablePanel? = null,
widget: LevelGaugeWidget,
x: Float = 0f,
y: Float = 0f,
width: Float = HorizontalPowerGaugePanel.GAUGE_BACKGROUND_TALL.w,
height: Float = HorizontalPowerGaugePanel.GAUGE_BACKGROUND_TALL.h
) = HorizontalPowerGaugePanel(screen, parent, widget, x, y, width, height)

View File

@ -15,8 +15,8 @@ open class PowerGaugePanel(
val widget: LevelGaugeWidget, val widget: LevelGaugeWidget,
x: Float = 0f, x: Float = 0f,
y: Float = 0f, y: Float = 0f,
width: Float = 9f, width: Float = GAUGE_BACKGROUND.w,
height: Float = 48f height: Float = GAUGE_BACKGROUND.h
) : EditablePanel(screen, parent, x, y, width, height) { ) : EditablePanel(screen, parent, x, y, width, height) {
init { init {
scissor = true scissor = true

View File

@ -54,13 +54,13 @@ open class ProgressGaugePanel(
} }
if (flop) { if (flop) {
GAUGE_BACKGROUND.render(stack, winding = UVWindingOrder.U1_V0_U0_V1) GAUGE_BACKGROUND.render(stack, height = height, width = this.width, winding = UVWindingOrder.U1_V0_U0_V1)
val width = this.width * widget.percentage() val width = this.width * widget.percentage()
GAUGE_FOREGROUND.renderPartial(stack, x = this.width - width, width = width, winding = UVWindingOrder.U1_V0_U0_V1) GAUGE_FOREGROUND.renderPartial(stack, x = this.width - width, height = height, width = width, winding = UVWindingOrder.U1_V0_U0_V1)
} else { } else {
GAUGE_BACKGROUND.render(stack) GAUGE_BACKGROUND.render(stack, height = height, width = this.width)
val width = this.width * widget.percentage() val width = this.width * widget.percentage()
GAUGE_FOREGROUND.renderPartial(stack, width = width) GAUGE_FOREGROUND.renderPartial(stack, height = height, width = width)
} }
if (widget.isStuck() && tick % 40 <= 20) { if (widget.isStuck() && tick % 40 <= 20) {

View File

@ -9,10 +9,9 @@ class StoragePowerSupplierMenu @JvmOverloads constructor(
p_38852_: Int, p_38852_: Int,
inventory: Inventory, inventory: Inventory,
tile: StoragePowerSupplierBlockEntity? = null tile: StoragePowerSupplierBlockEntity? = null
) : MatteryPoweredMenu( ) : MatteryPoweredMenu(MMenus.STORAGE_POWER_SUPPLIER, p_38852_, inventory, tile) {
MMenus.STORAGE_POWER_SUPPLIER, p_38852_, inventory, tile
) {
var totalTransferred by mSynchronizer.fraction() var totalTransferred by mSynchronizer.fraction()
var activeNodes by mSynchronizer.int()
init { init {
addInventorySlots() addInventorySlots()
@ -21,6 +20,7 @@ class StoragePowerSupplierMenu @JvmOverloads constructor(
override fun broadcastChanges() { override fun broadcastChanges() {
if (tile is StoragePowerSupplierBlockEntity) { if (tile is StoragePowerSupplierBlockEntity) {
totalTransferred = tile.powerSupplied totalTransferred = tile.powerSupplied
activeNodes = tile.cell.storageGraph?.powerDemandingNodes?.size ?: 0
} }
super.broadcastChanges() super.broadcastChanges()