diff --git a/build.gradle.kts b/build.gradle.kts index 5974ee4..3737fde 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,9 +4,9 @@ plugins { } val MINECRAFT_VERSION by extra { "1.21.3" } -val NEOFORGE_VERSION by extra { "21.3.3-beta" } -val FABRIC_LOADER_VERSION by extra { "0.16.7" } -val FABRIC_API_VERSION by extra { "0.106.1+1.21.3" } +val NEOFORGE_VERSION by extra { "21.3.31-beta" } +val FABRIC_LOADER_VERSION by extra { "0.16.9" } +val FABRIC_API_VERSION by extra { "0.108.0+1.21.3" } // This value can be set to null to disable Parchment. val PARCHMENT_VERSION by extra { null } @@ -14,8 +14,8 @@ val PARCHMENT_VERSION by extra { null } // https://semver.org/ val MAVEN_GROUP by extra { "me.flashyreese.mods" } val ARCHIVE_NAME by extra { "reeses-sodium-options" } -val MOD_VERSION by extra { "1.8.0-beta.5" } -val SODIUM_VERSION by extra { "mc1.21.2-0.6.0-beta.3" } +val MOD_VERSION by extra { "1.8.0" } +val SODIUM_VERSION by extra { "mc1.21.3-0.6.0" } allprojects { apply(plugin = "java") diff --git a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/SodiumVideoOptionsScreen.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/SodiumVideoOptionsScreen.java index c4c8e8d..441a742 100644 --- a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/SodiumVideoOptionsScreen.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/SodiumVideoOptionsScreen.java @@ -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; @@ -49,7 +47,6 @@ public class SodiumVideoOptionsScreen extends Screen implements ScreenPromptable private final Screen prevScreen; private final List pages = new ArrayList<>(); - private AbstractFrame frame; private FlatButtonWidget applyButton, closeButton, undoButton; private FlatButtonWidget donateButton, hideDonateButton; private boolean hasPendingChanges; @@ -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) { @@ -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); @@ -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); } diff --git a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/AbstractFrame.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/AbstractFrame.java index 79dc824..d71d9d3 100644 --- a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/AbstractFrame.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/AbstractFrame.java @@ -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; @@ -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); } @@ -85,7 +86,7 @@ public void setFocused(@Nullable GuiEventListener focused) { } @Override - public List children() { + public @NotNull List children() { return this.children; } @@ -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()); } diff --git a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/BasicFrame.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/BasicFrame.java index 3d78e48..476fd8c 100644 --- a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/BasicFrame.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/BasicFrame.java @@ -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; @@ -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); } diff --git a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/OptionPageFrame.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/OptionPageFrame.java index 7ac0cf4..89eef95 100644 --- a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/OptionPageFrame.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/OptionPageFrame.java @@ -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; @@ -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) @@ -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); } diff --git a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/ScrollableFrame.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/ScrollableFrame.java index dbc00f5..830bd25 100644 --- a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/ScrollableFrame.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/ScrollableFrame.java @@ -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; @@ -70,7 +71,7 @@ public void setupFrame(AtomicReference 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); @@ -78,7 +79,7 @@ public void setupFrame(AtomicReference verticalScrollBarOffset, AtomicR 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); @@ -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) { @@ -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); @@ -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); } diff --git a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/ScrollBarComponent.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/ScrollBarComponent.java index 864260b..5e447d8 100644 --- a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/ScrollBarComponent.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/ScrollBarComponent.java @@ -12,69 +12,69 @@ public class ScrollBarComponent extends AbstractWidget { - protected static final int SCROLL_OFFSET = 6; - - protected final Dim2i dim; - private final Mode mode; - private final int frameLength; - private final int viewPortLength; - private final int maxScrollBarOffset; - private final Consumer onSetOffset; + protected static final int SCROLL_STEP = 6; + + protected final Dim2i scrollBarArea; + private final ScrollDirection mode; + private final int contentLength; + private final int visibleAreaLength; + private final int maxContentOffset; + private final Consumer offsetChangeListener; private int offset = 0; private boolean isDragging; private Dim2i scrollThumb = null; private int scrollThumbClickOffset; - private final Dim2i extendedScrollArea; + private final Dim2i extraScrollArea; - public ScrollBarComponent(Dim2i trackArea, Mode mode, int frameLength, int viewPortLength, Consumer onSetOffset) { - this(trackArea, mode, frameLength, viewPortLength, onSetOffset, null); + public ScrollBarComponent(Dim2i trackArea, ScrollDirection scrollDirection, int contentLength, int visibleAreaLength, Consumer offsetChangeListener) { + this(trackArea, scrollDirection, contentLength, visibleAreaLength, offsetChangeListener, null); } - public ScrollBarComponent(Dim2i scrollBarArea, Mode mode, int frameLength, int viewPortLength, Consumer onSetOffset, Dim2i extendedTrackArea) { - this.dim = scrollBarArea; - this.mode = mode; - this.frameLength = frameLength; - this.viewPortLength = viewPortLength; - this.onSetOffset = onSetOffset; - this.maxScrollBarOffset = this.frameLength - this.viewPortLength; - this.extendedScrollArea = extendedTrackArea; - this.updateThumbPosition(); + public ScrollBarComponent(Dim2i scrollBarArea, ScrollDirection scrollDirection, int contentLength, int visibleAreaLength, Consumer offsetChangeListener, Dim2i extraScrollArea) { + this.scrollBarArea = scrollBarArea; + this.mode = scrollDirection; + this.contentLength = contentLength; + this.visibleAreaLength = visibleAreaLength; + this.offsetChangeListener = offsetChangeListener; + this.maxContentOffset = this.contentLength - this.visibleAreaLength; + this.extraScrollArea = extraScrollArea; + this.updateThumbLocation(); } - public void updateThumbPosition() { - int trackSize = (this.mode == Mode.VERTICAL ? this.dim.height() : this.dim.width() - 6); - int scrollThumbLength = (this.viewPortLength * trackSize) / this.frameLength; - int maximumScrollThumbOffset = this.viewPortLength - scrollThumbLength; - int scrollThumbOffset = (this.offset * maximumScrollThumbOffset) / this.maxScrollBarOffset; + public void updateThumbLocation() { + int trackSize = (this.mode == ScrollDirection.VERTICAL ? this.scrollBarArea.height() : this.scrollBarArea.width() - 6); + int scrollThumbLength = (this.visibleAreaLength * trackSize) / this.contentLength; + int maximumScrollThumbOffset = this.visibleAreaLength - scrollThumbLength; + int scrollThumbOffset = (this.offset * maximumScrollThumbOffset) / this.maxContentOffset; this.scrollThumb = new Dim2i( - this.dim.x() + 2 + (this.mode == Mode.HORIZONTAL ? scrollThumbOffset : 0), - this.dim.y() + 2 + (this.mode == Mode.VERTICAL ? scrollThumbOffset : 0), - (this.mode == Mode.VERTICAL ? this.dim.width() : scrollThumbLength) - 4, - (this.mode == Mode.VERTICAL ? scrollThumbLength : this.dim.height()) - 4 + this.scrollBarArea.x() + 2 + (this.mode == ScrollDirection.HORIZONTAL ? scrollThumbOffset : 0), + this.scrollBarArea.y() + 2 + (this.mode == ScrollDirection.VERTICAL ? scrollThumbOffset : 0), + (this.mode == ScrollDirection.VERTICAL ? this.scrollBarArea.width() : scrollThumbLength) - 4, + (this.mode == ScrollDirection.VERTICAL ? scrollThumbLength : this.scrollBarArea.height()) - 4 ); } @Override public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) { - this.drawBorder(guiGraphics, this.dim.x(), this.dim.y(), this.dim.getLimitX(), this.dim.getLimitY(), 0xFFAAAAAA); + this.drawBorder(guiGraphics, this.scrollBarArea.x(), this.scrollBarArea.y(), this.scrollBarArea.getLimitX(), this.scrollBarArea.getLimitY(), 0xFFAAAAAA); this.drawRect(guiGraphics, this.scrollThumb.x(), this.scrollThumb.y(), this.scrollThumb.getLimitX(), this.scrollThumb.getLimitY(), 0xFFAAAAAA); if (this.isFocused()) { - this.drawBorder(guiGraphics, this.dim.x(), this.dim.y(), this.dim.getLimitX(), this.dim.getLimitY(), -1); + this.drawBorder(guiGraphics, this.scrollBarArea.x(), this.scrollBarArea.y(), this.scrollBarArea.getLimitX(), this.scrollBarArea.getLimitY(), -1); } } @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (this.dim.containsCursor(mouseX, mouseY)) { + if (this.scrollBarArea.containsCursor(mouseX, mouseY)) { if (this.scrollThumb.containsCursor(mouseX, mouseY)) { - this.scrollThumbClickOffset = (int) (this.mode == Mode.VERTICAL ? mouseY - this.scrollThumb.getCenterY() : mouseX - this.scrollThumb.getCenterX()); + this.scrollThumbClickOffset = (int) (this.mode == ScrollDirection.VERTICAL ? mouseY - this.scrollThumb.getCenterY() : mouseX - this.scrollThumb.getCenterX()); this.isDragging = true; } else { - int thumbLength = this.mode == Mode.VERTICAL ? this.scrollThumb.height() : this.scrollThumb.width(); - int trackLength = this.mode == Mode.VERTICAL ? this.dim.height() : this.dim.width(); - int value = (int) (((this.mode == Mode.VERTICAL ? mouseY - this.dim.y() : mouseX - this.dim.x()) - thumbLength / 2.0) * this.maxScrollBarOffset / (trackLength - thumbLength)); + int thumbLength = this.mode == ScrollDirection.VERTICAL ? this.scrollThumb.height() : this.scrollThumb.width(); + int trackLength = this.mode == ScrollDirection.VERTICAL ? this.scrollBarArea.height() : this.scrollBarArea.width(); + int value = (int) (((this.mode == ScrollDirection.VERTICAL ? mouseY - this.scrollBarArea.y() : mouseX - this.scrollBarArea.x()) - thumbLength / 2.0) * this.maxContentOffset / (trackLength - thumbLength)); this.setOffset(value); this.isDragging = false; } @@ -95,9 +95,9 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) { @Override public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { if (this.isDragging) { - int thumbLength = this.mode == Mode.VERTICAL ? this.scrollThumb.height() : this.scrollThumb.width(); - int trackLength = this.mode == Mode.VERTICAL ? this.dim.height() : this.dim.width(); - int value = (int) (((this.mode == Mode.VERTICAL ? mouseY : mouseX) - this.scrollThumbClickOffset - (this.mode == Mode.VERTICAL ? this.dim.y() : this.dim.x()) - thumbLength / 2.0) * this.maxScrollBarOffset / (trackLength - thumbLength)); + int thumbLength = this.mode == ScrollDirection.VERTICAL ? this.scrollThumb.height() : this.scrollThumb.width(); + int trackLength = this.mode == ScrollDirection.VERTICAL ? this.scrollBarArea.height() : this.scrollBarArea.width(); + int value = (int) (((this.mode == ScrollDirection.VERTICAL ? mouseY : mouseX) - this.scrollThumbClickOffset - (this.mode == ScrollDirection.VERTICAL ? this.scrollBarArea.y() : this.scrollBarArea.x()) - thumbLength / 2.0) * this.maxContentOffset / (trackLength - thumbLength)); this.setOffset(value); return true; } @@ -106,8 +106,8 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del @Override public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { - if (this.dim.containsCursor(mouseX, mouseY) || this.extendedScrollArea != null && this.extendedScrollArea.containsCursor(mouseX, mouseY)) { - this.setOffset(this.offset - (int) verticalAmount * SCROLL_OFFSET); + if (this.scrollBarArea.containsCursor(mouseX, mouseY) || this.extraScrollArea != null && this.extraScrollArea.containsCursor(mouseX, mouseY)) { + this.setOffset(this.offset - (int) verticalAmount * SCROLL_STEP); return true; } return false; @@ -118,14 +118,14 @@ public int getOffset() { } public void setOffset(int value) { - this.offset = Mth.clamp(value, 0, this.maxScrollBarOffset); - this.updateThumbPosition(); - this.onSetOffset.accept(this.offset); + this.offset = Mth.clamp(value, 0, this.maxContentOffset); + this.updateThumbLocation(); + this.offsetChangeListener.accept(this.offset); } @Override public @NotNull ScreenRectangle getRectangle() { - return new ScreenRectangle(this.dim.x(), this.dim.y(), this.dim.width(), this.dim.height()); + return new ScreenRectangle(this.scrollBarArea.x(), this.scrollBarArea.y(), this.scrollBarArea.width(), this.scrollBarArea.height()); } @Override @@ -135,10 +135,10 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { } int newOffset = switch (keyCode) { - case GLFW.GLFW_KEY_UP -> this.getOffset() - SCROLL_OFFSET; - case GLFW.GLFW_KEY_DOWN -> this.getOffset() + SCROLL_OFFSET; - case GLFW.GLFW_KEY_LEFT -> this.mode == Mode.HORIZONTAL ? this.getOffset() - SCROLL_OFFSET : this.getOffset(); - case GLFW.GLFW_KEY_RIGHT -> this.mode == Mode.HORIZONTAL ? this.getOffset() + SCROLL_OFFSET : this.getOffset(); + case GLFW.GLFW_KEY_UP -> this.getOffset() - SCROLL_STEP; + case GLFW.GLFW_KEY_DOWN -> this.getOffset() + SCROLL_STEP; + case GLFW.GLFW_KEY_LEFT -> this.mode == ScrollDirection.HORIZONTAL ? this.getOffset() - SCROLL_STEP : this.getOffset(); + case GLFW.GLFW_KEY_RIGHT -> this.mode == ScrollDirection.HORIZONTAL ? this.getOffset() + SCROLL_STEP : this.getOffset(); default -> this.getOffset(); }; @@ -150,7 +150,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { return false; } - public enum Mode { + public enum ScrollDirection { HORIZONTAL, VERTICAL } diff --git a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/SearchTextFieldComponent.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/SearchTextFieldComponent.java index b65159e..dbe8064 100644 --- a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/SearchTextFieldComponent.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/SearchTextFieldComponent.java @@ -21,6 +21,7 @@ import net.minecraft.util.FormattedCharSequence; import net.minecraft.util.Mth; import net.minecraft.util.StringUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; @@ -53,6 +54,12 @@ public class SearchTextFieldComponent extends AbstractWidget { private int selectionEnd; private int lastCursorPosition = this.getCursor(); + // Cursor properties + private static final long CURSOR_ANIMATION_DURATION = 750; + private long nextCursorUpdate; + private boolean currentCursorState; + private float currentCursorAlpha; + public SearchTextFieldComponent(Dim2i dim, List pages, AtomicReference tabFrameSelectedTab, AtomicReference tabFrameScrollBarOffset, AtomicReference optionPageScrollBarOffset, int tabDimHeight, SodiumVideoOptionsScreen sodiumVideoOptionsScreen, AtomicReference lastSearch, AtomicReference lastSearchIndex) { this.dim = dim; this.pages = pages; @@ -69,10 +76,11 @@ public SearchTextFieldComponent(Dim2i dim, List pages, AtomicReferen } @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.isVisible()) { return; } + updateCursorAlpha(); if (!this.isFocused() && this.text.isBlank()) { String key = "rso.search_bar_empty"; Component emptyText = Component.translatable(key); @@ -109,7 +117,8 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) } // Cursor if (this.isFocused()) { - guiGraphics.fill(RenderType.guiOverlay(), cursorX, textStartY - 1, cursorX + 1, textStartY + 1 + this.font.lineHeight, -3092272); + int color = ((int) (this.currentCursorAlpha * 255) << 24) | 0x00D0D0D0; + guiGraphics.fill(RenderType.guiOverlay(), cursorX, textStartY - 1, cursorX + 1, textStartY + 1 + this.font.lineHeight, color); } // Highlighted text if (selectionEndOffset != selectionStartOffset) { @@ -184,6 +193,9 @@ public void write(String text) { String beforeSelectionText = (new StringBuilder(this.text)).replace(selectionStartIndex, selectionEndIndex, filteredText).toString(); if (this.textPredicate.test(beforeSelectionText)) { + this.currentCursorState = true; + this.nextCursorUpdate = System.currentTimeMillis() + CURSOR_ANIMATION_DURATION; + this.text = beforeSelectionText; this.setSelectionStart(selectionStartIndex + filteredTextLength); this.setSelectionEnd(this.selectionStart); @@ -327,26 +339,24 @@ public void setCursorToEnd() { public void setSelectionEnd(int index) { int textLength = this.text.length(); this.selectionEnd = Mth.clamp(index, 0, textLength); - if (this.font != null) { - if (this.firstCharacterIndex > textLength) { - this.firstCharacterIndex = textLength; - } - - int innerWidth = this.getInnerWidth(); - String displayText = this.font.plainSubstrByWidth(this.text.substring(this.firstCharacterIndex), innerWidth); - int endIndex = displayText.length() + this.firstCharacterIndex; - if (this.selectionEnd == this.firstCharacterIndex) { - this.firstCharacterIndex -= this.font.plainSubstrByWidth(this.text, innerWidth, true).length(); - } + if (this.firstCharacterIndex > textLength) { + this.firstCharacterIndex = textLength; + } - if (this.selectionEnd > endIndex) { - this.firstCharacterIndex += this.selectionEnd - endIndex; - } else if (this.selectionEnd <= this.firstCharacterIndex) { - this.firstCharacterIndex -= this.firstCharacterIndex - this.selectionEnd; - } + int innerWidth = this.getInnerWidth(); + String displayText = this.font.plainSubstrByWidth(this.text.substring(this.firstCharacterIndex), innerWidth); + int endIndex = displayText.length() + this.firstCharacterIndex; + if (this.selectionEnd == this.firstCharacterIndex) { + this.firstCharacterIndex -= this.font.plainSubstrByWidth(this.text, innerWidth, true).length(); + } - this.firstCharacterIndex = Mth.clamp(this.firstCharacterIndex, 0, textLength); + if (this.selectionEnd > endIndex) { + this.firstCharacterIndex += this.selectionEnd - endIndex; + } else if (this.selectionEnd <= this.firstCharacterIndex) { + this.firstCharacterIndex -= this.firstCharacterIndex - this.selectionEnd; } + + this.firstCharacterIndex = Mth.clamp(this.firstCharacterIndex, 0, textLength); } public boolean isActive() { @@ -490,6 +500,28 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { } } + private void updateCursorAlpha() { + long currentTimeMillis = System.currentTimeMillis(); + if (currentTimeMillis >= this.nextCursorUpdate) { + this.currentCursorState = !this.currentCursorState; + this.nextCursorUpdate = currentTimeMillis + CURSOR_ANIMATION_DURATION; + } + + float cursorAlpha = (float) (this.nextCursorUpdate - currentTimeMillis) / CURSOR_ANIMATION_DURATION; + + if (cursorAlpha <= 0.25f) { + cursorAlpha *= 4f; + } else if (cursorAlpha >= 0.75f) { + cursorAlpha = (1 - cursorAlpha) * 4f; + } else { + cursorAlpha = 1f; + } + + cursorAlpha = Math.clamp(cursorAlpha, 0f, 1f); + + this.currentCursorAlpha = this.currentCursorState ? 1 : 1 - cursorAlpha; + } + public boolean isVisible() { return visible; } @@ -510,7 +542,7 @@ public int getInnerWidth() { } @Override - public ScreenRectangle getRectangle() { + public @NotNull ScreenRectangle getRectangle() { return new ScreenRectangle(this.dim.x(), this.dim.y(), this.dim.width(), this.dim.height()); } } \ No newline at end of file diff --git a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/tab/TabFrame.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/tab/TabFrame.java index 93bd41c..61b1ba4 100644 --- a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/tab/TabFrame.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/tab/TabFrame.java @@ -11,6 +11,7 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import org.apache.commons.lang3.Validate; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; @@ -43,7 +44,7 @@ public TabFrame(Dim2i dim, boolean renderOutline, List> tabs, Runnable on this.onSetTab = onSetTab; if (this.tabSectionCanScroll) { - this.tabSectionScrollBar = new ScrollBarComponent(new Dim2i(this.tabSection.getLimitX() - 11, this.tabSection.y(), 10, this.tabSection.height()), ScrollBarComponent.Mode.VERTICAL, tabSectionY, this.dim.height(), offset -> { + this.tabSectionScrollBar = new ScrollBarComponent(new Dim2i(this.tabSection.getLimitX() - 11, this.tabSection.y(), 10, this.tabSection.height()), ScrollBarComponent.ScrollDirection.VERTICAL, tabSectionY, this.dim.height(), offset -> { //this.buildFrame(); tabSectionScrollBarOffset.set(offset); ((Dim2iExtended) ((Object) this.tabSection)).setY(this.dim.y() - this.tabSectionScrollBar.getOffset()); @@ -91,7 +92,7 @@ public void buildFrame() { this.rebuildTabFrame(); if (this.tabSectionCanScroll) { - this.tabSectionScrollBar.updateThumbPosition(); + this.tabSectionScrollBar.updateThumbLocation(); this.children.add(this.tabSectionScrollBar); } @@ -113,9 +114,6 @@ public void buildFrame() { private void rebuildTabs() { int offsetY = 0; for (Tab tab : this.tabs) { - int x = this.tabSection.x(); - int y = this.tabSection.y(); - //int yOffset = offsetY - (this.tabSectionCanScroll ? this.tabSectionScrollBar.getOffset() : 0); int width = this.tabSection.width() - (this.tabSectionCanScroll ? 12 : 4); int height = 18; Dim2i tabDim = new Dim2i(0, offsetY, width, height); @@ -141,7 +139,7 @@ private void rebuildTabFrame() { } @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.applyScissor(guiGraphics, this.dim.x(), this.dim.y(), this.dim.width(), this.dim.height(), () -> { for (AbstractWidget widget : this.children) { if (widget != this.selectedFrame) { diff --git a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinFlatButtonWidget.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinFlatButtonWidget.java index fae6744..09eee41 100644 --- a/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinFlatButtonWidget.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinFlatButtonWidget.java @@ -4,14 +4,13 @@ import net.caffeinemc.mods.sodium.client.gui.widgets.AbstractWidget; import net.caffeinemc.mods.sodium.client.gui.widgets.FlatButtonWidget; import net.caffeinemc.mods.sodium.client.util.Dim2i; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.network.chat.Component; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.ModifyArgs; +import org.spongepowered.asm.mixin.injection.invoke.arg.Args; @Mixin(FlatButtonWidget.class) public abstract class MixinFlatButtonWidget extends AbstractWidget implements FlatButtonWidgetExtended { @@ -23,21 +22,20 @@ public abstract class MixinFlatButtonWidget extends AbstractWidget implements Fl @Unique private boolean leftAligned; - @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/gui/widgets/FlatButtonWidget;drawString(Lnet/minecraft/client/gui/GuiGraphics;Lnet/minecraft/network/chat/Component;III)V")) - public void redirectDrawString(FlatButtonWidget instance, GuiGraphics guiGraphics, Component text, int x, int y, int color) { - if (this.leftAligned) { - this.drawString(guiGraphics, text, this.dim.x() + 10, y, color); - } else { - this.drawString(guiGraphics, text, x, y, color); + @ModifyArgs(method = "render", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/gui/widgets/FlatButtonWidget;drawString(Lnet/minecraft/client/gui/GuiGraphics;Lnet/minecraft/network/chat/Component;III)V")) + public void redirectDrawString(Args args) { + if (this.leftAligned) { // Aligns the text to the left by 10 pixels + //this.drawString(guiGraphics, text, this.dim.x() + 10, y, color); + args.set(2, this.dim.x() + 10); } } - @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/gui/widgets/FlatButtonWidget;drawRect(Lnet/minecraft/client/gui/GuiGraphics;IIIII)V", ordinal = 1)) - public void redirectDrawRect(FlatButtonWidget instance, GuiGraphics guiGraphics, int x1, int y1, int x2, int y2, int color) { + @ModifyArgs(method = "render", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/gui/widgets/FlatButtonWidget;drawRect(Lnet/minecraft/client/gui/GuiGraphics;IIIII)V", ordinal = 1)) + public void redirectDrawRect(Args args) { if (this.leftAligned) { - this.drawRect(guiGraphics, x1, this.dim.y(), x1 + 1, y2, color); - } else { - this.drawRect(guiGraphics, x1, y1, x2, y2, color); + //this.drawRect(guiGraphics, x1, this.dim.y(), x1 + 1, y2, color); + args.set(2, this.dim.y()); + args.set(3, (int) args.get(1) + 1); } } diff --git a/common/src/main/resources/assets/reeses-sodium-options/lang/es_es.json b/common/src/main/resources/assets/reeses-sodium-options/lang/es_es.json new file mode 100644 index 0000000..afff66d --- /dev/null +++ b/common/src/main/resources/assets/reeses-sodium-options/lang/es_es.json @@ -0,0 +1,5 @@ +{ + "rso.search_bar_empty": "Buscar...", + "modmenu.summaryTranslation.reeses-sodium-options": "Sustituye la Pantalla de Opciones de Sodium", + "modmenu.descriptionTranslation.reeses-sodium-options": "Sustituye la pantalla de opciones de Sodium con la intenciĆ³n de mejorar la experiencia de usuario." +} diff --git a/common/src/main/resources/assets/reeses-sodium-options/lang/nl_nl.json b/common/src/main/resources/assets/reeses-sodium-options/lang/nl_nl.json new file mode 100644 index 0000000..0d86a45 --- /dev/null +++ b/common/src/main/resources/assets/reeses-sodium-options/lang/nl_nl.json @@ -0,0 +1,5 @@ +{ + "rso.search_bar_empty": "Zoek opties...", + "modmenu.summaryTranslation.reeses-sodium-options": "Vervangt Sodiums Optie Scherm", + "modmenu.descriptionTranslation.reeses-sodium-options": "Vervangt Sodium's Optie Scherm met als doel de gebruikerservaring te verbeteren (UX)" +} diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 51b1085..7f4fb29 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -39,8 +39,8 @@ } }, "depends": { - "minecraft": ">=1.21", - "sodium": ">=0.6.0-beta.3" + "minecraft": ">=1.21.1", + "sodium": ">=0.6.0" }, "breaks": { "iris": "<1.1.4", diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index daf4e48..d709246 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -19,14 +19,14 @@ Replaces Sodium's Options Screen [[dependencies.reeses_sodium_options]] modId = "minecraft" type = "required" -versionRange = "[1.20.4,1.21.4)" +versionRange = "[1.21,)" ordering = "NONE" side = "CLIENT" [[dependencies.reeses_sodium_options]] modId = "sodium" type = "required" -versionRange = "[0.6.0-beta.3,0.6.0)" +versionRange = "[0.6.0,)" ordering = "NONE" side = "CLIENT"