use of org.spongepowered.vanilla.client.gui.widget.list.PluginSelectionList 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)));
}
Aggregations