inventorydynamiclist to have more options; fixed wrong shade values for trees; commonresourcepool to check dupes

This commit is contained in:
minjaesong
2019-08-05 04:58:33 +09:00
parent 3dfbde0e6c
commit df63824f69
3 changed files with 65 additions and 33 deletions

View File

@@ -18,10 +18,10 @@
"49";"49";"BLOCK_PLANK_EBONY";"0.1252";"0.1252";"0.1252";"0.1252";"19";"1200";"WOOD";"1";"0";"1";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A"
"50";"50";"BLOCK_PLANK_BIRCH";"0.1252";"0.1252";"0.1252";"0.1252";"15";"670";"WOOD";"1";"0";"1";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A"
"51";"51";"BLOCK_PLANK_BLOODROSE";"0.1252";"0.1252";"0.1252";"0.1252";"17";"900";"WOOD";"1";"0";"1";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A"
"64";"64";"BLOCK_TRUNK_NORMAL";"0.1252";"0.1252";"0.1252";"0.1252";"16";"740";"WOOD";"0";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A"
"65";"65";"BLOCK_TRUNK_EBONY";"0.1252";"0.1252";"0.1252";"0.1252";"19";"1200";"WOOD";"0";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A"
"66";"66";"BLOCK_TRUNK_BIRCH";"0.1252";"0.1252";"0.1252";"0.1252";"15";"670";"WOOD";"0";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A"
"67";"67";"BLOCK_TRUNK_BLOODROSE";"0.1252";"0.1252";"0.1252";"0.1252";"17";"900";"WOOD";"0";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A"
"64";"64";"BLOCK_TRUNK_NORMAL";"0.0312";"0.0312";"0.0312";"0.0312";"16";"740";"WOOD";"0";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A"
"65";"65";"BLOCK_TRUNK_EBONY";"0.0312";"0.0312";"0.0312";"0.0312";"19";"1200";"WOOD";"0";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A"
"66";"66";"BLOCK_TRUNK_BIRCH";"0.0312";"0.0312";"0.0312";"0.0312";"15";"670";"WOOD";"0";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A"
"67";"67";"BLOCK_TRUNK_BLOODROSE";"0.0312";"0.0312";"0.0312";"0.0312";"17";"900";"WOOD";"0";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A"
"80";"80";"BLOCK_SAND";"0.1252";"0.1252";"0.1252";"0.1252";"24";"2400";"SAND";"1";"0";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A"
"81";"81";"BLOCK_SAND_WHITE";"0.1252";"0.1252";"0.1252";"0.1252";"24";"2400";"SAND";"1";"0";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A"
"82";"82";"BLOCK_SAND_RED";"0.1252";"0.1252";"0.1252";"0.1252";"24";"2400";"SAND";"1";"0";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A"
@@ -99,9 +99,9 @@
"257";"257";"BLOCK_SUNSTONE";"0.1252";"0.1252";"0.1252";"0.1252";"1";"N/A";"ROCK";"1";"0";"0";"N/A";"2";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A"
"258";"258";"BLOCK_DAYLIGHT_CAPACITOR";"0.1252";"0.1252";"0.1252";"0.1252";"1";"N/A";"GLAS";"1";"0";"0";"N/A";"3";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A"
"272";"272";"BLOCK_SCAFFOLDING_NORMAL";"0.0312";"0.0312";"0.0312";"0.0312";"1";"N/A";"WOOD";"0";"1";"0";"6";"0";"0";"16";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A"
"273";"273";"BLOCK_SCAFFOLDING_EBONY";"0.0312";"0.0312";"0.0312";"0.0312";"1";"N/A";"WOOD";"0";"1";"0";"6";"0";"0";"16";"0.0";"0.0";"0.0";"0.0";"N/A";""
"274";"274";"BLOCK_SCAFFOLDING_BIRCH";"0.0312";"0.0312";"0.0312";"0.0312";"1";"N/A";"WOOD";"0";"1";"0";"6";"0";"0";"16";"0.0";"0.0";"0.0";"0.0";"N/A";""
"275";"275";"BLOCK_SCAFFOLDING_BLOODROSE";"0.0312";"0.0312";"0.0312";"0.0312";"1";"N/A";"WOOD";"0";"1";"0";"6";"0";"0";"16";"0.0";"0.0";"0.0";"0.0";"N/A";""
"273";"273";"BLOCK_SCAFFOLDING_EBONY";"0.0312";"0.0312";"0.0312";"0.0312";"1";"N/A";"WOOD";"0";"1";"0";"6";"0";"0";"16";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A"
"274";"274";"BLOCK_SCAFFOLDING_BIRCH";"0.0312";"0.0312";"0.0312";"0.0312";"1";"N/A";"WOOD";"0";"1";"0";"6";"0";"0";"16";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A"
"275";"275";"BLOCK_SCAFFOLDING_BLOODROSE";"0.0312";"0.0312";"0.0312";"0.0312";"1";"N/A";"WOOD";"0";"1";"0";"6";"0";"0";"16";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A"
"4091";"0";"ACTORBLOCK_NO_COLLISION";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"0";"0";"N/A";"0";"0";"0";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A"
"4092";"0";"ACTORBLOCK_FULL_COLLISION";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"0";"0";"N/A";"0";"0";"0";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A"
"4093";"0";"ACTORBLOCK_ALLOW_MOVE_DOWN";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"1";"0";"N/A";"0";"0";"0";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A"
@@ -113,6 +113,7 @@
## Notes ##
# Every block must have a shade value that is at least as dark as the air block's
#
# Lava/Water props are left for future references, do not delete them until FluidCodex is built #
#
1 id drop name shdr shdg shdb shduv str dsty mate solid plat wall grav dlfn fv fr lumr lumg lumb lumuv colour vscs
18 49 49 BLOCK_PLANK_EBONY 0.1252 0.1252 0.1252 0.1252 19 1200 WOOD 1 0 1 N/A 0 0 16 0.0000 0.0000 0.0000 0.0000 N/A N/A
19 50 50 BLOCK_PLANK_BIRCH 0.1252 0.1252 0.1252 0.1252 15 670 WOOD 1 0 1 N/A 0 0 16 0.0000 0.0000 0.0000 0.0000 N/A N/A
20 51 51 BLOCK_PLANK_BLOODROSE 0.1252 0.1252 0.1252 0.1252 17 900 WOOD 1 0 1 N/A 0 0 16 0.0000 0.0000 0.0000 0.0000 N/A N/A
21 64 64 BLOCK_TRUNK_NORMAL 0.1252 0.0312 0.1252 0.0312 0.1252 0.0312 0.1252 0.0312 16 740 WOOD 0 0 0 N/A 0 0 16 0.0000 0.0000 0.0000 0.0000 N/A N/A
22 65 65 BLOCK_TRUNK_EBONY 0.1252 0.0312 0.1252 0.0312 0.1252 0.0312 0.1252 0.0312 19 1200 WOOD 0 0 0 N/A 0 0 16 0.0000 0.0000 0.0000 0.0000 N/A N/A
23 66 66 BLOCK_TRUNK_BIRCH 0.1252 0.0312 0.1252 0.0312 0.1252 0.0312 0.1252 0.0312 15 670 WOOD 0 0 0 N/A 0 0 16 0.0000 0.0000 0.0000 0.0000 N/A N/A
24 67 67 BLOCK_TRUNK_BLOODROSE 0.1252 0.0312 0.1252 0.0312 0.1252 0.0312 0.1252 0.0312 17 900 WOOD 0 0 0 N/A 0 0 16 0.0000 0.0000 0.0000 0.0000 N/A N/A
25 80 80 BLOCK_SAND 0.1252 0.1252 0.1252 0.1252 24 2400 SAND 1 0 0 0 0 4 16 0.0000 0.0000 0.0000 0.0000 N/A N/A
26 81 81 BLOCK_SAND_WHITE 0.1252 0.1252 0.1252 0.1252 24 2400 SAND 1 0 0 0 0 4 16 0.0000 0.0000 0.0000 0.0000 N/A N/A
27 82 82 BLOCK_SAND_RED 0.1252 0.1252 0.1252 0.1252 24 2400 SAND 1 0 0 0 0 4 16 0.0000 0.0000 0.0000 0.0000 N/A N/A
99 257 257 BLOCK_SUNSTONE 0.1252 0.1252 0.1252 0.1252 1 N/A ROCK 1 0 0 N/A 2 0 16 0.0000 0.0000 0.0000 0.0000 N/A N/A
100 258 258 BLOCK_DAYLIGHT_CAPACITOR 0.1252 0.1252 0.1252 0.1252 1 N/A GLAS 1 0 0 N/A 3 0 16 0.0000 0.0000 0.0000 0.0000 N/A N/A
101 272 272 BLOCK_SCAFFOLDING_NORMAL 0.0312 0.0312 0.0312 0.0312 1 N/A WOOD 0 1 0 6 0 0 16 0.0 0.0 0.0 0.0 N/A N/A
102 273 273 BLOCK_SCAFFOLDING_EBONY 0.0312 0.0312 0.0312 0.0312 1 N/A WOOD 0 1 0 6 0 0 16 0.0 0.0 0.0 0.0 N/A N/A
103 274 274 BLOCK_SCAFFOLDING_BIRCH 0.0312 0.0312 0.0312 0.0312 1 N/A WOOD 0 1 0 6 0 0 16 0.0 0.0 0.0 0.0 N/A N/A
104 275 275 BLOCK_SCAFFOLDING_BLOODROSE 0.0312 0.0312 0.0312 0.0312 1 N/A WOOD 0 1 0 6 0 0 16 0.0 0.0 0.0 0.0 N/A N/A
105 4091 0 ACTORBLOCK_NO_COLLISION 0.0312 0.0312 0.0312 0.0312 1 1 NULL 0 0 0 N/A 0 0 0 0.0 0.0 0.0 0.0 N/A N/A
106 4092 0 ACTORBLOCK_FULL_COLLISION 0.0312 0.0312 0.0312 0.0312 1 1 NULL 0 0 0 N/A 0 0 0 0.0 0.0 0.0 0.0 N/A N/A
107 4093 0 ACTORBLOCK_ALLOW_MOVE_DOWN 0.0312 0.0312 0.0312 0.0312 1 1 NULL 0 1 0 N/A 0 0 0 0.0 0.0 0.0 0.0 N/A N/A
113 ## Notes ##
114 # # Every block must have a shade value that is at least as dark as the air block's
115 # Lava/Water props are left for future references, do not delete them until FluidCodex is built # #
116 # Lava/Water props are left for future references, do not delete them until FluidCodex is built #
117 #
118 # id: Block ID. ID equal to or greater than 4096 is for fluids, mainly for lighting calculation.
119 # drop: Drop ID

