diff --git a/cubyz-client/assets/cubyz/guis/inventory/inventory_bar.png b/cubyz-client/assets/cubyz/guis/inventory/inventory_bar.png new file mode 100644 index 00000000..410be1df Binary files /dev/null and b/cubyz-client/assets/cubyz/guis/inventory/inventory_bar.png differ diff --git a/cubyz-client/assets/cubyz/guis/inventory/inventory_container.png b/cubyz-client/assets/cubyz/guis/inventory/inventory_container.png new file mode 100644 index 00000000..87dfa5a7 Binary files /dev/null and b/cubyz-client/assets/cubyz/guis/inventory/inventory_container.png differ diff --git a/cubyz-client/assets/cubyz/guis/inventory/selected_slot.png b/cubyz-client/assets/cubyz/guis/inventory/selected_slot.png new file mode 100644 index 00000000..18a31a3c Binary files /dev/null and b/cubyz-client/assets/cubyz/guis/inventory/selected_slot.png differ diff --git a/cubyz-client/src/io/cubyz/client/Cubyz.java b/cubyz-client/src/io/cubyz/client/Cubyz.java index 609985a0..444e0f37 100644 --- a/cubyz-client/src/io/cubyz/client/Cubyz.java +++ b/cubyz-client/src/io/cubyz/client/Cubyz.java @@ -71,8 +71,8 @@ public class Cubyz implements IGameLogic { public static UISystem gameUI; public static World world; - private int inventorySelection = 0; // Selected slot in inventory - private static Inventory inventory; + public static int inventorySelection = 0; // Selected slot in inventory + public static Inventory inventory; private CubyzMeshSelectionDetector msd; diff --git a/cubyz-client/src/io/cubyz/ui/GameOverlay.java b/cubyz-client/src/io/cubyz/ui/GameOverlay.java index 0d792237..a72509e4 100644 --- a/cubyz-client/src/io/cubyz/ui/GameOverlay.java +++ b/cubyz-client/src/io/cubyz/ui/GameOverlay.java @@ -1,19 +1,53 @@ package io.cubyz.ui; import org.jungle.Window; +import org.jungle.hud.Font; + +import io.cubyz.client.Cubyz; +import io.cubyz.items.Inventory; +import io.cubyz.items.Item; +import io.cubyz.ui.components.Label; public class GameOverlay extends MenuGUI { int crosshair; + int hotBar; + int selection; + + private Label inv [] = new Label[8]; @Override public void init(long nvg) { crosshair = NGraphics.loadImage("assets/cubyz/textures/crosshair.png"); + hotBar = NGraphics.loadImage("assets/cubyz/guis/inventory/inventory_bar.png"); + selection = NGraphics.loadImage("assets/cubyz/guis/inventory/selected_slot.png"); + for(int i = 0; i < 8; i++) { + inv[i] = new Label(); + inv[i].setFont(new Font("OpenSans Bold", 16.f)); + } } @Override public void render(long nvg, Window win) { NGraphics.drawImage(crosshair, win.getWidth() / 2 - 16, win.getHeight() / 2 - 16, 32, 32); + NGraphics.drawImage(hotBar, win.getWidth()/2 - 255, win.getHeight() - 64, 510, 64); + NGraphics.setColor(0, 0, 0); + Inventory inventory = Cubyz.inventory; + for(int i = 0; i < 8; i++) { + Item item = inventory.getItem(i); + if(item != null) { + if(item.getImage() == -1) { + item.setImage(NGraphics.loadImage(item.getTexture())); + } + NGraphics.drawImage(item.getImage(), win.getWidth()/2 - 255 + i*510/8+2, win.getHeight() - 62, 510/8-4, 60); + if(i == Cubyz.inventorySelection) { + NGraphics.drawImage(selection, win.getWidth()/2 - 255 + i*510/8+2, win.getHeight() - 62, 510/8-4, 60); + } + inv[i].setText("" + inventory.getAmount(i)); + inv[i].setPosition(win.getWidth()/2 - 255 + (i+1)*510/8 - 16, win.getHeight()-16); + inv[i].render(nvg, win); + } + } } @Override diff --git a/cubyz-common/src/io/cubyz/items/Inventory.java b/cubyz-common/src/io/cubyz/items/Inventory.java index da843815..fe843a92 100644 --- a/cubyz-common/src/io/cubyz/items/Inventory.java +++ b/cubyz-common/src/io/cubyz/items/Inventory.java @@ -57,4 +57,16 @@ public class Inventory { return null; return items[selection].getBlock(); } + + public Item getItem(int selection) { + if(items[selection] == null) + return null; + return items[selection].getItem(); + } + + public int getAmount(int selection) { + if(items[selection] == null) + return 0; + return items[selection].number; + } } diff --git a/cubyz-common/src/io/cubyz/items/Item.java b/cubyz-common/src/io/cubyz/items/Item.java index d0b6ce3a..fa6d1aed 100644 --- a/cubyz-common/src/io/cubyz/items/Item.java +++ b/cubyz-common/src/io/cubyz/items/Item.java @@ -5,8 +5,7 @@ import io.cubyz.api.Resource; public class Item implements IRegistryElement { - //Texture _textureCache; - //Mesh _meshCache; + private int image = -1; protected String texturePath; protected String modelPath; @@ -22,6 +21,14 @@ public class Item implements IRegistryElement { this.texturePath = "./res/textures/items/" + texturePath; } + public void setImage(int image) { + this.image = image; + } + + public int getImage() { + return image; + } + /** * Sets the maximum stack size of an item.
* Should be between 1 and 64 diff --git a/cubyz-common/src/io/cubyz/items/ItemStack.java b/cubyz-common/src/io/cubyz/items/ItemStack.java index 27968f92..16bb26d9 100644 --- a/cubyz-common/src/io/cubyz/items/ItemStack.java +++ b/cubyz-common/src/io/cubyz/items/ItemStack.java @@ -15,29 +15,11 @@ public class ItemStack { public ItemStack(Block block) { this.block = block; item = new Item(); - item.setTexture(block.getTexture()); + item.setTexture("blocks/"+block.getTexture()+".png"); } public void update() {} -// public Mesh getMesh() { -// if (item._textureCache == null) { -// try { -// if (item.fullTexturePath == null) { -// item._textureCache = new Texture("./res/textures/items/" + item.getTexture() + ".png"); -// } else { -// item._textureCache = new Texture("./res/textures/" + item.fullTexturePath + ".png"); -// } -// item._meshCache = OBJLoader.loadMesh("res/models/cube.obj"); -// Material material = new Material(item._textureCache, 1.0F); -// item._meshCache.setMaterial(material); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// } -// return item._meshCache; -// } - public boolean filled() { return number >= item.stackSize; } @@ -67,11 +49,4 @@ public class ItemStack { return block; } -// public Spatial getSpatial() { -// if (spatial == null) { -// spatial = new Spatial(getMesh()); -// } -// return spatial; -// } - } \ No newline at end of file