Search in sources :

Example 1 with Rect2i

use of net.minecraft.client.util.Rect2i in project sodium-fabric by CaffeineMC.

the class SodiumOptionsGUI method renderOptionTooltip.

@SuppressWarnings("SuspiciousNameCombination")
private void renderOptionTooltip(ControlElement<?> element, int mouseX, int mouseY, float delta) {
    Rect2i dim = element.getDimensions();
    int textPadding = 3;
    int boxPadding = 3;
    int boxX = dim.getX() + dim.getWidth() + boxPadding;
    int boxY = dim.getY() + boxPadding;
    int boxWidth = Math.min(this.width - (dim.getX() + dim.getWidth() + (boxPadding * 2)), 280);
    Option<?> option = element.getOption();
    List<String> tooltip = new ArrayList<>(this.font.wrapStringToWidthAsList(option.getTooltip(), boxWidth - (textPadding * 2)));
    OptionImpact impact = option.getImpact();
    if (impact != null) {
        tooltip.add("");
        tooltip.add(TextFormat.GRAY + "Performance Impact: " + impact.toDisplayString());
    }
    int boxHeight = (tooltip.size() * 12) + boxPadding;
    this.fillGradient(boxX, boxY, boxX + boxWidth, boxY + boxHeight, 0xE0000000, 0xE0000000);
    for (int i = 0; i < tooltip.size(); i++) {
        String str = tooltip.get(i);
        if (str.isEmpty()) {
            continue;
        }
        this.font.draw(str, boxX + textPadding, boxY + textPadding + (i * 12), 0xFFFFFFFF);
    }
}
Also used : Rect2i(net.minecraft.client.util.Rect2i) ArrayList(java.util.ArrayList)

Example 2 with Rect2i

use of net.minecraft.client.util.Rect2i in project sodium-fabric by CaffeineMC.

the class SodiumOptionsGUI method rebuildGUIOptions.

private void rebuildGUIOptions() {
    int x = 10;
    int y = 28;
    for (OptionGroup group : this.currentPage.getGroups()) {
        for (Option<?> option : group.getOptions()) {
            Control<?> control = option.getControl();
            ControlElement<?> element = control.createElement(new Rect2i(x, y, 200, 18));
            Validate.notNull(element);
            this.controls.add(element);
            this.children.add(element);
            y += 18;
        }
        y += 4;
    }
}
Also used : Rect2i(net.minecraft.client.util.Rect2i)

Example 3 with Rect2i

use of net.minecraft.client.util.Rect2i in project sodium-fabric by CaffeineMC.

the class SodiumOptionsGUI method rebuildGUI.

private void rebuildGUI() {
    this.controls.clear();
    this.children.clear();
    this.drawable.clear();
    if (this.currentPage == null) {
        if (this.pages.isEmpty()) {
            throw new IllegalStateException("No pages are available?!");
        }
        // Just use the first page for now
        this.currentPage = this.pages.get(0);
    }
    this.rebuildGUIPages();
    this.rebuildGUIOptions();
    this.applyButton = new FlatButtonWidget(new Rect2i(10, this.height - 30, 80, 20), "Apply", this::applyChanges);
    this.closeButton = new FlatButtonWidget(new Rect2i(96, this.height - 30, 80, 20), "Close", this::popScreen);
    this.children.add(this.applyButton);
    this.children.add(this.closeButton);
    this.resetButton = new FlatButtonWidget(new Rect2i(this.width - 96, this.height - 30, 80, 20), "Reset", this::resetChanges);
    this.children.add(this.resetButton);
    for (Element element : this.children) {
        if (element instanceof Drawable) {
            this.drawable.add((Drawable) element);
        }
    }
}
Also used : Rect2i(net.minecraft.client.util.Rect2i) ControlElement(me.jellysquid.mods.sodium.client.gui.options.control.ControlElement) Element(net.minecraft.client.gui.Element) Drawable(net.minecraft.client.gui.Drawable) FlatButtonWidget(me.jellysquid.mods.sodium.client.gui.widgets.FlatButtonWidget)

Example 4 with Rect2i

use of net.minecraft.client.util.Rect2i in project sodium-fabric by CaffeineMC.

the class SodiumOptionsGUI method rebuildGUIPages.

private void rebuildGUIPages() {
    int x = 10;
    int y = 6;
    for (OptionPage page : this.pages) {
        int width = 10 + this.font.getStringWidth(page.getName());
        FlatButtonWidget button = new FlatButtonWidget(new Rect2i(x, y, width, 16), page.getName(), () -> {
            this.setPage(page);
        });
        button.setSelected(this.currentPage == page);
        x += width + 6;
        this.children.add(button);
    }
}
Also used : Rect2i(net.minecraft.client.util.Rect2i) FlatButtonWidget(me.jellysquid.mods.sodium.client.gui.widgets.FlatButtonWidget)

Aggregations

Rect2i (net.minecraft.client.util.Rect2i)4 FlatButtonWidget (me.jellysquid.mods.sodium.client.gui.widgets.FlatButtonWidget)2 ArrayList (java.util.ArrayList)1 ControlElement (me.jellysquid.mods.sodium.client.gui.options.control.ControlElement)1 Drawable (net.minecraft.client.gui.Drawable)1 Element (net.minecraft.client.gui.Element)1