2012-05-11 05:45:36 +00:00
|
|
|
/*
|
2016-06-23 03:49:47 +00:00
|
|
|
* Minecraft Forge
|
|
|
|
* Copyright (c) 2016.
|
2013-03-09 16:12:12 +00:00
|
|
|
*
|
2016-06-23 03:49:47 +00:00
|
|
|
* 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 Software Foundation version 2.1
|
|
|
|
* of the License.
|
2013-03-09 16:12:12 +00:00
|
|
|
*
|
2016-06-23 03:49:47 +00:00
|
|
|
* 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 A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2013-03-09 16:12:12 +00:00
|
|
|
*
|
2016-06-23 03:49:47 +00:00
|
|
|
* 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 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2012-05-11 05:45:36 +00:00
|
|
|
*/
|
|
|
|
|
2014-09-23 05:01:24 +00:00
|
|
|
package net.minecraftforge.fml.client;
|
2012-05-11 05:45:36 +00:00
|
|
|
|
2012-06-03 01:05:57 +00:00
|
|
|
import java.awt.Dimension;
|
2013-07-10 19:47:13 +00:00
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.io.IOException;
|
2013-07-14 17:31:13 +00:00
|
|
|
import java.io.InputStream;
|
2012-05-15 20:19:46 +00:00
|
|
|
import java.util.ArrayList;
|
2015-03-13 22:38:10 +00:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.List;
|
2015-11-04 22:37:15 +00:00
|
|
|
import java.util.Map.Entry;
|
2012-05-15 20:19:46 +00:00
|
|
|
|
2017-01-11 23:17:56 +00:00
|
|
|
import javax.annotation.Nullable;
|
2013-07-10 19:47:13 +00:00
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
2012-05-11 05:45:36 +00:00
|
|
|
import net.minecraft.client.Minecraft;
|
2012-12-09 04:21:03 +00:00
|
|
|
import net.minecraft.client.gui.FontRenderer;
|
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
import net.minecraft.client.gui.GuiScreen;
|
2015-03-13 22:38:10 +00:00
|
|
|
import net.minecraft.client.gui.GuiTextField;
|
2015-11-04 21:57:47 +00:00
|
|
|
import net.minecraft.client.gui.GuiUtilRenderComponents;
|
2015-06-17 22:16:48 +00:00
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
2012-12-09 04:21:03 +00:00
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
2017-06-05 21:04:10 +00:00
|
|
|
import net.minecraft.client.renderer.BufferBuilder;
|
2013-07-10 19:47:13 +00:00
|
|
|
import net.minecraft.client.renderer.texture.DynamicTexture;
|
|
|
|
import net.minecraft.client.renderer.texture.TextureManager;
|
2015-11-11 16:16:55 +00:00
|
|
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
2013-06-29 17:33:14 +00:00
|
|
|
import net.minecraft.client.resources.I18n;
|
2013-12-03 04:46:42 +00:00
|
|
|
import net.minecraft.client.resources.IResourcePack;
|
2016-03-01 12:58:03 +00:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
2016-03-02 12:32:22 +00:00
|
|
|
import net.minecraft.util.text.TextComponentString;
|
2013-07-10 19:47:13 +00:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2015-04-12 04:51:03 +00:00
|
|
|
import net.minecraft.util.StringUtils;
|
2015-11-04 21:57:47 +00:00
|
|
|
import net.minecraftforge.common.ForgeHooks;
|
2015-11-04 22:37:15 +00:00
|
|
|
import net.minecraftforge.common.ForgeVersion;
|
|
|
|
import net.minecraftforge.common.ForgeVersion.CheckResult;
|
|
|
|
import net.minecraftforge.common.ForgeVersion.Status;
|
2014-09-23 05:01:24 +00:00
|
|
|
import net.minecraftforge.fml.common.FMLLog;
|
|
|
|
import net.minecraftforge.fml.common.Loader;
|
|
|
|
import net.minecraftforge.fml.common.ModContainer;
|
|
|
|
import net.minecraftforge.fml.common.ModContainer.Disableable;
|
2015-11-04 22:37:15 +00:00
|
|
|
import net.minecraftforge.fml.common.versioning.ComparableVersion;
|
2016-03-02 12:32:22 +00:00
|
|
|
import static net.minecraft.util.text.TextFormatting.*;
|
2012-05-11 05:45:36 +00:00
|
|
|
|
2016-05-02 21:13:33 +00:00
|
|
|
import org.lwjgl.input.Mouse;
|
2012-08-17 13:24:38 +00:00
|
|
|
|
2012-09-15 19:58:20 +00:00
|
|
|
import com.google.common.base.Strings;
|
2018-02-11 19:48:02 +00:00
|
|
|
import org.lwjgl.opengl.GL11;
|
2012-09-15 19:58:20 +00:00
|
|
|
|
2012-05-11 05:45:36 +00:00
|
|
|
/**
|
|
|
|
* @author cpw
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class GuiModList extends GuiScreen
|
|
|
|
{
|
2015-04-14 04:52:53 +00:00
|
|
|
private enum SortType implements Comparator<ModContainer>
|
2015-03-13 22:38:10 +00:00
|
|
|
{
|
2015-04-14 04:52:53 +00:00
|
|
|
NORMAL(24),
|
|
|
|
A_TO_Z(25){ @Override protected int compare(String name1, String name2){ return name1.compareTo(name2); }},
|
|
|
|
Z_TO_A(26){ @Override protected int compare(String name1, String name2){ return name2.compareTo(name1); }};
|
2015-03-13 22:38:10 +00:00
|
|
|
|
|
|
|
private int buttonID;
|
|
|
|
|
|
|
|
private SortType(int buttonID)
|
|
|
|
{
|
|
|
|
this.buttonID = buttonID;
|
|
|
|
}
|
|
|
|
|
2017-01-11 23:17:56 +00:00
|
|
|
@Nullable
|
2015-03-13 22:38:10 +00:00
|
|
|
public static SortType getTypeForButton(GuiButton button)
|
|
|
|
{
|
2015-04-14 04:52:53 +00:00
|
|
|
for (SortType t : values())
|
|
|
|
{
|
|
|
|
if (t.buttonID == button.id)
|
|
|
|
{
|
2015-03-13 22:38:10 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2015-04-14 04:52:53 +00:00
|
|
|
|
|
|
|
protected int compare(String name1, String name2){ return 0; }
|
|
|
|
|
2015-04-12 04:51:03 +00:00
|
|
|
@Override
|
|
|
|
public int compare(ModContainer o1, ModContainer o2)
|
|
|
|
{
|
|
|
|
String name1 = StringUtils.stripControlCodes(o1.getName()).toLowerCase();
|
|
|
|
String name2 = StringUtils.stripControlCodes(o2.getName()).toLowerCase();
|
2015-04-14 04:52:53 +00:00
|
|
|
return compare(name1, name2);
|
2015-04-12 04:51:03 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-14 04:52:53 +00:00
|
|
|
|
2012-05-11 05:45:36 +00:00
|
|
|
private GuiScreen mainMenu;
|
|
|
|
private GuiSlotModList modList;
|
2015-11-04 21:57:47 +00:00
|
|
|
private GuiScrollingList modInfo;
|
2012-05-14 05:38:53 +00:00
|
|
|
private int selected = -1;
|
|
|
|
private ModContainer selectedMod;
|
2012-05-15 19:52:19 +00:00
|
|
|
private int listWidth;
|
2012-05-15 20:19:46 +00:00
|
|
|
private ArrayList<ModContainer> mods;
|
2013-12-16 16:47:48 +00:00
|
|
|
private GuiButton configModButton;
|
|
|
|
private GuiButton disableModButton;
|
2015-04-14 04:52:53 +00:00
|
|
|
|
2015-03-13 22:38:10 +00:00
|
|
|
private int buttonMargin = 1;
|
|
|
|
private int numButtons = SortType.values().length;
|
|
|
|
|
|
|
|
private String lastFilterText = "";
|
|
|
|
|
|
|
|
private GuiTextField search;
|
|
|
|
private boolean sorted = false;
|
|
|
|
private SortType sortType = SortType.NORMAL;
|
2012-05-11 05:45:36 +00:00
|
|
|
|
|
|
|
/**
|
2012-09-16 01:04:56 +00:00
|
|
|
* @param mainMenu
|
2012-05-11 05:45:36 +00:00
|
|
|
*/
|
|
|
|
public GuiModList(GuiScreen mainMenu)
|
|
|
|
{
|
2015-04-14 04:52:53 +00:00
|
|
|
this.mainMenu = mainMenu;
|
|
|
|
this.mods = new ArrayList<ModContainer>();
|
2012-06-01 18:55:49 +00:00
|
|
|
FMLClientHandler.instance().addSpecialModEntries(mods);
|
2015-03-13 22:38:10 +00:00
|
|
|
// Add child mods to their parent's list
|
2015-04-14 04:52:53 +00:00
|
|
|
for (ModContainer mod : Loader.instance().getModList())
|
|
|
|
{
|
|
|
|
if (mod.getMetadata() != null && mod.getMetadata().parentMod == null && !Strings.isNullOrEmpty(mod.getMetadata().parent))
|
|
|
|
{
|
2012-09-15 19:58:20 +00:00
|
|
|
String parentMod = mod.getMetadata().parent;
|
|
|
|
ModContainer parentContainer = Loader.instance().getIndexedModList().get(parentMod);
|
2012-11-18 04:51:14 +00:00
|
|
|
if (parentContainer != null)
|
2012-09-15 19:58:20 +00:00
|
|
|
{
|
|
|
|
mod.getMetadata().parentMod = parentContainer;
|
2012-09-25 23:00:36 +00:00
|
|
|
parentContainer.getMetadata().childMods.add(mod);
|
2012-09-15 19:58:20 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-05-25 19:25:35 +00:00
|
|
|
}
|
2015-04-14 04:52:53 +00:00
|
|
|
else if (mod.getMetadata() != null && mod.getMetadata().parentMod != null)
|
2012-11-18 04:51:14 +00:00
|
|
|
{
|
2015-03-13 22:38:10 +00:00
|
|
|
continue;
|
2012-11-18 04:51:14 +00:00
|
|
|
}
|
2012-05-25 19:25:35 +00:00
|
|
|
mods.add(mod);
|
|
|
|
}
|
2012-05-11 05:45:36 +00:00
|
|
|
}
|
2012-07-31 02:31:07 +00:00
|
|
|
|
|
|
|
@Override
|
2014-03-19 07:15:53 +00:00
|
|
|
public void initGui()
|
2012-05-11 05:45:36 +00:00
|
|
|
{
|
2016-03-23 13:48:29 +00:00
|
|
|
int slotHeight = 35;
|
2015-04-14 04:52:53 +00:00
|
|
|
for (ModContainer mod : mods)
|
|
|
|
{
|
|
|
|
listWidth = Math.max(listWidth,getFontRenderer().getStringWidth(mod.getName()) + 10);
|
2016-03-23 13:48:29 +00:00
|
|
|
listWidth = Math.max(listWidth,getFontRenderer().getStringWidth(mod.getVersion()) + 5 + slotHeight);
|
2012-05-15 19:52:19 +00:00
|
|
|
}
|
2015-04-14 04:52:53 +00:00
|
|
|
listWidth = Math.min(listWidth, 150);
|
2016-03-23 13:48:29 +00:00
|
|
|
this.modList = new GuiSlotModList(this, mods, listWidth, slotHeight);
|
2015-04-14 04:52:53 +00:00
|
|
|
|
2015-03-13 22:38:10 +00:00
|
|
|
this.buttonList.add(new GuiButton(6, ((modList.right + this.width) / 2) - 100, this.height - 38, I18n.format("gui.done")));
|
|
|
|
configModButton = new GuiButton(20, 10, this.height - 49, this.listWidth, 20, "Config");
|
|
|
|
disableModButton = new GuiButton(21, 10, this.height - 27, this.listWidth, 20, "Disable");
|
|
|
|
this.buttonList.add(configModButton);
|
|
|
|
this.buttonList.add(disableModButton);
|
2015-04-14 04:52:53 +00:00
|
|
|
|
2015-03-13 22:38:10 +00:00
|
|
|
search = new GuiTextField(0, getFontRenderer(), 12, modList.bottom + 17, modList.listWidth - 4, 14);
|
|
|
|
search.setFocused(true);
|
|
|
|
search.setCanLoseFocus(true);
|
|
|
|
|
|
|
|
int width = (modList.listWidth / numButtons);
|
|
|
|
int x = 10, y = 10;
|
|
|
|
GuiButton normalSort = new GuiButton(SortType.NORMAL.buttonID, x, y, width - buttonMargin, 20, I18n.format("fml.menu.mods.normal"));
|
|
|
|
normalSort.enabled = false;
|
|
|
|
buttonList.add(normalSort);
|
|
|
|
x += width + buttonMargin;
|
|
|
|
buttonList.add(new GuiButton(SortType.A_TO_Z.buttonID, x, y, width - buttonMargin, 20, "A-Z"));
|
|
|
|
x += width + buttonMargin;
|
|
|
|
buttonList.add(new GuiButton(SortType.Z_TO_A.buttonID, x, y, width - buttonMargin, 20, "Z-A"));
|
2015-11-04 21:57:47 +00:00
|
|
|
|
|
|
|
updateCache();
|
2015-03-13 22:38:10 +00:00
|
|
|
}
|
2015-04-14 04:52:53 +00:00
|
|
|
|
2015-03-13 22:38:10 +00:00
|
|
|
@Override
|
|
|
|
protected void mouseClicked(int x, int y, int button) throws IOException
|
|
|
|
{
|
|
|
|
super.mouseClicked(x, y, button);
|
|
|
|
search.mouseClicked(x, y, button);
|
2017-06-11 00:59:01 +00:00
|
|
|
if (button == 1 && x >= search.x && x < search.x + search.width && y >= search.y && y < search.y + search.height) {
|
2015-03-13 22:38:10 +00:00
|
|
|
search.setText("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void keyTyped(char c, int keyCode) throws IOException
|
|
|
|
{
|
|
|
|
super.keyTyped(c, keyCode);
|
|
|
|
search.textboxKeyTyped(c, keyCode);
|
|
|
|
}
|
2015-04-14 04:52:53 +00:00
|
|
|
|
2015-03-13 22:38:10 +00:00
|
|
|
@Override
|
|
|
|
public void updateScreen()
|
|
|
|
{
|
|
|
|
super.updateScreen();
|
|
|
|
search.updateCursorCounter();
|
|
|
|
|
|
|
|
if (!search.getText().equals(lastFilterText))
|
|
|
|
{
|
|
|
|
reloadMods();
|
|
|
|
sorted = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sorted)
|
|
|
|
{
|
2015-04-12 04:51:03 +00:00
|
|
|
reloadMods();
|
2015-04-14 04:52:53 +00:00
|
|
|
Collections.sort(mods, sortType);
|
2015-03-13 22:38:10 +00:00
|
|
|
selected = modList.selectedIndex = mods.indexOf(selectedMod);
|
|
|
|
sorted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void reloadMods()
|
|
|
|
{
|
|
|
|
ArrayList<ModContainer> mods = modList.getMods();
|
|
|
|
mods.clear();
|
|
|
|
for (ModContainer m : Loader.instance().getActiveModList())
|
|
|
|
{
|
|
|
|
// If it passes the filter, and is not a child mod
|
|
|
|
if (m.getName().toLowerCase().contains(search.getText().toLowerCase()) && m.getMetadata().parentMod == null)
|
|
|
|
{
|
|
|
|
mods.add(m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.mods = mods;
|
|
|
|
lastFilterText = search.getText();
|
2012-05-11 05:45:36 +00:00
|
|
|
}
|
|
|
|
|
2012-07-31 02:31:07 +00:00
|
|
|
@Override
|
2015-11-04 21:57:47 +00:00
|
|
|
protected void actionPerformed(GuiButton button) throws IOException
|
|
|
|
{
|
2014-03-19 07:15:53 +00:00
|
|
|
if (button.enabled)
|
2012-05-11 05:45:36 +00:00
|
|
|
{
|
2015-03-13 22:38:10 +00:00
|
|
|
SortType type = SortType.getTypeForButton(button);
|
|
|
|
|
|
|
|
if (type != null)
|
2012-05-11 05:45:36 +00:00
|
|
|
{
|
2016-03-23 14:34:48 +00:00
|
|
|
for (GuiButton b : buttonList)
|
2015-03-13 22:38:10 +00:00
|
|
|
{
|
|
|
|
if (SortType.getTypeForButton(b) != null)
|
|
|
|
{
|
|
|
|
b.enabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
button.enabled = false;
|
|
|
|
sorted = false;
|
|
|
|
sortType = type;
|
|
|
|
this.mods = modList.getMods();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (button.id)
|
|
|
|
{
|
2015-04-14 04:52:53 +00:00
|
|
|
case 6:
|
2015-11-04 21:57:47 +00:00
|
|
|
{
|
2015-04-14 04:52:53 +00:00
|
|
|
this.mc.displayGuiScreen(this.mainMenu);
|
|
|
|
return;
|
2015-11-04 21:57:47 +00:00
|
|
|
}
|
2015-04-14 04:52:53 +00:00
|
|
|
case 20:
|
2015-11-04 21:57:47 +00:00
|
|
|
{
|
2015-04-14 04:52:53 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
IModGuiFactory guiFactory = FMLClientHandler.instance().getGuiFactoryFor(selectedMod);
|
2017-06-15 18:26:14 +00:00
|
|
|
GuiScreen newScreen = guiFactory.createConfigGui(this);
|
2015-04-14 04:52:53 +00:00
|
|
|
this.mc.displayGuiScreen(newScreen);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2017-06-23 05:33:11 +00:00
|
|
|
FMLLog.log.error("There was a critical issue trying to build the config GUI for {}", selectedMod.getModId(), e);
|
2015-04-14 04:52:53 +00:00
|
|
|
}
|
|
|
|
return;
|
2014-01-02 16:51:16 +00:00
|
|
|
}
|
2015-11-04 21:57:47 +00:00
|
|
|
}
|
2012-05-11 05:45:36 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-19 07:15:53 +00:00
|
|
|
super.actionPerformed(button);
|
2012-05-11 05:45:36 +00:00
|
|
|
}
|
|
|
|
|
2012-05-30 13:25:04 +00:00
|
|
|
public int drawLine(String line, int offset, int shifty)
|
|
|
|
{
|
2017-06-11 00:59:01 +00:00
|
|
|
this.fontRenderer.drawString(line, offset, shifty, 0xd7edea);
|
2012-05-30 13:25:04 +00:00
|
|
|
return shifty + 10;
|
|
|
|
}
|
2012-07-31 02:31:07 +00:00
|
|
|
|
|
|
|
@Override
|
2015-11-04 21:57:47 +00:00
|
|
|
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
2012-05-11 05:45:36 +00:00
|
|
|
{
|
2015-11-04 21:57:47 +00:00
|
|
|
this.modList.drawScreen(mouseX, mouseY, partialTicks);
|
|
|
|
if (this.modInfo != null)
|
|
|
|
this.modInfo.drawScreen(mouseX, mouseY, partialTicks);
|
2012-07-31 02:31:07 +00:00
|
|
|
|
2015-11-04 21:57:47 +00:00
|
|
|
int left = ((this.width - this.listWidth - 38) / 2) + this.listWidth + 30;
|
2017-06-11 00:59:01 +00:00
|
|
|
this.drawCenteredString(this.fontRenderer, "Mod List", left, 16, 0xFFFFFF);
|
2015-11-04 21:57:47 +00:00
|
|
|
super.drawScreen(mouseX, mouseY, partialTicks);
|
2015-03-13 22:38:10 +00:00
|
|
|
|
|
|
|
String text = I18n.format("fml.menu.mods.search");
|
|
|
|
int x = ((10 + modList.right) / 2) - (getFontRenderer().getStringWidth(text) / 2);
|
|
|
|
getFontRenderer().drawString(text, x, modList.bottom + 5, 0xFFFFFF);
|
|
|
|
search.drawTextBox();
|
2012-05-11 05:45:36 +00:00
|
|
|
}
|
|
|
|
|
2016-05-02 21:13:33 +00:00
|
|
|
@Override
|
|
|
|
public void handleMouseInput() throws IOException
|
|
|
|
{
|
|
|
|
int mouseX = Mouse.getEventX() * this.width / this.mc.displayWidth;
|
|
|
|
int mouseY = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
|
|
|
|
|
|
|
|
super.handleMouseInput();
|
|
|
|
if (this.modInfo != null)
|
|
|
|
this.modInfo.handleMouseInput(mouseX, mouseY);
|
|
|
|
this.modList.handleMouseInput(mouseX, mouseY);
|
|
|
|
}
|
|
|
|
|
2015-04-14 04:52:53 +00:00
|
|
|
Minecraft getMinecraftInstance()
|
|
|
|
{
|
2014-03-19 07:15:53 +00:00
|
|
|
return mc;
|
2012-05-11 05:45:36 +00:00
|
|
|
}
|
2012-07-31 02:31:07 +00:00
|
|
|
|
2015-04-14 04:52:53 +00:00
|
|
|
FontRenderer getFontRenderer()
|
|
|
|
{
|
2017-06-11 00:59:01 +00:00
|
|
|
return fontRenderer;
|
2012-05-11 05:45:36 +00:00
|
|
|
}
|
2012-05-14 05:38:53 +00:00
|
|
|
|
2015-04-14 04:52:53 +00:00
|
|
|
public void selectModIndex(int index)
|
2012-05-14 05:38:53 +00:00
|
|
|
{
|
2015-11-04 21:57:47 +00:00
|
|
|
if (index == this.selected)
|
|
|
|
return;
|
2015-04-14 04:52:53 +00:00
|
|
|
this.selected = index;
|
|
|
|
this.selectedMod = (index >= 0 && index <= mods.size()) ? mods.get(selected) : null;
|
2015-11-04 21:57:47 +00:00
|
|
|
|
|
|
|
updateCache();
|
2012-05-14 05:38:53 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 04:52:53 +00:00
|
|
|
public boolean modIndexSelected(int index)
|
2012-05-14 05:38:53 +00:00
|
|
|
{
|
2015-04-14 04:52:53 +00:00
|
|
|
return index == selected;
|
2012-05-14 05:38:53 +00:00
|
|
|
}
|
2015-11-04 21:57:47 +00:00
|
|
|
|
|
|
|
private void updateCache()
|
|
|
|
{
|
|
|
|
configModButton.visible = false;
|
|
|
|
disableModButton.visible = false;
|
|
|
|
modInfo = null;
|
|
|
|
|
|
|
|
if (selectedMod == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ResourceLocation logoPath = null;
|
|
|
|
Dimension logoDims = new Dimension(0, 0);
|
|
|
|
List<String> lines = new ArrayList<String>();
|
2015-11-04 22:37:15 +00:00
|
|
|
CheckResult vercheck = ForgeVersion.getResult(selectedMod);
|
2015-11-04 21:57:47 +00:00
|
|
|
|
|
|
|
String logoFile = selectedMod.getMetadata().logoFile;
|
|
|
|
if (!logoFile.isEmpty())
|
|
|
|
{
|
|
|
|
TextureManager tm = mc.getTextureManager();
|
|
|
|
IResourcePack pack = FMLClientHandler.instance().getResourcePackFor(selectedMod.getModId());
|
|
|
|
try
|
|
|
|
{
|
|
|
|
BufferedImage logo = null;
|
|
|
|
if (pack != null)
|
|
|
|
{
|
|
|
|
logo = pack.getPackImage();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
InputStream logoResource = getClass().getResourceAsStream(logoFile);
|
|
|
|
if (logoResource != null)
|
|
|
|
logo = ImageIO.read(logoResource);
|
|
|
|
}
|
|
|
|
if (logo != null)
|
|
|
|
{
|
|
|
|
logoPath = tm.getDynamicTextureLocation("modlogo", new DynamicTexture(logo));
|
|
|
|
logoDims = new Dimension(logo.getWidth(), logo.getHeight());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (IOException e) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!selectedMod.getMetadata().autogenerated)
|
|
|
|
{
|
|
|
|
disableModButton.visible = true;
|
|
|
|
disableModButton.enabled = true;
|
|
|
|
disableModButton.packedFGColour = 0;
|
|
|
|
Disableable disableable = selectedMod.canBeDisabled();
|
|
|
|
if (disableable == Disableable.RESTART)
|
|
|
|
{
|
|
|
|
disableModButton.packedFGColour = 0xFF3377;
|
|
|
|
}
|
|
|
|
else if (disableable != Disableable.YES)
|
|
|
|
{
|
|
|
|
disableModButton.enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
IModGuiFactory guiFactory = FMLClientHandler.instance().getGuiFactoryFor(selectedMod);
|
|
|
|
configModButton.visible = true;
|
2017-04-01 21:24:50 +00:00
|
|
|
configModButton.enabled = false;
|
|
|
|
if (guiFactory != null)
|
|
|
|
{
|
2017-06-15 18:26:14 +00:00
|
|
|
configModButton.enabled = guiFactory.hasConfigGui();
|
2017-04-01 21:24:50 +00:00
|
|
|
}
|
2015-11-04 21:57:47 +00:00
|
|
|
lines.add(selectedMod.getMetadata().name);
|
|
|
|
lines.add(String.format("Version: %s (%s)", selectedMod.getDisplayVersion(), selectedMod.getVersion()));
|
|
|
|
lines.add(String.format("Mod ID: '%s' Mod State: %s", selectedMod.getModId(), Loader.instance().getModState(selectedMod)));
|
|
|
|
|
|
|
|
if (!selectedMod.getMetadata().credits.isEmpty())
|
|
|
|
{
|
|
|
|
lines.add("Credits: " + selectedMod.getMetadata().credits);
|
|
|
|
}
|
|
|
|
|
|
|
|
lines.add("Authors: " + selectedMod.getMetadata().getAuthorList());
|
|
|
|
lines.add("URL: " + selectedMod.getMetadata().url);
|
|
|
|
|
|
|
|
if (selectedMod.getMetadata().childMods.isEmpty())
|
|
|
|
lines.add("No child mods for this mod");
|
|
|
|
else
|
|
|
|
lines.add("Child mods: " + selectedMod.getMetadata().getChildModList());
|
|
|
|
|
2015-11-04 22:37:15 +00:00
|
|
|
if (vercheck.status == Status.OUTDATED || vercheck.status == Status.BETA_OUTDATED)
|
2016-03-23 14:34:48 +00:00
|
|
|
lines.add("Update Available: " + (vercheck.url == null ? "" : vercheck.url));
|
2015-11-04 21:57:47 +00:00
|
|
|
|
|
|
|
lines.add(null);
|
|
|
|
lines.add(selectedMod.getMetadata().description);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lines.add(WHITE + selectedMod.getName());
|
|
|
|
lines.add(WHITE + "Version: " + selectedMod.getVersion());
|
|
|
|
lines.add(WHITE + "Mod State: " + Loader.instance().getModState(selectedMod));
|
2015-11-04 22:37:15 +00:00
|
|
|
if (vercheck.status == Status.OUTDATED || vercheck.status == Status.BETA_OUTDATED)
|
2015-11-08 20:52:41 +00:00
|
|
|
lines.add("Update Available: " + (vercheck.url == null ? "" : vercheck.url));
|
2015-11-04 21:57:47 +00:00
|
|
|
|
|
|
|
lines.add(null);
|
|
|
|
lines.add(RED + "No mod information found");
|
|
|
|
lines.add(RED + "Ask your mod author to provide a mod mcmod.info file");
|
|
|
|
}
|
|
|
|
|
2015-11-04 22:37:15 +00:00
|
|
|
if ((vercheck.status == Status.OUTDATED || vercheck.status == Status.BETA_OUTDATED) && vercheck.changes.size() > 0)
|
2015-11-04 21:57:47 +00:00
|
|
|
{
|
|
|
|
lines.add(null);
|
|
|
|
lines.add("Changes:");
|
|
|
|
for (Entry<ComparableVersion, String> entry : vercheck.changes.entrySet())
|
|
|
|
{
|
|
|
|
lines.add(" " + entry.getKey() + ":");
|
|
|
|
lines.add(entry.getValue());
|
|
|
|
lines.add(null);
|
|
|
|
}
|
2015-11-04 22:37:15 +00:00
|
|
|
}
|
2015-11-04 21:57:47 +00:00
|
|
|
|
|
|
|
modInfo = new Info(this.width - this.listWidth - 30, lines, logoPath, logoDims);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class Info extends GuiScrollingList
|
|
|
|
{
|
2017-01-11 23:17:56 +00:00
|
|
|
@Nullable
|
2015-11-04 21:57:47 +00:00
|
|
|
private ResourceLocation logoPath;
|
|
|
|
private Dimension logoDims;
|
2016-03-01 12:58:03 +00:00
|
|
|
private List<ITextComponent> lines = null;
|
2015-11-04 21:57:47 +00:00
|
|
|
|
2017-01-11 23:17:56 +00:00
|
|
|
public Info(int width, List<String> lines, @Nullable ResourceLocation logoPath, Dimension logoDims)
|
2015-11-04 21:57:47 +00:00
|
|
|
{
|
|
|
|
super(GuiModList.this.getMinecraftInstance(),
|
|
|
|
width,
|
|
|
|
GuiModList.this.height,
|
|
|
|
32, GuiModList.this.height - 88 + 4,
|
|
|
|
GuiModList.this.listWidth + 20, 60,
|
|
|
|
GuiModList.this.width,
|
|
|
|
GuiModList.this.height);
|
|
|
|
this.lines = resizeContent(lines);
|
|
|
|
this.logoPath = logoPath;
|
|
|
|
this.logoDims = logoDims;
|
|
|
|
|
|
|
|
this.setHeaderInfo(true, getHeaderHeight());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override protected int getSize() { return 0; }
|
|
|
|
@Override protected void elementClicked(int index, boolean doubleClick) { }
|
|
|
|
@Override protected boolean isSelected(int index) { return false; }
|
|
|
|
@Override protected void drawBackground() {}
|
|
|
|
@Override protected void drawSlot(int slotIdx, int entryRight, int slotTop, int slotBuffer, Tessellator tess) { }
|
|
|
|
|
2016-03-01 12:58:03 +00:00
|
|
|
private List<ITextComponent> resizeContent(List<String> lines)
|
2015-11-04 21:57:47 +00:00
|
|
|
{
|
2016-03-01 12:58:03 +00:00
|
|
|
List<ITextComponent> ret = new ArrayList<ITextComponent>();
|
2015-11-04 21:57:47 +00:00
|
|
|
for (String line : lines)
|
|
|
|
{
|
|
|
|
if (line == null)
|
|
|
|
{
|
|
|
|
ret.add(null);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-03-01 12:58:03 +00:00
|
|
|
ITextComponent chat = ForgeHooks.newChatWithLinks(line, false);
|
2017-07-09 05:55:45 +00:00
|
|
|
int maxTextLength = this.listWidth - 8;
|
|
|
|
if (maxTextLength >= 0)
|
|
|
|
{
|
|
|
|
ret.addAll(GuiUtilRenderComponents.splitText(chat, maxTextLength, GuiModList.this.fontRenderer, false, true));
|
|
|
|
}
|
2015-11-04 21:57:47 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getHeaderHeight()
|
|
|
|
{
|
|
|
|
int height = 0;
|
|
|
|
if (logoPath != null)
|
|
|
|
{
|
|
|
|
double scaleX = logoDims.width / 200.0;
|
|
|
|
double scaleY = logoDims.height / 65.0;
|
|
|
|
double scale = 1.0;
|
|
|
|
if (scaleX > 1 || scaleY > 1)
|
|
|
|
{
|
|
|
|
scale = 1.0 / Math.max(scaleX, scaleY);
|
|
|
|
}
|
|
|
|
logoDims.width *= scale;
|
|
|
|
logoDims.height *= scale;
|
|
|
|
|
|
|
|
height += logoDims.height;
|
|
|
|
height += 10;
|
|
|
|
}
|
|
|
|
height += (lines.size() * 10);
|
|
|
|
if (height < this.bottom - this.top - 8) height = this.bottom - this.top - 8;
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-18 01:24:17 +00:00
|
|
|
@Override
|
2015-11-04 21:57:47 +00:00
|
|
|
protected void drawHeader(int entryRight, int relativeY, Tessellator tess)
|
|
|
|
{
|
|
|
|
int top = relativeY;
|
|
|
|
|
|
|
|
if (logoPath != null)
|
|
|
|
{
|
|
|
|
GlStateManager.enableBlend();
|
|
|
|
GuiModList.this.mc.renderEngine.bindTexture(logoPath);
|
2017-06-05 21:04:10 +00:00
|
|
|
BufferBuilder wr = tess.getBuffer();
|
2015-11-04 21:57:47 +00:00
|
|
|
int offset = (this.left + this.listWidth/2) - (logoDims.width / 2);
|
2018-02-11 19:48:02 +00:00
|
|
|
wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
|
2016-03-13 01:40:03 +00:00
|
|
|
wr.pos(offset, top + logoDims.height, zLevel).tex(0, 1).endVertex();
|
|
|
|
wr.pos(offset + logoDims.width, top + logoDims.height, zLevel).tex(1, 1).endVertex();
|
|
|
|
wr.pos(offset + logoDims.width, top, zLevel).tex(1, 0).endVertex();
|
|
|
|
wr.pos(offset, top, zLevel).tex(0, 0).endVertex();
|
2015-11-04 21:57:47 +00:00
|
|
|
tess.draw();
|
|
|
|
GlStateManager.disableBlend();
|
|
|
|
top += logoDims.height + 10;
|
|
|
|
}
|
|
|
|
|
2016-03-01 12:58:03 +00:00
|
|
|
for (ITextComponent line : lines)
|
2015-11-04 21:57:47 +00:00
|
|
|
{
|
|
|
|
if (line != null)
|
|
|
|
{
|
|
|
|
GlStateManager.enableBlend();
|
2017-06-11 00:59:01 +00:00
|
|
|
GuiModList.this.fontRenderer.drawStringWithShadow(line.getFormattedText(), this.left + 4, top, 0xFFFFFF);
|
2015-11-04 21:57:47 +00:00
|
|
|
GlStateManager.disableAlpha();
|
|
|
|
GlStateManager.disableBlend();
|
|
|
|
}
|
|
|
|
top += 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void clickHeader(int x, int y)
|
|
|
|
{
|
|
|
|
int offset = y;
|
|
|
|
if (logoPath != null) {
|
|
|
|
offset -= logoDims.height + 10;
|
|
|
|
}
|
|
|
|
if (offset <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int lineIdx = offset / 10;
|
|
|
|
if (lineIdx >= lines.size())
|
|
|
|
return;
|
|
|
|
|
2016-03-01 12:58:03 +00:00
|
|
|
ITextComponent line = lines.get(lineIdx);
|
2015-11-04 21:57:47 +00:00
|
|
|
if (line != null)
|
|
|
|
{
|
|
|
|
int k = -4;
|
2016-03-23 14:34:48 +00:00
|
|
|
for (ITextComponent part : line) {
|
2016-03-01 12:58:03 +00:00
|
|
|
if (!(part instanceof TextComponentString))
|
2015-11-04 21:57:47 +00:00
|
|
|
continue;
|
2017-06-11 00:59:01 +00:00
|
|
|
k += GuiModList.this.fontRenderer.getStringWidth(((TextComponentString)part).getText());
|
2015-11-04 21:57:47 +00:00
|
|
|
if (k >= x)
|
|
|
|
{
|
2015-11-24 04:18:52 +00:00
|
|
|
GuiModList.this.handleComponentClick(part);
|
2015-11-04 21:57:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-11 05:45:36 +00:00
|
|
|
}
|