From 659903ba387cdf8d22eda754ede065c06eb1f23f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 4 Dec 2020 19:51:20 +0100 Subject: [PATCH] added scrolling to the terminal gui Closes #64 --- .../terminal/containers/ItemTerminalGui.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalGui.java b/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalGui.java index 84ea048..9134142 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalGui.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalGui.java @@ -48,6 +48,7 @@ public class ItemTerminalGui extends ContainerScreen { private int requestAmount = 1; private int scrollOffset; private ItemStack hoveredCrafting; + private boolean isScrolling; public ItemTerminalGui(ItemTerminalContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) { super(screenContainer, inv, titleIn); @@ -136,6 +137,15 @@ public class ItemTerminalGui extends ContainerScreen { } } + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (button == 0 && mouseX >= this.guiLeft + this.getXOffset() + 172 && this.guiTop + mouseY >= 18 && mouseX < this.guiLeft + this.getXOffset() + 172 + 12 && mouseY < this.guiTop + 18 + 70) { + this.isScrolling = true; + return true; + } + return super.mouseClicked(mouseX, mouseY, button); + } + @Override public boolean mouseReleased(double mouseX, double mouseY, int button) { // we have to do the click logic here because JEI is activated when letting go of the mouse button @@ -147,9 +157,25 @@ public class ItemTerminalGui extends ContainerScreen { return true; } } + if (button == 0) + this.isScrolling = false; return super.mouseReleased(mouseX, mouseY, button); } + @Override + public boolean mouseDragged(double mouseX, double mouseY, int i, double j, double k) { + if (this.isScrolling) { + float percentage = MathHelper.clamp(((float) mouseY - (this.guiTop + 18) - 7.5F) / (70 - 15), 0, 1); + int offset = (int) (percentage * (float) (this.sortedItems.size() / 9 - 3)); + if (offset != this.scrollOffset) { + this.scrollOffset = offset; + this.updateWidgets(); + } + return true; + } + return super.mouseDragged(mouseX, mouseY, i, j, k); + } + @Override public boolean keyPressed(int x, int y, int z) { // for some reason we have to do this to make the text field allow the inventory key to be typed