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