mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 03:25:18 +00:00
Network init
This commit is contained in:
1 parent
b50b768852
commit
d7e9217695
43 files changed
+1064
-794
No files matched your search
@@ -21,8 +21,11 @@ package net.minecraftforge.fml.client;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.resources.DownloadingPackFinder;
|
||||
import net.minecraft.client.resources.ResourcePackInfoClient;
|
||||
import net.minecraft.resources.IReloadableResourceManager;
|
||||
import net.minecraft.resources.IResourcePack;
|
||||
import net.minecraft.resources.ResourcePackList;
|
||||
import net.minecraft.resources.data.IMetadataSectionSerializer;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
@@ -42,7 +45,7 @@ public class ClientModLoader
|
||||
private static boolean loading;
|
||||
private static Minecraft mc;
|
||||
|
||||
public static void begin(final Minecraft minecraft, final List<IResourcePack> defaultResourcePacks, final IReloadableResourceManager mcResourceManager, IMetadataSectionSerializer metadataSerializer)
|
||||
public static void begin(final Minecraft minecraft, final ResourcePackList<ResourcePackInfoClient> defaultResourcePacks, final IReloadableResourceManager mcResourceManager, DownloadingPackFinder metadataSerializer)
|
||||
{
|
||||
loading = true;
|
||||
ClientModLoader.mc = minecraft;
|
||||
@@ -50,7 +53,6 @@ public class ClientModLoader
|
||||
LogicalSidedProvider.setClient(()->minecraft);
|
||||
ModLoader.get().loadMods();
|
||||
ResourcePackLoader.loadResourcePacks(defaultResourcePacks);
|
||||
minecraft.refreshResources();
|
||||
}
|
||||
|
||||
public static void end()
|
||||
|
||||
@@ -19,10 +19,15 @@
|
||||
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import net.minecraft.client.resources.ResourcePackInfoClient;
|
||||
import net.minecraft.resources.AbstractResourcePack;
|
||||
import net.minecraft.resources.FilePack;
|
||||
import net.minecraft.resources.FolderPack;
|
||||
import net.minecraft.resources.IPackFinder;
|
||||
import net.minecraft.resources.IReloadableResourceManager;
|
||||
import net.minecraft.resources.IResourcePack;
|
||||
import net.minecraft.resources.ResourcePackInfo;
|
||||
import net.minecraft.resources.ResourcePackList;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
|
||||
@@ -37,20 +42,35 @@ public class ResourcePackLoader
|
||||
{
|
||||
private static Map<ModFile, ModFileResourcePack> modResourcePacks;
|
||||
private static AbstractResourcePack forgePack;
|
||||
private static ResourcePackList<?> resourcePackList;
|
||||
|
||||
public static IResourcePack getResourcePackFor(String modId)
|
||||
{
|
||||
return modResourcePacks.get(ModList.get().getModFileById(modId).getFile());
|
||||
}
|
||||
|
||||
public static void loadResourcePacks(List<IResourcePack> resourcePacks) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends ResourcePackInfo> T getResourcePackInfo(String modId) {
|
||||
return (T)resourcePackList.func_198981_a(modId);
|
||||
}
|
||||
|
||||
public static <T extends ResourcePackInfo> void loadResourcePacks(ResourcePackList<T> resourcePacks) {
|
||||
resourcePackList = resourcePacks;
|
||||
modResourcePacks = ModList.get().getModFiles().stream().
|
||||
map(mf -> new ModFileResourcePack(mf.getFile())).
|
||||
collect(Collectors.toMap(ModFileResourcePack::getModFile, Function.identity()));
|
||||
forgePack = Files.isDirectory(FMLLoader.getForgePath()) ?
|
||||
new FolderPack(FMLLoader.getForgePath().toFile()) :
|
||||
new FilePack(FMLLoader.getForgePath().toFile());
|
||||
resourcePacks.add(forgePack);
|
||||
resourcePacks.addAll(modResourcePacks.values());
|
||||
resourcePacks.func_198982_a(new ModPackFinder());
|
||||
}
|
||||
|
||||
private static class ModPackFinder implements net.minecraft.resources.IPackFinder
|
||||
{
|
||||
@Override
|
||||
public <T extends ResourcePackInfo> void func_195730_a(Map<String, T> packList, ResourcePackInfo.IFactory<T> factory)
|
||||
{
|
||||
packList.put("forge", ResourcePackInfo.func_195793_a("forge", true, ()->forgePack, factory, ResourcePackInfo.Priority.BOTTOM));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@
|
||||
package net.minecraftforge.fml.client.gui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
@@ -29,14 +28,17 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiListExtended;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.gui.GuiUtilRenderComponents;
|
||||
@@ -44,14 +46,14 @@ import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.client.renderer.texture.NativeImage;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
import net.minecraft.client.resources.ResourcePackInfoClient;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.VersionChecker;
|
||||
import net.minecraftforge.fml.client.ConfigGuiHandler;
|
||||
@@ -67,9 +69,6 @@ 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;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
* @author cpw
|
||||
@@ -78,7 +77,6 @@ import org.lwjgl.opengl.GL11;
|
||||
public class GuiModList extends GuiScreen
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
private enum SortType implements Comparator<ModInfo>
|
||||
{
|
||||
NORMAL(24),
|
||||
@@ -86,27 +84,15 @@ public class GuiModList extends GuiScreen
|
||||
Z_TO_A(26){ @Override protected int compare(String name1, String name2){ return name2.compareTo(name1); }};
|
||||
|
||||
|
||||
|
||||
GuiButton button;
|
||||
|
||||
private int buttonID;
|
||||
private SortType(int buttonID)
|
||||
{
|
||||
this.buttonID = buttonID;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static SortType getTypeForButton(GuiButton button)
|
||||
{
|
||||
for (SortType t : values())
|
||||
{
|
||||
if (t.buttonID == button.id)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected int compare(String name1, String name2){ return 0; }
|
||||
|
||||
@Override
|
||||
public int compare(ModInfo o1, ModInfo o2)
|
||||
{
|
||||
@@ -115,95 +101,142 @@ public class GuiModList extends GuiScreen
|
||||
return compare(name1, name2);
|
||||
}
|
||||
|
||||
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
|
||||
public void func_194829_a(double p_194829_1_, double p_194829_3_)
|
||||
{
|
||||
GuiModList.this.sortType = this.type;
|
||||
resortMods();
|
||||
}
|
||||
}
|
||||
|
||||
private GuiScreen mainMenu;
|
||||
|
||||
private GuiSlotModList modList;
|
||||
private GuiScrollingList modInfo;
|
||||
private InfoPanel modInfo;
|
||||
private int selected = -1;
|
||||
private ModInfo selectedMod;
|
||||
private int listWidth;
|
||||
private List<ModInfo> mods;
|
||||
private GuiButton configModButton;
|
||||
|
||||
private final List<ModInfo> unsortedMods;
|
||||
private GuiButton configButton;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @param mainMenu
|
||||
*/
|
||||
public GuiModList(GuiScreen mainMenu)
|
||||
{
|
||||
this.mainMenu = mainMenu;
|
||||
this.mods = ModList.get().getModFiles().stream().
|
||||
map(mf -> mf.getMods().stream().findFirst()).
|
||||
map(Optional::get).
|
||||
map(ModInfo.class::cast).
|
||||
collect(Collectors.toList());
|
||||
this.mods = Collections.unmodifiableList(ModList.get().getMods());
|
||||
this.unsortedMods = Collections.unmodifiableList(this.mods);
|
||||
}
|
||||
|
||||
class InfoPanel extends GuiListExtended<Info> {
|
||||
InfoPanel(Minecraft mcIn, int widthIn, int heightIn, int topIn, int bottomIn, int slotHeightIn)
|
||||
{
|
||||
super(mcIn, widthIn, heightIn, topIn, bottomIn, slotHeightIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getScrollBarX()
|
||||
{
|
||||
return this.width - 6;
|
||||
}
|
||||
|
||||
void setInfo(Info info)
|
||||
{
|
||||
this.func_195086_c();
|
||||
this.func_195085_a(info);
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
this.func_195086_c();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
int slotHeight = 35;
|
||||
for (ModInfo mod : mods)
|
||||
{
|
||||
listWidth = Math.max(listWidth,getFontRenderer().getStringWidth(mod.getDisplayName()) + 10);
|
||||
listWidth = Math.max(listWidth,getFontRenderer().getStringWidth(mod.getVersion().getVersionString()) + 5 + slotHeight);
|
||||
listWidth = Math.max(listWidth,getFontRenderer().getStringWidth(mod.getVersion().getVersionString()) + 5);
|
||||
}
|
||||
listWidth = Math.min(listWidth, 150);
|
||||
this.modList = new GuiSlotModList(this, mods, listWidth, slotHeight);
|
||||
this.modList = new GuiSlotModList(this, listWidth);
|
||||
this.modList.setSlotXBoundsFromLeft(6);
|
||||
this.modInfo = new InfoPanel(this.mc, this.width - this.listWidth - 30, this.height, 32, this.height - 88 + 4, 1);
|
||||
this.modInfo.setSlotXBoundsFromLeft(this.listWidth + 24);
|
||||
|
||||
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");
|
||||
this.buttonList.add(configModButton);
|
||||
this.addButton(new GuiButton(6, ((modList.right + this.width) / 2) - 100, this.height - 38, I18n.format("gui.done")){
|
||||
@Override
|
||||
public void func_194829_a(double p_194829_1_, double p_194829_3_)
|
||||
{
|
||||
GuiModList.this.mc.displayGuiScreen(GuiModList.this.mainMenu);
|
||||
}
|
||||
});
|
||||
this.addButton(this.configButton = new GuiButton(20, 10, this.height - 49, this.listWidth, 20, I18n.format("fml.menu.mods.config")){
|
||||
@Override
|
||||
public void func_194829_a(double p_194829_1_, double p_194829_3_)
|
||||
{
|
||||
GuiModList.this.displayModConfig();
|
||||
}
|
||||
});
|
||||
|
||||
search = new GuiTextField(0, getFontRenderer(), 12, modList.bottom + 17, modList.listWidth - 4, 14);
|
||||
search = new GuiTextField(0, getFontRenderer(), 12, modList.bottom + 17, modList.width - 4, 14);
|
||||
field_195124_j.add(search);
|
||||
field_195124_j.add(modList);
|
||||
search.setFocused(true);
|
||||
search.setCanLoseFocus(true);
|
||||
|
||||
int width = (modList.listWidth / numButtons);
|
||||
final int width = (modList.width / 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);
|
||||
addButton(SortType.NORMAL.button = new SortButton(SortType.NORMAL.buttonID, x, y, width - buttonMargin, 20, SortType.NORMAL));
|
||||
x += width + buttonMargin;
|
||||
buttonList.add(new GuiButton(SortType.A_TO_Z.buttonID, x, y, width - buttonMargin, 20, "A-Z"));
|
||||
addButton(SortType.A_TO_Z.button = new SortButton(SortType.NORMAL.buttonID, x, y, width - buttonMargin, 20, SortType.A_TO_Z));
|
||||
x += width + buttonMargin;
|
||||
buttonList.add(new GuiButton(SortType.Z_TO_A.buttonID, x, y, width - buttonMargin, 20, "Z-A"));
|
||||
|
||||
addButton(SortType.Z_TO_A.button = new SortButton(SortType.NORMAL.buttonID, x, y, width - buttonMargin, 20, SortType.Z_TO_A));
|
||||
resortMods();
|
||||
updateCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int button) throws IOException
|
||||
private void displayModConfig()
|
||||
{
|
||||
super.mouseClicked(x, y, button);
|
||||
search.mouseClicked(x, y, button);
|
||||
if (button == 1 && x >= search.x && x < search.x + search.width && y >= search.y && y < search.y + search.height) {
|
||||
search.setText("");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char c, int keyCode) throws IOException
|
||||
{
|
||||
super.keyTyped(c, keyCode);
|
||||
search.textboxKeyTyped(c, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen()
|
||||
{
|
||||
super.updateScreen();
|
||||
search.updateCursorCounter();
|
||||
|
||||
if (!search.getText().equals(lastFilterText))
|
||||
@@ -216,11 +249,17 @@ public class GuiModList extends GuiScreen
|
||||
{
|
||||
reloadMods();
|
||||
mods.sort(sortType);
|
||||
selected = modList.selectedIndex = mods.indexOf(selectedMod);
|
||||
selected = mods.indexOf(selectedMod);
|
||||
modList.refreshList();
|
||||
sorted = true;
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends GuiListExtended.IGuiListEntry<T>> void buildModList(Consumer<T> modListViewConsumer, Function<ModInfo, T> newEntry)
|
||||
{
|
||||
mods.forEach(mod->modListViewConsumer.accept(newEntry.apply(mod)));
|
||||
}
|
||||
|
||||
private void reloadMods()
|
||||
{
|
||||
this.mods = this.unsortedMods.stream().
|
||||
@@ -228,89 +267,30 @@ public class GuiModList extends GuiScreen
|
||||
lastFilterText = search.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException
|
||||
private void resortMods()
|
||||
{
|
||||
if (button.enabled)
|
||||
for (GuiButton b : buttonList)
|
||||
{
|
||||
SortType type = SortType.getTypeForButton(button);
|
||||
|
||||
if (type != null)
|
||||
{
|
||||
for (GuiButton b : buttonList)
|
||||
{
|
||||
if (SortType.getTypeForButton(b) != null)
|
||||
{
|
||||
b.enabled = true;
|
||||
}
|
||||
}
|
||||
button.enabled = false;
|
||||
sorted = false;
|
||||
sortType = type;
|
||||
Collections.copy(this.mods, this.unsortedMods);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (button.id)
|
||||
{
|
||||
case 6:
|
||||
{
|
||||
this.mc.displayGuiScreen(this.mainMenu);
|
||||
return;
|
||||
}
|
||||
case 20:
|
||||
{
|
||||
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);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (b instanceof SortButton) {
|
||||
b.enabled = sortType.button != b;
|
||||
}
|
||||
}
|
||||
super.actionPerformed(button);
|
||||
}
|
||||
|
||||
public int drawLine(String line, int offset, int shifty)
|
||||
{
|
||||
this.fontRenderer.drawString(line, offset, shifty, 0xd7edea);
|
||||
return shifty + 10;
|
||||
sorted = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.modList.drawScreen(mouseX, mouseY, partialTicks);
|
||||
if (this.modInfo != null)
|
||||
this.modInfo.drawScreen(mouseX, mouseY, partialTicks);
|
||||
this.modInfo.drawScreen(mouseX, mouseY, partialTicks);
|
||||
|
||||
int left = ((this.width - this.listWidth - 38) / 2) + this.listWidth + 30;
|
||||
this.drawCenteredString(this.fontRenderer, "Mod List", left, 16, 0xFFFFFF);
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@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);
|
||||
getFontRenderer().func_211126_b(text, x, modList.bottom + 5, 0xFFFFFF);
|
||||
this.search.func_195608_a(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
Minecraft getMinecraftInstance()
|
||||
@@ -325,10 +305,13 @@ public class GuiModList extends GuiScreen
|
||||
|
||||
public void selectModIndex(int index)
|
||||
{
|
||||
if (index == this.selected)
|
||||
return;
|
||||
this.selected = index;
|
||||
this.selectedMod = (index >= 0 && index < mods.size()) ? mods.get(selected) : null;
|
||||
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;
|
||||
|
||||
updateCache();
|
||||
}
|
||||
@@ -340,43 +323,34 @@ public class GuiModList extends GuiScreen
|
||||
|
||||
private void updateCache()
|
||||
{
|
||||
configModButton.visible = false;
|
||||
modInfo = null;
|
||||
|
||||
if (selectedMod == null)
|
||||
if (selectedMod == null) {
|
||||
modInfo.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
this.configButton.enabled = selectedMod.hasConfigUI();
|
||||
List<String> lines = new ArrayList<>();
|
||||
VersionChecker.CheckResult vercheck = VersionChecker.getResult(selectedMod);
|
||||
|
||||
Pair<ResourceLocation, Dimension> logoData = selectedMod.getLogoFile().map(logoFile->
|
||||
{
|
||||
TextureManager tm = mc.getTextureManager();
|
||||
IResourcePack pack = ResourcePackLoader.getResourcePackFor(selectedMod.getModId());
|
||||
ResourcePackInfoClient pack = ResourcePackLoader.getResourcePackInfo(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);
|
||||
}
|
||||
NativeImage logo = null;
|
||||
InputStream logoResource = getClass().getResourceAsStream(logoFile);
|
||||
if (logoResource != null)
|
||||
logo = NativeImage.func_195713_a(logoResource);
|
||||
if (logo != null)
|
||||
{
|
||||
return Pair.of(tm.getDynamicTextureLocation("modlogo", new DynamicTexture(logo)), new Dimension(logo.getWidth(), logo.getHeight()));
|
||||
return Pair.of(tm.getDynamicTextureLocation("modlogo", new DynamicTexture(logo)), new Dimension(logo.func_195702_a(), logo.func_195714_b()));
|
||||
}
|
||||
}
|
||||
catch (IOException e) { }
|
||||
return Pair.<ResourceLocation, Dimension>of(null, new Dimension(0, 0));
|
||||
}).orElse(Pair.of(null, new Dimension(0, 0)));
|
||||
|
||||
configModButton.visible = true;
|
||||
configModButton.enabled = true;
|
||||
lines.add(selectedMod.getDisplayName());
|
||||
lines.add(String.format("Version: %s", selectedMod.getVersion().getVersionString()));
|
||||
lines.add(String.format("Mod ID: '%s' Mod State: %s", selectedMod.getModId(), ModList.get().getModContainerById(selectedMod.getModId()).
|
||||
@@ -388,7 +362,7 @@ public class GuiModList extends GuiScreen
|
||||
lines.add("Authors: " + authors));
|
||||
selectedMod.getModConfig().getOptional("displayURL").ifPresent(displayURL ->
|
||||
lines.add("URL: " + displayURL));
|
||||
if (selectedMod.getOwningFile().getMods().size()==1)
|
||||
if (selectedMod.getOwningFile() == null || selectedMod.getOwningFile().getMods().size()==1)
|
||||
lines.add("No child mods for this mod");
|
||||
else
|
||||
lines.add("Child mods: " + selectedMod.getOwningFile().getMods().stream().map(IModInfo::getDisplayName).collect(Collectors.joining(",")));
|
||||
@@ -411,38 +385,23 @@ public class GuiModList extends GuiScreen
|
||||
}
|
||||
}
|
||||
|
||||
modInfo = new Info(this.width - this.listWidth - 30, lines, logoData.getLeft(), logoData.getRight());
|
||||
modInfo.setInfo(new Info(modInfo, lines, logoData.getLeft(), logoData.getRight()));
|
||||
}
|
||||
|
||||
private class Info extends GuiScrollingList
|
||||
class Info extends GuiListExtended.IGuiListEntry<Info>
|
||||
{
|
||||
@Nullable
|
||||
private ResourceLocation logoPath;
|
||||
private Dimension logoDims;
|
||||
private List<ITextComponent> lines = null;
|
||||
|
||||
public Info(int width, List<String> lines, @Nullable ResourceLocation logoPath, Dimension logoDims)
|
||||
public Info(GuiListExtended<Info> parent, List<String> lines, @Nullable ResourceLocation logoPath, Dimension logoDims)
|
||||
{
|
||||
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.field_195004_a = parent;
|
||||
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) { }
|
||||
|
||||
private List<ITextComponent> resizeContent(List<String> lines)
|
||||
{
|
||||
List<ITextComponent> ret = new ArrayList<ITextComponent>();
|
||||
@@ -454,8 +413,9 @@ public class GuiModList extends GuiScreen
|
||||
continue;
|
||||
}
|
||||
|
||||
ITextComponent chat = ForgeHooks.newChatWithLinks(line, false);
|
||||
int maxTextLength = this.listWidth - 8;
|
||||
// ITextComponent chat = ForgeHooks.newChatWithLinks(line, false);
|
||||
ITextComponent chat = new TextComponentString(line);
|
||||
int maxTextLength = this.func_195002_d() - 8;
|
||||
if (maxTextLength >= 0)
|
||||
{
|
||||
ret.addAll(GuiUtilRenderComponents.splitText(chat, maxTextLength, GuiModList.this.fontRenderer, false, true));
|
||||
@@ -464,39 +424,20 @@ public class GuiModList extends GuiScreen
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void drawHeader(int entryRight, int relativeY, Tessellator tess)
|
||||
public void func_194999_a(int p_194999_1_, int p_194999_2_, int p_194999_3_, int p_194999_4_, boolean p_194999_5_, float p_194999_6_)
|
||||
{
|
||||
int top = relativeY;
|
||||
int top = this.func_195001_c();
|
||||
int left = this.func_195002_d();
|
||||
/*
|
||||
int top = this.
|
||||
|
||||
if (logoPath != null)
|
||||
{
|
||||
GlStateManager.enableBlend();
|
||||
GuiModList.this.mc.renderEngine.bindTexture(logoPath);
|
||||
GlStateManager.draw
|
||||
BufferBuilder wr = tess.getBuffer();
|
||||
int offset = (this.left + this.listWidth/2) - (logoDims.width / 2);
|
||||
wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
|
||||
@@ -509,48 +450,19 @@ public class GuiModList extends GuiScreen
|
||||
top += logoDims.height + 10;
|
||||
}
|
||||
|
||||
*/
|
||||
for (ITextComponent line : lines)
|
||||
{
|
||||
if (line != null)
|
||||
{
|
||||
GlStateManager.enableBlend();
|
||||
GuiModList.this.fontRenderer.drawStringWithShadow(line.getFormattedText(), this.left + 4, top, 0xFFFFFF);
|
||||
GuiModList.this.fontRenderer.drawStringWithShadow(line.getFormattedText(), left + 4, top, 0xFFFFFF);
|
||||
GlStateManager.disableAlpha();
|
||||
GlStateManager.disableBlend();
|
||||
}
|
||||
top += 10;
|
||||
top += fontRenderer.FONT_HEIGHT + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
ITextComponent line = lines.get(lineIdx);
|
||||
if (line != null)
|
||||
{
|
||||
int k = -4;
|
||||
for (ITextComponent part : line) {
|
||||
if (!(part instanceof TextComponentString))
|
||||
continue;
|
||||
k += GuiModList.this.fontRenderer.getStringWidth(((TextComponentString)part).getText());
|
||||
if (k >= x)
|
||||
{
|
||||
GuiModList.this.handleComponentClick(part);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,395 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.gui;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraftforge.fml.client.config.GuiUtils;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class GuiScrollingList
|
||||
{
|
||||
private final Minecraft client;
|
||||
protected final int listWidth;
|
||||
protected final int listHeight;
|
||||
protected final int screenWidth;
|
||||
protected final int screenHeight;
|
||||
protected final int top;
|
||||
protected final int bottom;
|
||||
protected final int right;
|
||||
protected final int left;
|
||||
protected final int slotHeight;
|
||||
private int scrollUpActionId;
|
||||
private int scrollDownActionId;
|
||||
protected int mouseX;
|
||||
protected int mouseY;
|
||||
private float initialMouseClickY = -2.0F;
|
||||
private float scrollFactor;
|
||||
private float scrollDistance;
|
||||
protected int selectedIndex = -1;
|
||||
private long lastClickTime = 0L;
|
||||
private boolean highlightSelected = true;
|
||||
private boolean hasHeader;
|
||||
private int headerHeight;
|
||||
protected boolean captureMouse = true;
|
||||
|
||||
@Deprecated // We need to know screen size.
|
||||
public GuiScrollingList(Minecraft client, int width, int height, int top, int bottom, int left, int entryHeight)
|
||||
{
|
||||
this(client, width, height, top, bottom, left, entryHeight, width, height);
|
||||
}
|
||||
public GuiScrollingList(Minecraft client, int width, int height, int top, int bottom, int left, int entryHeight, int screenWidth, int screenHeight)
|
||||
{
|
||||
this.client = client;
|
||||
this.listWidth = width;
|
||||
this.listHeight = height;
|
||||
this.top = top;
|
||||
this.bottom = bottom;
|
||||
this.slotHeight = entryHeight;
|
||||
this.left = left;
|
||||
this.right = width + this.left;
|
||||
this.screenWidth = screenWidth;
|
||||
this.screenHeight = screenHeight;
|
||||
}
|
||||
|
||||
@Deprecated // Unused, remove in 1.9.3?
|
||||
public void func_27258_a(boolean p_27258_1_)
|
||||
{
|
||||
this.highlightSelected = p_27258_1_;
|
||||
}
|
||||
|
||||
@Deprecated protected void func_27259_a(boolean hasFooter, int footerHeight){ setHeaderInfo(hasFooter, footerHeight); }
|
||||
protected void setHeaderInfo(boolean hasHeader, int headerHeight)
|
||||
{
|
||||
this.hasHeader = hasHeader;
|
||||
this.headerHeight = headerHeight;
|
||||
if (!hasHeader) this.headerHeight = 0;
|
||||
}
|
||||
|
||||
protected abstract int getSize();
|
||||
|
||||
protected abstract void elementClicked(int index, boolean doubleClick);
|
||||
|
||||
protected abstract boolean isSelected(int index);
|
||||
|
||||
protected int getContentHeight()
|
||||
{
|
||||
return this.getSize() * this.slotHeight + this.headerHeight;
|
||||
}
|
||||
|
||||
protected abstract void drawBackground();
|
||||
|
||||
/**
|
||||
* Draw anything special on the screen. GL_SCISSOR is enabled for anything that
|
||||
* is rendered outside of the view box. Do not mess with SCISSOR unless you support this.
|
||||
*/
|
||||
protected abstract void drawSlot(int slotIdx, int entryRight, int slotTop, int slotBuffer, Tessellator tess);
|
||||
|
||||
@Deprecated protected void func_27260_a(int entryRight, int relativeY, Tessellator tess) {}
|
||||
/**
|
||||
* Draw anything special on the screen. GL_SCISSOR is enabled for anything that
|
||||
* is rendered outside of the view box. Do not mess with SCISSOR unless you support this.
|
||||
*/
|
||||
protected void drawHeader(int entryRight, int relativeY, Tessellator tess) { func_27260_a(entryRight, relativeY, tess); }
|
||||
|
||||
@Deprecated protected void func_27255_a(int x, int y) {}
|
||||
protected void clickHeader(int x, int y) { func_27255_a(x, y); }
|
||||
|
||||
@Deprecated protected void func_27257_b(int mouseX, int mouseY) {}
|
||||
/**
|
||||
* Draw anything special on the screen. GL_SCISSOR is enabled for anything that
|
||||
* is rendered outside of the view box. Do not mess with SCISSOR unless you support this.
|
||||
*/
|
||||
protected void drawScreen(int mouseX, int mouseY) { func_27257_b(mouseX, mouseY); }
|
||||
|
||||
@Deprecated // Unused, Remove in 1.9.3?
|
||||
public int func_27256_c(int x, int y)
|
||||
{
|
||||
int left = this.left + 1;
|
||||
int right = this.left + this.listWidth - 7;
|
||||
int relativeY = y - this.top - this.headerHeight + (int)this.scrollDistance - 4;
|
||||
int entryIndex = relativeY / this.slotHeight;
|
||||
return x >= left && x <= right && entryIndex >= 0 && relativeY >= 0 && entryIndex < this.getSize() ? entryIndex : -1;
|
||||
}
|
||||
|
||||
// FIXME: is this correct/still needed?
|
||||
public void registerScrollButtons(List<GuiButton> buttons, int upActionID, int downActionID)
|
||||
{
|
||||
this.scrollUpActionId = upActionID;
|
||||
this.scrollDownActionId = downActionID;
|
||||
}
|
||||
|
||||
private void applyScrollLimits()
|
||||
{
|
||||
int listHeight = this.getContentHeight() - (this.bottom - this.top - 4);
|
||||
|
||||
if (listHeight < 0)
|
||||
{
|
||||
listHeight /= 2;
|
||||
}
|
||||
|
||||
if (this.scrollDistance < 0.0F)
|
||||
{
|
||||
this.scrollDistance = 0.0F;
|
||||
}
|
||||
|
||||
if (this.scrollDistance > (float)listHeight)
|
||||
{
|
||||
this.scrollDistance = (float)listHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public void actionPerformed(GuiButton button)
|
||||
{
|
||||
if (button.enabled)
|
||||
{
|
||||
if (button.id == this.scrollUpActionId)
|
||||
{
|
||||
this.scrollDistance -= (float)(this.slotHeight * 2 / 3);
|
||||
this.initialMouseClickY = -2.0F;
|
||||
this.applyScrollLimits();
|
||||
}
|
||||
else if (button.id == this.scrollDownActionId)
|
||||
{
|
||||
this.scrollDistance += (float)(this.slotHeight * 2 / 3);
|
||||
this.initialMouseClickY = -2.0F;
|
||||
this.applyScrollLimits();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void handleMouseInput(int mouseX, int mouseY) throws IOException
|
||||
{
|
||||
boolean isHovering = mouseX >= this.left && mouseX <= this.left + this.listWidth &&
|
||||
mouseY >= this.top && mouseY <= this.bottom;
|
||||
if (!isHovering)
|
||||
return;
|
||||
|
||||
int scroll = Mouse.getEventDWheel();
|
||||
if (scroll != 0)
|
||||
{
|
||||
this.scrollDistance += (float)((-1 * scroll / 120.0F) * this.slotHeight / 2);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.mouseX = mouseX;
|
||||
this.mouseY = mouseY;
|
||||
this.drawBackground();
|
||||
|
||||
boolean isHovering = mouseX >= this.left && mouseX <= this.left + this.listWidth &&
|
||||
mouseY >= this.top && mouseY <= this.bottom;
|
||||
int listLength = this.getSize();
|
||||
int scrollBarWidth = 6;
|
||||
int scrollBarRight = this.left + this.listWidth;
|
||||
int scrollBarLeft = scrollBarRight - scrollBarWidth;
|
||||
int entryLeft = this.left;
|
||||
int entryRight = scrollBarLeft - 1;
|
||||
int viewHeight = this.bottom - this.top;
|
||||
int border = 4;
|
||||
|
||||
if (Mouse.isButtonDown(0))
|
||||
{
|
||||
if (this.initialMouseClickY == -1.0F)
|
||||
{
|
||||
if (isHovering)
|
||||
{
|
||||
int mouseListY = mouseY - this.top - this.headerHeight + (int)this.scrollDistance - border;
|
||||
int slotIndex = mouseListY / this.slotHeight;
|
||||
|
||||
if (mouseX >= entryLeft && mouseX <= entryRight && slotIndex >= 0 && mouseListY >= 0 && slotIndex < listLength)
|
||||
{
|
||||
this.elementClicked(slotIndex, slotIndex == this.selectedIndex && System.currentTimeMillis() - this.lastClickTime < 250L);
|
||||
this.selectedIndex = slotIndex;
|
||||
this.lastClickTime = System.currentTimeMillis();
|
||||
}
|
||||
else if (mouseX >= entryLeft && mouseX <= entryRight && mouseListY < 0)
|
||||
{
|
||||
this.clickHeader(mouseX - entryLeft, mouseY - this.top + (int)this.scrollDistance - border);
|
||||
}
|
||||
|
||||
if (mouseX >= scrollBarLeft && mouseX <= scrollBarRight)
|
||||
{
|
||||
this.scrollFactor = -1.0F;
|
||||
int scrollHeight = this.getContentHeight() - viewHeight - border;
|
||||
if (scrollHeight < 1) scrollHeight = 1;
|
||||
|
||||
int var13 = (int)((float)(viewHeight * viewHeight) / (float)this.getContentHeight());
|
||||
|
||||
if (var13 < 32) var13 = 32;
|
||||
if (var13 > viewHeight - border*2)
|
||||
var13 = viewHeight - border*2;
|
||||
|
||||
this.scrollFactor /= (float)(viewHeight - var13) / (float)scrollHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scrollFactor = 1.0F;
|
||||
}
|
||||
|
||||
this.initialMouseClickY = mouseY;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.initialMouseClickY = -2.0F;
|
||||
}
|
||||
}
|
||||
else if (this.initialMouseClickY >= 0.0F)
|
||||
{
|
||||
this.scrollDistance -= ((float)mouseY - this.initialMouseClickY) * this.scrollFactor;
|
||||
this.initialMouseClickY = (float)mouseY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.initialMouseClickY = -1.0F;
|
||||
}
|
||||
|
||||
this.applyScrollLimits();
|
||||
|
||||
Tessellator tess = Tessellator.getInstance();
|
||||
BufferBuilder worldr = tess.getBuffer();
|
||||
|
||||
ScaledResolution res = new ScaledResolution(client);
|
||||
double scaleW = client.displayWidth / res.getScaledWidth_double();
|
||||
double scaleH = client.displayHeight / res.getScaledHeight_double();
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
GL11.glScissor((int)(left * scaleW), (int)(client.displayHeight - (bottom * scaleH)),
|
||||
(int)(listWidth * scaleW), (int)(viewHeight * scaleH));
|
||||
|
||||
if (this.client.world != null)
|
||||
{
|
||||
this.drawGradientRect(this.left, this.top, this.right, this.bottom, 0xC0101010, 0xD0101010);
|
||||
}
|
||||
else // Draw dark dirt background
|
||||
{
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.disableFog();
|
||||
this.client.renderEngine.bindTexture(Gui.OPTIONS_BACKGROUND);
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
final float scale = 32.0F;
|
||||
worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
worldr.pos(this.left, this.bottom, 0.0D).tex(this.left / scale, (this.bottom + (int)this.scrollDistance) / scale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
|
||||
worldr.pos(this.right, this.bottom, 0.0D).tex(this.right / scale, (this.bottom + (int)this.scrollDistance) / scale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
|
||||
worldr.pos(this.right, this.top, 0.0D).tex(this.right / scale, (this.top + (int)this.scrollDistance) / scale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
|
||||
worldr.pos(this.left, this.top, 0.0D).tex(this.left / scale, (this.top + (int)this.scrollDistance) / scale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
|
||||
tess.draw();
|
||||
}
|
||||
|
||||
int baseY = this.top + border - (int)this.scrollDistance;
|
||||
|
||||
if (this.hasHeader) {
|
||||
this.drawHeader(entryRight, baseY, tess);
|
||||
}
|
||||
|
||||
for (int slotIdx = 0; slotIdx < listLength; ++slotIdx)
|
||||
{
|
||||
int slotTop = baseY + slotIdx * this.slotHeight + this.headerHeight;
|
||||
int slotBuffer = this.slotHeight - border;
|
||||
|
||||
if (slotTop <= this.bottom && slotTop + slotBuffer >= this.top)
|
||||
{
|
||||
if (this.highlightSelected && this.isSelected(slotIdx))
|
||||
{
|
||||
int min = this.left;
|
||||
int max = entryRight;
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlStateManager.disableTexture2D();
|
||||
worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
worldr.pos(min, slotTop + slotBuffer + 2, 0).tex(0, 1).color(0x80, 0x80, 0x80, 0xFF).endVertex();
|
||||
worldr.pos(max, slotTop + slotBuffer + 2, 0).tex(1, 1).color(0x80, 0x80, 0x80, 0xFF).endVertex();
|
||||
worldr.pos(max, slotTop - 2, 0).tex(1, 0).color(0x80, 0x80, 0x80, 0xFF).endVertex();
|
||||
worldr.pos(min, slotTop - 2, 0).tex(0, 0).color(0x80, 0x80, 0x80, 0xFF).endVertex();
|
||||
worldr.pos(min + 1, slotTop + slotBuffer + 1, 0).tex(0, 1).color(0x00, 0x00, 0x00, 0xFF).endVertex();
|
||||
worldr.pos(max - 1, slotTop + slotBuffer + 1, 0).tex(1, 1).color(0x00, 0x00, 0x00, 0xFF).endVertex();
|
||||
worldr.pos(max - 1, slotTop - 1, 0).tex(1, 0).color(0x00, 0x00, 0x00, 0xFF).endVertex();
|
||||
worldr.pos(min + 1, slotTop - 1, 0).tex(0, 0).color(0x00, 0x00, 0x00, 0xFF).endVertex();
|
||||
tess.draw();
|
||||
GlStateManager.enableTexture2D();
|
||||
}
|
||||
|
||||
this.drawSlot(slotIdx, entryRight, slotTop, slotBuffer, tess);
|
||||
}
|
||||
}
|
||||
|
||||
GlStateManager.disableDepth();
|
||||
|
||||
int extraHeight = (this.getContentHeight() + border) - viewHeight;
|
||||
if (extraHeight > 0)
|
||||
{
|
||||
int height = (viewHeight * viewHeight) / this.getContentHeight();
|
||||
|
||||
if (height < 32) height = 32;
|
||||
|
||||
if (height > viewHeight - border*2)
|
||||
height = viewHeight - border*2;
|
||||
|
||||
int barTop = (int)this.scrollDistance * (viewHeight - height) / extraHeight + this.top;
|
||||
if (barTop < this.top)
|
||||
{
|
||||
barTop = this.top;
|
||||
}
|
||||
|
||||
GlStateManager.disableTexture2D();
|
||||
worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
worldr.pos(scrollBarLeft, this.bottom, 0.0D).tex(0.0D, 1.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex();
|
||||
worldr.pos(scrollBarRight, this.bottom, 0.0D).tex(1.0D, 1.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex();
|
||||
worldr.pos(scrollBarRight, this.top, 0.0D).tex(1.0D, 0.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex();
|
||||
worldr.pos(scrollBarLeft, this.top, 0.0D).tex(0.0D, 0.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex();
|
||||
tess.draw();
|
||||
worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
worldr.pos(scrollBarLeft, barTop + height, 0.0D).tex(0.0D, 1.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex();
|
||||
worldr.pos(scrollBarRight, barTop + height, 0.0D).tex(1.0D, 1.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex();
|
||||
worldr.pos(scrollBarRight, barTop, 0.0D).tex(1.0D, 0.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex();
|
||||
worldr.pos(scrollBarLeft, barTop, 0.0D).tex(0.0D, 0.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex();
|
||||
tess.draw();
|
||||
worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
worldr.pos(scrollBarLeft, barTop + height - 1, 0.0D).tex(0.0D, 1.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
|
||||
worldr.pos(scrollBarRight - 1, barTop + height - 1, 0.0D).tex(1.0D, 1.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
|
||||
worldr.pos(scrollBarRight - 1, barTop, 0.0D).tex(1.0D, 0.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
|
||||
worldr.pos(scrollBarLeft, barTop, 0.0D).tex(0.0D, 0.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
|
||||
tess.draw();
|
||||
}
|
||||
|
||||
this.drawScreen(mouseX, mouseY);
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.shadeModel(GL11.GL_FLAT);
|
||||
GlStateManager.enableAlpha();
|
||||
GlStateManager.disableBlend();
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
protected void drawGradientRect(int left, int top, int right, int bottom, int color1, int color2)
|
||||
{
|
||||
GuiUtils.drawGradientRect(0, left, top, right, bottom, color1, color2);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import java.util.List;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiListExtended;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -37,31 +38,36 @@ import static net.minecraft.util.StringUtils.stripControlCodes;
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
public class GuiSlotModList extends GuiScrollingList
|
||||
public class GuiSlotModList extends GuiListExtended<GuiSlotModList.ModEntry>
|
||||
{
|
||||
|
||||
private static final ResourceLocation VERSION_CHECK_ICONS = new ResourceLocation(ForgeVersion.MOD_ID, "textures/gui/version_check_icons.png");
|
||||
|
||||
private final int listWidth;
|
||||
|
||||
private GuiModList parent;
|
||||
private List<ModInfo> mods;
|
||||
|
||||
public GuiSlotModList(GuiModList parent, List<ModInfo> mods, int listWidth, int slotHeight)
|
||||
public GuiSlotModList(GuiModList parent, int listWidth)
|
||||
{
|
||||
super(parent.getMinecraftInstance(), listWidth, parent.height, 32, parent.height - 88 + 4, 10, slotHeight, parent.width, parent.height);
|
||||
super(parent.getMinecraftInstance(), listWidth, parent.height, 32, parent.height - 88 + 4, parent.getFontRenderer().FONT_HEIGHT * 2 + 8);
|
||||
this.parent = parent;
|
||||
this.mods = mods;
|
||||
this.listWidth = listWidth;
|
||||
this.refreshList();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSize()
|
||||
protected int getScrollBarX()
|
||||
{
|
||||
return mods.size();
|
||||
return this.listWidth + 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void elementClicked(int index, boolean doubleClick)
|
||||
public int getListWidth()
|
||||
{
|
||||
this.parent.selectModIndex(index);
|
||||
return this.listWidth;
|
||||
}
|
||||
|
||||
void refreshList() {
|
||||
this.func_195086_c();
|
||||
parent.buildModList(this::func_195085_a, mod->new ModEntry(mod, this.parent));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,32 +82,42 @@ public class GuiSlotModList extends GuiScrollingList
|
||||
this.parent.drawDefaultBackground();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getContentHeight()
|
||||
{
|
||||
return (this.getSize()) * 35 + 1;
|
||||
}
|
||||
class ModEntry extends GuiListExtended.IGuiListEntry<ModEntry> {
|
||||
private final ModInfo modInfo;
|
||||
private final GuiModList parent;
|
||||
|
||||
@Override
|
||||
protected void drawSlot(int idx, int right, int top, int height, Tessellator tess)
|
||||
{
|
||||
ModInfo mc = mods.get(idx);
|
||||
String name = stripControlCodes(mc.getDisplayName());
|
||||
String version = stripControlCodes(mc.getVersion().getVersionString());
|
||||
FontRenderer font = this.parent.getFontRenderer();
|
||||
VersionChecker.CheckResult vercheck = VersionChecker.getResult(mc);
|
||||
ModEntry(ModInfo info, GuiModList parent) {
|
||||
this.modInfo = info;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
font.drawString(font.trimStringToWidth(name, listWidth - 10), this.left + 3 , top + 2, 0xFFFFFF);
|
||||
font.drawString(font.trimStringToWidth(version, listWidth - (5 + height)), this.left + 3 , top + 12, 0xCCCCCC);
|
||||
|
||||
if (vercheck.status.shouldDraw())
|
||||
@Override
|
||||
public void func_194999_a(int p_194999_1_, int p_194999_2_, int p_194999_3_, int p_194999_4_, boolean p_194999_5_, float p_194999_6_)
|
||||
{
|
||||
//TODO: Consider adding more icons for visualization
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(VERSION_CHECK_ICONS);
|
||||
GlStateManager.color(1, 1, 1, 1);
|
||||
GlStateManager.pushMatrix();
|
||||
Gui.drawModalRectWithCustomSizedTexture(right - (height / 2 + 4), top + (height / 2 - 4), vercheck.status.getSheetOffset() * 8, (vercheck.status.isAnimated() && ((System.currentTimeMillis() / 800 & 1)) == 1) ? 8 : 0, 8, 8, 64, 16);
|
||||
GlStateManager.popMatrix();
|
||||
int top = this.func_195001_c();
|
||||
int left = this.func_195002_d();
|
||||
String name = stripControlCodes(modInfo.getDisplayName());
|
||||
String version = stripControlCodes(modInfo.getVersion().getVersionString());
|
||||
VersionChecker.CheckResult vercheck = VersionChecker.getResult(modInfo);
|
||||
FontRenderer font = this.parent.getFontRenderer();
|
||||
font.func_211126_b(font.trimStringToWidth(name, listWidth),left + 3, top + 2, 0xFFFFFF);
|
||||
font.func_211126_b(font.trimStringToWidth(version, listWidth), left + 3 , top + 2 + font.FONT_HEIGHT, 0xCCCCCC);
|
||||
if (vercheck.status.shouldDraw())
|
||||
{
|
||||
//TODO: Consider adding more icons for visualization
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(VERSION_CHECK_ICONS);
|
||||
GlStateManager.color(1, 1, 1, 1);
|
||||
GlStateManager.pushMatrix();
|
||||
Gui.drawModalRectWithCustomSizedTexture(right - (height / 2 + 4), GuiSlotModList.this.top + (height / 2 - 4), vercheck.status.getSheetOffset() * 8, (vercheck.status.isAnimated() && ((System.currentTimeMillis() / 800 & 1)) == 1) ? 8 : 0, 8, 8, 64, 16);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double p_mouseClicked_1_, double p_mouseClicked_3_, int p_mouseClicked_5_)
|
||||
{
|
||||
parent.selectModIndex(this.func_195003_b());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user