material and 5 temporary vectors no longer go into the savegame

This commit is contained in:
minjaesong
2023-05-21 11:20:45 +09:00
parent b0d83325a7
commit 6268b99c1c
53 changed files with 777 additions and 5682 deletions

View File

@@ -88,7 +88,7 @@ class EntryPoint : ModuleEntryPoint() {
override var stackable = true
override var inventoryCategory = if (isWall) Category.WALL else Category.BLOCK
override var isDynamic = false
override val material = MaterialCodex.getOrDefault(tile.material)
override val materialId = tile.material
// override val itemImage: TextureRegion
// get() {
// val itemSheetNumber = App.tileMaker.tileIDtoItemSheetNumber(originalID)

View File

@@ -356,7 +356,9 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
codices.player.setPosition(it.physics.position)
if (isMultiplayer) {
printdbg(this, "Using world's ActorValue instead of player's")
codices.player.actorValue = it.actorValue!!
printdbg(this, "Using world's Inventory instead of player's")
codices.player.inventory = it.inventory!!
}
}

View File

@@ -186,9 +186,9 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) {
// load a half-gradient texture that would be used throughout the titlescreen and its sub UIs
CommonResourcePool.addToLoadingList("title_halfgrad") {
val t = Texture(Gdx.files.internal("./assets/graphics/halfgrad.tga"))
t.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
t
Texture(Gdx.files.internal("./assets/graphics/halfgrad.tga")).also {
it.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
}
}
CommonResourcePool.loadAll()

View File

@@ -191,7 +191,7 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
override val originalName: String = actorValue.getAsString(AVKey.NAME) ?: "(no name)"
override var stackable = false
override val isDynamic = false
override val material = Material()
override val materialId = ""
}
override fun update(delta: Float) {

View File

@@ -1,29 +1,12 @@
package net.torvald.terrarum.modulebasegame.gameactors
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.App.gamepadLabelStart
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory.Companion.CAPACITY_MODE_COUNT
import net.torvald.terrarum.modulebasegame.ui.*
import net.torvald.terrarum.modulebasegame.ui.UIInventoryCells.Companion.weightBarWidth
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELLS_VRT
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_X
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_Y
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.catBarWidth
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.controlHelpHeight
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.internalHeight
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.internalWidth
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.listGap
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import net.torvald.unicode.getKeycapPC
/**
* Created by minjaesong on 2019-07-08.
@@ -65,236 +48,3 @@ internal class FixtureStorageChest : FixtureBase {
const val MASS = 2.0
}
}
internal class UIStorageChest : UICanvas(
toggleKeyLiteral = App.getConfigInt("control_key_inventory"),
toggleButtonLiteral = App.getConfigInt("control_gamepad_start"),
), HasInventory {
lateinit var chestInventory: FixtureInventory
lateinit var chestNameFun: () -> String
override var width = App.scr.width
override var height = App.scr.height
private val negotiator = object : InventoryTransactionNegotiator() {
override fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Long) {
player.remove(item, amount)
fixture.add(item, amount)
}
override fun reject(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Long) {
fixture.remove(item, amount)
player.add(item, amount)
}
}
override fun getNegotiator() = negotiator
override fun getFixtureInventory(): FixtureInventory = chestInventory
override fun getPlayerInventory(): FixtureInventory = INGAME.actorNowPlaying!!.inventory
private val catBar: UIItemInventoryCatBar
private val itemListChest: UIItemInventoryItemGrid
private val itemListPlayer: UIItemInventoryItemGrid
private var encumbrancePerc = 0f
private var isEncumbered = false
private var halfSlotOffset = (UIItemInventoryElemSimple.height + listGap) / 2
init {
catBar = UIItemInventoryCatBar(
this,
(App.scr.width - catBarWidth) / 2,
42 - UIInventoryFull.YPOS_CORRECTION + (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
UIItemInventoryItemGrid.tooltipShowing.clear()
INGAME.setTooltipMessage(null)
}
private fun itemListUpdate() {
itemListChest.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
itemListPlayer.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
encumbrancePerc = getPlayerInventory().capacity.toFloat() / getPlayerInventory().maxCapacity
isEncumbered = getPlayerInventory().isEncumbered
}
private fun setCompact(yes: Boolean) {
itemListChest.isCompactMode = yes
itemListChest.gridModeButtons[0].highlighted = !yes
itemListChest.gridModeButtons[1].highlighted = yes
itemListChest.itemPage = 0
itemListChest.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
itemListPlayer.isCompactMode = yes
itemListPlayer.gridModeButtons[0].highlighted = !yes
itemListPlayer.gridModeButtons[1].highlighted = yes
itemListPlayer.itemPage = 0
itemListPlayer.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
itemListUpdate()
}
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
}
private val thisOffsetX = UIInventoryFull.INVENTORY_CELLS_OFFSET_X() - halfSlotOffset
private val thisOffsetX2 = thisOffsetX + (listGap + UIItemInventoryElemWide.height) * 7
private val thisOffsetY = UIInventoryFull.INVENTORY_CELLS_OFFSET_Y()
private val cellsWidth = (listGap + UIItemInventoryElemWide.height) * 6 - listGap
private val controlHelp: String
get() = if (App.environment == RunningEnvironment.PC)
"${getKeycapPC(App.getConfigInt("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}"
else
"$gamepadLabelStart ${Lang["GAME_ACTION_CLOSE"]} "
override fun renderUI(batch: SpriteBatch, camera: Camera) {
// background fill
UIInventoryFull.drawBackground(batch, handler.opacity)
// UI items
batch.color = Color.WHITE
catBar.render(batch, camera)
itemListChest.render(batch, camera)
itemListPlayer.render(batch, camera)
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 - weightBarWidth
val encumbBarTextXPos = encumbBarXPos - 6 - App.fontGame.getWidth(encumbranceText)
val yEnd = -UIInventoryFull.YPOS_CORRECTION + (App.scr.height + 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, weightBarWidth, 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
minOf(weightBarWidth, maxOf(1f, weightBarWidth * encumbrancePerc)),
controlHelpHeight - 6f
)
// chest name text
batch.color = Color.WHITE
App.fontGame.draw(batch, chestName, thisOffsetX + (cellsWidth - App.fontGame.getWidth(chestName)) / 2, thisOffsetY - 30)
App.fontGame.draw(batch, playerName, thisOffsetX2 + (cellsWidth - App.fontGame.getWidth(playerName)) / 2, thisOffsetY - 30)
// control hint
App.fontGame.draw(batch, controlHelp, thisOffsetX + 2f, encumbBarYPos - 3)
// encumb text
batch.color = Color.WHITE
App.fontGame.draw(batch, encumbranceText, encumbBarTextXPos, encumbBarYPos - 3f)
}
override fun doOpening(delta: Float) {
INGAME.pause()
INGAME.setTooltipMessage(null)
}
override fun doClosing(delta: Float) {
INGAME.resume()
INGAME.setTooltipMessage(null)
}
override fun endOpening(delta: Float) {
}
override fun endClosing(delta: Float) {
UIItemInventoryItemGrid.tooltipShowing.clear()
INGAME.setTooltipMessage(null) // required!
}
override fun dispose() {
}
}

View File

@@ -48,7 +48,7 @@ open class HumanoidNPC : ActorHumanoid, AIControlled, CanBeAnItem {
override val originalName: String = actorValue.getAsString(AVKey.NAME) ?: "NPC"
override var stackable = true
override val isDynamic = false
override val material = Material()
override val materialId = ""
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long {
try {

View File

@@ -44,7 +44,7 @@ open class FixtureItemBase(originalID: ItemID, val fixtureClassName: String) : G
override var inventoryCategory = Category.MISC
override val isUnique = false
override val isDynamic = false
override val material = Material()
override val materialId = ""
/**
* Do not address the CommonResourcePool directly; just do it like this snippet:

View File

@@ -17,7 +17,7 @@ class ItemLogicSignalEmitter(originalID: ItemID) : FixtureItemBase(originalID, "
override var inventoryCategory = Category.MISC
override val isUnique = false
override val isDynamic = false
override val material = Material()
override val materialId = ""
override val itemImage: TextureRegion
get() = getItemImageFromSingleImage("basegame", "sprites/fixtures/signal_source.tga")

View File

@@ -19,7 +19,7 @@ class ItemStorageChest(originalID: ItemID) : FixtureItemBase(originalID, "net.to
override var inventoryCategory = Category.MISC
override val isUnique = false
override val isDynamic = false
override val material = Material()
override val materialId = ""
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsTextureRegion("itemplaceholder_48")
override var baseToolSize: Double? = baseMass

View File

@@ -19,7 +19,7 @@ class ItemSwingingDoorOak(originalID: ItemID) :
override var inventoryCategory = Category.MISC
override val isUnique = false
override val isDynamic = false
override val material = Material()
override val materialId = ""
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsTextureRegion("itemplaceholder_16")
override var baseToolSize: Double? = baseMass
@@ -44,7 +44,7 @@ class ItemSwingingDoorEbony(originalID: ItemID) :
override var inventoryCategory = Category.MISC
override val isUnique = false
override val isDynamic = false
override val material = Material()
override val materialId = ""
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsTextureRegion("itemplaceholder_16")
override var baseToolSize: Double? = baseMass
@@ -69,7 +69,7 @@ class ItemSwingingDoorBirch(originalID: ItemID) :
override var inventoryCategory = Category.MISC
override val isUnique = false
override val isDynamic = false
override val material = Material()
override val materialId = ""
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsTextureRegion("itemplaceholder_16")
override var baseToolSize: Double? = baseMass
@@ -94,7 +94,7 @@ class ItemSwingingDoorRosewood(originalID: ItemID) :
override var inventoryCategory = Category.MISC
override val isUnique = false
override val isDynamic = false
override val material = Material()
override val materialId = ""
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsTextureRegion("itemplaceholder_16")
override var baseToolSize: Double? = baseMass

View File

@@ -21,7 +21,7 @@ class ItemTapestry(originalID: ItemID) : FixtureItemBase(originalID, "net.torval
override var inventoryCategory = Category.MISC
override val isUnique = false
override val isDynamic = false
override val material = Material()
override val materialId = ""
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsTextureRegion("itemplaceholder_16")
override var baseToolSize: Double? = baseMass

View File

@@ -17,7 +17,7 @@ class ItemTikiTorch(originalID: ItemID) : FixtureItemBase(originalID, "net.torva
override var inventoryCategory = Category.MISC
override val isUnique = false
override val isDynamic = false
override val material = Material()
override val materialId = ""
override val itemImage: TextureRegion
get() = getItemImageFromSheet("basegame", "sprites/fixtures/tiki_torch.tga", 16, 32)

View File

@@ -17,7 +17,7 @@ class ItemTypewriter(originalID: ItemID) : FixtureItemBase(originalID, "net.torv
override var inventoryCategory = Category.MISC
override val isUnique = false
override val isDynamic = false
override val material = Material()
override val materialId = ""
override val itemImage: TextureRegion
get() = getItemImageFromSheet("basegame", "sprites/fixtures/typewriter.tga", 32, 16)

View File

@@ -118,7 +118,7 @@ class PickaxeCopper(originalID: ItemID) : GameItem(originalID) {
override var inventoryCategory = Category.TOOL
override val isUnique = false
override val isDynamic = true
override val material = MaterialCodex["CUPR"]
override val materialId = "CUPR"
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsTextureRegionPack("basegame.items24").get(0,0)
@@ -148,7 +148,7 @@ class PickaxeIron(originalID: ItemID) : GameItem(originalID) {
override var inventoryCategory = Category.TOOL
override val isUnique = false
override val isDynamic = true
override val material = MaterialCodex["IRON"]
override val materialId = "IRON"
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsTextureRegionPack("basegame.items24").get(1,0)
@@ -178,7 +178,7 @@ class PickaxeSteel(originalID: ItemID) : GameItem(originalID) {
override var inventoryCategory = Category.TOOL
override val isUnique = false
override val isDynamic = true
override val material = MaterialCodex["STAL"]
override val materialId = "STAL"
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsTextureRegionPack("basegame.items24").get(2,0)

View File

@@ -92,7 +92,7 @@ class WireCutterAll(originalID: ItemID) : GameItem(originalID) {
override var inventoryCategory = Category.TOOL
override val isUnique = true
override val isDynamic = false
override val material = Material()
override val materialId = ""
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsTextureRegionPack("basegame.items16").get(0, 9)

View File

@@ -18,7 +18,7 @@ class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) {
override var inventoryCategory = Category.TOOL
override val isUnique = true
override val isDynamic = false
override val material = MaterialCodex["CUPR"]
override val materialId = "CUPR"
override var baseMass = 2.0
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsTextureRegion("itemplaceholder_24")

View File

@@ -22,7 +22,7 @@ class WirePieceSignalWire(originalID: ItemID, private val atlasID: String, priva
override var inventoryCategory = Category.WIRE
override val isUnique = false
override val isDynamic = false
override val material = Material()
override val materialId = ""
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsTextureRegionPack(atlasID).get(sheetX, sheetY)

View File

@@ -1,4 +1,4 @@
package net.torvald.terrarum.modulebasegame.gameactors
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
@@ -12,6 +12,8 @@ import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.itemproperties.CraftingCodex
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
import net.torvald.terrarum.modulebasegame.ui.*
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.listGap
import net.torvald.terrarum.ui.Toolkit

View File

@@ -9,7 +9,6 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.App.*
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.modulebasegame.gameactors.UICrafting
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemHorizontalFadeSlide
@@ -160,6 +159,7 @@ class UIInventoryFull(
fun unlockTransition() {
panelTransitionLocked = false
}
fun requestTransition(target: Int) = transitionPanel.requestTransition(target)
val catBar = UIItemInventoryCatBar(
this,
@@ -167,13 +167,12 @@ class UIInventoryFull(
42 - YPOS_CORRECTION + (App.scr.height - internalHeight) / 2,
internalWidth,
catBarWidth,
true,
{ i -> if (!panelTransitionLocked) requestTransition(i) }
)
true
) { i -> if (!panelTransitionLocked) requestTransition(i) }
// private val transitionalMinimap = UIInventoryMinimap(this) // PLACEHOLDER
private val transitionalCraftingUI = UICrafting(this) // PLACEHOLDER
// private val transitionalMinimap = UIInventoryMinimap(this)
private val transitionalCraftingUI = UICrafting(this)
private val transitionalItemCells = UIInventoryCells(this)
private val transitionalEscMenu = UIInventoryEscMenu(this)
private val transitionPanel = UIItemHorizontalFadeSlide(
@@ -258,8 +257,6 @@ class UIInventoryFull(
internal var offsetY = ((App.scr.height - internalHeight) / 2).toFloat()
private set
fun requestTransition(target: Int) = transitionPanel.requestTransition(target)
override fun updateUI(delta: Float) {
if (handler.openFired) {
rebuildList()

View File

@@ -7,7 +7,6 @@ import net.torvald.terrarum.UIItemInventoryCatBar
import net.torvald.terrarum.ceilInt
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.itemproperties.CraftingCodex
import net.torvald.terrarum.modulebasegame.gameactors.UICrafting
/**
* Created by minjaesong on 2022-06-28.

View File

@@ -85,8 +85,7 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : UICanvas() {
init {
CommonResourcePool.addToLoadingList("terrarum-defaultsavegamethumb") {
val t = TextureRegion(Texture(Gdx.files.internal("assets/graphics/gui/savegame_thumb_placeholder.png")))
t.flip(false, false); t
TextureRegion(Texture(Gdx.files.internal("assets/graphics/gui/savegame_thumb_placeholder.png")))
}
CommonResourcePool.addToLoadingList("savegame_status_icon") {
TextureRegionPack("assets/graphics/gui/savegame_status_icon.tga", 24, 24)

View File

@@ -0,0 +1,255 @@
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.AVKey
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.unicode.getKeycapPC
/**
* Created by minjaesong on 2019-07-08.
*/
internal class UIStorageChest : UICanvas(
toggleKeyLiteral = App.getConfigInt("control_key_inventory"),
toggleButtonLiteral = App.getConfigInt("control_gamepad_start"),
), HasInventory {
lateinit var chestInventory: FixtureInventory
lateinit var chestNameFun: () -> String
override var width = App.scr.width
override var height = App.scr.height
private val negotiator = object : InventoryTransactionNegotiator() {
override fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Long) {
player.remove(item, amount)
fixture.add(item, amount)
}
override fun reject(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Long) {
fixture.remove(item, amount)
player.add(item, amount)
}
}
override fun getNegotiator() = negotiator
override fun getFixtureInventory(): FixtureInventory = chestInventory
override fun getPlayerInventory(): FixtureInventory = INGAME.actorNowPlaying!!.inventory
private val catBar: UIItemInventoryCatBar
private val itemListChest: UIItemInventoryItemGrid
private val itemListPlayer: UIItemInventoryItemGrid
private var encumbrancePerc = 0f
private var isEncumbered = false
private var halfSlotOffset = (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap) / 2
init {
catBar = UIItemInventoryCatBar(
this,
(App.scr.width - UIInventoryFull.catBarWidth) / 2,
42 - UIInventoryFull.YPOS_CORRECTION + (App.scr.height - UIInventoryFull.internalHeight) / 2,
UIInventoryFull.internalWidth,
UIInventoryFull.catBarWidth,
false
)
catBar.selectionChangeListener = { old, new -> itemListUpdate() }
itemListChest = UIItemInventoryItemGrid(
this,
catBar,
{ getFixtureInventory() },
UIInventoryFull.INVENTORY_CELLS_OFFSET_X() - halfSlotOffset,
UIInventoryFull.INVENTORY_CELLS_OFFSET_Y(),
6, UIInventoryFull.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
UIInventoryFull.INVENTORY_CELLS_OFFSET_X() - halfSlotOffset + (UIItemInventoryItemGrid.listGap + UIItemInventoryElemWide.height) * 7,
UIInventoryFull.INVENTORY_CELLS_OFFSET_Y(),
6, UIInventoryFull.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
UIItemInventoryItemGrid.tooltipShowing.clear()
INGAME.setTooltipMessage(null)
}
private fun itemListUpdate() {
itemListChest.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
itemListPlayer.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
encumbrancePerc = getPlayerInventory().capacity.toFloat() / getPlayerInventory().maxCapacity
isEncumbered = getPlayerInventory().isEncumbered
}
private fun setCompact(yes: Boolean) {
itemListChest.isCompactMode = yes
itemListChest.gridModeButtons[0].highlighted = !yes
itemListChest.gridModeButtons[1].highlighted = yes
itemListChest.itemPage = 0
itemListChest.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
itemListPlayer.isCompactMode = yes
itemListPlayer.gridModeButtons[0].highlighted = !yes
itemListPlayer.gridModeButtons[1].highlighted = yes
itemListPlayer.itemPage = 0
itemListPlayer.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
itemListUpdate()
}
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
}
private val thisOffsetX = UIInventoryFull.INVENTORY_CELLS_OFFSET_X() - halfSlotOffset
private val thisOffsetX2 = thisOffsetX + (UIItemInventoryItemGrid.listGap + UIItemInventoryElemWide.height) * 7
private val thisOffsetY = UIInventoryFull.INVENTORY_CELLS_OFFSET_Y()
private val cellsWidth = (UIItemInventoryItemGrid.listGap + UIItemInventoryElemWide.height) * 6 - UIItemInventoryItemGrid.listGap
private val controlHelp: String
get() = if (App.environment == RunningEnvironment.PC)
"${getKeycapPC(App.getConfigInt("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}"
else
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]} "
override fun renderUI(batch: SpriteBatch, camera: Camera) {
// background fill
UIInventoryFull.drawBackground(batch, handler.opacity)
// UI items
batch.color = Color.WHITE
catBar.render(batch, camera)
itemListChest.render(batch, camera)
itemListPlayer.render(batch, camera)
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
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
minOf(UIInventoryCells.weightBarWidth, maxOf(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
UIInventoryFull.controlHelpHeight - 6f
)
// chest name text
batch.color = Color.WHITE
App.fontGame.draw(batch, chestName, thisOffsetX + (cellsWidth - App.fontGame.getWidth(chestName)) / 2, thisOffsetY - 30)
App.fontGame.draw(batch, playerName, thisOffsetX2 + (cellsWidth - App.fontGame.getWidth(playerName)) / 2, thisOffsetY - 30)
// control hint
App.fontGame.draw(batch, controlHelp, thisOffsetX + 2f, encumbBarYPos - 3)
// encumb text
batch.color = Color.WHITE
App.fontGame.draw(batch, encumbranceText, encumbBarTextXPos, encumbBarYPos - 3f)
}
override fun doOpening(delta: Float) {
INGAME.pause()
INGAME.setTooltipMessage(null)
}
override fun doClosing(delta: Float) {
INGAME.resume()
INGAME.setTooltipMessage(null)
}
override fun endOpening(delta: Float) {
}
override fun endClosing(delta: Float) {
UIItemInventoryItemGrid.tooltipShowing.clear()
INGAME.setTooltipMessage(null) // required!
}
override fun dispose() {
}
}

