mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 20:14:05 +09:00
changes in fade-slide transition container
This commit is contained in:
@@ -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)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -64,7 +64,9 @@ class UIWorldPortal : UICanvas(
|
|||||||
width,
|
width,
|
||||||
App.scr.height,
|
App.scr.height,
|
||||||
0f,
|
0f,
|
||||||
transitionalListing, transitionalSearch
|
listOf(transitionalListing),
|
||||||
|
listOf(),
|
||||||
|
listOf()
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user