    001    package net.minecraft.client.gui.achievement;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import net.minecraft.client.Minecraft;
    006    import net.minecraft.client.gui.Gui;
    007    import net.minecraft.client.gui.ScaledResolution;
    008    import net.minecraft.client.renderer.RenderHelper;
    009    import net.minecraft.client.renderer.entity.RenderItem;
    010    import net.minecraft.stats.Achievement;
    011    import net.minecraft.util.StatCollector;
    012    import org.lwjgl.opengl.GL11;
    013    import org.lwjgl.opengl.GL12;
    014
    015    @SideOnly(Side.CLIENT)
    016    public 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 var1 = new ScaledResolution(this.theGame.gameSettings, this.theGame.displayWidth, this.theGame.displayHeight);
    082            this.achievementWindowWidth = var1.getScaledWidth();
    083            this.achievementWindowHeight = var1.getScaledHeight();
    084            GL11.glClear(256);
    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 var1 = (double)(Minecraft.getSystemTime() - this.achievementTime) / 3000.0D;
    101
    102                if (!this.haveAchiement && (var1 < 0.0D || var1 > 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 var3 = var1 * 2.0D;
    112
    113                    if (var3 > 1.0D)
    114                    {
    115                        var3 = 2.0D - var3;
    116                    }
    117
    118                    var3 *= 4.0D;
    119                    var3 = 1.0D - var3;
    120
    121                    if (var3 < 0.0D)
    122                    {
    123                        var3 = 0.0D;
    124                    }
    125
    126                    var3 *= var3;
    127                    var3 *= var3;
    128                    int var5 = this.achievementWindowWidth - 160;
    129                    int var6 = 0 - (int)(var3 * 36.0D);
    130                    int var7 = this.theGame.renderEngine.getTexture("/achievement/bg.png");
    131                    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    132                    GL11.glEnable(GL11.GL_TEXTURE_2D);
    133                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, var7);
    134                    GL11.glDisable(GL11.GL_LIGHTING);
    135                    this.drawTexturedModalRect(var5, var6, 96, 202, 160, 32);
    136
    137                    if (this.haveAchiement)
    138                    {
    139                        this.theGame.fontRenderer.drawSplitString(this.achievementStatName, var5 + 30, var6 + 7, 120, -1);
    140                    }
    141                    else
    142                    {
    143                        this.theGame.fontRenderer.drawString(this.achievementGetLocalText, var5 + 30, var6 + 7, -256);
    144                        this.theGame.fontRenderer.drawString(this.achievementStatName, var5 + 30, var6 + 18, -1);
    145                    }
    146
    147                    RenderHelper.enableGUIStandardItemLighting();
    148                    GL11.glDisable(GL11.GL_LIGHTING);
    149                    GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    150                    GL11.glEnable(GL11.GL_COLOR_MATERIAL);
    151                    GL11.glEnable(GL11.GL_LIGHTING);
    152                    this.itemRender.renderItemAndEffectIntoGUI(this.theGame.fontRenderer, this.theGame.renderEngine, this.theAchievement.theItemStack, var5 + 8, var6 + 8);
    153                    GL11.glDisable(GL11.GL_LIGHTING);
    154                    GL11.glDepthMask(true);
    155                    GL11.glEnable(GL11.GL_DEPTH_TEST);
    156                }
    157            }
    158        }
    159    }