generalised things so that they would work outside of ingame.world; title screen wip

This commit is contained in:
minjaesong
2017-07-21 19:59:51 +09:00
parent cb8d3fd8b9
commit f1391bea6f
68 changed files with 1141 additions and 328 deletions

View File

@@ -20,7 +20,7 @@ abstract class UICanvas {
/**
* Usage: (in StateInGame:) uiHandlerField.ui.handler = uiHandlerField
*/
abstract var handler: UIHandler?
open lateinit var handler: UIHandler
/**
* In milliseconds
@@ -34,9 +34,9 @@ abstract class UICanvas {
val relativeMouseX: Int
get() = (Terrarum.mouseScreenX - (handler?.posX ?: 0))
get() = Terrarum.mouseScreenX - handler.posX
val relativeMouseY: Int
get() = (Terrarum.mouseScreenY - (handler?.posY ?: 0))
get() = Terrarum.mouseScreenY - handler.posY
/** If mouse is hovering over it */
val mouseUp: Boolean
@@ -51,22 +51,22 @@ abstract class UICanvas {
abstract fun render(batch: SpriteBatch)
/**
* Do not modify handler!!.openCloseCounter here.
* Do not modify handler.openCloseCounter here.
*/
abstract fun doOpening(delta: Float)
/**
* Do not modify handler!!.openCloseCounter here.
* Do not modify handler.openCloseCounter here.
*/
abstract fun doClosing(delta: Float)
/**
* Do not modify handler!!.openCloseCounter here.
* Do not modify handler.openCloseCounter here.
*/
abstract fun endOpening(delta: Float)
/**
* Do not modify handler!!.openCloseCounter here.
* Do not modify handler.openCloseCounter here.
*/
abstract fun endClosing(delta: Float)
@@ -118,82 +118,82 @@ abstract class UICanvas {
companion object {
const val OPENCLOSE_GENERIC = 0.2f
fun doOpeningFade(handler: UIHandler?, openCloseTime: Second) {
handler!!.opacity = handler.openCloseCounter / openCloseTime
fun doOpeningFade(handler: UIHandler, openCloseTime: Second) {
handler.opacity = handler.openCloseCounter / openCloseTime
}
fun doClosingFade(handler: UIHandler?, openCloseTime: Second) {
handler!!.opacity = (openCloseTime - handler.openCloseCounter) / openCloseTime
fun doClosingFade(handler: UIHandler, openCloseTime: Second) {
handler.opacity = (openCloseTime - handler.openCloseCounter) / openCloseTime
}
fun endOpeningFade(handler: UIHandler?) {
handler!!.opacity = 1f
fun endOpeningFade(handler: UIHandler) {
handler.opacity = 1f
}
fun endClosingFade(handler: UIHandler?) {
handler!!.opacity = 0f
fun endClosingFade(handler: UIHandler) {
handler.opacity = 0f
}
fun doOpeningPopOut(handler: UIHandler?, openCloseTime: Second, position: Position) {
fun doOpeningPopOut(handler: UIHandler, openCloseTime: Second, position: Position) {
when (position) {
Position.LEFT -> handler!!.posX = Movement.fastPullOut(
Position.LEFT -> handler.posX = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
-handler.UI.width.toFloat(),
0f
).roundInt()
Position.TOP -> handler!!.posY = Movement.fastPullOut(
Position.TOP -> handler.posY = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
-handler.UI.height.toFloat(),
0f
).roundInt()
Position.RIGHT -> handler!!.posX = Movement.fastPullOut(
Position.RIGHT -> handler.posX = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
Terrarum.WIDTH.toFloat(),
Terrarum.WIDTH - handler.UI.width.toFloat()
).roundInt()
Position.BOTTOM -> handler!!.posY = Movement.fastPullOut(
Position.BOTTOM -> handler.posY = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
Terrarum.HEIGHT.toFloat(),
Terrarum.HEIGHT - handler.UI.height.toFloat()
).roundInt()
}
}
fun doClosingPopOut(handler: UIHandler?, openCloseTime: Second, position: Position) {
fun doClosingPopOut(handler: UIHandler, openCloseTime: Second, position: Position) {
when (position) {
Position.LEFT -> handler!!.posX = Movement.fastPullOut(
Position.LEFT -> handler.posX = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
0f,
-handler.UI.width.toFloat()
).roundInt()
Position.TOP -> handler!!.posY = Movement.fastPullOut(
Position.TOP -> handler.posY = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
0f,
-handler.UI.height.toFloat()
).roundInt()
Position.RIGHT -> handler!!.posX = Movement.fastPullOut(
Position.RIGHT -> handler.posX = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
Terrarum.WIDTH - handler.UI.width.toFloat(),
Terrarum.WIDTH.toFloat()
).roundInt()
Position.BOTTOM -> handler!!.posY = Movement.fastPullOut(
Position.BOTTOM -> handler.posY = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
Terrarum.HEIGHT - handler.UI.height.toFloat(),
Terrarum.HEIGHT.toFloat()
).roundInt()
}
}
fun endOpeningPopOut(handler: UIHandler?, position: Position) {
fun endOpeningPopOut(handler: UIHandler, position: Position) {
when (position) {
Position.LEFT -> handler!!.posX = 0
Position.TOP -> handler!!.posY = 0
Position.RIGHT -> handler!!.posX = Terrarum.WIDTH - handler.UI.width
Position.BOTTOM -> handler!!.posY = Terrarum.HEIGHT - handler.UI.height
Position.LEFT -> handler.posX = 0
Position.TOP -> handler.posY = 0
Position.RIGHT -> handler.posX = Terrarum.WIDTH - handler.UI.width
Position.BOTTOM -> handler.posY = Terrarum.HEIGHT - handler.UI.height
}
}
fun endClosingPopOut(handler: UIHandler?, position: Position) {
fun endClosingPopOut(handler: UIHandler, position: Position) {
when (position) {
Position.LEFT -> handler!!.posX = -handler.UI.width
Position.TOP -> handler!!.posY = -handler.UI.height
Position.RIGHT -> handler!!.posX = Terrarum.WIDTH
Position.BOTTOM -> handler!!.posY = Terrarum.HEIGHT
Position.LEFT -> handler.posX = -handler.UI.width
Position.TOP -> handler.posY = -handler.UI.height
Position.RIGHT -> handler.posX = Terrarum.WIDTH
Position.BOTTOM -> handler.posY = Terrarum.HEIGHT
}
}