mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 12:34:05 +09:00
tooltipmanager
This commit is contained in:
@@ -6,6 +6,7 @@ import com.badlogic.gdx.utils.Disposable
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.TooltipListener
|
||||
import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
|
||||
import kotlin.math.max
|
||||
import kotlin.math.roundToInt
|
||||
@@ -63,7 +64,7 @@ abstract class UICanvas(
|
||||
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
|
||||
customPositioning: Boolean = false, // mainly used by vital meter
|
||||
doNotWarnConstant: Boolean = false
|
||||
): Disposable {
|
||||
): TooltipListener(), Disposable {
|
||||
|
||||
internal var openingClickLatched = false
|
||||
|
||||
@@ -136,6 +137,7 @@ abstract class UICanvas(
|
||||
/** A function that is run ONCE when the UI is requested to be opened; will work identical to [endOpening] if [openCloseTime] is zero */
|
||||
open fun show() {
|
||||
openingClickLatched = true
|
||||
clearTooltip()
|
||||
uiItems.forEach { it.show() }
|
||||
handler.subUIs.forEach { it.show() }
|
||||
}
|
||||
@@ -183,6 +185,7 @@ abstract class UICanvas(
|
||||
*/
|
||||
open fun endOpening(delta: Float) {
|
||||
handler.opacity = 1f
|
||||
clearTooltip()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,6 +193,7 @@ abstract class UICanvas(
|
||||
*/
|
||||
open fun endClosing(delta: Float) {
|
||||
handler.opacity = 0f
|
||||
clearTooltip()
|
||||
}
|
||||
|
||||
abstract override fun dispose()
|
||||
|
||||
@@ -14,7 +14,6 @@ import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.defaultInventoryCellTheme
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.tooltipShowing
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
@@ -131,7 +130,7 @@ class UIItemInventoryElemSimple(
|
||||
|
||||
|
||||
// set tooltip accordingly
|
||||
if (tooltipShowing[tooltipHash] != true && mouseUp) {
|
||||
if (!tooltipAcquired() && mouseUp) {
|
||||
// printdbg(this, "calling INGAME.setTooltipMessage by $hash")
|
||||
|
||||
val grey = App.fontGame.toColorCode(11, 11, 11)
|
||||
@@ -142,10 +141,7 @@ class UIItemInventoryElemSimple(
|
||||
|
||||
val finalStr = if (descStr != null) "$nameStr\n$grey$descStr" else nameStr
|
||||
|
||||
INGAME.setTooltipMessage(finalStr)
|
||||
|
||||
tooltipShowing[tooltipHash] = true
|
||||
// printdbg(this, tooltipShowing.entries)
|
||||
acquireTooltip(finalStr)
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -159,7 +155,7 @@ class UIItemInventoryElemSimple(
|
||||
}
|
||||
|
||||
if (item == null || !mouseUp) {
|
||||
tooltipShowing[tooltipHash] = false
|
||||
releaseTooltip()
|
||||
}
|
||||
|
||||
// see IFs above?
|
||||
@@ -168,10 +164,10 @@ class UIItemInventoryElemSimple(
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
tooltipShowing.remove(tooltipHash)
|
||||
removeFromTooltipRecord()
|
||||
}
|
||||
|
||||
override fun hide() {
|
||||
tooltipShowing.remove(tooltipHash)
|
||||
removeFromTooltipRecord()
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ import net.torvald.terrarum.modulebasegame.ui.InventoryCellColourTheme
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.tooltipShowing
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/***
|
||||
@@ -159,7 +158,7 @@ class UIItemInventoryElemWide(
|
||||
|
||||
|
||||
// set tooltip accordingly
|
||||
if (tooltipShowing[tooltipHash] != true && item != null && mouseUp) {
|
||||
if (!tooltipAcquired() && item != null && mouseUp) {
|
||||
// printdbg(this, "calling INGAME.setTooltipMessage by $hash")
|
||||
|
||||
val grey = App.fontGame.toColorCode(11, 11, 11)
|
||||
@@ -170,15 +169,12 @@ class UIItemInventoryElemWide(
|
||||
|
||||
val finalStr = if (descStr != null) "$nameStr\n$grey$descStr" else nameStr
|
||||
|
||||
INGAME.setTooltipMessage(finalStr)
|
||||
|
||||
tooltipShowing[tooltipHash] = true
|
||||
// printdbg(this, tooltipShowing.entries)
|
||||
acquireTooltip(finalStr)
|
||||
}
|
||||
}
|
||||
|
||||
if (item == null || !mouseUp) {
|
||||
tooltipShowing[tooltipHash] = false
|
||||
releaseTooltip()
|
||||
}
|
||||
|
||||
// see IFs above?
|
||||
@@ -186,10 +182,10 @@ class UIItemInventoryElemWide(
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
tooltipShowing.remove(tooltipHash)
|
||||
removeFromTooltipRecord()
|
||||
}
|
||||
|
||||
override fun hide() {
|
||||
tooltipShowing.remove(tooltipHash)
|
||||
removeFromTooltipRecord()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.torvald.terrarum.ui
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.utils.Disposable
|
||||
import net.torvald.terrarum.TooltipListener
|
||||
import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
|
||||
|
||||
/**
|
||||
@@ -28,7 +29,7 @@ abstract class UITemplate(val parent: UICanvas) : UIItemisable() {
|
||||
/**
|
||||
* Created by minjaesong on 2024-01-29.
|
||||
*/
|
||||
abstract class UIItemisable : Disposable {
|
||||
abstract class UIItemisable : TooltipListener(), Disposable {
|
||||
abstract fun update(delta: Float)
|
||||
abstract fun render(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera)
|
||||
open fun show() {}
|
||||
|
||||
Reference in New Issue
Block a user