mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-09 21:31:51 +09:00
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:
@@ -30,6 +30,7 @@ module Terrarum {
|
||||
requires org.graalvm.sdk;
|
||||
requires com.ibm.icu;
|
||||
requires org.lwjgl.opengl;
|
||||
requires prtree;
|
||||
|
||||
|
||||
exports net.torvald.colourutil;
|
||||
|
||||
@@ -392,6 +392,8 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
|
||||
uiTooltip.setAsOpen()
|
||||
}
|
||||
uiTooltip.message = message
|
||||
|
||||
// printStackTrace(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -167,6 +167,9 @@ internal class UIStorageChest : UICanvas(
|
||||
itemListUpdate()
|
||||
|
||||
openingClickLatched = Terrarum.mouseDown
|
||||
|
||||
UIItemInventoryItemGrid.tooltipShowing.clear()
|
||||
INGAME.setTooltipMessage(null)
|
||||
}
|
||||
|
||||
private fun itemListUpdate() {
|
||||
@@ -276,6 +279,7 @@ internal class UIStorageChest : UICanvas(
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
UIItemInventoryItemGrid.tooltipShowing.clear()
|
||||
INGAME.setTooltipMessage(null) // required!
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.torvald.terrarum.modulebasegame.ui.UIInventoryCells
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.listGap
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItemSpinner
|
||||
import net.torvald.terrarum.ui.UIItemTextButton
|
||||
|
||||
/**
|
||||
@@ -34,7 +35,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
|
||||
private val itemListPlayer: UIItemInventoryItemGrid
|
||||
private val itemListCraftable: UIItemInventoryItemGrid
|
||||
private val buttonCraft: UIItemTextButton
|
||||
private val buttonCancel: UIItemTextButton
|
||||
private val spinnerCraftCount: UIItemSpinner
|
||||
|
||||
private val fakeInventory = FixtureInventory()
|
||||
|
||||
@@ -82,15 +83,12 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
|
||||
}
|
||||
)
|
||||
|
||||
buttonCancel = UIItemTextButton(this, "MENU_LABEL_CANCEL", thisOffsetX + 1, craftButtonsY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true)
|
||||
buttonCraft = UIItemTextButton(this, "GAME_ACTION_CRAFT", thisOffsetX + 3 + buttonWidth + listGap, craftButtonsY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true)
|
||||
spinnerCraftCount = UIItemSpinner(this, thisOffsetX + 1, craftButtonsY, 1, 1, 100, 1, buttonWidth)
|
||||
|
||||
buttonCraft.touchDownListener = { _,_,_,_ ->
|
||||
printdbg(this, "Craft!")
|
||||
}
|
||||
buttonCancel.touchDownListener = { _,_,_,_ ->
|
||||
printdbg(this, "Cancel!")
|
||||
}
|
||||
|
||||
// make grid mode buttons work together
|
||||
itemListCraftable.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) }
|
||||
@@ -121,7 +119,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
|
||||
|
||||
addUIitem(itemListCraftable)
|
||||
addUIitem(itemListPlayer)
|
||||
addUIitem(buttonCancel)
|
||||
addUIitem(spinnerCraftCount)
|
||||
addUIitem(buttonCraft)
|
||||
}
|
||||
|
||||
@@ -134,10 +132,15 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
|
||||
|
||||
override fun show() {
|
||||
itemListPlayer.getInventory = { INGAME.actorNowPlaying!!.inventory }
|
||||
|
||||
itemListUpdate()
|
||||
|
||||
openingClickLatched = Terrarum.mouseDown
|
||||
|
||||
spinnerCraftCount.value = 1
|
||||
spinnerCraftCount.fboUpdateLatch = true
|
||||
|
||||
UIItemInventoryItemGrid.tooltipShowing.clear()
|
||||
INGAME.setTooltipMessage(null)
|
||||
}
|
||||
|
||||
private var encumbrancePerc = 0f
|
||||
@@ -174,9 +177,8 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
|
||||
}
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
catBar.update(delta)
|
||||
itemListCraftable.update(delta)
|
||||
itemListPlayer.update(delta)
|
||||
// NO super.update due to an infinite recursion
|
||||
this.uiItems.forEach { it.update(delta) }
|
||||
|
||||
if (openingClickLatched && !Terrarum.mouseDown) openingClickLatched = false
|
||||
}
|
||||
@@ -257,6 +259,11 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
|
||||
spinnerCraftCount.value = 1 // hide() is required as show() is not called unless the parent's panel number has changed (?)
|
||||
spinnerCraftCount.fboUpdateLatch = true
|
||||
|
||||
UIItemInventoryItemGrid.tooltipShowing.clear()
|
||||
INGAME.setTooltipMessage(null) // required!
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -34,6 +34,26 @@ import kotlin.math.roundToInt
|
||||
*
|
||||
* PosX/Y and relativeMouseX/Y are explained in ```work_files/terrarum_ui_elements_coord_explained.png```
|
||||
*
|
||||
* ## Show/Hide/Opening/Closing Timeline
|
||||
*
|
||||
* The functions `show`, `doOpening`, `doClosing`, `hide`, `endOpening`, `endClosing` are called sequentially in this order:
|
||||
*
|
||||
* ```
|
||||
* (open has triggered)
|
||||
* show()
|
||||
* doOpening()
|
||||
* doOpening()
|
||||
* ...
|
||||
* endOpening()
|
||||
* ...
|
||||
* (close has triggered)
|
||||
* hide()
|
||||
* doClosing()
|
||||
* doClosing()
|
||||
* ...
|
||||
* endClosing()
|
||||
* ```
|
||||
*
|
||||
* Created by minjaesong on 2015-12-31.
|
||||
*/
|
||||
abstract class UICanvas(
|
||||
|
||||
@@ -34,7 +34,7 @@ class UIItemSpinner(
|
||||
private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, width - 2*buttonW - 6, height - 4, false)
|
||||
|
||||
var value = initialValue.coerceIn(min, max)
|
||||
private var fboUpdateLatch = true
|
||||
var fboUpdateLatch = true
|
||||
|
||||
private var mouseOnButton = 0 // 0: nothing, 1: left, 2: right
|
||||
|
||||
|
||||
@@ -124,6 +124,14 @@ open class UIItemTransitionContainer(
|
||||
return true
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
uis.forEach { it.show() }
|
||||
}
|
||||
|
||||
override fun hide() {
|
||||
uis.forEach { it.hide() }
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
uis.forEach { it.dispose() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user