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