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