Search in sources :

Example 1 with EditBox

use of net.minecraft.client.gui.components.EditBox in project MinecraftForge by MinecraftForge.

the class ModListScreen method init.

@Override
public void init() {
    for (IModInfo 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;
    int fullButtonHeight = PADDING + 20 + PADDING;
    doneButton = new Button(((listWidth + PADDING + this.width - doneButtonWidth) / 2), y, doneButtonWidth, 20, new TranslatableComponent("gui.done"), b -> ModListScreen.this.onClose());
    openModsFolderButton = new Button(6, y, this.listWidth, 20, new TranslatableComponent("fml.menu.mods.openmodsfolder"), b -> Util.getPlatform().openFile(FMLPaths.MODSDIR.get().toFile()));
    y -= 20 + PADDING;
    configButton = new Button(6, y, this.listWidth, 20, new TranslatableComponent("fml.menu.mods.config"), b -> ModListScreen.this.displayModConfig());
    y -= 14 + PADDING;
    search = new EditBox(getFontRenderer(), PADDING + 1, y, listWidth - 2, 14, new TranslatableComponent("fml.menu.mods.search"));
    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);
    this.addRenderableWidget(modList);
    this.addRenderableWidget(modInfo);
    this.addRenderableWidget(search);
    this.addRenderableWidget(doneButton);
    this.addRenderableWidget(configButton);
    this.addRenderableWidget(openModsFolderButton);
    search.setFocus(false);
    search.setCanLoseFocus(true);
    configButton.active = false;
    final int width = listWidth / numButtons;
    int x = PADDING;
    addRenderableWidget(SortType.NORMAL.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.NORMAL.getButtonText(), b -> resortMods(SortType.NORMAL)));
    x += width + buttonMargin;
    addRenderableWidget(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;
    addRenderableWidget(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 : ResourceLocation(net.minecraft.resources.ResourceLocation) Font(net.minecraft.client.gui.Font) ObjectSelectionList(net.minecraft.client.gui.components.ObjectSelectionList) Pair(org.apache.commons.lang3.tuple.Pair) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) PathResourcePack(net.minecraftforge.resource.PathResourcePack) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) FMLPaths(net.minecraftforge.fml.loading.FMLPaths) Screen(net.minecraft.client.gui.screens.Screen) ModList(net.minecraftforge.fml.ModList) IModInfo(net.minecraftforge.forgespi.language.IModInfo) Collectors(java.util.stream.Collectors) Language(net.minecraft.locale.Language) Style(net.minecraft.network.chat.Style) List(java.util.List) Util(net.minecraft.Util) Logger(org.apache.logging.log4j.Logger) EditBox(net.minecraft.client.gui.components.EditBox) Entry(java.util.Map.Entry) FormattedCharSequence(net.minecraft.util.FormattedCharSequence) ForgeI18n(net.minecraftforge.common.ForgeI18n) Size2i(net.minecraftforge.common.util.Size2i) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) ForgeHooks(net.minecraftforge.common.ForgeHooks) ModContainer(net.minecraftforge.fml.ModContainer) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PoseStack(com.mojang.blaze3d.vertex.PoseStack) Minecraft(net.minecraft.client.Minecraft) MavenVersionStringHelper(net.minecraftforge.common.util.MavenVersionStringHelper) NativeImage(com.mojang.blaze3d.platform.NativeImage) Button(net.minecraft.client.gui.components.Button) StringUtils(net.minecraftforge.fml.loading.StringUtils) GameRenderer(net.minecraft.client.renderer.GameRenderer) ResourcePackLoader(net.minecraftforge.resource.ResourcePackLoader) Component(net.minecraft.network.chat.Component) NarrationElementOutput(net.minecraft.client.gui.narration.NarrationElementOutput) IOException(java.io.IOException) TextureManager(net.minecraft.client.renderer.texture.TextureManager) Consumer(java.util.function.Consumer) Tesselator(com.mojang.blaze3d.vertex.Tesselator) VersionChecker(net.minecraftforge.fml.VersionChecker) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) ModListWidget(net.minecraftforge.client.gui.widget.ModListWidget) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) ConfigGuiHandler(net.minecraftforge.client.ConfigGuiHandler) InputStream(java.io.InputStream) IModInfo(net.minecraftforge.forgespi.language.IModInfo) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Button(net.minecraft.client.gui.components.Button) EditBox(net.minecraft.client.gui.components.EditBox) ModListWidget(net.minecraftforge.client.gui.widget.ModListWidget)

