text rendering: fix max size[y] checking, chat: force 3 lines of text

This commit is contained in:
Bixilon 2022-02-04 15:42:22 +01:00
parent af49b9b2cb
commit 4dfcfc1b61
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 9 additions and 9 deletions

View File

@ -61,7 +61,7 @@ object TextComponentRenderer : ChatComponentRenderer<TextComponent> {
fun addY(height: Int): Boolean { fun addY(height: Int): Boolean {
val nextY = offset.y + height val nextY = offset.y + height
val nextSizeY = nextY - initialOffset.y + renderInfo.charHeight // add initial height for chars + end margin val nextSizeY = nextY - initialOffset.y + renderInfo.charHeight // add initial height for chars + end margin
if (nextSizeY >= elementMaxSize.y) { if (nextSizeY > elementMaxSize.y) {
return true return true
} }
offset.y = nextY offset.y = nextY

View File

@ -113,8 +113,8 @@ open class TextElement(
init { init {
this.parent = parent this.parent = parent
this.chatComponent = ChatComponent.of(text)
this.noBorder = noBorder this.noBorder = noBorder
this.chatComponent = ChatComponent.of(text)
} }
override fun forceSilentApply() { override fun forceSilentApply() {

View File

@ -19,6 +19,7 @@ import de.bixilon.minosoft.config.key.KeyCodes
import de.bixilon.minosoft.config.profile.delegate.watcher.SimpleProfileDelegateWatcher.Companion.profileWatchRendering import de.bixilon.minosoft.config.profile.delegate.watcher.SimpleProfileDelegateWatcher.Companion.profileWatchRendering
import de.bixilon.minosoft.data.ChatTextPositions import de.bixilon.minosoft.data.ChatTextPositions
import de.bixilon.minosoft.data.registries.ResourceLocation import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.gui.rendering.font.Font
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
import de.bixilon.minosoft.gui.rendering.gui.elements.Element import de.bixilon.minosoft.gui.rendering.gui.elements.Element
import de.bixilon.minosoft.gui.rendering.gui.elements.LayoutedElement import de.bixilon.minosoft.gui.rendering.gui.elements.LayoutedElement
@ -83,12 +84,11 @@ class ChatElement(guiRenderer: GUIRenderer) : Element(guiRenderer), LayoutedElem
messages += it.message messages += it.message
}) })
renderWindow.inputHandler.registerKeyCallback("minosoft:open_chat".toResourceLocation(), renderWindow.inputHandler.registerKeyCallback("minosoft:open_chat".toResourceLocation(), KeyBinding(
KeyBinding( mapOf(
mapOf( KeyAction.PRESS to setOf(KeyCodes.KEY_T),
KeyAction.PRESS to setOf(KeyCodes.KEY_T), ),
), )) { guiRenderer.gui.open(ChatElement) }
)) { guiRenderer.gui.open(ChatElement) }
} }
override fun forceRender(offset: Vec2i, z: Int, consumer: GUIVertexConsumer, options: GUIVertexOptions?): Int { override fun forceRender(offset: Vec2i, z: Int, consumer: GUIVertexConsumer, options: GUIVertexOptions?): Int {
@ -150,7 +150,7 @@ class ChatElement(guiRenderer: GUIRenderer) : Element(guiRenderer), LayoutedElem
companion object : HUDBuilder<LayoutedGUIElement<ChatElement>>, GUIBuilder<LayoutedGUIElement<ChatElement>> { companion object : HUDBuilder<LayoutedGUIElement<ChatElement>>, GUIBuilder<LayoutedGUIElement<ChatElement>> {
override val RESOURCE_LOCATION: ResourceLocation = "minosoft:chat_hud".toResourceLocation() override val RESOURCE_LOCATION: ResourceLocation = "minosoft:chat_hud".toResourceLocation()
private const val CHAT_INPUT_HEIGHT = 30 private const val CHAT_INPUT_HEIGHT = Font.TOTAL_CHAR_HEIGHT * 3 + Font.CHAR_MARGIN * 2
private const val CHAT_INPUT_MARGIN = 2 private const val CHAT_INPUT_MARGIN = 2
override fun build(guiRenderer: GUIRenderer): LayoutedGUIElement<ChatElement> { override fun build(guiRenderer: GUIRenderer): LayoutedGUIElement<ChatElement> {