Search in sources :

Example 1 with MetadataPanel

use of org.spongepowered.vanilla.client.gui.widget.MetadataPanel 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)1 ObjectArrayList (it.unimi.dsi.fastutil.objects.ObjectArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Locale (java.util.Locale)1 Collectors (java.util.stream.Collectors)1 Minecraft (net.minecraft.client.Minecraft)1 Button (net.minecraft.client.gui.components.Button)1 EditBox (net.minecraft.client.gui.components.EditBox)1 Widget (net.minecraft.client.gui.components.Widget)1 Screen (net.minecraft.client.gui.screens.Screen)1 I18n (net.minecraft.client.resources.language.I18n)1 TextComponent (net.minecraft.network.chat.TextComponent)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1 Launch (org.spongepowered.common.launch.Launch)1 PluginContainer (org.spongepowered.plugin.PluginContainer)1 PluginMetadata (org.spongepowered.plugin.metadata.PluginMetadata)1 MetadataPanel (org.spongepowered.vanilla.client.gui.widget.MetadataPanel)1 PluginSelectionList (org.spongepowered.vanilla.client.gui.widget.list.PluginSelectionList)1