    001    package net.minecraft.client.gui.inventory;
    002
    003    import cpw.mods.fml.relauncher.Side;
    004    import cpw.mods.fml.relauncher.SideOnly;
    005    import net.minecraft.block.Block;
    006    import net.minecraft.client.gui.GuiButton;
    007    import net.minecraft.client.gui.GuiScreen;
    008    import net.minecraft.client.multiplayer.NetClientHandler;
    009    import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
    010    import net.minecraft.network.packet.Packet130UpdateSign;
    011    import net.minecraft.tileentity.TileEntitySign;
    012    import net.minecraft.util.ChatAllowedCharacters;
    013    import org.lwjgl.input.Keyboard;
    014    import org.lwjgl.opengl.GL11;
    015
    016    @SideOnly(Side.CLIENT)
    017    public class GuiEditSign extends GuiScreen
    018    {
    019        /**
    020         * This String is just a local copy of the characters allowed in text rendering of minecraft.
    021         */
    022        private static final String allowedCharacters = ChatAllowedCharacters.allowedCharacters;
    023
    024        /** The title string that is displayed in the top-center of the screen. */
    025        protected String screenTitle = "Edit sign message:";
    026
    027        /** Reference to the sign object. */
    028        private TileEntitySign entitySign;
    029
    030        /** Counts the number of screen updates. */
    031        private int updateCounter;
    032
    033        /** The number of the line that is being edited. */
    034        private int editLine = 0;
    035
    036        public GuiEditSign(TileEntitySign par1TileEntitySign)
    037        {
    038            this.entitySign = par1TileEntitySign;
    039        }
    040
    041        /**
    042         * Adds the buttons (and other controls) to the screen in question.
    043         */
    044        public void initGui()
    045        {
    046            this.controlList.clear();
    047            Keyboard.enableRepeatEvents(true);
    048            this.controlList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 120, "Done"));
    049            this.entitySign.setEditable(false);
    050        }
    051
    052        /**
    053         * Called when the screen is unloaded. Used to disable keyboard repeat events
    054         */
    055        public void onGuiClosed()
    056        {
    057            Keyboard.enableRepeatEvents(false);
    058            NetClientHandler var1 = this.mc.getSendQueue();
    059
    060            if (var1 != null)
    061            {
    062                var1.addToSendQueue(new Packet130UpdateSign(this.entitySign.xCoord, this.entitySign.yCoord, this.entitySign.zCoord, this.entitySign.signText));
    063            }
    064
    065            this.entitySign.setEditable(true);
    066        }
    067
    068        /**
    069         * Called from the main game loop to update the screen.
    070         */
    071        public void updateScreen()
    072        {
    073            ++this.updateCounter;
    074        }
    075
    076        /**
    077         * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    078         */
    079        protected void actionPerformed(GuiButton par1GuiButton)
    080        {
    081            if (par1GuiButton.enabled)
    082            {
    083                if (par1GuiButton.id == 0)
    084                {
    085                    this.entitySign.onInventoryChanged();
    086                    this.mc.displayGuiScreen((GuiScreen)null);
    087                }
    088            }
    089        }
    090
    091        /**
    092         * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
    093         */
    094        protected void keyTyped(char par1, int par2)
    095        {
    096            if (par2 == 200)
    097            {
    098                this.editLine = this.editLine - 1 & 3;
    099            }
    100
    101            if (par2 == 208 || par2 == 28)
    102            {
    103                this.editLine = this.editLine + 1 & 3;
    104            }
    105
    106            if (par2 == 14 && this.entitySign.signText[this.editLine].length() > 0)
    107            {
    108                this.entitySign.signText[this.editLine] = this.entitySign.signText[this.editLine].substring(0, this.entitySign.signText[this.editLine].length() - 1);
    109            }
    110
    111            if (allowedCharacters.indexOf(par1) >= 0 && this.entitySign.signText[this.editLine].length() < 15)
    112            {
    113                this.entitySign.signText[this.editLine] = this.entitySign.signText[this.editLine] + par1;
    114            }
    115        }
    116
    117        /**
    118         * Draws the screen and all the components in it.
    119         */
    120        public void drawScreen(int par1, int par2, float par3)
    121        {
    122            this.drawDefaultBackground();
    123            this.drawCenteredString(this.fontRenderer, this.screenTitle, this.width / 2, 40, 16777215);
    124            GL11.glPushMatrix();
    125            GL11.glTranslatef((float)(this.width / 2), 0.0F, 50.0F);
    126            float var4 = 93.75F;
    127            GL11.glScalef(-var4, -var4, -var4);
    128            GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
    129            Block var5 = this.entitySign.getBlockType();
    130
    131            if (var5 == Block.signPost)
    132            {
    133                float var6 = (float)(this.entitySign.getBlockMetadata() * 360) / 16.0F;
    134                GL11.glRotatef(var6, 0.0F, 1.0F, 0.0F);
    135                GL11.glTranslatef(0.0F, -1.0625F, 0.0F);
    136            }
    137            else
    138            {
    139                int var8 = this.entitySign.getBlockMetadata();
    140                float var7 = 0.0F;
    141
    142                if (var8 == 2)
    143                {
    144                    var7 = 180.0F;
    145                }
    146
    147                if (var8 == 4)
    148                {
    149                    var7 = 90.0F;
    150                }
    151
    152                if (var8 == 5)
    153                {
    154                    var7 = -90.0F;
    155                }
    156
    157                GL11.glRotatef(var7, 0.0F, 1.0F, 0.0F);
    158                GL11.glTranslatef(0.0F, -1.0625F, 0.0F);
    159            }
    160
    161            if (this.updateCounter / 6 % 2 == 0)
    162            {
    163                this.entitySign.lineBeingEdited = this.editLine;
    164            }
    165
    166            TileEntityRenderer.instance.renderTileEntityAt(this.entitySign, -0.5D, -0.75D, -0.5D, 0.0F);
    167            this.entitySign.lineBeingEdited = -1;
    168            GL11.glPopMatrix();
    169            super.drawScreen(par1, par2, par3);
    170        }
    171    }