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

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

@ -1,14 +1,17 @@
package com.last.commit.inventory package com.last.commit.inventory
class Inventory { class Inventory(path: String) {
val items: MutableList<InventoryItem> = ArrayList() val items: MutableList<InventoryItem> = ArrayList()
val textureLoader = InventoryItemTextureLoader("sprites/genericItems_spritesheet_colored") val textureLoader = InventoryItemTextureLoader(path)
init { init {
textureLoader.parse() textureLoader.parse()
} }
/**
* @param name the name of the subtexture loaded from xml
*/
fun add(name: String) { fun add(name: String) {
items.add(InventoryItem(name, textureLoader.loadTexture(name))) 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.badlogic.gdx.scenes.scene2d.ui.Image
import com.last.commit.inventory.Inventory import com.last.commit.inventory.Inventory
class InventoryStage(inventory: Inventory) : Stage() { class InventoryStage(val inventory: Inventory) : Stage() {
var visible = false var visible = false
set(visible) {
field = visible
if (visible) {
refresh()
}
}
init { fun refresh() {
for (item in inventory.items) { super.clear()
inventory.items.forEachIndexed { index, inventoryItem ->
val image = Image(item.texture) val image = Image(inventoryItem.texture)
image.x = index * 32f
image.width = 32f image.width = 32f
image.height = 32f image.height = 32f

Loading…
Cancel
Save