Rename children properties

This commit is contained in:
DBotThePony 2022-10-26 18:28:21 +07:00
parent 44da2c4b11
commit d403fca482
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 55 additions and 56 deletions

View File

@ -3,7 +3,6 @@ package ru.dbotthepony.mc.otm.client.screen.panels
import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableList
import com.mojang.blaze3d.systems.RenderSystem import com.mojang.blaze3d.systems.RenderSystem
import com.mojang.blaze3d.vertex.PoseStack import com.mojang.blaze3d.vertex.PoseStack
import it.unimi.dsi.fastutil.objects.ObjectArraySet
import it.unimi.dsi.fastutil.objects.ReferenceArraySet import it.unimi.dsi.fastutil.objects.ReferenceArraySet
import net.minecraft.client.gui.Font import net.minecraft.client.gui.Font
import net.minecraft.client.gui.components.events.GuiEventListener import net.minecraft.client.gui.components.events.GuiEventListener
@ -20,7 +19,6 @@ import ru.dbotthepony.mc.otm.client.render.currentScissorRect
import ru.dbotthepony.mc.otm.client.render.popScissorRect import ru.dbotthepony.mc.otm.client.render.popScissorRect
import ru.dbotthepony.mc.otm.client.render.pushScissorRect import ru.dbotthepony.mc.otm.client.render.pushScissorRect
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
import ru.dbotthepony.mc.otm.nanoTime
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
import kotlin.math.roundToInt import kotlin.math.roundToInt
@ -170,9 +168,10 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
var dockedHeight: Float = 0f var dockedHeight: Float = 0f
private set private set
private val children = ArrayList<EditablePanel<*>>() private val childrenInternal = ArrayList<EditablePanel<*>>()
private val visibleChildren = ArrayList<EditablePanel<*>>() private val visibleChildrenInternal = ArrayList<EditablePanel<*>>()
val childrenView: List<EditablePanel<*>> = Collections.unmodifiableList(children) val children: List<EditablePanel<*>> = Collections.unmodifiableList(childrenInternal)
val visibleChildren: List<EditablePanel<*>> = Collections.unmodifiableList(visibleChildrenInternal)
var layoutInvalidated = true var layoutInvalidated = true
private set private set
@ -191,7 +190,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
if (old != new) { if (old != new) {
visibilityChanges(new, old) visibilityChanges(new, old)
val visibleChildrenParent = parent?.visibleChildren val visibleChildrenParent = parent?.visibleChildrenInternal
if (new) { if (new) {
killFocus() killFocus()
@ -384,7 +383,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
return true return true
} }
for (children in children) { for (children in childrenInternal) {
if (children.flashAnyBlockerInner(doFlash)) { if (children.flashAnyBlockerInner(doFlash)) {
return true return true
} }
@ -477,7 +476,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
val result = ArrayList<Rect2f>() val result = ArrayList<Rect2f>()
result.add(Rect2f(absoluteX, absoluteY, width, height)) result.add(Rect2f(absoluteX, absoluteY, width, height))
for (children in children) { for (children in childrenInternal) {
if (children.isOutsideOfParent && children.isVisible()) { if (children.isOutsideOfParent && children.isVisible()) {
result.addAll(children.calculateAbsoluteRectangles()) result.addAll(children.calculateAbsoluteRectangles())
} }
@ -517,7 +516,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
result.add(Rect2f(absoluteX, absoluteY, width, height)) result.add(Rect2f(absoluteX, absoluteY, width, height))
} }
for (children in visibleChildren) { for (children in visibleChildrenInternal) {
if (children.isOutsideOfParent || !isObstructing) { if (children.isOutsideOfParent || !isObstructing) {
result.addAll(children.calculateAbsoluteObstructingRectangles()) result.addAll(children.calculateAbsoluteObstructingRectangles())
} }
@ -547,7 +546,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
fun unsetHovered() { fun unsetHovered() {
isHovered = false isHovered = false
for (child in children) { for (child in childrenInternal) {
child.unsetHovered() child.unsetHovered()
} }
} }
@ -594,11 +593,11 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
} }
private fun onParent(child: EditablePanel<*>) { private fun onParent(child: EditablePanel<*>) {
if (children.contains(child)) throw IllegalStateException("Already containing $child") if (childrenInternal.contains(child)) throw IllegalStateException("Already containing $child")
children.add(child) childrenInternal.add(child)
if (child.visible) { if (child.visible) {
visibleChildren.add(child) visibleChildrenInternal.add(child)
layoutInvalidated = true layoutInvalidated = true
} }
@ -608,12 +607,12 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
} }
private fun onUnParent(child: EditablePanel<*>) { private fun onUnParent(child: EditablePanel<*>) {
val indexOf = children.indexOf(child) val indexOf = childrenInternal.indexOf(child)
if (indexOf == -1) throw IllegalStateException("Already not containing $child") if (indexOf == -1) throw IllegalStateException("Already not containing $child")
children.removeAt(indexOf) childrenInternal.removeAt(indexOf)
if (child.visible) { if (child.visible) {
visibleChildren.remove(child) visibleChildrenInternal.remove(child)
layoutInvalidated = true layoutInvalidated = true
} }
@ -659,7 +658,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
absoluteY = y absoluteY = y
} }
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
child.absoluteX = absoluteX + child.x + xOffset child.absoluteX = absoluteX + child.x + xOffset
child.absoluteY = absoluteY + child.y + yOffset child.absoluteY = absoluteY + child.y + yOffset
@ -719,7 +718,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
poseStack.popPose() poseStack.popPose()
} }
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
child.absoluteX = absoluteX + child.x + xOffset child.absoluteX = absoluteX + child.x + xOffset
child.absoluteY = absoluteY + child.y + yOffset child.absoluteY = absoluteY + child.y + yOffset
@ -739,7 +738,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
if ((childrenRectHeight > height || childrenRectWidth > width || childrenRectX < 0 || childrenRectY < 0) && parent == null) { if ((childrenRectHeight > height || childrenRectWidth > width || childrenRectX < 0 || childrenRectY < 0) && parent == null) {
var hit = false var hit = false
for (child in children) { for (child in childrenInternal) {
if (child.tickHover(mouseX, mouseY)) { if (child.tickHover(mouseX, mouseY)) {
hit = true hit = true
} }
@ -778,7 +777,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
return true to this.slot return true to this.slot
} }
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
val (status, slot) = child.findSlot(mouseX, mouseY) val (status, slot) = child.findSlot(mouseX, mouseY)
if (status) { if (status) {
@ -818,7 +817,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
return true to this.itemStack return true to this.itemStack
} }
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
val (status, itemStack) = child.findItemStack(mouseX, mouseY, ignoreMouseInputLock) val (status, itemStack) = child.findItemStack(mouseX, mouseY, ignoreMouseInputLock)
if (status) { if (status) {
@ -853,7 +852,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
return false return false
} }
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
if (child.renderTooltips(stack, mouseX, mouseY, partialTick)) { if (child.renderTooltips(stack, mouseX, mouseY, partialTick)) {
return true return true
} }
@ -950,7 +949,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
var top = dockPadding.top var top = dockPadding.top
var bottom = dockPadding.bottom var bottom = dockPadding.bottom
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
when (child.dock) { when (child.dock) {
Dock.NONE -> {} Dock.NONE -> {}
Dock.FILL -> {} Dock.FILL -> {}
@ -1013,7 +1012,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
} }
} }
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
if (child.dock == Dock.FILL) { if (child.dock == Dock.FILL) {
val w = width - child.dockMargin.left - child.dockMargin.right - right - left val w = width - child.dockMargin.left - child.dockMargin.right - right - left
val h = height - child.dockMargin.bottom - child.dockMargin.top - bottom - top val h = height - child.dockMargin.bottom - child.dockMargin.top - bottom - top
@ -1051,7 +1050,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
childrenRectWidth = 0f childrenRectWidth = 0f
childrenRectHeight = 0f childrenRectHeight = 0f
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
childrenRectX = childrenRectX.coerceAtMost(child.x) childrenRectX = childrenRectX.coerceAtMost(child.x)
childrenRectY = childrenRectY.coerceAtMost(child.y) childrenRectY = childrenRectY.coerceAtMost(child.y)
childrenRectWidth = childrenRectWidth.coerceAtLeast(child.x + child.width) childrenRectWidth = childrenRectWidth.coerceAtLeast(child.x + child.width)
@ -1077,7 +1076,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
var width = 1f var width = 1f
var height = 1f var height = 1f
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
width = width.coerceAtLeast(child.x + child.width) width = width.coerceAtLeast(child.x + child.width)
height = height.coerceAtLeast(child.y + child.height) height = height.coerceAtLeast(child.y + child.height)
} }
@ -1097,7 +1096,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
private fun updateVisible() { private fun updateVisible() {
val isVisible = isVisible() val isVisible = isVisible()
for (child in children) { for (child in childrenInternal) {
val old = child.isVisible() val old = child.isVisible()
child.visibleAsChildren = isVisible child.visibleAsChildren = isVisible
val new = child.isVisible() val new = child.isVisible()
@ -1111,7 +1110,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
} }
private fun killFocusInternal() { private fun killFocusInternal() {
for (child in children) { for (child in childrenInternal) {
child.killFocusInternal() child.killFocusInternal()
} }
@ -1132,7 +1131,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
return this return this
} }
for (child in children) { for (child in childrenInternal) {
val focus = child.findHierarchicalFocus() val focus = child.findHierarchicalFocus()
if (focus != null) { if (focus != null) {
@ -1163,7 +1162,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
onHierarchicalFocusChanged(focusedAsParent, old) onHierarchicalFocusChanged(focusedAsParent, old)
} }
for (child in children) { for (child in childrenInternal) {
child.updateFocus() child.updateFocus()
} }
} }
@ -1225,13 +1224,13 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
} }
fun fetchChildren(): List<EditablePanel<*>> { fun fetchChildren(): List<EditablePanel<*>> {
return ImmutableList.copyOf(children) return ImmutableList.copyOf(childrenInternal)
} }
fun getUndockedChildren(): List<EditablePanel<*>> { fun getUndockedChildren(): List<EditablePanel<*>> {
val list = LinkedList<EditablePanel<*>>() val list = LinkedList<EditablePanel<*>>()
for (child in children) { for (child in childrenInternal) {
if (child.dock == Dock.NONE) { if (child.dock == Dock.NONE) {
list.add(child) list.add(child)
} }
@ -1241,8 +1240,8 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
} }
operator fun get(index: Int): EditablePanel<*>? { operator fun get(index: Int): EditablePanel<*>? {
if (index < 0 || index >= children.size) return null if (index < 0 || index >= childrenInternal.size) return null
return children[index] return childrenInternal[index]
} }
fun isGrabbingMouseInput(): Boolean { fun isGrabbingMouseInput(): Boolean {
@ -1250,7 +1249,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
return true return true
} }
for (child in children) { for (child in childrenInternal) {
if (child.isGrabbingMouseInput()) { if (child.isGrabbingMouseInput()) {
return true return true
} }
@ -1281,7 +1280,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
} }
fun killFocusForEverythingExcept(except: EditablePanel<*>) { fun killFocusForEverythingExcept(except: EditablePanel<*>) {
for (child in children) { for (child in childrenInternal) {
if (child !== except) { if (child !== except) {
child.killFocusForEverythingExceptInner() child.killFocusForEverythingExceptInner()
} }
@ -1289,7 +1288,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
} }
fun killFocusForEverythingExceptInner() { fun killFocusForEverythingExceptInner() {
for (child in children) { for (child in childrenInternal) {
child.killFocusForEverythingExceptInner() child.killFocusForEverythingExceptInner()
} }
@ -1307,14 +1306,14 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
if (grabMouseInput) return mouseClickedInner(x, y, button) if (grabMouseInput) return mouseClickedInner(x, y, button)
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
if (child.isGrabbingMouseInput() && child.mouseClickedChecked(x, y, button)) { if (child.isGrabbingMouseInput() && child.mouseClickedChecked(x, y, button)) {
killFocusForEverythingExcept(child) killFocusForEverythingExcept(child)
return true return true
} }
} }
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
if (child.mouseClickedChecked(x, y, button)) { if (child.mouseClickedChecked(x, y, button)) {
killFocusForEverythingExcept(child) killFocusForEverythingExcept(child)
return true return true
@ -1331,7 +1330,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
if (acceptMouseInput && parent == null) popup() if (acceptMouseInput && parent == null) popup()
return mouseClicked(x, y, button) return mouseClicked(x, y, button)
} else if (withinExtendedBounds(x, y)) { } else if (withinExtendedBounds(x, y)) {
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
if (child.mouseClickedChecked(x, y, button)) { if (child.mouseClickedChecked(x, y, button)) {
killFocusForEverythingExcept(child) killFocusForEverythingExcept(child)
return true return true
@ -1359,13 +1358,13 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
if (grabMouseInput) return mouseReleasedInner(x, y, button) if (grabMouseInput) return mouseReleasedInner(x, y, button)
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
if (child.isGrabbingMouseInput() && child.mouseReleasedChecked(x, y, button)) { if (child.isGrabbingMouseInput() && child.mouseReleasedChecked(x, y, button)) {
return true return true
} }
} }
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
if (child.mouseReleasedChecked(x, y, button)) { if (child.mouseReleasedChecked(x, y, button)) {
return true return true
} }
@ -1380,7 +1379,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
if (isGrabbingMouseInput() || withinBounds(x, y)) { if (isGrabbingMouseInput() || withinBounds(x, y)) {
return mouseReleased(x, y, button) return mouseReleased(x, y, button)
} else if (withinExtendedBounds(x, y)) { } else if (withinExtendedBounds(x, y)) {
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
if (child.mouseReleasedChecked(x, y, button)) { if (child.mouseReleasedChecked(x, y, button)) {
return true return true
} }
@ -1403,13 +1402,13 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
if (grabMouseInput) return mouseDraggedInner(x, y, button, xDelta, yDelta) if (grabMouseInput) return mouseDraggedInner(x, y, button, xDelta, yDelta)
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
if (child.isGrabbingMouseInput() && child.mouseDraggedChecked(x, y, button, xDelta, yDelta)) { if (child.isGrabbingMouseInput() && child.mouseDraggedChecked(x, y, button, xDelta, yDelta)) {
return true return true
} }
} }
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
if (child.mouseDraggedChecked(x, y, button, xDelta, yDelta)) { if (child.mouseDraggedChecked(x, y, button, xDelta, yDelta)) {
return true return true
} }
@ -1424,7 +1423,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
if (isGrabbingMouseInput() || withinBounds(x, y)) { if (isGrabbingMouseInput() || withinBounds(x, y)) {
return mouseDragged(x, y, button, xDelta, yDelta) return mouseDragged(x, y, button, xDelta, yDelta)
} else if (withinExtendedBounds(x, y)) { } else if (withinExtendedBounds(x, y)) {
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
if (child.mouseDraggedChecked(x, y, button, xDelta, yDelta)) { if (child.mouseDraggedChecked(x, y, button, xDelta, yDelta)) {
return true return true
} }
@ -1448,13 +1447,13 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
if (grabMouseInput) return mouseScrolledInner(x, y, scroll) if (grabMouseInput) return mouseScrolledInner(x, y, scroll)
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
if (child.isGrabbingMouseInput() && child.mouseScrolledChecked(x, y, scroll)) { if (child.isGrabbingMouseInput() && child.mouseScrolledChecked(x, y, scroll)) {
return true return true
} }
} }
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
if (child.mouseScrolledChecked(x, y, scroll)) { if (child.mouseScrolledChecked(x, y, scroll)) {
return true return true
} }
@ -1469,7 +1468,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
if (isGrabbingMouseInput() || withinBounds(x, y)) { if (isGrabbingMouseInput() || withinBounds(x, y)) {
return mouseScrolled(x, y, scroll) return mouseScrolled(x, y, scroll)
} else if (withinExtendedBounds(x, y)) { } else if (withinExtendedBounds(x, y)) {
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
if (child.mouseScrolledChecked(x, y, scroll)) { if (child.mouseScrolledChecked(x, y, scroll)) {
return true return true
} }
@ -1493,7 +1492,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
if (isFocused) return keyPressedInternal(key, scancode, mods) if (isFocused) return keyPressedInternal(key, scancode, mods)
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
if (child.keyPressed(key, scancode, mods)) { if (child.keyPressed(key, scancode, mods)) {
return true return true
} }
@ -1516,7 +1515,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
if (isFocused) return keyReleasedInternal(key, scancode, mods) if (isFocused) return keyReleasedInternal(key, scancode, mods)
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
if (child.keyReleased(key, scancode, mods)) { if (child.keyReleased(key, scancode, mods)) {
return true return true
} }
@ -1539,7 +1538,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
if (isFocused) return charTypedInternal(codepoint, mods) if (isFocused) return charTypedInternal(codepoint, mods)
for (child in visibleChildren) { for (child in visibleChildrenInternal) {
if (child.charTyped(codepoint, mods)) { if (child.charTyped(codepoint, mods)) {
return true return true
} }
@ -1565,7 +1564,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
open fun tick() { open fun tick() {
tick++ tick++
for (child in Array(children.size) { children[it] }) { for (child in Array(childrenInternal.size) { childrenInternal[it] }) {
child.tick() child.tick()
} }
} }
@ -1588,7 +1587,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
screen.removePanel(this as EditablePanel<MatteryScreen<*>>) screen.removePanel(this as EditablePanel<MatteryScreen<*>>)
} }
for (child in Array(children.size) { children[it] }) { for (child in Array(childrenInternal.size) { childrenInternal[it] }) {
child.remove() child.remove()
} }

View File

@ -180,7 +180,7 @@ open class EffectListPanel<out S : Screen> @JvmOverloads constructor(
override fun performLayout() { override fun performLayout() {
super.performLayout() super.performLayout()
val sorted = childrenView.stream().filter { it is EffectSquare }.collect(Collectors.toList()) as MutableList<EffectListPanel<S>.EffectSquare> val sorted = children.stream().filter { it is EffectSquare }.collect(Collectors.toList()) as MutableList<EffectListPanel<S>.EffectSquare>
sorted.sortWith { a, b -> sorted.sortWith { a, b ->
a.effect.duration.compareTo(b.effect.duration) a.effect.duration.compareTo(b.effect.duration)

View File

@ -61,7 +61,7 @@ open class QueryUserPanel<out S: Screen>(
} }
} }
this.width = maxWidth.coerceAtLeast(bottom.childrenView.stream().mapToDouble { it.width.toDouble() }.sum().toFloat() + 2f) + PADDING * 2f this.width = maxWidth.coerceAtLeast(bottom.children.stream().mapToDouble { it.width.toDouble() }.sum().toFloat() + 2f) + PADDING * 2f
toScreenCenter() toScreenCenter()
} }