fix more hud bugs

This commit is contained in:
Bixilon 2021-10-16 13:48:13 +02:00
parent 7dbb07e2de
commit 4308a5354e
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
7 changed files with 27 additions and 27 deletions

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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)"
}
}

View File

@ -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)
}

View File

@ -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()

View File

@ -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)
}
}

View File

@ -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)
}

View File

@ -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) {

View File

@ -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++
}