Search in sources :

Example 1 with BoxWidget

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

use of com.simibubi.create.foundation.gui.widget.BoxWidget in project Create by Creators-of-Create.

the class SubMenuConfigScreen method init.

@Override
protected void init() {
    super.init();
    listWidth = Math.min(width - 80, 300);
    int yCenter = height / 2;
    int listL = this.width / 2 - listWidth / 2;
    int listR = this.width / 2 + listWidth / 2;
    resetAll = new BoxWidget(listR + 10, yCenter - 25, 20, 20).withPadding(2, 2).withCallback((x, y) -> new ConfirmationScreen().centered().withText(FormattedText.of("Resetting all settings of the " + type.toString() + " config. Are you sure?")).withAction(success -> {
        if (success)
            resetConfig(spec.getValues());
    }).open(this));
    resetAll.showingElement(AllIcons.I_CONFIG_RESET.asStencil().withElementRenderer(BoxWidget.gradientFactory.apply(resetAll)));
    resetAll.getToolTip().add(new TextComponent("Reset All"));
    resetAll.getToolTip().addAll(TooltipHelper.cutStringTextComponent("Click here to reset all settings to their default value.", ChatFormatting.GRAY, ChatFormatting.GRAY));
    saveChanges = new BoxWidget(listL - 30, yCenter - 25, 20, 20).withPadding(2, 2).withCallback((x, y) -> {
        if (ConfigHelper.changes.isEmpty())
            return;
        ConfirmationScreen confirm = new ConfirmationScreen().centered().withText(FormattedText.of("Saving " + ConfigHelper.changes.size() + " changed value" + (ConfigHelper.changes.size() != 1 ? "s" : "") + "")).withAction(success -> {
            if (success)
                saveChanges();
        });
        addAnnotationsToConfirm(confirm).open(this);
    });
    saveChanges.showingElement(AllIcons.I_CONFIG_SAVE.asStencil().withElementRenderer(BoxWidget.gradientFactory.apply(saveChanges)));
    saveChanges.getToolTip().add(new TextComponent("Save Changes"));
    saveChanges.getToolTip().addAll(TooltipHelper.cutStringTextComponent("Click here to save your current changes.", ChatFormatting.GRAY, ChatFormatting.GRAY));
    discardChanges = new BoxWidget(listL - 30, yCenter + 5, 20, 20).withPadding(2, 2).withCallback((x, y) -> {
        if (ConfigHelper.changes.isEmpty())
            return;
        new ConfirmationScreen().centered().withText(FormattedText.of("Discarding " + ConfigHelper.changes.size() + " unsaved change" + (ConfigHelper.changes.size() != 1 ? "s" : "") + "")).withAction(success -> {
            if (success)
                clearChanges();
        }).open(this);
    });
    discardChanges.showingElement(AllIcons.I_CONFIG_DISCARD.asStencil().withElementRenderer(BoxWidget.gradientFactory.apply(discardChanges)));
    discardChanges.getToolTip().add(new TextComponent("Discard Changes"));
    discardChanges.getToolTip().addAll(TooltipHelper.cutStringTextComponent("Click here to discard all the changes you made.", ChatFormatting.GRAY, ChatFormatting.GRAY));
    goBack = new BoxWidget(listL - 30, yCenter + 65, 20, 20).withPadding(2, 2).withCallback(this::attemptBackstep);
    goBack.showingElement(AllIcons.I_CONFIG_BACK.asStencil().withElementRenderer(BoxWidget.gradientFactory.apply(goBack)));
    goBack.getToolTip().add(new TextComponent("Go Back"));
    addRenderableWidget(resetAll);
    addRenderableWidget(saveChanges);
    addRenderableWidget(discardChanges);
    addRenderableWidget(goBack);
    list = new ConfigScreenList(minecraft, listWidth, height - 80, 35, height - 45, 40);
    list.setLeftPos(this.width / 2 - list.getWidth() / 2);
    addRenderableWidget(list);
    search = new ConfigTextField(font, width / 2 - listWidth / 2, height - 35, listWidth, 20);
    search.setResponder(this::updateFilter);
    search.setHint("Search...");
    search.moveCursorToStart();
    addRenderableWidget(search);
    configGroup.valueMap().forEach((key, obj) -> {
        String humanKey = toHumanReadable(key);
        if (obj instanceof AbstractConfig) {
            SubMenuEntry entry = new SubMenuEntry(this, humanKey, spec, (UnmodifiableConfig) obj);
            entry.path = key;
            list.children().add(entry);
            if (configGroup.valueMap().size() == 1)
                ScreenOpener.open(new SubMenuConfigScreen(parent, humanKey, type, spec, (UnmodifiableConfig) obj));
        } else if (obj instanceof ForgeConfigSpec.ConfigValue<?>) {
            ForgeConfigSpec.ConfigValue<?> configValue = (ForgeConfigSpec.ConfigValue<?>) obj;
            ForgeConfigSpec.ValueSpec valueSpec = spec.getRaw(configValue.getPath());
            Object value = configValue.get();
            ConfigScreenList.Entry entry = null;
            if (value instanceof Boolean) {
                entry = new BooleanEntry(humanKey, (ForgeConfigSpec.ConfigValue<Boolean>) configValue, valueSpec);
            } else if (value instanceof Enum) {
                entry = new EnumEntry(humanKey, (ForgeConfigSpec.ConfigValue<Enum<?>>) configValue, valueSpec);
            } else if (value instanceof Number) {
                entry = NumberEntry.create(value, humanKey, configValue, valueSpec);
            }
            if (entry == null)
                entry = new LabeledEntry("Impl missing - " + configValue.get().getClass().getSimpleName() + "  " + humanKey + " : " + value);
            if (highlights.contains(key))
                entry.annotations.put("highlight", ":)");
            list.children().add(entry);
        }
    });
    Collections.sort(list.children(), (e, e2) -> {
        int group = (e2 instanceof SubMenuEntry ? 1 : 0) - (e instanceof SubMenuEntry ? 1 : 0);
        if (group == 0 && e instanceof LabeledEntry && e2 instanceof LabeledEntry) {
            LabeledEntry le = (LabeledEntry) e;
            LabeledEntry le2 = (LabeledEntry) e2;
            return le.label.getComponent().getString().compareTo(le2.label.getComponent().getString());
        }
        return group;
    });
    list.search(highlights.stream().findFirst().orElse(""));
    // extras for server configs
    if (type != ModConfig.Type.SERVER)
        return;
    if (minecraft.hasSingleplayerServer())
        return;
    boolean canEdit = minecraft != null && minecraft.player != null && minecraft.player.hasPermissions(2);
    Couple<Color> red = Theme.p(Theme.Key.BUTTON_FAIL);
    Couple<Color> green = Theme.p(Theme.Key.BUTTON_SUCCESS);
    DelegatedStencilElement stencil = new DelegatedStencilElement();
    serverLocked = new BoxWidget(listR + 10, yCenter + 5, 20, 20).withPadding(2, 2).showingElement(stencil);
    if (!canEdit) {
        list.children().forEach(e -> e.setEditable(false));
        resetAll.active = false;
        stencil.withStencilRenderer((ms, w, h, alpha) -> AllIcons.I_CONFIG_LOCKED.render(ms, 0, 0));
        stencil.withElementRenderer((ms, w, h, alpha) -> UIRenderHelper.angledGradient(ms, 90, 8, 0, 16, 16, red));
        serverLocked.withBorderColors(red);
        serverLocked.getToolTip().add(new TextComponent("Locked").withStyle(ChatFormatting.BOLD));
        serverLocked.getToolTip().addAll(TooltipHelper.cutStringTextComponent("You do not have enough permissions to edit the server config. You can still look at the current values here though.", ChatFormatting.GRAY, ChatFormatting.GRAY));
    } else {
        stencil.withStencilRenderer((ms, w, h, alpha) -> AllIcons.I_CONFIG_UNLOCKED.render(ms, 0, 0));
        stencil.withElementRenderer((ms, w, h, alpha) -> UIRenderHelper.angledGradient(ms, 90, 8, 0, 16, 16, green));
        serverLocked.withBorderColors(green);
        serverLocked.getToolTip().add(new TextComponent("Unlocked").withStyle(ChatFormatting.BOLD));
        serverLocked.getToolTip().addAll(TooltipHelper.cutStringTextComponent("You have enough permissions to edit the server config. Changes you make here will be synced with the server when you save them.", ChatFormatting.GRAY, ChatFormatting.GRAY));
    }
    addRenderableWidget(serverLocked);
}
Also used : AllPackets(com.simibubi.create.foundation.networking.AllPackets) Arrays(java.util.Arrays) ForgeConfigSpec(net.minecraftforge.common.ForgeConfigSpec) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ValueEntry(com.simibubi.create.foundation.config.ui.entries.ValueEntry) SubMenuEntry(com.simibubi.create.foundation.config.ui.entries.SubMenuEntry) AllIcons(com.simibubi.create.foundation.gui.AllIcons) ArrayList(java.util.ArrayList) PoseStack(com.mojang.blaze3d.vertex.PoseStack) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) ConfirmationScreen(com.simibubi.create.foundation.gui.ConfirmationScreen) EnumEntry(com.simibubi.create.foundation.config.ui.entries.EnumEntry) Minecraft(net.minecraft.client.Minecraft) Locale(java.util.Locale) ChatFormatting(net.minecraft.ChatFormatting) Map(java.util.Map) LabeledEntry(com.simibubi.create.foundation.config.ui.ConfigScreenList.LabeledEntry) AbstractConfig(com.electronwill.nightconfig.core.AbstractConfig) Nonnull(javax.annotation.Nonnull) BooleanEntry(com.simibubi.create.foundation.config.ui.entries.BooleanEntry) ScreenOpener(com.simibubi.create.foundation.gui.ScreenOpener) Nullable(javax.annotation.Nullable) TooltipHelper(com.simibubi.create.foundation.item.TooltipHelper) Color(com.simibubi.create.foundation.utility.Color) Theme(com.simibubi.create.foundation.gui.Theme) Response(com.simibubi.create.foundation.gui.ConfirmationScreen.Response) Screen(net.minecraft.client.gui.screens.Screen) Set(java.util.Set) DelegatedStencilElement(com.simibubi.create.foundation.gui.element.DelegatedStencilElement) UIRenderHelper(com.simibubi.create.foundation.gui.UIRenderHelper) Pair(com.simibubi.create.foundation.utility.Pair) GLFW(org.lwjgl.glfw.GLFW) Consumer(java.util.function.Consumer) NumberEntry(com.simibubi.create.foundation.config.ui.entries.NumberEntry) GuiEventListener(net.minecraft.client.gui.components.events.GuiEventListener) List(java.util.List) TextComponent(net.minecraft.network.chat.TextComponent) BoxWidget(com.simibubi.create.foundation.gui.widget.BoxWidget) Couple(com.simibubi.create.foundation.utility.Couple) FormattedText(net.minecraft.network.chat.FormattedText) ModConfig(net.minecraftforge.fml.config.ModConfig) Collections(java.util.Collections) UnmodifiableConfig(com.electronwill.nightconfig.core.UnmodifiableConfig) LabeledEntry(com.simibubi.create.foundation.config.ui.ConfigScreenList.LabeledEntry) DelegatedStencilElement(com.simibubi.create.foundation.gui.element.DelegatedStencilElement) BoxWidget(com.simibubi.create.foundation.gui.widget.BoxWidget) ValueEntry(com.simibubi.create.foundation.config.ui.entries.ValueEntry) SubMenuEntry(com.simibubi.create.foundation.config.ui.entries.SubMenuEntry) EnumEntry(com.simibubi.create.foundation.config.ui.entries.EnumEntry) LabeledEntry(com.simibubi.create.foundation.config.ui.ConfigScreenList.LabeledEntry) BooleanEntry(com.simibubi.create.foundation.config.ui.entries.BooleanEntry) NumberEntry(com.simibubi.create.foundation.config.ui.entries.NumberEntry) ForgeConfigSpec(net.minecraftforge.common.ForgeConfigSpec) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConfirmationScreen(com.simibubi.create.foundation.gui.ConfirmationScreen) TextComponent(net.minecraft.network.chat.TextComponent) Color(com.simibubi.create.foundation.utility.Color) SubMenuEntry(com.simibubi.create.foundation.config.ui.entries.SubMenuEntry) AbstractConfig(com.electronwill.nightconfig.core.AbstractConfig) EnumEntry(com.simibubi.create.foundation.config.ui.entries.EnumEntry) BooleanEntry(com.simibubi.create.foundation.config.ui.entries.BooleanEntry)

