fixed a bug where storagechest would not show anything on the item slot; changed inventory UI so that it would sync with the Toolkit.Theme

This commit is contained in:
minjaesong
2021-10-29 15:00:16 +09:00
parent 8dd4248f67
commit 27ddb76df7
14 changed files with 275 additions and 290 deletions

View File

@@ -34,6 +34,7 @@ import net.torvald.terrarum.modulebasegame.worldgenerator.WorldgenParams
import net.torvald.terrarum.realestate.LandUtil
import net.torvald.terrarum.savegame.DiskSkimmer
import net.torvald.terrarum.savegame.VDUtil
import net.torvald.terrarum.savegame.VirtualDisk
import net.torvald.terrarum.serialise.Common
import net.torvald.terrarum.serialise.LoadSavegame
import net.torvald.terrarum.serialise.ReadActor
@@ -259,7 +260,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
}
data class Codices(
val disk: DiskSkimmer, // WORLD disk
val disk: VirtualDisk, // WORLD disk
val world: GameWorld,
// val meta: WriteMeta.WorldMeta,
// val block: BlockCodex,
@@ -349,7 +350,9 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
actorNowPlaying = codices.player
actorGamer = codices.player
makeSavegameBackupCopy() // don't put it on the postInit() or render(); postInitForNewGame calls this function on the savegamewriter's callback
// don't put it on the postInit() or render(); postInitForNewGame calls this function on the savegamewriter's callback
makeSavegameBackupCopy(getWorldSaveFiledesc(worldSavefileName))
makeSavegameBackupCopy(getPlayerSaveFiledesc(playerSavefileName))
}
private fun postInitForNewGame() {

View File

@@ -43,21 +43,21 @@ open class FixtureInventory() {
}
open fun add(item: GameItem, count: Int = 1) {
println("[ActorInventory] add-by-elem $item, $count")
// println("[ActorInventory] add-by-elem $item, $count")
// other invalid values
if (count == 0)
throw IllegalArgumentException("Item count is zero.")
throw IllegalArgumentException("[${this.javaClass.canonicalName}] Item count is zero.")
if (count < 0)
throw IllegalArgumentException("Item count is negative number. If you intended removing items, use remove()\n" +
"These commands are NOT INTERCHANGEABLE; they handle things differently according to the context.")
if (item.originalID == "actor:${Terrarum.PLAYER_REF_ID}" || item.originalID == ("actor:${0x51621D}")) // do not delete this magic
throw IllegalArgumentException("Attempted to put human player into the inventory.")
if (((Terrarum.ingame as? TerrarumIngame)?.gameFullyLoaded ?: false) &&
throw IllegalArgumentException("[${this.javaClass.canonicalName}] Attempted to put human player into the inventory.")
if (((Terrarum.ingame as? TerrarumIngame)?.gameFullyLoaded == true) &&
(item.originalID == "actor:${(Terrarum.ingame as? TerrarumIngame)?.actorNowPlaying?.referenceID}"))
throw IllegalArgumentException("Attempted to put active player into the inventory.")
throw IllegalArgumentException("[${this.javaClass.canonicalName}] Attempted to put active player into the inventory.")
if ((!item.stackable || item.dynamicID.startsWith("dyn:")) && count > 1)
throw IllegalArgumentException("Attempting to adding stack of item but the item is not stackable; item: $item, count: $count")
throw IllegalArgumentException("[${this.javaClass.canonicalName}] Attempted to adding stack of item but the item is not stackable; item: $item, count: $count")
@@ -89,9 +89,9 @@ open class FixtureInventory() {
println("[ActorInventory] remove $item, $count")
if (count == 0)
throw IllegalArgumentException("Item count is zero.")
throw IllegalArgumentException("[${this.javaClass.canonicalName}] Item count is zero.")
if (count < 0)
throw IllegalArgumentException("Item count is negative number. If you intended adding items, use add()" +
throw IllegalArgumentException("[${this.javaClass.canonicalName}] Item count is negative number. If you intended adding items, use add()" +
"These commands are NOT INTERCHANGEABLE; they handle things differently according to the context.")
@@ -101,7 +101,7 @@ open class FixtureInventory() {
val newCount = existingItem.qty - count
if (newCount < 0) {
throw Error("Tried to remove $count of $item, but the inventory only contains ${existingItem.qty} of them.")
throw Error("[${this.javaClass.canonicalName}] Tried to remove $count of $item, but the inventory only contains ${existingItem.qty} of them.")
}
else if (newCount > 0) {
// decrement count
@@ -115,7 +115,7 @@ open class FixtureInventory() {
}
}
else {
throw Error("Tried to remove $item, but the inventory does not have it.")
throw Error("[${this.javaClass.canonicalName}] Tried to remove $item, but the inventory does not have it.")
}
}

View File

@@ -103,7 +103,73 @@ internal class UIStorageChest : UICanvas(
private var halfSlotOffset = (UIItemInventoryElemSimple.height + listGap) / 2
private var initialised = false
init {
catBar = UIItemInventoryCatBar(
this,
(App.scr.width - catBarWidth) / 2,
42 + (App.scr.height - internalHeight) / 2,
internalWidth,
catBarWidth,
false
)
catBar.selectionChangeListener = { old, new -> itemListUpdate() }
itemListChest = UIItemInventoryItemGrid(
this,
catBar,
{ getFixtureInventory() },
INVENTORY_CELLS_OFFSET_X() - halfSlotOffset,
INVENTORY_CELLS_OFFSET_Y(),
6, CELLS_VRT,
drawScrollOnRightside = false,
drawWallet = false,
keyDownFun = { _, _, _ -> Unit },
touchDownFun = { gameItem, amount, _ ->
if (gameItem != null) {
negotiator.reject(getFixtureInventory(), getPlayerInventory(), gameItem, amount)
}
itemListUpdate()
}
)
// make grid mode buttons work together
itemListChest.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) }
itemListChest.gridModeButtons[1].touchDownListener = { _,_,_,_ -> setCompact(true) }
itemListPlayer = UIItemInventoryItemGrid(
this,
catBar,
{ INGAME.actorNowPlaying!!.inventory }, // literally a player's inventory
INVENTORY_CELLS_OFFSET_X() - halfSlotOffset + (listGap + UIItemInventoryElemWide.height) * 7,
INVENTORY_CELLS_OFFSET_Y(),
6, CELLS_VRT,
drawScrollOnRightside = true,
drawWallet = false,
keyDownFun = { _, _, _ -> Unit },
touchDownFun = { gameItem, amount, _ ->
if (gameItem != null) {
negotiator.accept(getPlayerInventory(), getFixtureInventory(), gameItem, amount)
}
itemListUpdate()
}
)
itemListPlayer.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) }
itemListPlayer.gridModeButtons[1].touchDownListener = { _,_,_,_ -> setCompact(true) }
handler.allowESCtoClose = true
addUIitem(catBar)
addUIitem(itemListChest)
addUIitem(itemListPlayer)
}
private var openingClickLatched = false
override fun show() {
itemListPlayer.getInventory = { INGAME.actorNowPlaying!!.inventory }
itemListUpdate()
openingClickLatched = Terrarum.mouseDown
}
private fun itemListUpdate() {
itemListChest.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
@@ -129,72 +195,19 @@ internal class UIStorageChest : UICanvas(
itemListUpdate()
}
override fun updateUI(delta: Float) {
if (!initialised) {
initialised = true
catBar = UIItemInventoryCatBar(
this,
(App.scr.width - catBarWidth) / 2,
42 + (App.scr.height - internalHeight) / 2,
internalWidth,
catBarWidth,
false
)
catBar.selectionChangeListener = { old, new -> itemListUpdate() }
itemListChest = UIItemInventoryItemGrid(
this,
catBar,
{ getFixtureInventory() },
INVENTORY_CELLS_OFFSET_X() - halfSlotOffset,
INVENTORY_CELLS_OFFSET_Y(),
6, CELLS_VRT,
drawScrollOnRightside = false,
drawWallet = false,
keyDownFun = { _, _, _ -> Unit },
touchDownFun = { gameItem, amount, _ ->
if (gameItem != null) {
negotiator.reject(getFixtureInventory(), getPlayerInventory(), gameItem, amount)
}
itemListUpdate()
}
)
itemListPlayer = UIItemInventoryItemGrid(
this,
catBar,
{ INGAME.actorNowPlaying!!.inventory }, // literally a player's inventory
INVENTORY_CELLS_OFFSET_X() - halfSlotOffset + (listGap + UIItemInventoryElemWide.height) * 7,
INVENTORY_CELLS_OFFSET_Y(),
6, CELLS_VRT,
drawScrollOnRightside = true,
drawWallet = false,
keyDownFun = { _, _, _ -> Unit },
touchDownFun = { gameItem, amount, _ ->
if (gameItem != null) {
negotiator.accept(getPlayerInventory(), getFixtureInventory(), gameItem, amount)
}
itemListUpdate()
}
)
handler.allowESCtoClose = true
// make grid mode buttons work together
itemListChest.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) }
itemListChest.gridModeButtons[1].touchDownListener = { _,_,_,_ -> setCompact(true) }
itemListPlayer.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) }
itemListPlayer.gridModeButtons[1].touchDownListener = { _,_,_,_ -> setCompact(true) }
addUIitem(catBar)
addUIitem(itemListChest)
addUIitem(itemListPlayer)
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (!openingClickLatched) {
return super.touchDown(screenX, screenY, pointer, button)
}
return false
}
override fun updateUI(delta: Float) {
catBar.update(delta)
itemListChest.update(delta)
itemListPlayer.update(delta)
if (openingClickLatched && !Terrarum.mouseDown) openingClickLatched = false
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {

View File

@@ -212,6 +212,7 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
}
override fun endOpening(delta: Float) {
INGAME.setTooltipMessage(null)
}
override fun endClosing(delta: Float) {

View File

@@ -5,13 +5,10 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.*
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK_ACTIVE
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELL_COL
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.ui.Toolkit
import net.torvald.terrarum.ui.Toolkit.Theme.COL_INVENTORY_CELL_BORDER
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem
@@ -32,7 +29,7 @@ class UIItemInventoryEquippedView(
companion object {
val WIDTH = 2 * UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap
//val HEIGHT = UIItemInventoryDynamicList.HEIGHT
val SPRITE_DRAW_COL = Color(0xddddddff.toInt())
val SPRITE_DRAW_COL = Color(0xf2f2f2ff.toInt())
}
private val listGap = 8
@@ -42,8 +39,6 @@ class UIItemInventoryEquippedView(
lateinit var inventorySortList: Array<GameItem?>
private var rebuildList = true
val spriteViewBackCol: Color = CELL_COL
private val equipPosIcon = CommonResourcePool.getAsTextureRegionPack("inventory_category")
private val cellToIcon = intArrayOf(0,1,2,3,4,5,6,7,6,7,6,7)
@@ -57,10 +52,6 @@ class UIItemInventoryEquippedView(
item = null,
amount = UIItemInventoryElemWide.UNIQUE_ITEM_HAS_NO_AMOUNT,
itemImage = null,
mouseoverBackCol = Color(CELLCOLOUR_BLACK_ACTIVE),
mouseoverBackBlendMode = BlendMode.SCREEN,
backCol = CELL_COL,
backBlendMode = BlendMode.NORMAL,
drawBackOnNull = true,
keyDownFun = createInvCellGenericKeyDownFun(),
touchDownFun = createInvCellGenericTouchDownFun(inventoryListRebuildFun) // to "unselect" the equipped item and main item grid would "untick" accordingly
@@ -73,16 +64,16 @@ class UIItemInventoryEquippedView(
}
override fun render(batch: SpriteBatch, camera: Camera) {
blendNormal(batch)
val posXDelta = posX - oldPosX
itemGrid.forEach { it.posX += posXDelta }
// sprite background
blendNormal(batch)
batch.color = spriteViewBackCol
// sprite cell background
batch.color = Toolkit.Theme.COL_CELL_FILL
Toolkit.fillArea(batch, posX, posY, width, width)
batch.color = COL_INVENTORY_CELL_BORDER
// sprite cell border
batch.color = Toolkit.Theme.COL_INVENTORY_CELL_BORDER
Toolkit.drawBoxBorder(batch, posX, posY, width, width)

View File

@@ -55,8 +55,6 @@ class UIItemInventoryItemGrid(
override val width = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
override val height = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
val backColour = CELL_COL
init {
CommonResourcePool.addToLoadingList("inventory_walletnumberfont") {
TextureRegionPack("./assets/graphics/fonts/inventory_wallet_numbers.tga", 20, 9)
@@ -92,13 +90,10 @@ class UIItemInventoryItemGrid(
var inventorySortList = ArrayList<InventoryPair>()
private var rebuildList = true
val defaultTextColour = Color(0xeaeaea_ff.toInt())
private val walletFont = TextureRegionPack("./assets/graphics/fonts/inventory_wallet_numbers.tga", 20, 9)
private var walletText = ""
companion object {
const val listGap = 8
const val LIST_TO_CONTROL_GAP = 12
@@ -179,12 +174,7 @@ class UIItemInventoryItemGrid(
item = null,
amount = UIItemInventoryElemWide.UNIQUE_ITEM_HAS_NO_AMOUNT,
itemImage = null,
mouseoverBackCol = Color(CELLCOLOUR_BLACK_ACTIVE),
mouseoverBackBlendMode = BlendMode.SCREEN,
backCol = backColour,
backBlendMode = BlendMode.NORMAL,
drawBackOnNull = true,
inactiveTextCol = defaultTextColour,
keyDownFun = keyDownFun,
touchDownFun = touchDownFun
)
@@ -202,12 +192,7 @@ class UIItemInventoryItemGrid(
item = null,
amount = UIItemInventoryElemWide.UNIQUE_ITEM_HAS_NO_AMOUNT,
itemImage = null,
mouseoverBackCol = Color(CELLCOLOUR_BLACK_ACTIVE),
mouseoverBackBlendMode = BlendMode.SCREEN,
backCol = backColour,
backBlendMode = BlendMode.NORMAL,
drawBackOnNull = true,
inactiveTextCol = defaultTextColour,
keyDownFun = keyDownFun,
touchDownFun = touchDownFun
)
@@ -228,7 +213,7 @@ class UIItemInventoryItemGrid(
posX - LIST_TO_CONTROL_GAP - catBar.catIcons.tileW + 2
private fun getIconPosY(index: Int) =
posY - 2 + (4 + UIItemInventoryElemWide.height - catBar.catIcons.tileH) * index
posY - 1 + (4 + UIItemInventoryElemWide.height - catBar.catIcons.tileH) * index
/** Long/compact mode buttons */
internal val gridModeButtons = Array<UIItemImageButton>(2) { index ->
@@ -350,7 +335,7 @@ class UIItemInventoryItemGrid(
batch.draw(
walletFont.get(0, it - '0'),
gridModeButtons[0].posX.toFloat(), // scroll button size: 20px, font width: 20 px
gridModeButtons[0].posY + height - index * walletFont.tileH.toFloat()
gridModeButtons[0].posY + height - index * walletFont.tileH - 1f
)
}
}