Skip to content

Commit

Permalink
Rewrite config screen (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
EnnuiL committed Oct 1, 2023
1 parent 888ef4c commit 070167c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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());
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down

0 comments on commit 070167c

Please sign in to comment.