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;
}
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;
}
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();
}
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));
}
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);
}
Aggregations