fixed a bug where closing the inventory ui while tooltip is showing will make it persist when the ui is opened again

This commit is contained in:
minjaesong
2022-03-12 17:52:48 +09:00
parent 54f1f590c4
commit 40a7c6876a
11 changed files with 87 additions and 17 deletions

View File

@@ -140,6 +140,7 @@ internal class UIInventoryCells(
}
override fun show() {
UIItemInventoryItemGrid.tooltipShowing.clear()
INGAME.setTooltipMessage(null)
}
@@ -153,6 +154,8 @@ internal class UIInventoryCells(
}
override fun endClosing(delta: Float) {
UIItemInventoryItemGrid.tooltipShowing.clear()
INGAME.setTooltipMessage(null)
}
override fun dispose() {

View File

@@ -239,9 +239,11 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
)
override fun show() {
UIItemInventoryItemGrid.tooltipShowing.clear()
INGAME.setTooltipMessage(null)
}
override fun updateUI(delta: Float) {
val yeet = screens[screen]
if (oldScreen != screen) {
@@ -311,6 +313,8 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
override fun endClosing(delta: Float) {
screen = 0
UIItemInventoryItemGrid.tooltipShowing.clear()
INGAME.setTooltipMessage(null)
}
override fun dispose() {

View File

@@ -233,6 +233,16 @@ class UIInventoryFull(
}
override fun show() {
transitionPanel.show()
UIItemInventoryItemGrid.tooltipShowing.clear()
INGAME.setTooltipMessage(null)
}
override fun hide() {
transitionPanel.hide()
}
internal var offsetX = ((width - internalWidth) / 2).toFloat()
private set
internal var offsetY = ((App.scr.height - internalHeight) / 2).toFloat()
@@ -308,6 +318,10 @@ class UIInventoryFull(
override fun endClosing(delta: Float) {
INGAME.setTooltipMessage(null) // required!
// MinimapComposer.revalidateAll()
UIItemInventoryItemGrid.tooltipShowing.clear()
// printdbg(this, "Clearing out tooltipShowing")
}

View File

@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.UIItemInventoryCatBar.Companion.CAT_ALL
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameitems.GameItem
@@ -49,6 +50,8 @@ class UIItemInventoryItemGrid(
//override var oldPosX = posX
//override var oldPosY = posY
private val hash = System.nanoTime()
override val width = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
override val height = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
@@ -163,7 +166,8 @@ class UIItemInventoryItemGrid(
}
// COMMON variables because more than one instance of this can be up on the screen
private val tooltipShowing = HashMap<UIItemInventoryItemGrid, Boolean>()
// This variable must be emptied out when the parent UI hides/closes
val tooltipShowing = HashMap<Long, Boolean>() // Long: `hash` field on UIItemInventoryItemGrid
}
private val itemGrid = Array<UIItemInventoryCellBase>(horizontalCells * verticalCells) {
@@ -350,15 +354,17 @@ class UIItemInventoryItemGrid(
super.update(delta)
tooltipShowing[this] = false
tooltipShowing[hash] = false
// printdbg(this, tooltipShowing.entries)
items.forEach {
it.update(delta)
// set tooltip accordingly
if ((App.IS_DEVELOPMENT_BUILD || isCompactMode) && it.item != null && it.mouseUp && tooltipShowing[this] != true) {
if ((App.IS_DEVELOPMENT_BUILD || isCompactMode) && tooltipShowing[hash] != true && it.item != null && it.mouseUp) {
// printdbg(this, "calling INGAME.setTooltipMessage by $hash")
INGAME.setTooltipMessage(
if (App.IS_DEVELOPMENT_BUILD) {
it.item?.name + "\n(${it.item?.originalID}${if (it.item?.originalID == it.item?.dynamicID) "" else "/${it.item?.dynamicID}"})"
@@ -368,7 +374,8 @@ class UIItemInventoryItemGrid(
}
)
tooltipShowing[this] = true
tooltipShowing[hash] = true
// printdbg(this, tooltipShowing.entries)
}
}
@@ -464,11 +471,11 @@ class UIItemInventoryItemGrid(
}
override fun dispose() {
tooltipShowing.remove(this)
tooltipShowing.remove(hash)
}
override fun hide() {
tooltipShowing.remove(this)
tooltipShowing.remove(hash)
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {