Skip to content

Commit 61cd049

Browse files
EnnuiLdouira
authored andcommitted
Tackle page headers and Apply/Done on bottom
1 parent 7b7c74e commit 61cd049

File tree

3 files changed

+84
-8
lines changed

3 files changed

+84
-8
lines changed

common/src/main/java/net/caffeinemc/mods/sodium/client/gui/VideoSettingsScreen.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class VideoSettingsScreen extends Screen implements ScreenPromptable {
5959
private DonationButtonWidget donateButton;
6060

6161
private boolean hasPendingChanges;
62+
private boolean reserveBottomSpace;
6263

6364
private final ScrollableTooltip tooltip = new ScrollableTooltip(this);
6465

@@ -190,15 +191,34 @@ private void rebuild() {
190191

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

193-
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);
194-
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);
195-
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);
194+
boolean stackVertically = false;
195+
this.reserveBottomSpace = false;
196196

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

199-
this.rebuildOptionList();
200+
if (this.width > minWidthToStack && this.width < maxWidthToStack) {
201+
stackVertically = true;
202+
} else if (this.width < minWidthToStack) {
203+
this.reserveBottomSpace = true;
204+
}
205+
206+
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);
207+
208+
if (stackVertically) {
209+
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);
210+
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);
211+
} else {
212+
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);
213+
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);
214+
}
215+
216+
this.donateButton = new DonationButtonWidget(this, List.of(), this.width, this::openDonationPage);
200217

201218
this.addRenderableWidget(this.pageList);
219+
220+
this.rebuildOptionList();
221+
202222
this.addRenderableWidget(this.undoButton);
203223
this.addRenderableWidget(this.applyButton);
204224
this.addRenderableWidget(this.closeButton);
@@ -211,8 +231,8 @@ private void rebuild() {
211231
private void rebuildOptionList() {
212232
this.removeWidget(this.optionList);
213233
this.optionList = this.addRenderableWidget(new OptionListWidget(this, new Dim2i(
214-
this.pageList.getLimitX() + Layout.INNER_MARGIN, Layout.INNER_MARGIN * 2 + Layout.BUTTON_SHORT,
215-
Layout.OPTION_WIDTH + Layout.OPTION_LIST_SCROLLBAR_OFFSET + Layout.SCROLLBAR_WIDTH, this.height - (Layout.INNER_MARGIN * 3 + Layout.BUTTON_SHORT)),
234+
this.pageList.getLimitX() + Layout.INNER_MARGIN, Layout.INNER_MARGIN,
235+
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))),
216236
this.currentPage, this.currentMod.theme()
217237
));
218238
this.controlList = this.optionList;
@@ -249,7 +269,8 @@ private void updateControls(int mouseX, int mouseY) {
249269
boolean hasChanges = ConfigManager.CONFIG.anyOptionChanged();
250270

251271
this.applyButton.setEnabled(hasChanges);
252-
this.setWidgetPresence(this.undoButton, hasChanges);
272+
// This breaks the navigation order and doesn't appear to do anything
273+
//this.setWidgetPresence(this.undoButton, hasChanges);
253274
this.undoButton.setVisible(hasChanges);
254275
this.closeButton.setEnabled(!hasChanges);
255276

common/src/main/java/net/caffeinemc/mods/sodium/client/gui/widgets/OptionListWidget.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
import net.caffeinemc.mods.sodium.client.config.structure.OptionGroup;
55
import net.caffeinemc.mods.sodium.client.config.structure.OptionPage;
66
import net.caffeinemc.mods.sodium.client.gui.ColorTheme;
7+
import net.caffeinemc.mods.sodium.client.gui.Colors;
78
import net.caffeinemc.mods.sodium.client.gui.Layout;
89
import net.caffeinemc.mods.sodium.client.gui.options.control.AbstractOptionList;
910
import net.caffeinemc.mods.sodium.client.util.Dim2i;
11+
import net.minecraft.client.gui.ComponentPath;
1012
import net.minecraft.client.gui.GuiGraphics;
13+
import net.minecraft.client.gui.navigation.FocusNavigationEvent;
1114
import net.minecraft.client.gui.screens.Screen;
1215
import org.jetbrains.annotations.NotNull;
16+
import org.jetbrains.annotations.Nullable;
1317

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

3640
int entryHeight = this.font.lineHeight * 2;
3741
int listHeight = 0;
42+
43+
var header = new HeaderWidget(this, new Dim2i(x, y + listHeight, width, entryHeight), this.page.name().getString(), this.theme.themeLighter);
44+
this.addRenderableChild(header);
45+
46+
maxWidth = Math.max(maxWidth, header.getContentWidth());
47+
listHeight += entryHeight + Layout.INNER_MARGIN;
48+
3849
for (OptionGroup group : this.page.groups()) {
3950
// Add each option's control element
4051
for (Option option : group.options()) {
@@ -63,4 +74,43 @@ public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float
6374
super.render(graphics, mouseX, mouseY, delta);
6475
graphics.disableScissor();
6576
}
77+
78+
public static class HeaderWidget extends AbstractWidget {
79+
protected final AbstractOptionList list;
80+
private final String title;
81+
private final int themeColor;
82+
83+
public HeaderWidget(AbstractOptionList list, Dim2i dim, String title, int themeColor) {
84+
super(dim);
85+
this.list = list;
86+
this.title = title;
87+
this.themeColor = themeColor;
88+
}
89+
90+
public int getContentWidth() {
91+
return 70;
92+
}
93+
94+
@Override
95+
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
96+
this.hovered = this.isMouseOver(mouseX, mouseY);
97+
98+
this.drawRect(graphics, this.getX(), this.getY(), this.getLimitX(), this.getLimitY(), Colors.BACKGROUND_DEFAULT);
99+
this.drawString(graphics, this.truncateLabelToFit(this.title), this.getX() + 6, this.getCenterY() - 4, this.themeColor);
100+
}
101+
102+
private String truncateLabelToFit(String name) {
103+
return truncateTextToFit(name, this.getWidth() - 12);
104+
}
105+
106+
@Override
107+
public int getY() {
108+
return super.getY() - this.list.getScrollAmount();
109+
}
110+
111+
@Override
112+
public @Nullable ComponentPath nextFocusPath(FocusNavigationEvent event) {
113+
return null;
114+
}
115+
}
66116
}