View File

@@ -4,12 +4,12 @@ import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.App
import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemTextButtonList
import kotlin.math.ceil
class UITitleLanguage(remoCon: UIRemoCon?) : UICanvas() {
@@ -22,8 +22,8 @@ class UITitleLanguage(remoCon: UIRemoCon?) : UICanvas() {
private val textButtonLineHeight = 32
private val localeList = Lang.languageList.toList().sorted()
private val localeFirstHalf = localeList.subList(0, localeList.size / 2)
private val localeSecondHalf = localeList.subList(localeList.size / 2, localeList.size)
private val localeFirstHalf = localeList.subList(0, ceil(localeList.size / 2f).toInt())
private val localeSecondHalf = localeList.subList(ceil(localeList.size / 2f).toInt(), localeList.size)
override var width = 480
override var height = maxOf(localeFirstHalf.size, localeSecondHalf.size) * textButtonLineHeight

View File

@@ -0,0 +1,126 @@
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.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemHorizontalFadeSlide
/**
* Structure:
*
* UIWorldPortal (the container)
* + UIWorldPortalSearch (left panel)
* + UIWorldPortalListing (centre panel)
* + UIWorldPortalCargo (right panel)
*
* Created by minjaesong on 2023-05-19.
*/
class UIWorldPortal : UICanvas() {
override var width = App.scr.width
override var height = App.scr.height
val gradStartCol = Color(0x404040_60)
val gradEndCol = Color(0x000000_70)
val gradHeight = 48f
val controlHelpHeight = App.fontGame.lineHeight
private var panelTransitionLocked = false
fun lockTransition() {
panelTransitionLocked = true
}
fun unlockTransition() {
panelTransitionLocked = false
}
fun requestTransition(target: Int) = transitionPanel.requestTransition(target)
val catBar = UIItemInventoryCatBar(
this,
(width - UIInventoryFull.catBarWidth) / 2,
42 - UIInventoryFull.YPOS_CORRECTION + (App.scr.height - UIInventoryFull.internalHeight) / 2,
UIInventoryFull.internalWidth,
UIInventoryFull.catBarWidth,
true
) { i -> if (!panelTransitionLocked) requestTransition(i) }
private val transitionalSearch = UIWorldPortalSearch(this)
private val transitionalListing = UIWorldPortalListing(this)
private val transitionalCargo = UIWorldPortalCargo(this)
private val transitionPanel = UIItemHorizontalFadeSlide(
this,
(width - UIInventoryFull.internalWidth) / 2,
UIInventoryFull.INVENTORY_CELLS_OFFSET_Y(),
width,
App.scr.height,
1f,
transitionalSearch, transitionalListing, transitionalCargo
)
init {
addUIitem(catBar)
addUIitem(transitionPanel)
}
override fun updateUI(delta: Float) {
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
UIInventoryFull.drawBackground(batch, handler.opacity)
// UI items
catBar.render(batch, camera)
transitionPanel.render(batch, camera)
}
override fun dispose() {
catBar.dispose()
}
fun resetUI() {
}
override fun doOpening(delta: Float) {
super.doOpening(delta)
resetUI()
INGAME.setTooltipMessage(null)
}
override fun doClosing(delta: Float) {
super.doClosing(delta)
INGAME.setTooltipMessage(null)
}
override fun endOpening(delta: Float) {
super.endOpening(delta)
UIItemInventoryItemGrid.tooltipShowing.clear()
INGAME.setTooltipMessage(null) // required!
}
override fun endClosing(delta: Float) {
super.endClosing(delta)
resetUI()
UIItemInventoryItemGrid.tooltipShowing.clear()
INGAME.setTooltipMessage(null) // required!
}
}

View File

@@ -0,0 +1,25 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.App
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas() {
override var width: Int = Toolkit.drawWidth
override var height: Int = App.scr.height
override fun updateUI(delta: Float) {
TODO("Not yet implemented")
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
TODO("Not yet implemented")
}
override fun dispose() {
TODO("Not yet implemented")
}
}

View File

@@ -0,0 +1,129 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_Y
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.listGap
import net.torvald.terrarum.savegame.DiskSkimmer
import net.torvald.terrarum.serialise.ascii85toUUID
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem
import net.torvald.terrarum.ui.UIItemTextButton
import java.util.*
/**
* Created by minjaesong on 2023-05-19.
*/
class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
override var width: Int = Toolkit.drawWidth
override var height: Int = App.scr.height
private val cellHeight = 48
private val buttonHeight = 24
private val gridGap = listGap
private var worldList: List<Pair<UUID, DiskSkimmer>>
private var selectedWorld: DiskSkimmer? = null
private val cellCol = UIInventoryFull.CELL_COL
private var highlightCol: Color = Color.WHITE
private val thumbw = 360
private val thumbh = 240
private val hx = Toolkit.drawWidth.div(2)
private val y = INVENTORY_CELLS_OFFSET_Y()
private val listCount = UIInventoryFull.CELLS_VRT
private val listHeight = cellHeight * listCount + gridGap * (listCount - 1)
private val deleteButtonWidth = 80
private val buttonReset = UIItemTextButton(this,
"MENU_LABEL_DELETE_WORLD",
hx - gridGap/2 - deleteButtonWidth,
y + listHeight - buttonHeight,
deleteButtonWidth,
readFromLang = true,
hasBorder = true,
alignment = UIItemTextButton.Companion.Alignment.CENTRE
)
init {
CommonResourcePool.addToLoadingList("terrarum-basegame-worldportalicons") {
TextureRegion(Texture(ModMgr.getGdxFile("basegame", "gui/worldportal_catbar.tga")), 20, 20).also {
it.flip(false, false)
}
}
CommonResourcePool.loadAll()
addUIitem(buttonReset)
worldList = (INGAME.actorGamer.actorValue.getAsString(AVKey.WORLD_PORTAL_DICT) ?: "").split(",").map {
it.ascii85toUUID().let { it to App.savegameWorlds[it] }
}.filter { it.second != null } as List<Pair<UUID, DiskSkimmer>>
}
override fun updateUI(delta: Float) {
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
batch.inUse {
// draw background //
// screencap panel
batch.color = cellCol
Toolkit.fillArea(batch, hx - thumbw - gridGap/2, y, thumbw, thumbh)
// draw border //
// screencap panel
batch.color = highlightCol
Toolkit.drawBoxBorder(batch, hx - thumbw - gridGap/2 - 1, y - 1, thumbw + 2, thumbh + 2)
// memory gauge
Toolkit.drawBoxBorder(batch, hx - 330 - gridGap/2 - 1, y + listHeight - 1, 240 + 2, buttonHeight + 2)
uiItems.forEach { it.render(batch, camera) }
}
}
override fun dispose() {
}
}
class UIItemWorldCellsSimple(
parent: UILoadDemoSavefiles,
initialX: Int,
initialY: Int,
val skimmer: DiskSkimmer
) : UIItem(parent, initialX, initialY) {
override val width: Int = 360
override val height: Int = 46
private val cellCol = UIInventoryFull.CELL_COL
private var highlightCol: Color = Color.WHITE
override fun dispose() {
}
}

View File

@@ -0,0 +1,28 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.App
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
/**
* Created by minjaesong on 2023-05-19.
*/
class UIWorldPortalSearch(val full: UIWorldPortal) : UICanvas() {
override var width: Int = Toolkit.drawWidth
override var height: Int = App.scr.height
override fun updateUI(delta: Float) {
TODO("Not yet implemented")
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
TODO("Not yet implemented")
}
override fun dispose() {
TODO("Not yet implemented")
}
}