192 lines
6.0 KiB
Java
Executable File
192 lines
6.0 KiB
Java
Executable File
package projectzombie.display;
|
|
|
|
import projectzombie.Main;
|
|
import projectzombie.display.bossbar.BossBars;
|
|
import projectzombie.entity.player.EntityPlayer;
|
|
import projectzombie.init.Models;
|
|
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 gl_engine.vec.Vec2d;
|
|
|
|
public class DisplayRenderUI
|
|
{
|
|
public static boolean showFPS = false;
|
|
public static boolean showPos = false;
|
|
public static int guiScale = 2;
|
|
|
|
public static void render()
|
|
{
|
|
double s = GlHelpers.getScale() / 10.0;
|
|
|
|
// Get some text settings
|
|
Vec2d text_size = new Vec2d(0.5, 0.5);
|
|
|
|
// Render the fps
|
|
if(showFPS) {
|
|
GlHelpers.pushMatrix();
|
|
GlHelpers.translate2(-10*s + 0.5, 10*s - 0.5);
|
|
GlHelpers.color3(1, 1, 0);
|
|
Text.render("FPS: " + DisplayStatsEventHandler.fps, text_size);
|
|
GlHelpers.popMatrix();
|
|
}
|
|
|
|
// 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()));
|
|
|
|
if(Main.menu.doGameRender && Main.menu.showIngameGUI)
|
|
{
|
|
// Render the position
|
|
if(showPos) {
|
|
GlHelpers.pushMatrix();
|
|
GlHelpers.translate2(-10*s + 0.5, 10*s - 1);
|
|
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 = Models.UI_HEALTH_FG;
|
|
TextureReference health_bg = Models.UI_HEALTH_BG;
|
|
|
|
GlHelpers.pushMatrix();
|
|
GlHelpers.translate2(-2*s, -9*s);
|
|
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 = Models.ITEM_AMMO_BOX;
|
|
TextureReference gunlevel_tex = Models.UI_GUN_LEVEL;
|
|
TextureReference deflevel_tex = Models.UI_DEFENCE_LEVEL;
|
|
|
|
GlHelpers.translate2(-9.5*s, -9*s);
|
|
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*s, -9.25*s);
|
|
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 = Models.UI_ITEM_SLOTS;
|
|
|
|
GlHelpers.pushMatrix();
|
|
GlHelpers.translate2(3*s, -9.5*s);
|
|
|
|
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 = Models.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*s, -9.5*s);
|
|
|
|
// 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, -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.12*s, -9.5*s);
|
|
GlHelpers.translate2(-0.08, 2.24);
|
|
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();
|
|
}
|
|
}
|