mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-08 12:51:51 +09:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user