use of buildcraft.lib.gui.elem.ToolTip in project BuildCraft by BuildCraft.
the class GuiArchitectOld method initGui.
@SuppressWarnings("unchecked")
@Override
public void initGui() {
super.initGui();
Keyboard.enableRepeatEvents(true);
optionRotate = new GuiBetterButton(0, guiLeft + 5, guiTop + 30, 79, "");
buttonList.add(optionRotate);
optionExcavate = new GuiBetterButton(1, guiLeft + 5, guiTop + 55, 79, "");
buttonList.add(optionExcavate);
optionAllowCreative = new GuiBetterButton(2, guiLeft + 5, guiTop + 80, 79, "");
optionAllowCreative.setToolTip(new ToolTip(500, new ToolTipLine(LocaleUtil.localize("tile.architect.tooltip.allowCreative.1")), new ToolTipLine(LocaleUtil.localize("tile.architect.tooltip.allowCreative.2"))));
buttonList.add(optionAllowCreative);
textField = new GuiTextField(0, this.fontRendererObj, TEXT_X, TEXT_Y, TEXT_WIDTH, TEXT_HEIGHT);
textField.setMaxStringLength(DefaultProps.MAX_NAME_SIZE);
textField.setText(architect.name);
textField.setFocused(true);
updateButtons();
}
use of buildcraft.lib.gui.elem.ToolTip 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);
}
use of buildcraft.lib.gui.elem.ToolTip in project BuildCraft by BuildCraft.
the class GuiBuildCraft method drawToolTips.
private void drawToolTips(Collection<?> objects, int mouseX, int mouseY, int offsetX, int offsetY) {
for (Object obj : objects) {
if (!(obj instanceof IToolTipProvider)) {
continue;
}
IToolTipProvider provider = (IToolTipProvider) obj;
if (!provider.isToolTipVisible()) {
continue;
}
ToolTip tips = provider.getToolTip();
if (tips == null) {
continue;
}
boolean mouseOver = provider.isMouseOver(mouseX, mouseY);
tips.onTick(mouseOver);
if (mouseOver && tips.isReady()) {
tips.refresh();
drawToolTips(tips, mouseX + offsetX, mouseY + offsetY);
}
}
}
use of buildcraft.lib.gui.elem.ToolTip 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.elem.ToolTip in project BuildCraft by BuildCraft.
the class GuiUtil method createToolTip.
public static ToolTip createToolTip(Supplier<ItemStack> stackRef) {
return new ToolTip() {
@Override
public void refresh() {
delegate().clear();
ItemStack stack = stackRef.get();
if (!stack.isEmpty()) {
delegate().addAll(GuiUtil.getFormattedTooltip(stack));
}
}
};
}
Aggregations