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