mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
tooltip UI; tooltip in the inventory
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
* Processor with 2.4 GHz speed
|
* Processor with 2.4 GHz speed
|
||||||
* GPU that can support OpenGL 2.1, is capable of 4K texture
|
* GPU that can support OpenGL 2.1, is capable of 4K texture
|
||||||
* 4 GB of RAM
|
* 6 GB of RAM
|
||||||
* 2 GB of free disk space
|
* 4 GB of free disk space
|
||||||
* Windows Vista/Mac OS X Lion or higher (Mac OS X Snow Leopard is incompatible with a shader the game uses)
|
* Windows Vista/Mac OS X Lion or higher (Mac OS X Snow Leopard is incompatible with a shader the game uses)
|
||||||
* PC: Java 8, Up-to-date graphics driver
|
* PC: Java 8, Up-to-date graphics driver
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
* Processor with 3.0 GHz speed, 4 threads available
|
* Processor with 3.0 GHz speed, 4 threads available
|
||||||
* GPU that can support OpenGL 2.1, is capable of 4K texture
|
* GPU that can support OpenGL 2.1, is capable of 4K texture
|
||||||
* 8 GB of RAM
|
* 8 GB of RAM
|
||||||
* 5 GB of free disk space
|
* 8 GB of free disk space
|
||||||
* Windows Vista/Mac OS X Lion or higher
|
* Windows Vista/Mac OS X Lion or higher
|
||||||
* PC: Java 8, Up-to-date graphics driver
|
* PC: Java 8, Up-to-date graphics driver
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -23,6 +23,7 @@ object CIEXYZUtil {
|
|||||||
return xyz.toColor()
|
return xyz.toColor()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Use one in CIELAB or CIELUV; CIEXYZ is not perceptually uniform")
|
||||||
fun getGradient(scale: Float, fromCol: Color, toCol: Color): Color {
|
fun getGradient(scale: Float, fromCol: Color, toCol: Color): Color {
|
||||||
val from = fromCol.toXYZ()
|
val from = fromCol.toXYZ()
|
||||||
val to = toCol.toXYZ()
|
val to = toCol.toXYZ()
|
||||||
|
|||||||
@@ -122,9 +122,10 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
lateinit var uiVitalSecondary: UICanvas
|
lateinit var uiVitalSecondary: UICanvas
|
||||||
lateinit var uiVitalItem: UICanvas // itemcount/durability of held block or active ammo of held gun. As for the block, max value is 500.
|
lateinit var uiVitalItem: UICanvas // itemcount/durability of held block or active ammo of held gun. As for the block, max value is 500.
|
||||||
|
|
||||||
lateinit var uiWatchBasic: UICanvas
|
private lateinit var uiWatchBasic: UICanvas
|
||||||
lateinit var uiWatchTierOne: UICanvas
|
private lateinit var uiWatchTierOne: UICanvas
|
||||||
|
|
||||||
|
private lateinit var uiTooltip: UITooltip
|
||||||
|
|
||||||
// UI aliases
|
// UI aliases
|
||||||
lateinit var uiAliases: ArrayList<UICanvas>
|
lateinit var uiAliases: ArrayList<UICanvas>
|
||||||
@@ -357,6 +358,9 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
uiWatchTierOne.setPosition(Terrarum.WIDTH - uiWatchTierOne.width, uiWatchBasic.height - 2)
|
uiWatchTierOne.setPosition(Terrarum.WIDTH - uiWatchTierOne.width, uiWatchBasic.height - 2)
|
||||||
|
|
||||||
|
|
||||||
|
uiTooltip = UITooltip()
|
||||||
|
|
||||||
|
|
||||||
// batch-process uiAliases
|
// batch-process uiAliases
|
||||||
uiAliases = arrayListOf(
|
uiAliases = arrayListOf(
|
||||||
// drawn first
|
// drawn first
|
||||||
@@ -367,7 +371,8 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
uiPieMenu,
|
uiPieMenu,
|
||||||
uiQuickBar,
|
uiQuickBar,
|
||||||
uiWatchBasic,
|
uiWatchBasic,
|
||||||
uiWatchTierOne
|
uiWatchTierOne,
|
||||||
|
uiTooltip
|
||||||
// drawn last
|
// drawn last
|
||||||
)
|
)
|
||||||
uiAlasesPausing = arrayListOf(
|
uiAlasesPausing = arrayListOf(
|
||||||
@@ -384,6 +389,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
updateThreadWrapper = Thread(ingameUpdateThread, "Terrarum UpdateThread")
|
updateThreadWrapper = Thread(ingameUpdateThread, "Terrarum UpdateThread")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LightmapRenderer.fireRecalculateEvent()
|
LightmapRenderer.fireRecalculateEvent()
|
||||||
}// END enter
|
}// END enter
|
||||||
|
|
||||||
@@ -1388,6 +1394,18 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setTooltipMessage(message: String?) {
|
||||||
|
if (message == null) {
|
||||||
|
uiTooltip.setAsClose()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (uiTooltip.isClosed || uiTooltip.isClosing) {
|
||||||
|
uiTooltip.setAsOpen()
|
||||||
|
}
|
||||||
|
uiTooltip.message = message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun pause() {
|
override fun pause() {
|
||||||
// TODO no pause when off-focus on desktop
|
// TODO no pause when off-focus on desktop
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ object Terrarum : Screen {
|
|||||||
private set
|
private set
|
||||||
|
|
||||||
val memInUse: Long
|
val memInUse: Long
|
||||||
get() = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) shr 20
|
get() = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() + Gdx.app.nativeHeap) shr 20
|
||||||
val memTotal: Long
|
val memTotal: Long
|
||||||
get() = Runtime.getRuntime().totalMemory() shr 20
|
get() = Runtime.getRuntime().totalMemory() shr 20
|
||||||
val memXmx: Long
|
val memXmx: Long
|
||||||
@@ -713,12 +713,16 @@ object Terrarum : Screen {
|
|||||||
return file // TODO TEST CODE
|
return file // TODO TEST CODE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Position of the cursor in the world */
|
||||||
inline val mouseX: Double
|
inline val mouseX: Double
|
||||||
get() = WorldCamera.x + Gdx.input.x / (ingame?.screenZoom ?: 1f).toDouble()
|
get() = WorldCamera.x + Gdx.input.x / (ingame?.screenZoom ?: 1f).toDouble()
|
||||||
|
/** Position of the cursor in the world */
|
||||||
inline val mouseY: Double
|
inline val mouseY: Double
|
||||||
get() = WorldCamera.y + Gdx.input.y / (ingame?.screenZoom ?: 1f).toDouble()
|
get() = WorldCamera.y + Gdx.input.y / (ingame?.screenZoom ?: 1f).toDouble()
|
||||||
|
/** Position of the cursor in the world */
|
||||||
@JvmStatic inline val mouseTileX: Int
|
@JvmStatic inline val mouseTileX: Int
|
||||||
get() = (mouseX / FeaturesDrawer.TILE_SIZE).floorInt()
|
get() = (mouseX / FeaturesDrawer.TILE_SIZE).floorInt()
|
||||||
|
/** Position of the cursor in the world */
|
||||||
@JvmStatic inline val mouseTileY: Int
|
@JvmStatic inline val mouseTileY: Int
|
||||||
get() = (mouseY / FeaturesDrawer.TILE_SIZE).floorInt()
|
get() = (mouseY / FeaturesDrawer.TILE_SIZE).floorInt()
|
||||||
inline val mouseScreenX: Int
|
inline val mouseScreenX: Int
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class UIInventoryFull(
|
|||||||
val catSelectedIcon: Int
|
val catSelectedIcon: Int
|
||||||
get() = catBar.selectedIcon
|
get() = catBar.selectedIcon
|
||||||
|
|
||||||
override var openCloseTime: Second = 0.1f
|
override var openCloseTime: Second = 0.0f
|
||||||
|
|
||||||
|
|
||||||
private val itemList: UIItemInventoryDynamicList? =
|
private val itemList: UIItemInventoryDynamicList? =
|
||||||
@@ -227,15 +227,18 @@ class UIInventoryFull(
|
|||||||
|
|
||||||
|
|
||||||
override fun doOpening(delta: Float) {
|
override fun doOpening(delta: Float) {
|
||||||
|
Terrarum.ingame?.setTooltipMessage(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doClosing(delta: Float) {
|
override fun doClosing(delta: Float) {
|
||||||
|
Terrarum.ingame?.setTooltipMessage(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun endOpening(delta: Float) {
|
override fun endOpening(delta: Float) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun endClosing(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.Terrarum
|
||||||
import net.torvald.terrarum.UIItemInventoryElem
|
import net.torvald.terrarum.UIItemInventoryElem
|
||||||
import net.torvald.terrarum.UIItemInventoryElemSimple
|
import net.torvald.terrarum.UIItemInventoryElemSimple
|
||||||
import net.torvald.terrarum.console.Inventory
|
|
||||||
import net.torvald.terrarum.gameactors.ActorInventory
|
import net.torvald.terrarum.gameactors.ActorInventory
|
||||||
import net.torvald.terrarum.gameactors.InventoryPair
|
import net.torvald.terrarum.gameactors.InventoryPair
|
||||||
import net.torvald.terrarum.itemproperties.GameItem
|
import net.torvald.terrarum.itemproperties.GameItem
|
||||||
@@ -109,7 +108,7 @@ class UIItemInventoryDynamicList(
|
|||||||
private var items: Array<UIItemInventoryCellBase>
|
private var items: Array<UIItemInventoryCellBase>
|
||||||
= if (catArrangement[selection] in compactViewCat) itemGrid else itemList // this is INIT code
|
= 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) {
|
set(value) {
|
||||||
items = if (value) itemGrid else itemList
|
items = if (value) itemGrid else itemList
|
||||||
|
|
||||||
@@ -118,6 +117,7 @@ class UIItemInventoryDynamicList(
|
|||||||
field = value
|
field = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Long/compact mode buttons */
|
||||||
private val gridModeButtons = Array<UIItemImageButton>(2, { index ->
|
private val gridModeButtons = Array<UIItemImageButton>(2, { index ->
|
||||||
val iconPosX = posX - 12 - parentUI.catIcons.tileW + 2
|
val iconPosX = posX - 12 - parentUI.catIcons.tileW + 2
|
||||||
val iconPosY = posY - 2 + (4 + UIItemInventoryElem.height - parentUI.catIcons.tileH) * index
|
val iconPosY = posY - 2 + (4 + UIItemInventoryElem.height - parentUI.catIcons.tileH) * index
|
||||||
@@ -135,16 +135,16 @@ class UIItemInventoryDynamicList(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
// initially highlight grid mode buttons
|
// initially highlight grid mode buttons
|
||||||
gridModeButtons[if (isCompactView) 1 else 0].highlighted = true
|
gridModeButtons[if (isCompactMode) 1 else 0].highlighted = true
|
||||||
|
|
||||||
|
|
||||||
gridModeButtons[0].touchDownListener = { _, _, _, _ ->
|
gridModeButtons[0].touchDownListener = { _, _, _, _ ->
|
||||||
isCompactView = false
|
isCompactMode = false
|
||||||
gridModeButtons[0].highlighted = true
|
gridModeButtons[0].highlighted = true
|
||||||
gridModeButtons[1].highlighted = false
|
gridModeButtons[1].highlighted = false
|
||||||
}
|
}
|
||||||
gridModeButtons[1].touchDownListener = { _, _, _, _ ->
|
gridModeButtons[1].touchDownListener = { _, _, _, _ ->
|
||||||
isCompactView = true
|
isCompactMode = true
|
||||||
gridModeButtons[0].highlighted = false
|
gridModeButtons[0].highlighted = false
|
||||||
gridModeButtons[1].highlighted = true
|
gridModeButtons[1].highlighted = true
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,26 @@ class UIItemInventoryDynamicList(
|
|||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
super.update(delta)
|
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) }
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
BIN
work_files/graphics/fonts/newrunes_large.psd
LFS
Normal file
BIN
work_files/graphics/fonts/newrunes_large.psd
LFS
Normal file
Binary file not shown.
Reference in New Issue
Block a user