aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJ10a1n15 <45315647+j10a1n15@users.noreply.github.com>2024-04-30 19:12:23 +0200
committerGitHub <noreply@github.com>2024-04-30 19:12:23 +0200
commitab49f89977c19cc8eba7911c073a9d74ede1eadf (patch)
treea7bcd2ef05478a92c2e29be350d5f0624b504dcd /src
parent249e02778ce9543afc515ee4c7b5a57e154ac61d (diff)
downloadskyhanni-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')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/AlignmentConfig.java20
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/CustomScoreboard.kt31
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt103
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt18
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableUtils.kt2
6 files changed, 121 insertions, 55 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt
index 9a08a2385..faeab5a00 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt
@@ -12,7 +12,7 @@ import com.google.gson.JsonPrimitive
object ConfigUpdaterMigrator {
val logger = LorenzLogger("ConfigMigration")
- const val CONFIG_VERSION = 42
+ const val CONFIG_VERSION = 43
fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? {
if (chain.isEmpty()) return this
if (this !is JsonObject) return null
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/AlignmentConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/AlignmentConfig.java
index b63db9b51..0b62bfcbc 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/AlignmentConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/gui/customscoreboard/AlignmentConfig.java
@@ -1,20 +1,20 @@
package at.hannibal2.skyhanni.config.features.gui.customscoreboard;
+import at.hannibal2.skyhanni.utils.RenderUtils.HorizontalAlignment;
+import at.hannibal2.skyhanni.utils.RenderUtils.VerticalAlignment;
import com.google.gson.annotations.Expose;
-import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
+import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
public class AlignmentConfig {
- // TODO: Switch to Dropdowns with multiple different alignment ways in the future
- // Horizontal: Left, Center, Right
- // Vertical: Top, Center, Bottom
+
@Expose
- @ConfigOption(name = "Align to the right", desc = "Align the scoreboard to the right side of the screen.")
- @ConfigEditorBoolean
- public boolean alignRight = true;
+ @ConfigOption(name = "Horizontal Alignment", desc = "Alignment for the scoreboard on the horizontal axis.")
+ @ConfigEditorDropdown
+ public HorizontalAlignment horizontalAlignment = HorizontalAlignment.RIGHT;
@Expose
- @ConfigOption(name = "Align to the center vertically", desc = "Align the scoreboard to the center of the screen vertically.")
- @ConfigEditorBoolean
- public boolean alignCenterVertically = true;
+ @ConfigOption(name = "Vertical Alignment", desc = "Alignment for the scoreboard on the vertical axis.")
+ @ConfigEditorDropdown
+ public VerticalAlignment verticalAlignment = VerticalAlignment.CENTER;
}
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
+ )
+ }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
index b89850608..3de627f50 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
@@ -47,17 +47,20 @@ object RenderUtils {
LEFT("Left"),
CENTER("Center"),
RIGHT("Right"),
+ DONT_ALIGN("Don't Align"),
;
- override fun toString(): String {
- return value
- }
+ override fun toString() = value
}
- enum class VerticalAlignment {
- TOP,
- CENTER,
- BOTTOM,
+ enum class VerticalAlignment(private val value: String) {
+ TOP("Top"),
+ CENTER("Center"),
+ BOTTOM("Bottom"),
+ DONT_ALIGN("Don't Align"),
+ ;
+
+ override fun toString() = value
}
private val beaconBeam = ResourceLocation("textures/entity/beacon_beam.png")
@@ -497,6 +500,7 @@ object RenderUtils {
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)
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableUtils.kt
index 4af54b09f..e1f93574e 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableUtils.kt
@@ -35,12 +35,14 @@ internal object RenderableUtils {
HorizontalAlignment.LEFT -> 0
HorizontalAlignment.CENTER -> (xSpace - renderable.width) / 2
HorizontalAlignment.RIGHT -> xSpace - renderable.width
+ else -> 0
}
private fun calculateAlignmentYOffset(renderable: Renderable, ySpace: Int) = when (renderable.verticalAlign) {
VerticalAlignment.TOP -> 0
VerticalAlignment.CENTER -> (ySpace - renderable.height) / 2
VerticalAlignment.BOTTOM -> ySpace - renderable.height
+ else -> 0
}
fun Renderable.renderXYAligned(posX: Int, posY: Int, xSpace: Int, ySpace: Int) {