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