mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 04:24:05 +09:00
changes in fade-slide transition container
This commit is contained in:
@@ -2,42 +2,78 @@ package net.torvald.terrarum.ui
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.INGAME
|
||||
import net.torvald.terrarum.modulebasegame.ui.NullUI
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* Three virtual slide panels for horizontal sliding transition.
|
||||
*
|
||||
* The left/centre/right designation is arbitrary: you can have "left" as a centre (main) and the "centre" as a right (aux)
|
||||
*
|
||||
* @param width size of the canvas where transition occurs
|
||||
* @param height size of the canvas where transition occurs
|
||||
*/
|
||||
class UIItemHorizontalFadeSlide(
|
||||
parent: UICanvas,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
width: Int,
|
||||
height: Int,
|
||||
parent: UICanvas,
|
||||
initialX: Int,
|
||||
initialY: Int,
|
||||
width: Int,
|
||||
height: Int,
|
||||
//transitionLength: Float,
|
||||
currentPosition: Float,
|
||||
vararg uis: UICanvas
|
||||
) : UIItemTransitionContainer(parent, initialX, initialY, width, height, 0.12f, currentPosition, uis) {
|
||||
currentPosition: Float,
|
||||
private val uisOnLeft: List<UICanvas>,
|
||||
private val uisOnCentre: List<UICanvas>,
|
||||
private val uisOnRight: List<UICanvas> = emptyList(),
|
||||
) : UIItemTransitionContainer(parent, initialX, initialY, width, height, 0.12f, currentPosition, emptyList()) {
|
||||
|
||||
fun getOffX(index: Int) = ((currentPosition - index) * width / 2f).roundToInt()
|
||||
fun getOffX(index: Int) = -((currentPosition - index) * width / 2f).roundToInt()
|
||||
fun getOpacity(index: Int) = 1f - (currentPosition - index).absoluteValue.coerceIn(0f, 1f)
|
||||
|
||||
private var leftUI: UICanvas = uisOnLeft.firstOrNull() ?: NullUI
|
||||
private var centreUI: UICanvas = uisOnCentre.firstOrNull() ?: NullUI
|
||||
private var rightUI: UICanvas = uisOnRight.firstOrNull() ?: NullUI
|
||||
|
||||
override val uis: List<UICanvas>; get() = listOf(leftUI, centreUI, rightUI)
|
||||
|
||||
fun setLeftUI(index: Int) {
|
||||
leftUI = uisOnLeft[index]
|
||||
}
|
||||
fun setCentreUI(index: Int) {
|
||||
centreUI = uisOnCentre[index]
|
||||
}
|
||||
fun setRightUI(index: Int) {
|
||||
rightUI = uisOnRight[index]
|
||||
}
|
||||
|
||||
init {
|
||||
// re-position the uis according to the initial choice of currentPosition
|
||||
uis.forEachIndexed { index, it ->
|
||||
it.posX = 0 + getOffX(index)
|
||||
it.initialX = 0 + getOffX(index)
|
||||
uisOnLeft.forEachIndexed { index, it ->
|
||||
it.posX = getOffX(0)
|
||||
it.initialX = getOffX(0)
|
||||
it.posY = 0
|
||||
it.initialY = 0
|
||||
it.opacity = getOpacity(index)
|
||||
it.opacity = getOpacity(0)
|
||||
}
|
||||
uisOnCentre.forEachIndexed { index, it ->
|
||||
it.posX = getOffX(1)
|
||||
it.initialX = getOffX(1)
|
||||
it.posY = 0
|
||||
it.initialY = 0
|
||||
it.opacity = getOpacity(1)
|
||||
}
|
||||
uisOnRight.forEachIndexed { index, it ->
|
||||
it.posX = getOffX(2)
|
||||
it.initialX = getOffX(2)
|
||||
it.posY = 0
|
||||
it.initialY = 0
|
||||
it.opacity = getOpacity(2)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTransition(currentPosition: Float, uis: Array<out UICanvas>) {
|
||||
override fun onTransition(currentPosition: Float, uis: List<UICanvas>) {
|
||||
uis.forEachIndexed { index, it ->
|
||||
it.posX = -getOffX(index)
|
||||
it.posX = getOffX(index)
|
||||
it.posY = it.initialY
|
||||
it.opacity = getOpacity(index)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user