From e09871b5dae9e225ed2bae10f2fe83be81eb9d3b Mon Sep 17 00:00:00 2001 From: Bixilon Date: Thu, 21 Oct 2021 17:32:46 +0200 Subject: [PATCH] hud: fix some hotbar offset issues --- .../minosoft/gui/rendering/gui/elements/items/ItemElement.kt | 1 + .../rendering/gui/hud/elements/hotbar/HotbarBaseElement.kt | 2 +- .../gui/rendering/gui/hud/elements/hotbar/HotbarElement.kt | 3 +++ .../rendering/gui/hud/elements/hotbar/HotbarHealthElement.kt | 2 +- .../rendering/gui/hud/elements/hotbar/HotbarHungerElement.kt | 2 +- .../de/bixilon/minosoft/gui/rendering/util/vec/Vec4Util.kt | 5 +++++ 6 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/items/ItemElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/items/ItemElement.kt index 099f5528a..96cea20d3 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/items/ItemElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/items/ItemElement.kt @@ -51,6 +51,7 @@ class ItemElement( countText.text = when { count < 0 -> TextComponent((count < -99).decide({ "-∞" }, { count }), color = ChatColors.RED) // No clue why I do this... count == 0 -> TextComponent("0", color = ChatColors.YELLOW) + count == 1 -> TextComponent("") count > ProtocolDefinition.ITEM_STACK_MAX_SIZE -> TextComponent((count > 99).decide({ "∞" }, { count }), color = ChatColors.RED) else -> TextComponent(count) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarBaseElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarBaseElement.kt index 27878e4d8..ee502712e 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarBaseElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarBaseElement.kt @@ -76,7 +76,7 @@ class HotbarBaseElement(hudRenderer: HUDRenderer) : Element(hudRenderer), Pollab private val HOTBAR_BASE_SIZE = Vec2i(182, 22) private const val FRAME_SIZE = 24 - private const val HORIZONTAL_MARGIN = 1 + const val HORIZONTAL_MARGIN = 1 private const val FRAME_OFFSET = -2 // FRAME_SIZE - HOTBAR_BASE_SIZE.y } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarElement.kt index b13d24a91..3135db562 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarElement.kt @@ -22,6 +22,7 @@ import de.bixilon.minosoft.gui.rendering.gui.elements.layout.RowLayout import de.bixilon.minosoft.gui.rendering.gui.hud.HUDRenderer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer import de.bixilon.minosoft.gui.rendering.util.vec.Vec2Util.max +import de.bixilon.minosoft.gui.rendering.util.vec.Vec4Util.copy import glm_.vec2.Vec2i import java.lang.Integer.max @@ -51,10 +52,12 @@ class HotbarElement(hudRenderer: HUDRenderer) : Element(hudRenderer) { topLeft.apply { parent = this@HotbarElement spacing = VERTICAL_SPACING + margin = margin.copy(left = HotbarBaseElement.HORIZONTAL_MARGIN) } topRight.apply { parent = this@HotbarElement spacing = VERTICAL_SPACING + margin = margin.copy(right = HotbarBaseElement.HORIZONTAL_MARGIN) } topLeft += protection diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarHealthElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarHealthElement.kt index d4a663911..1e0877d21 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarHealthElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarHealthElement.kt @@ -222,7 +222,7 @@ class HotbarHealthElement(hudRenderer: HUDRenderer) : Element(hudRenderer), Poll rows++ } - _size = Vec2i(HEARTS_PER_ROW, rows) * HEART_SIZE + _size = Vec2i(HEARTS_PER_ROW, rows) * HEART_SIZE + Vec2i(1, 0) // 1 pixel is overlapping, so we have one more for the heart cacheUpToDate = false } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarHungerElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarHungerElement.kt index 799d4639e..af57fd6a4 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarHungerElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/hotbar/HotbarHungerElement.kt @@ -69,7 +69,7 @@ class HotbarHungerElement(hudRenderer: HUDRenderer) : Element(hudRenderer), Poll init { - size = Vec2i(HUNGER_CONTAINERS, 1) * HUNGER_SIZE + _size = Vec2i(HUNGER_CONTAINERS, 1) * HUNGER_SIZE + Vec2i(1, 0) // 1 pixel is overlapping per hunger, so one more } override fun forceRender(offset: Vec2i, z: Int, consumer: GUIVertexConsumer): Int { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/util/vec/Vec4Util.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/util/vec/Vec4Util.kt index c493e792b..f71659010 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/util/vec/Vec4Util.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/util/vec/Vec4Util.kt @@ -62,4 +62,9 @@ object Vec4Util { val Vec4i.offset: Vec2i get() = Vec2i(left, top) + + + fun Vec4i.copy(top: Int = this.top, right: Int = this.right, bottom: Int = this.bottom, left: Int = this.left): Vec4i { + return Vec4i(top, right, bottom, left) + } }