Add hotbar gui

This commit is contained in:
IntegratedQuantum 2019-03-28 23:09:03 +01:00
parent 6b3b5edd09
commit 9e89e51181
8 changed files with 58 additions and 30 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 479 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

View File

@ -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;

View File

@ -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

View File

@ -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;
}
}

View File

@ -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.<br/>
* Should be between <i>1</i> and <i>64</i>

View File

@ -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;
// }
}