mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-06 08:38:30 +09:00
Merge branch 'inventory-ui-transition-container' into master
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
"EAUR"; "768"; "0";"8192"; "21"; "1.36"; "1.0";"elven aurichalcum"
|
"EAUR"; "768"; "0";"8192"; "21"; "1.36"; "1.0";"elven aurichalcum"
|
||||||
"TIAL"; "900"; "0";"4420"; "33"; "2.16"; "1.0";"titanium alloy (Ti6Al4V)"
|
"TIAL"; "900"; "0";"4420"; "33"; "2.16"; "1.0";"titanium alloy (Ti6Al4V)"
|
||||||
"ADMT";"2000";"4090";"2700"; "71"; "3.42"; "1.0";"adamant"
|
"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"
|
"BONE"; "130"; "0";"2000"; "1"; "0.23"; "0.55";"data is that of bovine bone"
|
||||||
|
|
||||||
# idst: ID_STRING, ALL CAPS
|
# idst: ID_STRING, ALL CAPS
|
||||||
|
|||||||
|
@@ -213,6 +213,8 @@ public class AppLoader implements ApplicationListener {
|
|||||||
public static final int minimumW = 1080;
|
public static final int minimumW = 1080;
|
||||||
public static final int minimumH = 720;
|
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
|
private static ShaderProgram shaderBayerSkyboxFill; // ONLY to be used by the splash screen
|
||||||
@@ -483,14 +485,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
|
false, Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest, false, 256, false
|
||||||
);
|
);
|
||||||
Lang.invoke();
|
Lang.invoke();
|
||||||
|
|
||||||
// make loading list
|
// make loading list
|
||||||
|
|
||||||
|
|
||||||
CommonResourcePool.INSTANCE.loadAll();
|
CommonResourcePool.INSTANCE.loadAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,6 @@ class UIItemInventoryCatBar(
|
|||||||
override val width: Int
|
override val width: Int
|
||||||
) : UIItem(parentUI, initialX, initialY) {
|
) : UIItem(parentUI, initialX, initialY) {
|
||||||
|
|
||||||
// deal with the moving position
|
|
||||||
override var oldPosX = posX
|
|
||||||
override var oldPosY = posY
|
|
||||||
|
|
||||||
private val parentInventory = parentUI
|
private val parentInventory = parentUI
|
||||||
|
|
||||||
private val catIcons = parentUI.catIcons
|
private val catIcons = parentUI.catIcons
|
||||||
@@ -178,6 +174,7 @@ class UIItemInventoryCatBar(
|
|||||||
selectedPanel = 1
|
selectedPanel = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// move selection highlighter
|
||||||
if (btn.mousePushed && index != selectedIndex) {
|
if (btn.mousePushed && index != selectedIndex) {
|
||||||
// normal stuffs
|
// normal stuffs
|
||||||
val oldIndex = selectedIndex
|
val oldIndex = selectedIndex
|
||||||
@@ -207,7 +204,6 @@ class UIItemInventoryCatBar(
|
|||||||
if (selectedPanel != 0) transitionFired = true
|
if (selectedPanel != 0) transitionFired = true
|
||||||
mainButtons.forEach { it.highlighted = false }
|
mainButtons.forEach { it.highlighted = false }
|
||||||
selectedPanel = 0
|
selectedPanel = 0
|
||||||
parentInventory.requestTransition(0)
|
|
||||||
|
|
||||||
sideButtons[0].highlighted = true
|
sideButtons[0].highlighted = true
|
||||||
sideButtons[3].highlighted = false
|
sideButtons[3].highlighted = false
|
||||||
@@ -216,7 +212,6 @@ class UIItemInventoryCatBar(
|
|||||||
if (selectedPanel != 2) transitionFired = true
|
if (selectedPanel != 2) transitionFired = true
|
||||||
mainButtons.forEach { it.highlighted = false }
|
mainButtons.forEach { it.highlighted = false }
|
||||||
selectedPanel = 2
|
selectedPanel = 2
|
||||||
parentInventory.requestTransition(2)
|
|
||||||
transitionFired = true
|
transitionFired = true
|
||||||
|
|
||||||
sideButtons[0].highlighted = false
|
sideButtons[0].highlighted = false
|
||||||
@@ -226,7 +221,7 @@ class UIItemInventoryCatBar(
|
|||||||
|
|
||||||
if (transitionFired) {
|
if (transitionFired) {
|
||||||
transitionFired = false
|
transitionFired = false
|
||||||
parentInventory.requestTransition(2 - selectedPanel)
|
parentInventory.requestTransition(selectedPanel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,10 +41,6 @@ class UIItemInventoryElem(
|
|||||||
val drawBackOnNull: Boolean = true
|
val drawBackOnNull: Boolean = true
|
||||||
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot) {
|
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot) {
|
||||||
|
|
||||||
// deal with the moving position
|
|
||||||
override var oldPosX = posX
|
|
||||||
override var oldPosY = posY
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val height = 48
|
val height = 48
|
||||||
val UNIQUE_ITEM_HAS_NO_AMOUNT = -1
|
val UNIQUE_ITEM_HAS_NO_AMOUNT = -1
|
||||||
|
|||||||
@@ -39,10 +39,6 @@ class UIItemInventoryElemSimple(
|
|||||||
val drawBackOnNull: Boolean = true
|
val drawBackOnNull: Boolean = true
|
||||||
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot) {
|
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot) {
|
||||||
|
|
||||||
// deal with the moving position
|
|
||||||
override var oldPosX = posX
|
|
||||||
override var oldPosY = posY
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val height = UIItemInventoryElem.height
|
val height = UIItemInventoryElem.height
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,6 +178,8 @@ fun str16ToInt(rec: CSVRecord, s: String): Int {
|
|||||||
}
|
}
|
||||||
catch (e1: IllegalStateException) {
|
catch (e1: IllegalStateException) {
|
||||||
}
|
}
|
||||||
|
catch (e2: NullPointerException) {
|
||||||
|
}
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
@@ -191,6 +193,8 @@ fun intVal(rec: CSVRecord, s: String): Int {
|
|||||||
}
|
}
|
||||||
catch (e1: IllegalStateException) {
|
catch (e1: IllegalStateException) {
|
||||||
}
|
}
|
||||||
|
catch (e2: NullPointerException) {
|
||||||
|
}
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
@@ -204,6 +208,8 @@ fun floatVal(rec: CSVRecord, s: String): Float {
|
|||||||
}
|
}
|
||||||
catch (e1: IllegalStateException) {
|
catch (e1: IllegalStateException) {
|
||||||
}
|
}
|
||||||
|
catch (e2: NullPointerException) {
|
||||||
|
}
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|||||||
150
src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt
Normal file
150
src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
init {
|
||||||
|
uiItems.add(itemList)
|
||||||
|
uiItems.add(equipped)
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,29 +1,21 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.ui
|
package net.torvald.terrarum.modulebasegame.ui
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.Input
|
|
||||||
import com.badlogic.gdx.graphics.*
|
import com.badlogic.gdx.graphics.*
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||||
import net.torvald.ENDASH
|
import net.torvald.ENDASH
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.AppLoader.*
|
import net.torvald.terrarum.AppLoader.*
|
||||||
import net.torvald.terrarum.blockstats.MinimapComposer
|
import net.torvald.terrarum.blockstats.MinimapComposer
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
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.gameactors.Pocketed
|
||||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryDynamicList.Companion.CAT_ALL
|
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryDynamicList.Companion.CAT_ALL
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.*
|
||||||
import net.torvald.terrarum.ui.UIItem
|
|
||||||
import net.torvald.terrarum.ui.UIItemTextButtonList
|
|
||||||
import net.torvald.terrarum.ui.UIItemTextButtonList.Companion.DEFAULT_LINE_HEIGHT
|
import net.torvald.terrarum.ui.UIItemTextButtonList.Companion.DEFAULT_LINE_HEIGHT
|
||||||
import net.torvald.terrarum.ui.UIUtils
|
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
import kotlin.math.roundToInt
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2017-10-21.
|
* Created by minjaesong on 2017-10-21.
|
||||||
@@ -41,11 +33,12 @@ class UIInventoryFull(
|
|||||||
|
|
||||||
override var width: Int = AppLoader.screenW
|
override var width: Int = AppLoader.screenW
|
||||||
override var height: Int = AppLoader.screenH
|
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
|
val CELLS_HOR = 10
|
||||||
private val CELLS_VRT = (AppLoader.screenH - REQUIRED_MARGIN - 134 + UIItemInventoryDynamicList.listGap) / // 134 is another magic number
|
val CELLS_VRT = (AppLoader.screenH - REQUIRED_MARGIN - 134 + UIItemInventoryDynamicList.listGap) / // 134 is another magic number
|
||||||
(UIItemInventoryElemSimple.height + UIItemInventoryDynamicList.listGap)
|
(UIItemInventoryElemSimple.height + UIItemInventoryDynamicList.listGap)
|
||||||
|
|
||||||
private val itemListToEquipViewGap = UIItemInventoryDynamicList.listGap // used to be 24; figured out that the extra gap does nothig
|
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 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 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 {
|
init {
|
||||||
handler.allowESCtoClose = true
|
handler.allowESCtoClose = true
|
||||||
CommonResourcePool.addToLoadingList("inventory_caticons") {
|
CommonResourcePool.addToLoadingList("inventory_caticons") {
|
||||||
@@ -107,10 +102,6 @@ class UIInventoryFull(
|
|||||||
"$gamepadLabelLT ${Lang["GAME_INVENTORY"]}"
|
"$gamepadLabelLT ${Lang["GAME_INVENTORY"]}"
|
||||||
val controlHelpHeight = AppLoader.fontGame.lineHeight
|
val controlHelpHeight = AppLoader.fontGame.lineHeight
|
||||||
|
|
||||||
private var encumbrancePerc = 0f
|
|
||||||
private var isEncumbered = false
|
|
||||||
|
|
||||||
|
|
||||||
val catBarWidth = 330
|
val catBarWidth = 330
|
||||||
val categoryBar = UIItemInventoryCatBar(
|
val categoryBar = UIItemInventoryCatBar(
|
||||||
this,
|
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 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 gameMenuListHeight = DEFAULT_LINE_HEIGHT * gameMenu.size
|
||||||
private val gameMenuListWidth = 400
|
private val gameMenuListWidth = 400
|
||||||
private val gameMenuButtons = UIItemTextButtonList(
|
private val gameMenuButtons = UIItemTextButtonList(
|
||||||
this, gameMenu,
|
this, gameMenu,
|
||||||
(AppLoader.screenW - gameMenuListWidth) / 2,
|
(AppLoader.screenW - gameMenuListWidth) / 2,
|
||||||
(itemList.height - gameMenuListHeight) / 2 + itemList.posY,
|
(transitionalItemCells.itemList.height - gameMenuListHeight) / 2 + transitionalItemCells.itemList.posY,
|
||||||
gameMenuListWidth, gameMenuListHeight,
|
gameMenuListWidth, gameMenuListHeight,
|
||||||
readFromLang = true,
|
readFromLang = true,
|
||||||
textAreaWidth = gameMenuListWidth,
|
textAreaWidth = gameMenuListWidth,
|
||||||
@@ -162,31 +146,19 @@ class UIInventoryFull(
|
|||||||
private val SCREEN_INVENTORY = 1f
|
private val SCREEN_INVENTORY = 1f
|
||||||
private val SCREEN_MENU = 2f
|
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<UIItem>()
|
|
||||||
private val transitionalUpdateUIoriginalPosX = ArrayList<Int>()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
addItem(categoryBar)
|
addUIitem(categoryBar)
|
||||||
itemList.let { addItem(it) }
|
addUIitem(transitionPanel)
|
||||||
equipped.let { addItem(it) }
|
//itemList.let { addUIitem(it) }
|
||||||
|
//equipped.let { addUIitem(it) }
|
||||||
|
|
||||||
|
|
||||||
categoryBar.selectionChangeListener = { old, new ->
|
categoryBar.selectionChangeListener = { old, new ->
|
||||||
rebuildList()
|
rebuildList()
|
||||||
itemList.itemPage = 0 // set scroll to zero
|
transitionalItemCells.resetStatusAsCatChanges(old, new)
|
||||||
itemList.rebuild(catIconsMeaning[catArrangement[new]]) // have to manually rebuild, too!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -204,10 +176,12 @@ class UIInventoryFull(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var offsetX = ((AppLoader.screenW - internalWidth) / 2).toFloat()
|
internal var offsetX = ((AppLoader.screenW - internalWidth) / 2).toFloat()
|
||||||
private var offsetY = ((AppLoader.screenH - internalHeight) / 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) {
|
override fun updateUI(delta: Float) {
|
||||||
if (handler.openFired) {
|
if (handler.openFired) {
|
||||||
@@ -216,25 +190,25 @@ class UIInventoryFull(
|
|||||||
|
|
||||||
|
|
||||||
categoryBar.update(delta)
|
categoryBar.update(delta)
|
||||||
|
transitionPanel.update(delta)
|
||||||
|
|
||||||
transitionalUpdateUIs.forEach { it.update(delta) }
|
|
||||||
|
|
||||||
// update map while visible
|
// update map while visible
|
||||||
if (currentScreenTransition > 1f + epsilon) {
|
/*if (currentScreenTransition > 1f + epsilon) {
|
||||||
MinimapComposer.setWorld(Terrarum.ingame!!.world)
|
MinimapComposer.setWorld(Terrarum.ingame!!.world)
|
||||||
MinimapComposer.update()
|
MinimapComposer.update()
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// update inventory while visible
|
// update inventory while visible
|
||||||
if (currentScreenTransition in epsilon..2f - epsilon) {
|
/*if (currentScreenTransition in epsilon..2f - epsilon) {
|
||||||
itemList.update(delta)
|
itemList.update(delta)
|
||||||
equipped.update(delta)
|
equipped.update(delta)
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// update menu while visible
|
// update menu while visible
|
||||||
if (currentScreenTransition < 1f - epsilon) {
|
/*if (currentScreenTransition < 1f - epsilon) {
|
||||||
gameMenuButtons.update(delta)
|
gameMenuButtons.update(delta)
|
||||||
}
|
}*/
|
||||||
|
|
||||||
minimapRerenderTimer += Gdx.graphics.rawDeltaTime
|
minimapRerenderTimer += Gdx.graphics.rawDeltaTime
|
||||||
}
|
}
|
||||||
@@ -244,50 +218,25 @@ class UIInventoryFull(
|
|||||||
private val shapeRenderer = ShapeRenderer()
|
private val shapeRenderer = ShapeRenderer()
|
||||||
private val gradHeight = 48f
|
private val gradHeight = 48f
|
||||||
|
|
||||||
private val weightBarWidth = UIItemInventoryElemSimple.height * 2f + UIItemInventoryDynamicList.listGap
|
internal var xEnd = (AppLoader.screenW + internalWidth).div(2).toFloat()
|
||||||
|
private set
|
||||||
private var xEnd = (AppLoader.screenW + internalWidth).div(2).toFloat()
|
internal var yEnd = (AppLoader.screenH + internalHeight).div(2).toFloat()
|
||||||
private var yEnd = (AppLoader.screenH + internalHeight).div(2).toFloat()
|
private set
|
||||||
|
|
||||||
private var minimapRerenderTimer = 0f
|
private var minimapRerenderTimer = 0f
|
||||||
private val minimapRerenderInterval = .5f
|
private val minimapRerenderInterval = .5f
|
||||||
|
|
||||||
fun requestTransition(target: Int) {
|
// TODO implemented on UIItemTransitionContainer
|
||||||
|
/*fun requestTransition(target: Int) {
|
||||||
if (!transitionOngoing) {
|
if (!transitionOngoing) {
|
||||||
transitionRequested = true
|
transitionRequested = true
|
||||||
transitionReqSource = currentScreenTransition.round()
|
transitionReqSource = currentScreenTransition.round()
|
||||||
transitionReqTarget = target.toFloat()
|
transitionReqTarget = target.toFloat()
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
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
|
// background fill
|
||||||
batch.end()
|
batch.end()
|
||||||
@@ -312,43 +261,44 @@ class UIInventoryFull(
|
|||||||
|
|
||||||
// UI items
|
// UI items
|
||||||
categoryBar.render(batch, camera)
|
categoryBar.render(batch, camera)
|
||||||
|
transitionPanel.render(batch, camera)
|
||||||
|
|
||||||
// render map while visible
|
// render map while visible
|
||||||
if (currentScreenTransition > 1f + epsilon) {
|
/*if (currentScreenTransition > 1f + epsilon) {
|
||||||
renderScreenMinimap(batch, camera)
|
renderScreenMinimap(batch, camera)
|
||||||
|
|
||||||
if (debugvals) {
|
if (debugvals) {
|
||||||
batch.color = Color.CORAL
|
batch.color = Color.CORAL
|
||||||
AppLoader.fontSmallNumbers.draw(batch, "Map", 300f, 10f)
|
AppLoader.fontSmallNumbers.draw(batch, "Map", 300f, 10f)
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// render inventory while visible
|
// render inventory while visible
|
||||||
if (currentScreenTransition in epsilon..2f - epsilon) {
|
/*if (currentScreenTransition in epsilon..2f - epsilon) {
|
||||||
renderScreenInventory(batch, camera)
|
renderScreenInventory(batch, camera)
|
||||||
|
|
||||||
if (debugvals) {
|
if (debugvals) {
|
||||||
batch.color = Color.CHARTREUSE
|
batch.color = Color.CHARTREUSE
|
||||||
AppLoader.fontSmallNumbers.draw(batch, "Inv", 350f, 10f)
|
AppLoader.fontSmallNumbers.draw(batch, "Inv", 350f, 10f)
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// render menu while visible
|
// render menu while visible
|
||||||
if (currentScreenTransition < 1f - epsilon) {
|
/*if (currentScreenTransition < 1f - epsilon) {
|
||||||
renderScreenGamemenu(batch, camera)
|
renderScreenGamemenu(batch, camera)
|
||||||
|
|
||||||
if (debugvals) {
|
if (debugvals) {
|
||||||
batch.color = Color.SKY
|
batch.color = Color.SKY
|
||||||
AppLoader.fontSmallNumbers.draw(batch, "Men", 400f, 10f)
|
AppLoader.fontSmallNumbers.draw(batch, "Men", 400f, 10f)
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if (debugvals) {
|
/*if (debugvals) {
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
AppLoader.fontSmallNumbers.draw(batch, "minimap:$minimapScrOffX", 500f, 0f)
|
AppLoader.fontSmallNumbers.draw(batch, "minimap:$minimapScrOffX", 500f, 0f)
|
||||||
AppLoader.fontSmallNumbers.draw(batch, "inven:$inventoryScrOffX", 500f, 10f)
|
AppLoader.fontSmallNumbers.draw(batch, "inven:$inventoryScrOffX", 500f, 10f)
|
||||||
AppLoader.fontSmallNumbers.draw(batch, "menu:$menuScrOffX", 500f, 20f)
|
AppLoader.fontSmallNumbers.draw(batch, "menu:$menuScrOffX", 500f, 20f)
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -360,7 +310,7 @@ class UIInventoryFull(
|
|||||||
* - +WIDTH on minimap screen
|
* - +WIDTH on minimap screen
|
||||||
* - -WIDTH on gamemenu screen
|
* - -WIDTH on gamemenu screen
|
||||||
*/
|
*/
|
||||||
private val minimapScrOffX: Float
|
/*private val minimapScrOffX: Float
|
||||||
get() = (currentScreenTransition - 2f) * AppLoader.screenW / 2f
|
get() = (currentScreenTransition - 2f) * AppLoader.screenW / 2f
|
||||||
private val inventoryScrOffX: Float
|
private val inventoryScrOffX: Float
|
||||||
get() = (currentScreenTransition - 1f) * AppLoader.screenW / 2f
|
get() = (currentScreenTransition - 1f) * AppLoader.screenW / 2f
|
||||||
@@ -372,24 +322,24 @@ class UIInventoryFull(
|
|||||||
private val inventoryScrOpacity: Float
|
private val inventoryScrOpacity: Float
|
||||||
get() = (currentScreenTransition - 1f).coerceIn(0f, 1f)
|
get() = (currentScreenTransition - 1f).coerceIn(0f, 1f)
|
||||||
private val menuScrOpacity: Float
|
private val menuScrOpacity: Float
|
||||||
get() = (currentScreenTransition - 0f).coerceIn(0f, 1f)
|
get() = (currentScreenTransition - 0f).coerceIn(0f, 1f)*/
|
||||||
|
|
||||||
private val MINIMAP_WIDTH = 800f
|
//private val MINIMAP_WIDTH = 800f
|
||||||
private val MINIMAP_HEIGHT = itemList.height.toFloat()
|
//private val MINIMAP_HEIGHT = itemList.height.toFloat()
|
||||||
private val MINIMAP_SKYCOL = Color(0x88bbddff.toInt())
|
//private val MINIMAP_SKYCOL = Color(0x88bbddff.toInt())
|
||||||
private var minimapZoom = 1f
|
//private var minimapZoom = 1f
|
||||||
private var minimapPanX = -MinimapComposer.totalWidth / 2f
|
//private var minimapPanX = -MinimapComposer.totalWidth / 2f
|
||||||
private var minimapPanY = -MinimapComposer.totalHeight / 2f
|
//private var minimapPanY = -MinimapComposer.totalHeight / 2f
|
||||||
private val MINIMAP_ZOOM_MIN = 0.5f
|
//private val MINIMAP_ZOOM_MIN = 0.5f
|
||||||
private val MINIMAP_ZOOM_MAX = 8f
|
//private val MINIMAP_ZOOM_MAX = 8f
|
||||||
private val minimapFBO = FrameBuffer(Pixmap.Format.RGBA8888, MINIMAP_WIDTH.toInt(), MINIMAP_HEIGHT.toInt(), false)
|
//private val minimapFBO = FrameBuffer(Pixmap.Format.RGBA8888, MINIMAP_WIDTH.toInt(), MINIMAP_HEIGHT.toInt(), false)
|
||||||
private val minimapCamera = OrthographicCamera(MINIMAP_WIDTH, MINIMAP_HEIGHT)
|
//private val minimapCamera = OrthographicCamera(MINIMAP_WIDTH, MINIMAP_HEIGHT)
|
||||||
|
|
||||||
|
|
||||||
// TODO put 3 bare sub-UIs into proper UIcanvas to handle the motherfucking opacity
|
// TODO put 3 bare sub-UIs into proper UIcanvas to handle the motherfucking opacity
|
||||||
|
|
||||||
|
// TODO not yet refactored
|
||||||
private fun renderScreenMinimap(batch: SpriteBatch, camera: Camera) {
|
/*private fun renderScreenMinimap(batch: SpriteBatch, camera: Camera) {
|
||||||
blendNormal(batch)
|
blendNormal(batch)
|
||||||
|
|
||||||
// update map panning
|
// update map panning
|
||||||
@@ -482,9 +432,10 @@ class UIInventoryFull(
|
|||||||
|
|
||||||
// the minimap
|
// the minimap
|
||||||
batch.draw(minimapFBO.colorBufferTexture, minimapScrOffX + (AppLoader.screenW - MINIMAP_WIDTH) / 2, itemList.posY.toFloat())
|
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
|
// control hints
|
||||||
blendNormal(batch)
|
blendNormal(batch)
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
@@ -493,9 +444,10 @@ class UIInventoryFull(
|
|||||||
// text buttons
|
// text buttons
|
||||||
gameMenuButtons.posX = gameMenuButtons.initialX + menuScrOffX.roundToInt()
|
gameMenuButtons.posX = gameMenuButtons.initialX + menuScrOffX.roundToInt()
|
||||||
gameMenuButtons.render(batch, camera)
|
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.posX = itemList.initialX + inventoryScrOffX.roundToInt()
|
||||||
itemList.render(batch, camera)
|
itemList.render(batch, camera)
|
||||||
equipped.posX = equipped.initialX + inventoryScrOffX.roundToInt()
|
equipped.posX = equipped.initialX + inventoryScrOffX.roundToInt()
|
||||||
@@ -553,17 +505,11 @@ class UIInventoryFull(
|
|||||||
encumbBarYPos + controlHelpHeight - 4f
|
encumbBarYPos + controlHelpHeight - 4f
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
fun rebuildList() {
|
fun rebuildList() {
|
||||||
printdbg(this, "rebuilding list")
|
transitionalItemCells.rebuildList()
|
||||||
|
|
||||||
itemList.rebuild(catIconsMeaning[categoryBar.selectedIcon])
|
|
||||||
equipped.rebuild()
|
|
||||||
|
|
||||||
encumbrancePerc = actor.inventory.capacity.toFloat() / actor.inventory.maxCapacity
|
|
||||||
isEncumbered = actor.inventory.isEncumbered
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Int.fastLen(): Int {
|
private fun Int.fastLen(): Int {
|
||||||
@@ -582,8 +528,8 @@ class UIInventoryFull(
|
|||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
categoryBar.dispose()
|
categoryBar.dispose()
|
||||||
itemList.dispose()
|
transitionPanel.dispose()
|
||||||
equipped.dispose()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -618,40 +564,5 @@ class UIInventoryFull(
|
|||||||
xEnd = (AppLoader.screenW + internalWidth).div(2).toFloat()
|
xEnd = (AppLoader.screenW + internalWidth).div(2).toFloat()
|
||||||
yEnd = (AppLoader.screenH + internalHeight).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)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ class UIItemInventoryDynamicList(
|
|||||||
) : UIItem(parentUI, initialX, initialY) {
|
) : UIItem(parentUI, initialX, initialY) {
|
||||||
|
|
||||||
// deal with the moving position
|
// deal with the moving position
|
||||||
override var oldPosX = posX
|
//override var oldPosX = posX
|
||||||
override var oldPosY = posY
|
//override var oldPosY = posY
|
||||||
|
|
||||||
override val width = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
|
override val width = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
|
||||||
override val height = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
|
override val height = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class UIItemInventoryEquippedView(
|
|||||||
|
|
||||||
|
|
||||||
override val width = WIDTH
|
override val width = WIDTH
|
||||||
override val height = parentUI.itemList.height
|
override val height = parentUI.itemListHeight
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val WIDTH = 2 * UIItemInventoryElemSimple.height + UIItemInventoryDynamicList.listGap
|
val WIDTH = 2 * UIItemInventoryElemSimple.height + UIItemInventoryDynamicList.listGap
|
||||||
@@ -71,10 +71,6 @@ class UIItemInventoryEquippedView(
|
|||||||
itemGrid.forEach { it.update(delta) }
|
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) {
|
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||||
val posXDelta = posX - oldPosX
|
val posXDelta = posX - oldPosX
|
||||||
itemGrid.forEach { it.posX += posXDelta }
|
itemGrid.forEach { it.posX += posXDelta }
|
||||||
|
|||||||
@@ -25,10 +25,6 @@ class UIItemPlayerInfoCell(
|
|||||||
var ingamePlayer: IngamePlayer? = null
|
var ingamePlayer: IngamePlayer? = null
|
||||||
) : UIItem(parent, initialX, initialY) {
|
) : UIItem(parent, initialX, initialY) {
|
||||||
|
|
||||||
// deal with the moving position
|
|
||||||
override var oldPosX = posX
|
|
||||||
override var oldPosY = posY
|
|
||||||
|
|
||||||
override val height = HEIGHT
|
override val height = HEIGHT
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -21,10 +21,6 @@ class UIItemSavegameInfoCell(
|
|||||||
initialY: Int
|
initialY: Int
|
||||||
) : UIItem(parent, initialX, initialY) {
|
) : 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 val height: Int = AppLoader.fontGame.lineHeight.toInt() * 2
|
||||||
|
|
||||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class UIQuickslotPie : UICanvas() {
|
|||||||
val slotX = slotCentrePoint.x.toInt()
|
val slotX = slotCentrePoint.x.toInt()
|
||||||
val slotY = slotCentrePoint.y.toInt()
|
val slotY = slotCentrePoint.y.toInt()
|
||||||
|
|
||||||
drawColor.a = handler.opacity * UIQuickslotBar.DISPLAY_OPACITY
|
drawColor.a = UIQuickslotBar.DISPLAY_OPACITY
|
||||||
batch.color = drawColor
|
batch.color = drawColor
|
||||||
image.draw(batch, slotX, slotY)
|
image.draw(batch, slotX, slotY)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.ui
|
package net.torvald.terrarum.modulebasegame.ui
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Camera
|
import com.badlogic.gdx.graphics.Camera
|
||||||
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.EMDASH
|
import net.torvald.EMDASH
|
||||||
import net.torvald.terrarum.AppLoader
|
import net.torvald.terrarum.AppLoader
|
||||||
@@ -34,7 +35,7 @@ class UIScreenZoom : UICanvas(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
batch.color = handler.opacityColour
|
batch.color = Color.WHITE
|
||||||
|
|
||||||
AppLoader.fontGame.draw(
|
AppLoader.fontGame.draw(
|
||||||
batch, zoomText,
|
batch, zoomText,
|
||||||
|
|||||||
@@ -23,10 +23,11 @@ import net.torvald.terrarum.modulebasegame.worldgenerator.BiomegenParams
|
|||||||
import net.torvald.terrarum.modulebasegame.worldgenerator.TerragenParams
|
import net.torvald.terrarum.modulebasegame.worldgenerator.TerragenParams
|
||||||
import net.torvald.terrarum.modulebasegame.worldgenerator.shake
|
import net.torvald.terrarum.modulebasegame.worldgenerator.shake
|
||||||
import net.torvald.terrarum.worlddrawer.toRGBA
|
import net.torvald.terrarum.worlddrawer.toRGBA
|
||||||
|
import java.util.concurrent.Future
|
||||||
import kotlin.math.cos
|
import kotlin.math.cos
|
||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
import kotlinx.coroutines.*
|
import kotlin.coroutines.*
|
||||||
|
|
||||||
const val WIDTH = 768
|
const val WIDTH = 768
|
||||||
const val HEIGHT = 512
|
const val HEIGHT = 512
|
||||||
@@ -52,6 +53,8 @@ class WorldgenNoiseSandbox : ApplicationAdapter() {
|
|||||||
|
|
||||||
private var generationTimeInMeasure = false
|
private var generationTimeInMeasure = false
|
||||||
private var generationStartTime = 0L
|
private var generationStartTime = 0L
|
||||||
|
private var genSlices: Int = 0
|
||||||
|
private var genFutures: Array<Future<*>?> = arrayOfNulls(genSlices)
|
||||||
|
|
||||||
override fun create() {
|
override fun create() {
|
||||||
font = BitmapFont() // use default because fuck it
|
font = BitmapFont() // use default because fuck it
|
||||||
@@ -67,6 +70,8 @@ class WorldgenNoiseSandbox : ApplicationAdapter() {
|
|||||||
testTex.blending = Pixmap.Blending.None
|
testTex.blending = Pixmap.Blending.None
|
||||||
tempTex = Texture(1, 1, Pixmap.Format.RGBA8888)
|
tempTex = Texture(1, 1, Pixmap.Format.RGBA8888)
|
||||||
|
|
||||||
|
genSlices = maxOf(ThreadExecutor.threadCount, testTex.width / 8)
|
||||||
|
|
||||||
println("Init done")
|
println("Init done")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +96,7 @@ class WorldgenNoiseSandbox : ApplicationAdapter() {
|
|||||||
renderNoise()
|
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
|
// check if generation is done
|
||||||
if (coroutineExecFinished) {
|
if (coroutineExecFinished) {
|
||||||
generateKeyLatched = false
|
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<Job>
|
|
||||||
|
|
||||||
private fun renderNoise() {
|
private fun renderNoise() {
|
||||||
generationStartTime = System.nanoTime()
|
generationStartTime = System.nanoTime()
|
||||||
@@ -220,7 +219,7 @@ class WorldgenNoiseSandbox : ApplicationAdapter() {
|
|||||||
} }*/
|
} }*/
|
||||||
|
|
||||||
// 2. each runner gets their own copy of Joise
|
// 2. each runner gets their own copy of Joise
|
||||||
val runnables: List<RunnableFun> = xSlices.map { range -> {
|
val runnables: List<RunnableFun> = (0 until testTex.width).sliceEvenly(genSlices).map { range -> {
|
||||||
val localJoise = getNoiseGenerator(seed)
|
val localJoise = getNoiseGenerator(seed)
|
||||||
for (x in range) {
|
for (x in range) {
|
||||||
for (y in 0 until HEIGHT) {
|
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
|
initialGenDone = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,13 @@ abstract class UICanvas(
|
|||||||
get() = handler.posY
|
get() = handler.posY
|
||||||
set(value) { handler.posY = value }
|
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
|
* Usage: (in StateInGame:) uiHandlerField.ui.handler = uiHandlerField
|
||||||
*/
|
*/
|
||||||
@@ -103,16 +110,19 @@ 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)
|
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.
|
* 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.
|
* 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.
|
* 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
|
* The transparency of the handler is independent of the draw, you must set the drawing color yourself
|
||||||
* using handler.opacity or handler.opacityColour
|
* (use handler.opacity or handler.opacityColour)
|
||||||
*/
|
*/
|
||||||
abstract fun renderUI(batch: SpriteBatch, camera: Camera)
|
abstract fun renderUI(batch: SpriteBatch, camera: Camera)
|
||||||
|
|
||||||
@@ -138,7 +148,7 @@ abstract class UICanvas(
|
|||||||
|
|
||||||
abstract override fun dispose()
|
abstract override fun dispose()
|
||||||
|
|
||||||
fun addItem(uiItem: UIItem) {
|
fun addUIitem(uiItem: UIItem) {
|
||||||
uiItems.add(uiItem)
|
uiItems.add(uiItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.Camera
|
|||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.utils.Disposable
|
import com.badlogic.gdx.utils.Disposable
|
||||||
|
import net.torvald.terrarum.AppLoader
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
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.
|
* 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.
|
* 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!
|
* New UIs are NORMALLY HIDDEN; set it visible as you need!
|
||||||
*
|
*
|
||||||
* Created by minjaesong on 2015-12-31.
|
* Created by minjaesong on 2015-12-31.
|
||||||
@@ -28,10 +32,51 @@ class UIHandler(//var UI: UICanvas,
|
|||||||
internal var allowESCtoClose: Boolean = false
|
internal var allowESCtoClose: Boolean = false
|
||||||
): Disposable {
|
): 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.
|
// X/Y Position relative to the game window.
|
||||||
var posX: Int = 0
|
var posX: Int = 0
|
||||||
var posY: Int = 0
|
var posY: Int = 0
|
||||||
|
|
||||||
|
var initialX = posX
|
||||||
|
var initialY = posY
|
||||||
|
|
||||||
private var alwaysVisible = false
|
private var alwaysVisible = false
|
||||||
|
|
||||||
var isOpening = false
|
var isOpening = false
|
||||||
@@ -60,16 +105,18 @@ class UIHandler(//var UI: UICanvas,
|
|||||||
var closeFired = false
|
var closeFired = false
|
||||||
|
|
||||||
var opacity = 1f
|
var opacity = 1f
|
||||||
set(value) {
|
/*set(value) {
|
||||||
field = value
|
field = value
|
||||||
opacityColour.set(1f,1f,1f,opacity)
|
opacityColour.a = value
|
||||||
}
|
}*/
|
||||||
var scale = 1f
|
var scale = 1f
|
||||||
|
|
||||||
val opacityColour = Color(1f, 1f, 1f, opacity)
|
//val opacityColour = Color(1f, 1f, 1f, opacity)
|
||||||
|
|
||||||
var openCloseCounter = 0f
|
var openCloseCounter = 0f
|
||||||
|
|
||||||
|
private val shader = AppLoader.loadShaderInline(SHADER_PROG_VERT, SHADER_PROG_FRAG)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
//UI.handler = this
|
//UI.handler = this
|
||||||
}
|
}
|
||||||
@@ -201,9 +248,12 @@ class UIHandler(//var UI: UICanvas,
|
|||||||
}
|
}
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
|
|
||||||
|
batch.shader = shader
|
||||||
|
shader.setUniformf("opacity", opacity)
|
||||||
ui.renderUI(batch, camera)
|
ui.renderUI(batch, camera)
|
||||||
//ingameGraphics.flush()
|
//ingameGraphics.flush()
|
||||||
|
|
||||||
|
batch.shader = null
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
|
|
||||||
|
|
||||||
@@ -381,5 +431,6 @@ class UIHandler(//var UI: UICanvas,
|
|||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
toggleKey?.let { KeyToggler.forceSet(it, false) }
|
toggleKey?.let { KeyToggler.forceSet(it, false) }
|
||||||
toggleButton?.let { /* ButtonToggler.forceSet(it, false) */ }
|
toggleButton?.let { /* ButtonToggler.forceSet(it, false) */ }
|
||||||
|
shader.dispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
|||||||
* oldPosX = posX
|
* oldPosX = posX
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
protected abstract var oldPosX: Int
|
protected var oldPosX: Int = initialX
|
||||||
/** This variable is NOT updated on its own.
|
/** This variable is NOT updated on its own.
|
||||||
* ```
|
* ```
|
||||||
* val posYDelta = posY - oldPosY
|
* val posYDelta = posY - oldPosY
|
||||||
@@ -75,7 +75,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
|||||||
* oldPosY = posY
|
* oldPosY = posY
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
protected abstract var oldPosY: Int
|
protected var oldPosY: Int = initialY
|
||||||
|
|
||||||
/** Position of mouse relative to this item */
|
/** Position of mouse relative to this item */
|
||||||
protected val relativeMouseX: Int
|
protected val relativeMouseX: Int
|
||||||
|
|||||||
@@ -36,9 +36,6 @@ class UIItemConfigKeycap(
|
|||||||
override val width = capTex.tileW * keySize
|
override val width = capTex.tileW * keySize
|
||||||
override val height = capTex.tileH
|
override val height = capTex.tileH
|
||||||
|
|
||||||
override var oldPosX = posX
|
|
||||||
override var oldPosY = posY
|
|
||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
super.update(delta)
|
super.update(delta)
|
||||||
}
|
}
|
||||||
|
|||||||
44
src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt
Normal file
44
src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package net.torvald.terrarum.ui
|
||||||
|
|
||||||
|
import com.jme3.math.FastMath
|
||||||
|
import kotlin.math.absoluteValue
|
||||||
|
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.15f, currentPosition, uis) {
|
||||||
|
|
||||||
|
fun getOffX(index: Int) = ((currentPosition - index) * width / 2f).roundToInt()
|
||||||
|
fun getOpacity(index: Int) = 1f - (currentPosition - index).absoluteValue.coerceIn(0f, 1f)
|
||||||
|
|
||||||
|
|
||||||
|
init {
|
||||||
|
// re-position the uis according to the initial choice of currentPosition
|
||||||
|
uis.forEachIndexed { index, it ->
|
||||||
|
it.posX = 0 + getOffX(index)
|
||||||
|
it.initialX = 0 + getOffX(index)
|
||||||
|
it.posY = 0
|
||||||
|
it.initialY = 0
|
||||||
|
it.opacity = getOpacity(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTransition(currentPosition: Float, uis: Array<out UICanvas>) {
|
||||||
|
uis.forEachIndexed { index, it ->
|
||||||
|
it.posX = -getOffX(index)
|
||||||
|
it.posY = it.initialY
|
||||||
|
it.opacity = getOpacity(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,10 +41,6 @@ open class UIItemImageButton(
|
|||||||
var highlightable: Boolean
|
var highlightable: Boolean
|
||||||
) : UIItem(parent, initialX, initialY) {
|
) : UIItem(parent, initialX, initialY) {
|
||||||
|
|
||||||
// deal with the moving position
|
|
||||||
override var oldPosX = posX
|
|
||||||
override var oldPosY = posY
|
|
||||||
|
|
||||||
var highlighted = false
|
var highlighted = false
|
||||||
|
|
||||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||||
|
|||||||
@@ -20,10 +20,6 @@ class UIItemImageGallery(
|
|||||||
val column: Int = 1
|
val column: Int = 1
|
||||||
) : UIItem(parentUI, initialX, initialY) {
|
) : UIItem(parentUI, initialX, initialY) {
|
||||||
|
|
||||||
// deal with the moving position
|
|
||||||
override var oldPosX = posX
|
|
||||||
override var oldPosY = posY
|
|
||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,10 +75,6 @@ class UIItemIntSlider(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// deal with the moving position
|
|
||||||
override var oldPosX = posX
|
|
||||||
override var oldPosY = posY
|
|
||||||
|
|
||||||
var value = initValue
|
var value = initValue
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,10 +36,6 @@ class UIItemList<Item: UIItem>(
|
|||||||
val border: Int = 0
|
val border: Int = 0
|
||||||
) : UIItem(parentUI, initialX, initialY) {
|
) : UIItem(parentUI, initialX, initialY) {
|
||||||
|
|
||||||
// deal with the moving position
|
|
||||||
override var oldPosX = posX
|
|
||||||
override var oldPosY = posY
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
itemList.forEachIndexed { index, item ->
|
itemList.forEachIndexed { index, item ->
|
||||||
item.posX = this.posX + border
|
item.posX = this.posX + border
|
||||||
|
|||||||
@@ -16,10 +16,6 @@ class UIItemModuleInfoCell(
|
|||||||
initialY: Int
|
initialY: Int
|
||||||
) : UIItem(parent, initialX, initialY) {
|
) : 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 val height: Int = AppLoader.fontGame.lineHeight.toInt() * 2
|
||||||
|
|
||||||
private val numberAreaWidth = AppLoader.fontSmallNumbers.W * 3 + 4
|
private val numberAreaWidth = AppLoader.fontSmallNumbers.W * 3 + 4
|
||||||
|
|||||||
@@ -17,10 +17,6 @@ class UIItemTextArea(
|
|||||||
val align: Alignment = Alignment.LEFT
|
val align: Alignment = Alignment.LEFT
|
||||||
) : UIItem(parentUI, initialX, initialY) {
|
) : UIItem(parentUI, initialX, initialY) {
|
||||||
|
|
||||||
// deal with the moving position
|
|
||||||
override var oldPosX = posX
|
|
||||||
override var oldPosY = posY
|
|
||||||
|
|
||||||
private var entireText: List<String> = listOf("") // placeholder
|
private var entireText: List<String> = listOf("") // placeholder
|
||||||
|
|
||||||
var scrollPos = 0
|
var scrollPos = 0
|
||||||
|
|||||||
@@ -48,10 +48,6 @@ open class UIItemTextButton(
|
|||||||
val hitboxSize: Int = UIItemTextButton.height
|
val hitboxSize: Int = UIItemTextButton.height
|
||||||
) : UIItem(parentUI, initialX, initialY) {
|
) : UIItem(parentUI, initialX, initialY) {
|
||||||
|
|
||||||
// deal with the moving position
|
|
||||||
override var oldPosX = posX
|
|
||||||
override var oldPosY = posY
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val font = AppLoader.fontGame
|
val font = AppLoader.fontGame
|
||||||
val height = font.lineHeight.toInt()
|
val height = font.lineHeight.toInt()
|
||||||
|
|||||||
@@ -57,10 +57,6 @@ class UIItemTextButtonList(
|
|||||||
val DEFAULT_LINE_HEIGHT = 36
|
val DEFAULT_LINE_HEIGHT = 36
|
||||||
}
|
}
|
||||||
|
|
||||||
// deal with the moving position
|
|
||||||
override var oldPosX = posX
|
|
||||||
override var oldPosY = posY
|
|
||||||
|
|
||||||
val iconToTextGap = 20
|
val iconToTextGap = 20
|
||||||
val iconCellWidth = (iconSpriteSheet?.tileW ?: -iconToTextGap) / (iconSpriteSheet?.horizontalCount ?: 1)
|
val iconCellWidth = (iconSpriteSheet?.tileW ?: -iconToTextGap) / (iconSpriteSheet?.horizontalCount ?: 1)
|
||||||
val iconCellHeight = (iconSpriteSheet?.tileH ?: 0) / (iconSpriteSheet?.verticalCount ?: 1)
|
val iconCellHeight = (iconSpriteSheet?.tileH ?: 0) / (iconSpriteSheet?.verticalCount ?: 1)
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ class UIItemToggleButton(
|
|||||||
get() = togglerBase.width
|
get() = togglerBase.width
|
||||||
override val height: Int
|
override val height: Int
|
||||||
get() = togglerBase.height
|
get() = togglerBase.height
|
||||||
override var oldPosX = posX
|
|
||||||
override var oldPosY = posY
|
|
||||||
|
|
||||||
private var togglerBase = CommonResourcePool.getAsTexture("ui_item_toggler_base")
|
private var togglerBase = CommonResourcePool.getAsTexture("ui_item_toggler_base")
|
||||||
private var togglerHandle = CommonResourcePool.getAsTexture("ui_item_toggler_handle")
|
private var togglerHandle = CommonResourcePool.getAsTexture("ui_item_toggler_handle")
|
||||||
|
|||||||
127
src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt
Normal file
127
src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
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.15f,
|
||||||
|
var currentPosition: Float = 0f,
|
||||||
|
val uis: Array<out UICanvas>
|
||||||
|
) : 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
|
||||||
|
|
||||||
|
private fun timeToUpdate(index: Int) = true//(currentPosition > index - 1 + epsilon && currentPosition < index + 1 - epsilon)
|
||||||
|
|
||||||
|
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 (timeToUpdate(index)) ui.update(delta) }
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun onTransition(currentPosition: Float, uis: Array<out UICanvas>) {}
|
||||||
|
|
||||||
|
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 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() }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,17 @@ import net.torvald.terrarum.sqr
|
|||||||
object UIUtils {
|
object UIUtils {
|
||||||
fun moveQuick(start: Float, end: Float, timer: Float, duration: Float) =
|
fun moveQuick(start: Float, end: Float, timer: Float, duration: Float) =
|
||||||
(start - end) * ((timer / duration) - 1).sqr() + end
|
(start - end) * ((timer / duration) - 1).sqr() + end
|
||||||
fun moveLinear(start: Float, end: Float, timer: Float, duration: Float) =
|
fun moveLinear(start: Float, end: Float, timer: Float, duration: Float): Float {
|
||||||
(start - end) * (1 - (timer / duration)) + end
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
|
||||||
<orderEntry type="library" name="lib" level="project" />
|
<orderEntry type="library" name="lib" level="project" />
|
||||||
<orderEntry type="library" name="com.badlogicgames.gdx:gdx-backend-lwjgl:1.9.10" level="project" />
|
<orderEntry type="library" name="com.badlogicgames.gdx:gdx-backend-lwjgl:1.9.10" level="project" />
|
||||||
<orderEntry type="library" name="com.badlogicgames.gdx:gdx-backend-lwjgl3:1.9.10" level="project" />
|
<orderEntry type="library" name="com.badlogicgames.gdx:gdx-backend-lwjgl3:1.9.10" level="project" />
|
||||||
|
|||||||
Reference in New Issue
Block a user