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