inventory item count is now Long; should not interfere with the existing savegame

This commit is contained in:
minjaesong
2022-02-11 09:33:50 +09:00
parent 97d3edf1b9
commit 5c94e88d76
14 changed files with 67 additions and 60 deletions

View File

@@ -11,7 +11,7 @@ abstract class InventoryNegotiator {
/** Retrieve item filter to be used to show only the acceptable items when player's own inventory is being displayed */
open fun getItemFilter(): List<String> = listOf(CAT_ALL) // GameItem.Category
/** Accepts item from the player and pass it to right inventory (object), slot (UI), etc... */
abstract fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Int = 1)
abstract fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Long = 1L)
/** Rejects item and perhaps returns it back to the player, or make explosion, etc... */
abstract fun reject(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Int = 1)
abstract fun reject(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Long = 1L)
}

View File

@@ -10,6 +10,7 @@ import net.torvald.terrarum.abs
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem
import kotlin.math.absoluteValue
import kotlin.math.roundToInt
/**
@@ -22,12 +23,12 @@ abstract class UIItemInventoryCellBase(
initialX: Int,
initialY: Int,
open var item: GameItem?,
open var amount: Int,
open var amount: Long,
open var itemImage: TextureRegion?,
open var quickslot: Int? = null,
open var equippedSlot: Int? = null,
val keyDownFun: (GameItem?, Int, Int) -> Unit,
val touchDownFun: (GameItem?, Int, Int) -> Unit
val keyDownFun: (GameItem?, Long, Int) -> Unit, // Item, Amount, Keycode
val touchDownFun: (GameItem?, Long, Int) -> Unit // Item, Amount, Button
) : UIItem(parentUI, initialX, initialY) {
abstract override fun update(delta: Float)
abstract override fun render(batch: SpriteBatch, camera: Camera)
@@ -64,7 +65,7 @@ object UIItemInventoryCellCommonRes {
fun getHealthMeterColour(value: Int, start: Int, end: Int) = getHealthMeterColour(value.toFloat(), start.toFloat(), end.toFloat())
fun Int.toItemCountText() = (if (this < 0) "-" else "") + when (this.abs()) {
fun Long.toItemCountText() = (if (this < 0) "-" else "") + when (this.absoluteValue) {
in 0..999999 -> "$this"
in 1_000_000..999_999_999 -> "${this / 1_000_000}.${this.rem(1_000_000) / 10_000}M"
else -> "${this / 1_000_000_000}.${this.rem(1_000_000_000) / 10_000_000}B"

View File

@@ -8,6 +8,8 @@ import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.itemListHeight
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericKeyDownFun
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericTouchDownFun
import net.torvald.terrarum.spriteassembler.ADProperties.Companion.EXTRA_HEADROOM_X
import net.torvald.terrarum.spriteassembler.ADProperties.Companion.EXTRA_HEADROOM_Y
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem
@@ -85,8 +87,8 @@ class UIItemInventoryEquippedView(
batch.color = SPRITE_DRAW_COL
batch.draw(
it.textureRegion.get(0, 0),
posX + (width - it.cellWidth).div(2).toFloat(),
posY + (width - it.cellHeight).div(2).toFloat()
posX + (width - it.cellWidth + EXTRA_HEADROOM_X).div(2).toFloat(),
posY + (width - it.cellHeight - EXTRA_HEADROOM_Y).div(2).toFloat()
)
}

View File

@@ -42,8 +42,8 @@ class UIItemInventoryItemGrid(
val verticalCells: Int,
val drawScrollOnRightside: Boolean = false,
val drawWallet: Boolean = true,
keyDownFun: (GameItem?, Int, Int) -> Unit,
touchDownFun: (GameItem?, Int, Int) -> Unit
keyDownFun: (GameItem?, Long, Int) -> Unit, // Item, Amount, Keycode
touchDownFun: (GameItem?, Long, Int) -> Unit // Item, Amount, Button
) : UIItem(parentUI, initialX, initialY) {
// deal with the moving position
@@ -99,8 +99,8 @@ class UIItemInventoryItemGrid(
fun getEstimatedW(horizontalCells: Int) = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
fun getEstimatedH(verticalCells: Int) = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
fun createInvCellGenericKeyDownFun(): (GameItem?, Int, Int) -> Unit {
return { item: GameItem?, amount: Int, keycode: Int ->
fun createInvCellGenericKeyDownFun(): (GameItem?, Long, Int) -> Unit {
return { item: GameItem?, amount: Long, keycode: Int ->
if (item != null && Terrarum.ingame != null && keycode in Input.Keys.NUM_0..Input.Keys.NUM_9) {
val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player != null) {
@@ -129,8 +129,8 @@ class UIItemInventoryItemGrid(
}
}
fun createInvCellGenericTouchDownFun(listRebuildFun: () -> Unit): (GameItem?, Int, Int) -> Unit {
return { item: GameItem?, amount: Int, button: Int ->
fun createInvCellGenericTouchDownFun(listRebuildFun: () -> Unit): (GameItem?, Long, Int) -> Unit {
return { item: GameItem?, amount: Long, button: Int ->
if (item != null && Terrarum.ingame != null) {
// equip da shit
val itemEquipSlot = item.equipPosition