FIX: quickbar opacity bug, Notification won't display, remaned majuscule to fullwidth, keyboard layouts for control helper

Former-commit-id: 99c51499131a7cbae1b7345c15d804bd5340e7b6
Former-commit-id: 1326b69cb920d3590fe2cbe33013c85c9eeb1191
This commit is contained in:
Song Minjae
2016-07-29 21:02:24 +09:00
parent ee647652d2
commit fb11d5c9c2
42 changed files with 232 additions and 115 deletions

View File

@@ -25,7 +25,6 @@ class BasicDebugInfoWindow : UICanvas {
override var height: Int = Terrarum.HEIGHT
override var openCloseTime: Int = 0
override var openCloseTimer: Int = 0
override var handler: UIHandler? = null

View File

@@ -34,7 +34,6 @@ class ConsoleWindow : UICanvas, KeyboardControlled {
override var height: Int = LINE_HEIGHT * (MESSAGES_DISPLAY_COUNT + 1)
override var openCloseTime: Int = 0
override var openCloseTimer: Int = 0
private var drawOffX: Float = 0f
private var drawOffY: Float = -height.toFloat()

View File

@@ -27,13 +27,8 @@ constructor(override var width: Int, isBlackVariant: Boolean) : UICanvas {
override var openCloseTime: Int = OPEN_CLOSE_TIME
internal var opacity = 0f
override var openCloseTimer = 0
override var handler: UIHandler? = null
private lateinit var uidrawCanvas: Image // render all the images and fonts here; will be faded
init {
if (!isBlackVariant) {
segmentLeft = Image("./res/graphics/gui/message_twoline_white_left.png");
@@ -49,7 +44,6 @@ constructor(override var width: Int, isBlackVariant: Boolean) : UICanvas {
height = segmentLeft!!.height
messageWindowRadius = segmentLeft!!.width
messagesList = arrayOf("", "")
uidrawCanvas = Image(FastMath.nearestPowerOfTwo(width), FastMath.nearestPowerOfTwo(height))
}
fun setMessage(messagesList: Array<String>) {
@@ -61,25 +55,21 @@ constructor(override var width: Int, isBlackVariant: Boolean) : UICanvas {
}
override fun render(gc: GameContainer, g: Graphics) {
val canvasG = uidrawCanvas.graphics
setBlendDisable()
drawSegments(canvasG)
canvasG.setDrawMode(Graphics.MODE_ALPHA_MAP)
drawSegments(canvasG)
canvasG.font = uiFont
drawSegments(g)
g.setDrawMode(Graphics.MODE_ALPHA_MAP)
drawSegments(g)
canvasG.setDrawMode(Graphics.MODE_NORMAL)
g.font = uiFont
g.setDrawMode(Graphics.MODE_NORMAL)
for (i in 0..Math.min(messagesList.size, MESSAGES_DISPLAY) - 1) {
canvasG.color = fontCol
canvasG.drawString(messagesList[i], (messageWindowRadius + 4).toFloat(), (messageWindowRadius + GLYPH_HEIGHT * i).toFloat())
g.color = fontCol
g.drawString(messagesList[i], (messageWindowRadius + 4).toFloat(), (messageWindowRadius + GLYPH_HEIGHT * i).toFloat())
}
setBlendNormal()
g.drawImage(uidrawCanvas, 0f, 0f, Color(1f,1f,1f,opacity))
canvasG.clear()
}
override fun processInput(input: Input) {
@@ -87,27 +77,15 @@ constructor(override var width: Int, isBlackVariant: Boolean) : UICanvas {
}
override fun doOpening(gc: GameContainer, delta: Int) {
openCloseTimer += delta
opacity = FastMath.interpolateLinear(openCloseTimer.toFloat() / openCloseTime.toFloat(),
0f, 1f
)
}
override fun doClosing(gc: GameContainer, delta: Int) {
openCloseTimer += delta
opacity = FastMath.interpolateLinear(openCloseTimer.toFloat() / openCloseTime.toFloat(),
1f, 0f
)
}
override fun endOpening(gc: GameContainer, delta: Int) {
opacity = 1f
openCloseTimer = 0
}
override fun endClosing(gc: GameContainer, delta: Int) {
opacity = 0f
openCloseTimer = 0
}
private fun drawSegments(g: Graphics) {

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
import com.jme3.math.FastMath
import net.torvald.terrarum.Terrarum
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
@@ -12,78 +13,68 @@ import org.newdawn.slick.SlickException
class Notification @Throws(SlickException::class)
constructor() : UICanvas {
override var width: Int = 0
override var height: Int = 0
internal var visibleTime: Int
override var openCloseTimer = 0
private val SHOWUP_MAX = 15000
override var width: Int = 500
internal var msgUI = MessageWindow(width, true)
override var height: Int = msgUI.height
private val visibleTime = Math.min(
Terrarum.getConfigInt("notificationshowuptime"),
SHOWUP_MAX
)
private var displayTimer = 0
internal var isShowing = false
internal var message: Array<String> = Array(MessageWindow.MESSAGES_DISPLAY, { i -> ""})
internal var msgUI: MessageWindow
override var openCloseTime: Int = MessageWindow.OPEN_CLOSE_TIME
override var handler: UIHandler? = null
private val SHOWUP_MAX = 15000
init {
width = 500
msgUI = MessageWindow(width, true)
height = msgUI.height
visibleTime = Math.min(
Terrarum.getConfigInt("notificationshowuptime"),
SHOWUP_MAX
)
}
override fun update(gc: GameContainer, delta: Int) {
if (openCloseTimer >= visibleTime && isShowing) {
// invoke closing mode
doClosing(gc, delta)
// check if msgUI is fully fade out
if (msgUI.opacity <= 0.001f) {
endClosing(gc, delta)
isShowing = false
}
}
if (handler!!.isOpened)
displayTimer += delta
if (isShowing) {
openCloseTimer += delta
}
if (displayTimer >= visibleTime)
handler!!.setAsClose()
}
override fun render(gc: GameContainer, g: Graphics) {
if (isShowing) {
msgUI.render(gc, g)
}
msgUI.render(gc, g)
}
override fun doOpening(gc: GameContainer, delta: Int) {
msgUI.doOpening(gc, delta)
handler!!.opacity = FastMath.interpolateLinear(handler!!.openCloseCounter.toFloat() / openCloseTime.toFloat(),
0f, 1f
)
}
override fun doClosing(gc: GameContainer, delta: Int) {
msgUI.doClosing(gc, delta)
handler!!.opacity = FastMath.interpolateLinear(handler!!.openCloseCounter.toFloat() / openCloseTime.toFloat(),
1f, 0f
)
}
override fun endOpening(gc: GameContainer, delta: Int) {
msgUI.endOpening(gc, delta)
handler!!.opacity = 1f
}
override fun endClosing(gc: GameContainer, delta: Int) {
msgUI.endClosing(gc, delta)
handler!!.opacity = 0f
}
override fun processInput(input: Input) {
}
fun sendNotification(gc: GameContainer, delta: Int, message: Array<String>) {
isShowing = true
fun sendNotification(message: Array<String>) {
this.message = message
msgUI.setMessage(this.message)
openCloseTimer = 0
handler!!.openCloseCounter = 0
handler!!.opacity = 0f
handler!!.setAsOpen()
}
}

View File

@@ -12,16 +12,17 @@ interface UICanvas {
var width: Int
var height: Int
/**
* Usage: (in StateInGame:) uiHandlerField.ui.handler = uiHandlerField
*/
var handler: UIHandler?
/**
* In milliseconds
*
* Timer itself is implemented in the handler.
*/
var openCloseTime: Int
/**
* Usage: get() = handler!!.openCloseCounter
*/
var openCloseTimer: Int
fun update(gc: GameContainer, delta: Int)
@@ -29,11 +30,23 @@ interface UICanvas {
fun processInput(input: Input)
/**
* Do not modify handler!!.openCloseCounter here.
*/
fun doOpening(gc: GameContainer, delta: Int)
/**
* Do not modify handler!!.openCloseCounter here.
*/
fun doClosing(gc: GameContainer, delta: Int)
/**
* Do not modify handler!!.openCloseCounter here.
*/
fun endOpening(gc: GameContainer, delta: Int)
/**
* Do not modify handler!!.openCloseCounter here.
*/
fun endClosing(gc: GameContainer, delta: Int)
}

View File

@@ -27,8 +27,6 @@ class UIPieMenu : UICanvas {
* In milliseconds
*/
override var openCloseTime: Int = 160
override var openCloseTimer: Int = 0
get() = handler!!.openCloseCounter
private val smallenSize = 0.93f
@@ -82,12 +80,12 @@ class UIPieMenu : UICanvas {
}
override fun doOpening(gc: GameContainer, delta: Int) {
handler!!.opacity = openCloseTimer.toFloat() / openCloseTime
handler!!.opacity = handler!!.openCloseCounter.toFloat() / openCloseTime
handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity)
}
override fun doClosing(gc: GameContainer, delta: Int) {
handler!!.opacity = (openCloseTime - openCloseTimer.toFloat()) / openCloseTime
handler!!.opacity = (openCloseTime - handler!!.openCloseCounter.toFloat()) / openCloseTime
handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity)
}

View File

@@ -17,7 +17,6 @@ class UIQuickBar : UICanvas, MouseControlled {
* In milliseconds
*/
override var openCloseTime: Int = 160
override var openCloseTimer: Int = 0
private val startPointX = ItemSlotImageBuilder.slotLarge.width / 2
private val startPointY = ItemSlotImageBuilder.slotLarge.height / 2
@@ -56,11 +55,11 @@ class UIQuickBar : UICanvas, MouseControlled {
}
override fun doOpening(gc: GameContainer, delta: Int) {
handler!!.opacity = openCloseTimer.toFloat() / openCloseTime
handler!!.opacity = handler!!.openCloseCounter.toFloat() / openCloseTime
}
override fun doClosing(gc: GameContainer, delta: Int) {
handler!!.opacity = (openCloseTime - openCloseTimer.toFloat()) / openCloseTime
handler!!.opacity = (openCloseTime - handler!!.openCloseCounter.toFloat()) / openCloseTime
}
override fun endOpening(gc: GameContainer, delta: Int) {