GuiWinGame .java

net.minecraft.client.gui.GuiWinGame (class, 246 lines): members: VIGNETTE_TEXTURE, MINECRAFT_LOGO, field_146578_s, field_146579_r, field_146581_h, initGui.

net.minecraft.client.guiclass246 linesclientextends GuiScreen10.0 KB

API Surface (5)

void updateScreen()
void keyTyped(char typedChar, int keyCode)
boolean doesGuiPauseGame()
void initGui()
void drawScreen(int mouseX, int mouseY, float partialTicks)

Fields & Constants (7)

logger
MINECRAFT_LOGO
VIGNETTE_TEXTURE
field_146581_h
field_146582_i
field_146579_r
field_146578_s

String literals (7)

"textures/gui/title/minecraft.png"
"textures/misc/vignette.png"
"texts/end.txt"
"PLAYERNAME"
"XXXXXXXX"
"texts/credits.txt"
"Couldn\'t load credits"

Full Source

GuiWinGame.java246 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.gui;
2
3
import com.google.common.collect.Lists;
4
import java.io.BufferedReader;
5
import java.io.IOException;
6
import java.io.InputStream;
7
import java.io.InputStreamReader;
8
import java.util.List;
9
import java.util.Random;
10
import net.minecraft.client.audio.MusicTicker;
11
import net.minecraft.client.audio.SoundHandler;
12
import net.minecraft.client.renderer.GlStateManager;
13
import net.minecraft.client.renderer.Tessellator;
14
import net.minecraft.client.renderer.WorldRenderer;
15
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
16
import net.minecraft.network.play.client.C16PacketClientStatus;
17
import net.minecraft.util.EnumChatFormatting;
18
import net.minecraft.util.ResourceLocation;
19
import org.apache.commons.io.Charsets;
20
import org.apache.logging.log4j.LogManager;
21
import org.apache.logging.log4j.Logger;
22
23
public class GuiWinGame extends GuiScreen
24
{
25
    private static final Logger logger = LogManager.getLogger();
26
    private static final ResourceLocation MINECRAFT_LOGO = new ResourceLocation("textures/gui/title/minecraft.png");
27
    private static final ResourceLocation VIGNETTE_TEXTURE = new ResourceLocation("textures/misc/vignette.png");
28
    private int field_146581_h;
29
    private List<String> field_146582_i;
30
    private int field_146579_r;
31
    private float field_146578_s = 0.5F;
32
33
    /**
34
     * Called from the main game loop to update the screen.
35
     */
36
    public void updateScreen()
37
    {
38
        MusicTicker musicticker = this.mc.getMusicTicker();
39
        SoundHandler soundhandler = this.mc.getSoundHandler();
40
41
        if (this.field_146581_h == 0)
42
        {
43
            musicticker.func_181557_a();
44
            musicticker.func_181558_a(MusicTicker.MusicType.CREDITS);
45
            soundhandler.resumeSounds();
46
        }
47
48
        soundhandler.update();
49
        ++this.field_146581_h;
50
        float f = (float)(this.field_146579_r + this.height + this.height + 24) / this.field_146578_s;
51
52
        if ((float)this.field_146581_h > f)
53
        {
54
            this.sendRespawnPacket();
55
        }
56
    }
57
58
    /**
59
     * Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
60
     * KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
61
     */
62
    protected void keyTyped(char typedChar, int keyCode) throws IOException
63
    {
64
        if (keyCode == 1)
65
        {
66
            this.sendRespawnPacket();
67
        }
68
    }
69
70
    private void sendRespawnPacket()
71
    {
72
        this.mc.thePlayer.sendQueue.addToSendQueue(new C16PacketClientStatus(C16PacketClientStatus.EnumState.PERFORM_RESPAWN));
73
        this.mc.displayGuiScreen((GuiScreen)null);
74
    }
75
76
    /**
77
     * Returns true if this GUI should pause the game when it is displayed in single-player
78
     */
79
    public boolean doesGuiPauseGame()
80
    {
81
        return true;
82
    }
83
84
    /**
85
     * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
86
     * window resizes, the buttonList is cleared beforehand.
87
     */
88
    public void initGui()
89
    {
90
        if (this.field_146582_i == null)
91
        {
92
            this.field_146582_i = Lists.<String>newArrayList();
93
94
            try
95
            {
96
                String s = "";
97
                String s1 = "" + EnumChatFormatting.WHITE + EnumChatFormatting.OBFUSCATED + EnumChatFormatting.GREEN + EnumChatFormatting.AQUA;
98
                int i = 274;
99
                InputStream inputstream = this.mc.getResourceManager().getResource(new ResourceLocation("texts/end.txt")).getInputStream();
100
                BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(inputstream, Charsets.UTF_8));
101
                Random random = new Random(8124371L);
102
103
                while ((s = bufferedreader.readLine()) != null)
104
                {
105
                    String s2;
106
                    String s3;
107
108
                    for (s = s.replaceAll("PLAYERNAME", this.mc.getSession().getUsername()); s.contains(s1); s = s2 + EnumChatFormatting.WHITE + EnumChatFormatting.OBFUSCATED + "XXXXXXXX".substring(0, random.nextInt(4) + 3) + s3)
109
                    {
110
                        int j = s.indexOf(s1);
111
                        s2 = s.substring(0, j);
112
                        s3 = s.substring(j + s1.length());
113
                    }
114
115
                    this.field_146582_i.addAll(this.mc.fontRendererObj.listFormattedStringToWidth(s, i));
116
                    this.field_146582_i.add("");
117
                }
118
119
                inputstream.close();
120
121
                for (int k = 0; k < 8; ++k)
122
                {
123
                    this.field_146582_i.add("");
124
                }
125
126
                inputstream = this.mc.getResourceManager().getResource(new ResourceLocation("texts/credits.txt")).getInputStream();
127
                bufferedreader = new BufferedReader(new InputStreamReader(inputstream, Charsets.UTF_8));
128
129
                while ((s = bufferedreader.readLine()) != null)
130
                {
131
                    s = s.replaceAll("PLAYERNAME", this.mc.getSession().getUsername());
132
                    s = s.replaceAll("\t", "    ");
133
                    this.field_146582_i.addAll(this.mc.fontRendererObj.listFormattedStringToWidth(s, i));
134
                    this.field_146582_i.add("");
135
                }
136
137
                inputstream.close();
138
                this.field_146579_r = this.field_146582_i.size() * 12;
139
            }
140
            catch (Exception exception)
141
            {
142
                logger.error((String)"Couldn\'t load credits", (Throwable)exception);
143
            }
144
        }
145
    }
