    001    package net.minecraft.client.gui;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.util.ArrayList;
    006    import java.util.Iterator;
    007    import java.util.List;
    008    import java.util.TreeMap;
    009    import java.util.Map.Entry;
    010    import net.minecraft.client.settings.EnumOptions;
    011    import net.minecraft.client.settings.GameSettings;
    012    import net.minecraft.util.StatCollector;
    013
    014    @SideOnly(Side.CLIENT)
    015    public 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 var1 = StatCollector.translateToLocal("options.snooper.desc");
    044            ArrayList var2 = new ArrayList();
    045            Iterator var3 = this.fontRenderer.listFormattedStringToWidth(var1, this.width - 30).iterator();
    046
    047            while (var3.hasNext())
    048            {
    049                String var4 = (String)var3.next();
    050                var2.add(var4);
    051            }
    052
    053            this.field_74101_n = (String[])var2.toArray(new String[0]);
    054            this.field_74098_c.clear();
    055            this.field_74096_d.clear();
    056            this.controlList.add(this.buttonAllowSnooping = new GuiButton(1, this.width / 2 - 152, this.height - 30, 150, 20, this.snooperGameSettings.getKeyBinding(EnumOptions.SNOOPER_ENABLED)));
    057            this.controlList.add(new GuiButton(2, this.width / 2 + 2, this.height - 30, 150, 20, StatCollector.translateToLocal("gui.done")));
    058            boolean var6 = this.mc.getIntegratedServer() != null && this.mc.getIntegratedServer().getPlayerUsageSnooper() != null;
    059            Iterator var7 = (new TreeMap(this.mc.getPlayerUsageSnooper().getCurrentStats())).entrySet().iterator();
    060            Entry var5;
    061
    062            while (var7.hasNext())
    063            {
    064                var5 = (Entry)var7.next();
    065                this.field_74098_c.add((var6 ? "C " : "") + (String)var5.getKey());
    066                this.field_74096_d.add(this.fontRenderer.trimStringToWidth((String)var5.getValue(), this.width - 220));
    067            }
    068
    069            if (var6)
    070            {
    071                var7 = (new TreeMap(this.mc.getIntegratedServer().getPlayerUsageSnooper().getCurrentStats())).entrySet().iterator();
    072
    073                while (var7.hasNext())
    074                {
    075                    var5 = (Entry)var7.next();
    076                    this.field_74098_c.add("S " + (String)var5.getKey());
    077                    this.field_74096_d.add(this.fontRenderer.trimStringToWidth((String)var5.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 var4 = 22;
    115            String[] var5 = this.field_74101_n;
    116            int var6 = var5.length;
    117
    118            for (int var7 = 0; var7 < var6; ++var7)
    119            {
    120                String var8 = var5[var7];
    121                this.drawCenteredString(this.fontRenderer, var8, this.width / 2, var4, 8421504);
    122                var4 += 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    }