    001package net.minecraft.client.gui.achievement;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import net.minecraft.client.Minecraft;
    006import net.minecraft.client.gui.FontRenderer;
    007import net.minecraft.client.gui.GuiButton;
    008import net.minecraft.client.gui.GuiScreen;
    009import net.minecraft.client.gui.GuiSlot;
    010import net.minecraft.client.renderer.RenderHelper;
    011import net.minecraft.client.renderer.Tessellator;
    012import net.minecraft.client.renderer.entity.RenderItem;
    013import net.minecraft.item.ItemStack;
    014import net.minecraft.stats.StatFileWriter;
    015import net.minecraft.util.StatCollector;
    016import net.minecraft.util.StringTranslate;
    017import org.lwjgl.opengl.GL11;
    018import org.lwjgl.opengl.GL12;
    019
    020@SideOnly(Side.CLIENT)
    021public class GuiStats extends GuiScreen
    022{
    023    private static RenderItem renderItem = new RenderItem();
    024    protected GuiScreen parentGui;
    025
    026    /** The title of the stats screen. */
    027    protected String statsTitle = "Select world";
    028
    029    /** The slot for general stats. */
    030    private GuiSlotStatsGeneral slotGeneral;
    031
    032    /** The slot for item stats. */
    033    private GuiSlotStatsItem slotItem;
    034
    035    /** The slot for block stats. */
    036    private GuiSlotStatsBlock slotBlock;
    037    private StatFileWriter statFileWriter;
    038
    039    /** The currently-selected slot. */
    040    private GuiSlot selectedSlot = null;
    041
    042    public GuiStats(GuiScreen par1GuiScreen, StatFileWriter par2StatFileWriter)
    043    {
    044        this.parentGui = par1GuiScreen;
    045        this.statFileWriter = par2StatFileWriter;
    046    }
    047
    048    /**
    049     * Adds the buttons (and other controls) to the screen in question.
    050     */
    051    public void initGui()
    052    {
    053        this.statsTitle = StatCollector.translateToLocal("gui.stats");
    054        this.slotGeneral = new GuiSlotStatsGeneral(this);
    055        this.slotGeneral.registerScrollButtons(this.buttonList, 1, 1);
    056        this.slotItem = new GuiSlotStatsItem(this);
    057        this.slotItem.registerScrollButtons(this.buttonList, 1, 1);
    058        this.slotBlock = new GuiSlotStatsBlock(this);
    059        this.slotBlock.registerScrollButtons(this.buttonList, 1, 1);
    060        this.selectedSlot = this.slotGeneral;
    061        this.addHeaderButtons();
    062    }
    063
    064    /**
    065     * Creates the buttons that appear at the top of the Stats GUI.
    066     */
    067    public void addHeaderButtons()
    068    {
    069        StringTranslate stringtranslate = StringTranslate.getInstance();
    070        this.buttonList.add(new GuiButton(0, this.width / 2 + 4, this.height - 28, 150, 20, stringtranslate.translateKey("gui.done")));
    071        this.buttonList.add(new GuiButton(1, this.width / 2 - 154, this.height - 52, 100, 20, stringtranslate.translateKey("stat.generalButton")));
    072        GuiButton guibutton;
    073        this.buttonList.add(guibutton = new GuiButton(2, this.width / 2 - 46, this.height - 52, 100, 20, stringtranslate.translateKey("stat.blocksButton")));
    074        GuiButton guibutton1;
    075        this.buttonList.add(guibutton1 = new GuiButton(3, this.width / 2 + 62, this.height - 52, 100, 20, stringtranslate.translateKey("stat.itemsButton")));
    076
    077        if (this.slotBlock.getSize() == 0)
    078        {
    079            guibutton.enabled = false;
    080        }
    081
    082        if (this.slotItem.getSize() == 0)
    083        {
    084            guibutton1.enabled = false;
    085        }
    086    }
    087
    088    /**
    089     * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    090     */
    091    protected void actionPerformed(GuiButton par1GuiButton)
    092    {
    093        if (par1GuiButton.enabled)
    094        {
    095            if (par1GuiButton.id == 0)
    096            {
    097                this.mc.displayGuiScreen(this.parentGui);
    098            }
    099            else if (par1GuiButton.id == 1)
    100            {
    101                this.selectedSlot = this.slotGeneral;
    102            }
    103            else if (par1GuiButton.id == 3)
    104            {
    105                this.selectedSlot = this.slotItem;
    106            }
    107            else if (par1GuiButton.id == 2)
    108            {
    109                this.selectedSlot = this.slotBlock;
    110            }
    111            else
    112            {
    113                this.selectedSlot.actionPerformed(par1GuiButton);
    114            }
    115        }
    116    }
    117
    118    /**
    119     * Draws the screen and all the components in it.
    120     */
    121    public void drawScreen(int par1, int par2, float par3)
    122    {
    123        this.selectedSlot.drawScreen(par1, par2, par3);
    124        this.drawCenteredString(this.fontRenderer, this.statsTitle, this.width / 2, 20, 16777215);
    125        super.drawScreen(par1, par2, par3);
    126    }
    127
    128    /**
    129     * Draws the item sprite on top of the background sprite.
    130     */
    131    private void drawItemSprite(int par1, int par2, int par3)
    132    {
    133        this.drawButtonBackground(par1 + 1, par2 + 1);
    134        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    135        RenderHelper.enableGUIStandardItemLighting();
    136        renderItem.renderItemIntoGUI(this.fontRenderer, this.mc.renderEngine, new ItemStack(par3, 1, 0), par1 + 2, par2 + 2);
    137        RenderHelper.disableStandardItemLighting();
    138        GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    139    }
    140
    141    /**
    142     * Draws a gray box that serves as a button background.
    143     */
    144    private void drawButtonBackground(int par1, int par2)
    145    {
    146        this.drawSprite(par1, par2, 0, 0);
    147    }
    148
    149    /**
    150     * Draws a sprite from /gui/slot.png.
    151     */
    152    private void drawSprite(int par1, int par2, int par3, int par4)
    153    {
    154        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    155        this.mc.renderEngine.bindTexture("/gui/slot.png");
    156        Tessellator tessellator = Tessellator.instance;
    157        tessellator.startDrawingQuads();
    158        tessellator.addVertexWithUV((double)(par1 + 0), (double)(par2 + 18), (double)this.zLevel, (double)((float)(par3 + 0) * 0.0078125F), (double)((float)(par4 + 18) * 0.0078125F));
    159        tessellator.addVertexWithUV((double)(par1 + 18), (double)(par2 + 18), (double)this.zLevel, (double)((float)(par3 + 18) * 0.0078125F), (double)((float)(par4 + 18) * 0.0078125F));
    160        tessellator.addVertexWithUV((double)(par1 + 18), (double)(par2 + 0), (double)this.zLevel, (double)((float)(par3 + 18) * 0.0078125F), (double)((float)(par4 + 0) * 0.0078125F));
    161        tessellator.addVertexWithUV((double)(par1 + 0), (double)(par2 + 0), (double)this.zLevel, (double)((float)(par3 + 0) * 0.0078125F), (double)((float)(par4 + 0) * 0.0078125F));
    162        tessellator.draw();
    163    }
    164
    165    static Minecraft getMinecraft(GuiStats par0GuiStats)
    166    {
    167        return par0GuiStats.mc;
    168    }
    169
    170    /**
    171     * there are 11 identical methods like this
    172     */
    173    static FontRenderer getFontRenderer1(GuiStats par0GuiStats)
    174    {
    175        return par0GuiStats.fontRenderer;
    176    }
    177
    178    static StatFileWriter getStatsFileWriter(GuiStats par0GuiStats)
    179    {
    180        return par0GuiStats.statFileWriter;
    181    }
    182
    183    /**
    184     * there are 11 identical methods like this
    185     */
    186    static FontRenderer getFontRenderer2(GuiStats par0GuiStats)
    187    {
    188        return par0GuiStats.fontRenderer;
    189    }
    190
    191    /**
    192     * there are 11 identical methods like this
    193     */
    194    static FontRenderer getFontRenderer3(GuiStats par0GuiStats)
    195    {
    196        return par0GuiStats.fontRenderer;
    197    }
    198
    199    /**
    200     * exactly the same as 27141
    201     */
    202    static Minecraft getMinecraft1(GuiStats par0GuiStats)
    203    {
    204        return par0GuiStats.mc;
    205    }
    206
    207    /**
    208     * Draws a sprite from /gui/slot.png.
    209     */
    210    static void drawSprite(GuiStats par0GuiStats, int par1, int par2, int par3, int par4)
    211    {
    212        par0GuiStats.drawSprite(par1, par2, par3, par4);
    213    }
    214
    215    /**
    216     * exactly the same as 27141 and 27143
    217     */
    218    static Minecraft getMinecraft2(GuiStats par0GuiStats)
    219    {
    220        return par0GuiStats.mc;
    221    }
    222
    223    /**
    224     * there are 11 identical methods like this
    225     */
    226    static FontRenderer getFontRenderer4(GuiStats par0GuiStats)
    227    {
    228        return par0GuiStats.fontRenderer;
    229    }
    230
    231    /**
    232     * there are 11 identical methods like this
    233     */
    234    static FontRenderer getFontRenderer5(GuiStats par0GuiStats)
    235    {
    236        return par0GuiStats.fontRenderer;
    237    }
    238
    239    /**
    240     * there are 11 identical methods like this
    241     */
    242    static FontRenderer getFontRenderer6(GuiStats par0GuiStats)
    243    {
    244        return par0GuiStats.fontRenderer;
    245    }
    246
    247    /**
    248     * there are 11 identical methods like this
    249     */
    250    static FontRenderer getFontRenderer7(GuiStats par0GuiStats)
    251    {
    252        return par0GuiStats.fontRenderer;
    253    }
    254
    255    /**
    256     * there are 11 identical methods like this
    257     */
    258    static FontRenderer getFontRenderer8(GuiStats par0GuiStats)
    259    {
    260        return par0GuiStats.fontRenderer;
    261    }
    262
    263    static void drawGradientRect(GuiStats par0GuiStats, int par1, int par2, int par3, int par4, int par5, int par6)
    264    {
    265        par0GuiStats.drawGradientRect(par1, par2, par3, par4, par5, par6);
    266    }
    267
    268    /**
    269     * there are 11 identical methods like this
    270     */
    271    static FontRenderer getFontRenderer9(GuiStats par0GuiStats)
    272    {
    273        return par0GuiStats.fontRenderer;
    274    }
    275
    276    /**
    277     * there are 11 identical methods like this
    278     */
    279    static FontRenderer getFontRenderer10(GuiStats par0GuiStats)
    280    {
    281        return par0GuiStats.fontRenderer;
    282    }
    283
    284    /**
    285     * exactly the same as 27129
    286     */
    287    static void drawGradientRect1(GuiStats par0GuiStats, int par1, int par2, int par3, int par4, int par5, int par6)
    288    {
    289        par0GuiStats.drawGradientRect(par1, par2, par3, par4, par5, par6);
    290    }
    291
    292    /**
    293     * there are 11 identical methods like this
    294     */
    295    static FontRenderer getFontRenderer11(GuiStats par0GuiStats)
    296    {
    297        return par0GuiStats.fontRenderer;
    298    }
    299
    300    /**
    301     * Draws the item sprite on top of the background sprite.
    302     */
    303    static void drawItemSprite(GuiStats par0GuiStats, int par1, int par2, int par3)
    304    {
    305        par0GuiStats.drawItemSprite(par1, par2, par3);
    306    }
    307}