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