Skip to content

Commit

Permalink
Adds image color option.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Mar 19, 2024
1 parent adc4413 commit ac207d7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class HudImageElement(parent: HudImpl, private val image: ImageLayout, gui: GuiL
}
ImageRenderer(
hud,
image.color,
list,
image.conditions.and(image.image.conditions)
)
Expand Down
2 changes: 2 additions & 0 deletions dist/src/main/kotlin/kr/toxicity/hud/layout/ImageLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package kr.toxicity.hud.layout
import kr.toxicity.hud.image.HudImage
import kr.toxicity.hud.image.ImageLocation
import kr.toxicity.hud.placeholder.ConditionBuilder
import net.kyori.adventure.text.format.TextColor

class ImageLayout(
val image: HudImage,
val color: TextColor,
val location: ImageLocation,
val scale: Double,
val outline: Boolean,
Expand Down
8 changes: 3 additions & 5 deletions dist/src/main/kotlin/kr/toxicity/hud/layout/LayoutGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kr.toxicity.hud.manager.TextManager
import kr.toxicity.hud.util.forEachSubConfiguration
import kr.toxicity.hud.util.ifNull
import kr.toxicity.hud.util.toConditions
import kr.toxicity.hud.util.toTextColor
import net.kyori.adventure.text.format.NamedTextColor
import net.kyori.adventure.text.format.TextColor
import org.bukkit.configuration.ConfigurationSection
Expand All @@ -32,6 +33,7 @@ class LayoutGroup(section: ConfigurationSection) {
configurationSection.getString("name").ifNull("name value not set: $s").let { n ->
ImageManager.getImage(n).ifNull("this image doesn't exist: $n")
},
configurationSection.getString("color")?.toTextColor() ?: NamedTextColor.WHITE,
ImageLocation(configurationSection) + loc,
configurationSection.getDouble("scale", 1.0),
configurationSection.getBoolean("outline"),
Expand All @@ -55,11 +57,7 @@ class LayoutGroup(section: ConfigurationSection) {
configurationSection.getString("align")?.let {
TextLayout.Align.valueOf(it.uppercase())
} ?: TextLayout.Align.LEFT,
configurationSection.getString("color")?.let {
if (it.startsWith('#') && it.length == 7) {
TextColor.fromHexString(it)
} else NamedTextColor.NAMES.value(it)
} ?: NamedTextColor.WHITE,
configurationSection.getString("color")?.toTextColor() ?: NamedTextColor.WHITE,
configurationSection.getBoolean("outline"),
configurationSection.getInt("layer"),
configurationSection.getString("number-equation")?.let {
Expand Down
1 change: 1 addition & 0 deletions dist/src/main/kotlin/kr/toxicity/hud/popup/PopupLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class PopupLayout(

ImageRenderer(
hudImage,
target.color,
list,
hudImage.conditions.and(target.conditions)
)
Expand Down
12 changes: 10 additions & 2 deletions dist/src/main/kotlin/kr/toxicity/hud/renderer/ImageRenderer.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package kr.toxicity.hud.renderer

import kr.toxicity.hud.api.component.PixelComponent
import kr.toxicity.hud.api.component.WidthComponent
import kr.toxicity.hud.api.listener.HudListener
import kr.toxicity.hud.api.player.HudPlayer
import kr.toxicity.hud.api.update.UpdateEvent
import kr.toxicity.hud.image.HudImage
import kr.toxicity.hud.image.ImageType
import kr.toxicity.hud.placeholder.ConditionBuilder
import kr.toxicity.hud.util.EMPTY_PIXEL_COMPONENT
import net.kyori.adventure.text.format.TextColor

class ImageRenderer(
image: HudImage,
private val components: List<PixelComponent>,
color: TextColor,
components: List<PixelComponent>,
private val conditions: ConditionBuilder
) {
private val type: ImageType = image.type
private val type = image.type
private val components = components.map {
val comp = it.component
PixelComponent(WidthComponent(comp.component.color(color), comp.width), it.pixel)
}

val listener: (UpdateEvent) -> HudListener = image.listener ?: HudListener.ZERO.let {
{ _ ->
it
Expand Down
4 changes: 4 additions & 0 deletions dist/src/main/kotlin/kr/toxicity/hud/util/Adventures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kr.toxicity.hud.api.component.WidthComponent
import net.kyori.adventure.key.Key
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.NamedTextColor
import net.kyori.adventure.text.format.TextColor
import net.kyori.adventure.text.format.TextDecoration
import net.kyori.adventure.text.minimessage.MiniMessage
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver
Expand Down Expand Up @@ -42,6 +43,9 @@ val NEGATIVE_ONE_SPACE_COMPONENT
WidthComponent(Component.text((0xD0000 - 1).parseChar()).font(SPACE_KEY), 0)
}

fun String.toTextColor() = if (startsWith('#') && length == 7) {
TextColor.fromHexString(this)
} else NamedTextColor.NAMES.value(this) ?: NamedTextColor.WHITE
fun WidthComponent.toPixelComponent(pixel: Int) = PixelComponent(this, pixel)

fun Int.parseChar(): String {
Expand Down

0 comments on commit ac207d7

Please sign in to comment.