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