Search in sources :

Example 1 with BoxElement

use of com.simibubi.create.foundation.gui.element.BoxElement in project Create by Creators-of-Create.

the class ConfirmationScreen method init.

@Override
protected void init() {
    super.init();
    ArrayList<FormattedText> copy = new ArrayList<>(text);
    text.clear();
    copy.forEach(t -> text.addAll(font.getSplitter().splitLines(t, 300, Style.EMPTY)));
    textHeight = text.size() * (font.lineHeight + 1) + 4;
    textWidth = 300;
    if (centered) {
        x = width / 2 - textWidth / 2 - 2;
        y = height / 2 - textHeight / 2 - 16;
    } else {
        x = Math.max(0, x - textWidth / 2);
        y = Math.max(0, y -= textHeight);
    }
    if (x + textWidth > width) {
        x = width - textWidth;
    }
    if (y + textHeight + 30 > height) {
        y = height - textHeight - 30;
    }
    int buttonX = x + textWidth / 2 - 6 - (int) (70 * (tristate ? 1.5f : 1));
    TextStencilElement confirmText = new TextStencilElement(font, tristate ? "Save" : "Confirm").centered(true, true);
    confirm = new BoxWidget(buttonX, y + textHeight + 6, 70, 16).withCallback(() -> accept(Response.Confirm));
    confirm.showingElement(confirmText.withElementRenderer(BoxWidget.gradientFactory.apply(confirm)));
    addRenderableWidget(confirm);
    buttonX += 12 + 70;
    if (tristate) {
        TextStencilElement confirmDontSaveText = new TextStencilElement(font, "Don't Save").centered(true, true);
        confirmDontSave = new BoxWidget(buttonX, y + textHeight + 6, 70, 16).withCallback(() -> accept(Response.ConfirmDontSave));
        confirmDontSave.showingElement(confirmDontSaveText.withElementRenderer(BoxWidget.gradientFactory.apply(confirmDontSave)));
        addRenderableWidget(confirmDontSave);
        buttonX += 12 + 70;
    }
    TextStencilElement cancelText = new TextStencilElement(font, "Cancel").centered(true, true);
    cancel = new BoxWidget(buttonX, y + textHeight + 6, 70, 16).withCallback(() -> accept(Response.Cancel));
    cancel.showingElement(cancelText.withElementRenderer(BoxWidget.gradientFactory.apply(cancel)));
    addRenderableWidget(cancel);
    textBackground = new BoxElement().gradientBorder(Theme.p(Theme.Key.BUTTON_DISABLE)).withBounds(width + 10, textHeight + 35).at(-5, y - 5);
    if (text.size() == 1)
        x = (width - font.width(text.get(0))) / 2;
}
Also used : BoxWidget(com.simibubi.create.foundation.gui.widget.BoxWidget) BoxElement(com.simibubi.create.foundation.gui.element.BoxElement) ArrayList(java.util.ArrayList) TextStencilElement(com.simibubi.create.foundation.gui.element.TextStencilElement) FormattedText(net.minecraft.network.chat.FormattedText)

Example 2 with BoxElement

use of com.simibubi.create.foundation.gui.element.BoxElement in project Create by Creators-of-Create.

the class PonderProgressBar method renderButton.

@Override
public void renderButton(@Nonnull PoseStack ms, int mouseX, int mouseY, float partialTicks) {
    isHovered = clicked(mouseX, mouseY);
    new BoxElement().withBackground(Theme.c(Theme.Key.PONDER_BACKGROUND_FLAT)).gradientBorder(Theme.p(Theme.Key.PONDER_IDLE)).at(x, y, 300).withBounds(width, height).render(ms);
    ms.pushPose();
    ms.translate(x - 2, y - 2, 200);
    ms.pushPose();
    ms.scale((width + 4) * progress.getValue(partialTicks), 1, 1);
    int c1 = Theme.i(Theme.Key.PONDER_PROGRESSBAR, true);
    int c2 = Theme.i(Theme.Key.PONDER_PROGRESSBAR, false);
    GuiUtils.drawGradientRect(ms.last().pose(), 110, 0, 3, 1, 4, c1, c1);
    GuiUtils.drawGradientRect(ms.last().pose(), 110, 0, 4, 1, 5, c2, c2);
    ms.popPose();
    renderKeyframes(ms, mouseX, partialTicks);
    ms.popPose();
}
Also used : BoxElement(com.simibubi.create.foundation.gui.element.BoxElement)

Example 3 with BoxElement

use of com.simibubi.create.foundation.gui.element.BoxElement in project Create by Creators-of-Create.

the class TextWindowElement method render.

