Search in sources :

Example 1 with IGuiArea

use of buildcraft.lib.gui.pos.IGuiArea in project BuildCraft by BuildCraft.

the class GuiElementStatementVariant method create.

public static GuiElementStatementVariant create(BuildCraftGui gui, IGuiArea parent, IReference<? extends IGuiSlot> ref, IGuiSlot[] possible) {
    int count = Math.min(OFFSET_HOVER.length, possible.length);
    possible = possible.length == count ? possible : Arrays.copyOf(possible, count);
    IGuiArea[] posPossible = new IGuiArea[count];
    IGuiArea base = new GuiRectangle(18, 18).offset(parent);
    for (int i = 0; i < count; i++) {
        posPossible[i] = base.offset(OFFSET_HOVER[i][0] * 18, OFFSET_HOVER[i][1] * 18);
    }
    int sub = 18 * (count > 9 ? 2 : 1);
    int add = 18 * (count > 9 ? 3 : 1);
    int offset = -sub - 4;
    int size = 8 + add + 18 * 2;
    IGuiArea area = new GuiRectangle(offset, offset, size, size).offset(parent);
    return new GuiElementStatementVariant(gui, area, ref, possible, posPossible);
}
Also used : IGuiArea(buildcraft.lib.gui.pos.IGuiArea) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle)

Example 2 with IGuiArea

use of buildcraft.lib.gui.pos.IGuiArea in project BuildCraft by BuildCraft.

the class ElementTypeStatementSlot method deserialize0.

@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    if (!json.properties.containsKey("size[0]")) {
        json.properties.put("size[0]", "18");
    }
    if (!json.properties.containsKey("size[1]")) {
        json.properties.put("size[1]", "18");
    }
    inheritProperty(json, "pos[0]", "area[0]");
    inheritProperty(json, "pos[1]", "area[1]");
    inheritProperty(json, "size[0]", "area[2]");
    inheritProperty(json, "size[1]", "area[3]");
    IGuiArea area = resolveArea(json, "area", parent, ctx);
    String source;
    if (json.properties.containsKey("source")) {
        source = json.properties.get("source");
    } else {
        source = resolveEquation(json, "source_expression", ctx);
        if (source == null) {
            throw new JsonSyntaxException("Expected either 'source' or 'source_expression' for " + NAME);
        }
    }
    boolean draw = !"false".equals(json.properties.get("draw"));
    FullStatement<?> fullStatement = gui.properties.get(source, FullStatement.class);
    if (fullStatement == null) {
        throw new JsonSyntaxException("Can't find a statement called '" + source + "'");
    }
    StatementContext<?> context = gui.properties.get(source, StatementContext.class);
    return new GuiElementStatement<>(gui, area, fullStatement, context, draw);
}
Also used : IGuiArea(buildcraft.lib.gui.pos.IGuiArea) JsonSyntaxException(com.google.gson.JsonSyntaxException) FunctionContext(buildcraft.lib.expression.FunctionContext) GuiElementStatement(buildcraft.lib.gui.statement.GuiElementStatement)

Example 3 with IGuiArea

use of buildcraft.lib.gui.pos.IGuiArea in project BuildCraft by BuildCraft.

the class ElementTypeStatementParam method deserialize0.

@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    if (!json.properties.containsKey("size[0]")) {
        json.properties.put("size[0]", "18");
    }
    if (!json.properties.containsKey("size[1]")) {
        json.properties.put("size[1]", "18");
    }
    inheritProperty(json, "pos[0]", "area[0]");
    inheritProperty(json, "pos[1]", "area[1]");
    inheritProperty(json, "size[0]", "area[2]");
    inheritProperty(json, "size[1]", "area[3]");
    IGuiArea area = resolveArea(json, "area", parent, ctx);
    String source;
    if (json.properties.containsKey("source")) {
        source = json.properties.get("source");
    } else {
        source = resolveEquation(json, "source_expression", ctx);
        if (source == null) {
            throw new JsonSyntaxException("Expected either 'source' or 'source_expression' for " + NAME);
        }
    }
    boolean draw = !"false".equals(json.properties.get("draw"));
    int index = resolveEquationInt(json, "index", ctx);
    FullStatement<?> fullStatement = gui.properties.get(source, FullStatement.class);
    IStatementContainer statementContainer = gui.properties.get("statement.container", IStatementContainer.class);
    return new GuiElementStatementParam(gui, area, statementContainer, fullStatement, index, draw);
}
Also used : IGuiArea(buildcraft.lib.gui.pos.IGuiArea) JsonSyntaxException(com.google.gson.JsonSyntaxException) IStatementContainer(buildcraft.api.statements.IStatementContainer) GuiElementStatementParam(buildcraft.lib.gui.statement.GuiElementStatementParam) FunctionContext(buildcraft.lib.expression.FunctionContext)

Example 4 with IGuiArea

use of buildcraft.lib.gui.pos.IGuiArea in project BuildCraft by BuildCraft.

the class ElementTypeToolTip method deserialize0.

