mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
fixed notificator UI
This commit is contained in:
Binary file not shown.
@@ -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!
|
||||
|
||||
|
||||
@@ -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.")
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@@ -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<String> = Array(MessageWindow.MESSAGES_DISPLAY) { "" }
|
||||
internal var message: Array<String> = 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<String>) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user