use of buildcraft.lib.client.guide.PageEntry in project BuildCraft by BuildCraft.
the class GuidePageContents method loadMainGui.
public void loadMainGui() {
TypeOrder order = GuiGuide.SORTING_TYPES[gui.sortingOrderIndex];
contents.clear();
quickSearcher = new SuffixArray<>();
lastSearchText = "";
Set<Item> itemsAdded = new HashSet<>();
final String underline = TextFormatting.UNDERLINE.toString();
for (PageEntry<?> entry : GuideManager.INSTANCE.getAllEntries()) {
GuidePageFactory entryFactory = GuideManager.INSTANCE.getFactoryFor(entry);
String[] ordered = entry.typeTags.getOrdered(order);
String header = underline + LocaleUtil.localize(ordered[0]);
String subHeader = underline + LocaleUtil.localize(ordered[1]);
String translatedTitle = LocaleUtil.localize(entry.title);
ISimpleDrawable icon = entry.createDrawable();
PageLine line = new PageLine(icon, icon, 2, translatedTitle, true);
GuideText text = new GuideText(gui, line);
SubHeader pageHolder = contents.getOrAddSubHeader(header, subHeader);
if (entryFactory == null) {
if (entry.value instanceof ItemStackValueFilter) {
ItemStack stack = ((ItemStackValueFilter) entry.value).stack.baseStack;
itemsAdded.add(stack.getItem());
PageLinkGenerated pageLink = pageHolder.addKnownPage(text, stack);
if (pageLink != null) {
quickSearcher.add(pageLink, pageLink.joinedTooltip.toLowerCase(Locale.ROOT));
}
}
} else {
if (entry.value instanceof ItemStackValueFilter) {
ItemStack stack = ((ItemStackValueFilter) entry.value).stack.baseStack;
itemsAdded.add(stack.getItem());
}
PageLinkNormal pageLink = pageHolder.addNormalPage(text, entryFactory);
quickSearcher.add(pageLink, pageLink.getName().toLowerCase(Locale.ROOT));
}
}
String localizedGroup = underline + "\u0379" + LocaleUtil.localize("buildcraft.guide.contents.all_group");
String localizedItems = underline + LocaleUtil.localize("buildcraft.guide.contents.item_stacks");
Title allTitle = contents.getOrAddTitle(localizedGroup);
SubHeader allHolder = allTitle.getOrAddSubHeader(localizedItems);
for (Item item : ForgeRegistries.ITEMS) {
if (itemsAdded.contains(item)) {
continue;
}
NonNullList<ItemStack> stacks = NonNullList.create();
item.getSubItems(CreativeTabs.SEARCH, stacks);
for (int i = 0; i < stacks.size(); i++) {
ItemStack stack = stacks.get(i);
PageLinkGenerated pageLink = allHolder.addUnknownStack(stack);
if (pageLink != null) {
quickSearcher.add(pageLink, pageLink.joinedTooltip.toLowerCase(Locale.ROOT));
}
if (i > 50) {
// most likely the same item
break;
}
}
}
String localizedTriggers = underline + LocaleUtil.localize("buildcraft.guide.contents.triggers");
String localizedActions = underline + LocaleUtil.localize("buildcraft.guide.contents.actions");
SubHeader triggers = allTitle.getOrAddSubHeader(localizedTriggers);
SubHeader actions = allTitle.getOrAddSubHeader(localizedActions);
Set<IStatement> added = new HashSet<>();
for (IStatement statement : new TreeMap<>(StatementManager.statements).values()) {
if (!added.add(statement)) {
continue;
}
if (GuideManager.INSTANCE.getEntryFor(statement) != null) {
continue;
}
ISimpleDrawable icon = (x, y) -> GuiElementStatementSource.drawGuiSlot(statement, x, y);
List<String> tooltip = statement.getTooltip();
String title = tooltip.isEmpty() ? statement.getUniqueTag() : tooltip.get(0);
GuideText text = new GuideText(gui, new PageLine(icon, icon, 2, title, true));
final PageLinkNormal pageLink;
if (statement instanceof ITrigger) {
pageLink = triggers.addUnknownPage(text, g -> new GuidePage(gui, ImmutableList.of(), title));
} else if (statement instanceof IAction) {
pageLink = actions.addUnknownPage(text, g -> new GuidePage(gui, ImmutableList.of(), title));
} else {
pageLink = null;
}
if (pageLink != null) {
String joinedTooltip = tooltip.stream().collect(Collectors.joining(" ", "", ""));
String searchSr = statement.getUniqueTag() + " " + joinedTooltip;
quickSearcher.add(pageLink, searchSr.toLowerCase(Locale.ROOT));
}
}
quickSearcher.generate();
contents.sortAll();
}
Aggregations