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