From 35f2cf6b4d70685507c20ae6997db887faa7a990 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 25 Nov 2017 17:56:29 +0900 Subject: [PATCH] tooltip UI; tooltip in the inventory --- SYSTEM_REQUIREMENTS.md | 6 +- assets/graphics/fonts/numeric_small.tga | 2 +- assets/modules/basegame/fonts/7segnum.tga | 4 +- src/net/torvald/colourutil/CIEXYZUtil.kt | 1 + src/net/torvald/terrarum/Ingame.kt | 24 +++++- src/net/torvald/terrarum/Terrarum.kt | 6 +- .../torvald/terrarum/ui/UIInventoryFull.kt | 5 +- .../terrarum/ui/UIItemInventoryDynamicList.kt | 31 ++++++-- src/net/torvald/terrarum/ui/UITooltip.kt | 74 +++++++++++++++++++ work_files/UI/portable_computer_mockup.psd | 4 +- work_files/graphics/fonts/newrunes.psd | 4 +- work_files/graphics/fonts/newrunes_large.psd | 3 + 12 files changed, 143 insertions(+), 21 deletions(-) create mode 100644 src/net/torvald/terrarum/ui/UITooltip.kt create mode 100644 work_files/graphics/fonts/newrunes_large.psd diff --git a/SYSTEM_REQUIREMENTS.md b/SYSTEM_REQUIREMENTS.md index c56a8c892..fa9aa9feb 100644 --- a/SYSTEM_REQUIREMENTS.md +++ b/SYSTEM_REQUIREMENTS.md @@ -2,8 +2,8 @@ * Processor with 2.4 GHz speed * GPU that can support OpenGL 2.1, is capable of 4K texture -* 4 GB of RAM -* 2 GB of free disk space +* 6 GB of RAM +* 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) * PC: Java 8, Up-to-date graphics driver @@ -12,7 +12,7 @@ * Processor with 3.0 GHz speed, 4 threads available * GPU that can support OpenGL 2.1, is capable of 4K texture * 8 GB of RAM -* 5 GB of free disk space +* 8 GB of free disk space * Windows Vista/Mac OS X Lion or higher * PC: Java 8, Up-to-date graphics driver diff --git a/assets/graphics/fonts/numeric_small.tga b/assets/graphics/fonts/numeric_small.tga index 37a3cd6fa..d72eafacd 100644 --- a/assets/graphics/fonts/numeric_small.tga +++ b/assets/graphics/fonts/numeric_small.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5f867dba3e64de688decaaa909b426a2d22242d9d420a3a4587e2462d0ba5e82 +oid sha256:7560947ae44f39861dfd05239b9ed8b45f21b0b9efa7e579e73534f2f5ddf577 size 15404 diff --git a/assets/modules/basegame/fonts/7segnum.tga b/assets/modules/basegame/fonts/7segnum.tga index 7ad2a7d3b..c7d79dcf1 100644 --- a/assets/modules/basegame/fonts/7segnum.tga +++ b/assets/modules/basegame/fonts/7segnum.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ee9264365987bd11dbf39f9d1f2f1f347c688f4213a7370e285d3aae3f35b033 -size 8756 +oid sha256:07c17c9a81f660108bc8b0f30730dc05218d3c8abf5cf3b397de41c0f6d22e71 +size 13508 diff --git a/src/net/torvald/colourutil/CIEXYZUtil.kt b/src/net/torvald/colourutil/CIEXYZUtil.kt index 569289377..16e7fa23e 100644 --- a/src/net/torvald/colourutil/CIEXYZUtil.kt +++ b/src/net/torvald/colourutil/CIEXYZUtil.kt @@ -23,6 +23,7 @@ object CIEXYZUtil { return xyz.toColor() } + @Deprecated("Use one in CIELAB or CIELUV; CIEXYZ is not perceptually uniform") fun getGradient(scale: Float, fromCol: Color, toCol: Color): Color { val from = fromCol.toXYZ() val to = toCol.toXYZ() diff --git a/src/net/torvald/terrarum/Ingame.kt b/src/net/torvald/terrarum/Ingame.kt index bc20c7bca..9f9d5e4b8 100644 --- a/src/net/torvald/terrarum/Ingame.kt +++ b/src/net/torvald/terrarum/Ingame.kt @@ -122,9 +122,10 @@ class Ingame(val batch: SpriteBatch) : Screen { 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 uiWatchBasic: UICanvas - lateinit var uiWatchTierOne: UICanvas + private lateinit var uiWatchBasic: UICanvas + private lateinit var uiWatchTierOne: UICanvas + private lateinit var uiTooltip: UITooltip // UI aliases lateinit var uiAliases: ArrayList @@ -357,6 +358,9 @@ class Ingame(val batch: SpriteBatch) : Screen { uiWatchTierOne.setPosition(Terrarum.WIDTH - uiWatchTierOne.width, uiWatchBasic.height - 2) + uiTooltip = UITooltip() + + // batch-process uiAliases uiAliases = arrayListOf( // drawn first @@ -367,7 +371,8 @@ class Ingame(val batch: SpriteBatch) : Screen { uiPieMenu, uiQuickBar, uiWatchBasic, - uiWatchTierOne + uiWatchTierOne, + uiTooltip // drawn last ) uiAlasesPausing = arrayListOf( @@ -384,6 +389,7 @@ class Ingame(val batch: SpriteBatch) : Screen { updateThreadWrapper = Thread(ingameUpdateThread, "Terrarum UpdateThread") + LightmapRenderer.fireRecalculateEvent() }// 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() { // TODO no pause when off-focus on desktop } diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index bf25774a4..bc1a90b21 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -136,7 +136,7 @@ object Terrarum : Screen { private set 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 get() = Runtime.getRuntime().totalMemory() shr 20 val memXmx: Long @@ -713,12 +713,16 @@ object Terrarum : Screen { return file // TODO TEST CODE } + /** Position of the cursor in the world */ inline val mouseX: Double get() = WorldCamera.x + Gdx.input.x / (ingame?.screenZoom ?: 1f).toDouble() + /** Position of the cursor in the world */ inline val mouseY: Double get() = WorldCamera.y + Gdx.input.y / (ingame?.screenZoom ?: 1f).toDouble() + /** Position of the cursor in the world */ @JvmStatic inline val mouseTileX: Int get() = (mouseX / FeaturesDrawer.TILE_SIZE).floorInt() + /** Position of the cursor in the world */ @JvmStatic inline val mouseTileY: Int get() = (mouseY / FeaturesDrawer.TILE_SIZE).floorInt() inline val mouseScreenX: Int diff --git a/src/net/torvald/terrarum/ui/UIInventoryFull.kt b/src/net/torvald/terrarum/ui/UIInventoryFull.kt index d25684116..ca88cc55a 100644 --- a/src/net/torvald/terrarum/ui/UIInventoryFull.kt +++ b/src/net/torvald/terrarum/ui/UIInventoryFull.kt @@ -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!! } diff --git a/src/net/torvald/terrarum/ui/UIItemInventoryDynamicList.kt b/src/net/torvald/terrarum/ui/UIItemInventoryDynamicList.kt index 2b382825b..77f605f22 100644 --- a/src/net/torvald/terrarum/ui/UIItemInventoryDynamicList.kt +++ b/src/net/torvald/terrarum/ui/UIItemInventoryDynamicList.kt @@ -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 = 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(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) } } diff --git a/src/net/torvald/terrarum/ui/UITooltip.kt b/src/net/torvald/terrarum/ui/UITooltip.kt new file mode 100644 index 000000000..70d679141 --- /dev/null +++ b/src/net/torvald/terrarum/ui/UITooltip.kt @@ -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() + } + +} \ No newline at end of file diff --git a/work_files/UI/portable_computer_mockup.psd b/work_files/UI/portable_computer_mockup.psd index fed764953..b61a8770c 100644 --- a/work_files/UI/portable_computer_mockup.psd +++ b/work_files/UI/portable_computer_mockup.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3b2fdafe9ba9f98b47594fecd42c939b640c988371e6e808d93c1db9b1fc4d75 -size 212796 +oid sha256:0be1fae52a3b3995dc8f8f4adfd7330792f4a3eb03c54917b20bf3bb455d2ef8 +size 215098 diff --git a/work_files/graphics/fonts/newrunes.psd b/work_files/graphics/fonts/newrunes.psd index bfcc2a73a..bf450df11 100644 --- a/work_files/graphics/fonts/newrunes.psd +++ b/work_files/graphics/fonts/newrunes.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0fc6afbc2ea95e6e849d1a2eb80b8d0a8e9322181e4c07b2f87b9590b2617d32 -size 77753 +oid sha256:f58dd7c71b257307c98c4abfcb1b9ca41712c136edc138def2361fa87f79f42e +size 77760 diff --git a/work_files/graphics/fonts/newrunes_large.psd b/work_files/graphics/fonts/newrunes_large.psd new file mode 100644 index 000000000..f2d300d64 --- /dev/null +++ b/work_files/graphics/fonts/newrunes_large.psd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0d4702ff075cc5e0e128b53ef9e444a25d75f92e92a7fc0415d7757252ff0191 +size 242464