mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
hud: WIP: text
This commit is contained in:
parent
2296b4ef43
commit
03f6683697
@ -21,6 +21,7 @@ import de.bixilon.minosoft.gui.rendering.hud.elements.position.HUDElementVec2
|
||||
import glm_.mat4x4.Mat4
|
||||
|
||||
abstract class HUDElement(
|
||||
json: Map<String, Any>,
|
||||
val position: HUDElementVec2,
|
||||
val positionAnchor: HUDElementPositionAnchors,
|
||||
val content: ResourceLocation,
|
||||
|
@ -15,6 +15,7 @@ object HUDElementSerializer {
|
||||
val positionAnchor = HUDElementPositionAnchors.HUD_ELEMENT_POSITION_ATTACHMENTS_MAPPING[ResourceLocation((json["position"] as Map<*,*>)["location"].toString())]!!
|
||||
val size = HUDElementVec2.deserialize(json["size"])
|
||||
return HUD_ELEMENT_TYPES[ResourceLocation(json["type"].toString())]?.constructors?.first()?.call(
|
||||
json,
|
||||
position,
|
||||
positionAnchor,
|
||||
ResourceLocation(json["content"].toString()),
|
||||
|
@ -16,13 +16,14 @@ import glm_.vec4.Vec4
|
||||
import glm_.vec4.swizzle.xy
|
||||
|
||||
class HUDImageElement(
|
||||
json: Map<String, Any>,
|
||||
position: HUDElementVec2,
|
||||
positionAnchor: HUDElementPositionAnchors,
|
||||
content: ResourceLocation,
|
||||
size: HUDElementVec2,
|
||||
realZ: Float,
|
||||
tint: RGBColor = ChatColors.WHITE,
|
||||
) : HUDElement(position, positionAnchor, content, size, realZ, tint) {
|
||||
) : HUDElement(json, position, positionAnchor, content, size, realZ, tint) {
|
||||
|
||||
private var mesh = SimpleTextureMesh()
|
||||
|
||||
|
@ -0,0 +1,46 @@
|
||||
package de.bixilon.minosoft.gui.rendering.hud.elements.primitive
|
||||
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.data.text.ChatColors
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.data.text.RGBColor
|
||||
import de.bixilon.minosoft.gui.rendering.hud.elements.position.HUDElementPositionAnchors
|
||||
import de.bixilon.minosoft.gui.rendering.hud.elements.position.HUDElementVec2
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import glm_.glm
|
||||
|
||||
class HUDTextElement(
|
||||
json: Map<String, Any>,
|
||||
position: HUDElementVec2,
|
||||
positionAnchor: HUDElementPositionAnchors,
|
||||
content: ResourceLocation,
|
||||
size: HUDElementVec2,
|
||||
realZ: Float,
|
||||
tint: RGBColor = ChatColors.WHITE,
|
||||
): HUDElement(json, position, positionAnchor, content, size, realZ, tint) {
|
||||
val charImages = mutableListOf<HUDImageElement>()
|
||||
|
||||
val HUDTextElementAlignment = HUDTextElementAlignments.deserialize(json["alignment"] as String)!!
|
||||
|
||||
fun renderChatComponent(chatComponent: ChatComponent) {
|
||||
var width = 0
|
||||
var lines = 1
|
||||
var maxHeight = 0
|
||||
fun newLine() {
|
||||
lines++
|
||||
}
|
||||
|
||||
val chars = chatComponent.message.toCharArray()
|
||||
|
||||
for (char in chars) {
|
||||
if (ProtocolDefinition.LINE_BREAK_CHARS.contains(char)) {
|
||||
newLine()
|
||||
}
|
||||
val fontChar = hudRenderer.renderWindow.font.getChar(char)
|
||||
width += fontChar.size.x
|
||||
maxHeight = glm.max(maxHeight, fontChar.size.y)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package de.bixilon.minosoft.gui.rendering.hud.elements.primitive
|
||||
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
|
||||
enum class HUDTextElementAlignments(val resourceLocation: ResourceLocation, val transform: (Float, Float) -> Float) {
|
||||
LEFT(ResourceLocation("minosoft:left"), { _, position ->
|
||||
position
|
||||
}),
|
||||
CENTER(ResourceLocation("minosoft:center"), { size, position ->
|
||||
size/2 - position/2
|
||||
}),
|
||||
RIGHT(ResourceLocation("minosoft:right"), { size, position ->
|
||||
size - position
|
||||
}),
|
||||
;
|
||||
|
||||
companion object {
|
||||
val HUD_TEXT_ELEMENT_ALIGNMENTS = values()
|
||||
|
||||
val HUD_TEXT_ELEMENT_ALIGNMENT_NAMES = run {
|
||||
val result = mutableMapOf<ResourceLocation, HUDTextElementAlignments>()
|
||||
for (hudTextElementAlignment in HUD_TEXT_ELEMENT_ALIGNMENTS) {
|
||||
result[hudTextElementAlignment.resourceLocation] = hudTextElementAlignment
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fun deserialize(string: String): HUDTextElementAlignments? {
|
||||
return HUD_TEXT_ELEMENT_ALIGNMENT_NAMES[ResourceLocation(string)]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user