Make children panels override tickInner

This commit is contained in:
DBotThePony 2023-02-17 14:46:12 +07:00
parent 49caf1c0b2
commit d66b96c791
Signed by: DBot
GPG Key ID: DCC23B5715498507
14 changed files with 50 additions and 45 deletions

View File

@ -142,8 +142,8 @@ class MatterPanelScreen(
return menu.tasks.firstOrNull { it.id == task.id }?.let { it.stack((it.required + it.inProgress).coerceAtLeast(1)) } ?: task.stack((task.required + task.inProgress).coerceAtLeast(1)) return menu.tasks.firstOrNull { it.id == task.id }?.let { it.stack((it.required + it.inProgress).coerceAtLeast(1)) } ?: task.stack((task.required + task.inProgress).coerceAtLeast(1))
} }
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
if (!menu.tasks.any { it.id == task.id }) { if (!menu.tasks.any { it.id == task.id }) {
frame.remove() frame.remove()
@ -208,8 +208,8 @@ class MatterPanelScreen(
} }
} }
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
if (!menu.patterns.any { it.id == pattern.id }) { if (!menu.patterns.any { it.id == pattern.id }) {
frame.remove() frame.remove()

View File

@ -1598,10 +1598,15 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
return x >= pos.x && x <= pos.x + width && y >= pos.y && y + height <= pos.y return x >= pos.x && x <= pos.x + width && y >= pos.y && y + height <= pos.y
} }
protected var tick = 0 var tickCount = 0
private set
open fun tick() { protected open fun tickInner() {}
tick++
fun tick() {
tickCount++
tickInner()
for (child in Array(visibleChildrenInternal.size) { visibleChildrenInternal[it] }) { for (child in Array(visibleChildrenInternal.size) { visibleChildrenInternal[it] }) {
child.tick() child.tick()

View File

@ -100,8 +100,8 @@ open class EffectListPanel<out S : Screen> @JvmOverloads constructor(
return true return true
} }
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
if (!isStillValid) { if (!isStillValid) {
effectButtons.remove(effectType) effectButtons.remove(effectType)
@ -163,14 +163,14 @@ open class EffectListPanel<out S : Screen> @JvmOverloads constructor(
canvas.yOffset = newScroll * -26f canvas.yOffset = newScroll * -26f
} }
override fun tick() { override fun tickInner() {
for (effect in entity.activeEffects) { for (effect in entity.activeEffects) {
effectButtons.computeIfAbsent(effect.effect, Object2ObjectFunction { effectButtons.computeIfAbsent(effect.effect, Object2ObjectFunction {
EffectSquare(effect) EffectSquare(effect)
}) })
} }
super.tick() super.tickInner()
} }
val canvas = object : EditablePanel<S>(screen, this@EffectListPanel, 0f, 0f, width, height) { val canvas = object : EditablePanel<S>(screen, this@EffectListPanel, 0f, 0f, width, height) {

View File

@ -26,8 +26,8 @@ abstract class Widget2Panel<out S : Screen, T : AbstractWidget>(
val isWidgetDisabled: Boolean val isWidgetDisabled: Boolean
get() = disableTicks > 0 get() = disableTicks > 0
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
if (disableTicks > 0) { if (disableTicks > 0) {
disableTicks-- disableTicks--

View File

@ -41,8 +41,8 @@ fun <S : MatteryScreen<*>> makeDeviceControls(
redstone: IPlayerInputWithFeedback<RedstoneSetting>? = null redstone: IPlayerInputWithFeedback<RedstoneSetting>? = null
): EditablePanel<S> { ): EditablePanel<S> {
val panel = object : EditablePanel<S>(screen, parent, width = LargeEnumRectangleButtonPanel.SIZE, height = 0f, x = parent.width + 3f) { val panel = object : EditablePanel<S>(screen, parent, width = LargeEnumRectangleButtonPanel.SIZE, height = 0f, x = parent.width + 3f) {
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
x = parent.width + 3f x = parent.width + 3f
y = 0f y = 0f
} }

View File

@ -36,8 +36,8 @@ open class EditBoxPanel<out S : Screen>(
new_widget.value = old_widget.value new_widget.value = old_widget.value
} }
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
widget?.tick() widget?.tick()
} }

View File

@ -55,8 +55,8 @@ open class NetworkNumberInputPanel<out S : Screen> @JvmOverloads constructor(
return super.mouseClickedInner(x, y, button) return super.mouseClickedInner(x, y, button)
} }
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
if (isFocused) { if (isFocused) {
if (!isAvailable.asBoolean) { if (!isAvailable.asBoolean) {

View File

@ -34,8 +34,8 @@ open class NetworkedStringInputPanel<out S : Screen>(
backend.accept(new) backend.accept(new)
} }
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
if (milliTime >= lastChanges) { if (milliTime >= lastChanges) {
text = backend.value text = backend.value

View File

@ -182,8 +182,8 @@ open class TextInputPanel<out S : Screen>(
private var snapshotTimer: Long? = null private var snapshotTimer: Long? = null
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
if (snapshotTimer != null && snapshotTimer!! <= milliTime) { if (snapshotTimer != null && snapshotTimer!! <= milliTime) {
pushbackSnapshot() pushbackSnapshot()

View File

@ -64,8 +64,8 @@ open class FoldableSlotPanel<out S : MatteryScreen<*>, out T : Slot> @JvmOverloa
remove() remove()
} }
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
x = this@FoldableSlotPanel.absoluteX - dockPadding.left x = this@FoldableSlotPanel.absoluteX - dockPadding.left
y = this@FoldableSlotPanel.absoluteY - dockPadding.top y = this@FoldableSlotPanel.absoluteY - dockPadding.top
@ -92,8 +92,8 @@ open class FoldableSlotPanel<out S : MatteryScreen<*>, out T : Slot> @JvmOverloa
hoverPanel?.remove() hoverPanel?.remove()
} }
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
val hoveringSince = hoveringSince val hoveringSince = hoveringSince

View File

@ -42,8 +42,8 @@ class StoragePowerSupplierScreen(menu: StoragePowerSupplierMenu, inventory: Inve
dock = Dock.TOP dock = Dock.TOP
} }
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
text = TranslatableComponent( text = TranslatableComponent(
"otm.item.power.passed", "otm.item.power.passed",
@ -57,8 +57,8 @@ class StoragePowerSupplierScreen(menu: StoragePowerSupplierMenu, inventory: Inve
dock = Dock.TOP dock = Dock.TOP
} }
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
text = TranslatableComponent( text = TranslatableComponent(
"otm.gui.power_supplier.active_nodes", "otm.gui.power_supplier.active_nodes",

View File

@ -551,8 +551,8 @@ class AndroidStationScreen constructor(p_97741_: AndroidStationMenu, p_97742_: I
return super.mouseClickedInner(x, y, button) return super.mouseClickedInner(x, y, button)
} }
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
if (isPreview && !layoutInvalidated) { if (isPreview && !layoutInvalidated) {
if (firstTick) { if (firstTick) {

View File

@ -17,8 +17,8 @@ class EnergyCounterScreen(menu: EnergyCounterMenu, inventory: Inventory, title:
val frame = super.makeMainFrame()!! val frame = super.makeMainFrame()!!
var label: Label<EnergyCounterScreen> = object : Label<EnergyCounterScreen>(this@EnergyCounterScreen, frame) { var label: Label<EnergyCounterScreen> = object : Label<EnergyCounterScreen>(this@EnergyCounterScreen, frame) {
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
text = TranslatableComponent( text = TranslatableComponent(
"otm.item.power.passed", "otm.item.power.passed",
menu.passed.formatPower(formatAsReadable = ShiftPressedCond) menu.passed.formatPower(formatAsReadable = ShiftPressedCond)
@ -30,8 +30,8 @@ class EnergyCounterScreen(menu: EnergyCounterMenu, inventory: Inventory, title:
label.setDockMargin(4f, 0f, 0f, 0f) label.setDockMargin(4f, 0f, 0f, 0f)
label = object : Label<EnergyCounterScreen>(this@EnergyCounterScreen, frame) { label = object : Label<EnergyCounterScreen>(this@EnergyCounterScreen, frame) {
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
text = TranslatableComponent( text = TranslatableComponent(
"otm.item.power.average", "otm.item.power.average",
menu.average.formatPower(formatAsReadable = ShiftPressedCond) menu.average.formatPower(formatAsReadable = ShiftPressedCond)
@ -43,8 +43,8 @@ class EnergyCounterScreen(menu: EnergyCounterMenu, inventory: Inventory, title:
label.setDockMargin(4f, 0f, 0f, 0f) label.setDockMargin(4f, 0f, 0f, 0f)
label = object : Label<EnergyCounterScreen>(this@EnergyCounterScreen, frame) { label = object : Label<EnergyCounterScreen>(this@EnergyCounterScreen, frame) {
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
text = TranslatableComponent( text = TranslatableComponent(
"otm.item.power.last_20_ticks", "otm.item.power.last_20_ticks",
menu.last20Ticks.formatPower(formatAsReadable = ShiftPressedCond) menu.last20Ticks.formatPower(formatAsReadable = ShiftPressedCond)
@ -56,8 +56,8 @@ class EnergyCounterScreen(menu: EnergyCounterMenu, inventory: Inventory, title:
label.setDockMargin(4f, 0f, 0f, 0f) label.setDockMargin(4f, 0f, 0f, 0f)
label = object : Label<EnergyCounterScreen>(this@EnergyCounterScreen, frame) { label = object : Label<EnergyCounterScreen>(this@EnergyCounterScreen, frame) {
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
text = TranslatableComponent( text = TranslatableComponent(
"otm.item.power.last_tick", "otm.item.power.last_tick",
menu.lastTick.formatPower(formatAsReadable = ShiftPressedCond) menu.lastTick.formatPower(formatAsReadable = ShiftPressedCond)
@ -69,8 +69,8 @@ class EnergyCounterScreen(menu: EnergyCounterMenu, inventory: Inventory, title:
label.setDockMargin(4f, 0f, 0f, 0f) label.setDockMargin(4f, 0f, 0f, 0f)
label = object : Label<EnergyCounterScreen>(this@EnergyCounterScreen, frame) { label = object : Label<EnergyCounterScreen>(this@EnergyCounterScreen, frame) {
override fun tick() { override fun tickInner() {
super.tick() super.tickInner()
text = TranslatableComponent( text = TranslatableComponent(
"block.overdrive_that_matters.energy_counter.facing", "block.overdrive_that_matters.energy_counter.facing",

View File

@ -49,7 +49,7 @@ open class ProgressGaugePanel<S : Screen> @JvmOverloads constructor(
} }
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
if (widget.isStuck() && tick % 40 <= 20) { if (widget.isStuck() && tickCount % 40 <= 20) {
RenderSystem.setShaderColor(0.75f, 0.4f, 0.4f, 1f) RenderSystem.setShaderColor(0.75f, 0.4f, 0.4f, 1f)
} }
@ -63,7 +63,7 @@ open class ProgressGaugePanel<S : Screen> @JvmOverloads constructor(
GAUGE_FOREGROUND.renderPartial(stack, height = height, width = width) GAUGE_FOREGROUND.renderPartial(stack, height = height, width = width)
} }
if (widget.isStuck() && tick % 40 <= 20) { if (widget.isStuck() && tickCount % 40 <= 20) {
RenderSystem.setShaderColor(1f, 1f, 1f, 1f) RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
} }
} }