mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-09 20:28:57 -04:00
Add hotbar gui
This commit is contained in:
parent
6b3b5edd09
commit
9e89e51181
BIN
cubyz-client/assets/cubyz/guis/inventory/inventory_bar.png
Normal file
BIN
cubyz-client/assets/cubyz/guis/inventory/inventory_bar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 479 B |
BIN
cubyz-client/assets/cubyz/guis/inventory/inventory_container.png
Normal file
BIN
cubyz-client/assets/cubyz/guis/inventory/inventory_container.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
BIN
cubyz-client/assets/cubyz/guis/inventory/selected_slot.png
Normal file
BIN
cubyz-client/assets/cubyz/guis/inventory/selected_slot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 128 B |
@ -71,8 +71,8 @@ public class Cubyz implements IGameLogic {
|
|||||||
public static UISystem gameUI;
|
public static UISystem gameUI;
|
||||||
public static World world;
|
public static World world;
|
||||||
|
|
||||||
private int inventorySelection = 0; // Selected slot in inventory
|
public static int inventorySelection = 0; // Selected slot in inventory
|
||||||
private static Inventory inventory;
|
public static Inventory inventory;
|
||||||
|
|
||||||
private CubyzMeshSelectionDetector msd;
|
private CubyzMeshSelectionDetector msd;
|
||||||
|
|
||||||
|
@ -1,19 +1,53 @@
|
|||||||
package io.cubyz.ui;
|
package io.cubyz.ui;
|
||||||
|
|
||||||
import org.jungle.Window;
|
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 {
|
public class GameOverlay extends MenuGUI {
|
||||||
|
|
||||||
int crosshair;
|
int crosshair;
|
||||||
|
int hotBar;
|
||||||
|
int selection;
|
||||||
|
|
||||||
|
private Label inv [] = new Label[8];
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(long nvg) {
|
public void init(long nvg) {
|
||||||
crosshair = NGraphics.loadImage("assets/cubyz/textures/crosshair.png");
|
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
|
@Override
|
||||||
public void render(long nvg, Window win) {
|
public void render(long nvg, Window win) {
|
||||||
NGraphics.drawImage(crosshair, win.getWidth() / 2 - 16, win.getHeight() / 2 - 16, 32, 32);
|
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
|
@Override
|
||||||
|
@ -57,4 +57,16 @@ public class Inventory {
|
|||||||
return null;
|
return null;
|
||||||
return items[selection].getBlock();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,7 @@ import io.cubyz.api.Resource;
|
|||||||
|
|
||||||
public class Item implements IRegistryElement {
|
public class Item implements IRegistryElement {
|
||||||
|
|
||||||
//Texture _textureCache;
|
private int image = -1;
|
||||||
//Mesh _meshCache;
|
|
||||||
|
|
||||||
protected String texturePath;
|
protected String texturePath;
|
||||||
protected String modelPath;
|
protected String modelPath;
|
||||||
@ -22,6 +21,14 @@ public class Item implements IRegistryElement {
|
|||||||
this.texturePath = "./res/textures/items/" + texturePath;
|
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/>
|
* Sets the maximum stack size of an item.<br/>
|
||||||
* Should be between <i>1</i> and <i>64</i>
|
* Should be between <i>1</i> and <i>64</i>
|
||||||
|
@ -15,29 +15,11 @@ public class ItemStack {
|
|||||||
public ItemStack(Block block) {
|
public ItemStack(Block block) {
|
||||||
this.block = block;
|
this.block = block;
|
||||||
item = new Item();
|
item = new Item();
|
||||||
item.setTexture(block.getTexture());
|
item.setTexture("blocks/"+block.getTexture()+".png");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {}
|
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() {
|
public boolean filled() {
|
||||||
return number >= item.stackSize;
|
return number >= item.stackSize;
|
||||||
}
|
}
|
||||||
@ -67,11 +49,4 @@ public class ItemStack {
|
|||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public Spatial getSpatial() {
|
|
||||||
// if (spatial == null) {
|
|
||||||
// spatial = new Spatial(getMesh());
|
|
||||||
// }
|
|
||||||
// return spatial;
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user