Search in sources :

Example 1 with ModListWidget

use of net.minecraftforge.fml.client.gui.widget.ModListWidget in project Magma-1.16.x by magmafoundation.

the class ModListScreen method init.

@Override
public void init() {
    for (ModInfo mod : mods) {
        listWidth = Math.max(listWidth, getFontRenderer().width(mod.getDisplayName()) + 10);
        listWidth = Math.max(listWidth, getFontRenderer().width(MavenVersionStringHelper.artifactVersionToString(mod.getVersion())) + 5);
    }
    listWidth = Math.max(Math.min(listWidth, width / 3), 100);
    listWidth += listWidth % numButtons != 0 ? (numButtons - listWidth % numButtons) : 0;
    int modInfoWidth = this.width - this.listWidth - (PADDING * 3);
    int doneButtonWidth = Math.min(modInfoWidth, 200);
    int y = this.height - 20 - PADDING;
    this.addButton(new Button(((listWidth + PADDING + this.width - doneButtonWidth) / 2), y, doneButtonWidth, 20, new TranslationTextComponent("gui.done"), b -> ModListScreen.this.onClose()));
    this.addButton(this.openModsFolderButton = new Button(6, y, this.listWidth, 20, new TranslationTextComponent("fml.menu.mods.openmodsfolder"), b -> Util.getPlatform().openFile(FMLPaths.MODSDIR.get().toFile())));
    y -= 20 + PADDING;
    this.addButton(this.configButton = new Button(6, y, this.listWidth, 20, new TranslationTextComponent("fml.menu.mods.config"), b -> ModListScreen.this.displayModConfig()));
    this.configButton.active = false;
    y -= 14 + PADDING + 1;
    search = new TextFieldWidget(getFontRenderer(), PADDING + 1, y, listWidth - 2, 14, new TranslationTextComponent("fml.menu.mods.search"));
    int fullButtonHeight = PADDING + 20 + PADDING;
    this.modList = new ModListWidget(this, listWidth, fullButtonHeight, search.y - getFontRenderer().lineHeight - PADDING);
    this.modList.setLeftPos(6);
    this.modInfo = new InfoPanel(this.minecraft, modInfoWidth, this.height - PADDING - fullButtonHeight, PADDING);
    children.add(search);
    children.add(modList);
    children.add(modInfo);
    search.setFocus(false);
    search.setCanLoseFocus(true);
    final int width = listWidth / numButtons;
    int x = PADDING;
    addButton(SortType.NORMAL.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.NORMAL.getButtonText(), b -> resortMods(SortType.NORMAL)));
    x += width + buttonMargin;
    addButton(SortType.A_TO_Z.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.A_TO_Z.getButtonText(), b -> resortMods(SortType.A_TO_Z)));
    x += width + buttonMargin;
    addButton(SortType.Z_TO_A.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.Z_TO_A.getButtonText(), b -> resortMods(SortType.Z_TO_A)));
    resortMods(SortType.NORMAL);
    updateCache();
}
Also used : NativeImage(net.minecraft.client.renderer.texture.NativeImage) Pair(org.apache.commons.lang3.tuple.Pair) Button(net.minecraft.client.gui.widget.button.Button) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) ResourcePackLoader(net.minecraftforge.fml.packs.ResourcePackLoader) FMLPaths(net.minecraftforge.fml.loading.FMLPaths) ConfigGuiHandler(net.minecraftforge.fml.client.ConfigGuiHandler) ModList(net.minecraftforge.fml.ModList) IModInfo(net.minecraftforge.forgespi.language.IModInfo) Collectors(java.util.stream.Collectors) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Screen(net.minecraft.client.gui.screen.Screen) ScrollPanel(net.minecraftforge.client.gui.ScrollPanel) Environment(cpw.mods.modlauncher.Environment) FMLEnvironment(net.minecraftforge.fml.loading.FMLEnvironment) Entry(java.util.Map.Entry) ModFileResourcePack(net.minecraftforge.fml.packs.ModFileResourcePack) Size2i(net.minecraftforge.common.util.Size2i) net.minecraft.util.text(net.minecraft.util.text) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) ForgeHooks(net.minecraftforge.common.ForgeHooks) ModContainer(net.minecraftforge.fml.ModContainer) Util(net.minecraft.util.Util) ForgeI18n(net.minecraftforge.fml.ForgeI18n) IReorderingProcessor(net.minecraft.util.IReorderingProcessor) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ModInfo(net.minecraftforge.fml.loading.moddiscovery.ModInfo) Minecraft(net.minecraft.client.Minecraft) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) MavenVersionStringHelper(net.minecraftforge.fml.MavenVersionStringHelper) ModListWidget(net.minecraftforge.fml.client.gui.widget.ModListWidget) StringUtils(net.minecraftforge.fml.loading.StringUtils) GuiUtils(net.minecraftforge.fml.client.gui.GuiUtils) ExtendedList(net.minecraft.client.gui.widget.list.ExtendedList) IOException(java.io.IOException) TextureManager(net.minecraft.client.renderer.texture.TextureManager) Consumer(java.util.function.Consumer) VersionChecker(net.minecraftforge.fml.VersionChecker) FontRenderer(net.minecraft.client.gui.FontRenderer) Tessellator(net.minecraft.client.renderer.Tessellator) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) ResourceLocation(net.minecraft.util.ResourceLocation) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) Button(net.minecraft.client.gui.widget.button.Button) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) IModInfo(net.minecraftforge.forgespi.language.IModInfo) ModInfo(net.minecraftforge.fml.loading.moddiscovery.ModInfo) ModListWidget(net.minecraftforge.fml.client.gui.widget.ModListWidget)

