update inventory

add readable names for easier reference
update loading of files consistent (need to have same names)
viewport-stuff
Matthias 2 years ago
parent 0a1dc86a26
commit 796f2bead0

@ -1,5 +1,5 @@
<TextureAtlas imagePath="sprites.png">
<SubTexture name="genericItem_color_001.png" x="0" y="322" width="162" height="94"/>
<SubTexture name="drill" x="0" y="322" width="162" height="94"/>
<SubTexture name="genericItem_color_002.png" x="136" y="1231" width="120" height="110"/>
<SubTexture name="genericItem_color_003.png" x="130" y="1791" width="89" height="45"/>
<SubTexture name="genericItem_color_004.png" x="623" y="1826" width="70" height="88"/>
@ -31,7 +31,7 @@
<SubTexture name="genericItem_color_030.png" x="367" y="784" width="57" height="56"/>
<SubTexture name="genericItem_color_031.png" x="146" y="776" width="116" height="96"/>
<SubTexture name="genericItem_color_032.png" x="152" y="649" width="116" height="112"/>
<SubTexture name="genericItem_color_033.png" x="0" y="1879" width="128" height="114"/>
<SubTexture name="red_book_back" x="0" y="1879" width="128" height="114"/>
<SubTexture name="genericItem_color_034.png" x="461" y="1314" width="90" height="128"/>
<SubTexture name="genericItem_color_035.png" x="256" y="1514" width="109" height="125"/>
<SubTexture name="genericItem_color_036.png" x="373" y="436" width="94" height="98"/>
@ -44,21 +44,21 @@
<SubTexture name="genericItem_color_043.png" x="256" y="1639" width="54" height="37"/>
<SubTexture name="genericItem_color_044.png" x="462" y="1057" width="88" height="75"/>
<SubTexture name="genericItem_color_045.png" x="365" y="1611" width="96" height="70"/>
<SubTexture name="genericItem_color_046.png" x="0" y="532" width="152" height="88"/>
<SubTexture name="camera" x="0" y="532" width="152" height="88"/>
<SubTexture name="genericItem_color_047.png" x="134" y="1514" width="112" height="80"/>
<SubTexture name="genericItem_color_048.png" x="460" y="1738" width="93" height="117"/>
<SubTexture name="genericItem_color_049.png" x="0" y="0" width="174" height="99"/>
<SubTexture name="genericItem_color_050.png" x="0" y="1027" width="143" height="136"/>
<SubTexture name="genericItem_color_051.png" x="0" y="1231" width="136" height="129"/>
<SubTexture name="laptop_back" x="0" y="0" width="174" height="99"/>
<SubTexture name="laptop_front" x="0" y="1027" width="143" height="136"/>
<SubTexture name="monitor" x="0" y="1231" width="136" height="129"/>
<SubTexture name="genericItem_color_052.png" x="162" y="322" width="114" height="134"/>
<SubTexture name="genericItem_color_053.png" x="0" y="191" width="163" height="131"/>
<SubTexture name="screen_wide_front" x="0" y="191" width="163" height="131"/>
<SubTexture name="genericItem_color_054.png" x="363" y="1331" width="98" height="128"/>
<SubTexture name="genericItem_color_055.png" x="364" y="1804" width="96" height="135"/>
<SubTexture name="genericItem_color_056.png" x="0" y="1839" width="129" height="40"/>
<SubTexture name="genericItem_color_057.png" x="0" y="736" width="152" height="40"/>
<SubTexture name="genericItem_color_058.png" x="310" y="1639" width="46" height="38"/>
<SubTexture name="genericItem_color_059.png" x="261" y="1186" width="51" height="38"/>
<SubTexture name="genericItem_color_060.png" x="0" y="1163" width="141" height="68"/>
<SubTexture name="smartphone" x="0" y="1163" width="141" height="68"/>
<SubTexture name="genericItem_color_061.png" x="132" y="1686" width="52" height="13"/>
<SubTexture name="genericItem_color_062.png" x="626" y="1501" width="64" height="88"/>
<SubTexture name="genericItem_color_063.png" x="692" y="590" width="44" height="96"/>
@ -73,10 +73,10 @@
<SubTexture name="genericItem_color_072.png" x="553" y="1930" width="70" height="92"/>
<SubTexture name="genericItem_color_073.png" x="688" y="1178" width="58" height="79"/>
<SubTexture name="genericItem_color_074.png" x="261" y="1095" width="105" height="91"/>
<SubTexture name="genericItem_color_075.png" x="0" y="1360" width="134" height="122"/>
<SubTexture name="files" x="0" y="1360" width="134" height="122"/>
<SubTexture name="genericItem_color_076.png" x="155" y="456" width="112" height="76"/>
<SubTexture name="genericItem_color_077.png" x="132" y="1600" width="124" height="86"/>
<SubTexture name="genericItem_color_078.png" x="0" y="99" width="163" height="92"/>
<SubTexture name="graphics_card" x="0" y="99" width="163" height="92"/>
<SubTexture name="genericItem_color_079.png" x="626" y="1409" width="64" height="92"/>
<SubTexture name="genericItem_color_080.png" x="627" y="1279" width="62" height="99"/>
<SubTexture name="genericItem_color_081.png" x="367" y="1681" width="94" height="57"/>
@ -112,7 +112,7 @@
<SubTexture name="genericItem_color_111.png" x="254" y="1804" width="110" height="138"/>
<SubTexture name="genericItem_color_112.png" x="464" y="696" width="86" height="86"/>
<SubTexture name="genericItem_color_113.png" x="129" y="1839" width="125" height="194"/>
<SubTexture name="genericItem_color_114.png" x="0" y="776" width="146" height="104"/>
<SubTexture name="pot" x="0" y="776" width="146" height="104"/>
<SubTexture name="genericItem_color_115.png" x="470" y="232" width="86" height="134"/>
<SubTexture name="genericItem_color_116.png" x="369" y="632" width="95" height="152"/>
<SubTexture name="genericItem_color_117.png" x="111" y="2033" width="90" height="14"/>
@ -123,7 +123,7 @@
<SubTexture name="genericItem_color_122.png" x="691" y="1914" width="46" height="95"/>
<SubTexture name="genericItem_color_123.png" x="691" y="1710" width="47" height="95"/>
<SubTexture name="genericItem_color_124.png" x="145" y="880" width="117" height="113"/>
<SubTexture name="genericItem_color_125.png" x="0" y="620" width="152" height="116"/>
<SubTexture name="tea_pot" x="0" y="620" width="152" height="116"/>
<SubTexture name="genericItem_color_126.png" x="558" y="0" width="70" height="135"/>
<SubTexture name="genericItem_color_127.png" x="691" y="696" width="50" height="140"/>
<SubTexture name="genericItem_color_128.png" x="130" y="1709" width="124" height="82"/>
@ -131,22 +131,22 @@
<SubTexture name="genericItem_color_130.png" x="726" y="1805" width="27" height="97"/>
<SubTexture name="genericItem_color_131.png" x="736" y="571" width="20" height="106"/>
<SubTexture name="genericItem_color_132.png" x="254" y="1686" width="113" height="118"/>
<SubTexture name="genericItem_color_133.png" x="0" y="880" width="145" height="147"/>
<SubTexture name="file" x="0" y="880" width="145" height="147"/>
<SubTexture name="genericItem_color_134.png" x="461" y="1855" width="92" height="132"/>
<SubTexture name="genericItem_color_135.png" x="462" y="1132" width="88" height="140"/>
<SubTexture name="genericItem_color_136.png" x="626" y="1589" width="62" height="146"/>
<SubTexture name="genericItem_color_137.png" x="461" y="921" width="89" height="136"/>
<SubTexture name="genericItem_color_138.png" x="174" y="0" width="109" height="90"/>
<SubTexture name="genericItem_color_139.png" x="0" y="1600" width="132" height="109"/>
<SubTexture name="kitchen_machine" x="0" y="1600" width="132" height="109"/>
<SubTexture name="genericItem_color_140.png" x="276" y="278" width="100" height="158"/>
<SubTexture name="genericItem_color_141.png" x="143" y="1116" width="118" height="110"/>
<SubTexture name="genericItem_color_142.png" x="163" y="99" width="113" height="202"/>
<SubTexture name="genericItem_color_143.png" x="254" y="1942" width="109" height="98"/>
<SubTexture name="genericItem_color_144.png" x="461" y="784" width="89" height="137"/>
<SubTexture name="genericItem_color_145.png" x="0" y="416" width="155" height="116"/>
<SubTexture name="genericItem_color_146.png" x="0" y="1482" width="134" height="118"/>
<SubTexture name="genericItem_color_147.png" x="0" y="1709" width="130" height="130"/>
<SubTexture name="genericItem_color_148.png" x="262" y="840" width="101" height="135"/>
<SubTexture name="suitcase" x="0" y="416" width="155" height="116"/>
<SubTexture name="green_jug" x="0" y="1482" width="134" height="118"/>
<SubTexture name="steering_wheel" x="0" y="1709" width="130" height="130"/>
<SubTexture name="flight_manual" x="262" y="840" width="101" height="135"/>
<SubTexture name="genericItem_color_149.png" x="373" y="534" width="91" height="89"/>
<SubTexture name="genericItem_color_150.png" x="283" y="0" width="99" height="88"/>
<SubTexture name="genericItem_color_151.png" x="550" y="1175" width="76" height="130"/>
@ -156,10 +156,10 @@
<SubTexture name="genericItem_color_155.png" x="625" y="293" width="63" height="65"/>
<SubTexture name="genericItem_color_156.png" x="550" y="1075" width="77" height="100"/>
<SubTexture name="genericItem_color_157.png" x="363" y="1942" width="98" height="102"/>
<SubTexture name="genericItem_color_158.png" x="268" y="649" width="101" height="106"/>
<SubTexture name="money" x="268" y="649" width="101" height="106"/>
<SubTexture name="genericItem_color_159.png" x="405" y="1057" width="36" height="36"/>
<SubTexture name="genericItem_color_160.png" x="380" y="232" width="36" height="36"/>
<SubTexture name="genericItem_color_161.png" x="145" y="993" width="24" height="24"/>
<SubTexture name="genericItem_color_162.png" x="262" y="761" width="105" height="79"/>
<SubTexture name="compass" x="262" y="761" width="105" height="79"/>
<SubTexture name="genericItem_color_163.png" x="474" y="98" width="83" height="76"/>
</TextureAtlas>

@ -43,7 +43,7 @@ class FirstScreen : Screen, InputProcessor {
this.spawnPlayer()
this.updateCamera()
player.addItemToInventory("genericItem_color_001.png")
player.addItemToInventory("drill")
inventoryStage = InventoryStage(player.inventory)
Gdx.input.setInputProcessor(this)

@ -3,7 +3,7 @@ package com.last.commit.inventory
class Inventory {
val items: MutableList<InventoryItem> = ArrayList()
val textureLoader = InventoryItemTextureLoader()
val textureLoader = InventoryItemTextureLoader("sprites/genericItems_spritesheet_colored")
init {
textureLoader.parse()

@ -1,16 +1,23 @@
package com.last.commit.inventory
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.files.FileHandle
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.utils.Array
import com.badlogic.gdx.utils.XmlReader
class InventoryItemTextureLoader {
class InventoryItemTextureLoader(path: String) {
private val itemsSpriteSheet = Texture("sprites/genericItems_spritesheet_colored.png")
private val itemsSpriteSheet: Texture
private val textureMapping: FileHandle
private lateinit var subTextures: Array<XmlReader.Element>
init {
itemsSpriteSheet = Texture("${path}.png")
textureMapping = Gdx.files.local("${path}.xml")
}
fun loadTexture(itemName: String): TextureRegion {
var subtexture = subTextures.first { it.getAttribute("name") == itemName }
val x = subtexture.getIntAttribute("x")
@ -22,7 +29,7 @@ class InventoryItemTextureLoader {
fun parse() {
val xml = XmlReader()
val textureAtlasElement = xml.parse(Gdx.files.local("sprites/genericItems_spritesheet_colored.xml"))
val textureAtlasElement = xml.parse(textureMapping)
this.subTextures = textureAtlasElement.getChildrenByName("SubTexture")
println("Found ${subTextures.size} textures")
}

Loading…
Cancel
Save