From de164f6516b31d4ee1aa6fb6c590d2d48555f863 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 30 Aug 2020 16:09:42 +0900 Subject: [PATCH 1/8] inventory ui transition wip --- assets/mods/basegame/materials/materials.csv | 2 +- .../torvald/terrarum/UIItemInventoryCatBar.kt | 4 - .../torvald/terrarum/UIItemInventoryElem.kt | 4 - .../terrarum/UIItemInventoryElemSimple.kt | 6 +- .../terrarum/blockproperties/BlockCodex.kt | 6 + .../modulebasegame/ui/UIInventoryCells.kt | 145 ++++++++++++ .../modulebasegame/ui/UIInventoryFull.kt | 207 +++++++----------- .../ui/UIItemInventoryDynamicList.kt | 4 +- .../ui/UIItemInventoryEquippedView.kt | 6 +- .../modulebasegame/ui/UIItemPlayerInfoCell.kt | 4 - .../ui/UIItemSavegameInfoCell.kt | 4 - .../modulebasegame/weather/WeatherMixer.kt | 4 +- .../terrarum/tests/WorldgenNoiseSandbox.kt | 24 +- src/net/torvald/terrarum/ui/UICanvas.kt | 16 +- src/net/torvald/terrarum/ui/UIHandler.kt | 3 + src/net/torvald/terrarum/ui/UIItem.kt | 4 +- .../torvald/terrarum/ui/UIItemConfigKeycap.kt | 3 - .../terrarum/ui/UIItemHorizontalFadeSlide.kt | 41 ++++ .../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 | 4 - .../terrarum/ui/UIItemModuleInfoCell.kt | 4 - src/net/torvald/terrarum/ui/UIItemTextArea.kt | 4 - .../torvald/terrarum/ui/UIItemTextButton.kt | 4 - .../terrarum/ui/UIItemTextButtonList.kt | 4 - .../torvald/terrarum/ui/UIItemToggleButton.kt | 2 - .../terrarum/ui/UIItemTransitionContainer.kt | 95 ++++++++ src/net/torvald/terrarum/ui/UIUtils.kt | 15 +- terrarum.iml | 1 - 30 files changed, 415 insertions(+), 217 deletions(-) create mode 100644 src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt create mode 100644 src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt create mode 100644 src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt diff --git a/assets/mods/basegame/materials/materials.csv b/assets/mods/basegame/materials/materials.csv index 803b63d5a..02021f213 100644 --- a/assets/mods/basegame/materials/materials.csv +++ b/assets/mods/basegame/materials/materials.csv @@ -8,7 +8,7 @@ "EAUR"; "768"; "0";"8192"; "21"; "1.36"; "1.0";"elven aurichalcum" "TIAL"; "900"; "0";"4420"; "33"; "2.16"; "1.0";"titanium alloy (Ti6Al4V)" "ADMT";"2000";"4090";"2700"; "71"; "3.42"; "1.0";"adamant" -"OOZE"; "20"; "0";"1000"; "1"; "N/A"; "0.5";"genetic ooze; data is about human skin" +"OOZE"; "20"; "0";"1000"; "1"; "0.08"; "0.5";"genetic ooze; data is about human skin" "BONE"; "130"; "0";"2000"; "1"; "0.23"; "0.55";"data is that of bovine bone" # idst: ID_STRING, ALL CAPS diff --git a/src/net/torvald/terrarum/UIItemInventoryCatBar.kt b/src/net/torvald/terrarum/UIItemInventoryCatBar.kt index 0b3fc37f7..4859119ee 100644 --- a/src/net/torvald/terrarum/UIItemInventoryCatBar.kt +++ b/src/net/torvald/terrarum/UIItemInventoryCatBar.kt @@ -20,10 +20,6 @@ class UIItemInventoryCatBar( override val width: Int ) : UIItem(parentUI, initialX, initialY) { - // deal with the moving position - override var oldPosX = posX - override var oldPosY = posY - private val parentInventory = parentUI private val catIcons = parentUI.catIcons diff --git a/src/net/torvald/terrarum/UIItemInventoryElem.kt b/src/net/torvald/terrarum/UIItemInventoryElem.kt index 05a10a6c5..1123272db 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElem.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElem.kt @@ -41,10 +41,6 @@ class UIItemInventoryElem( val drawBackOnNull: Boolean = true ) : UIItemInventoryCellBase(parentUI, initialX, initialY, 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 a0d1cac07..867b9049f 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt @@ -38,11 +38,7 @@ class UIItemInventoryElemSimple( override var equippedSlot: Int? = null, val drawBackOnNull: Boolean = true ) : UIItemInventoryCellBase(parentUI, initialX, initialY, 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/blockproperties/BlockCodex.kt b/src/net/torvald/terrarum/blockproperties/BlockCodex.kt index c3244c980..07d5e54c4 100644 --- a/src/net/torvald/terrarum/blockproperties/BlockCodex.kt +++ b/src/net/torvald/terrarum/blockproperties/BlockCodex.kt @@ -178,6 +178,8 @@ fun str16ToInt(rec: CSVRecord, s: String): Int { } catch (e1: IllegalStateException) { } + catch (e2: NullPointerException) { + } return ret } @@ -191,6 +193,8 @@ fun intVal(rec: CSVRecord, s: String): Int { } catch (e1: IllegalStateException) { } + catch (e2: NullPointerException) { + } return ret } @@ -204,6 +208,8 @@ fun floatVal(rec: CSVRecord, s: String): Float { } catch (e1: IllegalStateException) { } + catch (e2: NullPointerException) { + } return ret } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt new file mode 100644 index 000000000..c37c4c2ae --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt @@ -0,0 +1,145 @@ +package net.torvald.terrarum.modulebasegame.ui + +import com.badlogic.gdx.graphics.Camera +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import net.torvald.terrarum.* +import net.torvald.terrarum.gameactors.ActorWithBody +import net.torvald.terrarum.langpack.Lang +import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory +import net.torvald.terrarum.ui.UICanvas +import kotlin.math.roundToInt + +internal class UIInventoryCells( + val full: UIInventoryFull +) : UICanvas() { + + override var width: Int = AppLoader.screenW + override var height: Int = AppLoader.screenH + override var openCloseTime: Second = 0.0f + + + private val weightBarWidth = UIItemInventoryElemSimple.height * 2f + UIItemInventoryDynamicList.listGap + + internal var encumbrancePerc = 0f + private set + internal var isEncumbered = false + private set + + + internal val itemList: UIItemInventoryDynamicList = + UIItemInventoryDynamicList( + full, + full.actor.inventory, + 0 + (AppLoader.screenW - full.internalWidth) / 2, + 107 + (AppLoader.screenH - full.internalHeight) / 2, + full.CELLS_HOR, full.CELLS_VRT + ) + + + private val equipped: UIItemInventoryEquippedView = + UIItemInventoryEquippedView( + full, + full.actor.inventory, + full.actor as ActorWithBody, + full.internalWidth - UIItemInventoryEquippedView.WIDTH + (AppLoader.screenW - full.internalWidth) / 2, + 107 + (AppLoader.screenH - full.internalHeight) / 2 + ) + + fun rebuildList() { + AppLoader.printdbg(this, "rebuilding list") + + itemList.rebuild(full.catIconsMeaning[full.categoryBar.selectedIcon]) + equipped.rebuild() + + encumbrancePerc = full.actor.inventory.capacity.toFloat() / full.actor.inventory.maxCapacity + isEncumbered = full.actor.inventory.isEncumbered + } + + fun resetStatusAsCatChanges(oldcat: Int?, newcat: Int) { + itemList.itemPage = 0 // set scroll to zero + itemList.rebuild(full.catIconsMeaning[full.catArrangement[newcat]]) // have to manually rebuild, too! + } + + override fun updateUI(delta: Float) { + itemList.update(delta) + equipped.update(delta) + } + + override fun renderUI(batch: SpriteBatch, camera: Camera) { + //itemList.posX = itemList.initialX + inventoryScrOffX.roundToInt() + itemList.render(batch, camera) + //equipped.posX = equipped.initialX + inventoryScrOffX.roundToInt() + equipped.render(batch, camera) + + + // control hints + val controlHintXPos = full.offsetX + blendNormal(batch) + batch.color = Color.WHITE + AppLoader.fontGame.draw(batch, full.listControlHelp, controlHintXPos, full.yEnd - 20) + + + // encumbrance meter + val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"] + // encumbrance bar will go one row down if control help message is too long + val encumbBarXPos = full.xEnd - weightBarWidth + val encumbBarTextXPos = encumbBarXPos - 6 - AppLoader.fontGame.getWidth(encumbranceText) + val encumbBarYPos = full.yEnd-20 + 3f + + if (AppLoader.fontGame.getWidth(full.listControlHelp) + 2 + controlHintXPos >= encumbBarTextXPos) + AppLoader.fontGame.lineHeight + else 0f + + AppLoader.fontGame.draw(batch, + encumbranceText, + encumbBarTextXPos, + encumbBarYPos - 3f + ) + + // encumbrance bar background + blendNormal(batch) + val encumbCol = UIItemInventoryCellCommonRes.getHealthMeterColour(1f - encumbrancePerc, 0f, 1f) + val encumbBack = encumbCol mul UIItemInventoryCellCommonRes.meterBackDarkening + batch.color = encumbBack + batch.fillRect( + encumbBarXPos, encumbBarYPos, + weightBarWidth, full.controlHelpHeight - 6f + ) + // encumbrance bar + batch.color = encumbCol + batch.fillRect( + encumbBarXPos, encumbBarYPos, + if (full.actor.inventory.capacityMode == ActorInventory.CAPACITY_MODE_NO_ENCUMBER) + 1f + else // make sure 1px is always be seen + minOf(weightBarWidth, maxOf(1f, weightBarWidth * encumbrancePerc)), + full.controlHelpHeight - 6f + ) + // debug text + batch.color = Color.LIGHT_GRAY + if (AppLoader.IS_DEVELOPMENT_BUILD) { + AppLoader.fontSmallNumbers.draw(batch, + "${full.actor.inventory.capacity}/${full.actor.inventory.maxCapacity}", + encumbBarTextXPos, + encumbBarYPos + full.controlHelpHeight - 4f + ) + } + } + + override fun doOpening(delta: Float) { + } + + override fun doClosing(delta: Float) { + } + + override fun endOpening(delta: Float) { + } + + override fun endClosing(delta: Float) { + } + + override fun dispose() { + itemList.dispose() + equipped.dispose() + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt index bdd0a86d6..e98a90f2e 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt @@ -1,29 +1,21 @@ package net.torvald.terrarum.modulebasegame.ui import com.badlogic.gdx.Gdx -import com.badlogic.gdx.Input import com.badlogic.gdx.graphics.* import com.badlogic.gdx.graphics.g2d.SpriteBatch -import com.badlogic.gdx.graphics.glutils.FrameBuffer import com.badlogic.gdx.graphics.glutils.ShapeRenderer import net.torvald.ENDASH import net.torvald.terrarum.* import net.torvald.terrarum.AppLoader.* import net.torvald.terrarum.blockstats.MinimapComposer -import net.torvald.terrarum.gameactors.ActorWithBody import net.torvald.terrarum.gameitem.GameItem import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.modulebasegame.TerrarumIngame -import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory.Companion.CAPACITY_MODE_NO_ENCUMBER import net.torvald.terrarum.modulebasegame.gameactors.Pocketed import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryDynamicList.Companion.CAT_ALL -import net.torvald.terrarum.ui.UICanvas -import net.torvald.terrarum.ui.UIItem -import net.torvald.terrarum.ui.UIItemTextButtonList +import net.torvald.terrarum.ui.* 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. @@ -41,11 +33,12 @@ class UIInventoryFull( override var width: Int = AppLoader.screenW override var height: Int = AppLoader.screenH + override var openCloseTime: Second = 0.0f - private val REQUIRED_MARGIN = 166 // hard-coded value. Don't know the details + val REQUIRED_MARGIN = 166 // hard-coded value. Don't know the details - private val CELLS_HOR = 10 - private val CELLS_VRT = (AppLoader.screenH - REQUIRED_MARGIN - 134 + UIItemInventoryDynamicList.listGap) / // 134 is another magic number + val CELLS_HOR = 10 + val CELLS_VRT = (AppLoader.screenH - REQUIRED_MARGIN - 134 + UIItemInventoryDynamicList.listGap) / // 134 is another magic number (UIItemInventoryElemSimple.height + UIItemInventoryDynamicList.listGap) private val itemListToEquipViewGap = UIItemInventoryDynamicList.listGap // used to be 24; figured out that the extra gap does nothig @@ -53,6 +46,8 @@ class UIInventoryFull( val internalWidth: Int = UIItemInventoryDynamicList.getEstimatedW(CELLS_HOR) + UIItemInventoryEquippedView.WIDTH + itemListToEquipViewGap val internalHeight: Int = REQUIRED_MARGIN + UIItemInventoryDynamicList.getEstimatedH(CELLS_VRT) // grad_begin..grad_end..contents..grad_begin..grad_end + val itemListHeight: Int = CELLS_VRT * UIItemInventoryElemSimple.height + (CELLS_VRT - 1) * net.torvald.terrarum.modulebasegame.ui.UIItemInventoryDynamicList.Companion.listGap + init { handler.allowESCtoClose = true CommonResourcePool.addToLoadingList("inventory_caticons") { @@ -107,10 +102,6 @@ class UIInventoryFull( "$gamepadLabelLT ${Lang["GAME_INVENTORY"]}" val controlHelpHeight = AppLoader.fontGame.lineHeight - private var encumbrancePerc = 0f - private var isEncumbered = false - - val catBarWidth = 330 val categoryBar = UIItemInventoryCatBar( this, @@ -120,34 +111,27 @@ class UIInventoryFull( ) - override var openCloseTime: Second = 0.0f + private val transitionalMinimap = UIInventoryCells(this) // PLACEHOLDER + private val transitionalItemCells = UIInventoryCells(this) + private val transitionalEscMenu = UIInventoryCells(this) // PLACEHOLDER + private val transitionPanel = UIItemHorizontalFadeSlide( + this, + (AppLoader.screenW - internalWidth) / 2, + 107 + (AppLoader.screenH - internalHeight) / 2, + AppLoader.screenW, + AppLoader.screenH, + 1f, + transitionalMinimap, transitionalItemCells, transitionalEscMenu + ) - internal val itemList: UIItemInventoryDynamicList = - UIItemInventoryDynamicList( - this, - actor.inventory, - 0 + (AppLoader.screenW - internalWidth) / 2, - 107 + (AppLoader.screenH - internalHeight) / 2, - CELLS_HOR, CELLS_VRT - ) - - - private val equipped: UIItemInventoryEquippedView = - UIItemInventoryEquippedView( - this, - actor.inventory, - actor as ActorWithBody, - internalWidth - UIItemInventoryEquippedView.WIDTH + (AppLoader.screenW - internalWidth) / 2, - 107 + (AppLoader.screenH - internalHeight) / 2 - ) private val gameMenu = arrayOf("MENU_LABEL_MAINMENU", "MENU_LABEL_DESKTOP", "MENU_OPTIONS_CONTROLS", "MENU_OPTIONS_SOUND", "MENU_LABEL_GRAPHICS") private val gameMenuListHeight = DEFAULT_LINE_HEIGHT * gameMenu.size private val gameMenuListWidth = 400 private val gameMenuButtons = UIItemTextButtonList( this, gameMenu, (AppLoader.screenW - gameMenuListWidth) / 2, - (itemList.height - gameMenuListHeight) / 2 + itemList.posY, + (transitionalItemCells.itemList.height - gameMenuListHeight) / 2 + transitionalItemCells.itemList.posY, gameMenuListWidth, gameMenuListHeight, readFromLang = true, textAreaWidth = gameMenuListWidth, @@ -162,31 +146,19 @@ class UIInventoryFull( private val SCREEN_INVENTORY = 1f private val SCREEN_MENU = 2f - /** 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 - private var transitionReqTarget = SCREEN_INVENTORY - private var transitionTimer = 0f - private val transitionLength = 0.212f - - - private val transitionalUpdateUIs = ArrayList() - private val transitionalUpdateUIoriginalPosX = ArrayList() init { - addItem(categoryBar) - itemList.let { addItem(it) } - equipped.let { addItem(it) } + addUIitem(categoryBar) + addUIitem(transitionPanel) + //itemList.let { addUIitem(it) } + //equipped.let { addUIitem(it) } categoryBar.selectionChangeListener = { old, new -> rebuildList() - itemList.itemPage = 0 // set scroll to zero - itemList.rebuild(catIconsMeaning[catArrangement[new]]) // have to manually rebuild, too! + transitionalItemCells.resetStatusAsCatChanges(old, new) } @@ -204,10 +176,12 @@ class UIInventoryFull( } - private var offsetX = ((AppLoader.screenW - internalWidth) / 2).toFloat() - private var offsetY = ((AppLoader.screenH - internalHeight) / 2).toFloat() - + internal var offsetX = ((AppLoader.screenW - internalWidth) / 2).toFloat() + private set + internal var offsetY = ((AppLoader.screenH - internalHeight) / 2).toFloat() + private set + fun requestTransition(target: Int) = transitionPanel.requestTransition(target) override fun updateUI(delta: Float) { if (handler.openFired) { @@ -216,25 +190,25 @@ class UIInventoryFull( categoryBar.update(delta) + transitionPanel.update(delta) - transitionalUpdateUIs.forEach { it.update(delta) } // update map while visible - if (currentScreenTransition > 1f + epsilon) { + /*if (currentScreenTransition > 1f + epsilon) { MinimapComposer.setWorld(Terrarum.ingame!!.world) MinimapComposer.update() - } + }*/ // update inventory while visible - if (currentScreenTransition in epsilon..2f - epsilon) { + /*if (currentScreenTransition in epsilon..2f - epsilon) { itemList.update(delta) equipped.update(delta) - } + }*/ // update menu while visible - if (currentScreenTransition < 1f - epsilon) { + /*if (currentScreenTransition < 1f - epsilon) { gameMenuButtons.update(delta) - } + }*/ minimapRerenderTimer += Gdx.graphics.rawDeltaTime } @@ -244,50 +218,25 @@ class UIInventoryFull( private val shapeRenderer = ShapeRenderer() private val gradHeight = 48f - private val weightBarWidth = UIItemInventoryElemSimple.height * 2f + UIItemInventoryDynamicList.listGap - - private var xEnd = (AppLoader.screenW + internalWidth).div(2).toFloat() - private var yEnd = (AppLoader.screenH + internalHeight).div(2).toFloat() + internal var xEnd = (AppLoader.screenW + internalWidth).div(2).toFloat() + private set + internal var yEnd = (AppLoader.screenH + internalHeight).div(2).toFloat() + private set private var minimapRerenderTimer = 0f private val minimapRerenderInterval = .5f - fun requestTransition(target: Int) { + // TODO implemented on UIItemTransitionContainer + /*fun requestTransition(target: Int) { if (!transitionOngoing) { transitionRequested = true transitionReqSource = currentScreenTransition.round() transitionReqTarget = target.toFloat() } - } + }*/ override fun renderUI(batch: SpriteBatch, camera: Camera) { - if (transitionRequested && !transitionOngoing) { - transitionRequested = false - transitionOngoing = true - transitionTimer = 0f - } - - if (transitionOngoing) { - transitionTimer += Gdx.graphics.rawDeltaTime - - currentScreenTransition = UIUtils.moveLinear(transitionReqSource, transitionReqTarget, transitionTimer, transitionLength) - - if (transitionTimer > transitionLength) { - transitionOngoing = false - currentScreenTransition = transitionReqTarget - } - } - - - - // update at render time - if (debugvals) { - batch.color = Color.WHITE - AppLoader.fontSmallNumbers.draw(batch, "screen:$currentScreenTransition", 500f, 30f) - } - - // background fill batch.end() @@ -314,41 +263,41 @@ class UIInventoryFull( categoryBar.render(batch, camera) // render map while visible - if (currentScreenTransition > 1f + epsilon) { + /*if (currentScreenTransition > 1f + epsilon) { renderScreenMinimap(batch, camera) if (debugvals) { batch.color = Color.CORAL AppLoader.fontSmallNumbers.draw(batch, "Map", 300f, 10f) } - } + }*/ // render inventory while visible - if (currentScreenTransition in epsilon..2f - epsilon) { + /*if (currentScreenTransition in epsilon..2f - epsilon) { renderScreenInventory(batch, camera) if (debugvals) { batch.color = Color.CHARTREUSE AppLoader.fontSmallNumbers.draw(batch, "Inv", 350f, 10f) } - } + }*/ // render menu while visible - if (currentScreenTransition < 1f - epsilon) { + /*if (currentScreenTransition < 1f - epsilon) { renderScreenGamemenu(batch, camera) if (debugvals) { batch.color = Color.SKY AppLoader.fontSmallNumbers.draw(batch, "Men", 400f, 10f) } - } + }*/ - if (debugvals) { + /*if (debugvals) { batch.color = Color.WHITE AppLoader.fontSmallNumbers.draw(batch, "minimap:$minimapScrOffX", 500f, 0f) AppLoader.fontSmallNumbers.draw(batch, "inven:$inventoryScrOffX", 500f, 10f) AppLoader.fontSmallNumbers.draw(batch, "menu:$menuScrOffX", 500f, 20f) - } + }*/ } @@ -360,7 +309,7 @@ class UIInventoryFull( * - +WIDTH on minimap screen * - -WIDTH on gamemenu screen */ - private val minimapScrOffX: Float + /*private val minimapScrOffX: Float get() = (currentScreenTransition - 2f) * AppLoader.screenW / 2f private val inventoryScrOffX: Float get() = (currentScreenTransition - 1f) * AppLoader.screenW / 2f @@ -372,24 +321,24 @@ class UIInventoryFull( private val inventoryScrOpacity: Float get() = (currentScreenTransition - 1f).coerceIn(0f, 1f) private val menuScrOpacity: Float - get() = (currentScreenTransition - 0f).coerceIn(0f, 1f) + get() = (currentScreenTransition - 0f).coerceIn(0f, 1f)*/ - private val MINIMAP_WIDTH = 800f - private val MINIMAP_HEIGHT = itemList.height.toFloat() - private val MINIMAP_SKYCOL = Color(0x88bbddff.toInt()) - private var minimapZoom = 1f - private var minimapPanX = -MinimapComposer.totalWidth / 2f - private var minimapPanY = -MinimapComposer.totalHeight / 2f - private val MINIMAP_ZOOM_MIN = 0.5f - private val MINIMAP_ZOOM_MAX = 8f - private val minimapFBO = FrameBuffer(Pixmap.Format.RGBA8888, MINIMAP_WIDTH.toInt(), MINIMAP_HEIGHT.toInt(), false) - private val minimapCamera = OrthographicCamera(MINIMAP_WIDTH, MINIMAP_HEIGHT) + //private val MINIMAP_WIDTH = 800f + //private val MINIMAP_HEIGHT = itemList.height.toFloat() + //private val MINIMAP_SKYCOL = Color(0x88bbddff.toInt()) + //private var minimapZoom = 1f + //private var minimapPanX = -MinimapComposer.totalWidth / 2f + //private var minimapPanY = -MinimapComposer.totalHeight / 2f + //private val MINIMAP_ZOOM_MIN = 0.5f + //private val MINIMAP_ZOOM_MAX = 8f + //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) { + // TODO not yet refactored + /*private fun renderScreenMinimap(batch: SpriteBatch, camera: Camera) { blendNormal(batch) // update map panning @@ -482,9 +431,10 @@ class UIInventoryFull( // the minimap batch.draw(minimapFBO.colorBufferTexture, minimapScrOffX + (AppLoader.screenW - MINIMAP_WIDTH) / 2, itemList.posY.toFloat()) - } + }*/ - private fun renderScreenGamemenu(batch: SpriteBatch, camera: Camera) { + // TODO not yet refactored + /*private fun renderScreenGamemenu(batch: SpriteBatch, camera: Camera) { // control hints blendNormal(batch) batch.color = Color.WHITE @@ -493,9 +443,10 @@ class UIInventoryFull( // text buttons gameMenuButtons.posX = gameMenuButtons.initialX + menuScrOffX.roundToInt() gameMenuButtons.render(batch, camera) - } + }*/ - private fun renderScreenInventory(batch: SpriteBatch, camera: Camera) { + // TODO refactoring wip + /*private fun renderScreenInventory(batch: SpriteBatch, camera: Camera) { itemList.posX = itemList.initialX + inventoryScrOffX.roundToInt() itemList.render(batch, camera) equipped.posX = equipped.initialX + inventoryScrOffX.roundToInt() @@ -553,17 +504,11 @@ class UIInventoryFull( encumbBarYPos + controlHelpHeight - 4f ) } - } + }*/ fun rebuildList() { - printdbg(this, "rebuilding list") - - itemList.rebuild(catIconsMeaning[categoryBar.selectedIcon]) - equipped.rebuild() - - encumbrancePerc = actor.inventory.capacity.toFloat() / actor.inventory.maxCapacity - isEncumbered = actor.inventory.isEncumbered + transitionalItemCells.rebuildList() } private fun Int.fastLen(): Int { @@ -582,8 +527,8 @@ class UIInventoryFull( override fun dispose() { categoryBar.dispose() - itemList.dispose() - equipped.dispose() + transitionPanel.dispose() + } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt index efbd6dfab..db94ca239 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt @@ -40,8 +40,8 @@ class UIItemInventoryDynamicList( ) : UIItem(parentUI, initialX, initialY) { // deal with the moving position - override var oldPosX = posX - override var oldPosY = posY + //override var oldPosX = posX + //override var oldPosY = posY override val width = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap override val height = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt index ad25e66cb..e0578453c 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt @@ -28,7 +28,7 @@ class UIItemInventoryEquippedView( override val width = WIDTH - override val height = parentUI.itemList.height + override val height = parentUI.itemListHeight companion object { val WIDTH = 2 * UIItemInventoryElemSimple.height + UIItemInventoryDynamicList.listGap @@ -71,10 +71,6 @@ class UIItemInventoryEquippedView( itemGrid.forEach { it.update(delta) } } - // deal with the moving position - override var oldPosX = posX - override var oldPosY = posY - override fun render(batch: SpriteBatch, camera: Camera) { val posXDelta = posX - oldPosX itemGrid.forEach { it.posX += posXDelta } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemPlayerInfoCell.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemPlayerInfoCell.kt index ed0e6940b..0daf29dc7 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemPlayerInfoCell.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemPlayerInfoCell.kt @@ -25,10 +25,6 @@ class UIItemPlayerInfoCell( var ingamePlayer: IngamePlayer? = null ) : UIItem(parent, initialX, initialY) { - // deal with the moving position - override var oldPosX = posX - override var oldPosY = posY - override val height = HEIGHT companion object { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemSavegameInfoCell.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemSavegameInfoCell.kt index 4ef01eceb..5e92350a8 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemSavegameInfoCell.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemSavegameInfoCell.kt @@ -21,10 +21,6 @@ class UIItemSavegameInfoCell( initialY: Int ) : UIItem(parent, initialX, initialY) { - // deal with the moving position - override var oldPosX = posX - override var oldPosY = posY - override val height: Int = AppLoader.fontGame.lineHeight.toInt() * 2 override fun render(batch: SpriteBatch, camera: Camera) { diff --git a/src/net/torvald/terrarum/modulebasegame/weather/WeatherMixer.kt b/src/net/torvald/terrarum/modulebasegame/weather/WeatherMixer.kt index 5b6362b44..b6650b9c8 100644 --- a/src/net/torvald/terrarum/modulebasegame/weather/WeatherMixer.kt +++ b/src/net/torvald/terrarum/modulebasegame/weather/WeatherMixer.kt @@ -300,13 +300,13 @@ internal object WeatherMixer : RNGConsumer { var mixFrom: String? try { mixFrom = JSON.get("mixFrom").asJsonPrimitive.asString } - catch (e: IllegalStateException) { mixFrom = null } + catch (e: NullPointerException) { mixFrom = null } var mixPercentage: Double? try { mixPercentage = JSON.get("mixPercentage").asJsonPrimitive.asDouble } - catch (e: IllegalStateException) { mixPercentage = null } + catch (e: NullPointerException) { mixPercentage = null } diff --git a/src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt b/src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt index e17fe39a6..d1edeab66 100644 --- a/src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt +++ b/src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt @@ -23,10 +23,11 @@ import net.torvald.terrarum.modulebasegame.worldgenerator.BiomegenParams import net.torvald.terrarum.modulebasegame.worldgenerator.TerragenParams import net.torvald.terrarum.modulebasegame.worldgenerator.shake import net.torvald.terrarum.worlddrawer.toRGBA +import java.util.concurrent.Future import kotlin.math.cos import kotlin.math.sin import kotlin.random.Random -import kotlinx.coroutines.* +import kotlin.coroutines.* const val WIDTH = 768 const val HEIGHT = 512 @@ -52,6 +53,8 @@ class WorldgenNoiseSandbox : ApplicationAdapter() { private var generationTimeInMeasure = false private var generationStartTime = 0L + private var genSlices: Int = 0 + private var genFutures: Array?> = arrayOfNulls(genSlices) override fun create() { font = BitmapFont() // use default because fuck it @@ -67,6 +70,8 @@ class WorldgenNoiseSandbox : ApplicationAdapter() { testTex.blending = Pixmap.Blending.None tempTex = Texture(1, 1, Pixmap.Format.RGBA8888) + genSlices = maxOf(ThreadExecutor.threadCount, testTex.width / 8) + println("Init done") } @@ -91,7 +96,7 @@ class WorldgenNoiseSandbox : ApplicationAdapter() { renderNoise() } - val coroutineExecFinished = coroutineJobs.fold(true) { acc, it -> acc and it.isCompleted } + val coroutineExecFinished = genFutures.fold(true) { acc, it -> acc and (it?.isDone ?: true) } // check if generation is done if (coroutineExecFinished) { generateKeyLatched = false @@ -158,12 +163,6 @@ class WorldgenNoiseSandbox : ApplicationAdapter() { } } - //private val xSlices = (0 until WIDTH).sliceEvenly(ThreadExecutor.threadCount) - private val xSlices = (0 until WIDTH).sliceEvenly(maxOf(WIDTH, ThreadExecutor.threadCount, WIDTH / 8)) - - private val runs = (0 until WIDTH).map { x -> (x until WIDTH * HEIGHT step WIDTH) }.flatten() - - private lateinit var coroutineJobs: List private fun renderNoise() { generationStartTime = System.nanoTime() @@ -220,7 +219,7 @@ class WorldgenNoiseSandbox : ApplicationAdapter() { } }*/ // 2. each runner gets their own copy of Joise - val runnables: List = xSlices.map { range -> { + val runnables: List = (0 until testTex.width).sliceEvenly(genSlices).map { range -> { val localJoise = getNoiseGenerator(seed) for (x in range) { for (y in 0 until HEIGHT) { @@ -235,7 +234,12 @@ class WorldgenNoiseSandbox : ApplicationAdapter() { } } - coroutineJobs = runnables.map { r -> GlobalScope.launch { r() } } + ThreadExecutor.renew() + runnables.forEach { + ThreadExecutor.submit(it) + } + + ThreadExecutor.join() initialGenDone = true } diff --git a/src/net/torvald/terrarum/ui/UICanvas.kt b/src/net/torvald/terrarum/ui/UICanvas.kt index 38e9ec7c6..29d2ba6d2 100644 --- a/src/net/torvald/terrarum/ui/UICanvas.kt +++ b/src/net/torvald/terrarum/ui/UICanvas.kt @@ -53,6 +53,13 @@ abstract class UICanvas( get() = handler.posY set(value) { handler.posY = value } + inline var initialX: Int + get() = handler.initialX + set(value) { handler.initialX = value } + inline var initialY: Int + get() = handler.initialY + set(value) { handler.initialY = value } + /** * Usage: (in StateInGame:) uiHandlerField.ui.handler = uiHandlerField */ @@ -103,9 +110,12 @@ abstract class UICanvas( } - /** Override this for the actual update. Note that you must update uiItems by yourself. */ + /** **DO NOT CALL THIS FUNCTION FOR THE ACTUAL UPDATING OF THE UI — USE update() INSTEAD** + * + * Override this for the actual update. Note that you must update uiItems by yourself. */ abstract fun updateUI(delta: Float) - /** + /** **DO NOT CALL THIS FUNCTION FOR THE ACTUAL RENDERING OF THE UI — USE render() INSTEAD** + * * Override this for the actual render. Note that you must render uiItems by yourself. * * Under normal circumstances, draws are automatically translated as per the handler's X/Y position. @@ -138,7 +148,7 @@ abstract class UICanvas( abstract override fun dispose() - fun addItem(uiItem: UIItem) { + fun addUIitem(uiItem: UIItem) { uiItems.add(uiItem) } diff --git a/src/net/torvald/terrarum/ui/UIHandler.kt b/src/net/torvald/terrarum/ui/UIHandler.kt index 5df4898eb..d6899880a 100644 --- a/src/net/torvald/terrarum/ui/UIHandler.kt +++ b/src/net/torvald/terrarum/ui/UIHandler.kt @@ -32,6 +32,9 @@ class UIHandler(//var UI: UICanvas, var posX: Int = 0 var posY: Int = 0 + var initialX = posX + var initialY = posY + private var alwaysVisible = false var isOpening = false diff --git a/src/net/torvald/terrarum/ui/UIItem.kt b/src/net/torvald/terrarum/ui/UIItem.kt index e13841b5f..a8b15e417 100644 --- a/src/net/torvald/terrarum/ui/UIItem.kt +++ b/src/net/torvald/terrarum/ui/UIItem.kt @@ -66,7 +66,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I * oldPosX = posX * ``` */ - protected abstract var oldPosX: Int + protected var oldPosX: Int = initialX /** This variable is NOT updated on its own. * ``` * val posYDelta = posY - oldPosY @@ -75,7 +75,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I * oldPosY = posY * ``` */ - protected abstract var oldPosY: Int + protected var oldPosY: Int = initialY /** Position of mouse relative to this item */ protected val relativeMouseX: Int diff --git a/src/net/torvald/terrarum/ui/UIItemConfigKeycap.kt b/src/net/torvald/terrarum/ui/UIItemConfigKeycap.kt index b12fe0f7e..5e8229ae6 100644 --- a/src/net/torvald/terrarum/ui/UIItemConfigKeycap.kt +++ b/src/net/torvald/terrarum/ui/UIItemConfigKeycap.kt @@ -36,9 +36,6 @@ class UIItemConfigKeycap( override val width = capTex.tileW * keySize override val height = capTex.tileH - override var oldPosX = posX - override var oldPosY = posY - override fun update(delta: Float) { super.update(delta) } diff --git a/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt b/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt new file mode 100644 index 000000000..4340de32a --- /dev/null +++ b/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt @@ -0,0 +1,41 @@ +package net.torvald.terrarum.ui + +import kotlin.math.roundToInt + +/** + * @param width size of the canvas where transition occurs + * @param height size of the canvas where transition occurs + */ +class UIItemHorizontalFadeSlide( + parent: UICanvas, + initialX: Int, + initialY: Int, + width: Int, + height: Int, + //transitionLength: Float, + currentPosition: Float, + vararg uis: UICanvas +) : UIItemTransitionContainer(parent, initialX, initialY, width, height, 0.212f, currentPosition, uis) { + + fun getOffX(index: Int) = ((currentPosition - index) * width).roundToInt() + fun getOpacity(index: Int) = (currentPosition - index).coerceIn(0f, 1f) + + init { + // re-position the uis according to the initial choice of currentPosition + uis.forEachIndexed { index, it -> + it.posX = posX + getOffX(index) + it.initialX = posX + getOffX(index) + it.posY = posY + it.initialY = posY + it.opacity = getOpacity(index) + } + } + + override fun onTransition(currentPosition: Float, uis: Array) { + uis.forEachIndexed { index, it -> + it.posX = it.initialX + getOffX(index) + it.posY = posY + it.opacity = getOpacity(index) + } + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/UIItemImageButton.kt b/src/net/torvald/terrarum/ui/UIItemImageButton.kt index 8f488057e..f51553b52 100644 --- a/src/net/torvald/terrarum/ui/UIItemImageButton.kt +++ b/src/net/torvald/terrarum/ui/UIItemImageButton.kt @@ -41,10 +41,6 @@ open class UIItemImageButton( var highlightable: Boolean ) : UIItem(parent, initialX, initialY) { - // 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 55ec41dd8..cc932e71b 100644 --- a/src/net/torvald/terrarum/ui/UIItemImageGallery.kt +++ b/src/net/torvald/terrarum/ui/UIItemImageGallery.kt @@ -20,10 +20,6 @@ class UIItemImageGallery( val column: Int = 1 ) : UIItem(parentUI, initialX, initialY) { - // 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 8a5b8ffd5..6135e019f 100644 --- a/src/net/torvald/terrarum/ui/UIItemIntSlider.kt +++ b/src/net/torvald/terrarum/ui/UIItemIntSlider.kt @@ -75,10 +75,6 @@ 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 79c633d30..d106b9a70 100644 --- a/src/net/torvald/terrarum/ui/UIItemList.kt +++ b/src/net/torvald/terrarum/ui/UIItemList.kt @@ -36,10 +36,6 @@ class UIItemList( val border: Int = 0 ) : UIItem(parentUI, initialX, initialY) { - // deal with the moving position - override var oldPosX = posX - override var oldPosY = posY - init { itemList.forEachIndexed { index, item -> item.posX = this.posX + border diff --git a/src/net/torvald/terrarum/ui/UIItemModuleInfoCell.kt b/src/net/torvald/terrarum/ui/UIItemModuleInfoCell.kt index e6cd649f2..cfdd77516 100644 --- a/src/net/torvald/terrarum/ui/UIItemModuleInfoCell.kt +++ b/src/net/torvald/terrarum/ui/UIItemModuleInfoCell.kt @@ -16,10 +16,6 @@ class UIItemModuleInfoCell( initialY: Int ) : UIItem(parent, initialX, initialY) { - // deal with the moving position - override var oldPosX = posX - override var oldPosY = posY - override val height: Int = AppLoader.fontGame.lineHeight.toInt() * 2 private val numberAreaWidth = AppLoader.fontSmallNumbers.W * 3 + 4 diff --git a/src/net/torvald/terrarum/ui/UIItemTextArea.kt b/src/net/torvald/terrarum/ui/UIItemTextArea.kt index ce032dcd3..9abd6bded 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextArea.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextArea.kt @@ -17,10 +17,6 @@ class UIItemTextArea( val align: Alignment = Alignment.LEFT ) : UIItem(parentUI, initialX, initialY) { - // 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 6c3820f51..fd2dcea06 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextButton.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextButton.kt @@ -48,10 +48,6 @@ open class UIItemTextButton( val hitboxSize: Int = UIItemTextButton.height ) : UIItem(parentUI, initialX, initialY) { - // deal with the moving position - override var oldPosX = posX - override var oldPosY = posY - companion object { val font = AppLoader.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 e91a1a130..f75fe51a8 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt @@ -57,10 +57,6 @@ class UIItemTextButtonList( val DEFAULT_LINE_HEIGHT = 36 } - // 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) diff --git a/src/net/torvald/terrarum/ui/UIItemToggleButton.kt b/src/net/torvald/terrarum/ui/UIItemToggleButton.kt index 3a78260a2..a54cc9b88 100644 --- a/src/net/torvald/terrarum/ui/UIItemToggleButton.kt +++ b/src/net/torvald/terrarum/ui/UIItemToggleButton.kt @@ -34,8 +34,6 @@ class UIItemToggleButton( get() = togglerBase.width override val height: Int get() = togglerBase.height - override var oldPosX = posX - override var oldPosY = posY private var togglerBase = CommonResourcePool.getAsTexture("ui_item_toggler_base") private var togglerHandle = CommonResourcePool.getAsTexture("ui_item_toggler_handle") diff --git a/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt b/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt new file mode 100644 index 000000000..b907841ce --- /dev/null +++ b/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt @@ -0,0 +1,95 @@ +package net.torvald.terrarum.ui + +import com.badlogic.gdx.Gdx +import com.badlogic.gdx.graphics.Camera +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import net.torvald.terrarum.AppLoader + +open class UIItemTransitionContainer( + parent: UICanvas, + initialX: Int, + initialY: Int, + override val width: Int, + override val height: Int, + val transitionLength: Float = 0.212f, + var currentPosition: Float = 0f, + val uis: Array +) : UIItem(parent, initialX, initialY) { + + val debugvals = true + + private var transitionRequested = false + private var transitionOngoing = false + private var transitionReqSource = currentPosition + private var transitionReqTarget = currentPosition + private var transitionTimer = 0f + + private val epsilon = 0.001f + + fun requestTransition(target: Int) { + if (!transitionOngoing) { + transitionRequested = true + transitionReqSource = Math.round(currentPosition).toFloat() + transitionReqTarget = target.toFloat() + } + } + + override fun update(delta: Float) { + super.update(delta) + + uis.forEachIndexed { index, ui -> + if (currentPosition > index - 1 + epsilon && currentPosition < index + 1 - epsilon) { + ui.update(delta) + } + } + } + + open fun onTransition(currentPosition: Float, uis: Array) {} + + override fun render(batch: SpriteBatch, camera: Camera) { + super.render(batch, camera) + + if (transitionRequested && !transitionOngoing) { + transitionRequested = false + transitionOngoing = true + transitionTimer = 0f + } + + if (transitionOngoing) { + transitionTimer += Gdx.graphics.rawDeltaTime + + currentPosition = UIUtils.moveLinear(transitionReqSource, transitionReqTarget, transitionTimer, transitionLength) + + if (transitionTimer > transitionLength) { + transitionOngoing = false + currentPosition = transitionReqTarget + } + + onTransition(currentPosition, uis) + } + + uis.forEachIndexed { index, ui -> + if (currentPosition > index - 1 + epsilon && currentPosition < index + 1 - epsilon) { + ui.setAsOpen() + ui.render(batch, camera) + + if (debugvals) { + AppLoader.fontSmallNumbers.draw(batch, "$index", 300f + (20 * index), 10f) + } + } + else { + ui.setAsClose() + } + } + + if (debugvals) { + batch.color = Color.WHITE + AppLoader.fontSmallNumbers.draw(batch, "position:$currentPosition", 500f, 10f) + } + } + + override fun dispose() { + uis.forEach { it.dispose() } + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/UIUtils.kt b/src/net/torvald/terrarum/ui/UIUtils.kt index 3d01251d8..576226d2e 100644 --- a/src/net/torvald/terrarum/ui/UIUtils.kt +++ b/src/net/torvald/terrarum/ui/UIUtils.kt @@ -8,6 +8,17 @@ 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 + fun moveLinear(start: Float, end: Float, timer: Float, duration: Float): Float { + val scale = timer / duration + if (start == end) { + return start + } + if (scale <= 0f) { + return start + } + if (scale >= 1f) { + return end + } + return ((1f - scale) * start) + (scale * end) + } } \ No newline at end of file diff --git a/terrarum.iml b/terrarum.iml index 2664b041f..5ead1470d 100644 --- a/terrarum.iml +++ b/terrarum.iml @@ -8,7 +8,6 @@ - From 299e10a381a6022e3d64730e8e2f2c49f5292caf Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 9 Sep 2020 15:38:21 +0900 Subject: [PATCH 2/8] UI visible and render is offsetted but update is ok --- src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt | 1 + .../torvald/terrarum/modulebasegame/weather/WeatherMixer.kt | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt index e98a90f2e..82b747d3b 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt @@ -261,6 +261,7 @@ class UIInventoryFull( // UI items categoryBar.render(batch, camera) + transitionPanel.render(batch, camera) // render map while visible /*if (currentScreenTransition > 1f + epsilon) { diff --git a/src/net/torvald/terrarum/modulebasegame/weather/WeatherMixer.kt b/src/net/torvald/terrarum/modulebasegame/weather/WeatherMixer.kt index b6650b9c8..5b6362b44 100644 --- a/src/net/torvald/terrarum/modulebasegame/weather/WeatherMixer.kt +++ b/src/net/torvald/terrarum/modulebasegame/weather/WeatherMixer.kt @@ -300,13 +300,13 @@ internal object WeatherMixer : RNGConsumer { var mixFrom: String? try { mixFrom = JSON.get("mixFrom").asJsonPrimitive.asString } - catch (e: NullPointerException) { mixFrom = null } + catch (e: IllegalStateException) { mixFrom = null } var mixPercentage: Double? try { mixPercentage = JSON.get("mixPercentage").asJsonPrimitive.asDouble } - catch (e: NullPointerException) { mixPercentage = null } + catch (e: IllegalStateException) { mixPercentage = null } From f5624af47c991bf7c0f02f2a1feb070ee16ef2b8 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 9 Sep 2020 16:05:56 +0900 Subject: [PATCH 3/8] UI is now rendered in correct pos --- .../torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt b/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt index 4340de32a..4c9b2f212 100644 --- a/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt +++ b/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt @@ -23,10 +23,10 @@ class UIItemHorizontalFadeSlide( init { // re-position the uis according to the initial choice of currentPosition uis.forEachIndexed { index, it -> - it.posX = posX + getOffX(index) - it.initialX = posX + getOffX(index) - it.posY = posY - it.initialY = posY + it.posX = 0 + getOffX(index) + it.initialX = 0 + getOffX(index) + it.posY = 0 + it.initialY = 0 it.opacity = getOpacity(index) } } @@ -34,7 +34,7 @@ class UIItemHorizontalFadeSlide( override fun onTransition(currentPosition: Float, uis: Array) { uis.forEachIndexed { index, it -> it.posX = it.initialX + getOffX(index) - it.posY = posY + it.posY = it.initialY it.opacity = getOpacity(index) } } From ac144da0b45e581408647d68f8ecbe3a9899eaba Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 9 Sep 2020 16:58:35 +0900 Subject: [PATCH 4/8] index is reversed, transparency not working --- src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt b/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt index 4c9b2f212..6638aca32 100644 --- a/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt +++ b/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt @@ -17,7 +17,7 @@ class UIItemHorizontalFadeSlide( vararg uis: UICanvas ) : UIItemTransitionContainer(parent, initialX, initialY, width, height, 0.212f, currentPosition, uis) { - fun getOffX(index: Int) = ((currentPosition - index) * width).roundToInt() + fun getOffX(index: Int) = ((currentPosition - index) * width / 2f).roundToInt() fun getOpacity(index: Int) = (currentPosition - index).coerceIn(0f, 1f) init { From b07e7f5fdd0bc6a0d83d2a2fc6f753ba458a3992 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 12 Sep 2020 11:24:32 +0900 Subject: [PATCH 5/8] q&d hack for ui opacity control using a shader --- .../modulebasegame/ui/UIQuickslotPie.kt | 2 +- .../modulebasegame/ui/UIScreenZoom.kt | 3 +- src/net/torvald/terrarum/ui/UICanvas.kt | 4 +- src/net/torvald/terrarum/ui/UIHandler.kt | 58 +++++++++++++++++-- .../terrarum/ui/UIItemHorizontalFadeSlide.kt | 4 +- .../terrarum/ui/UIItemTransitionContainer.kt | 2 +- 6 files changed, 61 insertions(+), 12 deletions(-) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotPie.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotPie.kt index bc7b5ef79..7c0d33ebf 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotPie.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotPie.kt @@ -79,7 +79,7 @@ class UIQuickslotPie : UICanvas() { val slotX = slotCentrePoint.x.toInt() val slotY = slotCentrePoint.y.toInt() - drawColor.a = handler.opacity * UIQuickslotBar.DISPLAY_OPACITY + drawColor.a = UIQuickslotBar.DISPLAY_OPACITY batch.color = drawColor image.draw(batch, slotX, slotY) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIScreenZoom.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIScreenZoom.kt index 9f93e343a..3a718e91f 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIScreenZoom.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIScreenZoom.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.modulebasegame.ui import com.badlogic.gdx.graphics.Camera +import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.EMDASH import net.torvald.terrarum.AppLoader @@ -34,7 +35,7 @@ class UIScreenZoom : UICanvas( } override fun renderUI(batch: SpriteBatch, camera: Camera) { - batch.color = handler.opacityColour + batch.color = Color.WHITE AppLoader.fontGame.draw( batch, zoomText, diff --git a/src/net/torvald/terrarum/ui/UICanvas.kt b/src/net/torvald/terrarum/ui/UICanvas.kt index 29d2ba6d2..93eed3e94 100644 --- a/src/net/torvald/terrarum/ui/UICanvas.kt +++ b/src/net/torvald/terrarum/ui/UICanvas.kt @@ -121,8 +121,8 @@ abstract class UICanvas( * Under normal circumstances, draws are automatically translated as per the handler's X/Y position. * This means, don't write like: ```draw(posX + 4, posY + 32)```, do instead: ```draw(4, 32)``` unless you have a good reason to do so. * - * The transparency of the handler is independent of the draw, you must specified the color yourself - * using handler.opacity or handler.opacityColour + * The transparency of the handler is independent of the draw, you must set the drawing color yourself + * (use handler.opacity or handler.opacityColour) */ abstract fun renderUI(batch: SpriteBatch, camera: Camera) diff --git a/src/net/torvald/terrarum/ui/UIHandler.kt b/src/net/torvald/terrarum/ui/UIHandler.kt index d6899880a..f3ecf7cf6 100644 --- a/src/net/torvald/terrarum/ui/UIHandler.kt +++ b/src/net/torvald/terrarum/ui/UIHandler.kt @@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.utils.Disposable +import net.torvald.terrarum.AppLoader import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gamecontroller.KeyToggler import net.torvald.terrarum.modulebasegame.TerrarumIngame @@ -15,6 +16,9 @@ import net.torvald.terrarum.modulebasegame.TerrarumIngame * to the coordinate of displayed cartesian coords, and update and render the UI. * It also process game inputs and send control events to the UI so that the UI can handle them. * + * The UI is *non-compositing* and thus has no underlying framebuffers, meaning that some of the effects (opacity, scaling) + * must be separately implemented onto the UICanvas (which may cause some artefacts when UI elements are overlapping and they are both semi-transparent) + * * New UIs are NORMALLY HIDDEN; set it visible as you need! * * Created by minjaesong on 2015-12-31. @@ -28,6 +32,44 @@ class UIHandler(//var UI: UICanvas, internal var allowESCtoClose: Boolean = false ): Disposable { + companion object { + private val SHADER_PROG_FRAG = """ +#version 130 +#ifdef GL_ES + precision mediump float; +#endif + +varying vec4 v_color; +varying vec2 v_texCoords; +uniform sampler2D u_texture; + +uniform float opacity; + +void main(void) { + vec4 color = texture2D(u_texture, v_texCoords).rgba; + + gl_FragColor = v_color * vec4(color.rgb, color.a * opacity); +} +""".trimIndent() + + private val SHADER_PROG_VERT = """ +attribute vec4 a_position; +attribute vec4 a_color; +attribute vec2 a_texCoord0; + +uniform mat4 u_projTrans; + +varying vec4 v_color; +varying vec2 v_texCoords; + +void main() { + v_color = a_color; + v_texCoords = a_texCoord0; + gl_Position = u_projTrans * a_position; +} + """.trimIndent() + } + // X/Y Position relative to the game window. var posX: Int = 0 var posY: Int = 0 @@ -63,16 +105,18 @@ class UIHandler(//var UI: UICanvas, var closeFired = false var opacity = 1f - set(value) { + /*set(value) { field = value - opacityColour.set(1f,1f,1f,opacity) - } + opacityColour.a = value + }*/ var scale = 1f - val opacityColour = Color(1f, 1f, 1f, opacity) + //val opacityColour = Color(1f, 1f, 1f, opacity) var openCloseCounter = 0f + private val shader = AppLoader.loadShaderInline(SHADER_PROG_VERT, SHADER_PROG_FRAG) + init { //UI.handler = this } @@ -204,9 +248,12 @@ class UIHandler(//var UI: UICanvas, } batch.color = Color.WHITE - + batch.shader = shader + shader.setUniformf("opacity", opacity) ui.renderUI(batch, camera) //ingameGraphics.flush() + + batch.shader = null batch.color = Color.WHITE @@ -384,5 +431,6 @@ class UIHandler(//var UI: UICanvas, override fun dispose() { toggleKey?.let { KeyToggler.forceSet(it, false) } toggleButton?.let { /* ButtonToggler.forceSet(it, false) */ } + shader.dispose() } } diff --git a/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt b/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt index 6638aca32..e363a1936 100644 --- a/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt +++ b/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt @@ -15,10 +15,10 @@ class UIItemHorizontalFadeSlide( //transitionLength: Float, currentPosition: Float, vararg uis: UICanvas -) : UIItemTransitionContainer(parent, initialX, initialY, width, height, 0.212f, currentPosition, uis) { +) : UIItemTransitionContainer(parent, initialX, initialY, width, height, 0.15f, currentPosition, uis) { fun getOffX(index: Int) = ((currentPosition - index) * width / 2f).roundToInt() - fun getOpacity(index: Int) = (currentPosition - index).coerceIn(0f, 1f) + fun getOpacity(index: Int) = 1f - (currentPosition - index).coerceIn(0f, 1f) // fixme make it work for both direction init { // re-position the uis according to the initial choice of currentPosition diff --git a/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt b/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt index b907841ce..40107a427 100644 --- a/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt +++ b/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt @@ -12,7 +12,7 @@ open class UIItemTransitionContainer( initialY: Int, override val width: Int, override val height: Int, - val transitionLength: Float = 0.212f, + val transitionLength: Float = 0.15f, var currentPosition: Float = 0f, val uis: Array ) : UIItem(parent, initialX, initialY) { From eb2e47e2a53efaa52d30c44d5db07ed820fe3e55 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 14 Sep 2020 14:04:46 +0900 Subject: [PATCH 6/8] fix: inventory panels and their indices are mutually inversed --- src/net/torvald/terrarum/UIItemInventoryCatBar.kt | 5 ++--- .../torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt | 10 ++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/net/torvald/terrarum/UIItemInventoryCatBar.kt b/src/net/torvald/terrarum/UIItemInventoryCatBar.kt index 4859119ee..e4f1277f0 100644 --- a/src/net/torvald/terrarum/UIItemInventoryCatBar.kt +++ b/src/net/torvald/terrarum/UIItemInventoryCatBar.kt @@ -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) } } diff --git a/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt b/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt index e363a1936..ef3faa198 100644 --- a/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt +++ b/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt @@ -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) { uis.forEachIndexed { index, it -> - it.posX = it.initialX + getOffX(index) + it.posX = it.initialX - getOffX(index) it.posY = it.initialY it.opacity = getOpacity(index) } From b2ad5413554e36ed264bdd72e051c66e12dd40f4 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 14 Sep 2020 15:19:34 +0900 Subject: [PATCH 7/8] transition works as intended but ui is not tangible --- src/net/torvald/terrarum/AppLoader.java | 6 +++--- src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt | 9 +++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/net/torvald/terrarum/AppLoader.java b/src/net/torvald/terrarum/AppLoader.java index 3c7c6b0a6..fe4262097 100644 --- a/src/net/torvald/terrarum/AppLoader.java +++ b/src/net/torvald/terrarum/AppLoader.java @@ -213,6 +213,8 @@ public class AppLoader implements ApplicationListener { public static final int minimumW = 1080; public static final int minimumH = 720; + public static final String FONT_DIR = "assets/graphics/fonts/terrarum-sans-bitmap"; + private static ShaderProgram shaderBayerSkyboxFill; // ONLY to be used by the splash screen @@ -481,14 +483,12 @@ public class AppLoader implements ApplicationListener { }*/ - fontGame = new GameFontBase("assets/graphics/fonts/terrarum-sans-bitmap", false, true, + fontGame = new GameFontBase(FONT_DIR, false, true, false, Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest, false, 256, false ); Lang.invoke(); // make loading list - - CommonResourcePool.INSTANCE.loadAll(); } diff --git a/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt b/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt index ef3faa198..0438649ba 100644 --- a/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt +++ b/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.ui import com.jme3.math.FastMath +import kotlin.math.absoluteValue import kotlin.math.roundToInt /** @@ -19,11 +20,7 @@ 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 - /*if (currentPosition >= index) - 1f - (currentPosition - index).coerceIn(0f, 1f) - else - (currentPosition - index).coerceIn(0f, 1f) - 1f*/ + fun getOpacity(index: Int) = 1f - (currentPosition - index).absoluteValue.coerceIn(0f, 1f) init { @@ -39,7 +36,7 @@ class UIItemHorizontalFadeSlide( override fun onTransition(currentPosition: Float, uis: Array) { uis.forEachIndexed { index, it -> - it.posX = it.initialX - getOffX(index) + it.posX = -getOffX(index) it.posY = it.initialY it.opacity = getOpacity(index) } From e0fcf35f5b0c5c61a31633190f6056da770ea8a9 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Thu, 17 Sep 2020 11:22:03 +0900 Subject: [PATCH 8/8] fix: inventory cells not tangible --- .../modulebasegame/ui/UIInventoryCells.kt | 5 +++ .../modulebasegame/ui/UIInventoryFull.kt | 35 --------------- .../terrarum/ui/UIItemTransitionContainer.kt | 44 ++++++++++++++++--- 3 files changed, 43 insertions(+), 41 deletions(-) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt index c37c4c2ae..b530d50cf 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt @@ -46,6 +46,11 @@ internal class UIInventoryCells( 107 + (AppLoader.screenH - full.internalHeight) / 2 ) + init { + uiItems.add(itemList) + uiItems.add(equipped) + } + fun rebuildList() { AppLoader.printdbg(this, "rebuilding list") diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt index 82b747d3b..6b227442f 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt @@ -564,40 +564,5 @@ class UIInventoryFull( xEnd = (AppLoader.screenW + internalWidth).div(2).toFloat() yEnd = (AppLoader.screenH + internalHeight).div(2).toFloat() } - - - - override fun keyDown(keycode: Int): Boolean { - return super.keyDown(keycode) - } - - override fun keyTyped(character: Char): Boolean { - return super.keyTyped(character) - } - - override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { - return super.touchDown(screenX, screenY, pointer, button) - } - - override fun keyUp(keycode: Int): Boolean { - return super.keyUp(keycode) - } - - override fun mouseMoved(screenX: Int, screenY: Int): Boolean { - return super.mouseMoved(screenX, screenY) - } - - override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean { - return super.touchDragged(screenX, screenY, pointer) - } - - override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { - return super.touchUp(screenX, screenY, pointer, button) - } - - override fun scrolled(amount: Int): Boolean { - return super.scrolled(amount) - } - } diff --git a/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt b/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt index 40107a427..8d3fd03f1 100644 --- a/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt +++ b/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt @@ -27,6 +27,8 @@ open class UIItemTransitionContainer( private val epsilon = 0.001f + private fun timeToUpdate(index: Int) = true//(currentPosition > index - 1 + epsilon && currentPosition < index + 1 - epsilon) + fun requestTransition(target: Int) { if (!transitionOngoing) { transitionRequested = true @@ -37,12 +39,7 @@ open class UIItemTransitionContainer( override fun update(delta: Float) { super.update(delta) - - uis.forEachIndexed { index, ui -> - if (currentPosition > index - 1 + epsilon && currentPosition < index + 1 - epsilon) { - ui.update(delta) - } - } + uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.update(delta) } } open fun onTransition(currentPosition: Float, uis: Array) {} @@ -89,6 +86,41 @@ open class UIItemTransitionContainer( } } + override fun keyDown(keycode: Int): Boolean { + uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.keyDown(keycode) } + return true + } + + override fun keyUp(keycode: Int): Boolean { + uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.keyUp(keycode) } + return true + } + + override fun mouseMoved(screenX: Int, screenY: Int): Boolean { + uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.mouseMoved(screenX, screenY) } + return true + } + + override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean { + uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.touchDragged(screenX, screenY, pointer) } + return true + } + + override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { + uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.touchDown(screenX, screenY, pointer, button) } + return true + } + + override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { + uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.touchUp(screenX, screenY, pointer, button) } + return true + } + + override fun scrolled(amount: Int): Boolean { + uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.scrolled(amount) } + return true + } + override fun dispose() { uis.forEach { it.dispose() } }