diff --git a/changelog/1.10.md b/changelog/1.10.md index 7a6d04e0..e3c7cddb 100644 --- a/changelog/1.10.md +++ b/changelog/1.10.md @@ -76,7 +76,28 @@ test_layout: second: 0.33 operation: "<" ``` +- Add 'static-scale' in render scale +```yaml +test_head: + heads: + 1: + name: test_head + align: center + type: fancy + y: 64 + x: 64 + render-scale: + x: 3.0 + y: 3.0 + static-scale: true +``` +- Add these option in config.yml +```yaml +disable-legacy-offset: false #If this is true, a correct pixel offset is provided. +``` + ## Fix - Fix placeholder comma. - Fix Folia adaption -- Fix layout identifier. \ No newline at end of file +- Fix layout identifier. +- Fix render scale calculation. \ No newline at end of file diff --git a/dist/src/main/kotlin/kr/toxicity/hud/hud/HudHeadParser.kt b/dist/src/main/kotlin/kr/toxicity/hud/hud/HudHeadParser.kt index 869dcfa9..904686e3 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/hud/HudHeadParser.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/hud/HudHeadParser.kt @@ -15,9 +15,10 @@ class HudHeadParser(parent: HudImpl, private val head: HeadLayout, gui: GuiLocat private val renderer = run { val final = head.location + pixel + val render = head.renderScale + pixel val shader = HudShader( gui, - head.renderScale, + render, head.layer, head.outline, final.opacity, @@ -27,7 +28,7 @@ class HudHeadParser(parent: HudImpl, private val head: HeadLayout, gui: GuiLocat STANDARD -> shader FANCY -> HudShader( gui, - head.renderScale * 1.125, + render * 1.125, head.layer + 1, true, final.opacity, @@ -45,7 +46,7 @@ class HudHeadParser(parent: HudImpl, private val head: HeadLayout, gui: GuiLocat val ascent = final.y + i * head.source.pixel val height = head.source.pixel val char = parent.newChar - val mainChar = head(head.identifier(shader, ascent)) { + val mainChar = head(head.identifier(shader, ascent, fileName)) { parent.jsonArray?.let { array -> createAscent(shader, ascent) { y -> array += jsonObjectOf( @@ -64,7 +65,7 @@ class HudHeadParser(parent: HudImpl, private val head: HeadLayout, gui: GuiLocat FANCY -> { HeadKey( mainChar, - head(head.identifier(hair, ascent - head.source.pixel)) { + head(head.identifier(hair, ascent - head.source.pixel, fileName)) { val twoChar = parent.newChar parent.jsonArray?.let { array -> createAscent(hair, ascent - head.source.pixel) { y -> diff --git a/dist/src/main/kotlin/kr/toxicity/hud/hud/HudImageParser.kt b/dist/src/main/kotlin/kr/toxicity/hud/hud/HudImageParser.kt index 9a369b44..52384c42 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/hud/HudImageParser.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/hud/HudImageParser.kt @@ -22,7 +22,7 @@ class HudImageParser(parent: HudImpl, private val imageLayout: ImageLayout, gui: val shader = HudShader( gui, - imageLayout.renderScale, + imageLayout.renderScale + pixel, imageLayout.layer, imageLayout.outline, finalPixel.opacity, diff --git a/dist/src/main/kotlin/kr/toxicity/hud/hud/HudImpl.kt b/dist/src/main/kotlin/kr/toxicity/hud/hud/HudImpl.kt index afed7e11..4c45c82d 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/hud/HudImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/hud/HudImpl.kt @@ -54,7 +54,7 @@ class HudImpl( HudAnimation( layout.animation.type, layout.animation.location.map { - HudElement( + HudParser( this@HudImpl, resource, layout, @@ -117,6 +117,6 @@ class HudImpl( private class HudAnimation( val animationType: AnimationType, - val elements: List + val elements: List ) } \ No newline at end of file diff --git a/dist/src/main/kotlin/kr/toxicity/hud/hud/HudElement.kt b/dist/src/main/kotlin/kr/toxicity/hud/hud/HudParser.kt similarity index 98% rename from dist/src/main/kotlin/kr/toxicity/hud/hud/HudElement.kt rename to dist/src/main/kotlin/kr/toxicity/hud/hud/HudParser.kt index cab6461b..89541b47 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/hud/HudElement.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/hud/HudParser.kt @@ -9,7 +9,7 @@ import kr.toxicity.hud.location.GuiLocation import kr.toxicity.hud.resource.GlobalResource import kr.toxicity.hud.util.EMPTY_WIDTH_COMPONENT -class HudElement( +class HudParser( hud: HudImpl, resource: GlobalResource, private val layout: LayoutGroup, diff --git a/dist/src/main/kotlin/kr/toxicity/hud/hud/HudTextParser.kt b/dist/src/main/kotlin/kr/toxicity/hud/hud/HudTextParser.kt index 749ffa33..f1aa837b 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/hud/HudTextParser.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/hud/HudTextParser.kt @@ -29,9 +29,10 @@ class HudTextParser( private val renderer = run { val loc = text.location + pixel + val render = text.renderScale + pixel val shader = HudShader( gui, - text.renderScale, + render, text.layer, text.outline, loc.opacity, @@ -84,7 +85,7 @@ class HudTextParser( val div = height.toDouble() / image.image.height createAscent(HudShader( gui, - text.renderScale, + render, text.layer - 1, false, loc.opacity * it.location.opacity, diff --git a/dist/src/main/kotlin/kr/toxicity/hud/layout/HeadLayout.kt b/dist/src/main/kotlin/kr/toxicity/hud/layout/HeadLayout.kt index c1858549..44ca660a 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/layout/HeadLayout.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/layout/HeadLayout.kt @@ -15,8 +15,8 @@ interface HeadLayout : HudLayout { val type: HeadRenderType val align: LayoutAlign - fun identifier(shader: HudShader, ascent: Int): HudLayout.Identifier { - return ShaderGroup(shader, source.name, ascent) + fun identifier(shader: HudShader, ascent: Int, fileName: String): HudLayout.Identifier { + return ShaderGroup(shader, fileName, ascent) } class Impl( diff --git a/dist/src/main/kotlin/kr/toxicity/hud/location/PixelLocation.kt b/dist/src/main/kotlin/kr/toxicity/hud/location/PixelLocation.kt index 39b175bb..1cdce2f9 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/location/PixelLocation.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/location/PixelLocation.kt @@ -1,6 +1,7 @@ package kr.toxicity.hud.location import kr.toxicity.hud.api.yaml.YamlObject +import kr.toxicity.hud.manager.ConfigManagerImpl data class PixelLocation(val x: Int, val y: Int, val opacity: Double) : Comparable { companion object { @@ -13,7 +14,9 @@ data class PixelLocation(val x: Int, val y: Int, val opacity: Double) : Comparab image.opacity } - val hotBarHeight = PixelLocation(0, -54, 1.0) + private val _hotBarHeight = PixelLocation(0, -54, 1.0) + val hotBarHeight + get() = if (ConfigManagerImpl.disableLegacyOffset) zero else _hotBarHeight val zero = PixelLocation(0, 0, 1.0) } constructor(section: YamlObject): this( diff --git a/dist/src/main/kotlin/kr/toxicity/hud/manager/ConfigManagerImpl.kt b/dist/src/main/kotlin/kr/toxicity/hud/manager/ConfigManagerImpl.kt index ecb43505..242d8bd4 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/manager/ConfigManagerImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/manager/ConfigManagerImpl.kt @@ -89,6 +89,8 @@ object ConfigManagerImpl : BetterHudManager, ConfigManager { var legacySerializer = LEGACY_AMPERSAND private set private var removeDefaultHotbar = false + var disableLegacyOffset = false + private set override fun start() { } @@ -191,6 +193,7 @@ object ConfigManagerImpl : BetterHudManager, ConfigManager { key = KeyResource(yaml["namespace"]?.asString() ?: NAME_SPACE) minecraftJarVersion = yaml["minecraft-jar-version"]?.asString() ?: "bukkit" removeDefaultHotbar = yaml.getAsBoolean("remove-default-hotbar", false) + disableLegacyOffset = yaml.getAsBoolean("disable-legacy-offset", false) }.onFailure { e -> warn( "Unable to load config.yml", diff --git a/dist/src/main/kotlin/kr/toxicity/hud/manager/ShaderManagerImpl.kt b/dist/src/main/kotlin/kr/toxicity/hud/manager/ShaderManagerImpl.kt index 2492d74d..293860ff 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/manager/ShaderManagerImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/manager/ShaderManagerImpl.kt @@ -37,8 +37,15 @@ object ShaderManagerImpl : BetterHudManager, ShaderManager { add("case ${id}:") if (shader.property > 0) add(" property = ${shader.property};") if (shader.opacity < 1.0) add(" opacity = ${shader.opacity.toFloat()};") - if (shader.renderScale.scale.x != 1.0) add(" pos.x = (pos.x - (${shader.renderScale.relativeOffset.x})) * ${shader.renderScale.scale.x} + (${shader.renderScale.relativeOffset.x});") - if (shader.renderScale.scale.y != 1.0) add(" pos.y = (pos.y - (${shader.renderScale.relativeOffset.y})) * ${shader.renderScale.scale.y} + (${shader.renderScale.relativeOffset.y});") + val static = shader.renderScale.scale.staticScale + fun applyScale(offset: Int, scale: Double, pos: String) { + if (scale != 1.0 || static) { + val scaleFloat = scale.toFloat() + add(" pos.$pos = (pos.$pos - (${offset})) * ${if (static) "$scaleFloat * ui.$pos / ScreenSize.$pos" else scaleFloat} + (${offset});") + } + } + applyScale(shader.renderScale.relativeOffset.x, shader.renderScale.scale.x, "x") + applyScale(shader.renderScale.relativeOffset.y, shader.renderScale.scale.y, "y") if (shader.gui.x != 0.0) add(" xGui = ui.x * ${shader.gui.x.toFloat()} / 100.0;") if (shader.gui.y != 0.0) add(" yGui = ui.y * ${shader.gui.y.toFloat()} / 100.0;") if (shader.layer != 0) add(" layer = ${shader.layer};") diff --git a/dist/src/main/kotlin/kr/toxicity/hud/pack/PackGenerator.kt b/dist/src/main/kotlin/kr/toxicity/hud/pack/PackGenerator.kt index 957e943a..352c28bc 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/pack/PackGenerator.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/pack/PackGenerator.kt @@ -28,7 +28,7 @@ object PackGenerator { private open class Builder { @Volatile var byte = 0L - val byteArrayMap = WeakHashMap() + val byteArrayMap = HashMap() } private class ZipBuilder( val zip: ZipOutputStream diff --git a/dist/src/main/kotlin/kr/toxicity/hud/popup/PopupLayout.kt b/dist/src/main/kotlin/kr/toxicity/hud/popup/PopupLayout.kt index dc2e0c1c..98ed79c9 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/popup/PopupLayout.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/popup/PopupLayout.kt @@ -111,7 +111,7 @@ class PopupLayout( val pixel = elementPixel + pair.pixel + target.location val imageShader = HudShader( elementGui, - target.renderScale, + target.renderScale + pair.pixel + target.location, target.layer, target.outline, pixel.opacity, @@ -170,10 +170,11 @@ class PopupLayout( } ?: 0 val texts = layout.text.map { textLayout -> - val pixel = elementPixel + pair.pixel + textLayout.location + val pixel = textLayout.location + elementPixel + pair.pixel + val render = textLayout.renderScale + elementPixel + pair.pixel val textShader = HudShader( elementGui, - textLayout.renderScale, + render, textLayout.layer, textLayout.outline, pixel.opacity, @@ -225,7 +226,7 @@ class PopupLayout( val div = height.toDouble() / image.image.height createAscent(HudShader( elementGui, - textLayout.renderScale, + render, textLayout.layer - 1, false, pixel.opacity * it.location.opacity, @@ -265,10 +266,11 @@ class PopupLayout( } val heads = layout.head.map { headLayout -> - val pixel = elementPixel + pair.pixel + headLayout.location + val pixel = headLayout.location + elementPixel + pair.pixel + val render = headLayout.renderScale + elementPixel + pair.pixel val shader = HudShader( elementGui, - headLayout.renderScale, + render, headLayout.layer, headLayout.outline, pixel.opacity, @@ -278,7 +280,7 @@ class PopupLayout( STANDARD -> shader FANCY -> HudShader( elementGui, - headLayout.renderScale * 1.125, + render * 1.125, headLayout.layer + 1, true, pixel.opacity, @@ -296,7 +298,7 @@ class PopupLayout( val char = parent.newChar val ascent = pixel.y + i * headLayout.source.pixel val height = headLayout.source.pixel - val mainChar = head(headLayout.identifier(shader, ascent)) { + val mainChar = head(headLayout.identifier(shader, ascent, fileName)) { createAscent(shader, ascent) { y -> array += jsonObjectOf( "type" to "bitmap", @@ -313,7 +315,7 @@ class PopupLayout( FANCY -> { HeadKey( mainChar, - head(headLayout.identifier(hair, ascent - headLayout.source.pixel)) { + head(headLayout.identifier(hair, ascent - headLayout.source.pixel, fileName)) { val twoChar = parent.newChar createAscent(hair, ascent - headLayout.source.pixel) { y -> array += jsonObjectOf( diff --git a/dist/src/main/kotlin/kr/toxicity/hud/shader/RenderScale.kt b/dist/src/main/kotlin/kr/toxicity/hud/shader/RenderScale.kt index a0609c0e..d57a473e 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/shader/RenderScale.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/shader/RenderScale.kt @@ -5,7 +5,7 @@ import kr.toxicity.hud.location.PixelLocation class RenderScale( val relativeOffset: PixelLocation, - val scale: Scale + val scale: Scale, ) : Comparable { companion object { private val scaleComparator = Comparator.comparing { scale: Scale -> @@ -19,20 +19,21 @@ class RenderScale( scale.scale } - private val scaleOne = Scale(1.0, 1.0) + private val scaleOne = Scale(1.0, 1.0, false) fun fromConfig(offset: PixelLocation, yamlObject: YamlObject) = RenderScale( offset, yamlObject["render-scale"]?.asObject()?.let { - Scale(it.getAsDouble("x", 1.0), it.getAsDouble("y", 1.0)) + Scale(it.getAsDouble("x", 1.0), it.getAsDouble("y", 1.0), it.getAsBoolean("static-scale", false)) } ?: scaleOne ) } + operator fun plus(other: PixelLocation) = RenderScale(relativeOffset + other, scale) operator fun times(multiplier: Double) = RenderScale(relativeOffset, scale * multiplier) - data class Scale(val x: Double, val y: Double) : Comparable { - operator fun times(multiplier: Double) = Scale(x * multiplier, y * multiplier) + data class Scale(val x: Double, val y: Double, val staticScale: Boolean) : Comparable { + operator fun times(multiplier: Double) = Scale(x * multiplier, y * multiplier, staticScale) override fun compareTo(other: Scale): Int = scaleComparator.compare(this, other) } override fun compareTo(other: RenderScale): Int = if (scale == scaleOne) scale.compareTo(other.scale) else { diff --git a/dist/src/main/resources/config.yml b/dist/src/main/resources/config.yml index 43b6fab5..98eb7e59 100644 --- a/dist/src/main/resources/config.yml +++ b/dist/src/main/resources/config.yml @@ -31,4 +31,5 @@ clear-build-folder: true #If you use Oraxen, set this to false. use-legacy-format: true legacy-serializer: ampersand #section, ampersand, both minecraft-jar-version: bukkit #1.21, 1.20.4, etc. -remove-default-hotbar: false \ No newline at end of file +remove-default-hotbar: false +disable-legacy-offset: false \ No newline at end of file