mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
hud: fix some text component crashes
This commit is contained in:
parent
805a1e1cde
commit
1330911287
@ -13,10 +13,23 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering.font.renderer
|
package de.bixilon.minosoft.gui.rendering.font.renderer
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.config.StaticConfiguration
|
||||||
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
|
import de.bixilon.minosoft.util.logging.LogLevels
|
||||||
|
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||||
|
|
||||||
class TextRenderInfo(
|
class TextRenderInfo(
|
||||||
val lines: MutableList<TextLineInfo> = mutableListOf(),
|
val lines: MutableList<TextLineInfo> = mutableListOf(),
|
||||||
var currentLineNumber: Int = 0,
|
var currentLineNumber: Int = 0,
|
||||||
) {
|
) {
|
||||||
val currentLine: TextLineInfo
|
val currentLine: TextLineInfo
|
||||||
get() = lines[currentLineNumber]
|
get() {
|
||||||
|
if (StaticConfiguration.DEBUG_MODE) {
|
||||||
|
if (currentLineNumber >= lines.size) {
|
||||||
|
Log.log(LogMessageType.RENDERING_GENERAL, LogLevels.WARN) { "Out of lines! Did you apply?: $lines ($currentLineNumber)" }
|
||||||
|
return TextLineInfo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lines[currentLineNumber]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import de.bixilon.minosoft.gui.rendering.gui.hud.HUDRenderer
|
|||||||
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIMeshCache
|
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIMeshCache
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
|
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
|
||||||
import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.EMPTY
|
import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.EMPTY
|
||||||
|
import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.isGreater
|
||||||
import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.isSmaller
|
import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.isSmaller
|
||||||
import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.max
|
import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.max
|
||||||
import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.min
|
import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.min
|
||||||
@ -173,12 +174,12 @@ abstract class Element(val hudRenderer: HUDRenderer) {
|
|||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
open fun silentApply(): Boolean {
|
open fun silentApply(): Boolean {
|
||||||
val maxSize = maxSize
|
val maxSize = maxSize
|
||||||
if (previousMaxSize != maxSize && (maxSize isSmaller size || maxSize isSmaller prefMaxSize)) {
|
if (previousMaxSize != maxSize && (maxSize isSmaller _size || maxSize isSmaller _prefMaxSize || (maxSize isGreater previousMaxSize && _size isSmaller _prefSize))) {
|
||||||
forceSilentApply()
|
forceSilentApply()
|
||||||
previousMaxSize = maxSize
|
previousMaxSize = maxSize
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return true
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -167,7 +167,7 @@ open class RowLayout(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.size = size
|
_size = size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -155,7 +155,6 @@ class GridLayout(hudRenderer: HUDRenderer, val grid: Vec2i) : Element(hudRendere
|
|||||||
override fun silentApply(): Boolean {
|
override fun silentApply(): Boolean {
|
||||||
// ToDo: Check
|
// ToDo: Check
|
||||||
forceSilentApply()
|
forceSilentApply()
|
||||||
applyOnlyChildren()
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ open class TextElement(
|
|||||||
|
|
||||||
this.previousMaxSize = maxSize
|
this.previousMaxSize = maxSize
|
||||||
this.cacheUpToDate = false
|
this.cacheUpToDate = false
|
||||||
this.size = size
|
_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!")
|
||||||
|
@ -108,7 +108,7 @@ class TextFlowElement(
|
|||||||
|
|
||||||
|
|
||||||
this.textSize = textSize
|
this.textSize = textSize
|
||||||
size = Vec2i(maxSize.x, visibleLines.size * Font.TOTAL_CHAR_HEIGHT)
|
_size = Vec2i(maxSize.x, visibleLines.size * Font.TOTAL_CHAR_HEIGHT)
|
||||||
background.size = size
|
background.size = size
|
||||||
this.visibleLines = visibleLines
|
this.visibleLines = visibleLines
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user