fix: inventory panels and their indices are mutually inversed

This commit is contained in:
minjaesong
2020-09-14 14:04:46 +09:00
parent f9883f2516
commit 1aadde9e9f
2 changed files with 10 additions and 5 deletions

View File

@@ -174,6 +174,7 @@ class UIItemInventoryCatBar(
selectedPanel = 1
}
// move selection highlighter
if (btn.mousePushed && index != selectedIndex) {
// normal stuffs
val oldIndex = selectedIndex
@@ -203,7 +204,6 @@ class UIItemInventoryCatBar(
if (selectedPanel != 0) transitionFired = true
mainButtons.forEach { it.highlighted = false }
selectedPanel = 0
parentInventory.requestTransition(0)
sideButtons[0].highlighted = true
sideButtons[3].highlighted = false
@@ -212,7 +212,6 @@ class UIItemInventoryCatBar(
if (selectedPanel != 2) transitionFired = true
mainButtons.forEach { it.highlighted = false }
selectedPanel = 2
parentInventory.requestTransition(2)
transitionFired = true
sideButtons[0].highlighted = false
@@ -222,7 +221,7 @@ class UIItemInventoryCatBar(
if (transitionFired) {
transitionFired = false
parentInventory.requestTransition(2 - selectedPanel)
parentInventory.requestTransition(selectedPanel)
}
}

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
import com.jme3.math.FastMath
import kotlin.math.roundToInt
/**
@@ -18,7 +19,12 @@ class UIItemHorizontalFadeSlide(
) : UIItemTransitionContainer(parent, initialX, initialY, width, height, 0.15f, currentPosition, uis) {
fun getOffX(index: Int) = ((currentPosition - index) * width / 2f).roundToInt()
fun getOpacity(index: Int) = 1f - (currentPosition - index).coerceIn(0f, 1f) // fixme make it work for both direction
fun getOpacity(index: Int) = 1f
/*if (currentPosition >= index)
1f - (currentPosition - index).coerceIn(0f, 1f)
else
(currentPosition - index).coerceIn(0f, 1f) - 1f*/
init {
// re-position the uis according to the initial choice of currentPosition
@@ -33,7 +39,7 @@ class UIItemHorizontalFadeSlide(
override fun onTransition(currentPosition: Float, uis: Array<out UICanvas>) {
uis.forEachIndexed { index, it ->
it.posX = it.initialX + getOffX(index)
it.posX = it.initialX - getOffX(index)
it.posY = it.initialY
it.opacity = getOpacity(index)
}