@Override
protected void render(PonderScene scene, PonderUI screen, PoseStack ms, float partialTicks, float fade) {
    if (bakedText == null)
        bakedText = textGetter.get();
    if (fade < 1 / 16f)
        return;
    Vec2 sceneToScreen = vec != null ? scene.getTransform().sceneToScreen(vec, partialTicks) : new Vec2(screen.width / 2, (screen.height - 200) / 2 + y - 8);
    float yDiff = (screen.height / 2f - sceneToScreen.y - 10) / 100f;
    int targetX = (int) (screen.width * Mth.lerp(yDiff * yDiff, 6f / 8, 5f / 8));
    if (nearScene)
        targetX = (int) Math.min(targetX, sceneToScreen.x + 50);
    int textWidth = Math.min(screen.width - targetX, 180);
    List<FormattedText> lines = screen.getFontRenderer().getSplitter().splitLines(bakedText, textWidth, Style.EMPTY);
    int boxWidth = 0;
    for (FormattedText line : lines) boxWidth = Math.max(boxWidth, screen.getFontRenderer().width(line));
    int boxHeight = screen.getFontRenderer().wordWrapHeight(bakedText, boxWidth);
    ms.pushPose();
    ms.translate(0, sceneToScreen.y, 400);
    new BoxElement().withBackground(Theme.c(Theme.Key.PONDER_BACKGROUND_FLAT)).gradientBorder(Theme.p(Theme.Key.TEXT_WINDOW_BORDER)).at(targetX - 10, 3, 100).withBounds(boxWidth, boxHeight - 1).render(ms);
    // PonderUI.renderBox(ms, targetX - 10, 3, boxWidth, boxHeight - 1, 0xaa000000, 0x30eebb00, 0x10eebb00);
    int brighterColor = Color.mixColors(color, 0xFFffffdd, 1 / 2f);
    if (vec != null) {
        ms.pushPose();
        ms.translate(sceneToScreen.x, 0, 0);
        double lineTarget = (targetX - sceneToScreen.x) * fade;
        ms.scale((float) lineTarget, 1, 1);
        Matrix4f model = ms.last().pose();
        GuiUtils.drawGradientRect(model, -100, 0, 0, 1, 1, brighterColor, brighterColor);
        GuiUtils.drawGradientRect(model, -100, 0, 1, 1, 2, 0xFF494949, 0xFF393939);
        ms.popPose();
    }
    ms.translate(0, 0, 400);
    for (int i = 0; i < lines.size(); i++) {
        screen.getFontRenderer().draw(ms, lines.get(i).getString(), targetX - 10, 3 + 9 * i, new Color(brighterColor).scaleAlpha(fade).getRGB());
    }
    ms.popPose();
}
Also used : Matrix4f(com.mojang.math.Matrix4f) BoxElement(com.simibubi.create.foundation.gui.element.BoxElement) Vec2(net.minecraft.world.phys.Vec2) Color(com.simibubi.create.foundation.utility.Color) FormattedText(net.minecraft.network.chat.FormattedText)

Example 4 with BoxElement

use of com.simibubi.create.foundation.gui.element.BoxElement in project Create by Creators-of-Create.

the class EnumEntry method render.

@Override
public void render(PoseStack ms, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean p_230432_9_, float partialTicks) {
    super.render(ms, index, y, x, width, height, mouseX, mouseY, p_230432_9_, partialTicks);
    cycleLeft.x = x + getLabelWidth(width) + 4;
    cycleLeft.y = y + 10;
    cycleLeft.render(ms, mouseX, mouseY, partialTicks);
    valueText.at(cycleLeft.x + cycleWidth - 8, y + 10, 200).withBounds(width - getLabelWidth(width) - 2 * cycleWidth - resetWidth - 4, 16).render(ms);
    cycleRight.x = x + width - cycleWidth * 2 - resetWidth + 10;
    cycleRight.y = y + 10;
    cycleRight.render(ms, mouseX, mouseY, partialTicks);
    new BoxElement().withBackground(Theme.c(Theme.Key.PONDER_BACKGROUND_FLAT)).flatBorder(0x01_000000).withBounds(48, 6).at(cycleLeft.x + 22, cycleLeft.y + 5).render(ms);
}
Also used : BoxElement(com.simibubi.create.foundation.gui.element.BoxElement)

Aggregations

BoxElement (com.simibubi.create.foundation.gui.element.BoxElement)4 FormattedText (net.minecraft.network.chat.FormattedText)2 Matrix4f (com.mojang.math.Matrix4f)1 TextStencilElement (com.simibubi.create.foundation.gui.element.TextStencilElement)1 BoxWidget (com.simibubi.create.foundation.gui.widget.BoxWidget)1 Color (com.simibubi.create.foundation.utility.Color)1 ArrayList (java.util.ArrayList)1 Vec2 (net.minecraft.world.phys.Vec2)1