package shootergame.display; import shootergame.Main; import shootergame.entity.player.EntityPlayer; import shootergame.init.Textures; import shootergame.inventory.Inventory; import shootergame.text.Text; import shootergame.util.gl.GlHelpers; import shootergame.util.gl.texture.TextureReference; import shootergame.util.math.ItemStack; import shootergame.util.math.vec.Vec2d; public class DisplayRenderUI { public static void render() { // Get the player EntityPlayer player = Main.player; // Disable some opengl options GlHelpers.disableDepthTest(); // Get some text settings Vec2d text_size = new Vec2d(0.5, 0.2); // Render the fps and the position GlHelpers.pushMatrix(); GlHelpers.translate(-9.5, 9.5, 0); GlHelpers.color3(1, 1, 0); Text.render("FPS: " + DisplayStatsEventHandler.fps, text_size); GlHelpers.translate(0, -0.5, 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.begin(); health_bg.texCoord(0, 1); GlHelpers.vertex2(-3.2, -8.0); health_bg.texCoord(0, 0); GlHelpers.vertex2(-3.2, -9.0); health_bg.texCoord(1, 0); GlHelpers.vertex2(3.2, -9.0); health_bg.texCoord(1, 1); GlHelpers.vertex2(3.2, -8.0); health_fg.texCoord(0, 1); GlHelpers.vertex2(-3.2, -8.0); health_fg.texCoord(0, 0); GlHelpers.vertex2(-3.2, -9.0); health_fg.texCoord(1-a, 0); GlHelpers.vertex2(3.2-a*6.4, -9.0); health_fg.texCoord(1-a, 1); GlHelpers.vertex2(3.2-a*6.4, -8.0); GlHelpers.end(); // 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.begin(); ammo_tex.texCoord(0, 1); GlHelpers.vertex2(-9.5, -8.5); ammo_tex.texCoord(0, 0); GlHelpers.vertex2(-9.5, -7.0); ammo_tex.texCoord(1, 0); GlHelpers.vertex2(-8.5, -7.0); ammo_tex.texCoord(1, 1); GlHelpers.vertex2(-8.5, -8.5); gunlevel_tex.texCoord(0, 1); GlHelpers.vertex2(-9.5, -6.5); gunlevel_tex.texCoord(0, 0); GlHelpers.vertex2(-9.5, -5.0); gunlevel_tex.texCoord(1, 0); GlHelpers.vertex2(-8.5, -5.0); gunlevel_tex.texCoord(1, 1); GlHelpers.vertex2(-8.5, -6.5); deflevel_tex.texCoord(0, 1); GlHelpers.vertex2(-9.5, -4.5); deflevel_tex.texCoord(0, 0); GlHelpers.vertex2(-9.5, -3.0); deflevel_tex.texCoord(1, 0); GlHelpers.vertex2(-8.5, -3.0); deflevel_tex.texCoord(1, 1); GlHelpers.vertex2(-8.5, -4.5); GlHelpers.end(); GlHelpers.translate(-8.5, -9, 0); Text.render(Integer.toString(player.ammo), text_size); GlHelpers.translate(0, 2.5, 0); Text.render(Integer.toString(player.gun_level), text_size); GlHelpers.translate(0, 2, 0); 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.begin(); slots_tex.texCoord(0, 1); GlHelpers.vertex2(9.5, -9.4); slots_tex.texCoord(0, 0); GlHelpers.vertex2(9.5, -7.6); slots_tex.texCoord(1, 0); GlHelpers.vertex2(3.5, -7.6); slots_tex.texCoord(1, 1); GlHelpers.vertex2(3.5, -9.4); 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(4.55 + player.inventory_hand, -9.45); hotbar_slot_tex.texCoord(0, 0); GlHelpers.vertex2(4.55 + player.inventory_hand, -7.55); hotbar_slot_tex.texCoord(1, 0); GlHelpers.vertex2(3.45 + player.inventory_hand, -7.55); hotbar_slot_tex.texCoord(1, 1); GlHelpers.vertex2(3.45 + player.inventory_hand, -9.45); GlHelpers.end(); // Get the players inventory Inventory player_inv = player.getInventory(); // Render the players inventory for(int i=0;i<6;i++) { ItemStack player_item = player_inv.getItem(i); if(!player_item.isEmpty()) { player_item.item.render(new Vec2d(3.5 + i, -9.2), new Vec2d(1, 1.5)); GlHelpers.pushMatrix(); GlHelpers.translate(3.8 + i, -9.2, 0); Text.render(Integer.toString(player_item.count), text_size); GlHelpers.popMatrix(); } } // Render the active slots text ItemStack item_active = player_inv.getItem(player.inventory_hand); if(!item_active.isEmpty()) { GlHelpers.pushMatrix(); GlHelpers.translate(3.8, -7.4, 0); Text.render(item_active.item.getName(item_active.meta), text_size); GlHelpers.popMatrix(); } // Render the loaded menu Main.menu.render(); } }