    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.src.FontRenderer;
    022    import net.minecraft.src.GuiButton;
    023    import net.minecraft.src.GuiScreen;
    024    import net.minecraft.src.GuiSmallButton;
    025    import net.minecraft.src.StringTranslate;
    026    import net.minecraft.src.Tessellator;
    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 && !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                mods.add(mod);
    068            }
    069        }
    070
    071        @Override
    072
    073        /**
    074         * Adds the buttons (and other controls) to the screen in question.
    075         */
    076        public void initGui()
    077        {
    078            for (ModContainer mod : mods) {
    079                listWidth=Math.max(listWidth,getFontRenderer().getStringWidth(mod.getName()) + 10);
    080                listWidth=Math.max(listWidth,getFontRenderer().getStringWidth(mod.getVersion()) + 10);
    081            }
    082            listWidth=Math.min(listWidth, 150);
    083            StringTranslate translations = StringTranslate.getInstance();
    084            this.controlList.add(new GuiSmallButton(6, this.width / 2 - 75, this.height - 38, translations.translateKey("gui.done")));
    085            this.modList=new GuiSlotModList(this, mods, listWidth);
    086            this.modList.registerScrollButtons(this.controlList, 7, 8);
    087        }
    088
    089        @Override
    090
    091        /**
    092         * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    093         */
    094        protected void actionPerformed(GuiButton button) {
    095            if (button.enabled)
    096            {
    097                switch (button.id)
    098                {
    099                    case 6:
    100                        this.mc.displayGuiScreen(this.mainMenu);
    101                        return;
    102                }
    103            }
    104            super.actionPerformed(button);
    105        }
    106
    107        public int drawLine(String line, int offset, int shifty)
    108        {
    109            this.fontRenderer.drawString(line, offset, shifty, 0xd7edea);
    110            return shifty + 10;
    111        }
    112
    113        @Override
    114
    115        /**
    116         * Draws the screen and all the components in it.
    117         */
    118        public void drawScreen(int p_571_1_, int p_571_2_, float p_571_3_)
    119        {
    120            this.modList.drawScreen(p_571_1_, p_571_2_, p_571_3_);
    121            this.drawCenteredString(this.fontRenderer, "Mod List", this.width / 2, 16, 0xFFFFFF);
    122            int offset = this.listWidth  + 20;
    123            if (selectedMod != null) {
    124                GL11.glEnable(GL11.GL_BLEND);
    125                if (!selectedMod.getMetadata().autogenerated) {
    126                    int shifty = 35;
    127                    if (!selectedMod.getMetadata().logoFile.isEmpty())
    128                    {
    129                        int texture = this.mc.renderEngine.getTexture(selectedMod.getMetadata().logoFile);
    130                        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    131                        this.mc.renderEngine.bindTexture(texture);
    132                        Dimension dim = TextureFXManager.instance().getTextureDimensions(texture);
    133                        int top = 32;
    134                        Tessellator tess = Tessellator.instance;
    135                        tess.startDrawingQuads();
    136                        tess.addVertexWithUV(offset,             top + dim.height, zLevel, 0, 1);
    137                        tess.addVertexWithUV(offset + dim.width, top + dim.height, zLevel, 1, 1);
    138                        tess.addVertexWithUV(offset + dim.width, top,              zLevel, 1, 0);
    139                        tess.addVertexWithUV(offset,             top,              zLevel, 0, 0);
    140                        tess.draw();
    141
    142                        shifty += 65;
    143                    }
    144                    this.fontRenderer.drawStringWithShadow(selectedMod.getMetadata().name, offset, shifty, 0xFFFFFF);
    145                    shifty += 12;
    146
    147                    shifty = drawLine(String.format("Version: %s (%s)", selectedMod.getDisplayVersion(), selectedMod.getVersion()), offset, shifty);
    148                    shifty = drawLine(String.format("Mod State: %s", Loader.instance().getModState(selectedMod)), offset, shifty);
    149                    if (!selectedMod.getMetadata().credits.isEmpty()) {
    150                       shifty = drawLine(String.format("Credits: %s", selectedMod.getMetadata().credits), offset, shifty);
    151                    }
    152                    shifty = drawLine(String.format("Authors: %s", selectedMod.getMetadata().getAuthorList()), offset, shifty);
    153                    shifty = drawLine(String.format("URL: %s", selectedMod.getMetadata().url), offset, shifty);
    154                    shifty = drawLine(selectedMod.getMetadata().childMods.isEmpty() ? "No child mods for this mod" : String.format("Child mods: %s", selectedMod.getMetadata().getChildModList()), offset, shifty);
    155                    this.getFontRenderer().drawSplitString(selectedMod.getMetadata().description, offset, shifty + 10, this.width - offset - 20, 0xDDDDDD);
    156                } else {
    157                    offset = ( this.listWidth + this.width ) / 2;
    158                    this.drawCenteredString(this.fontRenderer, selectedMod.getName(), offset, 35, 0xFFFFFF);
    159                    this.drawCenteredString(this.fontRenderer, String.format("Version: %s",selectedMod.getVersion()), offset, 45, 0xFFFFFF);
    160                    this.drawCenteredString(this.fontRenderer, String.format("Mod State: %s",Loader.instance().getModState(selectedMod)), offset, 55, 0xFFFFFF);
    161                    this.drawCenteredString(this.fontRenderer, "No mod information found", offset, 65, 0xDDDDDD);
    162                    this.drawCenteredString(this.fontRenderer, "Ask your mod author to provide a mod mcmod.info file", offset, 75, 0xDDDDDD);
    163                }
    164                GL11.glDisable(GL11.GL_BLEND);
    165            }
    166            super.drawScreen(p_571_1_, p_571_2_, p_571_3_);
    167        }
    168
    169        Minecraft getMinecraftInstance() {
    170            return mc;
    171        }
    172
    173        FontRenderer getFontRenderer() {
    174            return fontRenderer;
    175        }
    176
    177        /**
    178         * @param var1
    179         */
    180        public void selectModIndex(int var1)
    181        {
    182            this.selected=var1;
    183            if (var1>=0 && var1<=mods.size()) {
    184                this.selectedMod=mods.get(selected);
    185            } else {
    186                this.selectedMod=null;
    187            }
    188        }
    189
    190        public boolean modIndexSelected(int var1)
    191        {
    192            return var1==selected;
    193        }
    194    }