mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 03:44:54 -04:00
text style: shadowed, outline color
This commit is contained in:
parent
faa85491a4
commit
095cd14d8b
@ -14,7 +14,7 @@
|
|||||||
package de.bixilon.minosoft.data.text
|
package de.bixilon.minosoft.data.text
|
||||||
|
|
||||||
import de.bixilon.minosoft.data.language.Translator
|
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.ClickEvent
|
||||||
import de.bixilon.minosoft.data.text.events.HoverEvent
|
import de.bixilon.minosoft.data.text.events.HoverEvent
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||||
@ -122,13 +122,9 @@ class BaseComponent : ChatComponent {
|
|||||||
currentText = it
|
currentText = it
|
||||||
}
|
}
|
||||||
|
|
||||||
val color = json["color"]?.nullCast<String>()?.let { colorName ->
|
|
||||||
if (colorName.startsWith("#")) {
|
val color = json["color"]?.nullCast<String>()?.toColor() ?: parent?.color
|
||||||
colorName.asColor()
|
val outlineColor = json["outlineColor"]?.nullCast<String>()?.toColor() ?: parent?.outlineColor
|
||||||
} else {
|
|
||||||
ChatCode.FORMATTING_CODES[colorName].nullCast<RGBColor>()
|
|
||||||
}
|
|
||||||
} ?: parent?.color
|
|
||||||
|
|
||||||
val formatting = parent?.formatting?.toMutableSet() ?: mutableSetOf()
|
val formatting = parent?.formatting?.toMutableSet() ?: mutableSetOf()
|
||||||
|
|
||||||
@ -137,6 +133,7 @@ class BaseComponent : ChatComponent {
|
|||||||
formatting.addOrRemove(PreChatFormattingCodes.UNDERLINED, json["underlined"]?.toBoolean())
|
formatting.addOrRemove(PreChatFormattingCodes.UNDERLINED, json["underlined"]?.toBoolean())
|
||||||
formatting.addOrRemove(PreChatFormattingCodes.STRIKETHROUGH, json["strikethrough"]?.toBoolean())
|
formatting.addOrRemove(PreChatFormattingCodes.STRIKETHROUGH, json["strikethrough"]?.toBoolean())
|
||||||
formatting.addOrRemove(PreChatFormattingCodes.OBFUSCATED, json["obfuscated"]?.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 clickEvent = json["clickEvent"]?.compoundCast()?.let { click -> ClickEvent(click, restrictedMode) }
|
||||||
val hoverEvent = json["hoverEvent"]?.compoundCast()?.let { hover -> HoverEvent(hover) }
|
val hoverEvent = json["hoverEvent"]?.compoundCast()?.let { hover -> HoverEvent(hover) }
|
||||||
@ -144,6 +141,7 @@ class BaseComponent : ChatComponent {
|
|||||||
val textComponent = TextComponent(
|
val textComponent = TextComponent(
|
||||||
message = currentText,
|
message = currentText,
|
||||||
color = color,
|
color = color,
|
||||||
|
outlineColor = outlineColor,
|
||||||
formatting = formatting,
|
formatting = formatting,
|
||||||
clickEvent = clickEvent,
|
clickEvent = clickEvent,
|
||||||
hoverEvent = hoverEvent,
|
hoverEvent = hoverEvent,
|
||||||
|
@ -12,7 +12,9 @@
|
|||||||
*/
|
*/
|
||||||
package de.bixilon.minosoft.data.text
|
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.extend
|
||||||
|
import de.bixilon.minosoft.util.KUtil.nullCast
|
||||||
|
|
||||||
interface ChatCode {
|
interface ChatCode {
|
||||||
companion object {
|
companion object {
|
||||||
@ -54,5 +56,12 @@ interface ChatCode {
|
|||||||
}
|
}
|
||||||
return "%x".format(index)
|
return "%x".format(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun String.toColor(): RGBColor? {
|
||||||
|
if (this.startsWith("#")) {
|
||||||
|
return this.asColor()
|
||||||
|
}
|
||||||
|
return ChatCode.FORMATTING_CODES[this].nullCast<RGBColor>()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,9 @@ enum class PreChatFormattingCodes(
|
|||||||
BOLD('l', "\u001b[1m"),
|
BOLD('l', "\u001b[1m"),
|
||||||
STRIKETHROUGH('m', "\u001b[9m"),
|
STRIKETHROUGH('m', "\u001b[9m"),
|
||||||
UNDERLINED('n', "\u001b[4m"),
|
UNDERLINED('n', "\u001b[4m"),
|
||||||
ITALIC('o', "\u001b[3m")
|
ITALIC('o', "\u001b[3m"),
|
||||||
|
|
||||||
|
SHADOWED('s', ""),
|
||||||
;
|
;
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
|
@ -31,11 +31,12 @@ import javafx.util.Duration
|
|||||||
|
|
||||||
open class TextComponent(
|
open class TextComponent(
|
||||||
message: Any? = "",
|
message: Any? = "",
|
||||||
var color: RGBColor? = null,
|
override var color: RGBColor? = null,
|
||||||
var formatting: MutableSet<ChatFormattingCode> = mutableSetOf(),
|
override var outlineColor: RGBColor? = null,
|
||||||
|
override val formatting: MutableSet<ChatFormattingCode> = mutableSetOf(),
|
||||||
var clickEvent: ClickEvent? = null,
|
var clickEvent: ClickEvent? = null,
|
||||||
var hoverEvent: HoverEvent? = null,
|
var hoverEvent: HoverEvent? = null,
|
||||||
) : ChatComponent {
|
) : ChatComponent, TextStyle {
|
||||||
override var message: String = message?.toString() ?: "null"
|
override var message: String = message?.toString() ?: "null"
|
||||||
|
|
||||||
fun obfuscate(): TextComponent {
|
fun obfuscate(): TextComponent {
|
||||||
@ -63,11 +64,21 @@ open class TextComponent(
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun shadow(): TextComponent {
|
||||||
|
formatting.add(PreChatFormattingCodes.SHADOWED)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
fun color(color: RGBColor): TextComponent {
|
fun color(color: RGBColor): TextComponent {
|
||||||
this.color = color
|
this.color = color
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun outline(color: RGBColor): TextComponent {
|
||||||
|
this.outlineColor = color
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return legacyText
|
return legacyText
|
||||||
}
|
}
|
||||||
|
20
src/main/java/de/bixilon/minosoft/data/text/TextStyle.kt
Normal file
20
src/main/java/de/bixilon/minosoft/data/text/TextStyle.kt
Normal 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>
|
||||||
|
}
|
@ -19,13 +19,19 @@ class Font(
|
|||||||
val providers: MutableList<FontProvider>,
|
val providers: MutableList<FontProvider>,
|
||||||
) : FontProvider {
|
) : FontProvider {
|
||||||
|
|
||||||
|
|
||||||
override fun postInit() {
|
override fun postInit() {
|
||||||
for (provider in providers) {
|
for (provider in providers) {
|
||||||
provider.postInit()
|
provider.postInit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun get(char: Char): CharData? {
|
||||||
|
for (provider in providers) {
|
||||||
|
provider[char]?.let { return it }
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val CHAR_HEIGHT = 8
|
const val CHAR_HEIGHT = 8
|
||||||
|
@ -73,6 +73,10 @@ class BitmapFontProvider(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun get(char: Char): CharData? {
|
||||||
|
return chars[char]
|
||||||
|
}
|
||||||
|
|
||||||
companion object : FontProviderFactory<BitmapFontProvider> {
|
companion object : FontProviderFactory<BitmapFontProvider> {
|
||||||
private const val CHAR_WIDTH = 8
|
private const val CHAR_WIDTH = 8
|
||||||
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:bitmap".toResourceLocation()
|
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:bitmap".toResourceLocation()
|
||||||
|
@ -13,7 +13,12 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering.font.provider
|
package de.bixilon.minosoft.gui.rendering.font.provider
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.gui.rendering.font.CharData
|
||||||
|
|
||||||
interface FontProvider {
|
interface FontProvider {
|
||||||
|
|
||||||
fun postInit()
|
fun postInit()
|
||||||
|
|
||||||
|
|
||||||
|
operator fun get(char: Char): CharData?
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,10 @@ class LegacyUnicodeFontProvider(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun get(char: Char): CharData? {
|
||||||
|
return chars.getOrNull(char.code)
|
||||||
|
}
|
||||||
|
|
||||||
companion object : FontProviderFactory<LegacyUnicodeFontProvider> {
|
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)
|
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()
|
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:legacy_unicode".toResourceLocation()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user