use of buildcraft.lib.gui.pos.IGuiArea in project BuildCraft by BuildCraft.
the class ElementType method resolveArea.
public static IGuiArea resolveArea(JsonGuiElement json, String name, IGuiPosition parent, FunctionContext ctx) {
String eqn = json.properties.get(name);
if (eqn == null) {
INodeDouble x = getEquationDouble(json, name + "[0]", ctx);
INodeDouble y = getEquationDouble(json, name + "[1]", ctx);
INodeDouble w = getEquationDouble(json, name + "[2]", ctx);
INodeDouble h = getEquationDouble(json, name + "[3]", ctx);
return IGuiArea.create(x, y, w, h).offset(parent);
}
try {
return GenericExpressionCompiler.compileExpressionObject(IGuiArea.class, eqn, ctx).evaluate();
} catch (InvalidExpressionException e) {
throw new JsonSyntaxException("Failed to resolve an area for " + json.fullName, e);
}
}
use of buildcraft.lib.gui.pos.IGuiArea in project BuildCraft by BuildCraft.
the class ElementTypeContainer method deserialize0.
@Override
protected IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
FunctionContext ctx = createContext(json);
boolean scissor = resolveEquationBool(json, "limit", ctx, false);
if (scissor) {
IGuiArea area = resolveArea(json, "area", parent, ctx);
return new GuiElementContainerScissor(gui, area);
} else {
IGuiPosition pos = resolvePosition(json, "pos", parent, ctx);
return new GuiElementContainerResizing(gui, pos);
}
}
use of buildcraft.lib.gui.pos.IGuiArea in project BuildCraft by BuildCraft.
the class GuiGuide method drawOpen.
private void drawOpen(float partialTicks) {
// Draw the pages
mc.renderEngine.bindTexture(LEFT_PAGE);
PAGE_LEFT.drawAt(minX, minY);
mc.renderEngine.bindTexture(RIGHT_PAGE);
PAGE_RIGHT.drawAt(minX + PAGE_LEFT.width, minY);
isOverHover = PEN_HIDDEN_AREA.offset(minX, minY).contains(mouse);
// Now draw the actual contents of the book
String title = currentPage.getTitle();
if (title != null) {
int x = /* this.minX + */
(width - currentFont.getStringWidth(title)) / 2;
currentFont.drawString(title, x, minY + 12, 0);
}
tooltipStack = null;
tooltip.clear();
setupFontRenderer();
for (GuideChapter chapter : chapters) {
chapter.reset();
}
currentPage.renderFirstPage(minX + (int) PAGE_LEFT_TEXT.x, minY + (int) PAGE_LEFT_TEXT.y, (int) PAGE_LEFT_TEXT.width, (int) PAGE_LEFT_TEXT.height);
currentPage.renderSecondPage(minX + PAGE_LEFT.width + (int) PAGE_RIGHT_TEXT.x, minY + (int) PAGE_RIGHT_TEXT.y, (int) PAGE_RIGHT_TEXT.width, (int) PAGE_RIGHT_TEXT.height);
int chapterIndex = 0;
for (GuideChapter chapter : chapters) {
chapter.draw(chapterIndex, partialTicks);
chapterIndex++;
}
// Draw the back button if there are any pages on the stack
if (!pages.isEmpty()) {
GuiIcon icon = BACK;
IGuiArea position = BACK_POSITION.offset(minX, minY);
if (position.contains(mouse)) {
icon = BACK_HOVERED;
}
icon.drawAt(position);
}
// Reset the colour for the pen
GlStateManager.color(1, 1, 1);
// Draw the pen
if (isEditing) {
mc.renderEngine.bindTexture(ICONS_2);
if (isOverHover) {
PEN_UP.drawAt(mouse.getX() - PEN_UP.width / 2, mouse.getY() - PEN_UP.height);
} else {
PEN_ANGLED.drawAt(mouse.getX() - 2, mouse.getY() - PEN_ANGLED.height - 2);
}
} else {
int h = (int) (hoverStageLast * (1 - partialTicks) + hoverStageNext * partialTicks);
// Draw pen
mc.renderEngine.bindTexture(ICONS_2);
drawTexturedModalRect(minX + PAGE_LEFT.width - PEN_HIDDEN_WIDTH / 2, minY - h, PEN_HIDDEN_X, PEN_HIDDEN_Y, PEN_HIDDEN_WIDTH, h);
if (tooltipStack != null) {
renderToolTip(tooltipStack, (int) mouse.getX(), (int) mouse.getY());
} else if (!tooltip.isEmpty()) {
drawHoveringText(tooltip, (int) mouse.getX(), (int) mouse.getY());
}
}
}
use of buildcraft.lib.gui.pos.IGuiArea in project BuildCraft by BuildCraft.
the class ElementTypeHelp 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]
// - colour: The colour for the help element (overlay)
// - title: The name of the help element
@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
FunctionContext ctx = createContext(json);
String title = json.properties.get("title");
List<String> text = new ArrayList<>();
if (json.properties.containsKey("text[0]")) {
int i = 0;
while (true) {
String prop = json.properties.get("text[" + i + "]");
if (prop == null) {
break;
}
text.add(prop);
i++;
}
} else {
text.add(json.properties.getOrDefault("text", "ERROR: Help not given!"));
}
int colour = resolveEquationInt(json, "colour", ctx);
ElementHelpInfo help = new ElementHelpInfo(title, colour, text.toArray(new String[0]));
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 DummyHelpElement(area, help);
}
use of buildcraft.lib.gui.pos.IGuiArea 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));
}
Aggregations