From 4308a5354e6bd362b8ef0081f7198ecb07a324c3 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Sat, 16 Oct 2021 13:48:13 +0200 Subject: [PATCH] fix more hud bugs --- .../minosoft/data/entities/Rotation.kt | 20 ------------------- .../gui/rendering/gui/elements/Element.kt | 4 ++-- .../gui/elements/layout/RowLayout.kt | 3 +++ .../gui/elements/layout/grid/GridCell.kt | 14 ++++++++++++- .../gui/elements/layout/grid/GridLayout.kt | 5 +++-- .../gui/elements/text/TextElement.kt | 6 +++++- .../elements/hotbar/HotbarHealthElement.kt | 2 +- 7 files changed, 27 insertions(+), 27 deletions(-) delete mode 100644 src/main/java/de/bixilon/minosoft/data/entities/Rotation.kt diff --git a/src/main/java/de/bixilon/minosoft/data/entities/Rotation.kt b/src/main/java/de/bixilon/minosoft/data/entities/Rotation.kt deleted file mode 100644 index 998d81f36..000000000 --- a/src/main/java/de/bixilon/minosoft/data/entities/Rotation.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020 Moritz Zwerger - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. If not, see . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ -package de.bixilon.minosoft.data.entities - -data class Rotation(val yaw: Int, val pitch: Int) { - - override fun toString(): String { - return "(yaw=$yaw, pitch=$pitch)" - } -} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/Element.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/Element.kt index e7d14e290..47f11b7ad 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/Element.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/Element.kt @@ -47,7 +47,7 @@ abstract class Element(val hudRenderer: HUDRenderer) { protected open var _prefSize: Vec2i = Vec2i.EMPTY /** - * If maxSize was infinity, what size would the element have? + * If maxSize was infinity, what size would the element have? (Excluded margin!) */ open var prefSize: Vec2i get() = _prefSize @@ -185,7 +185,7 @@ abstract class Element(val hudRenderer: HUDRenderer) { /** * Called by the child of an element (probably a layout), because the child changed a relevant property (probably size) */ - open fun onChildChange(child: Element?) { + open fun onChildChange(child: Element) { parent?.onChildChange(this) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/layout/RowLayout.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/layout/RowLayout.kt index d6372416b..cc45ae42b 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/layout/RowLayout.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/layout/RowLayout.kt @@ -170,6 +170,9 @@ open class RowLayout( _size = size } + override fun onChildChange(child: Element) { + forceApply() // ToDo (Performance): Check if the size, prefSize or whatever changed + } override fun tick() { super.tick() diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/layout/grid/GridCell.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/layout/grid/GridCell.kt index de8e92874..c82aa882c 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/layout/grid/GridCell.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/layout/grid/GridCell.kt @@ -24,7 +24,7 @@ class GridCell( private val columnConstraint: GridColumnConstraint, private val rowConstraint: GridRowConstraint, private val child: Element, - override var parent: Element?, + parent: Element?, ) : Element(hudRenderer) { override var cacheUpToDate: Boolean by child::cacheUpToDate override var cacheEnabled: Boolean by child::cacheEnabled @@ -34,6 +34,10 @@ class GridCell( override var margin: Vec4i by child::margin override var prefSize: Vec2i by child::prefSize + init { + _parent = parent + } + override val maxSize: Vec2i get() { val maxSize = Vec2i(super.maxSize) @@ -72,4 +76,12 @@ class GridCell( override fun apply() { child.apply() } + + override fun forceApply() { + child.forceApply() + } + + override fun onChildChange(child: Element) { + super.onChildChange(this) + } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/layout/grid/GridLayout.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/layout/grid/GridLayout.kt index b6af2da78..a79744452 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/layout/grid/GridLayout.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/layout/grid/GridLayout.kt @@ -17,6 +17,7 @@ import de.bixilon.minosoft.gui.rendering.gui.elements.Element import de.bixilon.minosoft.gui.rendering.gui.elements.HorizontalAlignments.Companion.getOffset import de.bixilon.minosoft.gui.rendering.gui.hud.HUDRenderer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer +import de.bixilon.minosoft.gui.rendering.util.vec.Vec4Util.horizontal import de.bixilon.minosoft.gui.rendering.util.vec.Vec4Util.offset import glm_.vec2.Vec2i import java.lang.Integer.min @@ -67,7 +68,7 @@ class GridLayout(hudRenderer: HUDRenderer, val grid: Vec2i) : Element(hudRendere for (x in 0 until grid.x) { for (y in 0 until grid.y) { val child = children[x][y] ?: continue - width[x] = min(max(width[x], child.prefSize.x), columnConstraints[x].maxWidth) + width[x] = min(max(width[x], child.prefSize.x + child.margin.horizontal), columnConstraints[x].maxWidth) } } @@ -166,7 +167,7 @@ class GridLayout(hudRenderer: HUDRenderer, val grid: Vec2i) : Element(hudRendere } } - override fun onChildChange(child: Element?) { + override fun onChildChange(child: Element) { apply() parent?.onChildChange(this) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextElement.kt index a5490a2a3..b66765a37 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextElement.kt @@ -66,6 +66,10 @@ open class TextElement( override fun forceSilentApply() { val size = Vec2i.EMPTY + if (textComponent.message.contains("pitch=")) { + val a = maxSize + var b = 1 + } if (!emptyMessage) { val renderInfo = TextRenderInfo() ChatComponentRenderer.render(Vec2i.EMPTY, Vec2i.EMPTY, size, 0, this, fontAlignment, renderWindow, null, renderInfo, textComponent) @@ -77,7 +81,7 @@ open class TextElement( _size = size } - override fun onChildChange(child: Element?) = error("A TextElement can not have a child!") + override fun onChildChange(child: Element) = error("A TextElement can not have a child!") override fun forceRender(offset: Vec2i, z: Int, consumer: GUIVertexConsumer): Int { if (emptyMessage) { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarHealthElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarHealthElement.kt index 7d98a50a1..559194782 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarHealthElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarHealthElement.kt @@ -217,7 +217,7 @@ class HotbarHealthElement(hudRenderer: HUDRenderer) : Element(hudRenderer) { totalMaxHearts = (totalMaxHealth / 2).ceil rows = totalMaxHearts / HEARTS_PER_ROW - if (totalMaxHearts % HP_PER_ROW != 0) { + if (totalMaxHearts % HEARTS_PER_ROW != 0) { rows++ }