    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.util.StatCollector;
    008import net.minecraft.util.StringTranslate;
    009
    010@SideOnly(Side.CLIENT)
    011public class GuiVideoSettings extends GuiScreen
    012{
    013    private GuiScreen parentGuiScreen;
    014
    015    /** The title string that is displayed in the top-center of the screen. */
    016    protected String screenTitle = "Video Settings";
    017
    018    /** GUI game settings */
    019    private GameSettings guiGameSettings;
    020
    021    /**
    022     * True if the system is 64-bit (using a simple indexOf test on a system property)
    023     */
    024    private boolean is64bit = false;
    025
    026    /** An array of all of EnumOption's video options. */
    027    private static EnumOptions[] videoOptions = new EnumOptions[] {EnumOptions.GRAPHICS, EnumOptions.RENDER_DISTANCE, EnumOptions.AMBIENT_OCCLUSION, EnumOptions.FRAMERATE_LIMIT, EnumOptions.ANAGLYPH, EnumOptions.VIEW_BOBBING, EnumOptions.GUI_SCALE, EnumOptions.ADVANCED_OPENGL, EnumOptions.GAMMA, EnumOptions.RENDER_CLOUDS, EnumOptions.PARTICLES, EnumOptions.USE_SERVER_TEXTURES, EnumOptions.USE_FULLSCREEN, EnumOptions.ENABLE_VSYNC};
    028
    029    public GuiVideoSettings(GuiScreen par1GuiScreen, GameSettings par2GameSettings)
    030    {
    031        this.parentGuiScreen = par1GuiScreen;
    032        this.guiGameSettings = par2GameSettings;
    033    }
    034
    035    /**
    036     * Adds the buttons (and other controls) to the screen in question.
    037     */
    038    public void initGui()
    039    {
    040        StringTranslate stringtranslate = StringTranslate.getInstance();
    041        this.screenTitle = stringtranslate.translateKey("options.videoTitle");
    042        this.buttonList.clear();
    043        this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 168, stringtranslate.translateKey("gui.done")));
    044        this.is64bit = false;
    045        String[] astring = new String[] {"sun.arch.data.model", "com.ibm.vm.bitmode", "os.arch"};
    046        String[] astring1 = astring;
    047        int i = astring.length;
    048
    049        for (int j = 0; j < i; ++j)
    050        {
    051            String s = astring1[j];
    052            String s1 = System.getProperty(s);
    053
    054            if (s1 != null && s1.contains("64"))
    055            {
    056                this.is64bit = true;
    057                break;
    058            }
    059        }
    060
    061        int k = 0;
    062        i = this.is64bit ? 0 : -15;
    063        EnumOptions[] aenumoptions = videoOptions;
    064        int l = aenumoptions.length;
    065
    066        for (int i1 = 0; i1 < l; ++i1)
    067        {
    068            EnumOptions enumoptions = aenumoptions[i1];
    069
    070            if (enumoptions.getEnumFloat())
    071            {
    072                this.buttonList.add(new GuiSlider(enumoptions.returnEnumOrdinal(), this.width / 2 - 155 + k % 2 * 160, this.height / 7 + i + 24 * (k >> 1), enumoptions, this.guiGameSettings.getKeyBinding(enumoptions), this.guiGameSettings.getOptionFloatValue(enumoptions)));
    073            }
    074            else
    075            {
    076                this.buttonList.add(new GuiSmallButton(enumoptions.returnEnumOrdinal(), this.width / 2 - 155 + k % 2 * 160, this.height / 7 + i + 24 * (k >> 1), enumoptions, this.guiGameSettings.getKeyBinding(enumoptions)));
    077            }
    078
    079            ++k;
    080        }
    081    }
    082
    083    /**
    084     * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    085     */
    086    protected void actionPerformed(GuiButton par1GuiButton)
    087    {
    088        if (par1GuiButton.enabled)
    089        {
    090            int i = this.guiGameSettings.guiScale;
    091
    092            if (par1GuiButton.id < 100 && par1GuiButton instanceof GuiSmallButton)
    093            {
    094                this.guiGameSettings.setOptionValue(((GuiSmallButton)par1GuiButton).returnEnumOptions(), 1);
    095                par1GuiButton.displayString = this.guiGameSettings.getKeyBinding(EnumOptions.getEnumOptions(par1GuiButton.id));
    096            }
    097
    098            if (par1GuiButton.id == 200)
    099            {
    100                this.mc.gameSettings.saveOptions();
    101                this.mc.displayGuiScreen(this.parentGuiScreen);
    102            }
    103
    104            if (this.guiGameSettings.guiScale != i)
    105            {
    106                ScaledResolution scaledresolution = new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight);
    107                int j = scaledresolution.getScaledWidth();
    108                int k = scaledresolution.getScaledHeight();
    109                this.setWorldAndResolution(this.mc, j, k);
    110            }
    111        }
    112    }
    113
    114    /**
    115     * Draws the screen and all the components in it.
    116     */
    117    public void drawScreen(int par1, int par2, float par3)
    118    {
    119        this.drawDefaultBackground();
    120        this.drawCenteredString(this.fontRenderer, this.screenTitle, this.width / 2, this.is64bit ? 20 : 5, 16777215);
    121
    122        if (!this.is64bit && this.guiGameSettings.renderDistance == 0)
    123        {
    124            this.drawCenteredString(this.fontRenderer, StatCollector.translateToLocal("options.farWarning1"), this.width / 2, this.height / 6 + 144 + 1, 11468800);
    125            this.drawCenteredString(this.fontRenderer, StatCollector.translateToLocal("options.farWarning2"), this.width / 2, this.height / 6 + 144 + 13, 11468800);
    126        }
    127
    128        super.drawScreen(par1, par2, par3);
    129    }
    130}