From 0c98d82a100c97f3b0042a75edd87bed57341fa2 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Mon, 26 Aug 2024 03:29:32 +0200 Subject: Fix: Custom Scoreboard Issues (#2402) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../gui/customscoreboard/CustomScoreboard.kt | 19 ++++-- .../gui/customscoreboard/RenderBackground.kt | 73 ++++++++++++++-------- .../gui/customscoreboard/ScoreboardElements.kt | 2 +- 3 files changed, 63 insertions(+), 31 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features') diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt index 7c61eade8..f74253d36 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt @@ -59,7 +59,7 @@ object CustomScoreboard { val textRenderable = Renderable.verticalContainer( render.map { Renderable.string(it.first, horizontalAlign = it.second) }, - 0, + displayConfig.lineSpacing - 10, horizontalAlign = HorizontalAlignment.CENTER, verticalAlign = VerticalAlignment.CENTER, ) @@ -75,12 +75,23 @@ object CustomScoreboard { fun onGuiPositionMoved(event: GuiPositionMovedEvent) { if (event.guiName == guiName) { with(alignmentConfig) { - if (horizontalAlignment != HorizontalAlignment.DONT_ALIGN - || verticalAlignment != VerticalAlignment.DONT_ALIGN + if (horizontalAlignment != HorizontalAlignment.DONT_ALIGN || + verticalAlignment != VerticalAlignment.DONT_ALIGN ) { + val tempHori = horizontalAlignment + val tempVert = verticalAlignment + horizontalAlignment = HorizontalAlignment.DONT_ALIGN verticalAlignment = VerticalAlignment.DONT_ALIGN - ChatUtils.chat("Disabled Custom Scoreboard auto-alignment.") + ChatUtils.clickableChat( + "Disabled Custom Scoreboard auto-alignment. Click here to undo this action!", + oneTimeClick = true, + onClick = { + horizontalAlignment = tempHori + verticalAlignment = tempVert + ChatUtils.chat("Enabled Custom Scoreboard auto-alignment.") + }, + ) } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt index 44e5c927c..14d29d6ac 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt @@ -1,8 +1,10 @@ package at.hannibal2.skyhanni.features.gui.customscoreboard +import at.hannibal2.skyhanni.config.features.gui.customscoreboard.BackgroundConfig import at.hannibal2.skyhanni.data.GuiEditManager import at.hannibal2.skyhanni.data.GuiEditManager.getAbsX import at.hannibal2.skyhanni.data.GuiEditManager.getAbsY +import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboard.backgroundConfig import at.hannibal2.skyhanni.utils.ColorUtils.toChromaColor import at.hannibal2.skyhanni.utils.RenderUtils import at.hannibal2.skyhanni.utils.renderables.Renderable @@ -15,18 +17,35 @@ object RenderBackground { private val textureLocation by lazy { ResourceLocation("skyhanni", "scoreboard.png") } internal fun addBackground(renderable: Renderable): Renderable { - val backgroundConfig = CustomScoreboard.backgroundConfig - val outlineConfig = backgroundConfig.outline - val padding = backgroundConfig.borderSize + with(backgroundConfig) { + if (!backgroundConfig.enabled) return renderable - if (!backgroundConfig.enabled) return renderable + val backgroundRenderable = createBackground(renderable) - val backgroundRenderable = if (backgroundConfig.useCustomBackgroundImage) { + if (!outline.enabled) return backgroundRenderable + + return Renderable.drawInsideRoundedRectOutline( + backgroundRenderable, + 0, + backgroundConfig.roundedCornerSmoothness, + 1, + outline.colorTop.toChromaColor().rgb, + outline.colorBottom.toChromaColor().rgb, + outline.thickness, + outline.blur, + horizontalAlign = RenderUtils.HorizontalAlignment.CENTER, + verticalAlign = RenderUtils.VerticalAlignment.CENTER, + ) + } + } + + private fun BackgroundConfig.createBackground(renderable: Renderable): Renderable = + if (backgroundConfig.useCustomBackgroundImage) { Renderable.drawInsideImage( renderable, textureLocation, (backgroundConfig.customBackgroundImageOpacity * 255) / 100, - padding, + borderSize, horizontalAlign = RenderUtils.HorizontalAlignment.CENTER, verticalAlign = RenderUtils.VerticalAlignment.CENTER, radius = backgroundConfig.roundedCornerSmoothness, @@ -35,7 +54,7 @@ object RenderBackground { Renderable.drawInsideRoundedRect( renderable, backgroundConfig.color.toChromaColor(), - padding, + borderSize, backgroundConfig.roundedCornerSmoothness, 1, horizontalAlign = RenderUtils.HorizontalAlignment.CENTER, @@ -43,21 +62,6 @@ object RenderBackground { ) } - return if (outlineConfig.enabled) { - Renderable.drawInsideRoundedRectOutline( - backgroundRenderable, - 0, - backgroundConfig.roundedCornerSmoothness, - 1, - outlineConfig.colorTop.toChromaColor().rgb, - outlineConfig.colorBottom.toChromaColor().rgb, - outlineConfig.thickness, - outlineConfig.blur, - horizontalAlign = RenderUtils.HorizontalAlignment.CENTER, - verticalAlign = RenderUtils.VerticalAlignment.CENTER, - ) - } else backgroundRenderable - } internal fun updatePosition(renderable: Renderable) { if (GuiEditManager.isInGui()) return @@ -73,24 +77,41 @@ object RenderBackground { val scaledWidth = ScaledResolution(Minecraft.getMinecraft()).scaledWidth val scaledHeight = ScaledResolution(Minecraft.getMinecraft()).scaledHeight - val elementWidth = renderable.width - val elementHeight = renderable.height + val elementWidth = (renderable.width * position.effectiveScale).toInt() + val elementHeight = (renderable.height * position.effectiveScale).toInt() with(alignmentConfig) { - val x = when (horizontalAlignment) { + var x = when (horizontalAlignment) { RenderUtils.HorizontalAlignment.DONT_ALIGN -> position.getAbsX() RenderUtils.HorizontalAlignment.LEFT -> 0 + margin RenderUtils.HorizontalAlignment.CENTER -> scaledWidth / 2 - elementWidth / 2 RenderUtils.HorizontalAlignment.RIGHT -> scaledWidth - elementWidth - margin else -> 0 } - val y = when (verticalAlignment) { + var y = when (verticalAlignment) { RenderUtils.VerticalAlignment.DONT_ALIGN -> position.getAbsY() RenderUtils.VerticalAlignment.TOP -> 0 + margin RenderUtils.VerticalAlignment.CENTER -> scaledHeight / 2 - elementHeight / 2 RenderUtils.VerticalAlignment.BOTTOM -> scaledHeight - elementHeight - margin else -> 0 } + + val outlineConfig = backgroundConfig.outline + if (outlineConfig.enabled) { + val thickness = outlineConfig.thickness + + when (horizontalAlignment) { + RenderUtils.HorizontalAlignment.RIGHT -> x -= thickness / 2 + RenderUtils.HorizontalAlignment.LEFT -> x += thickness / 2 + else -> x + } + + when (verticalAlignment) { + RenderUtils.VerticalAlignment.TOP -> y += thickness / 2 + RenderUtils.VerticalAlignment.BOTTOM -> y -= thickness / 2 + else -> y + } + } CustomScoreboard.config.position.moveTo(x, y) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt index 57376dbbb..88072abc1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt @@ -411,7 +411,7 @@ private fun getMotesDisplayPair(): List { private fun getMotesShowWhen() = inAnyIsland(IslandType.THE_RIFT) private fun getBankDisplayPair(): List { - val bank = getBank() + val bank = getBank() ?: "0" return listOf( when { -- cgit