Search in sources :

Example 1 with TextStencilElement

use of com.simibubi.create.foundation.gui.element.TextStencilElement 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 TextStencilElement

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

the class BaseConfigScreen method init.

@Override
protected void init() {
    super.init();
    returnOnClose = true;
    TextStencilElement clientText = new TextStencilElement(font, new TextComponent(clientTile)).centered(true, true);
    addRenderableWidget(clientConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15 - 30, 200, 16).showingElement(clientText));
    if (clientSpec != null) {
        clientConfigWidget.withCallback(() -> linkTo(new SubMenuConfigScreen(this, ModConfig.Type.CLIENT, clientSpec)));
        clientText.withElementRenderer(BoxWidget.gradientFactory.apply(clientConfigWidget));
    } else {
        clientConfigWidget.active = false;
        clientConfigWidget.updateColorsFromState();
        clientText.withElementRenderer(DISABLED_RENDERER);
    }
    TextStencilElement commonText = new TextStencilElement(font, new TextComponent(commonTile)).centered(true, true);
    addRenderableWidget(commonConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15, 200, 16).showingElement(commonText));
    if (commonSpec != null) {
        commonConfigWidget.withCallback(() -> linkTo(new SubMenuConfigScreen(this, ModConfig.Type.COMMON, commonSpec)));
        commonText.withElementRenderer(BoxWidget.gradientFactory.apply(commonConfigWidget));
    } else {
        commonConfigWidget.active = false;
        commonConfigWidget.updateColorsFromState();
        commonText.withElementRenderer(DISABLED_RENDERER);
    }
    TextStencilElement serverText = new TextStencilElement(font, new TextComponent(serverTile)).centered(true, true);
    addRenderableWidget(serverConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15 + 30, 200, 16).showingElement(serverText));
    if (serverSpec == null) {
        serverConfigWidget.active = false;
        serverConfigWidget.updateColorsFromState();
        serverText.withElementRenderer(DISABLED_RENDERER);
    } else if (minecraft.level == null) {
        serverText.withElementRenderer(DISABLED_RENDERER);
        serverConfigWidget.getToolTip().add(new TextComponent("Stored individually per World"));
        serverConfigWidget.getToolTip().addAll(TooltipHelper.cutTextComponent(new TextComponent("Gameplay settings can only be accessed from the in-game menu after joining a World or Server."), ChatFormatting.GRAY, ChatFormatting.GRAY));
    } else {
        serverConfigWidget.withCallback(() -> linkTo(new SubMenuConfigScreen(this, ModConfig.Type.SERVER, serverSpec)));
        serverText.withElementRenderer(BoxWidget.gradientFactory.apply(serverConfigWidget));
    }
    TextStencilElement titleText = new TextStencilElement(font, modID.toUpperCase(Locale.ROOT)).centered(true, true).withElementRenderer((ms, w, h, alpha) -> {
        UIRenderHelper.angledGradient(ms, 0, 0, h / 2, h, w / 2, Theme.p(Theme.Key.CONFIG_TITLE_A));
        UIRenderHelper.angledGradient(ms, 0, w / 2, h / 2, h, w / 2, Theme.p(Theme.Key.CONFIG_TITLE_B));
    });
    int boxWidth = width + 10;
    int boxHeight = 39;
    int boxPadding = 4;
    title = new BoxWidget(-5, height / 2 - 110, boxWidth, boxHeight).withBorderColors(Theme.p(Theme.Key.BUTTON_IDLE)).withPadding(0, boxPadding).rescaleElement(boxWidth / 2f, // double the text size by telling it the element is only half as big as the available space
    (boxHeight - 2 * boxPadding) / 2f).showingElement(titleText.at(0, 7));
    title.active = false;
    addRenderableWidget(title);
    ConfigScreen.modID = this.modID;
    goBack = new BoxWidget(width / 2 - 134, height / 2, 20, 20).withPadding(2, 2).withCallback(() -> linkTo(parent));
    goBack.showingElement(AllIcons.I_CONFIG_BACK.asStencil().withElementRenderer(BoxWidget.gradientFactory.apply(goBack)));
    goBack.getToolTip().add(new TextComponent("Go Back"));
    addRenderableWidget(goBack);
    TextStencilElement othersText = new TextStencilElement(font, new TextComponent("Access Configs of other Mods")).centered(true, true);
    others = new BoxWidget(width / 2 - 100, height / 2 - 15 + 90, 200, 16).showingElement(othersText);
    othersText.withElementRenderer(BoxWidget.gradientFactory.apply(others));
    others.withCallback(() -> linkTo(new ConfigModListScreen(this)));
    addRenderableWidget(others);
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) BoxWidget(com.simibubi.create.foundation.gui.widget.BoxWidget) TextStencilElement(com.simibubi.create.foundation.gui.element.TextStencilElement)

Aggregations

TextStencilElement (com.simibubi.create.foundation.gui.element.TextStencilElement)2 BoxWidget (com.simibubi.create.foundation.gui.widget.BoxWidget)2 BoxElement (com.simibubi.create.foundation.gui.element.BoxElement)1 ArrayList (java.util.ArrayList)1 FormattedText (net.minecraft.network.chat.FormattedText)1 TextComponent (net.minecraft.network.chat.TextComponent)1