Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class VideoSettingsScreen extends Screen implements ScreenPromptable {
private DonationButtonWidget donateButton;

private boolean hasPendingChanges;
private boolean reserveBottomSpace;

private final ScrollableTooltip tooltip = new ScrollableTooltip(this);

Expand Down Expand Up @@ -190,15 +191,34 @@ private void rebuild() {

this.pageList = new PageListWidget(this, this::startSearch, new Dim2i(0, 0, Layout.PAGE_LIST_WIDTH, this.height));

this.applyButton = new FlatButtonWidget(new Dim2i(Layout.PAGE_LIST_WIDTH + Layout.INNER_MARGIN, Layout.INNER_MARGIN, Layout.BUTTON_LONG, Layout.BUTTON_SHORT), Component.translatable("sodium.options.buttons.apply"), ConfigManager.CONFIG::applyAllOptions, true, false);
this.closeButton = new FlatButtonWidget(new Dim2i(this.applyButton.getLimitX() + Layout.INNER_MARGIN, Layout.INNER_MARGIN, Layout.BUTTON_LONG, Layout.BUTTON_SHORT), Component.translatable("gui.done"), this::onClose, true, false);
this.undoButton = new FlatButtonWidget(new Dim2i(this.closeButton.getLimitX() + Layout.INNER_MARGIN, Layout.INNER_MARGIN, Layout.BUTTON_LONG, Layout.BUTTON_SHORT), Component.translatable("sodium.options.buttons.undo"), this::undoChanges, true, false);
boolean stackVertically = false;
this.reserveBottomSpace = false;

this.donateButton = new DonationButtonWidget(this, List.of(this.applyButton, this.closeButton, this.undoButton), this.width, this::openDonationPage);
int minWidthToStack = Layout.PAGE_LIST_WIDTH + Layout.INNER_MARGIN * 2 + Layout.OPTION_WIDTH + Layout.OPTION_LIST_SCROLLBAR_OFFSET + Layout.SCROLLBAR_WIDTH + Layout.BUTTON_LONG;
int maxWidthToStack = minWidthToStack + Layout.BUTTON_LONG * 2 + Layout.INNER_MARGIN;

this.rebuildOptionList();
if (this.width > minWidthToStack && this.width < maxWidthToStack) {
stackVertically = true;
} else if (this.width < minWidthToStack) {
this.reserveBottomSpace = true;
}

this.closeButton = new FlatButtonWidget(new Dim2i(this.width - Layout.BUTTON_LONG - Layout.INNER_MARGIN, this.height - (Layout.INNER_MARGIN + Layout.BUTTON_SHORT), Layout.BUTTON_LONG, Layout.BUTTON_SHORT), Component.translatable("gui.done"), this::onClose, true, false);

if (stackVertically) {
this.applyButton = new FlatButtonWidget(new Dim2i(this.closeButton.getX(), this.closeButton.getY() - (Layout.INNER_MARGIN + Layout.BUTTON_SHORT), Layout.BUTTON_LONG, Layout.BUTTON_SHORT), Component.translatable("sodium.options.buttons.apply"), ConfigManager.CONFIG::applyAllOptions, true, false);
this.undoButton = new FlatButtonWidget(new Dim2i(this.applyButton.getX(), this.applyButton.getY() - (Layout.INNER_MARGIN + Layout.BUTTON_SHORT), Layout.BUTTON_LONG, Layout.BUTTON_SHORT), Component.translatable("sodium.options.buttons.undo"), this::undoChanges, true, false);
} else {
this.applyButton = new FlatButtonWidget(new Dim2i(this.closeButton.getX() - Layout.INNER_MARGIN - Layout.BUTTON_LONG, this.height - (Layout.INNER_MARGIN + Layout.BUTTON_SHORT), Layout.BUTTON_LONG, Layout.BUTTON_SHORT), Component.translatable("sodium.options.buttons.apply"), ConfigManager.CONFIG::applyAllOptions, true, false);
this.undoButton = new FlatButtonWidget(new Dim2i(this.applyButton.getX() - Layout.INNER_MARGIN - Layout.BUTTON_LONG, this.height - (Layout.INNER_MARGIN + Layout.BUTTON_SHORT), Layout.BUTTON_LONG, Layout.BUTTON_SHORT), Component.translatable("sodium.options.buttons.undo"), this::undoChanges, true, false);
}

this.donateButton = new DonationButtonWidget(this, List.of(), this.width, this::openDonationPage);

this.addRenderableWidget(this.pageList);

this.rebuildOptionList();

this.addRenderableWidget(this.undoButton);
this.addRenderableWidget(this.applyButton);
this.addRenderableWidget(this.closeButton);
Expand All @@ -211,8 +231,8 @@ private void rebuild() {
private void rebuildOptionList() {
this.removeWidget(this.optionList);
this.optionList = this.addRenderableWidget(new OptionListWidget(this, new Dim2i(
this.pageList.getLimitX() + Layout.INNER_MARGIN, Layout.INNER_MARGIN * 2 + Layout.BUTTON_SHORT,
Layout.OPTION_WIDTH + Layout.OPTION_LIST_SCROLLBAR_OFFSET + Layout.SCROLLBAR_WIDTH, this.height - (Layout.INNER_MARGIN * 3 + Layout.BUTTON_SHORT)),
this.pageList.getLimitX() + Layout.INNER_MARGIN, Layout.INNER_MARGIN,
Layout.OPTION_WIDTH + Layout.OPTION_LIST_SCROLLBAR_OFFSET + Layout.SCROLLBAR_WIDTH, this.height - (this.reserveBottomSpace ? (Layout.INNER_MARGIN * 3 + Layout.BUTTON_SHORT) : (Layout.INNER_MARGIN))),
this.currentPage, this.currentMod.theme()
));
this.controlList = this.optionList;
Expand Down Expand Up @@ -249,7 +269,8 @@ private void updateControls(int mouseX, int mouseY) {
boolean hasChanges = ConfigManager.CONFIG.anyOptionChanged();

this.applyButton.setEnabled(hasChanges);
this.setWidgetPresence(this.undoButton, hasChanges);
// This breaks the navigation order and doesn't appear to do anything
//this.setWidgetPresence(this.undoButton, hasChanges);
this.undoButton.setVisible(hasChanges);
this.closeButton.setEnabled(!hasChanges);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import net.caffeinemc.mods.sodium.client.config.structure.OptionGroup;
import net.caffeinemc.mods.sodium.client.config.structure.OptionPage;
import net.caffeinemc.mods.sodium.client.gui.ColorTheme;
import net.caffeinemc.mods.sodium.client.gui.Colors;
import net.caffeinemc.mods.sodium.client.gui.Layout;
import net.caffeinemc.mods.sodium.client.gui.options.control.AbstractOptionList;
import net.caffeinemc.mods.sodium.client.util.Dim2i;
import net.minecraft.client.gui.ComponentPath;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.navigation.FocusNavigationEvent;
import net.minecraft.client.gui.screens.Screen;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class OptionListWidget extends AbstractOptionList {
private final OptionPage page;
Expand All @@ -35,6 +39,13 @@ private void rebuild(Screen screen) {

int entryHeight = this.font.lineHeight * 2;
int listHeight = 0;

var header = new HeaderWidget(this, new Dim2i(x, y + listHeight, width, entryHeight), this.page.name().getString(), this.theme.themeLighter);
this.addRenderableChild(header);

maxWidth = Math.max(maxWidth, header.getContentWidth());
listHeight += entryHeight + Layout.INNER_MARGIN;

for (OptionGroup group : this.page.groups()) {
// Add each option's control element
for (Option option : group.options()) {
Expand Down Expand Up @@ -63,4 +74,43 @@ public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float
super.render(graphics, mouseX, mouseY, delta);
graphics.disableScissor();
}

public static class HeaderWidget extends AbstractWidget {
protected final AbstractOptionList list;
private final String title;
private final int themeColor;

public HeaderWidget(AbstractOptionList list, Dim2i dim, String title, int themeColor) {
super(dim);
this.list = list;
this.title = title;
this.themeColor = themeColor;
}

public int getContentWidth() {
return 70;
}

@Override
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
this.hovered = this.isMouseOver(mouseX, mouseY);

this.drawRect(graphics, this.getX(), this.getY(), this.getLimitX(), this.getLimitY(), Colors.BACKGROUND_DEFAULT);
this.drawString(graphics, this.truncateLabelToFit(this.title), this.getX() + 6, this.getCenterY() - 4, this.themeColor);
}

private String truncateLabelToFit(String name) {
return truncateTextToFit(name, this.getWidth() - 12);
}

@Override
public int getY() {
return super.getY() - this.list.getScrollAmount();
}

@Override
public @Nullable ComponentPath nextFocusPath(FocusNavigationEvent event) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public void render(@NotNull GuiGraphics graphics) {
int arrowX = this.visibleDim.x() - ARROW_WIDTH;
int arrowY = this.hoveredElement.getCenterY() - (ARROW_HEIGHT / 2);

graphics.pose().pushPose();
graphics.pose().translate(0.0F, 0.0F, 400.0F);

// parameters are: render type, sprite, x, y, u offset, v offset, render width, render height, u size, v size, color
graphics.blit(RenderType::guiTextured, ARROW_TEXTURE, arrowX, arrowY, ARROW_WIDTH, 0, ARROW_WIDTH, ARROW_HEIGHT, SPRITE_WIDTH, ARROW_HEIGHT, Colors.BACKGROUND_LIGHT);
graphics.blit(RenderType::guiTextured, ARROW_TEXTURE, arrowX, arrowY, 0, 0, ARROW_WIDTH, ARROW_HEIGHT, SPRITE_WIDTH, ARROW_HEIGHT, Colors.BACKGROUND_DEFAULT);
Expand All @@ -158,12 +161,14 @@ public void render(@NotNull GuiGraphics graphics) {

graphics.enableScissor(this.visibleDim.x(), this.visibleDim.y(), this.visibleDim.getLimitX(), this.visibleDim.getLimitY());
graphics.fill(this.visibleDim.x(), this.visibleDim.y(), this.visibleDim.getLimitX(), this.visibleDim.getLimitY(), Colors.BACKGROUND_LIGHT);
graphics.pose().translate(0.0F, 0.0F, 400.0F);
for (int i = 0; i < this.content.size(); i++) {
graphics.drawString(this.font, this.content.get(i),
this.visibleDim.x() + TEXT_HORIZONTAL_PADDING, this.visibleDim.y() + TEXT_VERTICAL_PADDING + (i * lineHeight) - scrollAmount,
Colors.FOREGROUND);
}
graphics.disableScissor();
graphics.pose().popPose();
}

public boolean mouseScrolled(double d, double e, double amount) {
Expand Down
Loading