mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-15 21:14:04 +09:00
com.torvald → net.torvald
Former-commit-id: 375604da8a20a6ba7cd0a8d05a44add02b2d04f4 Former-commit-id: 287287c5920b07618174d7a7573f049d350ded66
This commit is contained in:
87
src/net/torvald/terrarum/ui/Notification.kt
Normal file
87
src/net/torvald/terrarum/ui/Notification.kt
Normal file
@@ -0,0 +1,87 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Input
|
||||
import org.newdawn.slick.SlickException
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-23.
|
||||
*/
|
||||
class Notification @Throws(SlickException::class)
|
||||
constructor() : UICanvas {
|
||||
|
||||
override var width: Int = 0
|
||||
override var height: Int = 0
|
||||
internal var visibleTime: Int
|
||||
internal var showupTimeConuter = 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
|
||||
|
||||
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 (showupTimeConuter >= 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 (isShowing) {
|
||||
showupTimeConuter += delta
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
if (isShowing) {
|
||||
msgUI.render(gc, g)
|
||||
}
|
||||
}
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
msgUI.doOpening(gc, delta)
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
msgUI.doClosing(gc, delta)
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
msgUI.endOpening(gc, delta)
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
msgUI.endClosing(gc, delta)
|
||||
}
|
||||
|
||||
override fun processInput(input: Input) {
|
||||
|
||||
}
|
||||
|
||||
fun sendNotification(gc: GameContainer, delta: Int, message: Array<String>) {
|
||||
isShowing = true
|
||||
this.message = message
|
||||
msgUI.setMessage(this.message)
|
||||
showupTimeConuter = 0
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user