You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.0 KiB
Kotlin
37 lines
1.0 KiB
Kotlin
package com.last.commit.inventory
|
|
|
|
import com.badlogic.gdx.scenes.scene2d.Actor
|
|
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
|
import com.badlogic.gdx.graphics.g2d.Batch
|
|
|
|
class Inventory: Actor() {
|
|
|
|
val textureLoader = InventoryItemTextureLoader("sprites/genericItems_spritesheet_colored")
|
|
val items: MutableList<InventoryItem> = ArrayList()
|
|
public var updated = false
|
|
private set
|
|
|
|
override fun draw(batch: Batch, delta: Float) {
|
|
items.mapIndexed { index, inventoryItem ->
|
|
val image = Image(textureLoader.getTexture(inventoryItem.name))
|
|
image.x = index * 32f
|
|
image.width = 32f
|
|
image.height = 32f
|
|
|
|
image
|
|
}.forEach{image -> image.draw(batch, 1f)}
|
|
}
|
|
|
|
/**
|
|
* @param name the name of the subtexture loaded from xml
|
|
*/
|
|
fun add(name: String) {
|
|
items.add(InventoryItem(name))
|
|
this.updated = true
|
|
}
|
|
|
|
fun remove(name: String) {
|
|
items.removeIf() {item -> item.name == name}
|
|
}
|
|
|
|
} |