Example 3 with BoxWidget

use of com.simibubi.create.foundation.gui.widget.BoxWidget 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)

Example 4 with BoxWidget

use of com.simibubi.create.foundation.gui.widget.BoxWidget in project Create by Creators-of-Create.

the class ConfigModListScreen method init.

@Override
protected void init() {
    super.init();
    int listWidth = Math.min(width - 80, 300);
    list = new ConfigScreenList(minecraft, listWidth, height - 60, 15, height - 45, 40);
    list.setLeftPos(this.width / 2 - list.getWidth() / 2);
    addRenderableWidget(list);
    allEntries = new ArrayList<>();
    ModList.get().getMods().stream().map(IModInfo::getModId).forEach(id -> allEntries.add(new ModEntry(id, this)));
    allEntries.sort((e1, e2) -> {
        int empty = (e2.button.active ? 1 : 0) - (e1.button.active ? 1 : 0);
        if (empty != 0)
            return empty;
        return e1.id.compareToIgnoreCase(e2.id);
    });
    list.children().clear();
    list.children().addAll(allEntries);
    goBack = new BoxWidget(width / 2 - listWidth / 2 - 30, height / 2 + 65, 20, 20).withPadding(2, 2).withCallback(() -> ScreenOpener.open(parent));
    goBack.showingElement(AllIcons.I_CONFIG_BACK.asStencil().withElementRenderer(BoxWidget.gradientFactory.apply(goBack)));
    goBack.getToolTip().add(new TextComponent("Go Back"));
    addRenderableWidget(goBack);
    search = new HintableTextFieldWidget(font, width / 2 - listWidth / 2, height - 35, listWidth, 20);
    search.setResponder(this::updateFilter);
    search.setHint("Search...");
    search.moveCursorToStart();
    addRenderableWidget(search);
}
Also used : BoxWidget(com.simibubi.create.foundation.gui.widget.BoxWidget) TextComponent(net.minecraft.network.chat.TextComponent)