// Args:
// - pos[0], pos[1]: the area for help (where it will be drawn, relative to the root of the gui). Defaults
// to 0,0
// - size[0], size[1]: the size of the help area
// - area[0-3]: mapping for pos[0], pos[1], size[0], size[1]
// - text: The text to display in the tooltip
// - expression: The expression to display in the tooltip
@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    List<String> text = new ArrayList<>();
    String key = "text";
    boolean isExpression = false;
    if (json.properties.containsKey("expression") || json.properties.containsKey("expression[0]")) {
        key = "expression";
        isExpression = true;
    }
    if (json.properties.containsKey(key + "[0]")) {
        int i = 0;
        while (true) {
            String prop = json.properties.get(key + "[" + i + "]");
            if (prop == null) {
                break;
            }
            text.add(prop);
            i++;
        }
    } else {
        text.add(json.properties.getOrDefault(key, "ERROR: Text not given!"));
    }
    INodeBoolean visible = getEquationBool(json, "visible", ctx, true);
    ITooltipElement source;
    if (isExpression) {
        List<INodeObject<String>> nodes = new ArrayList<>(text.size());
        try {
            for (String s : text) {
                nodes.add(GenericExpressionCompiler.compileExpressionString(s, ctx));
            }
        } catch (InvalidExpressionException e) {
            throw new JsonSyntaxException(e);
        }
        source = (list) -> {
            if (visible.evaluate()) {
                String[] arr = new String[nodes.size()];
                for (int i = 0; i < arr.length; i++) {
                    arr[i] = nodes.get(i).evaluate();
                }
                list.add(ToolTip.createLocalized(arr));
            }
        };
    } else {
        ToolTip tooltip = ToolTip.createLocalized(text.toArray(new String[0]));
        source = (list) -> {
            if (visible.evaluate()) {
                list.add(tooltip);
            }
        };
    }
    inheritProperty(json, "pos[0]", "area[0]");
    inheritProperty(json, "pos[1]", "area[1]");
    inheritProperty(json, "size[0]", "area[2]");
    inheritProperty(json, "size[1]", "area[3]");
    IGuiArea area = resolveArea(json, "area", parent, ctx);
    return new GuiElementToolTip(gui, area, source);
}
Also used : GuiElementToolTip(buildcraft.lib.gui.GuiElementToolTip) ToolTip(buildcraft.lib.gui.elem.ToolTip) IGuiArea(buildcraft.lib.gui.pos.IGuiArea) ITooltipElement(buildcraft.lib.gui.ITooltipElement) ArrayList(java.util.ArrayList) INodeBoolean(buildcraft.lib.expression.api.IExpressionNode.INodeBoolean) FunctionContext(buildcraft.lib.expression.FunctionContext) JsonSyntaxException(com.google.gson.JsonSyntaxException) InvalidExpressionException(buildcraft.lib.expression.api.InvalidExpressionException) GuiElementToolTip(buildcraft.lib.gui.GuiElementToolTip) INodeObject(buildcraft.lib.expression.api.IExpressionNode.INodeObject)

Example 5 with IGuiArea

use of buildcraft.lib.gui.pos.IGuiArea in project BuildCraft by BuildCraft.

the class LedgerHelp method drawForeground.

@Override
public void drawForeground(float partialTicks) {
    super.drawForeground(partialTicks);
    if (!shouldDrawOpen()) {
        return;
    }
    boolean set = false;
    List<HelpPosition> elements = new ArrayList<>();
    for (IGuiElement element : gui.shownElements) {
        element.addHelpElements(elements);
        foundAny |= elements.size() > 0;
        for (HelpPosition info : elements) {
            IGuiArea rect = info.target;
            boolean isHovered = rect.contains(gui.mouse);
            if (isHovered) {
                if (selected != element && !set) {
                    selected = element;
                    GuiElementContainerHelp container = new GuiElementContainerHelp(gui, positionLedgerInnerStart);
                    info.info.addGuiElements(container);
                    if (openElements.size() == 2) {
                        openElements.remove(1);
                    }
                    openElements.add(container);
                    title = LocaleUtil.localize("gui.ledger.help") + ": " + LocaleUtil.localize(info.info.title);
                    calculateMaxSize();
                    set = true;
                }
            }
            boolean isSelected = selected == element;
            SpriteNineSliced split = SPRITE_HELP_SPLIT[isHovered ? 1 : 0][isSelected ? 1 : 0];
            RenderUtil.setGLColorFromInt(info.info.colour);
            split.draw(rect);
        }
        elements.clear();
    }
    GlStateManager.color(1, 1, 1);
}
Also used : HelpPosition(buildcraft.lib.gui.help.ElementHelpInfo.HelpPosition) IGuiArea(buildcraft.lib.gui.pos.IGuiArea) ArrayList(java.util.ArrayList) IGuiElement(buildcraft.lib.gui.IGuiElement) GuiElementContainerHelp(buildcraft.lib.gui.elem.GuiElementContainerHelp) SpriteNineSliced(buildcraft.lib.client.sprite.SpriteNineSliced)

Aggregations

IGuiArea (buildcraft.lib.gui.pos.IGuiArea)13 FunctionContext (buildcraft.lib.expression.FunctionContext)7 GuiRectangle (buildcraft.lib.gui.pos.GuiRectangle)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)4 INodeBoolean (buildcraft.lib.expression.api.IExpressionNode.INodeBoolean)3 ISimpleDrawable (buildcraft.lib.gui.ISimpleDrawable)3 GuiElementDrawable (buildcraft.lib.gui.elem.GuiElementDrawable)3 IGuiPosition (buildcraft.lib.gui.pos.IGuiPosition)3 ArrayList (java.util.ArrayList)3 ISprite (buildcraft.api.core.render.ISprite)2 INodeDouble (buildcraft.lib.expression.api.IExpressionNode.INodeDouble)2 InvalidExpressionException (buildcraft.lib.expression.api.InvalidExpressionException)2 GuiElementToolTip (buildcraft.lib.gui.GuiElementToolTip)2 GuiIcon (buildcraft.lib.gui.GuiIcon)2 IGuiElement (buildcraft.lib.gui.IGuiElement)2 ITooltipElement (buildcraft.lib.gui.ITooltipElement)2 ToolTip (buildcraft.lib.gui.elem.ToolTip)2 ItemStack (net.minecraft.item.ItemStack)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 IStatementContainer (buildcraft.api.statements.IStatementContainer)1