Example 2 with EditBox

use of net.minecraft.client.gui.components.EditBox in project SpongeCommon by SpongePowered.

the class PluginScreen method init.

@Override
protected void init() {
    Minecraft.getInstance().keyboardHandler.setSendRepeatsToGui(true);
    final int listHeight = this.height - 122;
    this.selectionList = new PluginSelectionList(this, 4, 58, 175, listHeight, 26);
    this.contentPanel = new MetadataPanel(this.minecraft, this, this.width - this.selectionList.getWidth() - 12, listHeight, 58, this.selectionList.getRight() + 4);
    // Add plugin list
    this.selectionList.setSelectConsumer(e -> this.contentPanel.setMetadata(e == null ? null : e.metadata));
    this.generateEntries(Launch.instance().pluginManager().plugins().stream().map(PluginContainer::metadata).collect(Collectors.toList()));
    // Add search text field
    this.searchField = new EditBox(this.font, this.width / 2 - 100, 22, 200, 20, new TranslatableComponent(I18n.get("itemGroup.search")));
    this.searchField.setResponder(value -> {
        this.selectionList.setFilterSupplier(() -> {
            // Filter based on ID/Name
            final List<PluginSelectionList.Entry> filteredList = this.selectionList.children().stream().filter(entry -> entry.metadata.name().orElse("").toLowerCase(Locale.ROOT).contains(value.toLowerCase(Locale.ROOT)) || entry.metadata.id().toLowerCase(Locale.ROOT).contains(value.toLowerCase(Locale.ROOT))).collect(Collectors.toList());
            // If the current selection doesn't exist, then select what we can at the top of the filtered list
            if (!filteredList.contains(this.selectionList.getSelected())) {
                this.selectionList.setSelected(filteredList.stream().findFirst().orElse(null));
            }
            return filteredList;
        });
    });
    // Add controls
    this.children.addAll(Arrays.asList(this.selectionList, this.contentPanel, this.searchField));
    // Add the 'Done' button
    this.addButton(new Button(this.width / 2 - 50, this.height - 40, 100, 20, new TranslatableComponent(I18n.get("gui.done")), (p_214323_1_) -> Minecraft.getInstance().setScreen(this.previousScreen)));
}
Also used : Arrays(java.util.Arrays) PluginSelectionList(org.spongepowered.vanilla.client.gui.widget.list.PluginSelectionList) Widget(net.minecraft.client.gui.components.Widget) Collection(java.util.Collection) Screen(net.minecraft.client.gui.screens.Screen) Launch(org.spongepowered.common.launch.Launch) ObjectArrayList(it.unimi.dsi.fastutil.objects.ObjectArrayList) MetadataPanel(org.spongepowered.vanilla.client.gui.widget.MetadataPanel) Collectors(java.util.stream.Collectors) PoseStack(com.mojang.blaze3d.vertex.PoseStack) TextComponent(net.minecraft.network.chat.TextComponent) List(java.util.List) I18n(net.minecraft.client.resources.language.I18n) PluginContainer(org.spongepowered.plugin.PluginContainer) PluginMetadata(org.spongepowered.plugin.metadata.PluginMetadata) Minecraft(net.minecraft.client.Minecraft) Locale(java.util.Locale) EditBox(net.minecraft.client.gui.components.EditBox) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Button(net.minecraft.client.gui.components.Button) PluginContainer(org.spongepowered.plugin.PluginContainer) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Button(net.minecraft.client.gui.components.Button) MetadataPanel(org.spongepowered.vanilla.client.gui.widget.MetadataPanel) EditBox(net.minecraft.client.gui.components.EditBox) PluginSelectionList(org.spongepowered.vanilla.client.gui.widget.list.PluginSelectionList)

Aggregations

PoseStack (com.mojang.blaze3d.vertex.PoseStack)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Minecraft (net.minecraft.client.Minecraft)2 Button (net.minecraft.client.gui.components.Button)2 EditBox (net.minecraft.client.gui.components.EditBox)2 Screen (net.minecraft.client.gui.screens.Screen)2 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)2 NativeImage (com.mojang.blaze3d.platform.NativeImage)1 RenderSystem (com.mojang.blaze3d.systems.RenderSystem)1 Tesselator (com.mojang.blaze3d.vertex.Tesselator)1 ObjectArrayList (it.unimi.dsi.fastutil.objects.ObjectArrayList)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Locale (java.util.Locale)1