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.StringTranslate; 008 009@SideOnly(Side.CLIENT) 010public class ScreenChatOptions extends GuiScreen 011{ 012 /** An array of all EnumOptions which are to do with chat. */ 013 private static final EnumOptions[] allScreenChatOptions = new EnumOptions[] {EnumOptions.CHAT_VISIBILITY, EnumOptions.CHAT_COLOR, EnumOptions.CHAT_LINKS, EnumOptions.CHAT_OPACITY, EnumOptions.CHAT_LINKS_PROMPT, EnumOptions.CHAT_SCALE, EnumOptions.CHAT_HEIGHT_FOCUSED, EnumOptions.CHAT_HEIGHT_UNFOCUSED, EnumOptions.CHAT_WIDTH}; 014 private static final EnumOptions[] allMultiplayerOptions = new EnumOptions[] {EnumOptions.SHOW_CAPE}; 015 016 /** Instance of GuiScreen. */ 017 private final GuiScreen theGuiScreen; 018 019 /** Instance of GameSettings file. */ 020 private final GameSettings theSettings; 021 private String theChatOptions; 022 private String field_82268_n; 023 private int field_82269_o = 0; 024 025 public ScreenChatOptions(GuiScreen par1GuiScreen, GameSettings par2GameSettings) 026 { 027 this.theGuiScreen = par1GuiScreen; 028 this.theSettings = par2GameSettings; 029 } 030 031 /** 032 * Adds the buttons (and other controls) to the screen in question. 033 */ 034 public void initGui() 035 { 036 StringTranslate stringtranslate = StringTranslate.getInstance(); 037 int i = 0; 038 this.theChatOptions = stringtranslate.translateKey("options.chat.title"); 039 this.field_82268_n = stringtranslate.translateKey("options.multiplayer.title"); 040 EnumOptions[] aenumoptions = allScreenChatOptions; 041 int j = aenumoptions.length; 042 int k; 043 EnumOptions enumoptions; 044 045 for (k = 0; k < j; ++k) 046 { 047 enumoptions = aenumoptions[k]; 048 049 if (enumoptions.getEnumFloat()) 050 { 051 this.buttonList.add(new GuiSlider(enumoptions.returnEnumOrdinal(), this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), enumoptions, this.theSettings.getKeyBinding(enumoptions), this.theSettings.getOptionFloatValue(enumoptions))); 052 } 053 else 054 { 055 this.buttonList.add(new GuiSmallButton(enumoptions.returnEnumOrdinal(), this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), enumoptions, this.theSettings.getKeyBinding(enumoptions))); 056 } 057 058 ++i; 059 } 060 061 if (i % 2 == 1) 062 { 063 ++i; 064 } 065 066 this.field_82269_o = this.height / 6 + 24 * (i >> 1); 067 i += 2; 068 aenumoptions = allMultiplayerOptions; 069 j = aenumoptions.length; 070 071 for (k = 0; k < j; ++k) 072 { 073 enumoptions = aenumoptions[k]; 074 075 if (enumoptions.getEnumFloat()) 076 { 077 this.buttonList.add(new GuiSlider(enumoptions.returnEnumOrdinal(), this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), enumoptions, this.theSettings.getKeyBinding(enumoptions), this.theSettings.getOptionFloatValue(enumoptions))); 078 } 079 else 080 { 081 this.buttonList.add(new GuiSmallButton(enumoptions.returnEnumOrdinal(), this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), enumoptions, this.theSettings.getKeyBinding(enumoptions))); 082 } 083 084 ++i; 085 } 086 087 this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 168, stringtranslate.translateKey("gui.done"))); 088 } 089 090 /** 091 * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e). 092 */ 093 protected void actionPerformed(GuiButton par1GuiButton) 094 { 095 if (par1GuiButton.enabled) 096 { 097 if (par1GuiButton.id < 100 && par1GuiButton instanceof GuiSmallButton) 098 { 099 this.theSettings.setOptionValue(((GuiSmallButton)par1GuiButton).returnEnumOptions(), 1); 100 par1GuiButton.displayString = this.theSettings.getKeyBinding(EnumOptions.getEnumOptions(par1GuiButton.id)); 101 } 102 103 if (par1GuiButton.id == 200) 104 { 105 this.mc.gameSettings.saveOptions(); 106 this.mc.displayGuiScreen(this.theGuiScreen); 107 } 108 } 109 } 110 111 /** 112 * Draws the screen and all the components in it. 113 */ 114 public void drawScreen(int par1, int par2, float par3) 115 { 116 this.drawDefaultBackground(); 117 this.drawCenteredString(this.fontRenderer, this.theChatOptions, this.width / 2, 20, 16777215); 118 this.drawCenteredString(this.fontRenderer, this.field_82268_n, this.width / 2, this.field_82269_o + 7, 16777215); 119 super.drawScreen(par1, par2, par3); 120 } 121}