Skip to content

Commit

Permalink
Merge branch '1.20.x/dev' into 1.20.x/stable
Browse files Browse the repository at this point in the history
  • Loading branch information
FlashyReese committed Oct 27, 2023
2 parents 04cc700 + 0ca893d commit 39b5397
Show file tree
Hide file tree
Showing 18 changed files with 250 additions and 58 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'org.ajoberstar.grgit' version '5.0.0'
id 'fabric-loom' version '1.3-SNAPSHOT'
id 'org.ajoberstar.grgit' version '5.2.1'
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'maven-publish'
id 'signing'
}
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.1
loader_version=0.14.22
yarn_mappings=1.20.2+build.4
loader_version=0.14.24
# Mod Properties
version_type=release
revision=1
mod_version=1.6.5
mod_version=1.7.0
maven_group=me.flashyreese.mods
archives_base_name=reeses_sodium_options

Expand All @@ -17,4 +17,4 @@ org.gradle.jvmargs=-Xmx1G
iris_version=1.5.2+1.19.4

#Fabric api
fabric_version=0.89.0+1.20.2
fabric_version=0.90.4+1.20.2
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
5 changes: 4 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,13 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import me.jellysquid.mods.sodium.client.util.Dim2i;

public interface Dim2iExtended {
void setPoint2i(Point2i point2i);

void setX(int x);

void setY(int y);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package me.flashyreese.mods.reeses_sodium_options.client.gui;

import me.jellysquid.mods.sodium.client.util.Dim2i;

public interface FlatButtonWidgetExtended {
boolean isLeftAligned();

void setLeftAligned(boolean leftAligned);

Dim2i getDimensions();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package me.flashyreese.mods.reeses_sodium_options.client.gui;

public interface Point2i {
int getX();

void setX(int x);

int getY();

void setY(int y);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public abstract class AbstractFrame extends AbstractWidget implements ParentElement {
protected final Dim2i dim;
Expand All @@ -21,6 +22,7 @@ public abstract class AbstractFrame extends AbstractWidget implements ParentElem
protected boolean renderOutline;
private Element focused;
private boolean dragging;
private Consumer<Element> focusListener;

public AbstractFrame(Dim2i dim, boolean renderOutline) {
this.dim = dim;
Expand Down Expand Up @@ -59,6 +61,10 @@ public void applyScissor(int x, int y, int width, int height, Runnable action) {
RenderSystem.disableScissor();
}

public void registerFocusListener(Consumer<Element> focusListener) {
this.focusListener = focusListener;
}

@Override
public boolean isDragging() {
return this.dragging;
Expand All @@ -78,6 +84,9 @@ public Element getFocused() {
@Override
public void setFocused(@Nullable Element focused) {
this.focused = focused;
if (this.focusListener != null) {
this.focusListener.accept(focused);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.flashyreese.mods.reeses_sodium_options.client.gui.Dim2iExtended;
import me.flashyreese.mods.reeses_sodium_options.client.gui.OptionExtended;
import me.flashyreese.mods.reeses_sodium_options.client.gui.Point2i;
import me.jellysquid.mods.sodium.client.gui.options.Option;
import me.jellysquid.mods.sodium.client.gui.options.OptionGroup;
import me.jellysquid.mods.sodium.client.gui.options.OptionImpact;
Expand All @@ -11,11 +12,14 @@
import me.jellysquid.mods.sodium.client.util.Dim2i;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.navigation.GuiNavigation;
import net.minecraft.client.gui.navigation.GuiNavigationPath;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Language;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -76,7 +80,9 @@ public void buildFrame() {
// Add each option's control element
for (Option<?> option : group.getOptions()) {
Control<?> control = option.getControl();
ControlElement<?> element = control.createElement(new Dim2i(this.dim.x(), this.dim.y() + y, this.dim.width(), 18));
Dim2i dim = new Dim2i(0, y, this.dim.width(), 18);
((Dim2iExtended) (Object) dim).setPoint2i(((Point2i) (Object) this.dim));
ControlElement<?> element = control.createElement(dim);
this.children.add(element);

// Move down to the next option
Expand Down Expand Up @@ -162,6 +168,11 @@ private void renderOptionTooltip(DrawContext drawContext, ControlElement<?> elem
drawContext.getMatrices().pop();
}

@Override
public @Nullable GuiNavigationPath getNavigationPath(GuiNavigation navigation) {
return super.getNavigationPath(navigation);
}

public static class Builder {
private Dim2i dim;
private boolean renderOutline;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ 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.buildFrame();
//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.buildFrame();
//this.buildFrame();
((Dim2iExtended) ((Object) this.frame.dim)).setY(this.frameOrigin.y() - this.verticalScrollBar.getOffset());
verticalScrollBarOffset.set(offset);
}, this.viewPortDimension);
this.verticalScrollBar.setOffset(verticalScrollBarOffset.get());
Expand Down Expand Up @@ -112,6 +114,22 @@ public void buildFrame() {
this.frame.buildFrame();
this.children.add(this.frame);
super.buildFrame();

// fixme: Ridiculous hack to snap to focused element
// for the meanwhile this works until a proper solution is implemented.
// this shouldn't be hardcoded into scrollable frame
this.frame.registerFocusListener(element -> {
if (element instanceof ControlElement<?> controlElement && this.canScrollVertical) {
Dim2i dim = controlElement.getDimensions();
int inputOffset = this.verticalScrollBar.getOffset();
if (dim.y() <= this.viewPortDimension.y()) {
inputOffset += dim.y() - this.viewPortDimension.y();
} else if (dim.getLimitY() >= this.viewPortDimension.getLimitY()) {
inputOffset += dim.getLimitY() - this.viewPortDimension.getLimitY();
}
this.verticalScrollBar.setOffset(inputOffset);
}
});
}

@Override
Expand All @@ -134,26 +152,6 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)
}
}

// fixme: Ridiculous hack to snap to focused element, it also unfocuses the element for some unknown reason :>
// for the meanwhile this works until a proper solution is implemented.
// this shouldn't be hardcoded into scrollable frame
private void snapFocusedInViewport() {
if (this.frame.getFocused() instanceof ControlElement controlElement) {
Dim2i dim = controlElement.getDimensions();
if (this.canScrollVertical && !(dim.y() >= viewPortDimension.y() && dim.getLimitY() <= viewPortDimension.getLimitY())) {
int newOffset = this.verticalScrollBar.getOffset();
if (dim.y() < this.viewPortDimension.y()) {
newOffset -= 23;
} else if (dim.getLimitY() > this.viewPortDimension.getLimitY()) {
newOffset += 23; // widget size of 18 and 4 gap for groups
}

this.verticalScrollBar.setOffset(newOffset);
controlElement.setFocused(true);
}
}
}

@Override
public @Nullable GuiNavigationPath getNavigationPath(GuiNavigation navigation) {
//this.snapFocusedInViewport();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package me.flashyreese.mods.reeses_sodium_options.client.gui.frame.tab;

import me.flashyreese.mods.reeses_sodium_options.client.gui.Dim2iExtended;
import me.flashyreese.mods.reeses_sodium_options.client.gui.FlatButtonWidgetExtended;
import me.flashyreese.mods.reeses_sodium_options.client.gui.Point2i;
import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.AbstractFrame;
import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.components.ScrollBarComponent;
import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement;
import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget;
import me.jellysquid.mods.sodium.client.gui.widgets.FlatButtonWidget;
import me.jellysquid.mods.sodium.client.util.Dim2i;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.ScreenRect;
import net.minecraft.text.Text;
import org.apache.commons.lang3.Validate;

Expand Down Expand Up @@ -43,8 +45,9 @@ public TabFrame(Dim2i dim, boolean renderOutline, List<Tab<?>> 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.buildFrame();
//this.buildFrame();
tabSectionScrollBarOffset.set(offset);
((Dim2iExtended) ((Object) this.tabSection)).setY(this.dim.y() - this.tabSectionScrollBar.getOffset());
}, this.dim);
this.tabSectionScrollBar.setOffset(tabSectionScrollBarOffset.get());
}
Expand Down Expand Up @@ -91,19 +94,34 @@ public void buildFrame() {

if (this.tabSectionCanScroll) {
this.tabSectionScrollBar.updateThumbPosition();
this.children.add(this.tabSectionScrollBar);
}

super.buildFrame();
this.registerFocusListener(element -> {
if (element instanceof FlatButtonWidgetExtended flatButtonWidget && this.tabSectionCanScroll) {
Dim2i dim = flatButtonWidget.getDimensions();
int inputOffset = this.tabSectionScrollBar.getOffset();
if (dim.y() <= this.dim.y()) {
inputOffset += dim.y() - this.dim.y();
} else if (dim.getLimitY() >= this.dim.getLimitY()) {
inputOffset += dim.getLimitY() - this.dim.getLimitY();
}
this.tabSectionScrollBar.setOffset(inputOffset);
}
});
}

private void rebuildTabs() {
int offsetY = 0;
for (Tab<?> tab : this.tabs) {
int x = this.tabSection.x();
int y = this.tabSection.y() + offsetY - (this.tabSectionCanScroll ? this.tabSectionScrollBar.getOffset() : 0);
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(x, y, width, height);
Dim2i tabDim = new Dim2i(0, offsetY, width, height);
((Dim2iExtended)(Object) tabDim).setPoint2i(((Point2i)(Object) this.tabSection));

FlatButtonWidget button = new FlatButtonWidget(tabDim, tab.getTitle(), () -> this.setTab(tab));
button.setSelected(this.selectedTab == tab);
Expand Down
Loading

0 comments on commit 39b5397

Please sign in to comment.