001    package net.minecraft.src;
002    
003    import cpw.mods.fml.common.Side;
004    import cpw.mods.fml.common.asm.SideOnly;
005    
006    @SideOnly(Side.CLIENT)
007    public class ScreenChatOptions extends GuiScreen
008    {
009        /** An array of all EnumOptions which are to do with chat. */
010        private static final EnumOptions[] allScreenChatOptions = new EnumOptions[] {EnumOptions.CHAT_VISIBILITY, EnumOptions.CHAT_COLOR, EnumOptions.CHAT_LINKS, EnumOptions.CHAT_OPACITY, EnumOptions.CHAT_LINKS_PROMPT};
011    
012        /** Instance of GuiScreen. */
013        private final GuiScreen theGuiScreen;
014    
015        /** Instance of GameSettings file. */
016        private final GameSettings theSettings;
017        private String theChatOptions;
018    
019        public ScreenChatOptions(GuiScreen par1GuiScreen, GameSettings par2GameSettings)
020        {
021            this.theGuiScreen = par1GuiScreen;
022            this.theSettings = par2GameSettings;
023        }
024    
025        /**
026         * Adds the buttons (and other controls) to the screen in question.
027         */
028        public void initGui()
029        {
030            StringTranslate var1 = StringTranslate.getInstance();
031            int var2 = 0;
032            this.theChatOptions = var1.translateKey("options.chat.title");
033            EnumOptions[] var3 = allScreenChatOptions;
034            int var4 = var3.length;
035    
036            for (int var5 = 0; var5 < var4; ++var5)
037            {
038                EnumOptions var6 = var3[var5];
039    
040                if (var6.getEnumFloat())
041                {
042                    this.controlList.add(new GuiSlider(var6.returnEnumOrdinal(), this.width / 2 - 155 + var2 % 2 * 160, this.height / 6 + 24 * (var2 >> 1), var6, this.theSettings.getKeyBinding(var6), this.theSettings.getOptionFloatValue(var6)));
043                }
044                else
045                {
046                    this.controlList.add(new GuiSmallButton(var6.returnEnumOrdinal(), this.width / 2 - 155 + var2 % 2 * 160, this.height / 6 + 24 * (var2 >> 1), var6, this.theSettings.getKeyBinding(var6)));
047                }
048    
049                ++var2;
050            }
051    
052            this.controlList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 168, var1.translateKey("gui.done")));
053        }
054    
055        /**
056         * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
057         */
058        protected void actionPerformed(GuiButton par1GuiButton)
059        {
060            if (par1GuiButton.enabled)
061            {
062                if (par1GuiButton.id < 100 && par1GuiButton instanceof GuiSmallButton)
063                {
064                    this.theSettings.setOptionValue(((GuiSmallButton)par1GuiButton).returnEnumOptions(), 1);
065                    par1GuiButton.displayString = this.theSettings.getKeyBinding(EnumOptions.getEnumOptions(par1GuiButton.id));
066                }
067    
068                if (par1GuiButton.id == 200)
069                {
070                    this.mc.gameSettings.saveOptions();
071                    this.mc.displayGuiScreen(this.theGuiScreen);
072                }
073            }
074        }
075    
076        /**
077         * Draws the screen and all the components in it.
078         */
079        public void drawScreen(int par1, int par2, float par3)
080        {
081            this.drawDefaultBackground();
082            this.drawCenteredString(this.fontRenderer, this.theChatOptions, this.width / 2, 20, 16777215);
083            super.drawScreen(par1, par2, par3);
084        }
085    }