    001    package net.minecraft.src;
    002
    003    import net.minecraftforge.client.GuiControlsScrollPanel;
    004
    005    import cpw.mods.fml.common.Side;
    006    import cpw.mods.fml.common.asm.SideOnly;
    007
    008    @SideOnly(Side.CLIENT)
    009    public class GuiControls extends GuiScreen
    010    {
    011        /**
    012         * A reference to the screen object that created this. Used for navigating between screens.
    013         */
    014        private GuiScreen parentScreen;
    015
    016        /** The title string that is displayed in the top-center of the screen. */
    017        protected String screenTitle = "Controls";
    018
    019        /** Reference to the GameSettings object. */
    020        private GameSettings options;
    021
    022        /** The ID of the  button that has been pressed. */
    023        private int buttonId = -1;
    024
    025        private GuiControlsScrollPanel scrollPane;
    026
    027        public GuiControls(GuiScreen par1GuiScreen, GameSettings par2GameSettings)
    028        {
    029            this.parentScreen = par1GuiScreen;
    030            this.options = par2GameSettings;
    031        }
    032
    033        private int func_73907_g()
    034        {
    035            return this.width / 2 - 155;
    036        }
    037
    038        /**
    039         * Adds the buttons (and other controls) to the screen in question.
    040         */
    041        public void initGui()
    042        {
    043            scrollPane = new GuiControlsScrollPanel(this, options, mc);
    044            StringTranslate var1 = StringTranslate.getInstance();
    045            int var2 = this.func_73907_g();
    046
    047            this.controlList.add(new GuiButton(200, this.width / 2 - 100, this.height - 28, var1.translateKey("gui.done")));
    048            scrollPane.registerScrollButtons(controlList, 7, 8);
    049            this.screenTitle = var1.translateKey("controls.title");
    050        }
    051
    052        /**
    053         * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    054         */
    055        protected void actionPerformed(GuiButton par1GuiButton)
    056        {
    057            if (par1GuiButton.id == 200)
    058            {
    059                this.mc.displayGuiScreen(this.parentScreen);
    060            }
    061        }
    062
    063        /**
    064         * Called when the mouse is clicked.
    065         */
    066        protected void mouseClicked(int par1, int par2, int par3)
    067        {
    068            super.mouseClicked(par1, par2, par3);
    069        }
    070
    071        /**
    072         * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
    073         */
    074        protected void keyTyped(char par1, int par2)
    075        {
    076            if (scrollPane.keyTyped(par1, par2))
    077            {
    078                super.keyTyped(par1, par2);
    079            }
    080        }
    081
    082        /**
    083         * Draws the screen and all the components in it.
    084         */
    085        public void drawScreen(int par1, int par2, float par3)
    086        {
    087            this.drawDefaultBackground();
    088            scrollPane.drawScreen(par1, par2, par3);
    089            drawCenteredString(fontRenderer, screenTitle, width / 2, 4, 0xffffff);
    090            super.drawScreen(par1, par2, par3);
    091        }
    092    }