    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            NetClientHandler var1 = this.mc.getSendQueue();
    051
    052            if (var1 != null)
    053            {
    054                var1.addToSendQueue(new Packet130UpdateSign(this.entitySign.xCoord, this.entitySign.yCoord, this.entitySign.zCoord, this.entitySign.signText));
    055            }
    056
    057            this.entitySign.setEditable(true);
    058        }
    059
    060        /**
    061         * Called from the main game loop to update the screen.
    062         */
    063        public void updateScreen()
    064        {
    065            ++this.updateCounter;
    066        }
    067
    068        /**
    069         * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    070         */
    071        protected void actionPerformed(GuiButton par1GuiButton)
    072        {
    073            if (par1GuiButton.enabled)
    074            {
    075                if (par1GuiButton.id == 0)
    076                {
    077                    this.entitySign.onInventoryChanged();
    078                    this.mc.displayGuiScreen((GuiScreen)null);
    079                }
    080            }
    081        }
    082
    083        /**
    084         * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
    085         */
    086        protected void keyTyped(char par1, int par2)
    087        {
    088            if (par2 == 200)
    089            {
    090                this.editLine = this.editLine - 1 & 3;
    091            }
    092
    093            if (par2 == 208 || par2 == 28)
    094            {
    095                this.editLine = this.editLine + 1 & 3;
    096            }
    097
    098            if (par2 == 14 && this.entitySign.signText[this.editLine].length() > 0)
    099            {
    100                this.entitySign.signText[this.editLine] = this.entitySign.signText[this.editLine].substring(0, this.entitySign.signText[this.editLine].length() - 1);
    101            }
    102
    103            if (allowedCharacters.indexOf(par1) >= 0 && this.entitySign.signText[this.editLine].length() < 15)
    104            {
    105                this.entitySign.signText[this.editLine] = this.entitySign.signText[this.editLine] + par1;
    106            }
    107        }
    108
    109        /**
    110         * Draws the screen and all the components in it.
    111         */
    112        public void drawScreen(int par1, int par2, float par3)
    113        {
    114            this.drawDefaultBackground();
    115            this.drawCenteredString(this.fontRenderer, this.screenTitle, this.width / 2, 40, 16777215);
    116            GL11.glPushMatrix();
    117            GL11.glTranslatef((float)(this.width / 2), 0.0F, 50.0F);
    118            float var4 = 93.75F;
    119            GL11.glScalef(-var4, -var4, -var4);
    120            GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
    121            Block var5 = this.entitySign.getBlockType();
    122
    123            if (var5 == Block.signPost)
    124            {
    125                float var6 = (float)(this.entitySign.getBlockMetadata() * 360) / 16.0F;
    126                GL11.glRotatef(var6, 0.0F, 1.0F, 0.0F);
    127                GL11.glTranslatef(0.0F, -1.0625F, 0.0F);
    128            }
    129            else
    130            {
    131                int var8 = this.entitySign.getBlockMetadata();
    132                float var7 = 0.0F;
    133
    134                if (var8 == 2)
    135                {
    136                    var7 = 180.0F;
    137                }
    138
    139                if (var8 == 4)
    140                {
    141                    var7 = 90.0F;
    142                }
    143
    144                if (var8 == 5)
    145                {
    146                    var7 = -90.0F;
    147                }
    148
    149                GL11.glRotatef(var7, 0.0F, 1.0F, 0.0F);
    150                GL11.glTranslatef(0.0F, -1.0625F, 0.0F);
    151            }
    152
    153            if (this.updateCounter / 6 % 2 == 0)
    154            {
    155                this.entitySign.lineBeingEdited = this.editLine;
    156            }
    157
    158            TileEntityRenderer.instance.renderTileEntityAt(this.entitySign, -0.5D, -0.75D, -0.5D, 0.0F);
    159            this.entitySign.lineBeingEdited = -1;
    160            GL11.glPopMatrix();
    161            super.drawScreen(par1, par2, par3);
    162        }
    163    }