rework inventory handling

viewport-stuff
Matthias 2 years ago
parent 11c13170bc
commit edfeb7b645

@ -198,6 +198,7 @@ class FirstScreen : Screen, InputProcessor {
}
override fun resize(width: Int, height: Int) {
inventoryStage.resize(width, height)
// Resize your screen here. The parameters represent the new window size.
}
@ -238,8 +239,10 @@ class FirstScreen : Screen, InputProcessor {
map.teleport(player)
} else if (character == 'i') {
inventoryStage.visible = !inventoryStage.visible
} else if (character == 'p') {
player.inventory.add("compass")
inventoryStage.refresh()
}
// TODO Auto-generated method stub
return false
}

@ -15,7 +15,7 @@ class Player(private val textureRegion: TextureRegion) : Collidable {
private val movementSpeed = 200f
private val interactionRange = 60f
val inventory = Inventory()
val inventory = Inventory("sprites/genericItems_spritesheet_colored")
init {
val size = Math.max(textureRegion.regionWidth, textureRegion.regionHeight).toFloat()

@ -1,14 +1,17 @@
package com.last.commit.inventory
class Inventory {
class Inventory(path: String) {
val items: MutableList<InventoryItem> = ArrayList()
val textureLoader = InventoryItemTextureLoader("sprites/genericItems_spritesheet_colored")
val textureLoader = InventoryItemTextureLoader(path)
init {
textureLoader.parse()
}
/**
* @param name the name of the subtexture loaded from xml
*/
fun add(name: String) {
items.add(InventoryItem(name, textureLoader.loadTexture(name)))
}

@ -4,14 +4,21 @@ import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.last.commit.inventory.Inventory
class InventoryStage(inventory: Inventory) : Stage() {
class InventoryStage(val inventory: Inventory) : Stage() {
var visible = false
set(visible) {
field = visible
if (visible) {
refresh()
}
}
init {
for (item in inventory.items) {
val image = Image(item.texture)
fun refresh() {
super.clear()
inventory.items.forEachIndexed { index, inventoryItem ->
val image = Image(inventoryItem.texture)
image.x = index * 32f
image.width = 32f
image.height = 32f

Loading…
Cancel
Save