aboutsummaryrefslogtreecommitdiff
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
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>
-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
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt53
4 files changed, 64 insertions, 83 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 {
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
index f4a57cb18..0d6417688 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
@@ -4,7 +4,6 @@ import at.hannibal2.skyhanni.config.core.config.Position
import at.hannibal2.skyhanni.data.GuiEditManager
import at.hannibal2.skyhanni.data.GuiEditManager.getAbsX
import at.hannibal2.skyhanni.data.GuiEditManager.getAbsY
-import at.hannibal2.skyhanni.data.GuiEditManager.getDummySize
import at.hannibal2.skyhanni.data.model.Graph
import at.hannibal2.skyhanni.data.model.toPositionsList
import at.hannibal2.skyhanni.events.GuiContainerEvent
@@ -542,37 +541,6 @@ object RenderUtils {
return renderer.getStringWidth(display)
}
- // Aligns using the width of element to render
- private fun Position.renderString0(
- string: String?,
- offsetX: Int = 0,
- offsetY: Int = 0,
- alignmentEnum: HorizontalAlignment,
- ): Int {
- val display = "§f$string"
- GlStateManager.pushMatrix()
- transform()
- val minecraft = Minecraft.getMinecraft()
- val renderer = minecraft.renderManager.fontRenderer
- val width = this.getDummySize().x / this.scale
-
- GlStateManager.translate(offsetX + 1.0, offsetY + 1.0, 0.0)
-
- val strLen: Int = renderer.getStringWidth(string)
- val x2 = when (alignmentEnum) {
- HorizontalAlignment.LEFT -> offsetX.toFloat()
- HorizontalAlignment.CENTER -> offsetX + width / 2f - strLen / 2f
- HorizontalAlignment.RIGHT -> offsetX + width - strLen.toFloat()
- else -> offsetX.toFloat()
- }
- GL11.glTranslatef(x2, 0f, 0f)
- renderer.drawStringWithShadow(display, 0f, 0f, 0)
-
- GlStateManager.popMatrix()
-
- return renderer.getStringWidth(display)
- }
-
fun Position.renderStrings(list: List<String>, extraSpace: Int = 0, posLabel: String) {
if (list.isEmpty()) return
@@ -588,25 +556,6 @@ object RenderUtils {
GuiEditManager.add(this, posLabel, longestX, offsetY)
}
- fun Position.renderStringsAlignedWidth(
- list: List<Pair<String, HorizontalAlignment>>,
- extraSpace: Int = 0,
- posLabel: String,
- ) {
- if (list.isEmpty()) return
-
- var offsetY = 0
- var longestX = 0
- for (pair in list) {
- val x = renderString0(pair.first, offsetY = offsetY, alignmentEnum = pair.second)
- if (x > longestX) {
- longestX = x
- }
- offsetY += 10 + extraSpace
- }
- GuiEditManager.add(this, posLabel, longestX, offsetY)
- }
-
fun Position.renderRenderables(
renderables: List<Renderable>,
extraSpace: Int = 0,
@@ -698,7 +647,7 @@ object RenderUtils {
/**
* Accepts a single line to print.
- * This line is a list of things to print. Can print String or ItemStack objects.
+ * This line is a list of things to print. Can print String or ItemStack objects.
*/
@Deprecated("use List<Renderable>", ReplaceWith(""))
fun Position.renderSingleLineWithItems(