146
147
    private void drawWinGameScreen(int p_146575_1_, int p_146575_2_, float p_146575_3_)
148
    {
149
        Tessellator tessellator = Tessellator.getInstance();
150
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
151
        this.mc.getTextureManager().bindTexture(Gui.optionsBackground);
152
        worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
153
        int i = this.width;
154
        float f = 0.0F - ((float)this.field_146581_h + p_146575_3_) * 0.5F * this.field_146578_s;
155
        float f1 = (float)this.height - ((float)this.field_146581_h + p_146575_3_) * 0.5F * this.field_146578_s;
156
        float f2 = 0.015625F;
157
        float f3 = ((float)this.field_146581_h + p_146575_3_ - 0.0F) * 0.02F;
158
        float f4 = (float)(this.field_146579_r + this.height + this.height + 24) / this.field_146578_s;
159
        float f5 = (f4 - 20.0F - ((float)this.field_146581_h + p_146575_3_)) * 0.005F;
160
161
        if (f5 < f3)
162
        {
163
            f3 = f5;
164
        }
165
166
        if (f3 > 1.0F)
167
        {
168
            f3 = 1.0F;
169
        }
170
171
        f3 = f3 * f3;
172
        f3 = f3 * 96.0F / 255.0F;
173
        worldrenderer.pos(0.0D, (double)this.height, (double)this.zLevel).tex(0.0D, (double)(f * f2)).color(f3, f3, f3, 1.0F).endVertex();
174
        worldrenderer.pos((double)i, (double)this.height, (double)this.zLevel).tex((double)((float)i * f2), (double)(f * f2)).color(f3, f3, f3, 1.0F).endVertex();
175
        worldrenderer.pos((double)i, 0.0D, (double)this.zLevel).tex((double)((float)i * f2), (double)(f1 * f2)).color(f3, f3, f3, 1.0F).endVertex();
176
        worldrenderer.pos(0.0D, 0.0D, (double)this.zLevel).tex(0.0D, (double)(f1 * f2)).color(f3, f3, f3, 1.0F).endVertex();
177
        tessellator.draw();
178
    }
179
180
    /**
181
     * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
182
     */
183
    public void drawScreen(int mouseX, int mouseY, float partialTicks)
184
    {
185
        this.drawWinGameScreen(mouseX, mouseY, partialTicks);
186
        Tessellator tessellator = Tessellator.getInstance();
187
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
188
        int i = 274;
189
        int j = this.width / 2 - i / 2;
190
        int k = this.height + 50;
191
        float f = -((float)this.field_146581_h + partialTicks) * this.field_146578_s;
192
        GlStateManager.pushMatrix();
193
        GlStateManager.translate(0.0F, f, 0.0F);
194
        this.mc.getTextureManager().bindTexture(MINECRAFT_LOGO);
195
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
196
        this.drawTexturedModalRect(j, k, 0, 0, 155, 44);
197
        this.drawTexturedModalRect(j + 155, k, 0, 45, 155, 44);
198
        int l = k + 200;
199
200
        for (int i1 = 0; i1 < this.field_146582_i.size(); ++i1)
201
        {
202
            if (i1 == this.field_146582_i.size() - 1)
203
            {
204
                float f1 = (float)l + f - (float)(this.height / 2 - 6);
205
206
                if (f1 < 0.0F)
207
                {
208
                    GlStateManager.translate(0.0F, -f1, 0.0F);
209
                }
210
            }
211
212
            if ((float)l + f + 12.0F + 8.0F > 0.0F && (float)l + f < (float)this.height)
213
            {
214
                String s = (String)this.field_146582_i.get(i1);
215
216
                if (s.startsWith("[C]"))
217
                {
218
                    this.fontRendererObj.drawStringWithShadow(s.substring(3), (float)(j + (i - this.fontRendererObj.getStringWidth(s.substring(3))) / 2), (float)l, 16777215);
219
                }
220
                else
221
                {
222
                    this.fontRendererObj.fontRandom.setSeed((long)i1 * 4238972211L + (long)(this.field_146581_h / 4));
223
                    this.fontRendererObj.drawStringWithShadow(s, (float)j, (float)l, 16777215);
224
                }
225
            }
226
227
            l += 12;
228
        }
229
230
        GlStateManager.popMatrix();
231
        this.mc.getTextureManager().bindTexture(VIGNETTE_TEXTURE);
232
        GlStateManager.enableBlend();
233
        GlStateManager.blendFunc(0, 769);
234
        int j1 = this.width;
235
        int k1 = this.height;
236
        worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
237
        worldrenderer.pos(0.0D, (double)k1, (double)this.zLevel).tex(0.0D, 1.0D).color(1.0F, 1.0F, 1.0F, 1.0F).endVertex();
238
        worldrenderer.pos((double)j1, (double)k1, (double)this.zLevel).tex(1.0D, 1.0D).color(1.0F, 1.0F, 1.0F, 1.0F).endVertex();
239
        worldrenderer.pos((double)j1, 0.0D, (double)this.zLevel).tex(1.0D, 0.0D).color(1.0F, 1.0F, 1.0F, 1.0F).endVertex();
240
        worldrenderer.pos(0.0D, 0.0D, (double)this.zLevel).tex(0.0D, 0.0D).color(1.0F, 1.0F, 1.0F, 1.0F).endVertex();
241
        tessellator.draw();
242
        GlStateManager.disableBlend();
243
        super.drawScreen(mouseX, mouseY, partialTicks);
244
    }
245
}
246

Deobfuscated MCP 1.8.9 source of GuiWinGame from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/gui/GuiWinGame.java), stored verbatim.