From 29fbad889be8153f74ce6ad80777b9f5133eb30a Mon Sep 17 00:00:00 2001 From: minjaesong Date: Thu, 31 Jan 2019 20:54:25 +0900 Subject: [PATCH] fixed notificator UI --- assets/graphics/gui/message_black.tga | 4 +- src/net/torvald/terrarum/DefaultConfig.kt | 2 +- .../gamecontroller/IngameController.kt | 3 +- .../torvald/terrarum/modulebasegame/Ingame.kt | 15 +---- .../terrarum/modulebasegame/IngameRenderer.kt | 4 ++ .../modulebasegame/ui/MessageWindow.kt | 16 ++--- .../modulebasegame/ui/Notification.kt | 67 ++++++++++++++++--- .../modulebasegame/ui/UIQuickslotBar.kt | 5 +- .../modulebasegame/ui/uiQuickslotPie.kt | 5 +- src/net/torvald/terrarum/ui/UICanvas.kt | 13 ++-- src/net/torvald/terrarum/ui/UIHandler.kt | 13 +++- 11 files changed, 102 insertions(+), 45 deletions(-) diff --git a/assets/graphics/gui/message_black.tga b/assets/graphics/gui/message_black.tga index 63b3b1f43..c614e8086 100644 --- a/assets/graphics/gui/message_black.tga +++ b/assets/graphics/gui/message_black.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:85907cefb4e0f674cb4d83cf51a9dcf145a24825e9909eede4699fb36cb93454 -size 5394 +oid sha256:358aaf2ebfd9a02986113330b4d0ff86bf990d83dd2dfbc24e2a6f09d70e6764 +size 5420 diff --git a/src/net/torvald/terrarum/DefaultConfig.kt b/src/net/torvald/terrarum/DefaultConfig.kt index ec094afa0..6b6ac28bb 100644 --- a/src/net/torvald/terrarum/DefaultConfig.kt +++ b/src/net/torvald/terrarum/DefaultConfig.kt @@ -21,7 +21,7 @@ object DefaultConfig { jsonObject.addProperty("imtooyoungtodie", false) // no perma-death jsonObject.addProperty("language", AppLoader.getSysLang()) - jsonObject.addProperty("notificationshowuptime", 6500) + jsonObject.addProperty("notificationshowuptime", 4000) jsonObject.addProperty("multithread", true) // experimental! jsonObject.addProperty("multithreadedlight", false) // experimental! diff --git a/src/net/torvald/terrarum/gamecontroller/IngameController.kt b/src/net/torvald/terrarum/gamecontroller/IngameController.kt index 01466ad41..fed1a8c8d 100644 --- a/src/net/torvald/terrarum/gamecontroller/IngameController.kt +++ b/src/net/torvald/terrarum/gamecontroller/IngameController.kt @@ -103,8 +103,7 @@ class IngameController(val ingame: Ingame) : InputAdapter() { // screenshot key if (keycode == Input.Keys.F12 && !f12Down) { AppLoader.requestScreenshot() - // FIXME - //ingame.sendNotification(arrayOf("Screenshot taken", "")) + ingame.sendNotification(arrayOf("Screenshot taken", "")) f12Down = true println("Screenshot taken.") } diff --git a/src/net/torvald/terrarum/modulebasegame/Ingame.kt b/src/net/torvald/terrarum/modulebasegame/Ingame.kt index b130bec95..8de0d01c8 100644 --- a/src/net/torvald/terrarum/modulebasegame/Ingame.kt +++ b/src/net/torvald/terrarum/modulebasegame/Ingame.kt @@ -285,23 +285,14 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) { // init notifier notifier = Notification() notifier.setPosition( - (Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height) + (Terrarum.WIDTH - notifier.width) / 2, + Terrarum.HEIGHT - notifier.height - AppLoader.getTvSafeGraphicsHeight() + ) // >- queue up game UIs that should pause the world -< - // inventory - /*uiInventoryPlayer = UIInventory(player, - width = 900, - height = Terrarum.HEIGHT - 160, - categoryWidth = 210, - toggleKeyLiteral = AppLoader.getConfigInt("keyinventory") - )*/ - /*uiInventoryPlayer.setPosition( - -uiInventoryPlayer.width, - 70 - )*/ uiInventoryPlayer = UIInventoryFull(actorNowPlaying!!, toggleKeyLiteral = AppLoader.getConfigInt("keyinventory") ) diff --git a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt index 5f0ba24d9..95d19544f 100644 --- a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt +++ b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt @@ -79,6 +79,9 @@ object IngameRenderer { init() + batch.color = Color.WHITE + + BlocksDrawer.world = world LightmapRenderer.setWorld(world) FeaturesDrawer.world = world @@ -208,6 +211,7 @@ object IngameRenderer { // works but some UI elements have wrong transparency -> should be fixed with Terrarum.gdxCleanAndSetBlend -- Torvald 2019-01-12 blendNormal(batch) + batch.color = Color.WHITE } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/MessageWindow.kt b/src/net/torvald/terrarum/modulebasegame/ui/MessageWindow.kt index 8ae34958b..37b4edfc5 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/MessageWindow.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/MessageWindow.kt @@ -1,19 +1,10 @@ package net.torvald.terrarum.modulebasegame.ui -import com.badlogic.gdx.graphics.Camera -import com.badlogic.gdx.graphics.Color -import com.badlogic.gdx.graphics.g2d.SpriteBatch -import net.torvald.terrarum.Second -import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.blendNormal -import net.torvald.terrarum.ui.UICanvas -import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack - /** * Created by minjaesong on 2016-01-27. */ -class MessageWindow(override var width: Int, isBlackVariant: Boolean) : UICanvas() { +/*class MessageWindow(override var width: Int, isBlackVariant: Boolean) : UICanvas() { private val segment = if (isBlackVariant) SEGMENT_BLACK else SEGMENT_WHITE @@ -49,6 +40,9 @@ class MessageWindow(override var width: Int, isBlackVariant: Boolean) : UICanvas messagesList.forEachIndexed { index, s -> Terrarum.fontGame.draw(batch, s, segment.tileW + LRmargin, (segment.tileH - Terrarum.fontGame.lineHeight) / 2f) } + + AppLoader.printdbg(this, "render") + } override fun doOpening(delta: Float) { @@ -76,4 +70,4 @@ class MessageWindow(override var width: Int, isBlackVariant: Boolean) : UICanvas val SEGMENT_BLACK = TextureRegionPack("assets/graphics/gui/message_black.tga", 8, 56) val SEGMENT_WHITE = TextureRegionPack("assets/graphics/gui/message_white.tga", 8, 56) } -} +}*/ diff --git a/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt b/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt index 1524d5152..3b3fa512a 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt @@ -1,32 +1,45 @@ package net.torvald.terrarum.modulebasegame.ui import com.badlogic.gdx.graphics.Camera +import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.AppLoader import net.torvald.terrarum.Second +import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.blendNormal import net.torvald.terrarum.ui.UICanvas +import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack /** * Created by minjaesong on 2016-01-23. */ class Notification : UICanvas() { - private val SHOWUP_MAX = 15000 + private val segment = SEGMENT_BLACK + + private var fontCol: Color = Color.WHITE // assuming alpha of 1.0 + + override var openCloseTime: Second = OPEN_CLOSE_TIME + + private val LRmargin = 0f // there's "base value" of 8 px for LR (width of segment tile) + + + private val SHOWUP_MAX = 6500 override var width: Int = 500 - internal var msgUI = MessageWindow(width, true) - - override var height: Int = msgUI.height + override var height: Int = segment.tileH private val visibleTime = Math.min( AppLoader.getConfigInt("notificationshowuptime"), SHOWUP_MAX - ) + ) / 1000f private var displayTimer = 0f - internal var message: Array = Array(MessageWindow.MESSAGES_DISPLAY) { "" } + internal var message: Array = Array(MESSAGES_DISPLAY) { "" } - override var openCloseTime: Second = MessageWindow.OPEN_CLOSE_TIME + + init { + } override fun updateUI(delta: Float) { if (handler.isOpened) @@ -38,8 +51,34 @@ class Notification : UICanvas() { } } + private val textAreaHeight = 48f + private val imageToTextAreaDelta = (segment.tileH - textAreaHeight) / 2 + + private val drawColor = Color(1f,1f,1f,1f) + override fun renderUI(batch: SpriteBatch, camera: Camera) { - msgUI.render(batch, camera) + blendNormal(batch) + drawColor.a = handler.opacity + fontCol.a = handler.opacity + + val textWidth = width//maxOf(width, messagesList.map { Terrarum.fontGame.getWidth(it) }.sorted()[1]) + + batch.color = drawColor + + batch.draw(segment.get(0, 0), -segment.tileW.toFloat(), 0f) + batch.draw(segment.get(1, 0), 0f, 0f, textWidth.toFloat(), segment.tileH.toFloat()) + batch.draw(segment.get(2, 0), textWidth.toFloat(), 0f) + + batch.color = fontCol + message.forEachIndexed { index, s -> + val y = imageToTextAreaDelta + index * (textAreaHeight / 2) + (textAreaHeight / 2 - Terrarum.fontGame.lineHeight) / 2 + Terrarum.fontGame.draw(batch, s, LRmargin, y) + } + + + // dunno why, it doesn't work without this. + drawColor.a = 1f + fontCol.a = 1f } override fun doOpening(delta: Float) { @@ -60,7 +99,6 @@ class Notification : UICanvas() { fun sendNotification(message: Array) { this.message = message - msgUI.setMessage(this.message) handler.openCloseCounter = 0f handler.opacity = 0f handler.setAsOpen() @@ -68,4 +106,15 @@ class Notification : UICanvas() { override fun dispose() { } + + companion object { + // private int messagesShowingIndex = 0; + val MESSAGES_DISPLAY = 2 + val OPEN_CLOSE_TIME = 0.16f + + + // will be disposed by Terrarum (application main instance) + val SEGMENT_BLACK = TextureRegionPack("assets/graphics/gui/message_black.tga", 8, 56) + val SEGMENT_WHITE = TextureRegionPack("assets/graphics/gui/message_white.tga", 8, 56) + } } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotBar.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotBar.kt index 311805ea5..dbd2d8840 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotBar.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotBar.kt @@ -41,6 +41,8 @@ class UIQuickslotBar : UICanvas() { override fun updateUI(delta: Float) { } + private val drawColor = Color(1f,1f,1f,1f) + override fun renderUI(batch: SpriteBatch, camera: Camera) { for (i in 0..SLOT_COUNT - 1) { @@ -55,7 +57,8 @@ class UIQuickslotBar : UICanvas() { val slotY = cellSize / 2 // draw slots - batch.color = Color(1f, 1f, 1f, handler.opacity * DISPLAY_OPACITY) + drawColor.a = handler.opacity * DISPLAY_OPACITY + batch.color = drawColor image.draw(batch, slotX, slotY) } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/uiQuickslotPie.kt b/src/net/torvald/terrarum/modulebasegame/ui/uiQuickslotPie.kt index 144f0d6c9..70509d3a7 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/uiQuickslotPie.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/uiQuickslotPie.kt @@ -57,6 +57,8 @@ class uiQuickslotPie : UICanvas() { } } + private val drawColor = Color(1f,1f,1f,1f) + override fun renderUI(batch: SpriteBatch, camera: Camera) { // draw radial thingies for (i in 0..slotCount - 1) { @@ -75,7 +77,8 @@ class uiQuickslotPie : UICanvas() { val slotX = slotCentrePoint.x.toInt() val slotY = slotCentrePoint.y.toInt() - batch.color = Color(1f, 1f, 1f, handler.opacity * UIQuickslotBar.DISPLAY_OPACITY) + drawColor.a = handler.opacity * UIQuickslotBar.DISPLAY_OPACITY + batch.color = drawColor image.draw(batch, slotX, slotY) } diff --git a/src/net/torvald/terrarum/ui/UICanvas.kt b/src/net/torvald/terrarum/ui/UICanvas.kt index 0d1e5994a..864341676 100644 --- a/src/net/torvald/terrarum/ui/UICanvas.kt +++ b/src/net/torvald/terrarum/ui/UICanvas.kt @@ -89,6 +89,9 @@ abstract class UICanvas( * * Under normal circumstances, draws are automatically translated as per the handler's X/Y position. * This means, don't write like: ```draw(posX + 4, posY + 32)```, do instead: ```draw(4, 32)``` unless you have a good reason to do so. + * + * The transparency of the handler is independent of the draw, you must specified the color yourself + * using handler.opacity or handler.opacityColour */ abstract fun renderUI(batch: SpriteBatch, camera: Camera) @@ -201,7 +204,7 @@ abstract class UICanvas( // handler func aliases // - fun setPosition(x: Int, y: Int) { + open fun setPosition(x: Int, y: Int) { handler.setPosition(x, y) } @@ -209,15 +212,15 @@ abstract class UICanvas( handler.setAsAlwaysVisible() } - fun setAsOpen() { + open fun setAsOpen() { handler.setAsOpen() } - fun setAsClose() { + open fun setAsClose() { handler.setAsClose() } - fun toggleOpening() { + open fun toggleOpening() { handler.toggleOpening() } @@ -255,7 +258,7 @@ abstract class UICanvas( const val OPENCLOSE_GENERIC = 0.2f fun doOpeningFade(ui: UICanvas, openCloseTime: Second) { - ui.handler.opacity = ui.handler.openCloseCounter / openCloseTime + ui.handler.opacity = maxOf(0f, ui.handler.openCloseCounter - 0.02f) / openCloseTime // fade start 1/50 sec late, it's intended } fun doClosingFade(ui: UICanvas, openCloseTime: Second) { ui.handler.opacity = (openCloseTime - ui.handler.openCloseCounter) / openCloseTime diff --git a/src/net/torvald/terrarum/ui/UIHandler.kt b/src/net/torvald/terrarum/ui/UIHandler.kt index a5f50d0a9..724997e07 100644 --- a/src/net/torvald/terrarum/ui/UIHandler.kt +++ b/src/net/torvald/terrarum/ui/UIHandler.kt @@ -55,8 +55,14 @@ class UIHandler(//var UI: UICanvas, var closeFired = false var opacity = 1f + set(value) { + field = value + opacityColour.set(1f,1f,1f,opacity) + } var scale = 1f + val opacityColour = Color(1f,1f,1f,opacity) + var openCloseCounter = 0f init { @@ -175,13 +181,18 @@ class UIHandler(//var UI: UICanvas, ui.renderUI(batch, camera) //ingameGraphics.flush() + batch.color = Color.WHITE setCameraPosition(batch, camera, 0f, 0f) } - subUIs.forEach { it.render(batch, camera) } + subUIs.forEach { + it.render(batch, camera) + batch.color = Color.WHITE + } + } fun setPosition(x: Int, y: Int) {