mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-26 05:28:33 +01:00
added scrolling to the terminal ui
This commit is contained in:
parent
c357550956
commit
01dda04701
2 changed files with 24 additions and 3 deletions
|
@ -11,6 +11,7 @@ import net.minecraft.client.resources.I18n;
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -25,6 +26,7 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
|
||||||
private Button plusButton;
|
private Button plusButton;
|
||||||
private Button requestButton;
|
private Button requestButton;
|
||||||
private int requestAmount = 1;
|
private int requestAmount = 1;
|
||||||
|
private int scrollOffset;
|
||||||
|
|
||||||
public ItemTerminalGui(ItemTerminalContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
public ItemTerminalGui(ItemTerminalContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||||
super(screenContainer, inv, titleIn);
|
super(screenContainer, inv, titleIn);
|
||||||
|
@ -77,14 +79,14 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
|
||||||
|
|
||||||
public void updateItemList(List<ItemStack> items) {
|
public void updateItemList(List<ItemStack> items) {
|
||||||
this.items = items;
|
this.items = items;
|
||||||
this.updateWidgets(0);
|
this.updateWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateWidgets(int scrollOffset) {
|
private void updateWidgets() {
|
||||||
List<ItemTerminalWidget> widgets = this.streamWidgets().collect(Collectors.toList());
|
List<ItemTerminalWidget> widgets = this.streamWidgets().collect(Collectors.toList());
|
||||||
for (int i = 0; i < widgets.size(); i++) {
|
for (int i = 0; i < widgets.size(); i++) {
|
||||||
ItemTerminalWidget widget = widgets.get(i);
|
ItemTerminalWidget widget = widgets.get(i);
|
||||||
int index = i + scrollOffset * 9;
|
int index = i + this.scrollOffset * 9;
|
||||||
if (index >= this.items.size()) {
|
if (index >= this.items.size()) {
|
||||||
widget.stack = ItemStack.EMPTY;
|
widget.stack = ItemStack.EMPTY;
|
||||||
widget.visible = false;
|
widget.visible = false;
|
||||||
|
@ -119,6 +121,25 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
|
||||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||||
this.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
this.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
||||||
this.blit(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
this.blit(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
||||||
|
|
||||||
|
if (this.items != null && this.items.size() >= 9 * 4) {
|
||||||
|
float percentage = this.scrollOffset / (float) (this.items.size() / 9 - 3);
|
||||||
|
this.blit(this.guiLeft + 172, this.guiTop + 18 + (int) (percentage * (70 - 15)), 244, 0, 12, 15);
|
||||||
|
} else {
|
||||||
|
this.blit(this.guiLeft + 172, this.guiTop + 18, 244, 15, 12, 15);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseScrolled(double x, double y, double scroll) {
|
||||||
|
if (this.items != null && this.items.size() >= 9 * 4) {
|
||||||
|
int offset = MathHelper.clamp(this.scrollOffset - (int) Math.signum(scroll), 0, this.items.size() / 9 - 3);
|
||||||
|
if (offset != this.scrollOffset) {
|
||||||
|
this.scrollOffset = offset;
|
||||||
|
this.updateWidgets();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream<ItemTerminalWidget> streamWidgets() {
|
public Stream<ItemTerminalWidget> streamWidgets() {
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Loading…
Reference in a new issue