text style: shadowed, outline color

This commit is contained in:
Bixilon 2021-08-03 21:54:06 +02:00
parent faa85491a4
commit 095cd14d8b
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
9 changed files with 72 additions and 13 deletions

View File

@ -14,7 +14,7 @@
package de.bixilon.minosoft.data.text
import de.bixilon.minosoft.data.language.Translator
import de.bixilon.minosoft.data.text.RGBColor.Companion.asColor
import de.bixilon.minosoft.data.text.ChatCode.Companion.toColor
import de.bixilon.minosoft.data.text.events.ClickEvent
import de.bixilon.minosoft.data.text.events.HoverEvent
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
@ -122,13 +122,9 @@ class BaseComponent : ChatComponent {
currentText = it
}
val color = json["color"]?.nullCast<String>()?.let { colorName ->
if (colorName.startsWith("#")) {
colorName.asColor()
} else {
ChatCode.FORMATTING_CODES[colorName].nullCast<RGBColor>()
}
} ?: parent?.color
val color = json["color"]?.nullCast<String>()?.toColor() ?: parent?.color
val outlineColor = json["outlineColor"]?.nullCast<String>()?.toColor() ?: parent?.outlineColor
val formatting = parent?.formatting?.toMutableSet() ?: mutableSetOf()
@ -137,6 +133,7 @@ class BaseComponent : ChatComponent {
formatting.addOrRemove(PreChatFormattingCodes.UNDERLINED, json["underlined"]?.toBoolean())
formatting.addOrRemove(PreChatFormattingCodes.STRIKETHROUGH, json["strikethrough"]?.toBoolean())
formatting.addOrRemove(PreChatFormattingCodes.OBFUSCATED, json["obfuscated"]?.toBoolean())
formatting.addOrRemove(PreChatFormattingCodes.SHADOWED, json["shadowed"]?.toBoolean())
val clickEvent = json["clickEvent"]?.compoundCast()?.let { click -> ClickEvent(click, restrictedMode) }
val hoverEvent = json["hoverEvent"]?.compoundCast()?.let { hover -> HoverEvent(hover) }
@ -144,6 +141,7 @@ class BaseComponent : ChatComponent {
val textComponent = TextComponent(
message = currentText,
color = color,
outlineColor = outlineColor,
formatting = formatting,
clickEvent = clickEvent,
hoverEvent = hoverEvent,

View File

@ -12,7 +12,9 @@
*/
package de.bixilon.minosoft.data.text
import de.bixilon.minosoft.data.text.RGBColor.Companion.asColor
import de.bixilon.minosoft.util.KUtil.extend
import de.bixilon.minosoft.util.KUtil.nullCast
interface ChatCode {
companion object {
@ -54,5 +56,12 @@ interface ChatCode {
}
return "%x".format(index)
}
fun String.toColor(): RGBColor? {
if (this.startsWith("#")) {
return this.asColor()
}
return ChatCode.FORMATTING_CODES[this].nullCast<RGBColor>()
}
}
}

View File

@ -20,7 +20,9 @@ enum class PreChatFormattingCodes(
BOLD('l', "\u001b[1m"),
STRIKETHROUGH('m', "\u001b[9m"),
UNDERLINED('n', "\u001b[4m"),
ITALIC('o', "\u001b[3m")
ITALIC('o', "\u001b[3m"),
SHADOWED('s', ""),
;
override fun toString(): String {

View File

@ -31,11 +31,12 @@ import javafx.util.Duration
open class TextComponent(
message: Any? = "",
var color: RGBColor? = null,
var formatting: MutableSet<ChatFormattingCode> = mutableSetOf(),
override var color: RGBColor? = null,
override var outlineColor: RGBColor? = null,
override val formatting: MutableSet<ChatFormattingCode> = mutableSetOf(),
var clickEvent: ClickEvent? = null,
var hoverEvent: HoverEvent? = null,
) : ChatComponent {
) : ChatComponent, TextStyle {
override var message: String = message?.toString() ?: "null"
fun obfuscate(): TextComponent {
@ -63,11 +64,21 @@ open class TextComponent(
return this
}
fun shadow(): TextComponent {
formatting.add(PreChatFormattingCodes.SHADOWED)
return this
}
fun color(color: RGBColor): TextComponent {
this.color = color
return this
}
fun outline(color: RGBColor): TextComponent {
this.outlineColor = color
return this
}
override fun toString(): String {
return legacyText
}

View File

@ -0,0 +1,20 @@
/*
* 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.data.text
interface TextStyle {
var outlineColor: RGBColor?
var color: RGBColor?
val formatting: MutableCollection<ChatFormattingCode>
}

View File

@ -19,13 +19,19 @@ class Font(
val providers: MutableList<FontProvider>,
) : FontProvider {
override fun postInit() {
for (provider in providers) {
provider.postInit()
}
}
override fun get(char: Char): CharData? {
for (provider in providers) {
provider[char]?.let { return it }
}
return null
}
companion object {
const val CHAR_HEIGHT = 8

View File

@ -73,6 +73,10 @@ class BitmapFontProvider(
}
}
override fun get(char: Char): CharData? {
return chars[char]
}
companion object : FontProviderFactory<BitmapFontProvider> {
private const val CHAR_WIDTH = 8
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:bitmap".toResourceLocation()

View File

@ -13,7 +13,12 @@
package de.bixilon.minosoft.gui.rendering.font.provider
import de.bixilon.minosoft.gui.rendering.font.CharData
interface FontProvider {
fun postInit()
operator fun get(char: Char): CharData?
}

View File

@ -83,6 +83,10 @@ class LegacyUnicodeFontProvider(
}
}
override fun get(char: Char): CharData? {
return chars.getOrNull(char.code)
}
companion object : FontProviderFactory<LegacyUnicodeFontProvider> {
private val MISSING_UNICODE_PAGES = listOf(0x08, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xEE, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8)
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:legacy_unicode".toResourceLocation()