parent
a7b09441c5
commit
44da2c4b11
@ -4,6 +4,7 @@ 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
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
@ -74,7 +75,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
if (field === value)
|
||||
return
|
||||
|
||||
val set = ObjectArraySet<EditablePanel<*>>()
|
||||
val set = ReferenceArraySet<EditablePanel<*>>()
|
||||
set.add(this)
|
||||
var parent = value
|
||||
|
||||
@ -169,7 +170,8 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
var dockedHeight: Float = 0f
|
||||
private set
|
||||
|
||||
protected val children = ArrayList<EditablePanel<*>>()
|
||||
private val children = ArrayList<EditablePanel<*>>()
|
||||
private val visibleChildren = ArrayList<EditablePanel<*>>()
|
||||
val childrenView: List<EditablePanel<*>> = Collections.unmodifiableList(children)
|
||||
|
||||
var layoutInvalidated = true
|
||||
@ -189,17 +191,26 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
|
||||
if (old != new) {
|
||||
visibilityChanges(new, old)
|
||||
parent?.layoutInvalidated = true
|
||||
layoutInvalidated = true
|
||||
val visibleChildrenParent = parent?.visibleChildren
|
||||
|
||||
if (new) {
|
||||
killFocus()
|
||||
|
||||
if (visibleChildrenParent?.contains(this) == false) {
|
||||
visibleChildrenParent.add(this)
|
||||
parent?.layoutInvalidated = true
|
||||
}
|
||||
} else {
|
||||
if (visibleChildrenParent?.contains(this) == true) {
|
||||
visibleChildrenParent.remove(this)
|
||||
parent?.layoutInvalidated = true
|
||||
}
|
||||
}
|
||||
|
||||
updateVisible()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Позволяет смещать потомков на эту координату
|
||||
var xOffset = 0f
|
||||
@ -506,8 +517,8 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
result.add(Rect2f(absoluteX, absoluteY, width, height))
|
||||
}
|
||||
|
||||
for (children in children) {
|
||||
if ((children.isOutsideOfParent || !isObstructing) && children.isVisible()) {
|
||||
for (children in visibleChildren) {
|
||||
if (children.isOutsideOfParent || !isObstructing) {
|
||||
result.addAll(children.calculateAbsoluteObstructingRectangles())
|
||||
}
|
||||
}
|
||||
@ -585,17 +596,31 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
private fun onParent(child: EditablePanel<*>) {
|
||||
if (children.contains(child)) throw IllegalStateException("Already containing $child")
|
||||
children.add(child)
|
||||
|
||||
if (child.visible) {
|
||||
visibleChildren.add(child)
|
||||
layoutInvalidated = true
|
||||
}
|
||||
|
||||
if (child.isVisible() != isVisible()) {
|
||||
updateVisible()
|
||||
}
|
||||
}
|
||||
|
||||
private fun onUnParent(child: EditablePanel<*>) {
|
||||
val indexOf = children.indexOf(child)
|
||||
if (indexOf == -1) throw IllegalStateException("Already not containing $child")
|
||||
children.removeAt(indexOf)
|
||||
|
||||
if (child.visible) {
|
||||
visibleChildren.remove(child)
|
||||
layoutInvalidated = true
|
||||
}
|
||||
|
||||
if (child.isVisible() != isVisible()) {
|
||||
updateVisible()
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {}
|
||||
protected open fun innerRenderTooltips(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float): Boolean {
|
||||
@ -634,15 +659,13 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
absoluteY = y
|
||||
}
|
||||
|
||||
for (child in children) {
|
||||
if (child.isVisible()) {
|
||||
for (child in visibleChildren) {
|
||||
child.absoluteX = absoluteX + child.x + xOffset
|
||||
child.absoluteY = absoluteY + child.y + yOffset
|
||||
|
||||
child.updateAbsoluteCoordinates()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun render(poseStack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||
if (!isVisible()) {
|
||||
@ -696,14 +719,12 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
poseStack.popPose()
|
||||
}
|
||||
|
||||
for (child in children) {
|
||||
if (child.isVisible()) {
|
||||
for (child in visibleChildren) {
|
||||
child.absoluteX = absoluteX + child.x + xOffset
|
||||
child.absoluteY = absoluteY + child.y + yOffset
|
||||
|
||||
child.render(poseStack, mouseX, mouseY, partialTick)
|
||||
}
|
||||
}
|
||||
|
||||
if (scissor) {
|
||||
popScissorRect()
|
||||
@ -757,7 +778,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
return true to this.slot
|
||||
}
|
||||
|
||||
for (child in children) {
|
||||
for (child in visibleChildren) {
|
||||
val (status, slot) = child.findSlot(mouseX, mouseY)
|
||||
|
||||
if (status) {
|
||||
@ -797,7 +818,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
return true to this.itemStack
|
||||
}
|
||||
|
||||
for (child in children) {
|
||||
for (child in visibleChildren) {
|
||||
val (status, itemStack) = child.findItemStack(mouseX, mouseY, ignoreMouseInputLock)
|
||||
|
||||
if (status) {
|
||||
@ -832,8 +853,8 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
return false
|
||||
}
|
||||
|
||||
for (child in children) {
|
||||
if (child.isVisible() && child.renderTooltips(stack, mouseX, mouseY, partialTick)) {
|
||||
for (child in visibleChildren) {
|
||||
if (child.renderTooltips(stack, mouseX, mouseY, partialTick)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -929,8 +950,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
var top = dockPadding.top
|
||||
var bottom = dockPadding.bottom
|
||||
|
||||
for (child in children) {
|
||||
if (child.isVisible()) {
|
||||
for (child in visibleChildren) {
|
||||
when (child.dock) {
|
||||
Dock.NONE -> {}
|
||||
Dock.FILL -> {}
|
||||
@ -992,10 +1012,9 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (child in children) {
|
||||
if (child.isVisible() && child.dock == Dock.FILL) {
|
||||
for (child in visibleChildren) {
|
||||
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
|
||||
|
||||
@ -1032,14 +1051,12 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
childrenRectWidth = 0f
|
||||
childrenRectHeight = 0f
|
||||
|
||||
for (child in children) {
|
||||
if (child.isVisible()) {
|
||||
for (child in visibleChildren) {
|
||||
childrenRectX = childrenRectX.coerceAtMost(child.x)
|
||||
childrenRectY = childrenRectY.coerceAtMost(child.y)
|
||||
childrenRectWidth = childrenRectWidth.coerceAtLeast(child.x + child.width)
|
||||
childrenRectHeight = childrenRectHeight.coerceAtLeast(child.y + child.height)
|
||||
}
|
||||
}
|
||||
|
||||
childrenRectX = childrenRectX.coerceAtMost(childrenRectWidth)
|
||||
childrenRectY = childrenRectY.coerceAtMost(childrenRectHeight)
|
||||
@ -1060,12 +1077,10 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
var width = 1f
|
||||
var height = 1f
|
||||
|
||||
for (child in children) {
|
||||
if (child.isVisible()) {
|
||||
for (child in visibleChildren) {
|
||||
width = width.coerceAtLeast(child.x + child.width)
|
||||
height = height.coerceAtLeast(child.y + child.height)
|
||||
}
|
||||
}
|
||||
|
||||
this.width = width
|
||||
this.height = height
|
||||
@ -1080,9 +1095,11 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
private fun updateVisible() {
|
||||
val isVisible = isVisible()
|
||||
|
||||
for (child in children) {
|
||||
val old = child.isVisible()
|
||||
child.visibleAsChildren = isVisible()
|
||||
child.visibleAsChildren = isVisible
|
||||
val new = child.isVisible()
|
||||
|
||||
if (old != new) {
|
||||
@ -1290,14 +1307,14 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
|
||||
if (grabMouseInput) return mouseClickedInner(x, y, button)
|
||||
|
||||
for (child in children) {
|
||||
for (child in visibleChildren) {
|
||||
if (child.isGrabbingMouseInput() && child.mouseClickedChecked(x, y, button)) {
|
||||
killFocusForEverythingExcept(child)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for (child in children) {
|
||||
for (child in visibleChildren) {
|
||||
if (child.mouseClickedChecked(x, y, button)) {
|
||||
killFocusForEverythingExcept(child)
|
||||
return true
|
||||
@ -1314,7 +1331,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
if (acceptMouseInput && parent == null) popup()
|
||||
return mouseClicked(x, y, button)
|
||||
} else if (withinExtendedBounds(x, y)) {
|
||||
for (child in children) {
|
||||
for (child in visibleChildren) {
|
||||
if (child.mouseClickedChecked(x, y, button)) {
|
||||
killFocusForEverythingExcept(child)
|
||||
return true
|
||||
@ -1342,13 +1359,13 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
|
||||
if (grabMouseInput) return mouseReleasedInner(x, y, button)
|
||||
|
||||
for (child in children) {
|
||||
for (child in visibleChildren) {
|
||||
if (child.isGrabbingMouseInput() && child.mouseReleasedChecked(x, y, button)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for (child in children) {
|
||||
for (child in visibleChildren) {
|
||||
if (child.mouseReleasedChecked(x, y, button)) {
|
||||
return true
|
||||
}
|
||||
@ -1363,7 +1380,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
if (isGrabbingMouseInput() || withinBounds(x, y)) {
|
||||
return mouseReleased(x, y, button)
|
||||
} else if (withinExtendedBounds(x, y)) {
|
||||
for (child in children) {
|
||||
for (child in visibleChildren) {
|
||||
if (child.mouseReleasedChecked(x, y, button)) {
|
||||
return true
|
||||
}
|
||||
@ -1386,13 +1403,13 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
|
||||
if (grabMouseInput) return mouseDraggedInner(x, y, button, xDelta, yDelta)
|
||||
|
||||
for (child in children) {
|
||||
for (child in visibleChildren) {
|
||||
if (child.isGrabbingMouseInput() && child.mouseDraggedChecked(x, y, button, xDelta, yDelta)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for (child in children) {
|
||||
for (child in visibleChildren) {
|
||||
if (child.mouseDraggedChecked(x, y, button, xDelta, yDelta)) {
|
||||
return true
|
||||
}
|
||||
@ -1407,7 +1424,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
if (isGrabbingMouseInput() || withinBounds(x, y)) {
|
||||
return mouseDragged(x, y, button, xDelta, yDelta)
|
||||
} else if (withinExtendedBounds(x, y)) {
|
||||
for (child in children) {
|
||||
for (child in visibleChildren) {
|
||||
if (child.mouseDraggedChecked(x, y, button, xDelta, yDelta)) {
|
||||
return true
|
||||
}
|
||||
@ -1431,13 +1448,13 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
|
||||
if (grabMouseInput) return mouseScrolledInner(x, y, scroll)
|
||||
|
||||
for (child in children) {
|
||||
for (child in visibleChildren) {
|
||||
if (child.isGrabbingMouseInput() && child.mouseScrolledChecked(x, y, scroll)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for (child in children) {
|
||||
for (child in visibleChildren) {
|
||||
if (child.mouseScrolledChecked(x, y, scroll)) {
|
||||
return true
|
||||
}
|
||||
@ -1452,7 +1469,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
if (isGrabbingMouseInput() || withinBounds(x, y)) {
|
||||
return mouseScrolled(x, y, scroll)
|
||||
} else if (withinExtendedBounds(x, y)) {
|
||||
for (child in children) {
|
||||
for (child in visibleChildren) {
|
||||
if (child.mouseScrolledChecked(x, y, scroll)) {
|
||||
return true
|
||||
}
|
||||
@ -1476,7 +1493,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
|
||||
if (isFocused) return keyPressedInternal(key, scancode, mods)
|
||||
|
||||
for (child in children) {
|
||||
for (child in visibleChildren) {
|
||||
if (child.keyPressed(key, scancode, mods)) {
|
||||
return true
|
||||
}
|
||||
@ -1499,7 +1516,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
|
||||
if (isFocused) return keyReleasedInternal(key, scancode, mods)
|
||||
|
||||
for (child in children) {
|
||||
for (child in visibleChildren) {
|
||||
if (child.keyReleased(key, scancode, mods)) {
|
||||
return true
|
||||
}
|
||||
@ -1522,7 +1539,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
|
||||
if (isFocused) return charTypedInternal(codepoint, mods)
|
||||
|
||||
for (child in children) {
|
||||
for (child in visibleChildren) {
|
||||
if (child.charTyped(codepoint, mods)) {
|
||||
return true
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ open class EffectListPanel<out S : Screen> @JvmOverloads constructor(
|
||||
override fun performLayout() {
|
||||
super.performLayout()
|
||||
|
||||
val sorted = children.stream().filter { it is EffectSquare }.collect(Collectors.toList()) as MutableList<EffectListPanel<S>.EffectSquare>
|
||||
val sorted = childrenView.stream().filter { it is EffectSquare }.collect(Collectors.toList()) as MutableList<EffectListPanel<S>.EffectSquare>
|
||||
|
||||
sorted.sortWith { a, b ->
|
||||
a.effect.duration.compareTo(b.effect.duration)
|
||||
|
Loading…
Reference in New Issue
Block a user