Aggregations

BoxWidget (com.simibubi.create.foundation.gui.widget.BoxWidget)4 TextComponent (net.minecraft.network.chat.TextComponent)3 TextStencilElement (com.simibubi.create.foundation.gui.element.TextStencilElement)2 ArrayList (java.util.ArrayList)2 FormattedText (net.minecraft.network.chat.FormattedText)2 AbstractConfig (com.electronwill.nightconfig.core.AbstractConfig)1 UnmodifiableConfig (com.electronwill.nightconfig.core.UnmodifiableConfig)1 Lists (com.google.common.collect.Lists)1 PoseStack (com.mojang.blaze3d.vertex.PoseStack)1 LabeledEntry (com.simibubi.create.foundation.config.ui.ConfigScreenList.LabeledEntry)1 BooleanEntry (com.simibubi.create.foundation.config.ui.entries.BooleanEntry)1 EnumEntry (com.simibubi.create.foundation.config.ui.entries.EnumEntry)1 NumberEntry (com.simibubi.create.foundation.config.ui.entries.NumberEntry)1 SubMenuEntry (com.simibubi.create.foundation.config.ui.entries.SubMenuEntry)1 ValueEntry (com.simibubi.create.foundation.config.ui.entries.ValueEntry)1 AllIcons (com.simibubi.create.foundation.gui.AllIcons)1 ConfirmationScreen (com.simibubi.create.foundation.gui.ConfirmationScreen)1 Response (com.simibubi.create.foundation.gui.ConfirmationScreen.Response)1 ScreenOpener (com.simibubi.create.foundation.gui.ScreenOpener)1 Theme (com.simibubi.create.foundation.gui.Theme)1