From 070167cad90c2d718ee2abbd96e249078a6f0298 Mon Sep 17 00:00:00 2001 From: Ennui Langeweile <85590273+EnnuiL@users.noreply.github.com> Date: Sun, 1 Oct 2023 19:23:53 -0300 Subject: [PATCH] Rewrite config screen (2) --- gradle/libs.versions.toml | 2 +- .../screen/v2/OkZoomerEntryListWidget.java | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index bd04673..ee6d62c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] minecraft = "1.20.1" quilt_mappings = "1.20.1+build.23" # Latest version is available at https://lambdaurora.dev/tools/import_quilt.html -quilt_loader = "0.20.0" +quilt_loader = "0.20.2" quilted_fabric_api = "7.1.2+0.87.0-1.20.1" libzoomer = "0.7.0+1.20" diff --git a/src/main/java/io/github/ennuil/ok_zoomer/config/screen/v2/OkZoomerEntryListWidget.java b/src/main/java/io/github/ennuil/ok_zoomer/config/screen/v2/OkZoomerEntryListWidget.java index 3671008..b308481 100644 --- a/src/main/java/io/github/ennuil/ok_zoomer/config/screen/v2/OkZoomerEntryListWidget.java +++ b/src/main/java/io/github/ennuil/ok_zoomer/config/screen/v2/OkZoomerEntryListWidget.java @@ -10,6 +10,7 @@ import net.minecraft.util.CommonColors; import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.Nullable; +import org.lwjgl.glfw.GLFW; import org.quiltmc.loader.api.minecraft.ClientOnly; import java.util.ArrayList; @@ -28,6 +29,7 @@ public class OkZoomerEntryListWidget extends AbstractParentElement implements Dr private final int contentWidth = 220; private int contentHeight; private int scrollAmount; + private boolean scrolling; public OkZoomerEntryListWidget(MinecraftClient client, int width, int height, int x, int y) { this.client = client; @@ -42,6 +44,8 @@ public OkZoomerEntryListWidget(MinecraftClient client, int width, int height, in this.scrollAmount = 0; + this.scrolling = false; + for (int i = 0; i < 25; i++) { this.children.add(new ButtonEntry()); this.children.add(new TextEntry()); @@ -133,6 +137,14 @@ public boolean isMouseOver(double mouseX, double mouseY) { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (!this.scrolling) { + int pos = (this.width - x) / 2 + 156; + if (mouseX > pos) { + this.scrolling = true; + return true; + } + } + if (!this.isMouseOver(mouseX, mouseY)) { return false; } @@ -146,6 +158,39 @@ public boolean mouseScrolled(double mouseX, double mouseY, double amount) { return true; } + @Override + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { + if (super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) { + return true; + } else if (button == GLFW.GLFW_MOUSE_BUTTON_1 && this.scrolling) { + if (mouseY < this.y) { + this.setScrollAmount(0); + } else if (mouseY > this.y + this.height) { + this.setScrollAmount(this.contentHeight); + } else { + // TODO - Complete this + int size = MathHelper.clamp((this.height * this.height) / this.contentHeight, 0, this.height - 6); + + double a = Math.max(1.0, ((double) this.contentHeight / (this.height - size))); + this.setScrollAmount(this.getScrollAmount() + (int) (deltaY * a)); + } + + return true; + } + + return false; + } + + @Override + public boolean mouseReleased(double mouseX, double mouseY, int button) { + if (this.scrolling) { + this.scrolling = false; + return true; + } else { + return super.mouseReleased(mouseX, mouseY, button); + } + } + @Override public void setFocusedChild(@Nullable Element child) { super.setFocusedChild(child);