183 lines
5.7 KiB
Java
183 lines
5.7 KiB
Java
package projectzombie.display;
|
|
|
|
import projectzombie.Main;
|
|
import projectzombie.display.bossbar.BossBars;
|
|
import projectzombie.entity.player.EntityPlayer;
|
|
import projectzombie.init.Textures;
|
|
import projectzombie.inventory.Inventory;
|
|
import projectzombie.text.Text;
|
|
import projectzombie.util.gl.GlHelpers;
|
|
import projectzombie.util.gl.texture.TextureReference;
|
|
import projectzombie.util.math.ItemStack;
|
|
import projectzombie.util.math.vec.Vec2d;
|
|
|
|
public class DisplayRenderUI
|
|
{
|
|
|
|
|
|
public static void render()
|
|
{
|
|
// Get the player
|
|
EntityPlayer player = Main.player;
|
|
|
|
// Disable some opengl options
|
|
GlHelpers.disableDepthTest();
|
|
GlHelpers.color4(1, 1, 1, 1);
|
|
|
|
// Get the aspect ratio
|
|
double aspect_ratio = (
|
|
((double) Main.window.getWidth()) /
|
|
((double) Main.window.getHeight()));
|
|
|
|
// Get some text settings
|
|
Vec2d text_size = new Vec2d(0.45, 0.45);
|
|
|
|
/*// Render the fps
|
|
GlHelpers.pushMatrix();
|
|
GlHelpers.translate2(-9.5, 9.5);
|
|
GlHelpers.color3(1, 1, 0);
|
|
Text.render("FPS: " + DisplayStatsEventHandler.fps, text_size);
|
|
GlHelpers.popMatrix();*/
|
|
|
|
if(Main.menu.doGameRender)
|
|
{
|
|
/*// Render the fps and the position
|
|
GlHelpers.pushMatrix();
|
|
GlHelpers.translate2(-9.5, 9);
|
|
GlHelpers.color3(1, 1, 0);
|
|
Text.render("x: " + (int) player.pos.x + ", y: " + (int) player.pos.y, text_size);
|
|
GlHelpers.color3(1, 1, 1);
|
|
GlHelpers.popMatrix();*/
|
|
|
|
// Render the healthbar
|
|
double max_health = player.maxHealth();
|
|
double a = 1 - (player.getHealth() / max_health);
|
|
TextureReference health_fg = Textures.UI_HEALTH_FG;
|
|
TextureReference health_bg = Textures.UI_HEALTH_BG;
|
|
|
|
GlHelpers.pushMatrix();
|
|
GlHelpers.translate2(-2, -9);
|
|
GlHelpers.begin();
|
|
|
|
health_bg.texCoord(0, 1); GlHelpers.vertex2(-8, 1);
|
|
health_bg.texCoord(0, 0); GlHelpers.vertex2(-8, 0);
|
|
health_bg.texCoord(1, 0); GlHelpers.vertex2(8, 0);
|
|
health_bg.texCoord(1, 1); GlHelpers.vertex2(8, 1);
|
|
|
|
health_fg.texCoord(0, 1); GlHelpers.vertex2(-8, 1);
|
|
health_fg.texCoord(0, 0); GlHelpers.vertex2(-8, 0);
|
|
health_fg.texCoord(1-a, 0); GlHelpers.vertex2(8-a*16, 0);
|
|
health_fg.texCoord(1-a, 1); GlHelpers.vertex2(8-a*16, 1);
|
|
|
|
GlHelpers.end();
|
|
GlHelpers.popMatrix();
|
|
|
|
// Display the amount of ammo left, and the defence and gun level
|
|
GlHelpers.pushMatrix();
|
|
TextureReference ammo_tex = Textures.ITEM_AMMO_BOX;
|
|
TextureReference gunlevel_tex = Textures.UI_GUN_LEVEL;
|
|
TextureReference deflevel_tex = Textures.UI_DEFENCE_LEVEL;
|
|
|
|
GlHelpers.translate2(-9.5, -9);
|
|
GlHelpers.begin();
|
|
ammo_tex.texCoord(0, 1); GlHelpers.vertex2(0, 0);
|
|
ammo_tex.texCoord(0, 0); GlHelpers.vertex2(0, 2);
|
|
ammo_tex.texCoord(1, 0); GlHelpers.vertex2(2, 2);
|
|
ammo_tex.texCoord(1, 1); GlHelpers.vertex2(2, 0);
|
|
GlHelpers.end();
|
|
|
|
GlHelpers.translate2(0, 2.5);
|
|
GlHelpers.begin();
|
|
gunlevel_tex.texCoord(0, 1); GlHelpers.vertex2(0, 0);
|
|
gunlevel_tex.texCoord(0, 0); GlHelpers.vertex2(0, 2);
|
|
gunlevel_tex.texCoord(1, 0); GlHelpers.vertex2(2, 2);
|
|
gunlevel_tex.texCoord(1, 1); GlHelpers.vertex2(2, 0);
|
|
GlHelpers.end();
|
|
|
|
GlHelpers.translate2(0, 2.5);
|
|
GlHelpers.begin();
|
|
deflevel_tex.texCoord(0, 1); GlHelpers.vertex2(0, 0);
|
|
deflevel_tex.texCoord(0, 0); GlHelpers.vertex2(0, 2);
|
|
deflevel_tex.texCoord(1, 0); GlHelpers.vertex2(2, 2);
|
|
deflevel_tex.texCoord(1, 1); GlHelpers.vertex2(2, 0);
|
|
GlHelpers.end();
|
|
|
|
GlHelpers.popMatrix();
|
|
GlHelpers.pushMatrix();
|
|
GlHelpers.translate2(-8.5, -9.25);
|
|
Text.render(Integer.toString(player.ammo), text_size);
|
|
GlHelpers.translate2(0, 3);
|
|
Text.render(Integer.toString(player.gun_level), text_size);
|
|
GlHelpers.translate2(0, 2);
|
|
Text.render(Integer.toString(player.defence_level), text_size);
|
|
GlHelpers.popMatrix();
|
|
|
|
// Display all the items in the players inventory
|
|
TextureReference slots_tex = Textures.UI_ITEM_SLOTS;
|
|
|
|
GlHelpers.pushMatrix();
|
|
GlHelpers.translate2(3, -9.5);
|
|
|
|
GlHelpers.begin();
|
|
slots_tex.texCoord(0, 1); GlHelpers.vertex2(12, 2);
|
|
slots_tex.texCoord(0, 0); GlHelpers.vertex2(12, 0);
|
|
slots_tex.texCoord(1, 0); GlHelpers.vertex2(0, 0);
|
|
slots_tex.texCoord(1, 1); GlHelpers.vertex2(0, 2);
|
|
GlHelpers.end();
|
|
|
|
// Render the players active slot
|
|
TextureReference hotbar_slot_tex = Textures.UI_ACTIVE_SLOT;
|
|
GlHelpers.begin();
|
|
|
|
hotbar_slot_tex.texCoord(0, 1); GlHelpers.vertex2(2.1 + player.inventory_hand*2, 2.1);
|
|
hotbar_slot_tex.texCoord(0, 0); GlHelpers.vertex2(2.1 + player.inventory_hand*2, -0.1);
|
|
hotbar_slot_tex.texCoord(1, 0); GlHelpers.vertex2(-0.1 + player.inventory_hand*2, -0.1);
|
|
hotbar_slot_tex.texCoord(1, 1); GlHelpers.vertex2(-0.1 + player.inventory_hand*2, 2.1);
|
|
|
|
GlHelpers.end();
|
|
|
|
GlHelpers.popMatrix();
|
|
|
|
// Get the players inventory
|
|
Inventory player_inv = player.getInventory();
|
|
|
|
GlHelpers.pushMatrix();
|
|
GlHelpers.translate2(3.12, -9.5);
|
|
|
|
// Render the players inventory
|
|
for(int i=0;i<6;i++)
|
|
{
|
|
ItemStack player_item = player_inv.getItem(i);
|
|
|
|
if(!player_item.isEmpty())
|
|
{
|
|
GlHelpers.pushMatrix();
|
|
GlHelpers.translate2(i * 2 / aspect_ratio, 0.3);
|
|
player_item.item.render(new Vec2d(0, 0), new Vec2d(1.5, 1.5));
|
|
GlHelpers.translate2(0.5 / aspect_ratio, -0.1);
|
|
Text.render(Integer.toString(player_item.count), text_size);
|
|
GlHelpers.popMatrix();
|
|
}
|
|
}
|
|
|
|
GlHelpers.popMatrix();
|
|
|
|
// Render the active slots text
|
|
ItemStack item_active = player_inv.getItem(player.inventory_hand);
|
|
if(!item_active.isEmpty())
|
|
{
|
|
GlHelpers.pushMatrix();
|
|
GlHelpers.translate2(3.5, -7.25);
|
|
Text.render(item_active.item.getName(item_active.meta), text_size);
|
|
GlHelpers.popMatrix();
|
|
}
|
|
|
|
// Render the boss bars
|
|
BossBars.render();
|
|
}
|
|
|
|
// Render the loaded menu
|
|
Main.menu.render();
|
|
}
|
|
}
|