001package net.minecraft.client.gui.achievement; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005import net.minecraft.client.Minecraft; 006import net.minecraft.client.gui.Gui; 007import net.minecraft.client.gui.ScaledResolution; 008import net.minecraft.client.renderer.RenderHelper; 009import net.minecraft.client.renderer.entity.RenderItem; 010import net.minecraft.stats.Achievement; 011import net.minecraft.util.StatCollector; 012import org.lwjgl.opengl.GL11; 013import org.lwjgl.opengl.GL12; 014 015@SideOnly(Side.CLIENT) 016public class GuiAchievement extends Gui 017{ 018 /** Holds the instance of the game (Minecraft) */ 019 private Minecraft theGame; 020 021 /** Holds the latest width scaled to fit the game window. */ 022 private int achievementWindowWidth; 023 024 /** Holds the latest height scaled to fit the game window. */ 025 private int achievementWindowHeight; 026 private String achievementGetLocalText; 027 private String achievementStatName; 028 029 /** Holds the achievement that will be displayed on the GUI. */ 030 private Achievement theAchievement; 031 private long achievementTime; 032 033 /** 034 * Holds a instance of RenderItem, used to draw the achievement icons on screen (is based on ItemStack) 035 */ 036 private RenderItem itemRender; 037 private boolean haveAchiement; 038 039 public GuiAchievement(Minecraft par1Minecraft) 040 { 041 this.theGame = par1Minecraft; 042 this.itemRender = new RenderItem(); 043 } 044 045 /** 046 * Queue a taken achievement to be displayed. 047 */ 048 public void queueTakenAchievement(Achievement par1Achievement) 049 { 050 this.achievementGetLocalText = StatCollector.translateToLocal("achievement.get"); 051 this.achievementStatName = StatCollector.translateToLocal(par1Achievement.getName()); 052 this.achievementTime = Minecraft.getSystemTime(); 053 this.theAchievement = par1Achievement; 054 this.haveAchiement = false; 055 } 056 057 /** 058 * Queue a information about a achievement to be displayed. 059 */ 060 public void queueAchievementInformation(Achievement par1Achievement) 061 { 062 this.achievementGetLocalText = StatCollector.translateToLocal(par1Achievement.getName()); 063 this.achievementStatName = par1Achievement.getDescription(); 064 this.achievementTime = Minecraft.getSystemTime() - 2500L; 065 this.theAchievement = par1Achievement; 066 this.haveAchiement = true; 067 } 068 069 /** 070 * Update the display of the achievement window to match the game window. 071 */ 072 private void updateAchievementWindowScale() 073 { 074 GL11.glViewport(0, 0, this.theGame.displayWidth, this.theGame.displayHeight); 075 GL11.glMatrixMode(GL11.GL_PROJECTION); 076 GL11.glLoadIdentity(); 077 GL11.glMatrixMode(GL11.GL_MODELVIEW); 078 GL11.glLoadIdentity(); 079 this.achievementWindowWidth = this.theGame.displayWidth; 080 this.achievementWindowHeight = this.theGame.displayHeight; 081 ScaledResolution scaledresolution = new ScaledResolution(this.theGame.gameSettings, this.theGame.displayWidth, this.theGame.displayHeight); 082 this.achievementWindowWidth = scaledresolution.getScaledWidth(); 083 this.achievementWindowHeight = scaledresolution.getScaledHeight(); 084 GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT); 085 GL11.glMatrixMode(GL11.GL_PROJECTION); 086 GL11.glLoadIdentity(); 087 GL11.glOrtho(0.0D, (double)this.achievementWindowWidth, (double)this.achievementWindowHeight, 0.0D, 1000.0D, 3000.0D); 088 GL11.glMatrixMode(GL11.GL_MODELVIEW); 089 GL11.glLoadIdentity(); 090 GL11.glTranslatef(0.0F, 0.0F, -2000.0F); 091 } 092 093 /** 094 * Updates the small achievement tooltip window, showing a queued achievement if is needed. 095 */ 096 public void updateAchievementWindow() 097 { 098 if (this.theAchievement != null && this.achievementTime != 0L) 099 { 100 double d0 = (double)(Minecraft.getSystemTime() - this.achievementTime) / 3000.0D; 101 102 if (!this.haveAchiement && (d0 < 0.0D || d0 > 1.0D)) 103 { 104 this.achievementTime = 0L; 105 } 106 else 107 { 108 this.updateAchievementWindowScale(); 109 GL11.glDisable(GL11.GL_DEPTH_TEST); 110 GL11.glDepthMask(false); 111 double d1 = d0 * 2.0D; 112 113 if (d1 > 1.0D) 114 { 115 d1 = 2.0D - d1; 116 } 117 118 d1 *= 4.0D; 119 d1 = 1.0D - d1; 120 121 if (d1 < 0.0D) 122 { 123 d1 = 0.0D; 124 } 125 126 d1 *= d1; 127 d1 *= d1; 128 int i = this.achievementWindowWidth - 160; 129 int j = 0 - (int)(d1 * 36.0D); 130 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); 131 GL11.glEnable(GL11.GL_TEXTURE_2D); 132 this.theGame.renderEngine.bindTexture("/achievement/bg.png"); 133 GL11.glDisable(GL11.GL_LIGHTING); 134 this.drawTexturedModalRect(i, j, 96, 202, 160, 32); 135 136 if (this.haveAchiement) 137 { 138 this.theGame.fontRenderer.drawSplitString(this.achievementStatName, i + 30, j + 7, 120, -1); 139 } 140 else 141 { 142 this.theGame.fontRenderer.drawString(this.achievementGetLocalText, i + 30, j + 7, -256); 143 this.theGame.fontRenderer.drawString(this.achievementStatName, i + 30, j + 18, -1); 144 } 145 146 RenderHelper.enableGUIStandardItemLighting(); 147 GL11.glDisable(GL11.GL_LIGHTING); 148 GL11.glEnable(GL12.GL_RESCALE_NORMAL); 149 GL11.glEnable(GL11.GL_COLOR_MATERIAL); 150 GL11.glEnable(GL11.GL_LIGHTING); 151 this.itemRender.renderItemAndEffectIntoGUI(this.theGame.fontRenderer, this.theGame.renderEngine, this.theAchievement.theItemStack, i + 8, j + 8); 152 GL11.glDisable(GL11.GL_LIGHTING); 153 GL11.glDepthMask(true); 154 GL11.glEnable(GL11.GL_DEPTH_TEST); 155 } 156 } 157 } 158}