From d403fca48272492f60db5a6912df169e1cb6ddb4 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 26 Oct 2022 18:28:21 +0700 Subject: [PATCH] Rename children properties --- .../otm/client/screen/panels/EditablePanel.kt | 107 +++++++++--------- .../client/screen/panels/EffectListPanel.kt | 2 +- .../client/screen/panels/QueryUserPanel.kt | 2 +- 3 files changed, 55 insertions(+), 56 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt index 6f423bf30..762e4039c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt @@ -3,7 +3,6 @@ package ru.dbotthepony.mc.otm.client.screen.panels import com.google.common.collect.ImmutableList import com.mojang.blaze3d.systems.RenderSystem import com.mojang.blaze3d.vertex.PoseStack -import it.unimi.dsi.fastutil.objects.ObjectArraySet import it.unimi.dsi.fastutil.objects.ReferenceArraySet import net.minecraft.client.gui.Font 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.pushScissorRect import ru.dbotthepony.mc.otm.client.screen.MatteryScreen -import ru.dbotthepony.mc.otm.nanoTime import java.util.* import kotlin.collections.ArrayList import kotlin.math.roundToInt @@ -170,9 +168,10 @@ open class EditablePanel @JvmOverloads constructor( var dockedHeight: Float = 0f private set - private val children = ArrayList>() - private val visibleChildren = ArrayList>() - val childrenView: List> = Collections.unmodifiableList(children) + private val childrenInternal = ArrayList>() + private val visibleChildrenInternal = ArrayList>() + val children: List> = Collections.unmodifiableList(childrenInternal) + val visibleChildren: List> = Collections.unmodifiableList(visibleChildrenInternal) var layoutInvalidated = true private set @@ -191,7 +190,7 @@ open class EditablePanel @JvmOverloads constructor( if (old != new) { visibilityChanges(new, old) - val visibleChildrenParent = parent?.visibleChildren + val visibleChildrenParent = parent?.visibleChildrenInternal if (new) { killFocus() @@ -384,7 +383,7 @@ open class EditablePanel @JvmOverloads constructor( return true } - for (children in children) { + for (children in childrenInternal) { if (children.flashAnyBlockerInner(doFlash)) { return true } @@ -477,7 +476,7 @@ open class EditablePanel @JvmOverloads constructor( val result = ArrayList() result.add(Rect2f(absoluteX, absoluteY, width, height)) - for (children in children) { + for (children in childrenInternal) { if (children.isOutsideOfParent && children.isVisible()) { result.addAll(children.calculateAbsoluteRectangles()) } @@ -517,7 +516,7 @@ open class EditablePanel @JvmOverloads constructor( result.add(Rect2f(absoluteX, absoluteY, width, height)) } - for (children in visibleChildren) { + for (children in visibleChildrenInternal) { if (children.isOutsideOfParent || !isObstructing) { result.addAll(children.calculateAbsoluteObstructingRectangles()) } @@ -547,7 +546,7 @@ open class EditablePanel @JvmOverloads constructor( fun unsetHovered() { isHovered = false - for (child in children) { + for (child in childrenInternal) { child.unsetHovered() } } @@ -594,11 +593,11 @@ open class EditablePanel @JvmOverloads constructor( } private fun onParent(child: EditablePanel<*>) { - if (children.contains(child)) throw IllegalStateException("Already containing $child") - children.add(child) + if (childrenInternal.contains(child)) throw IllegalStateException("Already containing $child") + childrenInternal.add(child) if (child.visible) { - visibleChildren.add(child) + visibleChildrenInternal.add(child) layoutInvalidated = true } @@ -608,12 +607,12 @@ open class EditablePanel @JvmOverloads constructor( } private fun onUnParent(child: EditablePanel<*>) { - val indexOf = children.indexOf(child) + val indexOf = childrenInternal.indexOf(child) if (indexOf == -1) throw IllegalStateException("Already not containing $child") - children.removeAt(indexOf) + childrenInternal.removeAt(indexOf) if (child.visible) { - visibleChildren.remove(child) + visibleChildrenInternal.remove(child) layoutInvalidated = true } @@ -659,7 +658,7 @@ open class EditablePanel @JvmOverloads constructor( absoluteY = y } - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { child.absoluteX = absoluteX + child.x + xOffset child.absoluteY = absoluteY + child.y + yOffset @@ -719,7 +718,7 @@ open class EditablePanel @JvmOverloads constructor( poseStack.popPose() } - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { child.absoluteX = absoluteX + child.x + xOffset child.absoluteY = absoluteY + child.y + yOffset @@ -739,7 +738,7 @@ open class EditablePanel @JvmOverloads constructor( if ((childrenRectHeight > height || childrenRectWidth > width || childrenRectX < 0 || childrenRectY < 0) && parent == null) { var hit = false - for (child in children) { + for (child in childrenInternal) { if (child.tickHover(mouseX, mouseY)) { hit = true } @@ -778,7 +777,7 @@ open class EditablePanel @JvmOverloads constructor( return true to this.slot } - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { val (status, slot) = child.findSlot(mouseX, mouseY) if (status) { @@ -818,7 +817,7 @@ open class EditablePanel @JvmOverloads constructor( return true to this.itemStack } - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { val (status, itemStack) = child.findItemStack(mouseX, mouseY, ignoreMouseInputLock) if (status) { @@ -853,7 +852,7 @@ open class EditablePanel @JvmOverloads constructor( return false } - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { if (child.renderTooltips(stack, mouseX, mouseY, partialTick)) { return true } @@ -950,7 +949,7 @@ open class EditablePanel @JvmOverloads constructor( var top = dockPadding.top var bottom = dockPadding.bottom - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { when (child.dock) { Dock.NONE -> {} Dock.FILL -> {} @@ -1013,7 +1012,7 @@ open class EditablePanel @JvmOverloads constructor( } } - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { if (child.dock == Dock.FILL) { val w = width - child.dockMargin.left - child.dockMargin.right - right - left val h = height - child.dockMargin.bottom - child.dockMargin.top - bottom - top @@ -1051,7 +1050,7 @@ open class EditablePanel @JvmOverloads constructor( childrenRectWidth = 0f childrenRectHeight = 0f - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { childrenRectX = childrenRectX.coerceAtMost(child.x) childrenRectY = childrenRectY.coerceAtMost(child.y) childrenRectWidth = childrenRectWidth.coerceAtLeast(child.x + child.width) @@ -1077,7 +1076,7 @@ open class EditablePanel @JvmOverloads constructor( var width = 1f var height = 1f - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { width = width.coerceAtLeast(child.x + child.width) height = height.coerceAtLeast(child.y + child.height) } @@ -1097,7 +1096,7 @@ open class EditablePanel @JvmOverloads constructor( private fun updateVisible() { val isVisible = isVisible() - for (child in children) { + for (child in childrenInternal) { val old = child.isVisible() child.visibleAsChildren = isVisible val new = child.isVisible() @@ -1111,7 +1110,7 @@ open class EditablePanel @JvmOverloads constructor( } private fun killFocusInternal() { - for (child in children) { + for (child in childrenInternal) { child.killFocusInternal() } @@ -1132,7 +1131,7 @@ open class EditablePanel @JvmOverloads constructor( return this } - for (child in children) { + for (child in childrenInternal) { val focus = child.findHierarchicalFocus() if (focus != null) { @@ -1163,7 +1162,7 @@ open class EditablePanel @JvmOverloads constructor( onHierarchicalFocusChanged(focusedAsParent, old) } - for (child in children) { + for (child in childrenInternal) { child.updateFocus() } } @@ -1225,13 +1224,13 @@ open class EditablePanel @JvmOverloads constructor( } fun fetchChildren(): List> { - return ImmutableList.copyOf(children) + return ImmutableList.copyOf(childrenInternal) } fun getUndockedChildren(): List> { val list = LinkedList>() - for (child in children) { + for (child in childrenInternal) { if (child.dock == Dock.NONE) { list.add(child) } @@ -1241,8 +1240,8 @@ open class EditablePanel @JvmOverloads constructor( } operator fun get(index: Int): EditablePanel<*>? { - if (index < 0 || index >= children.size) return null - return children[index] + if (index < 0 || index >= childrenInternal.size) return null + return childrenInternal[index] } fun isGrabbingMouseInput(): Boolean { @@ -1250,7 +1249,7 @@ open class EditablePanel @JvmOverloads constructor( return true } - for (child in children) { + for (child in childrenInternal) { if (child.isGrabbingMouseInput()) { return true } @@ -1281,7 +1280,7 @@ open class EditablePanel @JvmOverloads constructor( } fun killFocusForEverythingExcept(except: EditablePanel<*>) { - for (child in children) { + for (child in childrenInternal) { if (child !== except) { child.killFocusForEverythingExceptInner() } @@ -1289,7 +1288,7 @@ open class EditablePanel @JvmOverloads constructor( } fun killFocusForEverythingExceptInner() { - for (child in children) { + for (child in childrenInternal) { child.killFocusForEverythingExceptInner() } @@ -1307,14 +1306,14 @@ open class EditablePanel @JvmOverloads constructor( if (grabMouseInput) return mouseClickedInner(x, y, button) - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { if (child.isGrabbingMouseInput() && child.mouseClickedChecked(x, y, button)) { killFocusForEverythingExcept(child) return true } } - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { if (child.mouseClickedChecked(x, y, button)) { killFocusForEverythingExcept(child) return true @@ -1331,7 +1330,7 @@ open class EditablePanel @JvmOverloads constructor( if (acceptMouseInput && parent == null) popup() return mouseClicked(x, y, button) } else if (withinExtendedBounds(x, y)) { - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { if (child.mouseClickedChecked(x, y, button)) { killFocusForEverythingExcept(child) return true @@ -1359,13 +1358,13 @@ open class EditablePanel @JvmOverloads constructor( if (grabMouseInput) return mouseReleasedInner(x, y, button) - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { if (child.isGrabbingMouseInput() && child.mouseReleasedChecked(x, y, button)) { return true } } - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { if (child.mouseReleasedChecked(x, y, button)) { return true } @@ -1380,7 +1379,7 @@ open class EditablePanel @JvmOverloads constructor( if (isGrabbingMouseInput() || withinBounds(x, y)) { return mouseReleased(x, y, button) } else if (withinExtendedBounds(x, y)) { - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { if (child.mouseReleasedChecked(x, y, button)) { return true } @@ -1403,13 +1402,13 @@ open class EditablePanel @JvmOverloads constructor( 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)) { return true } } - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { if (child.mouseDraggedChecked(x, y, button, xDelta, yDelta)) { return true } @@ -1424,7 +1423,7 @@ open class EditablePanel @JvmOverloads constructor( if (isGrabbingMouseInput() || withinBounds(x, y)) { return mouseDragged(x, y, button, xDelta, yDelta) } else if (withinExtendedBounds(x, y)) { - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { if (child.mouseDraggedChecked(x, y, button, xDelta, yDelta)) { return true } @@ -1448,13 +1447,13 @@ open class EditablePanel @JvmOverloads constructor( if (grabMouseInput) return mouseScrolledInner(x, y, scroll) - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { if (child.isGrabbingMouseInput() && child.mouseScrolledChecked(x, y, scroll)) { return true } } - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { if (child.mouseScrolledChecked(x, y, scroll)) { return true } @@ -1469,7 +1468,7 @@ open class EditablePanel @JvmOverloads constructor( if (isGrabbingMouseInput() || withinBounds(x, y)) { return mouseScrolled(x, y, scroll) } else if (withinExtendedBounds(x, y)) { - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { if (child.mouseScrolledChecked(x, y, scroll)) { return true } @@ -1493,7 +1492,7 @@ open class EditablePanel @JvmOverloads constructor( if (isFocused) return keyPressedInternal(key, scancode, mods) - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { if (child.keyPressed(key, scancode, mods)) { return true } @@ -1516,7 +1515,7 @@ open class EditablePanel @JvmOverloads constructor( if (isFocused) return keyReleasedInternal(key, scancode, mods) - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { if (child.keyReleased(key, scancode, mods)) { return true } @@ -1539,7 +1538,7 @@ open class EditablePanel @JvmOverloads constructor( if (isFocused) return charTypedInternal(codepoint, mods) - for (child in visibleChildren) { + for (child in visibleChildrenInternal) { if (child.charTyped(codepoint, mods)) { return true } @@ -1565,7 +1564,7 @@ open class EditablePanel @JvmOverloads constructor( open fun tick() { tick++ - for (child in Array(children.size) { children[it] }) { + for (child in Array(childrenInternal.size) { childrenInternal[it] }) { child.tick() } } @@ -1588,7 +1587,7 @@ open class EditablePanel @JvmOverloads constructor( screen.removePanel(this as EditablePanel>) } - for (child in Array(children.size) { children[it] }) { + for (child in Array(childrenInternal.size) { childrenInternal[it] }) { child.remove() } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EffectListPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EffectListPanel.kt index 10314dc40..97924708c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EffectListPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EffectListPanel.kt @@ -180,7 +180,7 @@ open class EffectListPanel @JvmOverloads constructor( override fun performLayout() { super.performLayout() - val sorted = childrenView.stream().filter { it is EffectSquare }.collect(Collectors.toList()) as MutableList.EffectSquare> + val sorted = children.stream().filter { it is EffectSquare }.collect(Collectors.toList()) as MutableList.EffectSquare> sorted.sortWith { a, b -> a.effect.duration.compareTo(b.effect.duration) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/QueryUserPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/QueryUserPanel.kt index 496a8b73e..6b6a9fcc0 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/QueryUserPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/QueryUserPanel.kt @@ -61,7 +61,7 @@ open class QueryUserPanel( } } - 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() }