Search in sources :

Example 1 with ISimpleDrawable

use of buildcraft.lib.gui.ISimpleDrawable in project BuildCraft by BuildCraft.

the class ElementTypeButton method deserialize0.

@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    // TODO: Find a sane way of making the position variable!
    inheritProperty(json, "area[0]", "pos[0]");
    inheritProperty(json, "area[1]", "pos[1]");
    inheritProperty(json, "area[2]", "size[0]");
    inheritProperty(json, "area[3]", "size[1]");
    inheritProperty(json, "size[0]", "modes.enabled[2]");
    inheritProperty(json, "size[1]", "modes.enabled[3]");
    inheritProperty(json, "sprite", "modes.enabled.sprite");
    inheritProperty(json, "texture", "modes.enabled.texture");
    inheritProperty(json, "size[0]", "modes.disabled[2]");
    inheritProperty(json, "size[1]", "modes.disabled[3]");
    inheritProperty(json, "sprite", "modes.disabled.sprite");
    inheritProperty(json, "texture", "modes.disabled.texture");
    inheritProperty(json, "size[0]", "modes.active[2]");
    inheritProperty(json, "size[1]", "modes.active[3]");
    inheritProperty(json, "sprite", "modes.active.sprite");
    inheritProperty(json, "texture", "modes.active.texture");
    inheritProperty(json, "size[0]", "modes.hovered[2]");
    inheritProperty(json, "size[1]", "modes.hovered[3]");
    inheritProperty(json, "sprite", "modes.hovered.sprite");
    inheritProperty(json, "texture", "modes.hovered.texture");
    inheritProperty(json, "size[0]", "modes.active_hovered[2]");
    inheritProperty(json, "size[1]", "modes.active_hovered[3]");
    inheritProperty(json, "sprite", "modes.active_hovered.sprite");
    inheritProperty(json, "texture", "modes.active_hovered.texture");
    int posX = resolveEquationInt(json, "pos[0]", ctx);
    int posY = resolveEquationInt(json, "pos[1]", ctx);
    int sizeX = resolveEquationInt(json, "size[0]", ctx);
    int sizeY = resolveEquationInt(json, "size[1]", ctx);
    String buttonId;
    if (json.properties.containsKey("button")) {
        buttonId = json.properties.get("button");
    } else {
        buttonId = resolveEquation(json, "button_expression", ctx);
    }
    ISimpleDrawable drEnabled = resolveDrawable(ctx, info, json, gui, sizeX, sizeY, "modes.enabled");
    GuiRectangle rect = new GuiRectangle(posX, posY, sizeX, sizeY);
    GuiButtonDrawable.Builder buttonBuilder = new GuiButtonDrawable.Builder(rect, drEnabled);
    buttonBuilder.active = resolveDrawable(ctx, info, json, gui, sizeX, sizeY, "modes.active");
    buttonBuilder.hovered = resolveDrawable(ctx, info, json, gui, sizeX, sizeY, "modes.hovered");
    buttonBuilder.activeHovered = resolveDrawable(ctx, info, json, gui, sizeX, sizeY, "modes.active_hovered");
    buttonBuilder.disabled = resolveDrawable(ctx, info, json, gui, sizeX, sizeY, "modes.disabled");
    buttonBuilder.disabledActive = resolveDrawable(ctx, info, json, gui, sizeX, sizeY, "modes.active_disabled");
    GuiButtonDrawable button = new GuiButtonDrawable(gui, json.name, parent, buttonBuilder);
    IButtonBehaviour behaviour = gui.properties.get(buttonId, IButtonBehaviour.class);
    if (behaviour != null) {
        button.setBehaviour(behaviour);
    }
    Boolean current = gui.properties.get(buttonId, Boolean.class);
    if (current != null) {
        button.setActive(current.booleanValue());
    }
    IButtonClickEventListener listener = gui.properties.get(buttonId, IButtonClickEventListener.class);
    if (listener == null) {
        BCLog.logger.warn("[lib.gui.json] Unknown button id '" + buttonId + "'");
    } else {
        button.registerListener(listener);
    }
    return button;
}
Also used : IButtonClickEventListener(buildcraft.lib.gui.button.IButtonClickEventListener) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) IButtonBehaviour(buildcraft.lib.gui.button.IButtonBehaviour) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) GuiButtonDrawable(buildcraft.lib.gui.button.GuiButtonDrawable) FunctionContext(buildcraft.lib.expression.FunctionContext)

Example 2 with ISimpleDrawable

use of buildcraft.lib.gui.ISimpleDrawable in project BuildCraft by BuildCraft.

the class GuidePart method renderLine.

