001package net.minecraft.client.gui;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import net.minecraft.client.settings.GameSettings;
006import net.minecraft.client.settings.KeyBinding;
007import net.minecraft.util.EnumChatFormatting;
008import net.minecraft.util.StringTranslate;
009
010import net.minecraftforge.client.GuiControlsScrollPanel;
011
012@SideOnly(Side.CLIENT)
013public class GuiControls extends GuiScreen
014{
015    /**
016     * A reference to the screen object that created this. Used for navigating between screens.
017     */
018    private GuiScreen parentScreen;
019
020    /** The title string that is displayed in the top-center of the screen. */
021    protected String screenTitle = "Controls";
022
023    /** Reference to the GameSettings object. */
024    private GameSettings options;
025
026    /** The ID of the  button that has been pressed. */
027    private int buttonId = -1;
028
029    private GuiControlsScrollPanel scrollPane;
030
031    public GuiControls(GuiScreen par1GuiScreen, GameSettings par2GameSettings)
032    {
033        this.parentScreen = par1GuiScreen;
034        this.options = par2GameSettings;
035    }
036
037    private int func_73907_g()
038    {
039        return this.width / 2 - 155;
040    }
041
042    /**
043     * Adds the buttons (and other controls) to the screen in question.
044     */
045    public void initGui()
046    {
047        scrollPane = new GuiControlsScrollPanel(this, options, mc);
048        StringTranslate stringtranslate = StringTranslate.getInstance();
049        this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height - 28, stringtranslate.translateKey("gui.done")));
050        scrollPane.registerScrollButtons(buttonList, 7, 8);
051        this.screenTitle = stringtranslate.translateKey("controls.title");
052    }
053
054    /**
055     * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
056     */
057    protected void actionPerformed(GuiButton par1GuiButton)
058    {        
059        if (par1GuiButton.id == 200)
060        {
061            this.mc.displayGuiScreen(this.parentScreen);
062        }
063    }
064
065    /**
066     * Called when the mouse is clicked.
067     */
068    protected void mouseClicked(int par1, int par2, int par3)
069    {
070        super.mouseClicked(par1, par2, par3);
071    }
072
073    /**
074     * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
075     */
076    protected void keyTyped(char par1, int par2)
077    {
078        if (scrollPane.keyTyped(par1, par2))
079        {
080            super.keyTyped(par1, par2);
081        }
082    }
083
084    /**
085     * Draws the screen and all the components in it.
086     */
087    public void drawScreen(int par1, int par2, float par3)
088    {
089        this.drawDefaultBackground();
090        /* Forge Start: Moved all rendering to GuiControlsScrollPanel
091        this.drawCenteredString(this.fontRenderer, this.screenTitle, this.width / 2, 20, 16777215);
092        int k = this.func_73907_g();
093        int l = 0;
094
095        while (l < this.options.keyBindings.length)
096        {
097            boolean flag = false;
098            int i1 = 0;
099
100            while (true)
101            {
102                if (i1 < this.options.keyBindings.length)
103                {
104                    if (i1 == l || this.options.keyBindings[l].keyCode != this.options.keyBindings[i1].keyCode)
105                    {
106                        ++i1;
107                        continue;
108                    }
109
110                    flag = true;
111                }
112
113                if (this.buttonId == l)
114                {
115                    ((GuiButton)this.buttonList.get(l)).displayString = "" + EnumChatFormatting.WHITE + "> " + EnumChatFormatting.YELLOW + "??? " + EnumChatFormatting.WHITE + "<";
116                }
117                else if (flag)
118                {
119                    ((GuiButton)this.buttonList.get(l)).displayString = EnumChatFormatting.RED + this.options.getOptionDisplayString(l);
120                }
121                else
122                {
123                    ((GuiButton)this.buttonList.get(l)).displayString = this.options.getOptionDisplayString(l);
124                }
125
126                this.drawString(this.fontRenderer, this.options.getKeyBindingDescription(l), k + l % 2 * 160 + 70 + 6, this.height / 6 + 24 * (l >> 1) + 7, -1);
127                ++l;
128                break;
129            }
130        }
131        */
132        scrollPane.drawScreen(par1, par2, par3);
133        drawCenteredString(fontRenderer, screenTitle, width / 2, 4, 0xffffff);
134        //Forge End
135
136        super.drawScreen(par1, par2, par3);
137    }
138}