    001package net.minecraft.client.gui;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.util.ArrayList;
    006import java.util.Iterator;
    007import java.util.List;
    008import java.util.TreeMap;
    009import java.util.Map.Entry;
    010import net.minecraft.client.settings.EnumOptions;
    011import net.minecraft.client.settings.GameSettings;
    012import net.minecraft.util.StatCollector;
    013
    014@SideOnly(Side.CLIENT)
    015public class GuiSnooper extends GuiScreen
    016{
    017    /** Instance of GuiScreen. */
    018    private final GuiScreen snooperGuiScreen;
    019
    020    /** Instance of GameSettings. */
    021    private final GameSettings snooperGameSettings;
    022    private final List field_74098_c = new ArrayList();
    023    private final List field_74096_d = new ArrayList();
    024
    025    /** The Snooper title. */
    026    private String snooperTitle;
    027    private String[] field_74101_n;
    028    private GuiSnooperList snooperList;
    029    private GuiButton buttonAllowSnooping;
    030
    031    public GuiSnooper(GuiScreen par1GuiScreen, GameSettings par2GameSettings)
    032    {
    033        this.snooperGuiScreen = par1GuiScreen;
    034        this.snooperGameSettings = par2GameSettings;
    035    }
    036
    037    /**
    038     * Adds the buttons (and other controls) to the screen in question.
    039     */
    040    public void initGui()
    041    {
    042        this.snooperTitle = StatCollector.translateToLocal("options.snooper.title");
    043        String s = StatCollector.translateToLocal("options.snooper.desc");
    044        ArrayList arraylist = new ArrayList();
    045        Iterator iterator = this.fontRenderer.listFormattedStringToWidth(s, this.width - 30).iterator();
    046
    047        while (iterator.hasNext())
    048        {
    049            String s1 = (String)iterator.next();
    050            arraylist.add(s1);
    051        }
    052
    053        this.field_74101_n = (String[])arraylist.toArray(new String[0]);
    054        this.field_74098_c.clear();
    055        this.field_74096_d.clear();
    056        this.buttonList.add(this.buttonAllowSnooping = new GuiButton(1, this.width / 2 - 152, this.height - 30, 150, 20, this.snooperGameSettings.getKeyBinding(EnumOptions.SNOOPER_ENABLED)));
    057        this.buttonList.add(new GuiButton(2, this.width / 2 + 2, this.height - 30, 150, 20, StatCollector.translateToLocal("gui.done")));
    058        boolean flag = this.mc.getIntegratedServer() != null && this.mc.getIntegratedServer().getPlayerUsageSnooper() != null;
    059        Iterator iterator1 = (new TreeMap(this.mc.getPlayerUsageSnooper().getCurrentStats())).entrySet().iterator();
    060        Entry entry;
    061
    062        while (iterator1.hasNext())
    063        {
    064            entry = (Entry)iterator1.next();
    065            this.field_74098_c.add((flag ? "C " : "") + (String)entry.getKey());
    066            this.field_74096_d.add(this.fontRenderer.trimStringToWidth((String)entry.getValue(), this.width - 220));
    067        }
    068
    069        if (flag)
    070        {
    071            iterator1 = (new TreeMap(this.mc.getIntegratedServer().getPlayerUsageSnooper().getCurrentStats())).entrySet().iterator();
    072
    073            while (iterator1.hasNext())
    074            {
    075                entry = (Entry)iterator1.next();
    076                this.field_74098_c.add("S " + (String)entry.getKey());
    077                this.field_74096_d.add(this.fontRenderer.trimStringToWidth((String)entry.getValue(), this.width - 220));
    078            }
    079        }
    080
    081        this.snooperList = new GuiSnooperList(this);
    082    }
    083
    084    /**
    085     * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    086     */
    087    protected void actionPerformed(GuiButton par1GuiButton)
    088    {
    089        if (par1GuiButton.enabled)
    090        {
    091            if (par1GuiButton.id == 2)
    092            {
    093                this.snooperGameSettings.saveOptions();
    094                this.snooperGameSettings.saveOptions();
    095                this.mc.displayGuiScreen(this.snooperGuiScreen);
    096            }
    097
    098            if (par1GuiButton.id == 1)
    099            {
    100                this.snooperGameSettings.setOptionValue(EnumOptions.SNOOPER_ENABLED, 1);
    101                this.buttonAllowSnooping.displayString = this.snooperGameSettings.getKeyBinding(EnumOptions.SNOOPER_ENABLED);
    102            }
    103        }
    104    }
    105
    106    /**
    107     * Draws the screen and all the components in it.
    108     */
    109    public void drawScreen(int par1, int par2, float par3)
    110    {
    111        this.drawDefaultBackground();
    112        this.snooperList.drawScreen(par1, par2, par3);
    113        this.drawCenteredString(this.fontRenderer, this.snooperTitle, this.width / 2, 8, 16777215);
    114        int k = 22;
    115        String[] astring = this.field_74101_n;
    116        int l = astring.length;
    117
    118        for (int i1 = 0; i1 < l; ++i1)
    119        {
    120            String s = astring[i1];
    121            this.drawCenteredString(this.fontRenderer, s, this.width / 2, k, 8421504);
    122            k += this.fontRenderer.FONT_HEIGHT;
    123        }
    124
    125        super.drawScreen(par1, par2, par3);
    126    }
    127
    128    static List func_74095_a(GuiSnooper par0GuiSnooper)
    129    {
    130        return par0GuiSnooper.field_74098_c;
    131    }
    132
    133    static List func_74094_b(GuiSnooper par0GuiSnooper)
    134    {
    135        return par0GuiSnooper.field_74096_d;
    136    }
    137}