/**
 * @param current The current location of the rendering. This will be different from start if this line needed to
 *            render over 2 (or more!) pages
 * @param line The line to render
 * @param x The x position the page rendering started from
 * @param y The y position the page rendering started from
 * @param width The width of rendering space available
 * @param height The height of rendering space available
 * @return The position for the next line to render at. Will automatically be the next page or line if necessary.
 */
protected PagePosition renderLine(PagePosition current, PageLine line, int x, int y, int width, int height, int pageRenderIndex) {
    wasHovered = false;
    wasIconHovered = false;
    // Firstly break off the last chunk if the total length is greater than the width allows
    int allowedWidth = width - INDENT_WIDTH * line.indent;
    if (allowedWidth <= 0) {
        throw new IllegalStateException("Was indented too far");
    }
    String toRender = line.text;
    ISimpleDrawable icon = line.startIcon;
    FormatString next = FormatString.split(line.text);
    int neededSpace = fontRenderer.getFontHeight(line.text);
    if (icon != null) {
        neededSpace = Math.max(16, neededSpace);
    }
    current = current.guaranteeSpace(neededSpace, height);
    int _x = x + INDENT_WIDTH * line.indent;
    if (icon != null && current.page == pageRenderIndex) {
        int iconX = _x - 18;
        int iconY = y + current.pixel - 5;
        GuiRectangle rect = new GuiRectangle(iconX, iconY, 16, 16);
        if (rect.contains(gui.mouse) && line.startIconHovered != null) {
            icon = line.startIconHovered;
        }
        icon.drawAt(iconX, iconY);
    }
    while (next != null) {
        FormatString[] strings = next.wrap(fontRenderer, allowedWidth);
        String text = strings[0].getFormatted();
        boolean render = current.page == pageRenderIndex;
        int _y = y + current.pixel;
        int _w = fontRenderer.getStringWidth(text);
        GuiRectangle rect = new GuiRectangle(_x, _y, _w, neededSpace);
        wasHovered |= rect.contains(gui.mouse);
        if (render) {
            if (wasHovered && line.link) {
                Gui.drawRect(_x - 2, _y - 2, _x + _w + 2, _y - 2 + neededSpace, 0xFFD3AD6C);
            }
            fontRenderer.drawString(text, _x, _y, 0);
        }
        next = strings.length == 1 ? null : strings[1];
        current = current.nextLine(fontRenderer.getFontHeight(text) + 3, height);
    }
    int additional = LINE_HEIGHT - fontRenderer.getFontHeight(toRender) - 3;
    current = current.nextLine(additional, height);
    return current;
}
Also used : ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) FormatString(buildcraft.lib.client.guide.node.FormatString) FormatString(buildcraft.lib.client.guide.node.FormatString)

Example 3 with ISimpleDrawable

