Skip to content

Commit

Permalink
change: Fix double rendering of the options
Browse files Browse the repository at this point in the history
  • Loading branch information
FlashyReese committed Oct 28, 2024
1 parent 8cd2331 commit 37b0a82
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@
import net.minecraft.client.gui.screens.options.VideoSettingsScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.FormattedText;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;

import java.io.IOException;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Stream;

Expand All @@ -49,7 +47,6 @@ public class SodiumVideoOptionsScreen extends Screen implements ScreenPromptable

private final Screen prevScreen;
private final List<OptionPage> pages = new ArrayList<>();
private AbstractFrame frame;
private FlatButtonWidget applyButton, closeButton, undoButton;
private FlatButtonWidget donateButton, hideDonateButton;
private boolean hasPendingChanges;
Expand Down Expand Up @@ -128,14 +125,14 @@ public void rebuildUI() {
protected void init() {
super.init();

this.frame = this.parentFrameBuilder().build();
this.addRenderableWidget(this.frame);
AbstractFrame frame = this.parentFrameBuilder().build();
this.addRenderableWidget(frame);

this.searchTextField.setFocused(!lastSearch.get().trim().isEmpty());
if (this.searchTextField.isFocused()) {
this.setFocused(this.searchTextField);
} else {
this.setFocused(this.frame);
this.setFocused(frame);
}

if (this.prompt != null) {
Expand Down Expand Up @@ -189,7 +186,7 @@ protected BasicFrame.Builder parentFrameBuilder() {

if (IrisCompat.isIrisPresent()) { // FabricLoader.getInstance().isModLoaded("iris")) {
//int size = this.client.textRenderer.getWidth(Text.translatable(IrisApi.getInstance().getMainScreenLanguageKey()));
int size = this.minecraft.font.width(Component.translatable(IrisCompat.getIrisShaderPacksScreenLanguageKey()));
int size = this.minecraft.font.width(Component.translatable(Objects.requireNonNull(IrisCompat.getIrisShaderPacksScreenLanguageKey())));
Dim2i shaderPackButtonDim;
if (!(SodiumClientMod.options().notifications.hasClearedDonationButton)) {
shaderPackButtonDim = new Dim2i(donateButtonDim.x() - 12 - size, tabFrameDim.y() - 26, 10 + size, 20);
Expand Down Expand Up @@ -238,10 +235,9 @@ public BasicFrame.Builder parentBasicFrameBuilder(Dim2i parentBasicFrameDim, Dim
}

@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
this.updateControls();
super.render(guiGraphics, this.prompt != null ? -1 : mouseX, this.prompt != null ? -1 : mouseY, delta);
this.frame.render(guiGraphics, this.prompt != null ? -1 : mouseX, this.prompt != null ? -1 : mouseY, delta);
if (this.prompt != null) {
this.prompt.render(guiGraphics, mouseX, mouseY, delta);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.navigation.FocusNavigationEvent;
import net.minecraft.client.gui.navigation.ScreenRectangle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
Expand Down Expand Up @@ -41,7 +42,7 @@ public void buildFrame() {
}

@Override
public void render(GuiGraphics drawContext, int mouseX, int mouseY, float delta) {
public void render(@NotNull GuiGraphics drawContext, int mouseX, int mouseY, float delta) {
if (this.renderOutline) {
this.drawBorder(drawContext, this.dim.x(), this.dim.y(), this.dim.getLimitX(), this.dim.getLimitY(), 0xFFAAAAAA);
}
Expand Down Expand Up @@ -85,7 +86,7 @@ public void setFocused(@Nullable GuiEventListener focused) {
}

@Override
public List<? extends GuiEventListener> children() {
public @NotNull List<? extends GuiEventListener> children() {
return this.children;
}

Expand All @@ -95,12 +96,12 @@ public boolean isMouseOver(double mouseX, double mouseY) {
}

@Override
public @Nullable ComponentPath nextFocusPath(FocusNavigationEvent navigation) {
public @Nullable ComponentPath nextFocusPath(@NotNull FocusNavigationEvent navigation) {
return ContainerEventHandler.super.nextFocusPath(navigation);
}

@Override
public ScreenRectangle getRectangle() {
public @NotNull ScreenRectangle getRectangle() {
return new ScreenRectangle(this.dim.x(), this.dim.y(), this.dim.width(), this.dim.height());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.caffeinemc.mods.sodium.client.util.Dim2i;
import net.minecraft.client.gui.GuiGraphics;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -34,7 +35,7 @@ public void buildFrame() {
}

@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
super.render(guiGraphics, mouseX, mouseY, delta);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.util.FormattedCharSequence;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
Expand Down Expand Up @@ -95,7 +96,7 @@ public void buildFrame() {
}

@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
ControlElement<?> hoveredElement = this.controlElements.stream()
.filter(controlElement -> ((Dim2iExtended) (Object) controlElement.getDimensions()).overlapWith(this.originalDim))
.filter(ControlElement::isHovered)
Expand Down Expand Up @@ -167,7 +168,7 @@ private void renderOptionTooltip(GuiGraphics guiGraphics, ControlElement<?> elem
}

@Override
public @Nullable ComponentPath nextFocusPath(FocusNavigationEvent navigation) {
public @Nullable ComponentPath nextFocusPath(@NotNull FocusNavigationEvent navigation) {
return super.nextFocusPath(navigation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.client.gui.ComponentPath;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.navigation.FocusNavigationEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -70,15 +71,15 @@ public void setupFrame(AtomicReference<Integer> verticalScrollBarOffset, AtomicR
}

if (this.canScrollHorizontal) {
this.horizontalScrollBar = new ScrollBarComponent(new Dim2i(this.viewPortDimension.x(), this.viewPortDimension.getLimitY() + 1, this.viewPortDimension.width(), 10), ScrollBarComponent.Mode.HORIZONTAL, this.frame.dim.width(), this.viewPortDimension.width(), offset -> {
this.horizontalScrollBar = new ScrollBarComponent(new Dim2i(this.viewPortDimension.x(), this.viewPortDimension.getLimitY() + 1, this.viewPortDimension.width(), 10), ScrollBarComponent.ScrollDirection.HORIZONTAL, this.frame.dim.width(), this.viewPortDimension.width(), offset -> {
//this.buildFrame();
((Dim2iExtended) ((Object) this.frame.dim)).setX(this.frameOrigin.x() - this.horizontalScrollBar.getOffset());
horizontalScrollBarOffset.set(offset);
});
this.horizontalScrollBar.setOffset(horizontalScrollBarOffset.get());
}
if (this.canScrollVertical) {
this.verticalScrollBar = new ScrollBarComponent(new Dim2i(this.viewPortDimension.getLimitX() + 1, this.viewPortDimension.y(), 10, this.viewPortDimension.height()), ScrollBarComponent.Mode.VERTICAL, this.frame.dim.height(), this.viewPortDimension.height(), offset -> {
this.verticalScrollBar = new ScrollBarComponent(new Dim2i(this.viewPortDimension.getLimitX() + 1, this.viewPortDimension.y(), 10, this.viewPortDimension.height()), ScrollBarComponent.ScrollDirection.VERTICAL, this.frame.dim.height(), this.viewPortDimension.height(), offset -> {
//this.buildFrame();
((Dim2iExtended) ((Object) this.frame.dim)).setY(this.frameOrigin.y() - this.verticalScrollBar.getOffset());
verticalScrollBarOffset.set(offset);
Expand All @@ -93,11 +94,11 @@ public void buildFrame() {
this.controlElements.clear();

if (this.canScrollHorizontal) {
this.horizontalScrollBar.updateThumbPosition();
this.horizontalScrollBar.updateThumbLocation();
}

if (this.canScrollVertical) {
this.verticalScrollBar.updateThumbPosition();
this.verticalScrollBar.updateThumbLocation();
}

if (this.canScrollHorizontal) {
Expand Down Expand Up @@ -132,7 +133,7 @@ public void buildFrame() {
}

@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
if (this.canScrollHorizontal || this.canScrollVertical) {
if (this.renderOutline) {
this.drawBorder(guiGraphics, this.dim.x(), this.dim.y(), this.dim.getLimitX(), this.dim.getLimitY(), 0xFFAAAAAA);
Expand All @@ -152,7 +153,7 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta)
}

@Override
public @Nullable ComponentPath nextFocusPath(FocusNavigationEvent navigation) {
public @Nullable ComponentPath nextFocusPath(@NotNull FocusNavigationEvent navigation) {
//this.snapFocusedInViewport();
return super.nextFocusPath(navigation);
}
Expand Down
Loading

0 comments on commit 37b0a82

Please sign in to comment.