GuiEditSign .java

net.minecraft.client.gui.inventory.GuiEditSign (class): members: editLine, tileSign, doneBtn, updateCounter, onGuiClosed, updateScreen, keyTyped, initGui.

net.minecraft.client.gui.inventoryclass180 linesclientextends GuiScreen5.5 KB

API Surface (6)

void initGui()
void onGuiClosed()
void updateScreen()
void actionPerformed(GuiButton button)
void keyTyped(char typedChar, int keyCode)
void drawScreen(int mouseX, int mouseY, float partialTicks)

Fields & Constants (4)

tileSign
updateCounter
editLine
doneBtn

String literals (2)

"gui.done"
"sign.edit"

Full Source

GuiEditSign.java180 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.gui.inventory;
2
3
import java.io.IOException;
4
import net.minecraft.block.Block;
5
import net.minecraft.client.gui.GuiButton;
6
import net.minecraft.client.gui.GuiScreen;
7
import net.minecraft.client.network.NetHandlerPlayClient;
8
import net.minecraft.client.renderer.GlStateManager;
9
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
10
import net.minecraft.client.resources.I18n;
11
import net.minecraft.init.Blocks;
12
import net.minecraft.network.play.client.C12PacketUpdateSign;
13
import net.minecraft.tileentity.TileEntitySign;
14
import net.minecraft.util.ChatAllowedCharacters;
15
import net.minecraft.util.ChatComponentText;
16
import org.lwjgl.input.Keyboard;
17
18
public class GuiEditSign extends GuiScreen
19
{
20
    /** Reference to the sign object. */
21
    private TileEntitySign tileSign;
22
23
    /** Counts the number of screen updates. */
24
    private int updateCounter;
25
26
    /** The index of the line that is being edited. */
27
    private int editLine;
28
29
    /** "Done" button for the GUI. */
30
    private GuiButton doneBtn;
31
32
    public GuiEditSign(TileEntitySign teSign)
33
    {
34
        this.tileSign = teSign;
35
    }
36
37
    /**
38
     * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
39
     * window resizes, the buttonList is cleared beforehand.
40
     */
41
    public void initGui()
42
    {
43
        this.buttonList.clear();
44
        Keyboard.enableRepeatEvents(true);
45
        this.buttonList.add(this.doneBtn = new GuiButton(0, this.width / 2 - 100, this.height / 4 + 120, I18n.format("gui.done", new Object[0])));
46
        this.tileSign.setEditable(false);
47
    }
48
49
    /**
50
     * Called when the screen is unloaded. Used to disable keyboard repeat events
51
     */
52
    public void onGuiClosed()
53
    {
54
        Keyboard.enableRepeatEvents(false);
55
        NetHandlerPlayClient nethandlerplayclient = this.mc.getNetHandler();
56
57
        if (nethandlerplayclient != null)
58
        {
59
            nethandlerplayclient.addToSendQueue(new C12PacketUpdateSign(this.tileSign.getPos(), this.tileSign.signText));
60
        }
61
62
        this.tileSign.setEditable(true);
63
    }
64
65
    /**
66
     * Called from the main game loop to update the screen.
67
     */
68
    public void updateScreen()
69
    {
70
        ++this.updateCounter;
71
    }
72
73
    /**
74
     * Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
75
     */
76
    protected void actionPerformed(GuiButton button) throws IOException
77
    {
78
        if (button.enabled)
79
        {
80
            if (button.id == 0)
81
            {
82
                this.tileSign.markDirty();
83
                this.mc.displayGuiScreen((GuiScreen)null);
84
            }
85
        }
86
    }
87
88
    /**
89
     * Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
90
     * KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
91
     */
92
    protected void keyTyped(char typedChar, int keyCode) throws IOException
93
    {
94
        if (keyCode == 200)
95
        {
96
            this.editLine = this.editLine - 1 & 3;
97
        }
98
99
        if (keyCode == 208 || keyCode == 28 || keyCode == 156)
100
        {
101
            this.editLine = this.editLine + 1 & 3;
102
        }
103
104
        String s = this.tileSign.signText[this.editLine].getUnformattedText();
105
106
        if (keyCode == 14 && s.length() > 0)
107
        {
108
            s = s.substring(0, s.length() - 1);
109
        }
110
111
        if (ChatAllowedCharacters.isAllowedCharacter(typedChar) && this.fontRendererObj.getStringWidth(s + typedChar) <= 90)
112
        {
113
            s = s + typedChar;
114
        }
115
116
        this.tileSign.signText[this.editLine] = new ChatComponentText(s);
117
118
        if (keyCode == 1)
119
        {
120
            this.actionPerformed(this.doneBtn);
121
        }
122
    }
123
124
    /**
125
     * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
126
     */
127
    public void drawScreen(int mouseX, int mouseY, float partialTicks)
128
    {
129
        this.drawDefaultBackground();
130
        this.drawCenteredString(this.fontRendererObj, I18n.format("sign.edit", new Object[0]), this.width / 2, 40, 16777215);
131
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
132
        GlStateManager.pushMatrix();
133
        GlStateManager.translate((float)(this.width / 2), 0.0F, 50.0F);
134
        float f = 93.75F;
135
        GlStateManager.scale(-f, -f, -f);
136
        GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
137
        Block block = this.tileSign.getBlockType();
138
139
        if (block == Blocks.standing_sign)
140
        {
141
            float f1 = (float)(this.tileSign.getBlockMetadata() * 360) / 16.0F;
142
            GlStateManager.rotate(f1, 0.0F, 1.0F, 0.0F);
143
            GlStateManager.translate(0.0F, -1.0625F, 0.0F);
144
        }
145
        else
146
        {
147
            int i = this.tileSign.getBlockMetadata();
148
            float f2 = 0.0F;
149
150
            if (i == 2)
151
            {
152
                f2 = 180.0F;
153
            }
154
155
            if (i == 4)
156
            {
157
                f2 = 90.0F;
158
            }
159
160
            if (i == 5)
161
            {
162
                f2 = -90.0F;
163
            }
164
165
            GlStateManager.rotate(f2, 0.0F, 1.0F, 0.0F);
166
            GlStateManager.translate(0.0F, -1.0625F, 0.0F);
167
        }
168
169
        if (this.updateCounter / 6 % 2 == 0)
170
        {
171
            this.tileSign.lineBeingEdited = this.editLine;
172
        }
173
174
        TileEntityRendererDispatcher.instance.renderTileEntityAt(this.tileSign, -0.5D, -0.75D, -0.5D, 0.0F);
175
        this.tileSign.lineBeingEdited = -1;
176
        GlStateManager.popMatrix();
177
        super.drawScreen(mouseX, mouseY, partialTicks);
178
    }
179
}
180

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