empty chat component, various performance improvements

This commit is contained in:
Bixilon 2022-05-11 20:35:28 +02:00
parent fcb7acb1af
commit 2d5fb3cb1d
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 40 additions and 2 deletions

View File

@ -81,7 +81,7 @@ interface ChatComponent {
fun cut(length: Int)
companion object {
val EMPTY = TextComponent("")
val EMPTY = EmptyComponent
@JvmOverloads
fun of(raw: Any? = null, translator: Translator? = null, parent: TextComponent? = null, ignoreJson: Boolean = false, restrictedMode: Boolean = false): ChatComponent {

View File

@ -0,0 +1,33 @@
/*
* Minosoft
* Copyright (C) 2020-2022 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.text
import javafx.collections.ObservableList
import javafx.scene.Node
object EmptyComponent : ChatComponent {
override val ansiColoredMessage: String = ""
override val legacyText: String = ""
override val message: String = ""
override fun getJavaFXText(nodes: ObservableList<Node>): ObservableList<Node> = nodes
override fun applyDefaultColor(color: RGBColor) = Unit
override fun getTextAt(pointer: Int): TextComponent = throw IllegalArgumentException()
override val length: Int get() = 0
override fun cut(length: Int) = Unit
}

View File

@ -18,6 +18,7 @@ import de.bixilon.kutil.cast.CastUtil.unsafeNull
import de.bixilon.kutil.primitive.BooleanUtil.decide
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.data.text.EmptyComponent
import de.bixilon.minosoft.data.text.RGBColor
import de.bixilon.minosoft.data.text.TextComponent
import de.bixilon.minosoft.gui.rendering.RenderConstants
@ -111,7 +112,7 @@ open class TextElement(
return
}
field = value
emptyMessage = value.message.isEmpty()
emptyMessage = value is EmptyComponent || value.message.isEmpty()
val prefSize = Vec2i.EMPTY
if (!emptyMessage) {
val renderInfo = TextRenderInfo(

View File

@ -32,6 +32,7 @@ import de.bixilon.minosoft.util.KUtil.toResourceLocation
class BreakProgressHUDElement(guiRenderer: GUIRenderer) : Element(guiRenderer), LayoutedElement, Drawable {
private val textElement = TextElement(guiRenderer, "").apply { parent = this@BreakProgressHUDElement }
private val breakInteractionHandler = guiRenderer.renderWindow.inputHandler.interactionManager.`break`
private val previousProgress = -1.0
override val layoutOffset: Vec2i
get() = Vec2i((guiRenderer.scaledSize.x / 2) + CrosshairHUDElement.CROSSHAIR_SIZE / 2 + 5, (guiRenderer.scaledSize.y - textElement.size.y) / 2)
@ -41,6 +42,9 @@ class BreakProgressHUDElement(guiRenderer: GUIRenderer) : Element(guiRenderer),
override fun draw() {
val breakProgress = breakInteractionHandler.breakProgress
if (this.previousProgress == breakProgress) {
return
}
if (breakProgress <= 0 || breakProgress >= 1.0) {
textElement.text = ChatComponent.EMPTY
this.percent = -1