aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorJ10a1n15 <45315647+j10a1n15@users.noreply.github.com>2024-08-26 03:29:32 +0200
committerGitHub <noreply@github.com>2024-08-26 03:29:32 +0200
commit0c98d82a100c97f3b0042a75edd87bed57341fa2 (patch)
tree58924b42bf37940e563e3475d3ee328d3dc2e404 /src/main/java/at/hannibal2/skyhanni/features
parent2b43ecc2a03c0e03fd51674cbd2b3cff3e9ba711 (diff)
downloadskyhanni-0c98d82a100c97f3b0042a75edd87bed57341fa2.tar.gz
skyhanni-0c98d82a100c97f3b0042a75edd87bed57341fa2.tar.bz2
skyhanni-0c98d82a100c97f3b0042a75edd87bed57341fa2.zip
Fix: Custom Scoreboard Issues (#2402)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt19
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt73
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt2
3 files changed, 63 insertions, 31 deletions
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<ScoreboardElementType> {
private fun getMotesShowWhen() = inAnyIsland(IslandType.THE_RIFT)
private fun getBankDisplayPair(): List<ScoreboardElementType> {
- val bank = getBank()
+ val bank = getBank() ?: "0"
return listOf(
when {