mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 01:48:04 -04:00
add chat component get and set properties
This commit is contained in:
parent
6c5781513e
commit
1f3624bbf0
@ -17,6 +17,8 @@ import com.google.gson.JsonElement
|
|||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import de.bixilon.minosoft.data.locale.minecraft.Translator
|
import de.bixilon.minosoft.data.locale.minecraft.Translator
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
|
import de.bixilon.minosoft.gui.rendering.font.text.TextGetProperties
|
||||||
|
import de.bixilon.minosoft.gui.rendering.font.text.TextSetProperties
|
||||||
import de.bixilon.minosoft.gui.rendering.hud.nodes.primitive.LabelNode
|
import de.bixilon.minosoft.gui.rendering.hud.nodes.primitive.LabelNode
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||||
import glm_.vec2.Vec2i
|
import glm_.vec2.Vec2i
|
||||||
@ -175,9 +177,9 @@ class BaseComponent : ChatComponent {
|
|||||||
return nodes
|
return nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun prepareRender(startPosition: Vec2i, offset: Vec2i, renderWindow: RenderWindow, textElement: LabelNode, z: Int, retMaxSize: Vec2i) {
|
override fun prepareRender(startPosition: Vec2i, offset: Vec2i, renderWindow: RenderWindow, textElement: LabelNode, z: Int, setProperties: TextSetProperties, getProperties: TextGetProperties) {
|
||||||
for (part in parts) {
|
for (part in parts) {
|
||||||
part.prepareRender(startPosition, offset, renderWindow, textElement, z, retMaxSize)
|
part.prepareRender(startPosition, offset, renderWindow, textElement, z, setProperties, getProperties)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,8 @@ import com.google.gson.JsonParser
|
|||||||
import com.google.gson.JsonPrimitive
|
import com.google.gson.JsonPrimitive
|
||||||
import de.bixilon.minosoft.data.locale.minecraft.Translator
|
import de.bixilon.minosoft.data.locale.minecraft.Translator
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
|
import de.bixilon.minosoft.gui.rendering.font.text.TextGetProperties
|
||||||
|
import de.bixilon.minosoft.gui.rendering.font.text.TextSetProperties
|
||||||
import de.bixilon.minosoft.gui.rendering.hud.nodes.primitive.LabelNode
|
import de.bixilon.minosoft.gui.rendering.hud.nodes.primitive.LabelNode
|
||||||
import glm_.vec2.Vec2i
|
import glm_.vec2.Vec2i
|
||||||
import javafx.collections.FXCollections
|
import javafx.collections.FXCollections
|
||||||
@ -60,7 +62,7 @@ interface ChatComponent {
|
|||||||
/**
|
/**
|
||||||
* Prepares the chat component for rendering (used in opengl)
|
* Prepares the chat component for rendering (used in opengl)
|
||||||
*/
|
*/
|
||||||
fun prepareRender(startPosition: Vec2i, offset: Vec2i, renderWindow: RenderWindow, textElement: LabelNode, z: Int, retMaxSize: Vec2i)
|
fun prepareRender(startPosition: Vec2i, offset: Vec2i, renderWindow: RenderWindow, textElement: LabelNode, z: Int, setProperties: TextSetProperties, getProperties: TextGetProperties)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@ import de.bixilon.minosoft.Minosoft
|
|||||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
import de.bixilon.minosoft.gui.rendering.font.Font
|
import de.bixilon.minosoft.gui.rendering.font.Font
|
||||||
|
import de.bixilon.minosoft.gui.rendering.font.text.TextGetProperties
|
||||||
|
import de.bixilon.minosoft.gui.rendering.font.text.TextSetProperties
|
||||||
import de.bixilon.minosoft.gui.rendering.hud.nodes.primitive.ImageNode
|
import de.bixilon.minosoft.gui.rendering.hud.nodes.primitive.ImageNode
|
||||||
import de.bixilon.minosoft.gui.rendering.hud.nodes.primitive.LabelNode
|
import de.bixilon.minosoft.gui.rendering.hud.nodes.primitive.LabelNode
|
||||||
import de.bixilon.minosoft.gui.rendering.hud.nodes.properties.NodeSizing
|
import de.bixilon.minosoft.gui.rendering.hud.nodes.properties.NodeSizing
|
||||||
@ -161,7 +163,7 @@ open class TextComponent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun prepareRender(startPosition: Vec2i, offset: Vec2i, renderWindow: RenderWindow, textElement: LabelNode, z: Int, retMaxSize: Vec2i) {
|
override fun prepareRender(startPosition: Vec2i, offset: Vec2i, renderWindow: RenderWindow, textElement: LabelNode, z: Int, setProperties: TextSetProperties, getProperties: TextGetProperties) {
|
||||||
val color = this.color ?: ChatColors.WHITE
|
val color = this.color ?: ChatColors.WHITE
|
||||||
|
|
||||||
|
|
||||||
@ -175,7 +177,7 @@ open class TextComponent(
|
|||||||
offset.x = 0
|
offset.x = 0
|
||||||
val yOffset = Font.CHAR_HEIGHT + RenderConstants.TEXT_LINE_PADDING
|
val yOffset = Font.CHAR_HEIGHT + RenderConstants.TEXT_LINE_PADDING
|
||||||
offset.y += yOffset
|
offset.y += yOffset
|
||||||
retMaxSize.y += yOffset
|
getProperties.size.y += yOffset
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
val fontChar = renderWindow.font.getChar(char)
|
val fontChar = renderWindow.font.getChar(char)
|
||||||
@ -186,13 +188,14 @@ open class TextComponent(
|
|||||||
|
|
||||||
// ad spacer between chars
|
// ad spacer between chars
|
||||||
offset.x += scaledWidth + Font.SPACE_BETWEEN_CHARS
|
offset.x += scaledWidth + Font.SPACE_BETWEEN_CHARS
|
||||||
if (offset.x > retMaxSize.x) {
|
if (offset.x > getProperties.size.x) {
|
||||||
retMaxSize.x += scaledWidth + Font.SPACE_BETWEEN_CHARS
|
getProperties.size.x += scaledWidth + Font.SPACE_BETWEEN_CHARS
|
||||||
}
|
}
|
||||||
if (offset.y >= retMaxSize.y) {
|
if (offset.y >= getProperties.size.y) {
|
||||||
if (retMaxSize.y < fontChar.height) {
|
if (getProperties.size.y < fontChar.height) {
|
||||||
retMaxSize.y = fontChar.height
|
getProperties.size.y = fontChar.height
|
||||||
}
|
}
|
||||||
|
getProperties.lines = (offset.y + Font.CHAR_HEIGHT) / (Font.CHAR_HEIGHT + RenderConstants.TEXT_LINE_PADDING)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ object RenderConstants {
|
|||||||
val TEXT_BACKGROUND_COLOR = RGBColor(0, 0, 0, 80)
|
val TEXT_BACKGROUND_COLOR = RGBColor(0, 0, 0, 80)
|
||||||
|
|
||||||
const val TEXT_LINE_PADDING = 0
|
const val TEXT_LINE_PADDING = 0
|
||||||
|
val WORD_SEPARATORS = arrayOf(' ', '.', ',', '!', '-', '?')
|
||||||
|
|
||||||
const val CHUNK_SECTIONS_PER_MESH = 1
|
const val CHUNK_SECTIONS_PER_MESH = 1
|
||||||
|
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2021 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.gui.rendering.font.text
|
||||||
|
|
||||||
|
import glm_.vec2.Vec2i
|
||||||
|
|
||||||
|
class TextGetProperties {
|
||||||
|
val size: Vec2i = Vec2i(0, 0)
|
||||||
|
var lines: Int = 0
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2021 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.gui.rendering.font.text
|
||||||
|
|
||||||
|
data class TextSetProperties(
|
||||||
|
/**
|
||||||
|
* Wraps after chars.
|
||||||
|
*/
|
||||||
|
var hardWrap: Int = Int.MAX_VALUE,
|
||||||
|
/**
|
||||||
|
* Wraps after words, or better: RenderConstants.WORD_SEPARATORS.
|
||||||
|
*/
|
||||||
|
var softWrap: Int = Int.MAX_VALUE,
|
||||||
|
)
|
@ -29,7 +29,7 @@ open class TextField(
|
|||||||
) : AbsoluteLayout(renderWindow), KeyConsumer, MouseConsumer {
|
) : AbsoluteLayout(renderWindow), KeyConsumer, MouseConsumer {
|
||||||
override var focused: Boolean = true
|
override var focused: Boolean = true
|
||||||
private var textBuilder: StringBuilder = StringBuilder(defaultText)
|
private var textBuilder: StringBuilder = StringBuilder(defaultText)
|
||||||
private val textElement = LabelNode(renderWindow, sizing = sizing, text = ChatComponent.valueOf(raw = text), background = false)
|
val textElement = LabelNode(renderWindow, sizing = sizing, text = ChatComponent.valueOf(raw = text), background = false)
|
||||||
private var position = text.length
|
private var position = text.length
|
||||||
|
|
||||||
var text: String
|
var text: String
|
||||||
|
@ -50,7 +50,7 @@ class ChatBoxHUDElement(hudRenderer: HUDRenderer) : HUDElement(hudRenderer), Scr
|
|||||||
|
|
||||||
override fun onScreenResize(screenDimensions: Vec2i) {
|
override fun onScreenResize(screenDimensions: Vec2i) {
|
||||||
layout.sizing.minSize.x = screenDimensions.x
|
layout.sizing.minSize.x = screenDimensions.x
|
||||||
inputFieldBackground.sizing.forceSize = Vec2i(screenDimensions.x - 2, MMath.clamp(inputField.sizing.currentSize.y, Font.CHAR_HEIGHT, Int.MAX_VALUE)) // 2 pixels for margin
|
inputFieldBackground.sizing.forceSize = Vec2i(screenDimensions.x - 2, MMath.clamp(inputField.textElement.getProperties.lines, 1, Int.MAX_VALUE) * (Font.CHAR_HEIGHT + RenderConstants.TEXT_LINE_PADDING)) // 2 pixels for margin
|
||||||
layout.sizing.maxSize.x = screenDimensions.x
|
layout.sizing.maxSize.x = screenDimensions.x
|
||||||
layout.sizing.validate()
|
layout.sizing.validate()
|
||||||
layout.apply()
|
layout.apply()
|
||||||
|
@ -18,6 +18,8 @@ import de.bixilon.minosoft.data.text.RGBColor
|
|||||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
import de.bixilon.minosoft.gui.rendering.font.Font
|
import de.bixilon.minosoft.gui.rendering.font.Font
|
||||||
|
import de.bixilon.minosoft.gui.rendering.font.text.TextGetProperties
|
||||||
|
import de.bixilon.minosoft.gui.rendering.font.text.TextSetProperties
|
||||||
import de.bixilon.minosoft.gui.rendering.hud.nodes.layout.AbsoluteLayout
|
import de.bixilon.minosoft.gui.rendering.hud.nodes.layout.AbsoluteLayout
|
||||||
import de.bixilon.minosoft.gui.rendering.hud.nodes.properties.NodeSizing
|
import de.bixilon.minosoft.gui.rendering.hud.nodes.properties.NodeSizing
|
||||||
import glm_.vec2.Vec2i
|
import glm_.vec2.Vec2i
|
||||||
@ -27,8 +29,11 @@ class LabelNode(
|
|||||||
sizing: NodeSizing = NodeSizing(minSize = Vec2i(0, Font.CHAR_HEIGHT)),
|
sizing: NodeSizing = NodeSizing(minSize = Vec2i(0, Font.CHAR_HEIGHT)),
|
||||||
text: ChatComponent = ChatComponent.valueOf(raw = ""),
|
text: ChatComponent = ChatComponent.valueOf(raw = ""),
|
||||||
var background: Boolean = true,
|
var background: Boolean = true,
|
||||||
|
val setProperties: TextSetProperties = TextSetProperties(),
|
||||||
) : AbsoluteLayout(renderWindow, sizing) {
|
) : AbsoluteLayout(renderWindow, sizing) {
|
||||||
private var _text: ChatComponent = text
|
private var _text: ChatComponent = text
|
||||||
|
var getProperties = TextGetProperties()
|
||||||
|
private set
|
||||||
|
|
||||||
var text: ChatComponent
|
var text: ChatComponent
|
||||||
get() = _text
|
get() = _text
|
||||||
@ -50,12 +55,12 @@ class LabelNode(
|
|||||||
|
|
||||||
private fun prepare() {
|
private fun prepare() {
|
||||||
clearChildren()
|
clearChildren()
|
||||||
val textSize = Vec2i(0, 0)
|
getProperties = TextGetProperties()
|
||||||
text.prepareRender(Vec2i(1, 1), Vec2i(), renderWindow, this, 1, textSize)
|
text.prepareRender(Vec2i(1, 1), Vec2i(), renderWindow, this, 1, setProperties, getProperties)
|
||||||
apply()
|
apply()
|
||||||
|
|
||||||
if (background) {
|
if (background) {
|
||||||
drawBackground(textSize + 1)
|
drawBackground(getProperties.size + 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user