mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
encumb bar extracted to separate function
This commit is contained in:
@@ -5,7 +5,6 @@ import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.*
|
||||
import net.torvald.terrarum.ui.UIItemCatBar.Companion.CAT_ALL
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
@@ -20,8 +19,6 @@ import net.torvald.terrarum.ui.*
|
||||
import net.torvald.terrarum.ui.UIItemCatBar.Companion.FILTER_CAT_ALL
|
||||
import net.torvald.unicode.getKeycapPC
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
* This UI has inventory, but it's just there to display all craftable items and should not be serialised.
|
||||
@@ -461,47 +458,9 @@ class UICrafting(val full: UIInventoryFull?) : UICanvas(
|
||||
|
||||
if (full != null) {
|
||||
//draw player encumb
|
||||
// encumbrance meter
|
||||
val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"]
|
||||
// encumbrance bar will go one row down if control help message is too long
|
||||
val encumbBarXPos = thisXend - UIInventoryCells.weightBarWidth + 36
|
||||
val encumbBarTextXPos = encumbBarXPos - 6 - App.fontGame.getWidth(encumbranceText)
|
||||
val encumbBarYPos = UIInventoryFull.yEnd - 20 + 3f +
|
||||
if (App.fontGame.getWidth(full.listControlHelp) + 2 + controlHintXPos >= encumbBarTextXPos)
|
||||
App.fontGame.lineHeight
|
||||
else 0f
|
||||
App.fontGame.draw(batch, encumbranceText, encumbBarTextXPos, encumbBarYPos - 3f)
|
||||
// encumbrance bar background
|
||||
blendNormalStraightAlpha(batch)
|
||||
val encumbCol = UIItemInventoryCellCommonRes.getHealthMeterColour(1f - encumbrancePerc, 0f, 1f)
|
||||
val encumbBack = encumbCol mul UIItemInventoryCellCommonRes.meterBackDarkening
|
||||
batch.color = encumbBack
|
||||
Toolkit.fillArea(
|
||||
batch,
|
||||
encumbBarXPos, encumbBarYPos,
|
||||
UIInventoryCells.weightBarWidth, UIInventoryFull.controlHelpHeight - 6f
|
||||
)
|
||||
// encumbrance bar
|
||||
batch.color = encumbCol
|
||||
Toolkit.fillArea(
|
||||
batch,
|
||||
encumbBarXPos, encumbBarYPos,
|
||||
if (full.actor.inventory.capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
|
||||
1f
|
||||
else // make sure 1px is always be seen
|
||||
min(UIInventoryCells.weightBarWidth, max(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
|
||||
UIInventoryFull.controlHelpHeight - 6f
|
||||
)
|
||||
// debug text
|
||||
batch.color = Color.LIGHT_GRAY
|
||||
if (App.IS_DEVELOPMENT_BUILD) {
|
||||
App.fontSmallNumbers.draw(
|
||||
batch,
|
||||
"${full.actor.inventory.capacity}/${full.actor.inventory.maxCapacity}",
|
||||
encumbBarTextXPos,
|
||||
encumbBarYPos + UIInventoryFull.controlHelpHeight - 4f
|
||||
)
|
||||
}
|
||||
val encumbBarYPos = UIInventoryFull.yEnd - 20 + 3f
|
||||
UIInventoryCells.drawEncumbranceBar(batch, encumbBarXPos, encumbBarYPos, encumbrancePerc, full.actor.inventory)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELLS_HOR
|
||||
@@ -33,6 +34,49 @@ internal class UIInventoryCells(
|
||||
companion object {
|
||||
val weightBarWidth = UIItemInventoryElemSimple.height * 2f + UIItemInventoryItemGrid.listGap
|
||||
// var encumbBarYPos = (App.scr.height + internalHeight).div(2) - 20 + 3f
|
||||
|
||||
fun drawEncumbranceBar(batch: SpriteBatch, encumbBarXPos: Float, encumbBarYPos: Float, encumbrancePerc: Float, actorInventory: FixtureInventory) {
|
||||
//draw player encumb
|
||||
// encumbrance meter
|
||||
val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"]
|
||||
// encumbrance bar will go one row down if control help message is too long
|
||||
val encumbBarTextXPos = encumbBarXPos - 6 - App.fontGame.getWidth(encumbranceText)
|
||||
App.fontGame.draw(batch, encumbranceText, encumbBarTextXPos, encumbBarYPos - 3f)
|
||||
// encumbrance bar fracme
|
||||
batch.color = Toolkit.Theme.COL_INVENTORY_CELL_BORDER
|
||||
Toolkit.drawBoxBorder(batch, encumbBarXPos, encumbBarYPos, UIInventoryCells.weightBarWidth, UIInventoryFull.controlHelpHeight - 6f)
|
||||
// encumbrance bar background
|
||||
blendNormalStraightAlpha(batch)
|
||||
val encumbCol = UIItemInventoryCellCommonRes.getHealthMeterColour(1f - encumbrancePerc, 0f, 1f)
|
||||
val encumbBack = encumbCol mul UIItemInventoryCellCommonRes.meterBackDarkening
|
||||
batch.color = encumbBack
|
||||
Toolkit.fillArea(
|
||||
batch,
|
||||
encumbBarXPos, encumbBarYPos,
|
||||
UIInventoryCells.weightBarWidth, UIInventoryFull.controlHelpHeight - 6f
|
||||
)
|
||||
// encumbrance bar
|
||||
batch.color = encumbCol
|
||||
Toolkit.fillArea(
|
||||
batch,
|
||||
encumbBarXPos, encumbBarYPos,
|
||||
if (actorInventory.capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
|
||||
1f
|
||||
else // make sure 1px is always be seen
|
||||
min(UIInventoryCells.weightBarWidth, max(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
|
||||
UIInventoryFull.controlHelpHeight - 6f
|
||||
)
|
||||
// debug text
|
||||
batch.color = Color.LIGHT_GRAY
|
||||
if (App.IS_DEVELOPMENT_BUILD) {
|
||||
App.fontSmallNumbers.draw(
|
||||
batch,
|
||||
"${actorInventory.capacity}/${actorInventory.maxCapacity}",
|
||||
encumbBarTextXPos,
|
||||
encumbBarYPos + UIInventoryFull.controlHelpHeight - 4f
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal var encumbrancePerc = 0f
|
||||
@@ -122,46 +166,10 @@ internal class UIInventoryCells(
|
||||
|
||||
|
||||
// encumbrance meter
|
||||
val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"]
|
||||
// encumbrance bar will go one row down if control help message is too long
|
||||
val encumbBarXPos = UIInventoryFull.xEnd - weightBarWidth
|
||||
val encumbBarTextXPos = encumbBarXPos - 6 - App.fontGame.getWidth(encumbranceText)
|
||||
val encumbBarYPos = UIInventoryFull.yEnd-20 + 3f +
|
||||
if (App.fontGame.getWidth(full.listControlHelp) + 2 + controlHintXPos >= encumbBarTextXPos)
|
||||
App.fontGame.lineHeight
|
||||
else 0f
|
||||
// Companion.encumbBarYPos = encumbBarYPos // q&d hack to share some numbers
|
||||
val encumbBarYPos = UIInventoryFull.yEnd-20 + 3f
|
||||
|
||||
App.fontGame.draw(batch, encumbranceText, encumbBarTextXPos, encumbBarYPos - 3f)
|
||||
|
||||
// encumbrance bar background
|
||||
blendNormalStraightAlpha(batch)
|
||||
val encumbCol = UIItemInventoryCellCommonRes.getHealthMeterColour(1f - encumbrancePerc, 0f, 1f)
|
||||
val encumbBack = encumbCol mul UIItemInventoryCellCommonRes.meterBackDarkening
|
||||
batch.color = encumbBack
|
||||
Toolkit.fillArea(batch,
|
||||
encumbBarXPos, encumbBarYPos,
|
||||
weightBarWidth, controlHelpHeight - 6f
|
||||
)
|
||||
// encumbrance bar
|
||||
batch.color = encumbCol
|
||||
Toolkit.fillArea(batch,
|
||||
encumbBarXPos, encumbBarYPos,
|
||||
if (full.actor.inventory.capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
|
||||
1f
|
||||
else // make sure 1px is always be seen
|
||||
min(weightBarWidth, max(1f, weightBarWidth * encumbrancePerc)),
|
||||
controlHelpHeight - 6f
|
||||
)
|
||||
// debug text
|
||||
batch.color = Color.LIGHT_GRAY
|
||||
if (App.IS_DEVELOPMENT_BUILD) {
|
||||
App.fontSmallNumbers.draw(batch,
|
||||
"enc: ${full.actor.inventory.encumberment}",
|
||||
encumbBarTextXPos,
|
||||
encumbBarYPos + controlHelpHeight - 4f
|
||||
)
|
||||
}
|
||||
UIInventoryCells.drawEncumbranceBar(batch, encumbBarXPos, encumbBarYPos, encumbrancePerc, full.actor.inventory)
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
|
||||
@@ -210,36 +210,13 @@ internal class UIStorageChest : UICanvas(
|
||||
blendNormalStraightAlpha(batch)
|
||||
|
||||
// encumbrance meter
|
||||
val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"]
|
||||
val chestName = chestNameFun()
|
||||
val playerName = INGAME.actorNowPlaying!!.actorValue.getAsString(AVKey.NAME).orEmpty().let { it.ifBlank { Lang["GAME_INVENTORY"] } }
|
||||
val encumbBarXPos = itemListPlayer.posX + itemListPlayer.width - UIInventoryCells.weightBarWidth + 36
|
||||
val encumbBarTextXPos = encumbBarXPos - 6 - App.fontGame.getWidth(encumbranceText)
|
||||
val yEnd = -UIInventoryFull.YPOS_CORRECTION + (App.scr.height + UIInventoryFull.internalHeight).div(2).toFloat() // directly copied from UIInventoryFull.yEnd
|
||||
val encumbBarYPos = yEnd - 20 + 3 // dunno why but extra 3 px is needed
|
||||
val encumbCol = UIItemInventoryCellCommonRes.getHealthMeterColour(1f - encumbrancePerc, 0f, 1f)
|
||||
val encumbBack = encumbCol mul UIItemInventoryCellCommonRes.meterBackDarkening
|
||||
|
||||
// encumbrance bar background
|
||||
batch.color = encumbBack
|
||||
Toolkit.fillArea(
|
||||
batch,
|
||||
encumbBarXPos,
|
||||
encumbBarYPos,
|
||||
UIInventoryCells.weightBarWidth,
|
||||
UIInventoryFull.controlHelpHeight - 6f
|
||||
)
|
||||
// encumbrance bar
|
||||
batch.color = encumbCol
|
||||
Toolkit.fillArea(
|
||||
batch,
|
||||
encumbBarXPos, encumbBarYPos,
|
||||
if (getPlayerInventory().capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
|
||||
1f
|
||||
else // make sure 1px is always be seen
|
||||
min(UIInventoryCells.weightBarWidth, max(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
|
||||
UIInventoryFull.controlHelpHeight - 6f
|
||||
)
|
||||
UIInventoryCells.drawEncumbranceBar(batch, encumbBarXPos, encumbBarYPos, encumbrancePerc, getPlayerInventory())
|
||||
|
||||
// chest name text
|
||||
batch.color = Color.WHITE
|
||||
@@ -249,9 +226,7 @@ internal class UIStorageChest : UICanvas(
|
||||
// control hint
|
||||
App.fontGame.draw(batch, controlHelp, thisOffsetX - 34f, encumbBarYPos - 3)
|
||||
|
||||
// encumb text
|
||||
batch.color = Color.WHITE
|
||||
App.fontGame.draw(batch, encumbranceText, encumbBarTextXPos, encumbBarYPos - 3f)
|
||||
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
|
||||
@@ -213,36 +213,11 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
|
||||
blendNormalStraightAlpha(batch)
|
||||
|
||||
// encumbrance meter
|
||||
val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"]
|
||||
val chestName = chestNameFun()
|
||||
val playerName = INGAME.actorNowPlaying!!.actorValue.getAsString(AVKey.NAME).orEmpty().let { it.ifBlank { Lang["GAME_INVENTORY"] } }
|
||||
val encumbBarXPos = itemListPlayer.posX + itemListPlayer.width - UIInventoryCells.weightBarWidth + 36
|
||||
val encumbBarTextXPos = encumbBarXPos - 6 - App.fontGame.getWidth(encumbranceText)
|
||||
val yEnd = -UIInventoryFull.YPOS_CORRECTION + (App.scr.height + UIInventoryFull.internalHeight).div(2).toFloat() // directly copied from UIInventoryFull.yEnd
|
||||
val encumbBarYPos = yEnd - 20 + 3 // dunno why but extra 3 px is needed
|
||||
val encumbCol = UIItemInventoryCellCommonRes.getHealthMeterColour(1f - encumbrancePerc, 0f, 1f)
|
||||
val encumbBack = encumbCol mul UIItemInventoryCellCommonRes.meterBackDarkening
|
||||
|
||||
// encumbrance bar background
|
||||
batch.color = encumbBack
|
||||
Toolkit.fillArea(
|
||||
batch,
|
||||
encumbBarXPos,
|
||||
encumbBarYPos,
|
||||
UIInventoryCells.weightBarWidth,
|
||||
UIInventoryFull.controlHelpHeight - 6f
|
||||
)
|
||||
// encumbrance bar
|
||||
batch.color = encumbCol
|
||||
Toolkit.fillArea(
|
||||
batch,
|
||||
encumbBarXPos, encumbBarYPos,
|
||||
if (getPlayerInventory().capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
|
||||
1f
|
||||
else // make sure 1px is always be seen
|
||||
min(UIInventoryCells.weightBarWidth, max(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
|
||||
UIInventoryFull.controlHelpHeight - 6f
|
||||
)
|
||||
|
||||
// chest name text
|
||||
batch.color = Color.WHITE
|
||||
@@ -252,9 +227,7 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
|
||||
// control hint
|
||||
App.fontGame.draw(batch, controlHelp, thisOffsetX - 34f, encumbBarYPos - 3)
|
||||
|
||||
// encumb text
|
||||
batch.color = Color.WHITE
|
||||
App.fontGame.draw(batch, encumbranceText, encumbBarTextXPos, encumbBarYPos - 3f)
|
||||
UIInventoryCells.drawEncumbranceBar(batch, encumbBarXPos, encumbBarYPos, encumbrancePerc, getPlayerInventory())
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
|
||||
Reference in New Issue
Block a user