fixed a bug where non-square items won't draw to the center of the UI cells (e.g. the inventory)

This commit is contained in:
minjaesong
2021-09-21 11:59:57 +09:00
parent 26c71e691c
commit 9e3bc09cee
2 changed files with 9 additions and 4 deletions

View File

@@ -44,8 +44,10 @@ class UIItemInventoryElemSimple(
override val width = UIItemInventoryElemSimple.height
override val height = UIItemInventoryElemSimple.height
private val imgOffset: Float
private val imgOffsetY: Float
get() = (this.height - itemImage!!.regionHeight).div(2).toFloat() // to snap to the pixel grid
private val imgOffsetX: Float
get() = (this.height - itemImage!!.regionWidth).div(2).toFloat() // to snap to the pixel grid
override fun update(delta: Float) {
@@ -79,7 +81,7 @@ class UIItemInventoryElemSimple(
// item image
batch.color = Color.WHITE
batch.draw(itemImage, posX + imgOffset, posY + imgOffset)
batch.draw(itemImage, posX + imgOffsetX, posY + imgOffsetY)
// if mouse is over, text lights up
// this one-liner sets color

View File

@@ -49,8 +49,11 @@ class UIItemInventoryElemWide(
override val height = UIItemInventoryElemWide.height
private val imgOffset: Float
private val imgOffsetY: Float
get() = (this.height - itemImage!!.regionHeight).div(2).toFloat() // to snap to the pixel grid
private val imgOffsetX: Float
get() = (this.height - itemImage!!.regionWidth).div(2).toFloat() // NOTE we're using this.height to get horizontal value; this is absofreakinlutely intentional (otherwise images would draw center of this wide cell which is not something we want)
private val textOffsetX = 50f
private val textOffsetY = 8f
@@ -96,7 +99,7 @@ class UIItemInventoryElemWide(
// item image
batch.color = Color.WHITE
batch.draw(itemImage, posX + imgOffset, posY + imgOffset)
batch.draw(itemImage, posX + imgOffsetX, posY + imgOffsetY)
// if mouse is over, text lights up
// this one-liner sets color