From 074fe2438d8e4429878a9f5ef5ec28c8abb986da Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 29 Jan 2019 23:37:38 +0900 Subject: [PATCH] inventory gamemenu visual only --- src/net/torvald/terrarum/Terrarum.kt | 2 + .../torvald/terrarum/UIItemInventoryCatBar.kt | 76 +++++++-- .../torvald/terrarum/UIItemInventoryElem.kt | 4 + .../terrarum/UIItemInventoryElemSimple.kt | 4 + .../modulebasegame/ui/UIInventoryFull.kt | 153 ++++++++++++++++-- .../ui/UIItemInventoryDynamicList.kt | 17 +- .../ui/UIItemInventoryEquippedView.kt | 3 +- .../modulebasegame/ui/UIItemModuleInfoCell.kt | 4 + .../ui/UIItemSavegameInfoCell.kt | 4 + src/net/torvald/terrarum/ui/UIItem.kt | 19 +++ .../torvald/terrarum/ui/UIItemImageButton.kt | 4 + .../torvald/terrarum/ui/UIItemImageGallery.kt | 4 + .../torvald/terrarum/ui/UIItemIntSlider.kt | 4 + src/net/torvald/terrarum/ui/UIItemList.kt | 16 +- src/net/torvald/terrarum/ui/UIItemTextArea.kt | 4 + .../torvald/terrarum/ui/UIItemTextButton.kt | 11 +- .../terrarum/ui/UIItemTextButtonList.kt | 24 ++- src/net/torvald/terrarum/ui/UIUtils.kt | 2 +- work_files/UI/minimap_inventory_gamemenu.psd | 4 +- 19 files changed, 307 insertions(+), 52 deletions(-) diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index 23048bd56..cf40a1cd6 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -246,6 +246,7 @@ object Terrarum : Screen { RunningEnvironment.PC } //} + } @@ -689,6 +690,7 @@ fun Double.roundInt(): Int = Math.round(this).toInt() fun Float.roundInt(): Int = Math.round(this) fun Double.abs() = Math.abs(this) fun Double.sqr() = this * this +fun Float.sqr() = this * this fun Double.sqrt() = Math.sqrt(this) fun Float.sqrt() = FastMath.sqrt(this) fun Int.abs() = this.absoluteValue diff --git a/src/net/torvald/terrarum/UIItemInventoryCatBar.kt b/src/net/torvald/terrarum/UIItemInventoryCatBar.kt index f6fe68f52..264b6d2d0 100644 --- a/src/net/torvald/terrarum/UIItemInventoryCatBar.kt +++ b/src/net/torvald/terrarum/UIItemInventoryCatBar.kt @@ -6,7 +6,9 @@ import com.badlogic.gdx.graphics.Pixmap import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull -import net.torvald.terrarum.ui.* +import net.torvald.terrarum.ui.UIItem +import net.torvald.terrarum.ui.UIItemImageButton +import net.torvald.terrarum.ui.UIUtils /** * Created by minjaesong on 2017-10-20. @@ -18,6 +20,12 @@ class UIItemInventoryCatBar( override val width: Int ) : UIItem(parentUI) { + // deal with the moving position + override var oldPosX = posX + override var oldPosY = posY + + private val parentInventory = parentUI + private val catIcons = parentUI.catIcons private val catArrangement = parentUI.catArrangement @@ -91,7 +99,7 @@ class UIItemInventoryCatBar( private val underlineColour = Color(0xeaeaea_40.toInt()) private val underlineHighlightColour = mainButtons[0].highlightCol - private var highlighterXPos = mainButtons[selectedIndex].posX.toDouble() + private var highlighterXPos = mainButtons[selectedIndex].posX.toFloat() private var highlighterXStart = highlighterXPos private var highlighterXEnd = highlighterXPos @@ -100,6 +108,14 @@ class UIItemInventoryCatBar( private val highlighterMoveDuration: Second = 0.1f private var highlighterMoveTimer: Second = 0f + private var transitionFired = false + + /** + * 0: map, 1: inventory caticons, 2: menu + */ + var selectedPanel = 1 + private set + // set up underlined indicator init { // procedurally generate texture @@ -134,8 +150,8 @@ class UIItemInventoryCatBar( highlighterXPos = UIUtils.moveQuick( highlighterXStart, highlighterXEnd, - highlighterMoveTimer.toDouble(), - highlighterMoveDuration.toDouble() + highlighterMoveTimer, + highlighterMoveDuration ) if (highlighterMoveTimer > highlighterMoveDuration) { @@ -150,23 +166,61 @@ class UIItemInventoryCatBar( mainButtons.forEachIndexed { index, btn -> btn.update(delta) + if (btn.mousePushed && selectedPanel != 1) { + transitionFired = true + selectedPanel = 1 + } if (btn.mousePushed && index != selectedIndex) { + // normal stuffs val oldIndex = selectedIndex - highlighterXStart = mainButtons[selectedIndex].posX.toDouble() // using old selectedIndex + highlighterXStart = mainButtons[selectedIndex].posX.toFloat() // using old selectedIndex selectedIndex = index highlighterMoving = true - highlighterXEnd = mainButtons[selectedIndex].posX.toDouble() // using new selectedIndex + highlighterXEnd = mainButtons[selectedIndex].posX.toFloat() // using new selectedIndex selectionChangeListener?.invoke(oldIndex, index) } - btn.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null + if (selectedPanel == 1) { + btn.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null + + sideButtons[0].highlighted = false + sideButtons[3].highlighted = false + } } sideButtons[0].update(delta) sideButtons[3].update(delta) + + + // more transition stuffs + if (sideButtons[0].mousePushed) { + if (selectedPanel != 0) transitionFired = true + mainButtons.forEach { it.highlighted = false } + selectedPanel = 0 + parentInventory.requestTransition(0) + + sideButtons[0].highlighted = true + sideButtons[3].highlighted = false + } + else if (sideButtons[3].mousePushed) { + if (selectedPanel != 2) transitionFired = true + mainButtons.forEach { it.highlighted = false } + selectedPanel = 2 + parentInventory.requestTransition(2) + transitionFired = true + + sideButtons[0].highlighted = false + sideButtons[3].highlighted = true + } + + + if (transitionFired) { + transitionFired = false + parentInventory.requestTransition(2 - selectedPanel) + } } override fun render(batch: SpriteBatch, camera: Camera) { @@ -186,8 +240,12 @@ class UIItemInventoryCatBar( batch.drawStraightLine(posX.toFloat(), posY + height - 1f, posX + width.toFloat(), 1f, false) // indicator - batch.color = underlineHighlightColour - batch.draw(underlineIndTex, (highlighterXPos - buttonGapSize / 2).toFloat().round(), posY + highlighterYPos) + if (selectedPanel == 1) { + batch.color = underlineHighlightColour + batch.draw(underlineIndTex, (highlighterXPos - buttonGapSize / 2).toFloat().round(), posY + highlighterYPos) + } + + } diff --git a/src/net/torvald/terrarum/UIItemInventoryElem.kt b/src/net/torvald/terrarum/UIItemInventoryElem.kt index ee687dcd9..496cb4b80 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElem.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElem.kt @@ -36,6 +36,10 @@ class UIItemInventoryElem( val drawBackOnNull: Boolean = true ) : UIItemInventoryCellBase(parentUI, posX, posY, item, amount, itemImage, quickslot, equippedSlot) { + // deal with the moving position + override var oldPosX = posX + override var oldPosY = posY + companion object { val height = 48 val UNIQUE_ITEM_HAS_NO_AMOUNT = -1 diff --git a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt b/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt index 0c1edc5be..df5bce2f7 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt @@ -33,6 +33,10 @@ class UIItemInventoryElemSimple( val drawBackOnNull: Boolean = true ) : UIItemInventoryCellBase(parentUI, posX, posY, item, amount, itemImage, quickslot, equippedSlot) { + // deal with the moving position + override var oldPosX = posX + override var oldPosY = posY + companion object { val height = UIItemInventoryElem.height } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt index b3b442e5a..29ab78bf9 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt @@ -6,7 +6,6 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.glutils.ShapeRenderer -import com.jme3.math.FastMath import net.torvald.terrarum.* import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.langpack.Lang @@ -15,6 +14,8 @@ import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory.Companion.C import net.torvald.terrarum.modulebasegame.gameactors.Pocketed import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UIItem +import net.torvald.terrarum.ui.UIItemTextButtonList +import net.torvald.terrarum.ui.UIUtils import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack /** @@ -29,6 +30,8 @@ class UIInventoryFull( doNotWarnConstant: Boolean = false ) : UICanvas(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant) { + private val debugvals = false + override var width: Int = Terrarum.WIDTH override var height: Int = Terrarum.HEIGHT @@ -60,12 +63,12 @@ class UIInventoryFull( get() = if (AppLoader.environment == RunningEnvironment.PC) "${0xe031.toChar()} ${Lang["GAME_ACTION_CLOSE"]}" else - "${0xe031.toChar()} ${Lang["GAME_ACTION_CLOSE"]}$SP${0xe06b.toChar()} ${Lang["GAME_INVENTORY"]}" + "${0xe069.toChar()} ${Lang["GAME_ACTION_CLOSE"]}$SP${0xe06b.toChar()} ${Lang["GAME_INVENTORY"]}" val gameMenuControlHelp: String get() = if (AppLoader.environment == RunningEnvironment.PC) "${0xe031.toChar()} ${Lang["GAME_ACTION_CLOSE"]}" else - "${0xe031.toChar()} ${Lang["GAME_ACTION_CLOSE"]}$SP${0xe068.toChar()} ${Lang["GAME_INVENTORY"]}" + "${0xe069.toChar()} ${Lang["GAME_ACTION_CLOSE"]}$SP${0xe068.toChar()} ${Lang["GAME_INVENTORY"]}" val controlHelpHeight = Terrarum.fontGame.lineHeight private var encumbrancePerc = 0f @@ -104,22 +107,41 @@ class UIInventoryFull( internalWidth - UIItemInventoryEquippedView.WIDTH + (Terrarum.WIDTH - internalWidth) / 2, 109 + (Terrarum.HEIGHT - internalHeight) / 2 ) + private val gameMenuListWidth = 400 + private val gameMenuListHeight = 40 * 5 + private val gameMenuCharInfoHeight = 64 + 40 // no top margin, 40 bottom margin + private val gameMenuListTotalHeight = gameMenuListHeight + gameMenuCharInfoHeight + private val gameMenuButtons = UIItemTextButtonList( + this, arrayOf("MENU_LABEL_MAINMENU", "MENU_LABEL_DESKTOP", "MENU_OPTIONS_CONTROLS", "MENU_OPTIONS_SOUND", "MENU_LABEL_GRAPHICS"), + Terrarum.WIDTH + (Terrarum.WIDTH - gameMenuListWidth) / 2, + (itemList.height - gameMenuListTotalHeight) / 2 + itemList.posY + gameMenuCharInfoHeight, + gameMenuListWidth, gameMenuListHeight, + readFromLang = true, + textAreaWidth = gameMenuListWidth, + activeBackCol = Color(0), + highlightBackCol = Color(0), + backgroundCol = Color(0), + inactiveCol = Color.WHITE, + defaultSelection = null + ) + private val SCREEN_MINIMAP = 2f + private val SCREEN_INVENTORY = 1f + private val SCREEN_MENU = 0f - private var currentScreen = 1f // + private var currentScreen = SCREEN_INVENTORY private var transitionRequested = false + private var transitionOngoing = false + private var transitionReqSource = SCREEN_INVENTORY + private var transitionReqTarget = SCREEN_INVENTORY private var transitionTimer = 0f - private val transitionLength = 0.5f - - private val SCREEN_MINIMAP = 0 - private val SCREEN_INVENTORY = 1 - private val SCREEN_MENU = 2 + private val transitionLength = 0.333f private val transitionalUpdateUIs = ArrayList() private val transitionalUpdateUIoriginalPosX = ArrayList() - - + + private fun addToTransitionalGroup(item: UIItem) { transitionalUpdateUIs.add(item) transitionalUpdateUIoriginalPosX.add(item.posX) @@ -151,6 +173,7 @@ class UIInventoryFull( addToTransitionalGroup(itemList) addToTransitionalGroup(equipped) + addToTransitionalGroup(gameMenuButtons) } private var offsetX = ((Terrarum.WIDTH - internalWidth) / 2).toFloat() @@ -165,8 +188,9 @@ class UIInventoryFull( categoryBar.update(delta) - itemList.update(delta) - equipped.update(delta) + + transitionalUpdateUIs.forEach { it.update(delta) } + } private val gradStartCol = Color(0x404040_60) @@ -179,13 +203,41 @@ class UIInventoryFull( private var xEnd = (Terrarum.WIDTH + internalWidth).div(2).toFloat() private var yEnd = (Terrarum.HEIGHT + internalHeight).div(2).toFloat() + fun requestTransition(target: Int) { + if (!transitionOngoing) { + transitionRequested = true + transitionReqSource = currentScreen.round() + transitionReqTarget = target.toFloat() + } + } + override fun renderUI(batch: SpriteBatch, camera: Camera) { - currentScreen = 1f + 0.1f * FastMath.sin(transitionTimer) - transitionTimer += Gdx.graphics.deltaTime + if (transitionRequested && !transitionOngoing) { + transitionRequested = false + transitionOngoing = true + transitionTimer = 0f + } + + if (transitionOngoing) { + transitionTimer += Gdx.graphics.deltaTime + + currentScreen = UIUtils.moveQuick(transitionReqSource, transitionReqTarget, transitionTimer, transitionLength) + + if (transitionTimer > transitionLength) { + transitionOngoing = false + currentScreen = transitionReqTarget + } + } + + // update at render time updateTransitionalItems() + if (debugvals) { + batch.color = Color.WHITE + AppLoader.fontSmallNumbers.draw(batch, "screen:$currentScreen", 500f, 20f) + } @@ -213,16 +265,83 @@ class UIInventoryFull( categoryBar.render(batch, camera) - renderScreenInventory(batch, camera) + if (currentScreen > 1f + epsilon) { + renderScreenMinimap(batch, camera) + + if (debugvals) { + batch.color = Color.CORAL + AppLoader.fontSmallNumbers.draw(batch, "Map", 300f, 10f) + } + } + + if (currentScreen in epsilon..2f - epsilon) { + renderScreenInventory(batch, camera) + + if (debugvals) { + batch.color = Color.CHARTREUSE + AppLoader.fontSmallNumbers.draw(batch, "Inv", 350f, 10f) + } + } + + if (currentScreen < 1f - epsilon) { + renderScreenGamemenu(batch, camera) + + if (debugvals) { + batch.color = Color.SKY + AppLoader.fontSmallNumbers.draw(batch, "Men", 400f, 10f) + } + } + + if (debugvals) { + batch.color = Color.WHITE + AppLoader.fontSmallNumbers.draw(batch, "inventoryScrOffX:$inventoryScrOffX", 500f, 10f) + } + + } + private val epsilon = 0.001f + private val minimapScrOffX: Float - get() = (currentScreen + 1f) * Terrarum.WIDTH + get() = (currentScreen - 2f) * Terrarum.WIDTH + /** + * - 0 on inventory screen + * - +WIDTH on minimap screen + * - -WIDTH on gamemenu screen + */ private val inventoryScrOffX: Float get() = (currentScreen - 1f) * Terrarum.WIDTH private val menuScrOffX: Float get() = (currentScreen) * Terrarum.WIDTH + private fun renderScreenMinimap(batch: SpriteBatch, camera: Camera) { + // control hints + blendNormal(batch) + batch.color = Color.WHITE + Terrarum.fontGame.draw(batch, minimapControlHelp, offsetX + minimapScrOffX, yEnd - 20) + } + + private fun renderScreenGamemenu(batch: SpriteBatch, camera: Camera) { + // control hints + blendNormal(batch) + batch.color = Color.WHITE + Terrarum.fontGame.draw(batch, gameMenuControlHelp, offsetX + menuScrOffX, yEnd - 20) + + // text buttons + gameMenuButtons.render(batch, camera) + + // character info window + + // !! DUMMY !! + batch.color = itemList.backColour + batch.fillRect( + ((Terrarum.WIDTH - 400) / 2) + menuScrOffX, + (itemList.height - gameMenuListTotalHeight) / 2 + itemList.posY.toFloat(), + gameMenuListWidth.toFloat(), + 64f + ) + } + private fun renderScreenInventory(batch: SpriteBatch, camera: Camera) { itemList.render(batch, camera) equipped.render(batch, camera) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt index 9e392795d..fd0b7dc49 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt @@ -32,8 +32,14 @@ class UIItemInventoryDynamicList( override var posY: Int ) : UIItem(parentUI) { - override val width = 496 - override val height = 384 + // deal with the moving position + override var oldPosX = posX + override var oldPosY = posY + + override val width = WIDTH + override val height = HEIGHT + + val backColour = Color(0x404040_88) private val catArrangement = parentUI.catArrangement @@ -94,7 +100,7 @@ class UIItemInventoryDynamicList( itemImage = null, mouseoverBackCol = Color(0x282828_ff), mouseoverBackBlendMode = BlendMode.SCREEN, - backCol = Color(0x404040_88), + backCol = backColour, backBlendMode = BlendMode.NORMAL, drawBackOnNull = true, inactiveTextCol = defaultTextColour @@ -111,7 +117,7 @@ class UIItemInventoryDynamicList( itemImage = null, mouseoverBackCol = Color(0x282828_ff), mouseoverBackBlendMode = BlendMode.SCREEN, - backCol = Color(0x404040_88), + backCol = backColour, backBlendMode = BlendMode.NORMAL, drawBackOnNull = true, inactiveTextCol = defaultTextColour @@ -165,9 +171,6 @@ class UIItemInventoryDynamicList( highlightable = false ) - // deal with the moving position - private var oldPosX = posX - fun scrollItemPage(relativeAmount: Int) { itemPage = if (itemPageCount == 0) 0 else (itemPage + relativeAmount).fmod(itemPageCount) } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt index 6df659c1e..b8ffc9c83 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt @@ -63,7 +63,8 @@ class UIItemInventoryEquippedView( private val spriteDrawCol = Color(0xddddddff.toInt()) // deal with the moving position - private var oldPosX = posX + override var oldPosX = posX + override var oldPosY = posY override fun render(batch: SpriteBatch, camera: Camera) { val posXDelta = posX - oldPosX diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemModuleInfoCell.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemModuleInfoCell.kt index 68ae60a86..ec40ebe0a 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemModuleInfoCell.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemModuleInfoCell.kt @@ -18,6 +18,10 @@ class UIItemModuleInfoCell( override var posY: Int ) : UIItem(parent) { + // deal with the moving position + override var oldPosX = posX + override var oldPosY = posY + override val height: Int = Terrarum.fontGame.lineHeight.toInt() * 2 private val numberAreaWidth = Terrarum.fontSmallNumbers.W * 3 + 4 diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemSavegameInfoCell.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemSavegameInfoCell.kt index 9082ded7d..59b256408 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemSavegameInfoCell.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemSavegameInfoCell.kt @@ -20,6 +20,10 @@ class UIItemSavegameInfoCell( override var posY: Int ) : UIItem(parent) { + // deal with the moving position + override var oldPosX = posX + override var oldPosY = posY + override val height: Int = Terrarum.fontGame.lineHeight.toInt() * 2 override fun render(batch: SpriteBatch, camera: Camera) { diff --git a/src/net/torvald/terrarum/ui/UIItem.kt b/src/net/torvald/terrarum/ui/UIItem.kt index b0d4bcd24..830d5dc75 100644 --- a/src/net/torvald/terrarum/ui/UIItem.kt +++ b/src/net/torvald/terrarum/ui/UIItem.kt @@ -44,6 +44,25 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI abstract val width: Int abstract val height: Int + /** This variable is NOT updated on its own. + * ``` + * val posXDelta = posX - oldPosX + * itemGrid.forEach { it.posX += posXDelta } + * ... + * oldPosX = posX + * ``` + */ + protected abstract var oldPosX: Int + /** This variable is NOT updated on its own. + * ``` + * val posYDelta = posY - oldPosY + * itemGrid.forEach { it.posY += posYDelta } + * ... + * oldPosY = posY + * ``` + */ + protected abstract var oldPosY: Int + /** Position of mouse relative to this item */ protected val relativeMouseX: Int get() = (Terrarum.mouseScreenX - (parentUI.posX) - this.posX) diff --git a/src/net/torvald/terrarum/ui/UIItemImageButton.kt b/src/net/torvald/terrarum/ui/UIItemImageButton.kt index 16206c0d5..ac4e1257f 100644 --- a/src/net/torvald/terrarum/ui/UIItemImageButton.kt +++ b/src/net/torvald/terrarum/ui/UIItemImageButton.kt @@ -35,6 +35,10 @@ open class UIItemImageButton( var highlightable: Boolean ) : UIItem(parent) { + // deal with the moving position + override var oldPosX = posX + override var oldPosY = posY + var highlighted = false override fun render(batch: SpriteBatch, camera: Camera) { diff --git a/src/net/torvald/terrarum/ui/UIItemImageGallery.kt b/src/net/torvald/terrarum/ui/UIItemImageGallery.kt index a0f486cae..78daa81e8 100644 --- a/src/net/torvald/terrarum/ui/UIItemImageGallery.kt +++ b/src/net/torvald/terrarum/ui/UIItemImageGallery.kt @@ -20,6 +20,10 @@ class UIItemImageGallery( val column: Int = 1 ) : UIItem(parentUI) { + // deal with the moving position + override var oldPosX = posX + override var oldPosY = posY + override fun update(delta: Float) { } diff --git a/src/net/torvald/terrarum/ui/UIItemIntSlider.kt b/src/net/torvald/terrarum/ui/UIItemIntSlider.kt index 0457fe6ea..9421eb2d4 100644 --- a/src/net/torvald/terrarum/ui/UIItemIntSlider.kt +++ b/src/net/torvald/terrarum/ui/UIItemIntSlider.kt @@ -67,6 +67,10 @@ class UIItemIntSlider( ) + // deal with the moving position + override var oldPosX = posX + override var oldPosY = posY + var value = initValue diff --git a/src/net/torvald/terrarum/ui/UIItemList.kt b/src/net/torvald/terrarum/ui/UIItemList.kt index bc3ee95d9..e38510559 100644 --- a/src/net/torvald/terrarum/ui/UIItemList.kt +++ b/src/net/torvald/terrarum/ui/UIItemList.kt @@ -36,6 +36,10 @@ class UIItemList( val border: Int = 0 ) : UIItem(parentUI) { + // deal with the moving position + override var oldPosX = posX + override var oldPosY = posY + init { itemList.forEachIndexed { index, item -> item.posX = this.posX + border @@ -47,7 +51,7 @@ class UIItemList( var selectedIndex: Int? = defaultSelection val selectedButton: UIItem? get() = if (selectedIndex != null) itemList[selectedIndex!!] else null - private var highlightY: Double? = if (selectedIndex != null) itemList[selectedIndex!!].posY.toDouble() else null + private var highlightY: Float? = if (selectedIndex != null) itemList[selectedIndex!!].posY.toFloat() else null private val highlighterMoveDuration: Second = 0.1f private var highlighterMoveTimer: Second = 0f private var highlighterMoving = false @@ -66,8 +70,8 @@ class UIItemList( highlightY = UIUtils.moveQuick( highlighterYStart!!, highlighterYEnd!!, - highlighterMoveTimer.toDouble(), - highlighterMoveDuration.toDouble() + highlighterMoveTimer, + highlighterMoveDuration ) } @@ -87,14 +91,14 @@ class UIItemList( val oldIndex = selectedIndex if (kinematic) { - highlighterYStart = itemList[selectedIndex!!].posY.toDouble() + highlighterYStart = itemList[selectedIndex!!].posY.toFloat() selectedIndex = index highlighterMoving = true - highlighterYEnd = itemList[selectedIndex!!].posY.toDouble() + highlighterYEnd = itemList[selectedIndex!!].posY.toFloat() } else { selectedIndex = index - highlightY = itemList[selectedIndex!!].posY.toDouble() + highlightY = itemList[selectedIndex!!].posY.toFloat() } selectionChangeListener?.invoke(oldIndex, index) diff --git a/src/net/torvald/terrarum/ui/UIItemTextArea.kt b/src/net/torvald/terrarum/ui/UIItemTextArea.kt index a74727efa..19c878ea4 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextArea.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextArea.kt @@ -17,6 +17,10 @@ class UIItemTextArea( val align: Alignment = Alignment.LEFT ) : UIItem(parentUI) { + // deal with the moving position + override var oldPosX = posX + override var oldPosY = posY + private var entireText: List = listOf("") // placeholder var scrollPos = 0 diff --git a/src/net/torvald/terrarum/ui/UIItemTextButton.kt b/src/net/torvald/terrarum/ui/UIItemTextButton.kt index b27d6cc63..6ea3bb16b 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextButton.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextButton.kt @@ -1,11 +1,14 @@ package net.torvald.terrarum.ui import com.badlogic.gdx.graphics.Camera -import net.torvald.terrarum.* -import net.torvald.terrarum.langpack.Lang import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.GlyphLayout import com.badlogic.gdx.graphics.g2d.SpriteBatch +import net.torvald.terrarum.BlendMode +import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.blendNormal +import net.torvald.terrarum.fillRect +import net.torvald.terrarum.langpack.Lang /** * Text button. Height of hitbox is extended (double lineHeight, or 40 px) for better clicking @@ -34,6 +37,10 @@ open class UIItemTextButton( val hitboxSize: Int = UIItemTextButton.height ) : UIItem(parentUI) { + // deal with the moving position + override var oldPosX = posX + override var oldPosY = posY + companion object { val font = Terrarum.fontGame val height = font.lineHeight.toInt() diff --git a/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt b/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt index f02120ffd..e199375b9 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt @@ -4,8 +4,8 @@ import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.BlendMode -import net.torvald.terrarum.fillRect import net.torvald.terrarum.Second +import net.torvald.terrarum.fillRect import net.torvald.terrarum.gameactors.ai.toInt import net.torvald.terrarum.roundInt import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack @@ -45,6 +45,10 @@ class UIItemTextButtonList( val itemHitboxSize: Int = UIItemTextButton.height ) : UIItem(parentUI) { + // deal with the moving position + override var oldPosX = posX + override var oldPosY = posY + val iconToTextGap = 20 val iconCellWidth = (iconSpriteSheet?.tileW ?: -iconToTextGap) / (iconSpriteSheet?.horizontalCount ?: 1) val iconCellHeight = (iconSpriteSheet?.tileH ?: 0) / (iconSpriteSheet?.verticalCount ?: 1) @@ -130,7 +134,7 @@ class UIItemTextButtonList( var selectedIndex: Int? = defaultSelection val selectedButton: UIItemTextButton? get() = if (selectedIndex != null) buttons[selectedIndex!!] else null - private var highlightY: Double? = if (selectedIndex != null) buttons[selectedIndex!!].posY.toDouble() else null + private var highlightY: Float? = if (selectedIndex != null) buttons[selectedIndex!!].posY.toFloat() else null private val highlighterMoveDuration: Second = 0.1f private var highlighterMoveTimer: Second = 0f private var highlighterMoving = false @@ -141,6 +145,10 @@ class UIItemTextButtonList( var selectionChangeListener: ((Int?, Int) -> Unit)? = null override fun update(delta: Float) { + val posXDelta = posX - oldPosX + buttons.forEach { it.posX += posXDelta } + + if (highlighterMoving) { highlighterMoveTimer += delta @@ -148,8 +156,8 @@ class UIItemTextButtonList( highlightY = UIUtils.moveQuick( highlighterYStart!!, highlighterYEnd!!, - highlighterMoveTimer.toDouble(), - highlighterMoveDuration.toDouble() + highlighterMoveTimer.toFloat(), + highlighterMoveDuration.toFloat() ) } @@ -170,13 +178,13 @@ class UIItemTextButtonList( if (kinematic) { selectedIndex = index - highlighterYStart = buttons[selectedIndex!!].posY.toDouble() + highlighterYStart = buttons[selectedIndex!!].posY.toFloat() highlighterMoving = true - highlighterYEnd = buttons[selectedIndex!!].posY.toDouble() + highlighterYEnd = buttons[selectedIndex!!].posY.toFloat() } else { selectedIndex = index - highlightY = buttons[selectedIndex!!].posY.toDouble() + highlightY = buttons[selectedIndex!!].posY.toFloat() } selectionChangeListener?.invoke(oldIndex, index) @@ -184,6 +192,8 @@ class UIItemTextButtonList( btn.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null } + + oldPosX = posX } override fun render(batch: SpriteBatch, camera: Camera) { diff --git a/src/net/torvald/terrarum/ui/UIUtils.kt b/src/net/torvald/terrarum/ui/UIUtils.kt index 75e6a505d..321f7671b 100644 --- a/src/net/torvald/terrarum/ui/UIUtils.kt +++ b/src/net/torvald/terrarum/ui/UIUtils.kt @@ -6,6 +6,6 @@ import net.torvald.terrarum.sqr * Created by minjaesong on 2017-03-14. */ object UIUtils { - fun moveQuick(start: Double, end: Double, timer: Double, duration: Double) = + fun moveQuick(start: Float, end: Float, timer: Float, duration: Float) = (start - end) * ((timer / duration) - 1).sqr() + end } \ No newline at end of file diff --git a/work_files/UI/minimap_inventory_gamemenu.psd b/work_files/UI/minimap_inventory_gamemenu.psd index a8029d4bf..14ab4d117 100644 --- a/work_files/UI/minimap_inventory_gamemenu.psd +++ b/work_files/UI/minimap_inventory_gamemenu.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:af8584763d76b2328842666f03fe7a15aea3d9257b3d1941b2176bdebcc01f41 -size 11525251 +oid sha256:97a2323911258409169a7c3aa1d266f804b256c60d06471ac825f2fb128b1fd3 +size 13524503