Example 2 with ModListWidget

use of net.minecraftforge.fml.client.gui.widget.ModListWidget in project LoliServer by Loli-Server.

the class ModListScreen method init.

@Override
public void init() {
    for (ModInfo mod : mods) {
        listWidth = Math.max(listWidth, getFontRenderer().width(mod.getDisplayName()) + 10);
        listWidth = Math.max(listWidth, getFontRenderer().width(MavenVersionStringHelper.artifactVersionToString(mod.getVersion())) + 5);
    }
    listWidth = Math.max(Math.min(listWidth, width / 3), 100);
    listWidth += listWidth % numButtons != 0 ? (numButtons - listWidth % numButtons) : 0;
    int modInfoWidth = this.width - this.listWidth - (PADDING * 3);
    int doneButtonWidth = Math.min(modInfoWidth, 200);
    int y = this.height - 20 - PADDING;
    this.addButton(new Button(((listWidth + PADDING + this.width - doneButtonWidth) / 2), y, doneButtonWidth, 20, new TranslationTextComponent("gui.done"), b -> ModListScreen.this.onClose()));
    this.addButton(this.openModsFolderButton = new Button(6, y, this.listWidth, 20, new TranslationTextComponent("fml.menu.mods.openmodsfolder"), b -> Util.getPlatform().openFile(FMLPaths.MODSDIR.get().toFile())));
    y -= 20 + PADDING;
    this.addButton(this.configButton = new Button(6, y, this.listWidth, 20, new TranslationTextComponent("fml.menu.mods.config"), b -> ModListScreen.this.displayModConfig()));
    this.configButton.active = false;
    y -= 14 + PADDING + 1;
    search = new TextFieldWidget(getFontRenderer(), PADDING + 1, y, listWidth - 2, 14, new TranslationTextComponent("fml.menu.mods.search"));
    int fullButtonHeight = PADDING + 20 + PADDING;
    this.modList = new ModListWidget(this, listWidth, fullButtonHeight, search.y - getFontRenderer().lineHeight - PADDING);
    this.modList.setLeftPos(6);
    this.modInfo = new InfoPanel(this.minecraft, modInfoWidth, this.height - PADDING - fullButtonHeight, PADDING);
    children.add(search);
    children.add(modList);
    children.add(modInfo);
    search.setFocus(false);
    search.setCanLoseFocus(true);
    final int width = listWidth / numButtons;
    int x = PADDING;
    addButton(SortType.NORMAL.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.NORMAL.getButtonText(), b -> resortMods(SortType.NORMAL)));
    x += width + buttonMargin;
    addButton(SortType.A_TO_Z.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.A_TO_Z.getButtonText(), b -> resortMods(SortType.A_TO_Z)));
    x += width + buttonMargin;
    addButton(SortType.Z_TO_A.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.Z_TO_A.getButtonText(), b -> resortMods(SortType.Z_TO_A)));
    resortMods(SortType.NORMAL);
    updateCache();
}
Also used : NativeImage(net.minecraft.client.renderer.texture.NativeImage) Pair(org.apache.commons.lang3.tuple.Pair) Button(net.minecraft.client.gui.widget.button.Button) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) ResourcePackLoader(net.minecraftforge.fml.packs.ResourcePackLoader) FMLPaths(net.minecraftforge.fml.loading.FMLPaths) ConfigGuiHandler(net.minecraftforge.fml.client.ConfigGuiHandler) ModList(net.minecraftforge.fml.ModList) IModInfo(net.minecraftforge.forgespi.language.IModInfo) Collectors(java.util.stream.Collectors) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Screen(net.minecraft.client.gui.screen.Screen) ScrollPanel(net.minecraftforge.client.gui.ScrollPanel) Environment(cpw.mods.modlauncher.Environment) FMLEnvironment(net.minecraftforge.fml.loading.FMLEnvironment) Entry(java.util.Map.Entry) ModFileResourcePack(net.minecraftforge.fml.packs.ModFileResourcePack) Size2i(net.minecraftforge.common.util.Size2i) net.minecraft.util.text(net.minecraft.util.text) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) ForgeHooks(net.minecraftforge.common.ForgeHooks) ModContainer(net.minecraftforge.fml.ModContainer) Util(net.minecraft.util.Util) ForgeI18n(net.minecraftforge.fml.ForgeI18n) IReorderingProcessor(net.minecraft.util.IReorderingProcessor) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ModInfo(net.minecraftforge.fml.loading.moddiscovery.ModInfo) Minecraft(net.minecraft.client.Minecraft) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) MavenVersionStringHelper(net.minecraftforge.fml.MavenVersionStringHelper) ModListWidget(net.minecraftforge.fml.client.gui.widget.ModListWidget) StringUtils(net.minecraftforge.fml.loading.StringUtils) GuiUtils(net.minecraftforge.fml.client.gui.GuiUtils) ExtendedList(net.minecraft.client.gui.widget.list.ExtendedList) IOException(java.io.IOException) TextureManager(net.minecraft.client.renderer.texture.TextureManager) Consumer(java.util.function.Consumer) VersionChecker(net.minecraftforge.fml.VersionChecker) FontRenderer(net.minecraft.client.gui.FontRenderer) Tessellator(net.minecraft.client.renderer.Tessellator) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) ResourceLocation(net.minecraft.util.ResourceLocation) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) Button(net.minecraft.client.gui.widget.button.Button) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) IModInfo(net.minecraftforge.forgespi.language.IModInfo) ModInfo(net.minecraftforge.fml.loading.moddiscovery.ModInfo) ModListWidget(net.minecraftforge.fml.client.gui.widget.ModListWidget)

Aggregations

MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)2 RenderSystem (com.mojang.blaze3d.systems.RenderSystem)2 Environment (cpw.mods.modlauncher.Environment)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 Consumer (java.util.function.Consumer)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Minecraft (net.minecraft.client.Minecraft)2 FontRenderer (net.minecraft.client.gui.FontRenderer)2 Screen (net.minecraft.client.gui.screen.Screen)2 TextFieldWidget (net.minecraft.client.gui.widget.TextFieldWidget)2 Button (net.minecraft.client.gui.widget.button.Button)2 ExtendedList (net.minecraft.client.gui.widget.list.ExtendedList)2 Tessellator (net.minecraft.client.renderer.Tessellator)2