changes in fade-slide transition container

This commit is contained in:
minjaesong
2023-07-07 00:19:56 +09:00
parent c0a3da1b66
commit c28b286553
5 changed files with 75 additions and 40 deletions

View File

@@ -220,7 +220,9 @@ class UIInventoryFull(
width, width,
App.scr.height, App.scr.height,
1f, 1f,
transitionalCraftingUI, transitionalItemCells, transitionalEscMenu listOf(transitionalCraftingUI),
listOf(transitionalItemCells),
listOf(transitionalEscMenu)
) )

View File

@@ -176,17 +176,12 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() {
width, width,
App.scr.height, App.scr.height,
0f, 0f,
transitionalListing, transitionalManage listOf(transitionalListing),
listOf(transitionalManage, transitionalAutosave, transitionalNewCharacter)
) )
init { init {
listOf(transitionalAutosave, transitionalManage, transitionalNewCharacter).forEach {
it.posX = (-width / 2f).roundToInt()
it.initialX = (-width / 2f).roundToInt()
it.posY = 0
it.initialY = 0
it.opacity = 0f
}
} }
private fun getDrawTextualInfoFun(disks: DiskPair): (UIItem, SpriteBatch) -> Unit { private fun getDrawTextualInfoFun(disks: DiskPair): (UIItem, SpriteBatch) -> Unit {

View File

@@ -64,7 +64,9 @@ class UIWorldPortal : UICanvas(
width, width,
App.scr.height, App.scr.height,
0f, 0f,
transitionalListing, transitionalSearch listOf(transitionalListing),
listOf(),
listOf()
) )
/** /**

View File

@@ -2,10 +2,15 @@ package net.torvald.terrarum.ui
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.terrarum.INGAME import net.torvald.terrarum.INGAME
import net.torvald.terrarum.modulebasegame.ui.NullUI
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
import kotlin.math.roundToInt 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 width size of the canvas where transition occurs
* @param height size of the canvas where transition occurs * @param height size of the canvas where transition occurs
*/ */
@@ -17,27 +22,58 @@ class UIItemHorizontalFadeSlide(
height: Int, height: Int,
//transitionLength: Float, //transitionLength: Float,
currentPosition: Float, currentPosition: Float,
vararg uis: UICanvas private val uisOnLeft: List<UICanvas>,
) : UIItemTransitionContainer(parent, initialX, initialY, width, height, 0.12f, currentPosition, uis) { 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) 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 { init {
// re-position the uis according to the initial choice of currentPosition // re-position the uis according to the initial choice of currentPosition
uis.forEachIndexed { index, it -> uisOnLeft.forEachIndexed { index, it ->
it.posX = 0 + getOffX(index) it.posX = getOffX(0)
it.initialX = 0 + getOffX(index) it.initialX = getOffX(0)
it.posY = 0 it.posY = 0
it.initialY = 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 -> uis.forEachIndexed { index, it ->
it.posX = -getOffX(index) it.posX = getOffX(index)
it.posY = it.initialY it.posY = it.initialY
it.opacity = getOpacity(index) it.opacity = getOpacity(index)
} }

View File

@@ -15,7 +15,7 @@ open class UIItemTransitionContainer(
override val height: Int, override val height: Int,
val transitionLength: Float = 0.15f, val transitionLength: Float = 0.15f,
var currentPosition: Float = 0f, var currentPosition: Float = 0f,
val uis: Array<out UICanvas> open val uis: List<UICanvas>
) : UIItem(parent, initialX, initialY) { ) : UIItem(parent, initialX, initialY) {
val debugvals = false val debugvals = false
@@ -51,7 +51,7 @@ open class UIItemTransitionContainer(
uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.update(delta) } uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.update(delta) }
} }
open fun onTransition(currentPosition: Float, uis: Array<out UICanvas>) {} open fun onTransition(currentPosition: Float, uis: List<UICanvas>) {}
override fun render(batch: SpriteBatch, camera: Camera) { override fun render(batch: SpriteBatch, camera: Camera) {
super.render(batch, camera) super.render(batch, camera)