diff options
author | J10a1n15 <45315647+j10a1n15@users.noreply.github.com> | 2024-04-30 19:12:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-30 19:12:23 +0200 |
commit | ab49f89977c19cc8eba7911c073a9d74ede1eadf (patch) | |
tree | a7bcd2ef05478a92c2e29be350d5f0624b504dcd /src/main/java/at/hannibal2/skyhanni/features/gui | |
parent | 249e02778ce9543afc515ee4c7b5a57e154ac61d (diff) | |
download | skyhanni-ab49f89977c19cc8eba7911c073a9d74ede1eadf.tar.gz skyhanni-ab49f89977c19cc8eba7911c073a9d74ede1eadf.tar.bz2 skyhanni-ab49f89977c19cc8eba7911c073a9d74ede1eadf.zip |
Improvement: Better Alignment + Outline Improvement in Custom Scoreboard (#1566)
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/gui')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt | 31 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt | 103 |
2 files changed, 97 insertions, 37 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 4182b37bb..7dca6c1b4 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 @@ -30,6 +30,7 @@ import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ConditionalUtils.onToggle import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.HorizontalAlignment +import at.hannibal2.skyhanni.utils.RenderUtils.VerticalAlignment import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAlignedWidth import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase import at.hannibal2.skyhanni.utils.TabListData @@ -70,10 +71,14 @@ class CustomScoreboard { @SubscribeEvent fun onGuiPositionMoved(event: GuiPositionMovedEvent) { if (event.guiName == guiName) { - if (alignmentConfig.alignRight || alignmentConfig.alignCenterVertically) { - alignmentConfig.alignRight = false - alignmentConfig.alignCenterVertically = false - ChatUtils.chat("Disabled Custom Scoreboard auto-alignment.") + with(alignmentConfig) { + if (horizontalAlignment != HorizontalAlignment.DONT_ALIGN + || verticalAlignment != VerticalAlignment.DONT_ALIGN + ) { + horizontalAlignment = HorizontalAlignment.DONT_ALIGN + verticalAlignment = VerticalAlignment.DONT_ALIGN + ChatUtils.chat("Disabled Custom Scoreboard auto-alignment.") + } } } } @@ -248,5 +253,23 @@ class CustomScoreboard { newArray } + event.move(43, "$displayPrefix.alignment.alignRight", "$displayPrefix.alignment.horizontalAlignment") { + JsonPrimitive( + if (it.asBoolean) { + HorizontalAlignment.RIGHT.name + } else { + HorizontalAlignment.DONT_ALIGN.name + } + ) + } + event.move(43, "$displayPrefix.alignment.alignCenterVertically", "$displayPrefix.alignment.verticalAlignment") { + JsonPrimitive( + if (it.asBoolean) { + VerticalAlignment.CENTER.name + } else { + VerticalAlignment.DONT_ALIGN.name + } + ) + } } } 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 2454946f5..c2de6152c 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 @@ -15,6 +15,7 @@ import net.minecraft.util.ResourceLocation import org.lwjgl.opengl.GL11 class RenderBackground { + fun renderBackground() { val alignmentConfig = CustomScoreboard.alignmentConfig val backgroundConfig = CustomScoreboard.backgroundConfig @@ -28,29 +29,12 @@ class RenderBackground { val elementWidth = position.getDummySize().x val elementHeight = position.getDummySize().y - val scaledWidth = ScaledResolution(Minecraft.getMinecraft()).scaledWidth - val scaledHeight = ScaledResolution(Minecraft.getMinecraft()).scaledHeight - // Update the position to the alignment options if ( - alignmentConfig.alignRight - || alignmentConfig.alignCenterVertically + alignmentConfig.horizontalAlignment != RenderUtils.HorizontalAlignment.DONT_ALIGN + || alignmentConfig.verticalAlignment != RenderUtils.VerticalAlignment.DONT_ALIGN ) { - var newX = if (alignmentConfig.alignRight) scaledWidth - elementWidth - (border * 2) else x - val newY = if (alignmentConfig.alignCenterVertically) scaledHeight / 2 - elementHeight / 2 else y - - if (outlineConfig.enabled) { - newX -= outlineConfig.thickness / 2 - } - - position.set( - Position( - newX, - newY, - position.getScale(), - position.isCenter - ) - ) + position.set(updatePosition(position)) } if (GuiEditManager.isInGui()) return @@ -82,23 +66,76 @@ class RenderBackground { backgroundConfig.color.toChromaColor().rgb, backgroundConfig.roundedCornerSmoothness ) - if (outlineConfig.enabled) { - RenderUtils.drawRoundRectOutline( - x - border, - y - border, - elementWidth + border * 3, - elementHeight + border * 2, - outlineConfig.colorTop.toChromaColor().rgb, - outlineConfig.colorBottom.toChromaColor().rgb, - outlineConfig.thickness, - backgroundConfig.roundedCornerSmoothness, - outlineConfig.blur - ) - } + } + if (outlineConfig.enabled) { + RenderUtils.drawRoundRectOutline( + x - border, + y - border, + elementWidth + border * 3, + elementHeight + border * 2, + outlineConfig.colorTop.toChromaColor().rgb, + outlineConfig.colorBottom.toChromaColor().rgb, + outlineConfig.thickness, + backgroundConfig.roundedCornerSmoothness, + outlineConfig.blur + ) } } GL11.glDepthMask(true) GlStateManager.popMatrix() GlStateManager.popAttrib() } + + private fun updatePosition(position: Position): Position { + val alignmentConfig = CustomScoreboard.alignmentConfig + val backgroundConfig = CustomScoreboard.backgroundConfig + val outlineConfig = backgroundConfig.outline + val border = backgroundConfig.borderSize + + val x = position.getAbsX() + val y = position.getAbsY() + + val elementWidth = position.getDummySize().x + val elementHeight = position.getDummySize().y + + val scaledWidth = ScaledResolution(Minecraft.getMinecraft()).scaledWidth + val scaledHeight = ScaledResolution(Minecraft.getMinecraft()).scaledHeight + + + var newX = when (alignmentConfig.horizontalAlignment) { + RenderUtils.HorizontalAlignment.LEFT -> border + RenderUtils.HorizontalAlignment.CENTER -> scaledWidth / 2 - (elementWidth + border * 3) / 2 + RenderUtils.HorizontalAlignment.RIGHT -> scaledWidth - (elementWidth + border * 2) + else -> x + } + + var newY = when (alignmentConfig.verticalAlignment) { + RenderUtils.VerticalAlignment.TOP -> border + RenderUtils.VerticalAlignment.CENTER -> scaledHeight / 2 - (elementHeight + border * 2) / 2 + RenderUtils.VerticalAlignment.BOTTOM -> scaledHeight - elementHeight - border + else -> y + } + + if (outlineConfig.enabled) { + val thickness = outlineConfig.thickness + if (alignmentConfig.horizontalAlignment == RenderUtils.HorizontalAlignment.RIGHT) { + newX -= thickness / 2 + } else if (alignmentConfig.horizontalAlignment == RenderUtils.HorizontalAlignment.LEFT) { + newX += thickness / 2 + } + + if (alignmentConfig.verticalAlignment == RenderUtils.VerticalAlignment.TOP) { + newY += thickness / 2 + } else if (alignmentConfig.verticalAlignment == RenderUtils.VerticalAlignment.BOTTOM) { + newY -= thickness / 2 + } + } + + return Position( + newX, + newY, + position.getScale(), + position.isCenter + ) + } } |