use of buildcraft.lib.gui.ISimpleDrawable 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();
}
Also used : SuffixArray(net.minecraft.client.util.SuffixArray) GuideManager(buildcraft.lib.client.guide.GuideManager) GuidePage(buildcraft.lib.client.guide.parts.GuidePage) Title(buildcraft.lib.client.guide.parts.contents.ContentsList.Title) GuiElementStatementSource(buildcraft.lib.gui.statement.GuiElementStatementSource) Item(net.minecraft.item.Item) TypeOrder(buildcraft.lib.client.guide.TypeOrder) SubHeader(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader) HashSet(java.util.HashSet) PageLinkNormal(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader.PageLinkNormal) GuiIcon(buildcraft.lib.gui.GuiIcon) ItemStack(net.minecraft.item.ItemStack) ImmutableList(com.google.common.collect.ImmutableList) StatementManager(buildcraft.api.statements.StatementManager) Locale(java.util.Locale) IAction(buildcraft.api.statements.IAction) GuideChapter(buildcraft.lib.client.guide.parts.GuideChapter) BCLib(buildcraft.lib.BCLib) CreativeTabs(net.minecraft.creativetab.CreativeTabs) NonNullList(net.minecraft.util.NonNullList) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) PageEntry(buildcraft.lib.client.guide.PageEntry) PageLinkGenerated(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader.PageLinkGenerated) GuiTextField(net.minecraft.client.gui.GuiTextField) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) GlStateManager(net.minecraft.client.renderer.GlStateManager) TextFormatting(net.minecraft.util.text.TextFormatting) ItemStackValueFilter(buildcraft.lib.client.guide.loader.entry.ItemStackValueFilter) GuidePageFactory(buildcraft.lib.client.guide.parts.GuidePageFactory) Set(java.util.Set) IOException(java.io.IOException) LocaleUtil(buildcraft.lib.misc.LocaleUtil) PageLine(buildcraft.lib.client.guide.PageLine) XmlPageLoader(buildcraft.lib.client.guide.loader.XmlPageLoader) ConfigurableFontRenderer(buildcraft.lib.client.render.font.ConfigurableFontRenderer) Collectors(java.util.stream.Collectors) GuiGuide(buildcraft.lib.client.guide.GuiGuide) IFontRenderer(buildcraft.lib.client.guide.font.IFontRenderer) RenderUtil(buildcraft.lib.misc.RenderUtil) List(java.util.List) TreeMap(java.util.TreeMap) FontRenderer(net.minecraft.client.gui.FontRenderer) IStatement(buildcraft.api.statements.IStatement) GuidePageBase(buildcraft.lib.client.guide.parts.GuidePageBase) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) GuideText(buildcraft.lib.client.guide.parts.GuideText) ITrigger(buildcraft.api.statements.ITrigger) PageLink(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader.PageLink) GuideText(buildcraft.lib.client.guide.parts.GuideText) TypeOrder(buildcraft.lib.client.guide.TypeOrder) Item(net.minecraft.item.Item) PageLine(buildcraft.lib.client.guide.PageLine) SubHeader(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader) HashSet(java.util.HashSet) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) IAction(buildcraft.api.statements.IAction) GuidePage(buildcraft.lib.client.guide.parts.GuidePage) Title(buildcraft.lib.client.guide.parts.contents.ContentsList.Title) ITrigger(buildcraft.api.statements.ITrigger) ItemStackValueFilter(buildcraft.lib.client.guide.loader.entry.ItemStackValueFilter) PageLinkGenerated(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader.PageLinkGenerated) GuidePageFactory(buildcraft.lib.client.guide.parts.GuidePageFactory) ItemStack(net.minecraft.item.ItemStack) IStatement(buildcraft.api.statements.IStatement) PageLinkNormal(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader.PageLinkNormal)

Example 4 with ISimpleDrawable

use of buildcraft.lib.gui.ISimpleDrawable in project BuildCraft by BuildCraft.

the class GuiEmzuliPipe_BC8 method addButton.

private void addButton(SlotIndex index, int x, int y) {
    Supplier<EnumDyeColor> getter = () -> container.behaviour.slotColours.get(index);
    Consumer<EnumDyeColor> setter = c -> container.paintWidgets.get(index).setColour(c);
    IGuiPosition elem = mainGui.rootElement.offset(x, y);
    GuiButtonDrawable button = new GuiButtonDrawable(mainGui, index.name(), elem, PAINT_BUTTON_BUILDER);
    button.registerListener((b, key) -> {
        final EnumDyeColor old = getter.get();
        EnumDyeColor nColour;
        switch(key) {
            case 0:
                {
                    nColour = ColourUtil.getNextOrNull(old);
                    break;
                }
            case 1:
                {
                    nColour = ColourUtil.getPrevOrNull(old);
                    break;
                }
            case 2:
                {
                    nColour = null;
                    break;
                }
            default:
                {
                    return;
                }
        }
        setter.accept(nColour);
    });
    mainGui.shownElements.add(button);
    // Button paintbrush
    IGuiArea area = new GuiRectangle(20, 20).offset(elem);
    ISimpleDrawable paintIcon = (px, py) -> {
        EnumDyeColor colour = getter.get();
        if (colour == null) {
            ICON_NO_PAINT.drawAt(px + 2, py + 2);
        } else {
            ISprite sprite = BCTransportSprites.ACTION_PIPE_COLOUR[colour.ordinal()];
            GuiIcon.drawAt(sprite, px + 2, py + 2, 16);
        }
    };
    mainGui.shownElements.add(new GuiElementDrawable(mainGui, area, paintIcon, false));
    ITooltipElement tooltips = list -> {
        EnumDyeColor colour = getter.get();
        String line;
        if (colour == null) {
            line = LocaleUtil.localize("gui.pipes.emzuli.nopaint");
        } else {
            line = LocaleUtil.localize("gui.pipes.emzuli.paint", ColourUtil.getTextFullTooltip(colour));
        }
        list.add(new ToolTip(line));
    };
    mainGui.shownElements.add(new GuiElementToolTip(mainGui, area, tooltips));
}
Also used : ITooltipElement(buildcraft.lib.gui.ITooltipElement) Supplier(java.util.function.Supplier) ISprite(buildcraft.api.core.render.ISprite) GuiIcon(buildcraft.lib.gui.GuiIcon) SlotIndex(buildcraft.transport.pipe.behaviour.PipeBehaviourEmzuli.SlotIndex) GuiBC8(buildcraft.lib.gui.GuiBC8) GuiElementDrawable(buildcraft.lib.gui.elem.GuiElementDrawable) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) BCLibSprites(buildcraft.lib.BCLibSprites) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) GuiElementToolTip(buildcraft.lib.gui.GuiElementToolTip) BCTransportSprites(buildcraft.transport.BCTransportSprites) LocaleUtil(buildcraft.lib.misc.LocaleUtil) PipeBehaviourEmzuli(buildcraft.transport.pipe.behaviour.PipeBehaviourEmzuli) Consumer(java.util.function.Consumer) ToolTip(buildcraft.lib.gui.elem.ToolTip) EnumDyeColor(net.minecraft.item.EnumDyeColor) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ResourceLocation(net.minecraft.util.ResourceLocation) ColourUtil(buildcraft.lib.misc.ColourUtil) ContainerEmzuliPipe_BC8(buildcraft.transport.container.ContainerEmzuliPipe_BC8) BCCoreSprites(buildcraft.core.BCCoreSprites) GuiButtonDrawable(buildcraft.lib.gui.button.GuiButtonDrawable) IGuiArea(buildcraft.lib.gui.pos.IGuiArea) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition) GuiElementToolTip(buildcraft.lib.gui.GuiElementToolTip) ToolTip(buildcraft.lib.gui.elem.ToolTip) IGuiArea(buildcraft.lib.gui.pos.IGuiArea) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) ITooltipElement(buildcraft.lib.gui.ITooltipElement) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) ISprite(buildcraft.api.core.render.ISprite) GuiButtonDrawable(buildcraft.lib.gui.button.GuiButtonDrawable) GuiElementDrawable(buildcraft.lib.gui.elem.GuiElementDrawable) EnumDyeColor(net.minecraft.item.EnumDyeColor) GuiElementToolTip(buildcraft.lib.gui.GuiElementToolTip) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition)

