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