mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 18:14:06 +09:00
inventory gamemenu visual only
This commit is contained in:
@@ -246,6 +246,7 @@ object Terrarum : Screen {
|
|||||||
RunningEnvironment.PC
|
RunningEnvironment.PC
|
||||||
}
|
}
|
||||||
//}
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -689,6 +690,7 @@ fun Double.roundInt(): Int = Math.round(this).toInt()
|
|||||||
fun Float.roundInt(): Int = Math.round(this)
|
fun Float.roundInt(): Int = Math.round(this)
|
||||||
fun Double.abs() = Math.abs(this)
|
fun Double.abs() = Math.abs(this)
|
||||||
fun Double.sqr() = this * this
|
fun Double.sqr() = this * this
|
||||||
|
fun Float.sqr() = this * this
|
||||||
fun Double.sqrt() = Math.sqrt(this)
|
fun Double.sqrt() = Math.sqrt(this)
|
||||||
fun Float.sqrt() = FastMath.sqrt(this)
|
fun Float.sqrt() = FastMath.sqrt(this)
|
||||||
fun Int.abs() = this.absoluteValue
|
fun Int.abs() = this.absoluteValue
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import com.badlogic.gdx.graphics.Pixmap
|
|||||||
import com.badlogic.gdx.graphics.Texture
|
import com.badlogic.gdx.graphics.Texture
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
|
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
|
||||||
import net.torvald.terrarum.ui.*
|
import net.torvald.terrarum.ui.UIItem
|
||||||
|
import net.torvald.terrarum.ui.UIItemImageButton
|
||||||
|
import net.torvald.terrarum.ui.UIUtils
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2017-10-20.
|
* Created by minjaesong on 2017-10-20.
|
||||||
@@ -18,6 +20,12 @@ class UIItemInventoryCatBar(
|
|||||||
override val width: Int
|
override val width: Int
|
||||||
) : UIItem(parentUI) {
|
) : UIItem(parentUI) {
|
||||||
|
|
||||||
|
// deal with the moving position
|
||||||
|
override var oldPosX = posX
|
||||||
|
override var oldPosY = posY
|
||||||
|
|
||||||
|
private val parentInventory = parentUI
|
||||||
|
|
||||||
private val catIcons = parentUI.catIcons
|
private val catIcons = parentUI.catIcons
|
||||||
private val catArrangement = parentUI.catArrangement
|
private val catArrangement = parentUI.catArrangement
|
||||||
|
|
||||||
@@ -91,7 +99,7 @@ class UIItemInventoryCatBar(
|
|||||||
private val underlineColour = Color(0xeaeaea_40.toInt())
|
private val underlineColour = Color(0xeaeaea_40.toInt())
|
||||||
private val underlineHighlightColour = mainButtons[0].highlightCol
|
private val underlineHighlightColour = mainButtons[0].highlightCol
|
||||||
|
|
||||||
private var highlighterXPos = mainButtons[selectedIndex].posX.toDouble()
|
private var highlighterXPos = mainButtons[selectedIndex].posX.toFloat()
|
||||||
private var highlighterXStart = highlighterXPos
|
private var highlighterXStart = highlighterXPos
|
||||||
private var highlighterXEnd = highlighterXPos
|
private var highlighterXEnd = highlighterXPos
|
||||||
|
|
||||||
@@ -100,6 +108,14 @@ class UIItemInventoryCatBar(
|
|||||||
private val highlighterMoveDuration: Second = 0.1f
|
private val highlighterMoveDuration: Second = 0.1f
|
||||||
private var highlighterMoveTimer: Second = 0f
|
private var highlighterMoveTimer: Second = 0f
|
||||||
|
|
||||||
|
private var transitionFired = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0: map, 1: inventory caticons, 2: menu
|
||||||
|
*/
|
||||||
|
var selectedPanel = 1
|
||||||
|
private set
|
||||||
|
|
||||||
// set up underlined indicator
|
// set up underlined indicator
|
||||||
init {
|
init {
|
||||||
// procedurally generate texture
|
// procedurally generate texture
|
||||||
@@ -134,8 +150,8 @@ class UIItemInventoryCatBar(
|
|||||||
highlighterXPos = UIUtils.moveQuick(
|
highlighterXPos = UIUtils.moveQuick(
|
||||||
highlighterXStart,
|
highlighterXStart,
|
||||||
highlighterXEnd,
|
highlighterXEnd,
|
||||||
highlighterMoveTimer.toDouble(),
|
highlighterMoveTimer,
|
||||||
highlighterMoveDuration.toDouble()
|
highlighterMoveDuration
|
||||||
)
|
)
|
||||||
|
|
||||||
if (highlighterMoveTimer > highlighterMoveDuration) {
|
if (highlighterMoveTimer > highlighterMoveDuration) {
|
||||||
@@ -150,23 +166,61 @@ class UIItemInventoryCatBar(
|
|||||||
mainButtons.forEachIndexed { index, btn ->
|
mainButtons.forEachIndexed { index, btn ->
|
||||||
btn.update(delta)
|
btn.update(delta)
|
||||||
|
|
||||||
|
if (btn.mousePushed && selectedPanel != 1) {
|
||||||
|
transitionFired = true
|
||||||
|
selectedPanel = 1
|
||||||
|
}
|
||||||
|
|
||||||
if (btn.mousePushed && index != selectedIndex) {
|
if (btn.mousePushed && index != selectedIndex) {
|
||||||
|
// normal stuffs
|
||||||
val oldIndex = selectedIndex
|
val oldIndex = selectedIndex
|
||||||
|
|
||||||
highlighterXStart = mainButtons[selectedIndex].posX.toDouble() // using old selectedIndex
|
highlighterXStart = mainButtons[selectedIndex].posX.toFloat() // using old selectedIndex
|
||||||
selectedIndex = index
|
selectedIndex = index
|
||||||
highlighterMoving = true
|
highlighterMoving = true
|
||||||
highlighterXEnd = mainButtons[selectedIndex].posX.toDouble() // using new selectedIndex
|
highlighterXEnd = mainButtons[selectedIndex].posX.toFloat() // using new selectedIndex
|
||||||
|
|
||||||
selectionChangeListener?.invoke(oldIndex, index)
|
selectionChangeListener?.invoke(oldIndex, index)
|
||||||
}
|
}
|
||||||
btn.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null
|
|
||||||
|
|
||||||
|
if (selectedPanel == 1) {
|
||||||
|
btn.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null
|
||||||
|
|
||||||
|
sideButtons[0].highlighted = false
|
||||||
|
sideButtons[3].highlighted = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sideButtons[0].update(delta)
|
sideButtons[0].update(delta)
|
||||||
sideButtons[3].update(delta)
|
sideButtons[3].update(delta)
|
||||||
|
|
||||||
|
|
||||||
|
// more transition stuffs
|
||||||
|
if (sideButtons[0].mousePushed) {
|
||||||
|
if (selectedPanel != 0) transitionFired = true
|
||||||
|
mainButtons.forEach { it.highlighted = false }
|
||||||
|
selectedPanel = 0
|
||||||
|
parentInventory.requestTransition(0)
|
||||||
|
|
||||||
|
sideButtons[0].highlighted = true
|
||||||
|
sideButtons[3].highlighted = false
|
||||||
|
}
|
||||||
|
else if (sideButtons[3].mousePushed) {
|
||||||
|
if (selectedPanel != 2) transitionFired = true
|
||||||
|
mainButtons.forEach { it.highlighted = false }
|
||||||
|
selectedPanel = 2
|
||||||
|
parentInventory.requestTransition(2)
|
||||||
|
transitionFired = true
|
||||||
|
|
||||||
|
sideButtons[0].highlighted = false
|
||||||
|
sideButtons[3].highlighted = true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (transitionFired) {
|
||||||
|
transitionFired = false
|
||||||
|
parentInventory.requestTransition(2 - selectedPanel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||||
@@ -186,8 +240,12 @@ class UIItemInventoryCatBar(
|
|||||||
batch.drawStraightLine(posX.toFloat(), posY + height - 1f, posX + width.toFloat(), 1f, false)
|
batch.drawStraightLine(posX.toFloat(), posY + height - 1f, posX + width.toFloat(), 1f, false)
|
||||||
|
|
||||||
// indicator
|
// indicator
|
||||||
batch.color = underlineHighlightColour
|
if (selectedPanel == 1) {
|
||||||
batch.draw(underlineIndTex, (highlighterXPos - buttonGapSize / 2).toFloat().round(), posY + highlighterYPos)
|
batch.color = underlineHighlightColour
|
||||||
|
batch.draw(underlineIndTex, (highlighterXPos - buttonGapSize / 2).toFloat().round(), posY + highlighterYPos)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ class UIItemInventoryElem(
|
|||||||
val drawBackOnNull: Boolean = true
|
val drawBackOnNull: Boolean = true
|
||||||
) : UIItemInventoryCellBase(parentUI, posX, posY, item, amount, itemImage, quickslot, equippedSlot) {
|
) : UIItemInventoryCellBase(parentUI, posX, posY, 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
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ class UIItemInventoryElemSimple(
|
|||||||
val drawBackOnNull: Boolean = true
|
val drawBackOnNull: Boolean = true
|
||||||
) : UIItemInventoryCellBase(parentUI, posX, posY, item, amount, itemImage, quickslot, equippedSlot) {
|
) : UIItemInventoryCellBase(parentUI, posX, posY, 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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import com.badlogic.gdx.graphics.Color
|
|||||||
import com.badlogic.gdx.graphics.GL20
|
import com.badlogic.gdx.graphics.GL20
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||||
import com.jme3.math.FastMath
|
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.gameactors.ActorWBMovable
|
import net.torvald.terrarum.gameactors.ActorWBMovable
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
@@ -15,6 +14,8 @@ import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory.Companion.C
|
|||||||
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
|
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
import net.torvald.terrarum.ui.UIItem
|
import net.torvald.terrarum.ui.UIItem
|
||||||
|
import net.torvald.terrarum.ui.UIItemTextButtonList
|
||||||
|
import net.torvald.terrarum.ui.UIUtils
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,6 +30,8 @@ class UIInventoryFull(
|
|||||||
doNotWarnConstant: Boolean = false
|
doNotWarnConstant: Boolean = false
|
||||||
) : UICanvas(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant) {
|
) : UICanvas(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant) {
|
||||||
|
|
||||||
|
private val debugvals = false
|
||||||
|
|
||||||
override var width: Int = Terrarum.WIDTH
|
override var width: Int = Terrarum.WIDTH
|
||||||
override var height: Int = Terrarum.HEIGHT
|
override var height: Int = Terrarum.HEIGHT
|
||||||
|
|
||||||
@@ -60,12 +63,12 @@ class UIInventoryFull(
|
|||||||
get() = if (AppLoader.environment == RunningEnvironment.PC)
|
get() = if (AppLoader.environment == RunningEnvironment.PC)
|
||||||
"${0xe031.toChar()} ${Lang["GAME_ACTION_CLOSE"]}"
|
"${0xe031.toChar()} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||||
else
|
else
|
||||||
"${0xe031.toChar()} ${Lang["GAME_ACTION_CLOSE"]}$SP${0xe06b.toChar()} ${Lang["GAME_INVENTORY"]}"
|
"${0xe069.toChar()} ${Lang["GAME_ACTION_CLOSE"]}$SP${0xe06b.toChar()} ${Lang["GAME_INVENTORY"]}"
|
||||||
val gameMenuControlHelp: String
|
val gameMenuControlHelp: String
|
||||||
get() = if (AppLoader.environment == RunningEnvironment.PC)
|
get() = if (AppLoader.environment == RunningEnvironment.PC)
|
||||||
"${0xe031.toChar()} ${Lang["GAME_ACTION_CLOSE"]}"
|
"${0xe031.toChar()} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||||
else
|
else
|
||||||
"${0xe031.toChar()} ${Lang["GAME_ACTION_CLOSE"]}$SP${0xe068.toChar()} ${Lang["GAME_INVENTORY"]}"
|
"${0xe069.toChar()} ${Lang["GAME_ACTION_CLOSE"]}$SP${0xe068.toChar()} ${Lang["GAME_INVENTORY"]}"
|
||||||
val controlHelpHeight = Terrarum.fontGame.lineHeight
|
val controlHelpHeight = Terrarum.fontGame.lineHeight
|
||||||
|
|
||||||
private var encumbrancePerc = 0f
|
private var encumbrancePerc = 0f
|
||||||
@@ -104,16 +107,35 @@ class UIInventoryFull(
|
|||||||
internalWidth - UIItemInventoryEquippedView.WIDTH + (Terrarum.WIDTH - internalWidth) / 2,
|
internalWidth - UIItemInventoryEquippedView.WIDTH + (Terrarum.WIDTH - internalWidth) / 2,
|
||||||
109 + (Terrarum.HEIGHT - internalHeight) / 2
|
109 + (Terrarum.HEIGHT - internalHeight) / 2
|
||||||
)
|
)
|
||||||
|
private val gameMenuListWidth = 400
|
||||||
|
private val gameMenuListHeight = 40 * 5
|
||||||
|
private val gameMenuCharInfoHeight = 64 + 40 // no top margin, 40 bottom margin
|
||||||
|
private val gameMenuListTotalHeight = gameMenuListHeight + gameMenuCharInfoHeight
|
||||||
|
private val gameMenuButtons = UIItemTextButtonList(
|
||||||
|
this, arrayOf("MENU_LABEL_MAINMENU", "MENU_LABEL_DESKTOP", "MENU_OPTIONS_CONTROLS", "MENU_OPTIONS_SOUND", "MENU_LABEL_GRAPHICS"),
|
||||||
|
Terrarum.WIDTH + (Terrarum.WIDTH - gameMenuListWidth) / 2,
|
||||||
|
(itemList.height - gameMenuListTotalHeight) / 2 + itemList.posY + gameMenuCharInfoHeight,
|
||||||
|
gameMenuListWidth, gameMenuListHeight,
|
||||||
|
readFromLang = true,
|
||||||
|
textAreaWidth = gameMenuListWidth,
|
||||||
|
activeBackCol = Color(0),
|
||||||
|
highlightBackCol = Color(0),
|
||||||
|
backgroundCol = Color(0),
|
||||||
|
inactiveCol = Color.WHITE,
|
||||||
|
defaultSelection = null
|
||||||
|
)
|
||||||
|
|
||||||
|
private val SCREEN_MINIMAP = 2f
|
||||||
|
private val SCREEN_INVENTORY = 1f
|
||||||
|
private val SCREEN_MENU = 0f
|
||||||
|
|
||||||
private var currentScreen = 1f //
|
private var currentScreen = SCREEN_INVENTORY
|
||||||
private var transitionRequested = false
|
private var transitionRequested = false
|
||||||
|
private var transitionOngoing = false
|
||||||
|
private var transitionReqSource = SCREEN_INVENTORY
|
||||||
|
private var transitionReqTarget = SCREEN_INVENTORY
|
||||||
private var transitionTimer = 0f
|
private var transitionTimer = 0f
|
||||||
private val transitionLength = 0.5f
|
private val transitionLength = 0.333f
|
||||||
|
|
||||||
private val SCREEN_MINIMAP = 0
|
|
||||||
private val SCREEN_INVENTORY = 1
|
|
||||||
private val SCREEN_MENU = 2
|
|
||||||
|
|
||||||
|
|
||||||
private val transitionalUpdateUIs = ArrayList<UIItem>()
|
private val transitionalUpdateUIs = ArrayList<UIItem>()
|
||||||
@@ -151,6 +173,7 @@ class UIInventoryFull(
|
|||||||
|
|
||||||
addToTransitionalGroup(itemList)
|
addToTransitionalGroup(itemList)
|
||||||
addToTransitionalGroup(equipped)
|
addToTransitionalGroup(equipped)
|
||||||
|
addToTransitionalGroup(gameMenuButtons)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var offsetX = ((Terrarum.WIDTH - internalWidth) / 2).toFloat()
|
private var offsetX = ((Terrarum.WIDTH - internalWidth) / 2).toFloat()
|
||||||
@@ -165,8 +188,9 @@ class UIInventoryFull(
|
|||||||
|
|
||||||
|
|
||||||
categoryBar.update(delta)
|
categoryBar.update(delta)
|
||||||
itemList.update(delta)
|
|
||||||
equipped.update(delta)
|
transitionalUpdateUIs.forEach { it.update(delta) }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val gradStartCol = Color(0x404040_60)
|
private val gradStartCol = Color(0x404040_60)
|
||||||
@@ -179,13 +203,41 @@ class UIInventoryFull(
|
|||||||
private var xEnd = (Terrarum.WIDTH + internalWidth).div(2).toFloat()
|
private var xEnd = (Terrarum.WIDTH + internalWidth).div(2).toFloat()
|
||||||
private var yEnd = (Terrarum.HEIGHT + internalHeight).div(2).toFloat()
|
private var yEnd = (Terrarum.HEIGHT + internalHeight).div(2).toFloat()
|
||||||
|
|
||||||
|
fun requestTransition(target: Int) {
|
||||||
|
if (!transitionOngoing) {
|
||||||
|
transitionRequested = true
|
||||||
|
transitionReqSource = currentScreen.round()
|
||||||
|
transitionReqTarget = target.toFloat()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
|
|
||||||
currentScreen = 1f + 0.1f * FastMath.sin(transitionTimer)
|
if (transitionRequested && !transitionOngoing) {
|
||||||
transitionTimer += Gdx.graphics.deltaTime
|
transitionRequested = false
|
||||||
|
transitionOngoing = true
|
||||||
|
transitionTimer = 0f
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transitionOngoing) {
|
||||||
|
transitionTimer += Gdx.graphics.deltaTime
|
||||||
|
|
||||||
|
currentScreen = UIUtils.moveQuick(transitionReqSource, transitionReqTarget, transitionTimer, transitionLength)
|
||||||
|
|
||||||
|
if (transitionTimer > transitionLength) {
|
||||||
|
transitionOngoing = false
|
||||||
|
currentScreen = transitionReqTarget
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// update at render time
|
// update at render time
|
||||||
updateTransitionalItems()
|
updateTransitionalItems()
|
||||||
|
if (debugvals) {
|
||||||
|
batch.color = Color.WHITE
|
||||||
|
AppLoader.fontSmallNumbers.draw(batch, "screen:$currentScreen", 500f, 20f)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -213,16 +265,83 @@ class UIInventoryFull(
|
|||||||
categoryBar.render(batch, camera)
|
categoryBar.render(batch, camera)
|
||||||
|
|
||||||
|
|
||||||
renderScreenInventory(batch, camera)
|
if (currentScreen > 1f + epsilon) {
|
||||||
|
renderScreenMinimap(batch, camera)
|
||||||
|
|
||||||
|
if (debugvals) {
|
||||||
|
batch.color = Color.CORAL
|
||||||
|
AppLoader.fontSmallNumbers.draw(batch, "Map", 300f, 10f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentScreen in epsilon..2f - epsilon) {
|
||||||
|
renderScreenInventory(batch, camera)
|
||||||
|
|
||||||
|
if (debugvals) {
|
||||||
|
batch.color = Color.CHARTREUSE
|
||||||
|
AppLoader.fontSmallNumbers.draw(batch, "Inv", 350f, 10f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentScreen < 1f - epsilon) {
|
||||||
|
renderScreenGamemenu(batch, camera)
|
||||||
|
|
||||||
|
if (debugvals) {
|
||||||
|
batch.color = Color.SKY
|
||||||
|
AppLoader.fontSmallNumbers.draw(batch, "Men", 400f, 10f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (debugvals) {
|
||||||
|
batch.color = Color.WHITE
|
||||||
|
AppLoader.fontSmallNumbers.draw(batch, "inventoryScrOffX:$inventoryScrOffX", 500f, 10f)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val epsilon = 0.001f
|
||||||
|
|
||||||
private val minimapScrOffX: Float
|
private val minimapScrOffX: Float
|
||||||
get() = (currentScreen + 1f) * Terrarum.WIDTH
|
get() = (currentScreen - 2f) * Terrarum.WIDTH
|
||||||
|
/**
|
||||||
|
* - 0 on inventory screen
|
||||||
|
* - +WIDTH on minimap screen
|
||||||
|
* - -WIDTH on gamemenu screen
|
||||||
|
*/
|
||||||
private val inventoryScrOffX: Float
|
private val inventoryScrOffX: Float
|
||||||
get() = (currentScreen - 1f) * Terrarum.WIDTH
|
get() = (currentScreen - 1f) * Terrarum.WIDTH
|
||||||
private val menuScrOffX: Float
|
private val menuScrOffX: Float
|
||||||
get() = (currentScreen) * Terrarum.WIDTH
|
get() = (currentScreen) * Terrarum.WIDTH
|
||||||
|
|
||||||
|
private fun renderScreenMinimap(batch: SpriteBatch, camera: Camera) {
|
||||||
|
// control hints
|
||||||
|
blendNormal(batch)
|
||||||
|
batch.color = Color.WHITE
|
||||||
|
Terrarum.fontGame.draw(batch, minimapControlHelp, offsetX + minimapScrOffX, yEnd - 20)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun renderScreenGamemenu(batch: SpriteBatch, camera: Camera) {
|
||||||
|
// control hints
|
||||||
|
blendNormal(batch)
|
||||||
|
batch.color = Color.WHITE
|
||||||
|
Terrarum.fontGame.draw(batch, gameMenuControlHelp, offsetX + menuScrOffX, yEnd - 20)
|
||||||
|
|
||||||
|
// text buttons
|
||||||
|
gameMenuButtons.render(batch, camera)
|
||||||
|
|
||||||
|
// character info window
|
||||||
|
|
||||||
|
// !! DUMMY !!
|
||||||
|
batch.color = itemList.backColour
|
||||||
|
batch.fillRect(
|
||||||
|
((Terrarum.WIDTH - 400) / 2) + menuScrOffX,
|
||||||
|
(itemList.height - gameMenuListTotalHeight) / 2 + itemList.posY.toFloat(),
|
||||||
|
gameMenuListWidth.toFloat(),
|
||||||
|
64f
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun renderScreenInventory(batch: SpriteBatch, camera: Camera) {
|
private fun renderScreenInventory(batch: SpriteBatch, camera: Camera) {
|
||||||
itemList.render(batch, camera)
|
itemList.render(batch, camera)
|
||||||
equipped.render(batch, camera)
|
equipped.render(batch, camera)
|
||||||
|
|||||||
@@ -32,8 +32,14 @@ class UIItemInventoryDynamicList(
|
|||||||
override var posY: Int
|
override var posY: Int
|
||||||
) : UIItem(parentUI) {
|
) : UIItem(parentUI) {
|
||||||
|
|
||||||
override val width = 496
|
// deal with the moving position
|
||||||
override val height = 384
|
override var oldPosX = posX
|
||||||
|
override var oldPosY = posY
|
||||||
|
|
||||||
|
override val width = WIDTH
|
||||||
|
override val height = HEIGHT
|
||||||
|
|
||||||
|
val backColour = Color(0x404040_88)
|
||||||
|
|
||||||
private val catArrangement = parentUI.catArrangement
|
private val catArrangement = parentUI.catArrangement
|
||||||
|
|
||||||
@@ -94,7 +100,7 @@ class UIItemInventoryDynamicList(
|
|||||||
itemImage = null,
|
itemImage = null,
|
||||||
mouseoverBackCol = Color(0x282828_ff),
|
mouseoverBackCol = Color(0x282828_ff),
|
||||||
mouseoverBackBlendMode = BlendMode.SCREEN,
|
mouseoverBackBlendMode = BlendMode.SCREEN,
|
||||||
backCol = Color(0x404040_88),
|
backCol = backColour,
|
||||||
backBlendMode = BlendMode.NORMAL,
|
backBlendMode = BlendMode.NORMAL,
|
||||||
drawBackOnNull = true,
|
drawBackOnNull = true,
|
||||||
inactiveTextCol = defaultTextColour
|
inactiveTextCol = defaultTextColour
|
||||||
@@ -111,7 +117,7 @@ class UIItemInventoryDynamicList(
|
|||||||
itemImage = null,
|
itemImage = null,
|
||||||
mouseoverBackCol = Color(0x282828_ff),
|
mouseoverBackCol = Color(0x282828_ff),
|
||||||
mouseoverBackBlendMode = BlendMode.SCREEN,
|
mouseoverBackBlendMode = BlendMode.SCREEN,
|
||||||
backCol = Color(0x404040_88),
|
backCol = backColour,
|
||||||
backBlendMode = BlendMode.NORMAL,
|
backBlendMode = BlendMode.NORMAL,
|
||||||
drawBackOnNull = true,
|
drawBackOnNull = true,
|
||||||
inactiveTextCol = defaultTextColour
|
inactiveTextCol = defaultTextColour
|
||||||
@@ -165,9 +171,6 @@ class UIItemInventoryDynamicList(
|
|||||||
highlightable = false
|
highlightable = false
|
||||||
)
|
)
|
||||||
|
|
||||||
// deal with the moving position
|
|
||||||
private var oldPosX = posX
|
|
||||||
|
|
||||||
fun scrollItemPage(relativeAmount: Int) {
|
fun scrollItemPage(relativeAmount: Int) {
|
||||||
itemPage = if (itemPageCount == 0) 0 else (itemPage + relativeAmount).fmod(itemPageCount)
|
itemPage = if (itemPageCount == 0) 0 else (itemPage + relativeAmount).fmod(itemPageCount)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,8 @@ class UIItemInventoryEquippedView(
|
|||||||
private val spriteDrawCol = Color(0xddddddff.toInt())
|
private val spriteDrawCol = Color(0xddddddff.toInt())
|
||||||
|
|
||||||
// deal with the moving position
|
// deal with the moving position
|
||||||
private var oldPosX = posX
|
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
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ class UIItemModuleInfoCell(
|
|||||||
override var posY: Int
|
override var posY: Int
|
||||||
) : UIItem(parent) {
|
) : UIItem(parent) {
|
||||||
|
|
||||||
|
// deal with the moving position
|
||||||
|
override var oldPosX = posX
|
||||||
|
override var oldPosY = posY
|
||||||
|
|
||||||
override val height: Int = Terrarum.fontGame.lineHeight.toInt() * 2
|
override val height: Int = Terrarum.fontGame.lineHeight.toInt() * 2
|
||||||
|
|
||||||
private val numberAreaWidth = Terrarum.fontSmallNumbers.W * 3 + 4
|
private val numberAreaWidth = Terrarum.fontSmallNumbers.W * 3 + 4
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ class UIItemSavegameInfoCell(
|
|||||||
override var posY: Int
|
override var posY: Int
|
||||||
) : UIItem(parent) {
|
) : UIItem(parent) {
|
||||||
|
|
||||||
|
// deal with the moving position
|
||||||
|
override var oldPosX = posX
|
||||||
|
override var oldPosY = posY
|
||||||
|
|
||||||
override val height: Int = Terrarum.fontGame.lineHeight.toInt() * 2
|
override val height: Int = Terrarum.fontGame.lineHeight.toInt() * 2
|
||||||
|
|
||||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||||
|
|||||||
@@ -44,6 +44,25 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
|
|||||||
abstract val width: Int
|
abstract val width: Int
|
||||||
abstract val height: Int
|
abstract val height: Int
|
||||||
|
|
||||||
|
/** This variable is NOT updated on its own.
|
||||||
|
* ```
|
||||||
|
* val posXDelta = posX - oldPosX
|
||||||
|
* itemGrid.forEach { it.posX += posXDelta }
|
||||||
|
* ...
|
||||||
|
* oldPosX = posX
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
protected abstract var oldPosX: Int
|
||||||
|
/** This variable is NOT updated on its own.
|
||||||
|
* ```
|
||||||
|
* val posYDelta = posY - oldPosY
|
||||||
|
* itemGrid.forEach { it.posY += posYDelta }
|
||||||
|
* ...
|
||||||
|
* oldPosY = posY
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
protected abstract var oldPosY: Int
|
||||||
|
|
||||||
/** Position of mouse relative to this item */
|
/** Position of mouse relative to this item */
|
||||||
protected val relativeMouseX: Int
|
protected val relativeMouseX: Int
|
||||||
get() = (Terrarum.mouseScreenX - (parentUI.posX) - this.posX)
|
get() = (Terrarum.mouseScreenX - (parentUI.posX) - this.posX)
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ open class UIItemImageButton(
|
|||||||
var highlightable: Boolean
|
var highlightable: Boolean
|
||||||
) : UIItem(parent) {
|
) : UIItem(parent) {
|
||||||
|
|
||||||
|
// 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,6 +20,10 @@ class UIItemImageGallery(
|
|||||||
val column: Int = 1
|
val column: Int = 1
|
||||||
) : UIItem(parentUI) {
|
) : UIItem(parentUI) {
|
||||||
|
|
||||||
|
// deal with the moving position
|
||||||
|
override var oldPosX = posX
|
||||||
|
override var oldPosY = posY
|
||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,10 @@ class UIItemIntSlider(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
// deal with the moving position
|
||||||
|
override var oldPosX = posX
|
||||||
|
override var oldPosY = posY
|
||||||
|
|
||||||
var value = initValue
|
var value = initValue
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ class UIItemList<Item: UIItem>(
|
|||||||
val border: Int = 0
|
val border: Int = 0
|
||||||
) : UIItem(parentUI) {
|
) : UIItem(parentUI) {
|
||||||
|
|
||||||
|
// 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
|
||||||
@@ -47,7 +51,7 @@ class UIItemList<Item: UIItem>(
|
|||||||
var selectedIndex: Int? = defaultSelection
|
var selectedIndex: Int? = defaultSelection
|
||||||
val selectedButton: UIItem?
|
val selectedButton: UIItem?
|
||||||
get() = if (selectedIndex != null) itemList[selectedIndex!!] else null
|
get() = if (selectedIndex != null) itemList[selectedIndex!!] else null
|
||||||
private var highlightY: Double? = if (selectedIndex != null) itemList[selectedIndex!!].posY.toDouble() else null
|
private var highlightY: Float? = if (selectedIndex != null) itemList[selectedIndex!!].posY.toFloat() else null
|
||||||
private val highlighterMoveDuration: Second = 0.1f
|
private val highlighterMoveDuration: Second = 0.1f
|
||||||
private var highlighterMoveTimer: Second = 0f
|
private var highlighterMoveTimer: Second = 0f
|
||||||
private var highlighterMoving = false
|
private var highlighterMoving = false
|
||||||
@@ -66,8 +70,8 @@ class UIItemList<Item: UIItem>(
|
|||||||
highlightY = UIUtils.moveQuick(
|
highlightY = UIUtils.moveQuick(
|
||||||
highlighterYStart!!,
|
highlighterYStart!!,
|
||||||
highlighterYEnd!!,
|
highlighterYEnd!!,
|
||||||
highlighterMoveTimer.toDouble(),
|
highlighterMoveTimer,
|
||||||
highlighterMoveDuration.toDouble()
|
highlighterMoveDuration
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,14 +91,14 @@ class UIItemList<Item: UIItem>(
|
|||||||
val oldIndex = selectedIndex
|
val oldIndex = selectedIndex
|
||||||
|
|
||||||
if (kinematic) {
|
if (kinematic) {
|
||||||
highlighterYStart = itemList[selectedIndex!!].posY.toDouble()
|
highlighterYStart = itemList[selectedIndex!!].posY.toFloat()
|
||||||
selectedIndex = index
|
selectedIndex = index
|
||||||
highlighterMoving = true
|
highlighterMoving = true
|
||||||
highlighterYEnd = itemList[selectedIndex!!].posY.toDouble()
|
highlighterYEnd = itemList[selectedIndex!!].posY.toFloat()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
selectedIndex = index
|
selectedIndex = index
|
||||||
highlightY = itemList[selectedIndex!!].posY.toDouble()
|
highlightY = itemList[selectedIndex!!].posY.toFloat()
|
||||||
}
|
}
|
||||||
|
|
||||||
selectionChangeListener?.invoke(oldIndex, index)
|
selectionChangeListener?.invoke(oldIndex, index)
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ class UIItemTextArea(
|
|||||||
val align: Alignment = Alignment.LEFT
|
val align: Alignment = Alignment.LEFT
|
||||||
) : UIItem(parentUI) {
|
) : UIItem(parentUI) {
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
package net.torvald.terrarum.ui
|
package net.torvald.terrarum.ui
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Camera
|
import com.badlogic.gdx.graphics.Camera
|
||||||
import net.torvald.terrarum.*
|
|
||||||
import net.torvald.terrarum.langpack.Lang
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout
|
import com.badlogic.gdx.graphics.g2d.GlyphLayout
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
|
import net.torvald.terrarum.BlendMode
|
||||||
|
import net.torvald.terrarum.Terrarum
|
||||||
|
import net.torvald.terrarum.blendNormal
|
||||||
|
import net.torvald.terrarum.fillRect
|
||||||
|
import net.torvald.terrarum.langpack.Lang
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Text button. Height of hitbox is extended (double lineHeight, or 40 px) for better clicking
|
* Text button. Height of hitbox is extended (double lineHeight, or 40 px) for better clicking
|
||||||
@@ -34,6 +37,10 @@ open class UIItemTextButton(
|
|||||||
val hitboxSize: Int = UIItemTextButton.height
|
val hitboxSize: Int = UIItemTextButton.height
|
||||||
) : UIItem(parentUI) {
|
) : UIItem(parentUI) {
|
||||||
|
|
||||||
|
// deal with the moving position
|
||||||
|
override var oldPosX = posX
|
||||||
|
override var oldPosY = posY
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val font = Terrarum.fontGame
|
val font = Terrarum.fontGame
|
||||||
val height = font.lineHeight.toInt()
|
val height = font.lineHeight.toInt()
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ 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 net.torvald.terrarum.BlendMode
|
import net.torvald.terrarum.BlendMode
|
||||||
import net.torvald.terrarum.fillRect
|
|
||||||
import net.torvald.terrarum.Second
|
import net.torvald.terrarum.Second
|
||||||
|
import net.torvald.terrarum.fillRect
|
||||||
import net.torvald.terrarum.gameactors.ai.toInt
|
import net.torvald.terrarum.gameactors.ai.toInt
|
||||||
import net.torvald.terrarum.roundInt
|
import net.torvald.terrarum.roundInt
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
@@ -45,6 +45,10 @@ class UIItemTextButtonList(
|
|||||||
val itemHitboxSize: Int = UIItemTextButton.height
|
val itemHitboxSize: Int = UIItemTextButton.height
|
||||||
) : UIItem(parentUI) {
|
) : UIItem(parentUI) {
|
||||||
|
|
||||||
|
// 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)
|
||||||
@@ -130,7 +134,7 @@ class UIItemTextButtonList(
|
|||||||
var selectedIndex: Int? = defaultSelection
|
var selectedIndex: Int? = defaultSelection
|
||||||
val selectedButton: UIItemTextButton?
|
val selectedButton: UIItemTextButton?
|
||||||
get() = if (selectedIndex != null) buttons[selectedIndex!!] else null
|
get() = if (selectedIndex != null) buttons[selectedIndex!!] else null
|
||||||
private var highlightY: Double? = if (selectedIndex != null) buttons[selectedIndex!!].posY.toDouble() else null
|
private var highlightY: Float? = if (selectedIndex != null) buttons[selectedIndex!!].posY.toFloat() else null
|
||||||
private val highlighterMoveDuration: Second = 0.1f
|
private val highlighterMoveDuration: Second = 0.1f
|
||||||
private var highlighterMoveTimer: Second = 0f
|
private var highlighterMoveTimer: Second = 0f
|
||||||
private var highlighterMoving = false
|
private var highlighterMoving = false
|
||||||
@@ -141,6 +145,10 @@ class UIItemTextButtonList(
|
|||||||
var selectionChangeListener: ((Int?, Int) -> Unit)? = null
|
var selectionChangeListener: ((Int?, Int) -> Unit)? = null
|
||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
|
val posXDelta = posX - oldPosX
|
||||||
|
buttons.forEach { it.posX += posXDelta }
|
||||||
|
|
||||||
|
|
||||||
if (highlighterMoving) {
|
if (highlighterMoving) {
|
||||||
highlighterMoveTimer += delta
|
highlighterMoveTimer += delta
|
||||||
|
|
||||||
@@ -148,8 +156,8 @@ class UIItemTextButtonList(
|
|||||||
highlightY = UIUtils.moveQuick(
|
highlightY = UIUtils.moveQuick(
|
||||||
highlighterYStart!!,
|
highlighterYStart!!,
|
||||||
highlighterYEnd!!,
|
highlighterYEnd!!,
|
||||||
highlighterMoveTimer.toDouble(),
|
highlighterMoveTimer.toFloat(),
|
||||||
highlighterMoveDuration.toDouble()
|
highlighterMoveDuration.toFloat()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,13 +178,13 @@ class UIItemTextButtonList(
|
|||||||
|
|
||||||
if (kinematic) {
|
if (kinematic) {
|
||||||
selectedIndex = index
|
selectedIndex = index
|
||||||
highlighterYStart = buttons[selectedIndex!!].posY.toDouble()
|
highlighterYStart = buttons[selectedIndex!!].posY.toFloat()
|
||||||
highlighterMoving = true
|
highlighterMoving = true
|
||||||
highlighterYEnd = buttons[selectedIndex!!].posY.toDouble()
|
highlighterYEnd = buttons[selectedIndex!!].posY.toFloat()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
selectedIndex = index
|
selectedIndex = index
|
||||||
highlightY = buttons[selectedIndex!!].posY.toDouble()
|
highlightY = buttons[selectedIndex!!].posY.toFloat()
|
||||||
}
|
}
|
||||||
|
|
||||||
selectionChangeListener?.invoke(oldIndex, index)
|
selectionChangeListener?.invoke(oldIndex, index)
|
||||||
@@ -184,6 +192,8 @@ class UIItemTextButtonList(
|
|||||||
btn.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null
|
btn.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oldPosX = posX
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||||
|
|||||||
@@ -6,6 +6,6 @@ import net.torvald.terrarum.sqr
|
|||||||
* Created by minjaesong on 2017-03-14.
|
* Created by minjaesong on 2017-03-14.
|
||||||
*/
|
*/
|
||||||
object UIUtils {
|
object UIUtils {
|
||||||
fun moveQuick(start: Double, end: Double, timer: Double, duration: Double) =
|
fun moveQuick(start: Float, end: Float, timer: Float, duration: Float) =
|
||||||
(start - end) * ((timer / duration) - 1).sqr() + end
|
(start - end) * ((timer / duration) - 1).sqr() + end
|
||||||
}
|
}
|
||||||
Binary file not shown.
Reference in New Issue
Block a user