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