@Override public void updatePosition(int parentX, int parentY, int parentSizeX, int parentSizeY) { // at most as big as the parent this.ySize = calcCappedYSize(parentSizeY - 10); // slider needed? if (getDisplayedRows() < getTotalRows()) { slider.enable(); this.xSize = columns * slot.w + slider.width + 2 * border.w; } else { slider.disable(); this.xSize = columns * slot.w + border.w * 2; } // update position super.updatePosition(parentX, parentY, parentSizeX, parentSizeY); // connected needs to move to the side if (connected) { if (yOffset == 0) { if (right) { border.cornerTopLeft = overlapTop; } else { border.cornerTopRight = overlapTop; } } xOffset = (border.w - 1) * (right ? -1 : 1); guiLeft += xOffset; } else { xOffset = 0; } // move it a bit this.guiTop += yOffset; border.setPosition(guiLeft, guiTop); border.setSize(xSize, ySize); int y = guiTop + border.h; int h = ySize - border.h * 2; if (shouldDrawName()) { y += textBackground.h; h -= textBackground.h; } slider.setPosition(guiLeft + columns * slot.w + border.w, y); slider.setSize(h); slider.setSliderParameters(0, getTotalRows() - getDisplayedRows(), 1); updateSlots(); }
// updates slot visibility protected void updateSlots() { firstSlotId = slider.getValue() * columns; lastSlotId = Math.min(slotCount, firstSlotId + getDisplayedRows() * columns); int xd = border.w + xOffset; int yd = border.h + yOffset; if (shouldDrawName()) { yd += textBackground.h; } for (Object o : inventorySlots.inventorySlots) { Slot slot = (Slot) o; if (shouldDrawSlot(slot)) { // calc position of the slot int offset = slot.getSlotIndex() - firstSlotId; int x = (offset % columns) * this.slot.w; int y = (offset / columns) * this.slot.h; slot.xDisplayPosition = xd + x + 1; slot.yDisplayPosition = yd + y + 1; if (this.right) { slot.xDisplayPosition += parent.realWidth; } else { slot.xDisplayPosition -= this.xSize; } } else { slot.xDisplayPosition = 0; slot.yDisplayPosition = 0; } } }
protected void updateSlider() { int max = 0; if (sliderActive) { slider.show(); max = slotCount / columns - rows + 1; // the assumption here is that for an active slider this always is >0 } else { slider.hide(); } slider.setPosition(guiLeft + xSize - slider.width, guiTop); slider.setSize(ySize); slider.setSliderParameters(0, max, 1); }
public void update(int mouseX, int mouseY) { if (!sliderActive) { return; } slider.update( mouseX, mouseY, !isMouseOverFullSlot(mouseX, mouseY) && isMouseInModule(mouseX, mouseY)); updateSlots(); }
@Override public boolean shouldDrawSlot(Slot slot) { if (slot.getSlotIndex() >= slotCount) { return false; } // all visible if (!slider.isEnabled()) { return true; } return firstSlotId <= slot.getSlotIndex() && lastSlotId > slot.getSlotIndex(); }
@Override public boolean shouldDrawSlot(Slot slot) { // all visible if (!slider.isEnabled()) { return true; } int index = slot.getSlotIndex(); return (firstSlotId <= index && lastSlotId > index); // inside visible area // || indexStart > index || indexEnd <= index; // or not our concern }
@Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { this.mc.getTextureManager().bindTexture(GuiGeneric.LOCATION); if (!slider.isHidden()) { slider.draw(); updateSlots(); } // fully filled rows int fullRows = (lastSlotId - firstSlotId) / columns; int w = columns * slot.w; int y; for (y = 0; y < fullRows * slot.h && y < ySize; y += slot.h) { slot.drawScaledX(guiLeft, guiTop + y, w); } // draw partial row and unused slots int slotsLeft = (lastSlotId - firstSlotId) % columns; if (slotsLeft > 0) { slot.drawScaledX(guiLeft, guiTop + y, slotsLeft * slot.w); // empty slots that don't exist slotEmpty.drawScaledX(guiLeft + slotsLeft * slot.w, guiTop + y, w - slotsLeft * slot.w); } }
// updates slot visibility public void updateSlots() { // calculate displayed slots firstSlotId = slider.getValue() * columns; lastSlotId = Math.min(slotCount, firstSlotId + rows * columns); for (Slot slot : container.inventorySlots) { if (shouldDrawSlot(slot)) { // calc position of the slot int offset = slot.getSlotIndex() - firstSlotId; int x = (offset % columns) * GuiDynInventory.slot.w; int y = (offset / columns) * GuiDynInventory.slot.h; slot.xDisplayPosition = xOffset + x + 1; slot.yDisplayPosition = yOffset + y + 1; } else { slot.xDisplayPosition = 0; slot.yDisplayPosition = 0; } } }
@Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { guiLeft += border.w; guiTop += border.h; GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(GUI_INVENTORY); int x = guiLeft; // + border.w; int y = guiTop; // + border.h; int midW = xSize - border.w * 2; int midH = ySize - border.h * 2; border.draw(); if (shouldDrawName()) { textBackground.drawScaledX(x, y, midW); y += textBackground.h; } this.mc.getTextureManager().bindTexture(GUI_INVENTORY); drawSlots(x, y); /* // draw the connection to the main thing if(right) { x = guiLeft; y = guiTop; if(guiTop == parent.cornerY) { borderTop.drawScaledX(x, y, overlapTopLeft.w); } else { overlapTopLeft.draw(x, y); } y += cornerTopLeft.h; overlap.drawScaledY(x, y, midH); y += midH; if(guiBottom() == parent.cornerX + parent.realHeight) { borderBottom.drawScaledX(x, y, overlapBottomLeft.w); } else { overlapBottomLeft.draw(x, y); } } else if(slider.isEnabled()) { y = guiTop; borderTop.drawScaledX(x, y, cornerTopRight.w); y += cornerTopRight.h; overlap.drawScaledY(x, y, midH); y += midH; borderBottom.drawScaledX(x, y, cornerBottomRight.w); x = guiRight() - 1; y = guiTop; if(guiTop == parent.cornerY) { borderTop.drawScaledX(x, y, overlapTopRight.w); } else { overlapTopRight.draw(x, y); } y += cornerTopRight.h; overlap.drawScaledY(x, y, midH); y += midH; if(guiBottom() == parent.cornerX + parent.realHeight) { borderBottom.drawScaledX(x, y, overlapBottomRight.w); } else { overlapBottomRight.draw(x, y); } } */ // slider if (slider.isEnabled()) { slider.update( mouseX, mouseY, !isMouseOverFullSlot(mouseX, mouseY) && isMouseInModule(mouseX, mouseY)); slider.draw(); updateSlots(); } guiLeft -= border.w; guiTop -= border.h; }