From 9e89e51181dd88bff80a5c53cb610a79a59e6c0d Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Thu, 28 Mar 2019 23:09:03 +0100 Subject: [PATCH] Add hotbar gui --- .../cubyz/guis/inventory/inventory_bar.png | Bin 0 -> 479 bytes .../guis/inventory/inventory_container.png | Bin 0 -> 3459 bytes .../cubyz/guis/inventory/selected_slot.png | Bin 0 -> 128 bytes cubyz-client/src/io/cubyz/client/Cubyz.java | 4 +-- cubyz-client/src/io/cubyz/ui/GameOverlay.java | 34 ++++++++++++++++++ .../src/io/cubyz/items/Inventory.java | 12 +++++++ cubyz-common/src/io/cubyz/items/Item.java | 11 ++++-- .../src/io/cubyz/items/ItemStack.java | 27 +------------- 8 files changed, 58 insertions(+), 30 deletions(-) create mode 100644 cubyz-client/assets/cubyz/guis/inventory/inventory_bar.png create mode 100644 cubyz-client/assets/cubyz/guis/inventory/inventory_container.png create mode 100644 cubyz-client/assets/cubyz/guis/inventory/selected_slot.png 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 0000000000000000000000000000000000000000..410be1df12465c857ccb96c6b01deae864d340d8 GIT binary patch literal 479 zcmeAS@N?(olHy`uVBq!ia0y~yVEhMUJ8-Z8$=^3brvNFoByV>YhW{YAVDIwDKoQOY zkH}&M2EM}}%y>M1MG8=my~NYkmHjcZjHm?1bT@@=piw!VE{-7;x8B}z83Yzq)@JnQ-udx#W5~DL z`MZnr_ivuRWpCyFidVa4NE=N5RCxB^oxj_xzkjp-t$CXtsA2KVT@`!hyxz+3?|Ied_rAAF-fv#Vz@hYqLE#TW!v|)DL;MUJ_P98BB_Z1AVa$R3 zv(|QBe!EZYzR2(5@3-IG0R{xn7YXz8{}gLpG(Y?=Y4=-T;QT%Z3^TX?dsrDf=h+=; Vju(`$`wff=22WQ%mvv4FO#r0?x%dD8 literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..87dfa5a7561e446964adea2909aa558223591456 GIT binary patch literal 3459 zcmeAS@N?(olHy`uVBq!ia0y~yU;;9k7&w@L)Zt|+Cx8@Vage(c!@6@aFM%AEbVpxD z28NCO+PgJ9P9IkUa`ULtsROz%2iRIlz3vP!i-9{C{Kv zhT!k)s=&zSEbxddW?$B>G+x7Qr=R!1^R1r^$f?t86Imld=x$KgDati)nFf!MEr0Uj%WOnx%oHWgZt{gKR@5IWBX&tbE~VX z-<|KS{{3}%J?n@2e{1(Peg1TAUw=W|{hRE6zP;pTD1N)1q3^u)?zn@Mzu(pM72Mmu zyZ^`A%i;{rZVgu)&v@tFYtcLRDqC*dWOn-d?T`R54ufex@CJuWRqv z`(}SAFtGe({Qp{T R%6FgygQu&X%Q~loCIBxwA*lcW literal 0 HcmV?d00001 diff --git a/cubyz-client/src/io/cubyz/client/Cubyz.java b/cubyz-client/src/io/cubyz/client/Cubyz.java index 609985a09..444e0f37a 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 0d792237b..a72509e4d 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 da8438154..fe843a92e 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 d0b6ce3ad..fa6d1aed4 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 27968f927..16bb26d99 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