added scrolling to the terminal gui

Closes #64
This commit is contained in:
Ell 2020-12-04 19:51:20 +01:00
parent 0255340626
commit 659903ba38

View file

@ -48,6 +48,7 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
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<ItemTerminalContainer> {
}
}
@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<ItemTerminalContainer> {
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