From dd1989320dccec8626603ba5762c926db15b7496 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 22 Aug 2020 18:23:17 +0900 Subject: [PATCH] less fancy inventory transition WIP --- .../torvald/terrarum/UIItemInventoryCatBar.kt | 14 +-- .../torvald/terrarum/UIItemInventoryElem.kt | 6 +- .../terrarum/UIItemInventoryElemSimple.kt | 6 +- .../UIBuildingMakerBlockChooser.kt | 4 +- .../modulebasegame/UIBuildingMakerPenMenu.kt | 4 +- .../ui/UIBuildingMakerToolbox.kt | 9 +- .../modulebasegame/ui/UIInventoryFull.kt | 95 +++++++++++-------- .../ui/UIItemInventoryCellBase.kt | 6 +- .../ui/UIItemInventoryDynamicList.kt | 26 ++--- .../ui/UIItemInventoryEquippedView.kt | 10 +- .../modulebasegame/ui/UIItemPlayerInfoCell.kt | 6 +- .../ui/UIItemSavegameInfoCell.kt | 6 +- src/net/torvald/terrarum/ui/UIItem.kt | 9 +- .../torvald/terrarum/ui/UIItemConfigKeycap.kt | 6 +- .../torvald/terrarum/ui/UIItemImageButton.kt | 6 +- .../torvald/terrarum/ui/UIItemImageGallery.kt | 6 +- .../torvald/terrarum/ui/UIItemIntSlider.kt | 16 ++-- src/net/torvald/terrarum/ui/UIItemList.kt | 6 +- .../terrarum/ui/UIItemModuleInfoCell.kt | 6 +- src/net/torvald/terrarum/ui/UIItemTextArea.kt | 6 +- .../torvald/terrarum/ui/UIItemTextButton.kt | 6 +- .../terrarum/ui/UIItemTextButtonList.kt | 18 ++-- .../torvald/terrarum/ui/UIItemToggleButton.kt | 6 +- src/net/torvald/terrarum/ui/UIUtils.kt | 2 + 24 files changed, 153 insertions(+), 132 deletions(-) diff --git a/src/net/torvald/terrarum/UIItemInventoryCatBar.kt b/src/net/torvald/terrarum/UIItemInventoryCatBar.kt index be76d7a68..0b3fc37f7 100644 --- a/src/net/torvald/terrarum/UIItemInventoryCatBar.kt +++ b/src/net/torvald/terrarum/UIItemInventoryCatBar.kt @@ -15,10 +15,10 @@ import net.torvald.terrarum.ui.UIUtils */ class UIItemInventoryCatBar( parentUI: UIInventoryFull, - override var posX: Int, - override var posY: Int, + initialX: Int, + initialY: Int, override val width: Int -) : UIItem(parentUI) { +) : UIItem(parentUI, initialX, initialY) { // deal with the moving position override var oldPosX = posX @@ -59,8 +59,8 @@ class UIItemInventoryCatBar( backgroundCol = Color(0), highlightBackCol = Color(0), activeBackBlendMode = BlendMode.NORMAL, - posX = posX + iconPosX, - posY = posY + iconPosY, + initialX = posX + iconPosX, + initialY = posY + iconPosY, highlightable = true ) } @@ -91,8 +91,8 @@ class UIItemInventoryCatBar( backgroundCol = Color(0), highlightBackCol = Color(0), activeBackBlendMode = BlendMode.NORMAL, - posX = iconPosX, - posY = posY + iconPosY, + initialX = iconPosX, + initialY = posY + iconPosY, inactiveCol = if (index == 0 || index == 3) Color.WHITE else Color(0xffffff7f.toInt()), activeCol = if (index == 0 || index == 3) Color(0xfff066_ff.toInt()) else Color(0xffffff7f.toInt()), highlightable = (index == 0 || index == 3) diff --git a/src/net/torvald/terrarum/UIItemInventoryElem.kt b/src/net/torvald/terrarum/UIItemInventoryElem.kt index 97eb850a6..05a10a6c5 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElem.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElem.kt @@ -24,8 +24,8 @@ import net.torvald.terrarum.ui.UIItemTextButton */ class UIItemInventoryElem( parentUI: UIInventoryFull, - override var posX: Int, - override var posY: Int, + initialX: Int, + initialY: Int, override val width: Int, override var item: GameItem?, override var amount: Int, @@ -39,7 +39,7 @@ class UIItemInventoryElem( override var quickslot: Int? = null, override var equippedSlot: Int? = null, val drawBackOnNull: Boolean = true -) : UIItemInventoryCellBase(parentUI, posX, posY, item, amount, itemImage, quickslot, equippedSlot) { +) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot) { // deal with the moving position override var oldPosX = posX diff --git a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt b/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt index d5570524a..a0d1cac07 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt @@ -22,8 +22,8 @@ import net.torvald.terrarum.ui.UIItemTextButton */ class UIItemInventoryElemSimple( parentUI: UIInventoryFull, - override var posX: Int, - override var posY: Int, + initialX: Int, + initialY: Int, override var item: GameItem?, override var amount: Int, override var itemImage: TextureRegion?, @@ -37,7 +37,7 @@ class UIItemInventoryElemSimple( override var quickslot: Int? = null, override var equippedSlot: Int? = null, val drawBackOnNull: Boolean = true -) : UIItemInventoryCellBase(parentUI, posX, posY, item, amount, itemImage, quickslot, equippedSlot) { +) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot) { // deal with the moving position override var oldPosX = posX diff --git a/src/net/torvald/terrarum/modulebasegame/UIBuildingMakerBlockChooser.kt b/src/net/torvald/terrarum/modulebasegame/UIBuildingMakerBlockChooser.kt index f9f0d4e20..f319439cf 100644 --- a/src/net/torvald/terrarum/modulebasegame/UIBuildingMakerBlockChooser.kt +++ b/src/net/torvald/terrarum/modulebasegame/UIBuildingMakerBlockChooser.kt @@ -40,8 +40,8 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() { // initialise with terrain blocks UIItemImageButton( this, ItemCodex.getItemImage(it), - posX = MENUBAR_SIZE + (it % 16) * TILESREGION_SIZE, - posY = (it / 16) * TILESREGION_SIZE, + initialX = MENUBAR_SIZE + (it % 16) * TILESREGION_SIZE, + initialY = (it / 16) * TILESREGION_SIZE, highlightable = false, width = TILESREGION_SIZE, height = TILESREGION_SIZE, diff --git a/src/net/torvald/terrarum/modulebasegame/UIBuildingMakerPenMenu.kt b/src/net/torvald/terrarum/modulebasegame/UIBuildingMakerPenMenu.kt index 6fe800250..875d7f804 100644 --- a/src/net/torvald/terrarum/modulebasegame/UIBuildingMakerPenMenu.kt +++ b/src/net/torvald/terrarum/modulebasegame/UIBuildingMakerPenMenu.kt @@ -57,8 +57,8 @@ class UIBuildingMakerPenMenu(val parent: BuildingMaker): UICanvas() { backgroundCol = Color(0), highlightBackCol = Color(0), activeBackCol = Color(0), - posX = newvec.x.roundInt(), - posY = newvec.y.roundInt(), + initialX = newvec.x.roundInt(), + initialY = newvec.y.roundInt(), width = ICON_SIZE, height = ICON_SIZE, highlightable = false ) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerToolbox.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerToolbox.kt index 2f5e20523..3e8257327 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerToolbox.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerToolbox.kt @@ -11,13 +11,12 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack class UIBuildingMakerToolbox : UICanvas() { val toolsTexture = TextureRegionPack(ModMgr.getGdxFile("basegame", "gui/building_maker_toolbox.tga"), 16, 16) - val tools = Array(toolsTexture.verticalCount, { UIItemImageButton( + val tools = Array(toolsTexture.verticalCount) { UIItemImageButton( this, toolsTexture.get(0, it), - posX = 0, - posY = 20 * it, + initialX = 0, + initialY = 20 * it, highlightable = true - - ) }) + ) } override var width = 16 override var height = 20 * tools.size - 4 diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt index b0720510f..bdd0a86d6 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt @@ -23,6 +23,7 @@ import net.torvald.terrarum.ui.UIItemTextButtonList import net.torvald.terrarum.ui.UIItemTextButtonList.Companion.DEFAULT_LINE_HEIGHT import net.torvald.terrarum.ui.UIUtils import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack +import kotlin.math.roundToInt /** * Created by minjaesong on 2017-10-21. @@ -36,7 +37,7 @@ class UIInventoryFull( doNotWarnConstant: Boolean = false ) : UICanvas(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant) { - private val debugvals = false + private val debugvals = true override var width: Int = AppLoader.screenW override var height: Int = AppLoader.screenH @@ -145,7 +146,7 @@ class UIInventoryFull( private val gameMenuListWidth = 400 private val gameMenuButtons = UIItemTextButtonList( this, gameMenu, - AppLoader.screenW + (AppLoader.screenW - gameMenuListWidth) / 2, + (AppLoader.screenW - gameMenuListWidth) / 2, (itemList.height - gameMenuListHeight) / 2 + itemList.posY, gameMenuListWidth, gameMenuListHeight, readFromLang = true, @@ -157,11 +158,12 @@ class UIInventoryFull( defaultSelection = null ) - private val SCREEN_MINIMAP = 2f + private val SCREEN_MINIMAP = 0f private val SCREEN_INVENTORY = 1f - private val SCREEN_MENU = 0f + private val SCREEN_MENU = 2f - private var currentScreen = SCREEN_INVENTORY + /** 0..2 where 0 is minimap, 1 is inventory, 2 is menu. Non-integer value means transition is on-going */ + private var currentScreenTransition = SCREEN_INVENTORY private var transitionRequested = false private var transitionOngoing = false private var transitionReqSource = SCREEN_INVENTORY @@ -173,18 +175,7 @@ class UIInventoryFull( private val transitionalUpdateUIs = ArrayList() private val transitionalUpdateUIoriginalPosX = ArrayList() - - private fun addToTransitionalGroup(item: UIItem) { - transitionalUpdateUIs.add(item) - transitionalUpdateUIoriginalPosX.add(item.posX) - } - private fun updateTransitionalItems() { - for (k in 0..transitionalUpdateUIs.lastIndex) { - val intOff = inventoryScrOffX.roundInt() - transitionalUpdateUIs[k].posX = transitionalUpdateUIoriginalPosX[k] + intOff - } - } init { addItem(categoryBar) @@ -201,11 +192,6 @@ class UIInventoryFull( rebuildList() - - addToTransitionalGroup(itemList) - addToTransitionalGroup(equipped) - addToTransitionalGroup(gameMenuButtons) - // make gameMenuButtons work gameMenuButtons.selectionChangeListener = { old, new -> if (new == 0) { @@ -233,11 +219,23 @@ class UIInventoryFull( transitionalUpdateUIs.forEach { it.update(delta) } - if (currentScreen > 1f + epsilon) { + // update map while visible + if (currentScreenTransition > 1f + epsilon) { MinimapComposer.setWorld(Terrarum.ingame!!.world) MinimapComposer.update() } + // update inventory while visible + if (currentScreenTransition in epsilon..2f - epsilon) { + itemList.update(delta) + equipped.update(delta) + } + + // update menu while visible + if (currentScreenTransition < 1f - epsilon) { + gameMenuButtons.update(delta) + } + minimapRerenderTimer += Gdx.graphics.rawDeltaTime } @@ -257,7 +255,7 @@ class UIInventoryFull( fun requestTransition(target: Int) { if (!transitionOngoing) { transitionRequested = true - transitionReqSource = currentScreen.round() + transitionReqSource = currentScreenTransition.round() transitionReqTarget = target.toFloat() } } @@ -273,21 +271,20 @@ class UIInventoryFull( if (transitionOngoing) { transitionTimer += Gdx.graphics.rawDeltaTime - currentScreen = UIUtils.moveQuick(transitionReqSource, transitionReqTarget, transitionTimer, transitionLength) + currentScreenTransition = UIUtils.moveLinear(transitionReqSource, transitionReqTarget, transitionTimer, transitionLength) if (transitionTimer > transitionLength) { transitionOngoing = false - currentScreen = transitionReqTarget + currentScreenTransition = transitionReqTarget } } // update at render time - updateTransitionalItems() if (debugvals) { batch.color = Color.WHITE - AppLoader.fontSmallNumbers.draw(batch, "screen:$currentScreen", 500f, 20f) + AppLoader.fontSmallNumbers.draw(batch, "screen:$currentScreenTransition", 500f, 30f) } @@ -316,8 +313,8 @@ class UIInventoryFull( // UI items categoryBar.render(batch, camera) - - if (currentScreen > 1f + epsilon) { + // render map while visible + if (currentScreenTransition > 1f + epsilon) { renderScreenMinimap(batch, camera) if (debugvals) { @@ -326,7 +323,8 @@ class UIInventoryFull( } } - if (currentScreen in epsilon..2f - epsilon) { + // render inventory while visible + if (currentScreenTransition in epsilon..2f - epsilon) { renderScreenInventory(batch, camera) if (debugvals) { @@ -335,7 +333,8 @@ class UIInventoryFull( } } - if (currentScreen < 1f - epsilon) { + // render menu while visible + if (currentScreenTransition < 1f - epsilon) { renderScreenGamemenu(batch, camera) if (debugvals) { @@ -346,7 +345,9 @@ class UIInventoryFull( if (debugvals) { batch.color = Color.WHITE - AppLoader.fontSmallNumbers.draw(batch, "inventoryScrOffX:$inventoryScrOffX", 500f, 10f) + AppLoader.fontSmallNumbers.draw(batch, "minimap:$minimapScrOffX", 500f, 0f) + AppLoader.fontSmallNumbers.draw(batch, "inven:$inventoryScrOffX", 500f, 10f) + AppLoader.fontSmallNumbers.draw(batch, "menu:$menuScrOffX", 500f, 20f) } @@ -354,17 +355,24 @@ class UIInventoryFull( private val epsilon = 0.001f - private val minimapScrOffX: Float - get() = (currentScreen - 2f) * AppLoader.screenW /** * - 0 on inventory screen * - +WIDTH on minimap screen * - -WIDTH on gamemenu screen */ + private val minimapScrOffX: Float + get() = (currentScreenTransition - 2f) * AppLoader.screenW / 2f private val inventoryScrOffX: Float - get() = (currentScreen - 1f) * AppLoader.screenW + get() = (currentScreenTransition - 1f) * AppLoader.screenW / 2f private val menuScrOffX: Float - get() = (currentScreen) * AppLoader.screenW + get() = (currentScreenTransition - 0f) * AppLoader.screenW / 2f + + private val minimapScrOpacity: Float + get() = (currentScreenTransition - 2f).coerceIn(0f, 1f) + private val inventoryScrOpacity: Float + get() = (currentScreenTransition - 1f).coerceIn(0f, 1f) + private val menuScrOpacity: Float + get() = (currentScreenTransition - 0f).coerceIn(0f, 1f) private val MINIMAP_WIDTH = 800f private val MINIMAP_HEIGHT = itemList.height.toFloat() @@ -377,11 +385,15 @@ class UIInventoryFull( private val minimapFBO = FrameBuffer(Pixmap.Format.RGBA8888, MINIMAP_WIDTH.toInt(), MINIMAP_HEIGHT.toInt(), false) private val minimapCamera = OrthographicCamera(MINIMAP_WIDTH, MINIMAP_HEIGHT) + + // TODO put 3 bare sub-UIs into proper UIcanvas to handle the motherfucking opacity + + private fun renderScreenMinimap(batch: SpriteBatch, camera: Camera) { blendNormal(batch) // update map panning - if (currentScreen >= 2f - epsilon) { + if (currentScreenTransition >= 2f - epsilon) { // if left click is down and cursor is in the map area if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary")) && Terrarum.mouseScreenY in itemList.posY..itemList.posY + itemList.height) { @@ -455,9 +467,9 @@ class UIInventoryFull( } batch.begin() - - AppLoader.fontSmallNumbers.draw(batch, "$minimapPanX, $minimapPanY; x$minimapZoom", minimapScrOffX + (AppLoader.screenW - MINIMAP_WIDTH) / 2, -10f + itemList.posY) - + if (debugvals) { + AppLoader.fontSmallNumbers.draw(batch, "$minimapPanX, $minimapPanY; x$minimapZoom", minimapScrOffX + (AppLoader.screenW - MINIMAP_WIDTH) / 2, -10f + itemList.posY) + } batch.projectionMatrix = camera.combined // 1px stroke @@ -479,11 +491,14 @@ class UIInventoryFull( AppLoader.fontGame.draw(batch, gameMenuControlHelp, offsetX + menuScrOffX, yEnd - 20) // text buttons + gameMenuButtons.posX = gameMenuButtons.initialX + menuScrOffX.roundToInt() gameMenuButtons.render(batch, camera) } private fun renderScreenInventory(batch: SpriteBatch, camera: Camera) { + itemList.posX = itemList.initialX + inventoryScrOffX.roundToInt() itemList.render(batch, camera) + equipped.posX = equipped.initialX + inventoryScrOffX.roundToInt() equipped.render(batch, camera) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt index bb86a8816..b3dbe8580 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt @@ -18,14 +18,14 @@ import kotlin.math.roundToInt */ abstract class UIItemInventoryCellBase( parentUI: UIInventoryFull, - override var posX: Int, - override var posY: Int, + initialX: Int, + initialY: Int, open var item: GameItem?, open var amount: Int, open var itemImage: TextureRegion?, open var quickslot: Int? = null, open var equippedSlot: Int? = null -) : UIItem(parentUI) { +) : UIItem(parentUI, initialX, initialY) { abstract override fun update(delta: Float) abstract override fun render(batch: SpriteBatch, camera: Camera) } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt index d7e570fcf..efbd6dfab 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt @@ -31,13 +31,13 @@ import java.util.* class UIItemInventoryDynamicList( parentUI: UIInventoryFull, val inventory: ActorInventory, // when you're going to display List of Craftables, you could implement a Delegator...? Or just build a virtual inventory - override var posX: Int, - override var posY: Int, + initialX: Int, + initialY: Int, val horizontalCells: Int, val verticalCells: Int, val drawScrollOnRightside: Boolean = false, val drawWallet: Boolean = true -) : UIItem(parentUI) { +) : UIItem(parentUI, initialX, initialY) { // deal with the moving position override var oldPosX = posX @@ -115,8 +115,8 @@ class UIItemInventoryDynamicList( private val itemGrid = Array(horizontalCells * verticalCells) { UIItemInventoryElemSimple( parentUI = inventoryUI, - posX = this.posX + (UIItemInventoryElemSimple.height + listGap) * (it % horizontalCells), - posY = this.posY + (UIItemInventoryElemSimple.height + listGap) * (it / horizontalCells), + initialX = this.posX + (UIItemInventoryElemSimple.height + listGap) * (it % horizontalCells), + initialY = this.posY + (UIItemInventoryElemSimple.height + listGap) * (it / horizontalCells), item = null, amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT, itemImage = null, @@ -132,8 +132,8 @@ class UIItemInventoryDynamicList( private val itemList = Array(verticalCells * 2) { UIItemInventoryElem( parentUI = inventoryUI, - posX = this.posX + (largeListWidth + listGap) * (it % 2), - posY = this.posY + (UIItemInventoryElem.height + listGap) * (it / 2), + initialX = this.posX + (largeListWidth + listGap) * (it % 2), + initialY = this.posY + (UIItemInventoryElem.height + listGap) * (it / 2), width = largeListWidth, item = null, amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT, @@ -174,8 +174,8 @@ class UIItemInventoryDynamicList( highlightBackCol = Color(0), activeBackBlendMode = BlendMode.NORMAL, activeCol = defaultActiveCol, - posX = iconPosX, - posY = getIconPosY(index), + initialX = iconPosX, + initialY = getIconPosY(index), highlightable = true ) } @@ -187,8 +187,8 @@ class UIItemInventoryDynamicList( activeBackCol = Color(0), activeBackBlendMode = BlendMode.NORMAL, activeCol = defaultActiveCol, - posX = iconPosX, - posY = getIconPosY(2), + initialX = iconPosX, + initialY = getIconPosY(2), highlightable = false ) @@ -199,8 +199,8 @@ class UIItemInventoryDynamicList( activeBackCol = Color(0), activeBackBlendMode = BlendMode.NORMAL, activeCol = defaultActiveCol, - posX = iconPosX, - posY = getIconPosY(3), + initialX = iconPosX, + initialY = getIconPosY(3), highlightable = false ) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt index 7c5e7be3e..ad25e66cb 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt @@ -22,9 +22,9 @@ class UIItemInventoryEquippedView( parentUI: UIInventoryFull, val inventory: ActorInventory, val theActor: ActorWithBody, - override var posX: Int, - override var posY: Int -) : UIItem(parentUI) { + initialX: Int, + initialY: Int +) : UIItem(parentUI, initialX, initialY) { override val width = WIDTH @@ -53,8 +53,8 @@ class UIItemInventoryEquippedView( private val itemGrid = Array(2 * 6) { UIItemInventoryElemSimple( parentUI = parentUI, - posX = this.posX + (UIItemInventoryElemSimple.height + listGap) * ((it + 4) % 2), - posY = this.posY + (UIItemInventoryElemSimple.height + listGap) * ((it + 4) / 2), + initialX = this.posX + (UIItemInventoryElemSimple.height + listGap) * ((it + 4) % 2), + initialY = this.posY + (UIItemInventoryElemSimple.height + listGap) * ((it + 4) / 2), item = null, amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT, itemImage = null, diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemPlayerInfoCell.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemPlayerInfoCell.kt index b628bbccf..ed0e6940b 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemPlayerInfoCell.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemPlayerInfoCell.kt @@ -19,11 +19,11 @@ class UIItemPlayerInfoCell( parent: UICanvas, val saveInfo: ReadWorldInfo.SaveMetaData, override val width: Int, - override var posX: Int, - override var posY: Int, + initialX: Int, + initialY: Int, var highlightable: Boolean, var ingamePlayer: IngamePlayer? = null -) : UIItem(parent) { +) : UIItem(parent, initialX, initialY) { // deal with the moving position override var oldPosX = posX diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemSavegameInfoCell.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemSavegameInfoCell.kt index 442b7f6e7..4ef01eceb 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemSavegameInfoCell.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemSavegameInfoCell.kt @@ -17,9 +17,9 @@ class UIItemSavegameInfoCell( parent: UICanvas, savefile: File, 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 diff --git a/src/net/torvald/terrarum/ui/UIItem.kt b/src/net/torvald/terrarum/ui/UIItem.kt index af28f0960..e13841b5f 100644 --- a/src/net/torvald/terrarum/ui/UIItem.kt +++ b/src/net/torvald/terrarum/ui/UIItem.kt @@ -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 diff --git a/src/net/torvald/terrarum/ui/UIItemConfigKeycap.kt b/src/net/torvald/terrarum/ui/UIItemConfigKeycap.kt index 8b0c6fedc..b12fe0f7e 100644 --- a/src/net/torvald/terrarum/ui/UIItemConfigKeycap.kt +++ b/src/net/torvald/terrarum/ui/UIItemConfigKeycap.kt @@ -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)") diff --git a/src/net/torvald/terrarum/ui/UIItemImageButton.kt b/src/net/torvald/terrarum/ui/UIItemImageButton.kt index c21fb907a..8f488057e 100644 --- a/src/net/torvald/terrarum/ui/UIItemImageButton.kt +++ b/src/net/torvald/terrarum/ui/UIItemImageButton.kt @@ -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 diff --git a/src/net/torvald/terrarum/ui/UIItemImageGallery.kt b/src/net/torvald/terrarum/ui/UIItemImageGallery.kt index b763f71af..55ec41dd8 100644 --- a/src/net/torvald/terrarum/ui/UIItemImageGallery.kt +++ b/src/net/torvald/terrarum/ui/UIItemImageGallery.kt @@ -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, val column: Int = 1 -) : UIItem(parentUI) { +) : UIItem(parentUI, initialX, initialY) { // deal with the moving position override var oldPosX = posX diff --git a/src/net/torvald/terrarum/ui/UIItemIntSlider.kt b/src/net/torvald/terrarum/ui/UIItemIntSlider.kt index 9421eb2d4..8a5b8ffd5 100644 --- a/src/net/torvald/terrarum/ui/UIItemIntSlider.kt +++ b/src/net/torvald/terrarum/ui/UIItemIntSlider.kt @@ -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 diff --git a/src/net/torvald/terrarum/ui/UIItemList.kt b/src/net/torvald/terrarum/ui/UIItemList.kt index a68089257..79c633d30 100644 --- a/src/net/torvald/terrarum/ui/UIItemList.kt +++ b/src/net/torvald/terrarum/ui/UIItemList.kt @@ -14,8 +14,8 @@ import net.torvald.terrarum.fillRect class UIItemList( parentUI: UICanvas, val itemList: ArrayList, - 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( 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 diff --git a/src/net/torvald/terrarum/ui/UIItemModuleInfoCell.kt b/src/net/torvald/terrarum/ui/UIItemModuleInfoCell.kt index b6b2695aa..e6cd649f2 100644 --- a/src/net/torvald/terrarum/ui/UIItemModuleInfoCell.kt +++ b/src/net/torvald/terrarum/ui/UIItemModuleInfoCell.kt @@ -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 diff --git a/src/net/torvald/terrarum/ui/UIItemTextArea.kt b/src/net/torvald/terrarum/ui/UIItemTextArea.kt index 985dbe855..ce032dcd3 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextArea.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextArea.kt @@ -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 diff --git a/src/net/torvald/terrarum/ui/UIItemTextButton.kt b/src/net/torvald/terrarum/ui/UIItemTextButton.kt index c49d3ced0..6c3820f51 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextButton.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextButton.kt @@ -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 diff --git a/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt b/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt index 31da69d02..e91a1a130 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt @@ -12,8 +12,8 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack class UIItemTextButtonList( parentUI: UICanvas, labelsList: Array, - 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 diff --git a/src/net/torvald/terrarum/ui/UIItemToggleButton.kt b/src/net/torvald/terrarum/ui/UIItemToggleButton.kt index 50de946d9..3a78260a2 100644 --- a/src/net/torvald/terrarum/ui/UIItemToggleButton.kt +++ b/src/net/torvald/terrarum/ui/UIItemToggleButton.kt @@ -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") { diff --git a/src/net/torvald/terrarum/ui/UIUtils.kt b/src/net/torvald/terrarum/ui/UIUtils.kt index 321f7671b..3d01251d8 100644 --- a/src/net/torvald/terrarum/ui/UIUtils.kt +++ b/src/net/torvald/terrarum/ui/UIUtils.kt @@ -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 } \ No newline at end of file