Example 5 with ISimpleDrawable

use of buildcraft.lib.gui.ISimpleDrawable in project BuildCraft by BuildCraft.

the class ElementTypeDrawnStack method deserialize0.

@Override
protected IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    IGuiPosition pos = resolvePosition(json, "pos", parent, ctx);
    INodeBoolean visible = getEquationBool(json, "visible", ctx, true);
    boolean foreground = resolveEquationBool(json, "foreground", ctx, false);
    Item item = JsonUtils.getItem(json.json, "id");
    int meta = resolveEquationInt(json, "meta", ctx);
    ItemStack stack = new ItemStack(item, 1, meta);
    ISimpleDrawable icon = new GuiStack(stack);
    IGuiArea area = IGuiArea.create(pos, 16, 16);
    return new GuiElementDrawable(gui, area, icon, foreground, visible);
}
Also used : Item(net.minecraft.item.Item) IGuiArea(buildcraft.lib.gui.pos.IGuiArea) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) GuiElementDrawable(buildcraft.lib.gui.elem.GuiElementDrawable) INodeBoolean(buildcraft.lib.expression.api.IExpressionNode.INodeBoolean) ItemStack(net.minecraft.item.ItemStack) GuiStack(buildcraft.lib.gui.GuiStack) FunctionContext(buildcraft.lib.expression.FunctionContext) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition)

Aggregations

ISimpleDrawable (buildcraft.lib.gui.ISimpleDrawable)6 GuiRectangle (buildcraft.lib.gui.pos.GuiRectangle)5 FunctionContext (buildcraft.lib.expression.FunctionContext)3 GuiElementDrawable (buildcraft.lib.gui.elem.GuiElementDrawable)3 IGuiArea (buildcraft.lib.gui.pos.IGuiArea)3 ISprite (buildcraft.api.core.render.ISprite)2 INodeBoolean (buildcraft.lib.expression.api.IExpressionNode.INodeBoolean)2 GuiIcon (buildcraft.lib.gui.GuiIcon)2 IGuiPosition (buildcraft.lib.gui.pos.IGuiPosition)2 LocaleUtil (buildcraft.lib.misc.LocaleUtil)2 Item (net.minecraft.item.Item)2 ItemStack (net.minecraft.item.ItemStack)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 IAction (buildcraft.api.statements.IAction)1 IStatement (buildcraft.api.statements.IStatement)1 ITrigger (buildcraft.api.statements.ITrigger)1 StatementManager (buildcraft.api.statements.StatementManager)1 BCCoreSprites (buildcraft.core.BCCoreSprites)1 BCLib (buildcraft.lib.BCLib)1 BCLibSprites (buildcraft.lib.BCLibSprites)1