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

@@ -214,13 +214,15 @@ class UIInventoryFull(
private val transitionalItemCells = UIInventoryCells(this) private val transitionalItemCells = UIInventoryCells(this)
private val transitionalEscMenu = UIInventoryEscMenu(this) private val transitionalEscMenu = UIInventoryEscMenu(this)
private val transitionPanel = UIItemHorizontalFadeSlide( private val transitionPanel = UIItemHorizontalFadeSlide(
this, this,
(width - internalWidth) / 2, (width - internalWidth) / 2,
INVENTORY_CELLS_OFFSET_Y(), INVENTORY_CELLS_OFFSET_Y(),
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,42 +2,78 @@ 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
*/ */
class UIItemHorizontalFadeSlide( class UIItemHorizontalFadeSlide(
parent: UICanvas, parent: UICanvas,
initialX: Int, initialX: Int,
initialY: Int, initialY: Int,
width: Int, width: Int,
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

@@ -8,14 +8,14 @@ import net.torvald.terrarum.App
import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.App.printdbg
open class UIItemTransitionContainer( open class UIItemTransitionContainer(
private val parent: UICanvas, private val parent: UICanvas,
initialX: Int, initialX: Int,
initialY: Int, initialY: Int,
override val width: Int, override val width: Int,
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)