use of buildcraft.lib.gui.pos.IGuiPosition 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));
}
use of buildcraft.lib.gui.pos.IGuiPosition 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);
}
use of buildcraft.lib.gui.pos.IGuiPosition in project BuildCraft by BuildCraft.
the class GuiUtil method moveRectangleToCentre.
public static IGuiArea moveRectangleToCentre(GuiRectangle area) {
final double w = area.width;
final double h = area.height;
DoubleSupplier posX = () -> (AREA_WHOLE_SCREEN.getWidth() - w) / 2;
DoubleSupplier posY = () -> (AREA_WHOLE_SCREEN.getHeight() - h) / 2;
IGuiPosition position = IGuiPosition.create(posX, posY);
return IGuiArea.create(position, area.width, area.height);
}
use of buildcraft.lib.gui.pos.IGuiPosition in project BuildCraft by BuildCraft.
the class ElementTypeText method deserialize0.
// pos: the position of the text
// text: The text to be drawn. Will be localised first, and used as a fallback
// expression: A replacement for text -- uses an expression rather than as a literal.
// colour: Default colour to be drawn
// centered: If true then the text will be centered around pos
@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
FunctionContext ctx = createContext(json);
IGuiPosition pos = resolvePosition(json, "pos", parent, ctx);
INodeObject<String> text;
String prop;
if ((prop = json.properties.get("text")) != null) {
String localized = LocaleUtil.localize(prop);
text = new NodeConstantObject<>(String.class, localized);
} else if ((prop = json.properties.get("expression")) != null) {
try {
text = GenericExpressionCompiler.compileExpressionString(prop, ctx);
} catch (InvalidExpressionException e) {
throw new JsonSyntaxException("Invalid expression for '" + json.name + "'", e);
}
} else {
throw new JsonSyntaxException("Require either 'text' or 'expression'!");
}
int colour;
if (json.properties.containsKey("colour")) {
colour = resolveEquationInt(json, "colour", ctx);
} else {
colour = resolveEquationInt(json, "color", ctx);
}
GuiElementText element = new GuiElementText(gui, pos, text, colour);
element.setCentered("true".equals(json.properties.get("centered")));
element.setDropShadow("true".equals(json.properties.get("shadow")));
element.setForeground("true".equals(json.properties.get("foreground")));
return element;
}
Aggregations