    001    /*
    002     * The FML Forge Mod Loader suite.
    003     * Copyright (C) 2012 cpw
    004     *
    005     * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free
    006     * Software Foundation; either version 2.1 of the License, or any later version.
    007     *
    008     * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
    009     * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    010     *
    011     * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51
    012     * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
    013     */
    014
    015    package cpw.mods.fml.client;
    016
    017    import java.awt.Dimension;
    018    import java.util.ArrayList;
    019
    020    import net.minecraft.client.Minecraft;
    021    import net.minecraft.client.gui.FontRenderer;
    022    import net.minecraft.client.gui.GuiButton;
    023    import net.minecraft.client.gui.GuiScreen;
    024    import net.minecraft.client.gui.GuiSmallButton;
    025    import net.minecraft.client.renderer.Tessellator;
    026    import net.minecraft.util.StringTranslate;
    027
    028    import org.lwjgl.opengl.GL11;
    029
    030    import com.google.common.base.Strings;
    031
    032    import cpw.mods.fml.common.Loader;
    033    import cpw.mods.fml.common.ModContainer;
    034
    035    /**
    036     * @author cpw
    037     *
    038     */
    039    public class GuiModList extends GuiScreen
    040    {
    041        private GuiScreen mainMenu;
    042        private GuiSlotModList modList;
    043        private int selected = -1;
    044        private ModContainer selectedMod;
    045        private int listWidth;
    046        private ArrayList<ModContainer> mods;
    047
    048        /**
    049         * @param mainMenu
    050         */
    051        public GuiModList(GuiScreen mainMenu)
    052        {
    053            this.mainMenu=mainMenu;
    054            this.mods=new ArrayList<ModContainer>();
    055            FMLClientHandler.instance().addSpecialModEntries(mods);
    056            for (ModContainer mod : Loader.instance().getModList()) {
    057                if (mod.getMetadata()!=null && mod.getMetadata().parentMod==null && !Strings.isNullOrEmpty(mod.getMetadata().parent)) {
    058                    String parentMod = mod.getMetadata().parent;
    059                    ModContainer parentContainer = Loader.instance().getIndexedModList().get(parentMod);
    060                    if (parentContainer != null)
    061                    {
    062                        mod.getMetadata().parentMod = parentContainer;
    063                        parentContainer.getMetadata().childMods.add(mod);
    064                        continue;
    065                    }
    066                }
    067                else if (mod.getMetadata()!=null && mod.getMetadata().parentMod!=null)
    068                {
    069                     continue;
    070                }
    071                mods.add(mod);
    072            }
    073        }
    074
    075        @Override
    076
    077        /**
    078         * Adds the buttons (and other controls) to the screen in question.
    079         */
    080        public void initGui()
    081        {
    082            for (ModContainer mod : mods) {
    083                listWidth=Math.max(listWidth,getFontRenderer().getStringWidth(mod.getName()) + 10);
    084                listWidth=Math.max(listWidth,getFontRenderer().getStringWidth(mod.getVersion()) + 10);
    085            }
    086            listWidth=Math.min(listWidth, 150);
    087            StringTranslate translations = StringTranslate.getInstance();
    088            this.controlList.add(new GuiSmallButton(6, this.width / 2 - 75, this.height - 38, translations.translateKey("gui.done")));
    089            this.modList=new GuiSlotModList(this, mods, listWidth);
    090            this.modList.registerScrollButtons(this.controlList, 7, 8);
    091        }
    092
    093        @Override
    094
    095        /**
    096         * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    097         */
    098        protected void actionPerformed(GuiButton button) {
    099            if (button.enabled)
    100            {
    101                switch (button.id)
    102                {
    103                    case 6:
    104                        this.mc.displayGuiScreen(this.mainMenu);
    105                        return;
    106                }
    107            }
    108            super.actionPerformed(button);
    109        }
    110
    111        public int drawLine(String line, int offset, int shifty)
    112        {
    113            this.fontRenderer.drawString(line, offset, shifty, 0xd7edea);
    114            return shifty + 10;
    115        }
    116
    117        @Override
    118
    119        /**
    120         * Draws the screen and all the components in it.
    121         */
    122        public void drawScreen(int p_571_1_, int p_571_2_, float p_571_3_)
    123        {
    124            this.modList.drawScreen(p_571_1_, p_571_2_, p_571_3_);
    125            this.drawCenteredString(this.fontRenderer, "Mod List", this.width / 2, 16, 0xFFFFFF);
    126            int offset = this.listWidth  + 20;
    127            if (selectedMod != null) {
    128                GL11.glEnable(GL11.GL_BLEND);
    129                if (!selectedMod.getMetadata().autogenerated) {
    130                    int shifty = 35;
    131                    if (!selectedMod.getMetadata().logoFile.isEmpty())
    132                    {
    133                        int texture = this.mc.renderEngine.getTexture(selectedMod.getMetadata().logoFile);
    134                        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    135                        this.mc.renderEngine.bindTexture(texture);
    136                        Dimension dim = TextureFXManager.instance().getTextureDimensions(texture);
    137                        int top = 32;
    138                        Tessellator tess = Tessellator.instance;
    139                        tess.startDrawingQuads();
    140                        tess.addVertexWithUV(offset,             top + dim.height, zLevel, 0, 1);
    141                        tess.addVertexWithUV(offset + dim.width, top + dim.height, zLevel, 1, 1);
    142                        tess.addVertexWithUV(offset + dim.width, top,              zLevel, 1, 0);
    143                        tess.addVertexWithUV(offset,             top,              zLevel, 0, 0);
    144                        tess.draw();
    145
    146                        shifty += 65;
    147                    }
    148                    this.fontRenderer.drawStringWithShadow(selectedMod.getMetadata().name, offset, shifty, 0xFFFFFF);
    149                    shifty += 12;
    150
    151                    shifty = drawLine(String.format("Version: %s (%s)", selectedMod.getDisplayVersion(), selectedMod.getVersion()), offset, shifty);
    152                    shifty = drawLine(String.format("Mod ID: '%s' Mod State: %s", selectedMod.getModId(), Loader.instance().getModState(selectedMod)), offset, shifty);
    153                    if (!selectedMod.getMetadata().credits.isEmpty()) {
    154                       shifty = drawLine(String.format("Credits: %s", selectedMod.getMetadata().credits), offset, shifty);
    155                    }
    156                    shifty = drawLine(String.format("Authors: %s", selectedMod.getMetadata().getAuthorList()), offset, shifty);
    157                    shifty = drawLine(String.format("URL: %s", selectedMod.getMetadata().url), offset, shifty);
    158                    shifty = drawLine(selectedMod.getMetadata().childMods.isEmpty() ? "No child mods for this mod" : String.format("Child mods: %s", selectedMod.getMetadata().getChildModList()), offset, shifty);
    159                    this.getFontRenderer().drawSplitString(selectedMod.getMetadata().description, offset, shifty + 10, this.width - offset - 20, 0xDDDDDD);
    160                } else {
    161                    offset = ( this.listWidth + this.width ) / 2;
    162                    this.drawCenteredString(this.fontRenderer, selectedMod.getName(), offset, 35, 0xFFFFFF);
    163                    this.drawCenteredString(this.fontRenderer, String.format("Version: %s",selectedMod.getVersion()), offset, 45, 0xFFFFFF);
    164                    this.drawCenteredString(this.fontRenderer, String.format("Mod State: %s",Loader.instance().getModState(selectedMod)), offset, 55, 0xFFFFFF);
    165                    this.drawCenteredString(this.fontRenderer, "No mod information found", offset, 65, 0xDDDDDD);
    166                    this.drawCenteredString(this.fontRenderer, "Ask your mod author to provide a mod mcmod.info file", offset, 75, 0xDDDDDD);
    167                }
    168                GL11.glDisable(GL11.GL_BLEND);
    169            }
    170            super.drawScreen(p_571_1_, p_571_2_, p_571_3_);
    171        }
    172
    173        Minecraft getMinecraftInstance() {
    174            return mc;
    175        }
    176
    177        FontRenderer getFontRenderer() {
    178            return fontRenderer;
    179        }
    180
    181        /**
    182         * @param var1
    183         */
    184        public void selectModIndex(int var1)
    185        {
    186            this.selected=var1;
    187            if (var1>=0 && var1<=mods.size()) {
    188                this.selectedMod=mods.get(selected);
    189            } else {
    190                this.selectedMod=null;
    191            }
    192        }
    193
    194        public boolean modIndexSelected(int var1)
    195        {
    196            return var1==selected;
    197        }
    198    }