View File

@@ -46,6 +46,17 @@ object CommonResourcePool {
t.flip(false, true)
/*return*/t
}
loadAll()
}
fun resourceExists(name: String): Boolean {
loadingList.forEach {
if (it.name == name) return true
}
pool.forEach {
if (it.key == name) return true
}
return false
}
/**
@@ -67,26 +78,30 @@ object CommonResourcePool {
* - net.torvald.UnsafePtr
*/
fun addToLoadingList(identifier: String, loadFunction: () -> Any, destroyFunction: (() -> Unit)?) {
loadingList.addFirst(ResourceLoadingDescriptor(identifier, loadFunction, destroyFunction))
// check if resource is already there
if (!resourceExists(identifier)) {
loadingList.addFirst(ResourceLoadingDescriptor(identifier, loadFunction, destroyFunction))
if (loadCounter == -1)
loadCounter = 1
else
loadCounter += 1
if (loadCounter == -1)
loadCounter = 1
else
loadCounter += 1
}
}
/**
* Consumes the loading list. After the load, the list will be empty
*/
fun loadAll() {
if (loaded) throw IllegalStateException("Assets are already loaded and shipped out :p")
if (loaded) return //throw IllegalStateException("Assets are already loaded and shipped out :p")
while (!loadingList.isEmpty) {
val (name, loadfun, killfun) = loadingList.removeFirst()
if (pool.containsKey(name)) {
// no need for the collision checking; quarantine is done when the loading list is being appended
/*if (pool.containsKey(name)) {
throw IllegalArgumentException("Assets with identifier '$name' already exists.")
}
}*/
//typesMap[name] = type
pool[name] = loadfun.invoke()

View File

@@ -4,8 +4,8 @@ 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.gameworld.fmod
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
@@ -31,9 +31,11 @@ import java.util.*
*/
class UIItemInventoryDynamicList(
parentUI: UIInventoryFull,
val inventory: ActorInventory,
val inventory: ActorInventory, // when you're going to display List of Craftables, you could implement a Delegator...? Or just build a virtual inventory
override var posX: Int,
override var posY: Int
override var posY: Int,
val drawScrollOnRightside: Boolean = false,
val drawWallet: Boolean = true
) : UIItem(parentUI) {
// deal with the moving position
@@ -47,7 +49,12 @@ class UIItemInventoryDynamicList(
private val catArrangement = parentUI.catArrangement
init {
CommonResourcePool.addToLoadingList("inventory_walletnumberfont") {
TextureRegionPack("./assets/graphics/fonts/inventory_wallet_numbers.tga", 20, 9)
}
CommonResourcePool.loadAll()
}
val catIconsMeaning = listOf( // sortedBy: catArrangement
arrayOf(GameItem.Category.WEAPON),
@@ -87,10 +94,13 @@ class UIItemInventoryDynamicList(
private val walletFont = TextureRegionPack("./assets/graphics/fonts/inventory_wallet_numbers.tga", 20, 9)
private var walletText = ""
companion object {
const val listGap = 8
const val horizontalCells = 11
const val verticalCells = 8
const val LIST_TO_CONTROL_GAP = 12
val largeListWidth = (horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 2) * listGap) / 2
val WIDTH = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
@@ -140,8 +150,11 @@ class UIItemInventoryDynamicList(
field = value
}
private val iconPosX = if (drawScrollOnRightside)
posX + width + LIST_TO_CONTROL_GAP
else
posX - LIST_TO_CONTROL_GAP - parentUI.catIcons.tileW + 2
private val iconPosX = posX - 12 - parentUI.catIcons.tileW + 2
private fun getIconPosY(index: Int) =
posY - 2 + (4 + UIItemInventoryElem.height - (parentUI as UIInventoryFull).catIcons.tileH) * index
@@ -233,9 +246,9 @@ class UIItemInventoryDynamicList(
scrollDownButton.posX += posXDelta
fun getScrollDotYHeight(i: Int) = scrollUpButton.posY + 10 + upDownButtonGapToDots + 10 * i
scrollDownButton.posY = getScrollDotYHeight(itemPageCount) + upDownButtonGapToDots
@@ -252,20 +265,22 @@ class UIItemInventoryDynamicList(
batch.color = colour
batch.draw(
(parentUI as UIInventoryFull).catIcons.get(if (i == itemPage) 20 else 21,0),
(parentUI as UIInventoryFull).catIcons.get(if (i == itemPage) 20 else 21, 0),
scrollUpButton.posX.toFloat(),
getScrollDotYHeight(i).toFloat()
)
}
// draw wallet text
batch.color = Color.WHITE
walletText.forEachIndexed { index, it ->
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()
)
if (drawWallet) {
batch.color = Color.WHITE
walletText.forEachIndexed { index, it ->
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()
)
}
}
super.render(batch, camera)
@@ -389,10 +404,11 @@ class UIItemInventoryDynamicList(
override fun dispose() {
itemList.forEach { it.dispose() }
itemGrid.forEach { it.dispose() }
gridModeButtons.forEach { it.dispose() }
scrollUpButton.dispose()
scrollDownButton.dispose()
walletFont.dispose()
// the icons are using common resources that are disposed when the app quits
//gridModeButtons.forEach { it.dispose() }
//scrollUpButton.dispose()
//scrollDownButton.dispose()
//walletFont.dispose()
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {