mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 04:24:05 +09:00
tooltip UI; tooltip in the inventory
This commit is contained in:
@@ -69,7 +69,7 @@ class UIInventoryFull(
|
||||
val catSelectedIcon: Int
|
||||
get() = catBar.selectedIcon
|
||||
|
||||
override var openCloseTime: Second = 0.1f
|
||||
override var openCloseTime: Second = 0.0f
|
||||
|
||||
|
||||
private val itemList: UIItemInventoryDynamicList? =
|
||||
@@ -227,15 +227,18 @@ class UIInventoryFull(
|
||||
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
Terrarum.ingame?.setTooltipMessage(null)
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
Terrarum.ingame?.setTooltipMessage(null)
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
Terrarum.ingame?.setTooltipMessage(null) // required!!
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import net.torvald.terrarum.BlendMode
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.UIItemInventoryElem
|
||||
import net.torvald.terrarum.UIItemInventoryElemSimple
|
||||
import net.torvald.terrarum.console.Inventory
|
||||
import net.torvald.terrarum.gameactors.ActorInventory
|
||||
import net.torvald.terrarum.gameactors.InventoryPair
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
@@ -109,7 +108,7 @@ class UIItemInventoryDynamicList(
|
||||
private var items: Array<UIItemInventoryCellBase>
|
||||
= if (catArrangement[selection] in compactViewCat) itemGrid else itemList // this is INIT code
|
||||
|
||||
var isCompactView = (catArrangement[selection] in compactViewCat) // this is INIT code
|
||||
var isCompactMode = (catArrangement[selection] in compactViewCat) // this is INIT code
|
||||
set(value) {
|
||||
items = if (value) itemGrid else itemList
|
||||
|
||||
@@ -118,6 +117,7 @@ class UIItemInventoryDynamicList(
|
||||
field = value
|
||||
}
|
||||
|
||||
/** Long/compact mode buttons */
|
||||
private val gridModeButtons = Array<UIItemImageButton>(2, { index ->
|
||||
val iconPosX = posX - 12 - parentUI.catIcons.tileW + 2
|
||||
val iconPosY = posY - 2 + (4 + UIItemInventoryElem.height - parentUI.catIcons.tileH) * index
|
||||
@@ -135,16 +135,16 @@ class UIItemInventoryDynamicList(
|
||||
|
||||
init {
|
||||
// initially highlight grid mode buttons
|
||||
gridModeButtons[if (isCompactView) 1 else 0].highlighted = true
|
||||
gridModeButtons[if (isCompactMode) 1 else 0].highlighted = true
|
||||
|
||||
|
||||
gridModeButtons[0].touchDownListener = { _, _, _, _ ->
|
||||
isCompactView = false
|
||||
isCompactMode = false
|
||||
gridModeButtons[0].highlighted = true
|
||||
gridModeButtons[1].highlighted = false
|
||||
}
|
||||
gridModeButtons[1].touchDownListener = { _, _, _, _ ->
|
||||
isCompactView = true
|
||||
isCompactMode = true
|
||||
gridModeButtons[0].highlighted = false
|
||||
gridModeButtons[1].highlighted = true
|
||||
}
|
||||
@@ -166,7 +166,26 @@ class UIItemInventoryDynamicList(
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
|
||||
items.forEach { it.update(delta) }
|
||||
var tooltipSet = false
|
||||
|
||||
|
||||
|
||||
items.forEach {
|
||||
it.update(delta)
|
||||
|
||||
|
||||
// set tooltip accordingly
|
||||
if (isCompactMode && it.mouseUp && !tooltipSet) {
|
||||
Terrarum.ingame?.setTooltipMessage(it.item?.name)
|
||||
tooltipSet = true
|
||||
}
|
||||
}
|
||||
|
||||
if (!tooltipSet) {
|
||||
Terrarum.ingame?.setTooltipMessage(null)
|
||||
}
|
||||
|
||||
|
||||
|
||||
gridModeButtons.forEach { it.update(delta) }
|
||||
}
|
||||
|
||||
74
src/net/torvald/terrarum/ui/UITooltip.kt
Normal file
74
src/net/torvald/terrarum/ui/UITooltip.kt
Normal file
@@ -0,0 +1,74 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.fillRect
|
||||
import net.torvald.terrarum.gameactors.Second
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-11-25.
|
||||
*/
|
||||
class UITooltip : UICanvas() {
|
||||
|
||||
override var openCloseTime: Second = 0f
|
||||
|
||||
var message: String = ""
|
||||
|
||||
private val textures = TextureRegionPack("assets/graphics/gui/tooltip_black.tga", 8, 36)
|
||||
|
||||
private val font = Terrarum.fontGame
|
||||
|
||||
val textMarginX = 4
|
||||
|
||||
override var width: Int
|
||||
get() = font.getWidth(message) + (textMarginX + textures.tileW) * 2
|
||||
set(value) { throw Error("You are not supposed to set the width of the tooltip manually.") }
|
||||
override var height: Int
|
||||
get() = textures.tileH
|
||||
set(value) { throw Error("You are not supposed to set the height of the tooltip manually.") }
|
||||
|
||||
|
||||
init {
|
||||
textures.texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
val mouseX = Terrarum.mouseScreenX.toFloat()
|
||||
val mouseY = Terrarum.mouseScreenY.toFloat()
|
||||
|
||||
val tooltipY = mouseY - textures.tileH
|
||||
|
||||
val txtW = font.getWidth(message) + 2f * textMarginX
|
||||
|
||||
batch.color = Color.WHITE
|
||||
batch.draw(textures.get(0, 0), mouseX, tooltipY)
|
||||
batch.draw(textures.get(1, 0), mouseX + textures.tileW, tooltipY, txtW, height.toFloat())
|
||||
batch.draw(textures.get(2, 0), mouseX + textures.tileW + txtW, tooltipY)
|
||||
font.draw(batch, message, mouseX + textures.tileW + textMarginX, mouseY - textures.tileH + (textures.tileH - font.lineHeight) / 2)
|
||||
}
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
textures.dispose()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user