diff --git a/assets/modules/basegame/blocks/blocks.csv b/assets/modules/basegame/blocks/blocks.csv index 6c9e5a557..d80a1679e 100644 --- a/assets/modules/basegame/blocks/blocks.csv +++ b/assets/modules/basegame/blocks/blocks.csv @@ -1,17 +1,18 @@ "id";"sid";"name" ; "opacity";"strength";"dsty";"mate";"fluid";"solid";"wall"; "lumcolor";"drop";"ddmg";"fall";"dlfn";"vscs";"fv";"friction" - "0"; "0";"BLOCK_AIR" ; "8396808"; "1"; "1";"null"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "N/A"; "0";"4" + "0"; "0";"BLOCK_AIR" ; "8396808"; "1"; "1";"null"; "0"; "0"; "1"; "0"; "0"; "0"; "0"; "0"; "N/A"; "0";"4" "1"; "0";"BLOCK_STONE" ; "33587232"; "48";"2400";"rock"; "0"; "1"; "1"; "0"; "1"; "0"; "0"; "0"; "N/A"; "0";"16" "1"; "1";"BLOCK_STONE_QUARRIED" ; "33587232"; "48";"2400";"rock"; "0"; "1"; "1"; "0"; "1"; "1"; "0"; "0"; "N/A"; "0";"16" "1"; "2";"BLOCK_STONE_TILE_WHITE" ; "33587232"; "48";"2400";"rock"; "0"; "1"; "1"; "0"; "1"; "2"; "0"; "0"; "N/A"; "0";"16" "1"; "3";"BLOCK_STONE_BRICKS" ; "33587232"; "48";"2400";"rock"; "0"; "1"; "1"; "0"; "1"; "3"; "0"; "0"; "N/A"; "0";"16" "2"; "0";"BLOCK_DIRT" ; "33587232"; "24";"1400";"dirt"; "0"; "1"; "1"; "0"; "2"; "0"; "0"; "0"; "N/A"; "0";"16" - "2"; "1";"BLOCK_GRASS" ; "33587232"; "24";"1400";"grss"; "0"; "1"; "1"; "0"; "2"; "1"; "0"; "0"; "N/A"; "0";"16" - "2"; "2";"BLOCK_FOLIAGE_GREEN" ; "33587232"; "24";"1400";"grss"; "0"; "1"; "1"; "0"; "2"; "2"; "0"; "0"; "N/A"; "0";"16" - "2"; "3";"BLOCK_FOLIAGE_LIME" ; "33587232"; "24";"1400";"grss"; "0"; "1"; "1"; "0"; "2"; "3"; "0"; "0"; "N/A"; "0";"16" - "2"; "4";"BLOCK_FOLIAGE_GOLD" ; "33587232"; "24";"1400";"grss"; "0"; "1"; "1"; "0"; "2"; "4"; "0"; "0"; "N/A"; "0";"16" - "2"; "5";"BLOCK_FOLIAGE_RED" ; "33587232"; "24";"1400";"grss"; "0"; "1"; "1"; "0"; "2"; "5"; "0"; "0"; "N/A"; "0";"16" - "2"; "6";"BLOCK_FOLIAGE_ICEBLUE" ; "33587232"; "24";"1400";"grss"; "0"; "1"; "1"; "0"; "2"; "6"; "0"; "0"; "N/A"; "0";"16" - "2"; "7";"BLOCK_FOLIAGE_PURPLE" ; "33587232"; "24";"1400";"grss"; "0"; "1"; "1"; "0"; "2"; "7"; "0"; "0"; "N/A"; "0";"16" + "2"; "1";"BLOCK_GRASS" ; "33587232"; "24";"1400";"grss"; "0"; "1"; "0"; "0"; "2"; "1"; "0"; "0"; "N/A"; "0";"16" + "2"; "2";"BLOCK_GRASSWALL" ; "33587232"; "24";"1400";"grss"; "0"; "1"; "1"; "0"; "2"; "2"; "0"; "0"; "N/A"; "0";"16" + "2"; "3";"BLOCK_FOLIAGE_GREEN" ; "33587232"; "24";"1400";"grss"; "0"; "1"; "1"; "0"; "2"; "3"; "0"; "0"; "N/A"; "0";"16" + "2"; "4";"BLOCK_FOLIAGE_LIME" ; "33587232"; "24";"1400";"grss"; "0"; "1"; "1"; "0"; "2"; "4"; "0"; "0"; "N/A"; "0";"16" + "2"; "5";"BLOCK_FOLIAGE_GOLD" ; "33587232"; "24";"1400";"grss"; "0"; "1"; "1"; "0"; "2"; "5"; "0"; "0"; "N/A"; "0";"16" + "2"; "6";"BLOCK_FOLIAGE_RED" ; "33587232"; "24";"1400";"grss"; "0"; "1"; "1"; "0"; "2"; "6"; "0"; "0"; "N/A"; "0";"16" + "2"; "7";"BLOCK_FOLIAGE_ICEBLUE" ; "33587232"; "24";"1400";"grss"; "0"; "1"; "1"; "0"; "2"; "7"; "0"; "0"; "N/A"; "0";"16" + "2"; "8";"BLOCK_FOLIAGE_PURPLE" ; "33587232"; "24";"1400";"grss"; "0"; "1"; "1"; "0"; "2"; "8"; "0"; "0"; "N/A"; "0";"16" "3"; "0";"BLOCK_PLANK_NORMAL" ; "33587232"; "16"; "740";"wood"; "0"; "1"; "1"; "0"; "3"; "0"; "0"; "0"; "N/A"; "0";"16" "3"; "1";"BLOCK_PLANK_EBONY" ; "33587232"; "19";"1200";"wood"; "0"; "1"; "1"; "0"; "3"; "1"; "0"; "0"; "N/A"; "0";"16" "3"; "2";"BLOCK_PLANK_BIRCH" ; "33587232"; "15"; "670";"wood"; "0"; "1"; "1"; "0"; "3"; "2"; "0"; "0"; "N/A"; "0";"16" diff --git a/assets/modules/basegame/items/testpick.groovy b/assets/modules/basegame/items/testpick.groovy index 4b2cf2d3b..9c138dad7 100644 --- a/assets/modules/basegame/items/testpick.groovy +++ b/assets/modules/basegame/items/testpick.groovy @@ -8,6 +8,7 @@ import net.torvald.point.Point2d import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.ActorWithPhysics +import net.torvald.terrarum.itemproperties.Calculate import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.blockproperties.Block diff --git a/src/net/torvald/terrarum/blockproperties/Block.kt b/src/net/torvald/terrarum/blockproperties/Block.kt index ceb827311..6b2db85d3 100644 --- a/src/net/torvald/terrarum/blockproperties/Block.kt +++ b/src/net/torvald/terrarum/blockproperties/Block.kt @@ -14,6 +14,7 @@ object Block { val DIRT = BlockCodex.idDamageToIndex(2, 0) val GRASS = BlockCodex.idDamageToIndex(2, 1) + val GRASSWALL = BlockCodex.idDamageToIndex(2, 2) val PLANK_NORMAL = BlockCodex.idDamageToIndex(3, 0) val PLANK_EBONY = BlockCodex.idDamageToIndex(3, 1) diff --git a/src/net/torvald/terrarum/gameactors/ActorInventory.kt b/src/net/torvald/terrarum/gameactors/ActorInventory.kt index 64b3d2905..9162d0495 100644 --- a/src/net/torvald/terrarum/gameactors/ActorInventory.kt +++ b/src/net/torvald/terrarum/gameactors/ActorInventory.kt @@ -1,9 +1,12 @@ package net.torvald.terrarum.gameactors import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_DYNAMIC +import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_WALLS +import net.torvald.terrarum.itemproperties.ItemID import net.torvald.terrarum.ui.UIInventory import java.util.* import java.util.concurrent.locks.Lock @@ -30,16 +33,25 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode * Sorted by referenceID. */ private val itemList = ArrayList() + private val quickBar = Array(10, { null }) init { } - fun add(itemID: Int, count: Int = 1) = add(ItemCodex[itemID], count) + fun add(itemID: ItemID, count: Int = 1) = add(ItemCodex[itemID], count) fun add(item: InventoryItem, count: Int = 1) { println("[ActorInventory] add $item, $count") + // not wall-able walls + if (item.inventoryCategory == InventoryItem.Category.WALL && + !BlockCodex[item.dynamicID - ITEM_WALLS.start].isWallable) { + throw IllegalArgumentException("Wall ID ${item.dynamicID - ITEM_WALLS.start} is not wall-able.") + } + + + // other invalid values if (count == 0) throw IllegalArgumentException("Item count is zero.") if (count < 0) @@ -71,7 +83,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode insertionSortLastElem(itemList) } - fun remove(itemID: Int, count: Int) = remove(ItemCodex[itemID], count) + fun remove(itemID: ItemID, count: Int) = remove(ItemCodex[itemID], count) /** Will check existence of the item using its Dynamic ID; careful with command order! * e.g. re-assign after this operation */ fun remove(item: InventoryItem, count: Int = 1) { @@ -109,6 +121,12 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode } } + fun setQuickBar(slot: Int, dynamicID: ItemID?) { + quickBar[slot] = dynamicID + } + + fun getQuickBar(slot: Int): InventoryPair? = getByDynamicID(quickBar[slot]) + /** * HashMap */ @@ -202,13 +220,13 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode fun contains(item: InventoryItem) = contains(item.dynamicID) - fun contains(id: Int) = + fun contains(id: ItemID) = if (itemList.size == 0) false else itemList.binarySearch(id, DYNAMIC_ID) >= 0 - fun getByDynamicID(id: Int): InventoryPair? { - if (itemList.size == 0) + fun getByDynamicID(id: ItemID?): InventoryPair? { + if (itemList.size == 0 || id == null) return null val index = itemList.binarySearch(id, DYNAMIC_ID) @@ -217,7 +235,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode else return itemList[index] } - private fun getByStaticID(id: Int): InventoryPair? { + private fun getByStaticID(id: ItemID): InventoryPair? { if (itemList.size == 0) return null @@ -240,7 +258,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode } private val STATIC_ID = 41324534 private val DYNAMIC_ID = 181643953 - private fun ArrayList.binarySearch(ID: Int, searchBy: Int): Int { + private fun ArrayList.binarySearch(ID: ItemID, searchBy: Int): Int { // code from collections/Collections.kt var low = 0 var high = this.size - 1 diff --git a/src/net/torvald/terrarum/gameactors/Player.kt b/src/net/torvald/terrarum/gameactors/Player.kt index eb2b33b2b..2fd7db639 100644 --- a/src/net/torvald/terrarum/gameactors/Player.kt +++ b/src/net/torvald/terrarum/gameactors/Player.kt @@ -11,8 +11,6 @@ import org.newdawn.slick.GameContainer class Player(born: GameDate) : ActorHumanoid(born) { - internal val quickBarRegistration = IntArray(UIQuickBar.SLOT_COUNT, { -1 }) - companion object { @Transient const val PLAYER_REF_ID: Int = 0x91A7E2 } diff --git a/src/net/torvald/terrarum/gameactors/PlayerBuilderSigrid.kt b/src/net/torvald/terrarum/gameactors/PlayerBuilderSigrid.kt index 40cd7b764..76bff4b69 100644 --- a/src/net/torvald/terrarum/gameactors/PlayerBuilderSigrid.kt +++ b/src/net/torvald/terrarum/gameactors/PlayerBuilderSigrid.kt @@ -71,7 +71,7 @@ object PlayerBuilderSigrid { // Test fill up inventory - val tiles = arrayOf( + val blocks = arrayOf( Block.AIR, Block.DIRT, Block.GLASS_CRUDE, Block.GRASS, Block.GRAVEL, Block.ICE_MAGICAL, Block.LANTERN, Block.PLANK_BIRCH, Block.PLANK_BLOODROSE, Block.PLANK_EBONY, Block.PLANK_NORMAL, @@ -79,7 +79,16 @@ object PlayerBuilderSigrid { Block.SANDSTONE_RED, Block.STONE, Block.STONE_BRICKS, Block.STONE_QUARRIED, Block.STONE_TILE_WHITE, Block.TORCH ) - tiles.forEach { p.addItem(it, 999) } + val walls = arrayOf( + Block.AIR, Block.DIRT, Block.GLASS_CRUDE, + Block.GRASSWALL, Block.ICE_MAGICAL, + Block.PLANK_BIRCH, Block.PLANK_BLOODROSE, Block.PLANK_EBONY, Block.PLANK_NORMAL, + Block.SANDSTONE, Block.SANDSTONE_BLACK, Block.SANDSTONE_GREEN, + Block.SANDSTONE_RED, Block.STONE, Block.STONE_BRICKS, + Block.STONE_QUARRIED, Block.STONE_TILE_WHITE + ) + blocks.forEach { p.addItem(it, 999) } + walls.forEach { p.addItem(it + 4096, 999) } p.inventory.add(ItemCodex.ITEM_STATIC.first) diff --git a/src/net/torvald/terrarum/itemproperties/IVKey.kt b/src/net/torvald/terrarum/itemproperties/IVKey.kt index e0e7a8deb..33a616703 100644 --- a/src/net/torvald/terrarum/itemproperties/IVKey.kt +++ b/src/net/torvald/terrarum/itemproperties/IVKey.kt @@ -4,6 +4,7 @@ package net.torvald.terrarum.itemproperties * Created by minjaesong on 16-09-09. */ object IVKey { + /** Weapon types or Armour types. Does not affect inventory categorising */ const val ITEMTYPE = "itemtype" // "sword1h", "sword2h", "pick", "hammer", "tile", "wall", etc const val UUID = "uuid" // some items need UUID to be stored @@ -12,8 +13,6 @@ object IVKey { object ItemType { - const val BLOCK = "tile" - const val WALL = "wall" // tools const val PICK = "pick" const val HAMMER= "hammer" diff --git a/src/net/torvald/terrarum/itemproperties/InventoryItem.kt b/src/net/torvald/terrarum/itemproperties/InventoryItem.kt index f9c1b9cf3..ec316bc65 100644 --- a/src/net/torvald/terrarum/itemproperties/InventoryItem.kt +++ b/src/net/torvald/terrarum/itemproperties/InventoryItem.kt @@ -10,16 +10,18 @@ import net.torvald.terrarum.langpack.Lang import org.newdawn.slick.Color import org.newdawn.slick.GameContainer +typealias ItemID = Int + /** * Created by minjaesong on 16-01-16. */ abstract class InventoryItem : Comparable, Cloneable { - abstract var dynamicID: Int + abstract var dynamicID: ItemID /** * if the ID is a Actor range, it's an actor contained in a pocket. */ - abstract val originalID: Int // WUT?! using init does not work!! + abstract val originalID: ItemID // WUT?! using init does not work!! /** @@ -237,6 +239,7 @@ abstract class InventoryItem : Comparable, Cloneable { @JvmStatic val MAGIC = "magic" @JvmStatic val BLOCK = "block" @JvmStatic val WALL = "wall" + @JvmStatic val WIRE = "wire" @JvmStatic val MISC = "misc" } diff --git a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt index d8cb7b158..296d71217 100644 --- a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt +++ b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt @@ -9,8 +9,8 @@ import net.torvald.terrarum.gamecontroller.mouseTileX import net.torvald.terrarum.gamecontroller.mouseTileY import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.worlddrawer.BlocksDrawer -import net.torvald.terrarum.worlddrawer.BlocksDrawer.wallOverlayColour import net.torvald.terrarum.blockproperties.BlockCodex +import net.torvald.terrarum.worlddrawer.FeaturesDrawer.TILE_SIZE import org.newdawn.slick.GameContainer import org.newdawn.slick.Image import java.util.* @@ -24,8 +24,8 @@ object ItemCodex { * * Will return corresponding Actor if ID >= ACTORID_MIN */ - private val itemCodex = HashMap() - private val dynamicItemDescription = HashMap() + private val itemCodex = HashMap() + private val dynamicItemDescription = HashMap() val ITEM_TILES = 0..GameWorld.TILES_SUPPORTED - 1 val ITEM_WALLS = GameWorld.TILES_SUPPORTED..GameWorld.TILES_SUPPORTED * 2 - 1 @@ -51,15 +51,12 @@ object ItemCodex { override var equipPosition = EquipPosition.HAND_GRIP override val originalName = BlockCodex[i % ITEM_WALLS.first].nameKey override var stackable = true - override var inventoryCategory = Category.BLOCK + override var inventoryCategory = if (i in ITEM_TILES) Category.BLOCK else Category.WALL override var isDynamic = false override val material = Material(0,0,0,0,0,0,0,0,0,0.0) init { - itemProperties[IVKey.ITEMTYPE] = if (i in ITEM_TILES) - IVKey.ItemType.BLOCK - else - IVKey.ItemType.WALL + } override fun primaryUse(gc: GameContainer, delta: Int): Boolean { @@ -69,14 +66,23 @@ object ItemCodex { override fun secondaryUse(gc: GameContainer, delta: Int): Boolean { val mousePoint = Point2d(gc.mouseTileX.toDouble(), gc.mouseTileY.toDouble()) - // linear search filter (check for intersection with tilewise mouse point and tilewise hitbox) - Terrarum.ingame!!.actorContainer.forEach { - if (it is ActorWithPhysics && it.tilewiseHitbox.intersects(mousePoint)) - return false + + // check for collision with actors (BLOCK only) + if (this.inventoryCategory == Category.BLOCK) { + Terrarum.ingame!!.actorContainer.forEach { + if (it is ActorWithPhysics && it.tilewiseHitbox.intersects(mousePoint)) + return false + } } // return false if the tile is already there - if (this.dynamicID == Terrarum.ingame!!.world.getTileFromTerrain(gc.mouseTileX, gc.mouseTileY)) + if (this.inventoryCategory == Category.BLOCK && + this.dynamicID == Terrarum.ingame!!.world.getTileFromTerrain(gc.mouseTileX, gc.mouseTileY) || + this.inventoryCategory == Category.WALL && + this.dynamicID - ITEM_WALLS.start == Terrarum.ingame!!.world.getTileFromWall(gc.mouseTileX, gc.mouseTileY) || + this.inventoryCategory == Category.WIRE && + this.dynamicID - ITEM_WIRES.start == Terrarum.ingame!!.world.getTileFromWire(gc.mouseTileX, gc.mouseTileY) + ) return false // filter passed, do the job @@ -167,7 +173,7 @@ object ItemCodex { /** * Returns clone of the item in the Codex */ - operator fun get(code: Int): InventoryItem { + operator fun get(code: ItemID): InventoryItem { if (code <= ITEM_STATIC.endInclusive) // generic item return itemCodex[code]!!.clone() // from CSV else if (code <= ITEM_DYNAMIC.endInclusive) { @@ -184,25 +190,31 @@ object ItemCodex { /** * Mainly used by GameItemLoader */ - operator fun set(code: Int, item: InventoryItem) { + operator fun set(code: ItemID, item: InventoryItem) { itemCodex[code] = item } fun getItemImage(item: InventoryItem): Image { // terrain if (item.originalID in ITEM_TILES) { - return BlocksDrawer.tilesTerrain.getSubImage((item.dynamicID % 16) * 16, item.originalID / 16) + return BlocksDrawer.tilesTerrain.getSubImage( + (item.originalID % 16) * 16, + item.originalID / 16 + ) } // wall else if (item.originalID in ITEM_WALLS) { - val img = BlocksDrawer.tilesTerrain.getSubImage((item.originalID % 16) * 16, item.originalID / 16) - img.setImageColor(wallOverlayColour.r, wallOverlayColour.g, wallOverlayColour.b) - return img + return BlocksDrawer.tileItemWall.getSubImage( + (item.originalID.minus(ITEM_WALLS.first) % 16) * TILE_SIZE, + (item.originalID.minus(ITEM_WALLS.first) / 16) * TILE_SIZE, + TILE_SIZE, TILE_SIZE + ) } // wire else if (item.originalID in ITEM_WIRES) { return BlocksDrawer.tilesWire.getSubImage((item.originalID % 16) * 16, item.originalID / 16) } + // TODO get it real, using originalID...? else return itemImagePlaceholder } diff --git a/src/net/torvald/terrarum/ui/UIPieMenu.kt b/src/net/torvald/terrarum/ui/UIPieMenu.kt index 90afdb0e9..080cb9daa 100644 --- a/src/net/torvald/terrarum/ui/UIPieMenu.kt +++ b/src/net/torvald/terrarum/ui/UIPieMenu.kt @@ -4,6 +4,8 @@ import com.jme3.math.FastMath import net.torvald.terrarum.Millisec import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gameactors.AVKey +import net.torvald.terrarum.itemproperties.ItemCodex +import net.torvald.terrarum.ui.UIQuickBar.Companion.CELL_SIZE import org.dyn4j.geometry.Vector2 import org.newdawn.slick.Color import org.newdawn.slick.GameContainer @@ -60,14 +62,34 @@ class UIPieMenu : UICanvas { else ItemSlotImageBuilder.produce(color, i + 1) + val slotSize = image.width + + val slotX = slotCentrePoint.x.toFloat() - (slotSize / 2) + Terrarum.HALFW + val slotY = slotCentrePoint.y.toFloat() - (slotSize / 2) + Terrarum.HALFH + g.drawImage( image, - slotCentrePoint.x.toFloat() - (image.width / 2) + Terrarum.HALFW, - slotCentrePoint.y.toFloat() - (image.width / 2) + Terrarum.HALFH, + slotX, + slotY, Color(1f, 1f, 1f, handler!!.opacity * UIQuickBar.finalOpacity) ) - // TODO draw item + + // draw item + val itemPair = Terrarum.ingame!!.player!!.inventory.getQuickBar(i) + + if (itemPair != null) { + val itemImage = ItemCodex.getItemImage(itemPair.item) + val itemW = itemImage.width + val itemH = itemImage.height + + g.drawImage( + itemImage, // using fixed CELL_SIZE for reasons + slotX + (CELL_SIZE - itemW) / 2f, + slotY + (CELL_SIZE - itemH) / 2f, + Color(1f, 1f, 1f, handler!!.opacity * UIQuickBar.finalOpacity) + ) + } } } diff --git a/src/net/torvald/terrarum/ui/UIQuickBar.kt b/src/net/torvald/terrarum/ui/UIQuickBar.kt index 699c34c07..8df87093a 100644 --- a/src/net/torvald/terrarum/ui/UIQuickBar.kt +++ b/src/net/torvald/terrarum/ui/UIQuickBar.kt @@ -3,6 +3,7 @@ package net.torvald.terrarum.ui import net.torvald.terrarum.Millisec import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gameactors.AVKey +import net.torvald.terrarum.itemproperties.ItemCodex import org.newdawn.slick.Color import org.newdawn.slick.GameContainer import org.newdawn.slick.Graphics @@ -41,18 +42,37 @@ class UIQuickBar : UICanvas, MouseControlled { else ItemSlotImageBuilder.COLOR_BLACK + val image = if (i == selection) + ItemSlotImageBuilder.produceLarge(color, i + 1) + else + ItemSlotImageBuilder.produce(color, i + 1) + + val slotX = startPointX + (CELL_SIZE + gutter).times(i).toFloat() + val slotY = startPointY.toFloat() + // draw slots g.drawImage( - if (i == selection) - ItemSlotImageBuilder.produceLarge(color, i + 1) - else - ItemSlotImageBuilder.produce(color, i + 1), - startPointX + (CELL_SIZE + gutter).times(i).toFloat(), - startPointY.toFloat(), - Color(1f, 1f, 1f, handler!!.opacity * 0.8f) + image, + slotX, + slotY, + Color(1f, 1f, 1f, handler!!.opacity * finalOpacity) ) - // draw items + // draw item + val itemPair = Terrarum.ingame!!.player!!.inventory.getQuickBar(i) + + if (itemPair != null) { + val itemImage = ItemCodex.getItemImage(itemPair.item) + val itemW = itemImage.width + val itemH = itemImage.height + + g.drawImage( + itemImage, // using fixed CELL_SIZE for reasons + slotX + (CELL_SIZE - itemW) / 2f, + slotY + (CELL_SIZE - itemH) / 2f, + Color(1f, 1f, 1f, handler!!.opacity * UIQuickBar.finalOpacity) + ) + } } } diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt index b3dc4a9f8..444245574 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt @@ -7,12 +7,14 @@ import net.torvald.terrarum.blockproperties.BlockCodex import com.jme3.math.FastMath import net.torvald.terrarum.* import net.torvald.terrarum.gameactors.roundInt +import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_TILES import net.torvald.terrarum.worlddrawer.WorldCamera.x import net.torvald.terrarum.worlddrawer.WorldCamera.y import net.torvald.terrarum.worlddrawer.WorldCamera.height import net.torvald.terrarum.worlddrawer.WorldCamera.width import org.lwjgl.opengl.GL11 import org.newdawn.slick.* +import org.newdawn.slick.imageout.ImageOut /** @@ -31,6 +33,11 @@ object BlocksDrawer { val tilesWire = SpriteSheet(ModMgr.getPath("basegame", "blocks/wire.tga.gz"), TILE_SIZE, TILE_SIZE) + val tileItemWall = Image(TILE_SIZE * 16, TILE_SIZE * GameWorld.TILES_SUPPORTED / 16) + + + val wallOverlayColour = Color(2f/3f, 2f/3f, 2f/3f, 1f) + val breakAnimSteps = 10 val WALL = GameWorld.WALL @@ -47,6 +54,30 @@ object BlocksDrawer { private val NEARBY_TILE_CODE_DOWN = 4 private val NEARBY_TILE_CODE_LEFT = 8 + + init { + val tg = tileItemWall.graphics + + // initialise item_wall images + (ITEM_TILES).forEach { + tg.drawImage( + tilesTerrain.getSubImage( + (it % 16) * 16, + (it / 16) + ), + (it % 16) * TILE_SIZE.toFloat(), + (it / 16) * TILE_SIZE.toFloat(), + wallOverlayColour + ) + } + + //tg.flush() + //ImageOut.write(tileItemWall, "./tileitemwalltest.png") + + tg.destroy() + } + + /** * Connectivity group 01 : artificial tiles * It holds different shading rule to discriminate with group 02, index 0 is single tile. @@ -228,8 +259,6 @@ object BlocksDrawer { val player = Terrarum.ingame!!.player } - val wallOverlayColour = Color(2f/3f, 2f/3f, 2f/3f, 1f) - fun renderWall(g: Graphics) { /** * render to camera