less fancy inventory transition WIP

This commit is contained in:
minjaesong
2020-08-22 18:23:17 +09:00
parent ba424accf2
commit dd1989320d
24 changed files with 153 additions and 132 deletions

View File

@@ -45,13 +45,16 @@ import net.torvald.terrarum.Terrarum
* As mentioned in [UICanvas], UIItems must be added to the Canvas to make listeners work without implementing
* everything by yourself.
*
* @param initialX initial position of the item. Useful for making transition that requires the item to be moved
* @param initialY initial position of the item. Useful for making transition that requires the item to be moved
*
* Created by minjaesong on 2015-12-31.
*/
abstract class UIItem(var parentUI: UICanvas): Disposable { // do not replace parentUI to UIHandler!
abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: Int): Disposable { // do not replace parentUI to UIHandler!
// X/Y Position relative to the containing canvas
abstract var posX: Int
abstract var posY: Int
var posX: Int = initialX
var posY: Int = initialY
abstract val width: Int
abstract val height: Int

View File

@@ -13,14 +13,14 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
*/
class UIItemConfigKeycap(
parent: UICanvas,
override var posX: Int,
override var posY: Int,
initialX: Int,
initialY: Int,
private val keySize: Int,
private val keycode: Int, // also used to draw key label
private var keyItem: Int? = null // internal index for the key's behaviour, also used to choose appropriate icon
) : UIItem(parent) {
) : UIItem(parent, initialX, initialY) {
init {
if (keySize < 3) throw IllegalArgumentException("Key size must be greater than 2 (got $keySize)")

View File

@@ -32,14 +32,14 @@ open class UIItemImageButton(
val backgroundCol: Color = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL,
val backgroundBlendMode: String = BlendMode.NORMAL,
override var posX: Int,
override var posY: Int,
initialX: Int,
initialY: Int,
override val width: Int = image.regionWidth,
override val height: Int = image.regionHeight,
/** When clicked, toggle its "lit" status */
var highlightable: Boolean
) : UIItem(parent) {
) : UIItem(parent, initialX, initialY) {
// deal with the moving position
override var oldPosX = posX

View File

@@ -12,13 +12,13 @@ import java.util.*
*/
class UIItemImageGallery(
parentUI: UICanvas,
override var posX: Int,
override var posY: Int,
initialX: Int,
initialY: Int,
override val width: Int,
override val height: Int,
val imageList: ArrayList<Texture>,
val column: Int = 1
) : UIItem(parentUI) {
) : UIItem(parentUI, initialX, initialY) {
// deal with the moving position
override var oldPosX = posX

View File

@@ -13,8 +13,12 @@ import java.awt.Color
class UIItemIntSlider(
parent: UICanvas,
initValue: Int,
initialX: Int,
initialY: Int,
override val width: Int,
override val height: Int,
val minValue: Int,
val maxValue: Int,
val step: Int,
@@ -38,11 +42,13 @@ class UIItemIntSlider(
val sliderUseColourMap: GdxColorMap? = null,
val sliderUseTexture: Texture? = null
) : UIItem(parent) {
) : UIItem(parent, initialX, initialY) {
constructor(
parent: UICanvas,
initValue: Int,
initialX: Int,
initialY: Int,
values: IntRange,
width: Int,
height: Int,
@@ -60,6 +66,8 @@ class UIItemIntSlider(
) : this(
parent,
initValue,
initialX,
initialY,
values.first,
values.last,
values.step,
@@ -84,12 +92,6 @@ class UIItemIntSlider(
// TODO unimplemented
override var posX: Int
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
set(value) {}
override var posY: Int
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
set(value) {}
override val mouseUp: Boolean
get() = super.mouseUp
override val mousePushed: Boolean

View File

@@ -14,8 +14,8 @@ import net.torvald.terrarum.fillRect
class UIItemList<Item: UIItem>(
parentUI: UICanvas,
val itemList: ArrayList<Item>,
override var posX: Int,
override var posY: Int,
initialX: Int,
initialY: Int,
override val width: Int,
override val height: Int,
@@ -34,7 +34,7 @@ class UIItemList<Item: UIItem>(
val backgroundBlendMode: String = BlendMode.NORMAL,
val kinematic: Boolean = false,
val border: Int = 0
) : UIItem(parentUI) {
) : UIItem(parentUI, initialX, initialY) {
// deal with the moving position
override var oldPosX = posX

View File

@@ -12,9 +12,9 @@ class UIItemModuleInfoCell(
parent: UICanvas,
var moduleName: String,
override val width: Int,
override var posX: Int,
override var posY: Int
) : UIItem(parent) {
initialX: Int,
initialY: Int
) : UIItem(parent, initialX, initialY) {
// deal with the moving position
override var oldPosX = posX

View File

@@ -8,14 +8,14 @@ import net.torvald.terrarum.ui.UIItemTextButton.Companion.Alignment
class UIItemTextArea(
parentUI: UICanvas,
override var posX: Int,
override var posY: Int,
initialX: Int,
initialY: Int,
override val width: Int,
override val height: Int,
val lineGap: Int = 0,
val lineCount: Int = ((height + lineGap) / AppLoader.fontGame.lineHeight).toInt(),
val align: Alignment = Alignment.LEFT
) : UIItem(parentUI) {
) : UIItem(parentUI, initialX, initialY) {
// deal with the moving position
override var oldPosX = posX

View File

@@ -18,8 +18,8 @@ open class UIItemTextButton(
parentUI: UICanvas,
/** Stored text (independent to the Langpack) */
val labelText: String,
override var posX: Int,
override var posY: Int,
initialX: Int,
initialY: Int,
override val width: Int,
val readFromLang: Boolean = false,
@@ -46,7 +46,7 @@ open class UIItemTextButton(
val alignment: Alignment = Alignment.CENTRE,
val hitboxSize: Int = UIItemTextButton.height
) : UIItem(parentUI) {
) : UIItem(parentUI, initialX, initialY) {
// deal with the moving position
override var oldPosX = posX

View File

@@ -12,8 +12,8 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
class UIItemTextButtonList(
parentUI: UICanvas,
labelsList: Array<String>,
override var posX: Int,
override var posY: Int,
initialX: Int,
initialY: Int,
override var width: Int,
override var height: Int = DEFAULT_LINE_HEIGHT * labelsList.size,
val readFromLang: Boolean = false,
@@ -48,7 +48,7 @@ class UIItemTextButtonList(
val alignment: UIItemTextButton.Companion.Alignment = UIItemTextButton.Companion.Alignment.CENTRE,
val itemHitboxSize: Int = DEFAULT_LINE_HEIGHT
) : UIItem(parentUI) {
) : UIItem(parentUI, initialX, initialY) {
companion object {
val DEFAULT_BACKGROUNDCOL = Color(0x242424_80)
@@ -83,8 +83,8 @@ class UIItemTextButtonList(
if (!kinematic) {
UIItemTextButton(
parentUI, s,
posX = posX,
posY = posY + vertOff,
initialX = posX,
initialY = posY + vertOff,
width = width,
readFromLang = readFromLang,
activeCol = activeCol,
@@ -105,8 +105,8 @@ class UIItemTextButtonList(
else {
UIItemTextButton(
parentUI, s,
posX = posX,
posY = posY + vertOff,
initialX = posX,
initialY = posY + vertOff,
width = width,
readFromLang = readFromLang,
activeCol = activeCol,
@@ -126,7 +126,7 @@ class UIItemTextButtonList(
}
/*override var posX = 0
/*initialX = 0
set(value) {
buttons.forEach {
val oldPosX = field
@@ -135,7 +135,7 @@ class UIItemTextButtonList(
}
field = value
}
override var posY = 0
initialY = 0
set(value) {
buttons.forEach {
val oldPosY = field

View File

@@ -15,10 +15,10 @@ import kotlin.math.roundToInt
*/
class UIItemToggleButton(
parent: UICanvas,
override var posX: Int,
override var posY: Int,
initialX: Int,
initialY: Int,
private var status: Boolean = false
) : UIItem(parent) {
) : UIItem(parent, initialX, initialY) {
init {
CommonResourcePool.addToLoadingList("ui_item_toggler_base") {

View File

@@ -8,4 +8,6 @@ import net.torvald.terrarum.sqr
object UIUtils {
fun moveQuick(start: Float, end: Float, timer: Float, duration: Float) =
(start - end) * ((timer / duration) - 1).sqr() + end
fun moveLinear(start: Float, end: Float, timer: Float, duration: Float) =
(start - end) * (1 - (timer / duration)) + end
}