    001    package net.minecraft.client.gui;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import net.minecraft.client.settings.EnumOptions;
    006    import net.minecraft.client.settings.GameSettings;
    007    import net.minecraft.util.StatCollector;
    008    import net.minecraft.util.StringTranslate;
    009
    010    @SideOnly(Side.CLIENT)
    011    public class GuiOptions extends GuiScreen
    012    {
    013        /**
    014         * An array of options that can be changed directly from the options GUI.
    015         */
    016        private static final EnumOptions[] relevantOptions = new EnumOptions[] {EnumOptions.MUSIC, EnumOptions.SOUND, EnumOptions.INVERT_MOUSE, EnumOptions.SENSITIVITY, EnumOptions.FOV, EnumOptions.DIFFICULTY};
    017
    018        /**
    019         * A reference to the screen object that created this. Used for navigating between screens.
    020         */
    021        private final GuiScreen parentScreen;
    022
    023        /** Reference to the GameSettings object. */
    024        private final GameSettings options;
    025
    026        /** The title string that is displayed in the top-center of the screen. */
    027        protected String screenTitle = "Options";
    028
    029        public GuiOptions(GuiScreen par1GuiScreen, GameSettings par2GameSettings)
    030        {
    031            this.parentScreen = par1GuiScreen;
    032            this.options = par2GameSettings;
    033        }
    034
    035        /**
    036         * Adds the buttons (and other controls) to the screen in question.
    037         */
    038        public void initGui()
    039        {
    040            StringTranslate var1 = StringTranslate.getInstance();
    041            int var2 = 0;
    042            this.screenTitle = var1.translateKey("options.title");
    043            EnumOptions[] var3 = relevantOptions;
    044            int var4 = var3.length;
    045
    046            for (int var5 = 0; var5 < var4; ++var5)
    047            {
    048                EnumOptions var6 = var3[var5];
    049
    050                if (var6.getEnumFloat())
    051                {
    052                    this.controlList.add(new GuiSlider(var6.returnEnumOrdinal(), this.width / 2 - 155 + var2 % 2 * 160, this.height / 6 + 24 * (var2 >> 1), var6, this.options.getKeyBinding(var6), this.options.getOptionFloatValue(var6)));
    053                }
    054                else
    055                {
    056                    GuiSmallButton var7 = new GuiSmallButton(var6.returnEnumOrdinal(), this.width / 2 - 155 + var2 % 2 * 160, this.height / 6 + 24 * (var2 >> 1), var6, this.options.getKeyBinding(var6));
    057
    058                    if (var6 == EnumOptions.DIFFICULTY && this.mc.theWorld != null && this.mc.theWorld.getWorldInfo().isHardcoreModeEnabled())
    059                    {
    060                        var7.enabled = false;
    061                        var7.displayString = StatCollector.translateToLocal("options.difficulty") + ": " + StatCollector.translateToLocal("options.difficulty.hardcore");
    062                    }
    063
    064                    this.controlList.add(var7);
    065                }
    066
    067                ++var2;
    068            }
    069
    070            this.controlList.add(new GuiButton(101, this.width / 2 - 152, this.height / 6 + 96 - 6, 150, 20, var1.translateKey("options.video")));
    071            this.controlList.add(new GuiButton(100, this.width / 2 + 2, this.height / 6 + 96 - 6, 150, 20, var1.translateKey("options.controls")));
    072            this.controlList.add(new GuiButton(102, this.width / 2 - 152, this.height / 6 + 120 - 6, 150, 20, var1.translateKey("options.language")));
    073            this.controlList.add(new GuiButton(103, this.width / 2 + 2, this.height / 6 + 120 - 6, 150, 20, var1.translateKey("options.multiplayer.title")));
    074            this.controlList.add(new GuiButton(104, this.width / 2 + 2, this.height / 6 + 144 - 6, 150, 20, var1.translateKey("options.snooper.view")));
    075            this.controlList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 168, var1.translateKey("gui.done")));
    076        }
    077
    078        /**
    079         * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    080         */
    081        protected void actionPerformed(GuiButton par1GuiButton)
    082        {
    083            if (par1GuiButton.enabled)
    084            {
    085                if (par1GuiButton.id < 100 && par1GuiButton instanceof GuiSmallButton)
    086                {
    087                    this.options.setOptionValue(((GuiSmallButton)par1GuiButton).returnEnumOptions(), 1);
    088                    par1GuiButton.displayString = this.options.getKeyBinding(EnumOptions.getEnumOptions(par1GuiButton.id));
    089                }
    090
    091                if (par1GuiButton.id == 101)
    092                {
    093                    this.mc.gameSettings.saveOptions();
    094                    this.mc.displayGuiScreen(new GuiVideoSettings(this, this.options));
    095                }
    096
    097                if (par1GuiButton.id == 100)
    098                {
    099                    this.mc.gameSettings.saveOptions();
    100                    this.mc.displayGuiScreen(new GuiControls(this, this.options));
    101                }
    102
    103                if (par1GuiButton.id == 102)
    104                {
    105                    this.mc.gameSettings.saveOptions();
    106                    this.mc.displayGuiScreen(new GuiLanguage(this, this.options));
    107                }
    108
    109                if (par1GuiButton.id == 103)
    110                {
    111                    this.mc.gameSettings.saveOptions();
    112                    this.mc.displayGuiScreen(new ScreenChatOptions(this, this.options));
    113                }
    114
    115                if (par1GuiButton.id == 104)
    116                {
    117                    this.mc.gameSettings.saveOptions();
    118                    this.mc.displayGuiScreen(new GuiSnooper(this, this.options));
    119                }
    120
    121                if (par1GuiButton.id == 200)
    122                {
    123                    this.mc.gameSettings.saveOptions();
    124                    this.mc.displayGuiScreen(this.parentScreen);
    125                }
    126            }
    127        }
    128
    129        /**
    130         * Draws the screen and all the components in it.
    131         */
    132        public void drawScreen(int par1, int par2, float par3)
    133        {
    134            this.drawDefaultBackground();
    135            this.drawCenteredString(this.fontRenderer, this.screenTitle, this.width / 2, 20, 16777215);
    136            super.drawScreen(par1, par2, par3);
    137        }
    138    }