Skip to content

Commit

Permalink
Add 'static-scale'
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Dec 2, 2024
1 parent 5f16af3 commit 3746df2
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 32 deletions.
23 changes: 22 additions & 1 deletion changelog/1.10.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
- Fix layout identifier.
- Fix render scale calculation.
9 changes: 5 additions & 4 deletions dist/src/main/kotlin/kr/toxicity/hud/hud/HudHeadParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -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 ->
Expand Down
2 changes: 1 addition & 1 deletion dist/src/main/kotlin/kr/toxicity/hud/hud/HudImageParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions dist/src/main/kotlin/kr/toxicity/hud/hud/HudImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class HudImpl(
HudAnimation(
layout.animation.type,
layout.animation.location.map {
HudElement(
HudParser(
this@HudImpl,
resource,
layout,
Expand Down Expand Up @@ -117,6 +117,6 @@ class HudImpl(

private class HudAnimation(
val animationType: AnimationType,
val elements: List<HudElement>
val elements: List<HudParser>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions dist/src/main/kotlin/kr/toxicity/hud/hud/HudTextParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions dist/src/main/kotlin/kr/toxicity/hud/layout/HeadLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ interface HeadLayout : HudLayout<HeadElement> {
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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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<PixelLocation> {
companion object {
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};")
Expand Down
2 changes: 1 addition & 1 deletion dist/src/main/kotlin/kr/toxicity/hud/pack/PackGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object PackGenerator {
private open class Builder {
@Volatile
var byte = 0L
val byteArrayMap = WeakHashMap<String, ByteArray>()
val byteArrayMap = HashMap<String, ByteArray>()
}
private class ZipBuilder(
val zip: ZipOutputStream
Expand Down
20 changes: 11 additions & 9 deletions dist/src/main/kotlin/kr/toxicity/hud/popup/PopupLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -278,7 +280,7 @@ class PopupLayout(
STANDARD -> shader
FANCY -> HudShader(
elementGui,
headLayout.renderScale * 1.125,
render * 1.125,
headLayout.layer + 1,
true,
pixel.opacity,
Expand All @@ -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",
Expand All @@ -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(
Expand Down
11 changes: 6 additions & 5 deletions dist/src/main/kotlin/kr/toxicity/hud/shader/RenderScale.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kr.toxicity.hud.location.PixelLocation

class RenderScale(
val relativeOffset: PixelLocation,
val scale: Scale
val scale: Scale,
) : Comparable<RenderScale> {
companion object {
private val scaleComparator = Comparator.comparing { scale: Scale ->
Expand All @@ -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<Scale> {
operator fun times(multiplier: Double) = Scale(x * multiplier, y * multiplier)
data class Scale(val x: Double, val y: Double, val staticScale: Boolean) : Comparable<Scale> {
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 {
Expand Down
3 changes: 2 additions & 1 deletion dist/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
remove-default-hotbar: false
disable-legacy-offset: false

0 comments on commit 3746df2

Please sign in to comment.