common/src/main/java/net/caffeinemc/mods/sodium/client/gui/widgets/ScrollableTooltip.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ public void render(@NotNull GuiGraphics graphics) {
145145
int arrowX = this.visibleDim.x() - ARROW_WIDTH;
146146
int arrowY = this.hoveredElement.getCenterY() - (ARROW_HEIGHT / 2);
147147

148+
graphics.pose().pushPose();
149+
graphics.pose().translate(0.0F, 0.0F, 400.0F);
150+
148151
// parameters are: render type, sprite, x, y, u offset, v offset, render width, render height, u size, v size, color
149152
graphics.blit(RenderType::guiTextured, ARROW_TEXTURE, arrowX, arrowY, ARROW_WIDTH, 0, ARROW_WIDTH, ARROW_HEIGHT, SPRITE_WIDTH, ARROW_HEIGHT, Colors.BACKGROUND_LIGHT);
150153
graphics.blit(RenderType::guiTextured, ARROW_TEXTURE, arrowX, arrowY, 0, 0, ARROW_WIDTH, ARROW_HEIGHT, SPRITE_WIDTH, ARROW_HEIGHT, Colors.BACKGROUND_DEFAULT);
@@ -158,12 +161,14 @@ public void render(@NotNull GuiGraphics graphics) {
158161

159162
graphics.enableScissor(this.visibleDim.x(), this.visibleDim.y(), this.visibleDim.getLimitX(), this.visibleDim.getLimitY());
160163
graphics.fill(this.visibleDim.x(), this.visibleDim.y(), this.visibleDim.getLimitX(), this.visibleDim.getLimitY(), Colors.BACKGROUND_LIGHT);
164+
graphics.pose().translate(0.0F, 0.0F, 400.0F);
161165
for (int i = 0; i < this.content.size(); i++) {
162166
graphics.drawString(this.font, this.content.get(i),
163167
this.visibleDim.x() + TEXT_HORIZONTAL_PADDING, this.visibleDim.y() + TEXT_VERTICAL_PADDING + (i * lineHeight) - scrollAmount,
164168
Colors.FOREGROUND);
165169
}
166170
graphics.disableScissor();
171+
graphics.pose().popPose();
167172
}
168173

169174
public boolean mouseScrolled(double d, double e, double amount) {

0 commit comments

Comments
 (0)