    001    package net.minecraft.client.gui;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.io.BufferedReader;
    006    import java.io.InputStreamReader;
    007    import java.nio.charset.Charset;
    008    import java.util.ArrayList;
    009    import java.util.List;
    010    import java.util.Random;
    011    import net.minecraft.client.renderer.Tessellator;
    012    import net.minecraft.network.packet.Packet205ClientCommand;
    013    import org.lwjgl.opengl.GL11;
    014
    015    @SideOnly(Side.CLIENT)
    016    public class GuiWinGame extends GuiScreen
    017    {
    018        /** Counts the number of screen updates. */
    019        private int updateCounter = 0;
    020
    021        /** List of lines on the ending poem and credits. */
    022        private List lines;
    023        private int field_73989_c = 0;
    024        private float field_73987_d = 0.5F;
    025
    026        /**
    027         * Called from the main game loop to update the screen.
    028         */
    029        public void updateScreen()
    030        {
    031            ++this.updateCounter;
    032            float var1 = (float)(this.field_73989_c + this.height + this.height + 24) / this.field_73987_d;
    033
    034            if ((float)this.updateCounter > var1)
    035            {
    036                this.respawnPlayer();
    037            }
    038        }
    039
    040        /**
    041         * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
    042         */
    043        protected void keyTyped(char par1, int par2)
    044        {
    045            if (par2 == 1)
    046            {
    047                this.respawnPlayer();
    048            }
    049        }
    050
    051        /**
    052         * Respawns the player.
    053         */
    054        private void respawnPlayer()
    055        {
    056            this.mc.thePlayer.sendQueue.addToSendQueue(new Packet205ClientCommand(1));
    057            this.mc.displayGuiScreen((GuiScreen)null);
    058        }
    059
    060        /**
    061         * Returns true if this GUI should pause the game when it is displayed in single-player
    062         */
    063        public boolean doesGuiPauseGame()
    064        {
    065            return true;
    066        }
    067
    068        /**
    069         * Adds the buttons (and other controls) to the screen in question.
    070         */
    071        public void initGui()
    072        {
    073            if (this.lines == null)
    074            {
    075                this.lines = new ArrayList();
    076
    077                try
    078                {
    079                    String var1 = "";
    080                    String var2 = "\u00a7f\u00a7k\u00a7a\u00a7b";
    081                    short var3 = 274;
    082                    BufferedReader var4 = new BufferedReader(new InputStreamReader(GuiWinGame.class.getResourceAsStream("/title/win.txt"), Charset.forName("UTF-8")));
    083                    Random var5 = new Random(8124371L);
    084                    int var6;
    085
    086                    while ((var1 = var4.readLine()) != null)
    087                    {
    088                        String var7;
    089                        String var8;
    090
    091                        for (var1 = var1.replaceAll("PLAYERNAME", this.mc.session.username); var1.contains(var2); var1 = var7 + "\u00a7f\u00a7k" + "XXXXXXXX".substring(0, var5.nextInt(4) + 3) + var8)
    092                        {
    093                            var6 = var1.indexOf(var2);
    094                            var7 = var1.substring(0, var6);
    095                            var8 = var1.substring(var6 + var2.length());
    096                        }
    097
    098                        this.lines.addAll(this.mc.fontRenderer.listFormattedStringToWidth(var1, var3));
    099                        this.lines.add("");
    100                    }
    101
    102                    for (var6 = 0; var6 < 8; ++var6)
    103                    {
    104                        this.lines.add("");
    105                    }
    106
    107                    var4 = new BufferedReader(new InputStreamReader(GuiWinGame.class.getResourceAsStream("/title/credits.txt"), Charset.forName("UTF-8")));
    108
    109                    while ((var1 = var4.readLine()) != null)
    110                    {
    111                        var1 = var1.replaceAll("PLAYERNAME", this.mc.session.username);
    112                        var1 = var1.replaceAll("\t", "    ");
    113                        this.lines.addAll(this.mc.fontRenderer.listFormattedStringToWidth(var1, var3));
    114                        this.lines.add("");
    115                    }
    116
    117                    this.field_73989_c = this.lines.size() * 12;
    118                }
    119                catch (Exception var9)
    120                {
    121                    var9.printStackTrace();
    122                }
    123            }
    124        }
    125
    126        private void func_73986_b(int par1, int par2, float par3)
    127        {
    128            Tessellator var4 = Tessellator.instance;
    129            GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("%blur%/gui/background.png"));
    130            var4.startDrawingQuads();
    131            var4.setColorRGBA_F(1.0F, 1.0F, 1.0F, 1.0F);
    132            int var5 = this.width;
    133            float var6 = 0.0F - ((float)this.updateCounter + par3) * 0.5F * this.field_73987_d;
    134            float var7 = (float)this.height - ((float)this.updateCounter + par3) * 0.5F * this.field_73987_d;
    135            float var8 = 0.015625F;
    136            float var9 = ((float)this.updateCounter + par3 - 0.0F) * 0.02F;
    137            float var10 = (float)(this.field_73989_c + this.height + this.height + 24) / this.field_73987_d;
    138            float var11 = (var10 - 20.0F - ((float)this.updateCounter + par3)) * 0.005F;
    139
    140            if (var11 < var9)
    141            {
    142                var9 = var11;
    143            }
    144
    145            if (var9 > 1.0F)
    146            {
    147                var9 = 1.0F;
    148            }
    149
    150            var9 *= var9;
    151            var9 = var9 * 96.0F / 255.0F;
    152            var4.setColorOpaque_F(var9, var9, var9);
    153            var4.addVertexWithUV(0.0D, (double)this.height, (double)this.zLevel, 0.0D, (double)(var6 * var8));
    154            var4.addVertexWithUV((double)var5, (double)this.height, (double)this.zLevel, (double)((float)var5 * var8), (double)(var6 * var8));
    155            var4.addVertexWithUV((double)var5, 0.0D, (double)this.zLevel, (double)((float)var5 * var8), (double)(var7 * var8));
    156            var4.addVertexWithUV(0.0D, 0.0D, (double)this.zLevel, 0.0D, (double)(var7 * var8));
    157            var4.draw();
    158        }
    159
    160        /**
    161         * Draws the screen and all the components in it.
    162         */
    163        public void drawScreen(int par1, int par2, float par3)
    164        {
    165            this.func_73986_b(par1, par2, par3);
    166            Tessellator var4 = Tessellator.instance;
    167            short var5 = 274;
    168            int var6 = this.width / 2 - var5 / 2;
    169            int var7 = this.height + 50;
    170            float var8 = -((float)this.updateCounter + par3) * this.field_73987_d;
    171            GL11.glPushMatrix();
    172            GL11.glTranslatef(0.0F, var8, 0.0F);
    173            GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/title/mclogo.png"));
    174            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    175            this.drawTexturedModalRect(var6, var7, 0, 0, 155, 44);
    176            this.drawTexturedModalRect(var6 + 155, var7, 0, 45, 155, 44);
    177            var4.setColorOpaque_I(16777215);
    178            int var9 = var7 + 200;
    179            int var10;
    180
    181            for (var10 = 0; var10 < this.lines.size(); ++var10)
    182            {
    183                if (var10 == this.lines.size() - 1)
    184                {
    185                    float var11 = (float)var9 + var8 - (float)(this.height / 2 - 6);
    186
    187                    if (var11 < 0.0F)
    188                    {
    189                        GL11.glTranslatef(0.0F, -var11, 0.0F);
    190                    }
    191                }
    192
    193                if ((float)var9 + var8 + 12.0F + 8.0F > 0.0F && (float)var9 + var8 < (float)this.height)
    194                {
    195                    String var12 = (String)this.lines.get(var10);
    196
    197                    if (var12.startsWith("[C]"))
    198                    {
    199                        this.fontRenderer.drawStringWithShadow(var12.substring(3), var6 + (var5 - this.fontRenderer.getStringWidth(var12.substring(3))) / 2, var9, 16777215);
    200                    }
    201                    else
    202                    {
    203                        this.fontRenderer.fontRandom.setSeed((long)var10 * 4238972211L + (long)(this.updateCounter / 4));
    204                        this.fontRenderer.drawStringWithShadow(var12, var6, var9, 16777215);
    205                    }
    206                }
    207
    208                var9 += 12;
    209            }
    210
    211            GL11.glPopMatrix();
    212            GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("%blur%/misc/vignette.png"));
    213            GL11.glEnable(GL11.GL_BLEND);
    214            GL11.glBlendFunc(GL11.GL_ZERO, GL11.GL_ONE_MINUS_SRC_COLOR);
    215            var4.startDrawingQuads();
    216            var4.setColorRGBA_F(1.0F, 1.0F, 1.0F, 1.0F);
    217            var10 = this.width;
    218            int var13 = this.height;
    219            var4.addVertexWithUV(0.0D, (double)var13, (double)this.zLevel, 0.0D, 1.0D);
    220            var4.addVertexWithUV((double)var10, (double)var13, (double)this.zLevel, 1.0D, 1.0D);
    221            var4.addVertexWithUV((double)var10, 0.0D, (double)this.zLevel, 1.0D, 0.0D);
    222            var4.addVertexWithUV(0.0D, 0.0D, (double)this.zLevel, 0.0D, 0.0D);
    223            var4.draw();
    224            GL11.glDisable(GL11.GL_BLEND);
    225            super.drawScreen(par1, par2, par3);
    226        }
    227    }