2012-05-11 05:45:36 +00:00
|
|
|
/*
|
2016-06-23 03:49:47 +00:00
|
|
|
* Minecraft Forge
|
2018-07-01 21:17:28 +00:00
|
|
|
* Copyright (c) 2016-2018.
|
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
|
|
|
*/
|
|
|
|
|
2018-06-11 13:56:44 +00:00
|
|
|
package net.minecraftforge.fml.client.gui;
|
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;
|
2018-09-05 00:23:45 +00:00
|
|
|
import net.minecraft.client.gui.Gui;
|
2012-12-09 04:21:03 +00:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
2018-09-05 00:23:45 +00:00
|
|
|
import net.minecraft.client.gui.GuiListExtended;
|
2012-12-09 04:21:03 +00:00
|
|
|
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;
|
2013-07-10 19:47:13 +00:00
|
|
|
import net.minecraft.client.renderer.texture.DynamicTexture;
|
2018-09-05 00:23:45 +00:00
|
|
|
import net.minecraft.client.renderer.texture.NativeImage;
|
2013-07-10 19:47:13 +00:00
|
|
|
import net.minecraft.client.renderer.texture.TextureManager;
|
2013-06-29 17:33:14 +00:00
|
|
|
import net.minecraft.client.resources.I18n;
|
2018-09-29 05:29:35 +00:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
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;
|
2018-09-29 05:29:35 +00:00
|
|
|
import net.minecraftforge.common.ForgeHooks;
|
2019-02-01 21:55:23 +00:00
|
|
|
import net.minecraftforge.fml.ForgeI18n;
|
|
|
|
import net.minecraftforge.fml.MavenVersionStringHelper;
|
|
|
|
import net.minecraftforge.fml.ModContainer;
|
|
|
|
import net.minecraftforge.fml.ModList;
|
|
|
|
import net.minecraftforge.fml.VersionChecker;
|
2018-06-11 13:56:44 +00:00
|
|
|
import net.minecraftforge.fml.client.ConfigGuiHandler;
|
2019-02-01 21:55:23 +00:00
|
|
|
import net.minecraftforge.fml.packs.ModFileResourcePack;
|
2018-10-06 01:42:15 +00:00
|
|
|
import net.minecraftforge.fml.packs.ResourcePackLoader;
|
2019-01-14 03:51:36 +00:00
|
|
|
import net.minecraftforge.forgespi.language.IModInfo;
|
2018-06-11 13:56:44 +00:00
|
|
|
import net.minecraftforge.fml.loading.StringUtils;
|
|
|
|
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2018-10-04 02:47:07 +00:00
|
|
|
import org.apache.maven.artifact.versioning.ComparableVersion;
|
2012-09-15 19:58:20 +00:00
|
|
|
|
2018-09-29 05:29:35 +00:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import java.awt.Dimension;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
import java.util.function.Function;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import static net.minecraft.util.StringUtils.stripControlCodes;
|
|
|
|
|
2012-05-11 05:45:36 +00:00
|
|
|
/**
|
|
|
|
* @author cpw
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class GuiModList extends GuiScreen
|
|
|
|
{
|
2018-06-11 13:56:44 +00:00
|
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
|
|
|
private enum SortType implements Comparator<ModInfo>
|
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
|
|
|
|
|
|
|
|
2018-09-05 00:23:45 +00:00
|
|
|
|
|
|
|
GuiButton button;
|
|
|
|
|
2018-06-11 13:56:44 +00:00
|
|
|
private int buttonID;
|
2015-03-13 22:38:10 +00:00
|
|
|
private SortType(int buttonID)
|
|
|
|
{
|
|
|
|
this.buttonID = buttonID;
|
|
|
|
}
|
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
|
2018-06-11 13:56:44 +00:00
|
|
|
public int compare(ModInfo o1, ModInfo o2)
|
2015-04-12 04:51:03 +00:00
|
|
|
{
|
2018-06-11 13:56:44 +00:00
|
|
|
String name1 = StringUtils.toLowerCase(stripControlCodes(o1.getDisplayName()));
|
|
|
|
String name2 = StringUtils.toLowerCase(stripControlCodes(o2.getDisplayName()));
|
2015-04-14 04:52:53 +00:00
|
|
|
return compare(name1, name2);
|
2015-04-12 04:51:03 +00:00
|
|
|
}
|
2018-06-11 13:56:44 +00:00
|
|
|
|
2018-09-05 00:23:45 +00:00
|
|
|
String getButtonText() {
|
|
|
|
return I18n.format("fml.menu.mods."+StringUtils.toLowerCase(name()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
private class SortButton extends GuiButton {
|
|
|
|
private final SortType type;
|
|
|
|
public SortButton(int buttonId, int x, int y, int width, int height, SortType type)
|
|
|
|
{
|
|
|
|
super(buttonId, x, y, width, height, type.getButtonText());
|
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-09-22 10:40:22 +00:00
|
|
|
public void onClick(double mouseX, double mouseY)
|
2018-09-05 00:23:45 +00:00
|
|
|
{
|
|
|
|
GuiModList.this.sortType = this.type;
|
|
|
|
resortMods();
|
|
|
|
}
|
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;
|
2018-09-05 00:23:45 +00:00
|
|
|
|
2012-05-11 05:45:36 +00:00
|
|
|
private GuiSlotModList modList;
|
2018-09-05 00:23:45 +00:00
|
|
|
private InfoPanel modInfo;
|
2012-05-14 05:38:53 +00:00
|
|
|
private int selected = -1;
|
2018-06-11 13:56:44 +00:00
|
|
|
private ModInfo selectedMod;
|
2012-05-15 19:52:19 +00:00
|
|
|
private int listWidth;
|
2018-06-11 13:56:44 +00:00
|
|
|
private List<ModInfo> mods;
|
|
|
|
private final List<ModInfo> unsortedMods;
|
2018-09-05 00:23:45 +00:00
|
|
|
private GuiButton configButton;
|
|
|
|
|
2015-03-13 22:38:10 +00:00
|
|
|
private int buttonMargin = 1;
|
|
|
|
private int numButtons = SortType.values().length;
|
|
|
|
private String lastFilterText = "";
|
|
|
|
|
|
|
|
private GuiTextField search;
|
2018-09-05 00:23:45 +00:00
|
|
|
|
2015-03-13 22:38:10 +00:00
|
|
|
private boolean sorted = false;
|
|
|
|
private SortType sortType = SortType.NORMAL;
|
2018-09-29 05:29:35 +00:00
|
|
|
|
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;
|
2018-09-05 00:23:45 +00:00
|
|
|
this.mods = Collections.unmodifiableList(ModList.get().getMods());
|
2018-06-11 13:56:44 +00:00
|
|
|
this.unsortedMods = Collections.unmodifiableList(this.mods);
|
2012-05-11 05:45:36 +00:00
|
|
|
}
|
2012-07-31 02:31:07 +00:00
|
|
|
|
2018-09-29 05:29:35 +00:00
|
|
|
class InfoPanel extends GuiListExtended<InfoPanel.Info> {
|
2018-09-05 00:23:45 +00:00
|
|
|
InfoPanel(Minecraft mcIn, int widthIn, int heightIn, int topIn, int bottomIn, int slotHeightIn)
|
|
|
|
{
|
|
|
|
super(mcIn, widthIn, heightIn, topIn, bottomIn, slotHeightIn);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected int getScrollBarX()
|
|
|
|
{
|
2018-09-29 05:29:35 +00:00
|
|
|
return this.right - 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getListWidth() {
|
|
|
|
return this.width;
|
2018-09-05 00:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setInfo(Info info)
|
|
|
|
{
|
2018-09-22 10:40:22 +00:00
|
|
|
this.clearEntries();
|
|
|
|
this.addEntry(info);
|
2018-09-05 00:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void clear()
|
|
|
|
{
|
2018-09-22 10:40:22 +00:00
|
|
|
this.clearEntries();
|
2018-09-05 00:23:45 +00:00
|
|
|
}
|
2018-09-29 05:29:35 +00:00
|
|
|
class Info extends GuiListExtended.IGuiListEntry<Info>
|
|
|
|
{
|
|
|
|
private ResourceLocation logoPath;
|
|
|
|
private Dimension logoDims;
|
|
|
|
private List<ITextComponent> lines;
|
|
|
|
|
|
|
|
public Info(GuiListExtended<Info> parent, List<String> lines, @Nullable ResourceLocation logoPath, Dimension logoDims)
|
|
|
|
{
|
|
|
|
this.list = parent;
|
|
|
|
this.lines = resizeContent(lines);
|
|
|
|
this.logoPath = logoPath;
|
|
|
|
this.logoDims = logoDims;
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<ITextComponent> resizeContent(List<String> lines)
|
|
|
|
{
|
|
|
|
List<ITextComponent> ret = new ArrayList<ITextComponent>();
|
|
|
|
for (String line : lines)
|
|
|
|
{
|
|
|
|
if (line == null)
|
|
|
|
{
|
|
|
|
ret.add(null);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ITextComponent chat = ForgeHooks.newChatWithLinks(line, false);
|
|
|
|
int maxTextLength = InfoPanel.this.width - 8;
|
|
|
|
if (maxTextLength >= 0)
|
|
|
|
{
|
|
|
|
ret.addAll(GuiUtilRenderComponents.splitText(chat, maxTextLength, GuiModList.this.fontRenderer, false, true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawEntry(int entryWidth, int entryHeight, int mouseX, int mouseY, boolean p_194999_5_, float partialTicks)
|
|
|
|
{
|
|
|
|
int top = this.getY();
|
|
|
|
int left = this.getX();
|
|
|
|
|
|
|
|
if (logoPath != null) {
|
|
|
|
mc.getTextureManager().bindTexture(logoPath);
|
|
|
|
GlStateManager.enableBlend();
|
|
|
|
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
Gui.drawModalRectWithCustomSizedTexture(left, top, 0.0F, 0.0F, logoDims.width, logoDims.height, logoDims.width, logoDims.height);
|
|
|
|
top += logoDims.height + 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ITextComponent line : lines)
|
|
|
|
{
|
|
|
|
if (line != null)
|
|
|
|
{
|
|
|
|
GlStateManager.enableBlend();
|
|
|
|
GuiModList.this.fontRenderer.drawStringWithShadow(line.getFormattedText(), left + 4, top, 0xFFFFFF);
|
|
|
|
GlStateManager.disableAlphaTest();
|
|
|
|
GlStateManager.disableBlend();
|
|
|
|
}
|
|
|
|
top += fontRenderer.FONT_HEIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
final ITextComponent component = findTextLine(mouseX, mouseY, 0, 0);
|
|
|
|
if (component!=null) {
|
|
|
|
GuiModList.this.handleComponentHover(component, mouseX, mouseY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private ITextComponent findTextLine(final int mouseX, final int mouseY, final int offX, final int offY) {
|
|
|
|
int offset = mouseY - offY;
|
|
|
|
if (logoPath != null) {
|
|
|
|
offset -= logoDims.height + 10;
|
|
|
|
}
|
|
|
|
if (offset <= 0)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
int lineIdx = offset / fontRenderer.FONT_HEIGHT;
|
|
|
|
if (lineIdx >= lines.size() || lineIdx < 1)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
ITextComponent line = lines.get(lineIdx-1);
|
|
|
|
if (line != null)
|
|
|
|
{
|
|
|
|
int k = offX;
|
|
|
|
for (ITextComponent part : line) {
|
|
|
|
if (!(part instanceof TextComponentString))
|
|
|
|
continue;
|
|
|
|
k += GuiModList.this.fontRenderer.getStringWidth(((TextComponentString)part).getText());
|
|
|
|
if (k >= mouseX)
|
|
|
|
{
|
|
|
|
return part;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean mouseClicked(final double mouseX, final double mouseY, final int buttonmask) {
|
|
|
|
final ITextComponent component = findTextLine((int) mouseX, (int) mouseY, InfoPanel.this.left, InfoPanel.this.top);
|
|
|
|
if (component != null) {
|
|
|
|
GuiModList.this.handleComponentClick(component);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-09-05 00:23:45 +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
|
|
|
{
|
2018-06-11 13:56:44 +00:00
|
|
|
for (ModInfo mod : mods)
|
2015-04-14 04:52:53 +00:00
|
|
|
{
|
2018-06-11 13:56:44 +00:00
|
|
|
listWidth = Math.max(listWidth,getFontRenderer().getStringWidth(mod.getDisplayName()) + 10);
|
2018-10-04 04:57:08 +00:00
|
|
|
listWidth = Math.max(listWidth,getFontRenderer().getStringWidth(MavenVersionStringHelper.artifactVersionToString(mod.getVersion())) + 5);
|
2012-05-15 19:52:19 +00:00
|
|
|
}
|
2015-04-14 04:52:53 +00:00
|
|
|
listWidth = Math.min(listWidth, 150);
|
2018-09-29 05:29:35 +00:00
|
|
|
listWidth += listWidth % numButtons != 0 ? (numButtons - listWidth % numButtons) : 0;
|
2018-09-05 00:23:45 +00:00
|
|
|
this.modList = new GuiSlotModList(this, listWidth);
|
|
|
|
this.modList.setSlotXBoundsFromLeft(6);
|
2018-09-29 05:29:35 +00:00
|
|
|
this.modInfo = new InfoPanel(this.mc, this.width - this.listWidth - 20, this.height, 10, this.height - 30, this.height - 46);
|
|
|
|
this.modInfo.setSlotXBoundsFromLeft(this.listWidth + 14);
|
2018-09-05 00:23:45 +00:00
|
|
|
|
2018-09-29 05:29:35 +00:00
|
|
|
this.addButton(new GuiButtonClickConsumer(6, ((modList.right + this.width) / 2) - 100, this.height - 24,
|
|
|
|
I18n.format("gui.done"), (x, y) -> GuiModList.this.mc.displayGuiScreen(GuiModList.this.mainMenu)));
|
|
|
|
this.addButton(this.configButton = new GuiButtonClickConsumer(20, 6, this.height - 24, this.listWidth, 20,
|
|
|
|
I18n.format("fml.menu.mods.config"), (x,y)-> GuiModList.this.displayModConfig()));
|
2015-04-14 04:52:53 +00:00
|
|
|
|
2018-09-29 05:29:35 +00:00
|
|
|
search = new GuiTextField(0, getFontRenderer(), 8, modList.bottom + 17, listWidth - 4, 14);
|
2018-09-22 10:40:22 +00:00
|
|
|
children.add(search);
|
|
|
|
children.add(modList);
|
2018-09-29 05:29:35 +00:00
|
|
|
children.add(modInfo);
|
2015-03-13 22:38:10 +00:00
|
|
|
search.setFocused(true);
|
|
|
|
search.setCanLoseFocus(true);
|
|
|
|
|
2018-09-29 05:29:35 +00:00
|
|
|
final int width = listWidth / numButtons;
|
|
|
|
int x = 6, y = 10;
|
2018-09-05 00:23:45 +00:00
|
|
|
addButton(SortType.NORMAL.button = new SortButton(SortType.NORMAL.buttonID, x, y, width - buttonMargin, 20, SortType.NORMAL));
|
2015-03-13 22:38:10 +00:00
|
|
|
x += width + buttonMargin;
|
2018-09-05 00:23:45 +00:00
|
|
|
addButton(SortType.A_TO_Z.button = new SortButton(SortType.NORMAL.buttonID, x, y, width - buttonMargin, 20, SortType.A_TO_Z));
|
2015-03-13 22:38:10 +00:00
|
|
|
x += width + buttonMargin;
|
2018-09-05 00:23:45 +00:00
|
|
|
addButton(SortType.Z_TO_A.button = new SortButton(SortType.NORMAL.buttonID, x, y, width - buttonMargin, 20, SortType.Z_TO_A));
|
|
|
|
resortMods();
|
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
|
|
|
|
2018-09-05 00:23:45 +00:00
|
|
|
private void displayModConfig()
|
2015-03-13 22:38:10 +00:00
|
|
|
{
|
2018-09-05 00:23:45 +00:00
|
|
|
if (selectedMod == null) return;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ConfigGuiHandler.getGuiFactoryFor(selectedMod).map(f->f.apply(this.mc, this)).ifPresent(newScreen -> this.mc.displayGuiScreen(newScreen));
|
|
|
|
}
|
|
|
|
catch (final Exception e)
|
|
|
|
{
|
|
|
|
LOGGER.error("There was a critical issue trying to build the config GUI for {}", selectedMod.getModId(), e);
|
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
|
2018-09-22 10:40:22 +00:00
|
|
|
public void tick()
|
2015-03-13 22:38:10 +00:00
|
|
|
{
|
2018-09-22 10:40:22 +00:00
|
|
|
search.tick();
|
2015-03-13 22:38:10 +00:00
|
|
|
|
|
|
|
if (!search.getText().equals(lastFilterText))
|
|
|
|
{
|
|
|
|
reloadMods();
|
|
|
|
sorted = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sorted)
|
|
|
|
{
|
2015-04-12 04:51:03 +00:00
|
|
|
reloadMods();
|
2018-06-11 13:56:44 +00:00
|
|
|
mods.sort(sortType);
|
2018-09-05 00:23:45 +00:00
|
|
|
selected = mods.indexOf(selectedMod);
|
|
|
|
modList.refreshList();
|
2015-03-13 22:38:10 +00:00
|
|
|
sorted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-05 00:23:45 +00:00
|
|
|
public <T extends GuiListExtended.IGuiListEntry<T>> void buildModList(Consumer<T> modListViewConsumer, Function<ModInfo, T> newEntry)
|
|
|
|
{
|
|
|
|
mods.forEach(mod->modListViewConsumer.accept(newEntry.apply(mod)));
|
|
|
|
}
|
|
|
|
|
2015-03-13 22:38:10 +00:00
|
|
|
private void reloadMods()
|
|
|
|
{
|
2018-06-11 13:56:44 +00:00
|
|
|
this.mods = this.unsortedMods.stream().
|
|
|
|
filter(mi->StringUtils.toLowerCase(stripControlCodes(mi.getDisplayName())).contains(StringUtils.toLowerCase(search.getText()))).collect(Collectors.toList());
|
2015-03-13 22:38:10 +00:00
|
|
|
lastFilterText = search.getText();
|
2012-05-11 05:45:36 +00:00
|
|
|
}
|
|
|
|
|
2018-09-05 00:23:45 +00:00
|
|
|
private void resortMods()
|
2015-11-04 21:57:47 +00:00
|
|
|
{
|
2018-09-22 10:40:22 +00:00
|
|
|
for (GuiButton b : buttons)
|
2012-05-11 05:45:36 +00:00
|
|
|
{
|
2018-09-05 00:23:45 +00:00
|
|
|
if (b instanceof SortButton) {
|
|
|
|
b.enabled = sortType.button != b;
|
2012-05-11 05:45:36 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-05 00:23:45 +00:00
|
|
|
sorted = false;
|
2012-05-30 13:25:04 +00:00
|
|
|
}
|
2012-07-31 02:31:07 +00:00
|
|
|
|
|
|
|
@Override
|
2018-09-22 10:40:22 +00:00
|
|
|
public void render(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);
|
2018-09-05 00:23:45 +00:00
|
|
|
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;
|
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);
|
2018-09-22 10:40:22 +00:00
|
|
|
getFontRenderer().drawString(text, x, modList.bottom + 5, 0xFFFFFF);
|
|
|
|
this.search.drawTextField(mouseX, mouseY, partialTicks);
|
2018-09-29 05:29:35 +00:00
|
|
|
super.render(mouseX, mouseY, partialTicks);
|
2016-05-02 21:13:33 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2018-09-05 00:23:45 +00:00
|
|
|
if (index == this.selected) {
|
|
|
|
this.selected = -1;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
this.selected = index;
|
|
|
|
}
|
|
|
|
this.selectedMod = (this.selected >= 0 && this.selected< mods.size()) ? mods.get(this.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()
|
|
|
|
{
|
2018-09-05 00:23:45 +00:00
|
|
|
if (selectedMod == null) {
|
|
|
|
modInfo.clear();
|
2015-11-04 21:57:47 +00:00
|
|
|
return;
|
2018-09-05 00:23:45 +00:00
|
|
|
}
|
2015-11-04 21:57:47 +00:00
|
|
|
|
2018-09-05 00:23:45 +00:00
|
|
|
this.configButton.enabled = selectedMod.hasConfigUI();
|
2018-06-11 13:56:44 +00:00
|
|
|
List<String> lines = new ArrayList<>();
|
|
|
|
VersionChecker.CheckResult vercheck = VersionChecker.getResult(selectedMod);
|
2015-11-04 21:57:47 +00:00
|
|
|
|
2018-06-11 13:56:44 +00:00
|
|
|
Pair<ResourceLocation, Dimension> logoData = selectedMod.getLogoFile().map(logoFile->
|
2015-11-04 21:57:47 +00:00
|
|
|
{
|
|
|
|
TextureManager tm = mc.getTextureManager();
|
2019-02-01 21:55:23 +00:00
|
|
|
final ModFileResourcePack resourcePack = ResourcePackLoader.getResourcePackFor(selectedMod.getModId())
|
|
|
|
.orElse(ResourcePackLoader.getResourcePackFor("forge").
|
|
|
|
orElseThrow(()->new RuntimeException("Can't find forge, WHAT!")));
|
2015-11-04 21:57:47 +00:00
|
|
|
try
|
|
|
|
{
|
2018-09-05 00:23:45 +00:00
|
|
|
NativeImage logo = null;
|
2019-02-01 21:55:23 +00:00
|
|
|
InputStream logoResource = resourcePack.getRootResourceStream(logoFile);
|
2018-09-05 00:23:45 +00:00
|
|
|
if (logoResource != null)
|
2018-09-22 10:40:22 +00:00
|
|
|
logo = NativeImage.read(logoResource);
|
2015-11-04 21:57:47 +00:00
|
|
|
if (logo != null)
|
|
|
|
{
|
2018-09-22 10:40:22 +00:00
|
|
|
return Pair.of(tm.getDynamicTextureLocation("modlogo", new DynamicTexture(logo)), new Dimension(logo.getWidth(), logo.getHeight()));
|
2015-11-04 21:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (IOException e) { }
|
2018-06-11 13:56:44 +00:00
|
|
|
return Pair.<ResourceLocation, Dimension>of(null, new Dimension(0, 0));
|
|
|
|
}).orElse(Pair.of(null, new Dimension(0, 0)));
|
|
|
|
|
|
|
|
lines.add(selectedMod.getDisplayName());
|
2018-10-04 04:57:08 +00:00
|
|
|
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.version", MavenVersionStringHelper.artifactVersionToString(selectedMod.getVersion())));
|
2018-09-29 05:29:35 +00:00
|
|
|
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.idstate", selectedMod.getModId(), ModList.get().getModContainerById(selectedMod.getModId()).
|
2018-06-11 13:56:44 +00:00
|
|
|
map(ModContainer::getCurrentState).map(Object::toString).orElse("NONE")));
|
|
|
|
|
|
|
|
selectedMod.getModConfig().getOptional("credits").ifPresent(credits->
|
2018-09-29 05:29:35 +00:00
|
|
|
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.credits", credits)));
|
2018-06-11 13:56:44 +00:00
|
|
|
selectedMod.getModConfig().getOptional("authors").ifPresent(authors ->
|
2018-09-29 05:29:35 +00:00
|
|
|
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.authors", authors)));
|
2018-06-11 13:56:44 +00:00
|
|
|
selectedMod.getModConfig().getOptional("displayURL").ifPresent(displayURL ->
|
2018-09-29 05:29:35 +00:00
|
|
|
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.displayurl", displayURL)));
|
2018-09-05 00:23:45 +00:00
|
|
|
if (selectedMod.getOwningFile() == null || selectedMod.getOwningFile().getMods().size()==1)
|
2018-09-29 05:29:35 +00:00
|
|
|
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.nochildmods"));
|
2015-11-04 21:57:47 +00:00
|
|
|
else
|
2018-09-29 05:29:35 +00:00
|
|
|
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.childmods", selectedMod.getOwningFile().getMods().stream().map(IModInfo::getDisplayName).collect(Collectors.joining(","))));
|
2015-11-04 21:57:47 +00:00
|
|
|
|
2018-06-11 13:56:44 +00:00
|
|
|
if (vercheck.status == VersionChecker.Status.OUTDATED || vercheck.status == VersionChecker.Status.BETA_OUTDATED)
|
2018-09-29 05:29:35 +00:00
|
|
|
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.updateavailable", vercheck.url == null ? "" : vercheck.url));
|
2018-06-11 13:56:44 +00:00
|
|
|
|
|
|
|
lines.add(null);
|
|
|
|
lines.add(selectedMod.getDescription());
|
2015-11-04 21:57:47 +00:00
|
|
|
|
2018-06-11 13:56:44 +00:00
|
|
|
if ((vercheck.status == VersionChecker.Status.OUTDATED || vercheck.status == VersionChecker.Status.BETA_OUTDATED) && vercheck.changes.size() > 0)
|
2015-11-04 21:57:47 +00:00
|
|
|
{
|
|
|
|
lines.add(null);
|
2018-09-29 05:29:35 +00:00
|
|
|
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.changelogheader"));
|
2015-11-04 21:57:47 +00:00
|
|
|
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
|
|
|
|
2018-09-29 05:29:35 +00:00
|
|
|
modInfo.setInfo(modInfo.new Info(modInfo, lines, logoData.getLeft(), logoData.getRight()));
|
2015-11-04 21:57:47 +00:00
|
|
|
}
|
2012-05-11 05:45:36 +00:00
|
|
|
}
|