2022-05-06 22:41:45 +03:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
2023-09-25 00:35:24 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
import codechicken.lib.vec.Rectangle4i;
|
|
|
|
|
import codechicken.nei.ItemPanel.ItemPanelSlot;
|
2022-05-06 22:41:45 +03:00
|
|
|
import codechicken.nei.api.GuiInfo;
|
|
|
|
|
import codechicken.nei.api.INEIGuiHandler;
|
|
|
|
|
import codechicken.nei.guihook.GuiContainerManager;
|
|
|
|
|
import codechicken.nei.recipe.GuiCraftingRecipe;
|
|
|
|
|
import codechicken.nei.recipe.GuiRecipe;
|
|
|
|
|
import codechicken.nei.recipe.GuiUsageRecipe;
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public abstract class PanelWidget extends Widget {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
protected static final int PADDING = 2;
|
|
|
|
|
|
2022-10-13 11:06:08 +03:00
|
|
|
public ItemStack draggedStack;
|
2022-05-06 22:41:45 +03:00
|
|
|
public int mouseDownSlot = -1;
|
|
|
|
|
|
|
|
|
|
public Button pagePrev;
|
|
|
|
|
public Button pageNext;
|
|
|
|
|
public Label pageLabel;
|
|
|
|
|
|
|
|
|
|
protected ItemsGrid grid;
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public ArrayList<ItemStack> getItems() {
|
2022-05-06 22:41:45 +03:00
|
|
|
return grid.getItems();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public ItemsGrid getGrid() {
|
2022-05-06 22:41:45 +03:00
|
|
|
return grid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void init() {
|
|
|
|
|
pageLabel = new Label("0/0", true);
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
pagePrev = new Button("Prev") {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
public boolean onButtonPress(boolean rightclick) {
|
|
|
|
|
if (!rightclick) {
|
|
|
|
|
grid.shiftPage(-1);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getRenderLabel() {
|
|
|
|
|
return "<";
|
|
|
|
|
}
|
|
|
|
|
};
|
2022-06-24 12:32:13 +01:00
|
|
|
pageNext = new Button("Next") {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
public boolean onButtonPress(boolean rightclick) {
|
|
|
|
|
if (!rightclick) {
|
|
|
|
|
grid.shiftPage(1);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getRenderLabel() {
|
|
|
|
|
return ">";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract String getLabelText();
|
|
|
|
|
|
|
|
|
|
protected abstract String getPositioningSettingName();
|
|
|
|
|
|
|
|
|
|
public abstract int getMarginLeft(GuiContainer gui);
|
|
|
|
|
|
|
|
|
|
public abstract int getMarginTop(GuiContainer gui);
|
|
|
|
|
|
|
|
|
|
public abstract int getWidth(GuiContainer gui);
|
|
|
|
|
|
|
|
|
|
public abstract int getHeight(GuiContainer gui);
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public void resize(GuiContainer gui) {
|
|
|
|
|
final Rectangle4i margin = new Rectangle4i(
|
|
|
|
|
getMarginLeft(gui),
|
|
|
|
|
getMarginTop(gui),
|
|
|
|
|
getWidth(gui),
|
|
|
|
|
getHeight(gui));
|
2022-05-06 22:41:45 +03:00
|
|
|
|
|
|
|
|
final int minWidth = 5 * ItemsGrid.SLOT_SIZE;
|
|
|
|
|
final int minHeight = 9 * ItemsGrid.SLOT_SIZE;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
final String settingName = getPositioningSettingName();
|
2022-06-24 12:32:13 +01:00
|
|
|
int paddingLeft = (int) Math
|
|
|
|
|
.ceil(margin.w * NEIClientConfig.getSetting(settingName + ".left").getIntValue() / 100000.0);
|
|
|
|
|
int paddingTop = (int) Math
|
|
|
|
|
.ceil(margin.h * NEIClientConfig.getSetting(settingName + ".top").getIntValue() / 100000.0);
|
|
|
|
|
int paddingRight = (int) Math
|
|
|
|
|
.ceil(margin.w * NEIClientConfig.getSetting(settingName + ".right").getIntValue() / 100000.0);
|
|
|
|
|
int paddingBottom = (int) Math
|
|
|
|
|
.ceil(margin.h * NEIClientConfig.getSetting(settingName + ".bottom").getIntValue() / 100000.0);
|
2022-05-06 22:41:45 +03:00
|
|
|
|
|
|
|
|
int deltaHeight = Math.min(0, margin.h - paddingTop - paddingBottom - minHeight) / 2;
|
|
|
|
|
|
|
|
|
|
paddingLeft = Math.min(paddingLeft, Math.max(0, margin.w - paddingRight - minWidth));
|
|
|
|
|
paddingRight = Math.min(paddingRight, Math.max(0, margin.w - paddingLeft - minWidth));
|
|
|
|
|
paddingTop = Math.min(margin.h - minHeight, Math.max(0, paddingTop + deltaHeight));
|
|
|
|
|
paddingBottom = Math.min(margin.h - paddingTop - minHeight, Math.max(0, paddingBottom - deltaHeight));
|
|
|
|
|
|
|
|
|
|
x = margin.x + paddingLeft;
|
|
|
|
|
y = margin.y + paddingTop;
|
|
|
|
|
w = margin.w - paddingLeft - paddingRight;
|
|
|
|
|
h = margin.h - paddingTop - paddingBottom;
|
|
|
|
|
|
|
|
|
|
final int header = resizeHeader(gui);
|
|
|
|
|
final int footer = resizeFooter(gui);
|
|
|
|
|
|
|
|
|
|
grid.setGridSize(x, y + header, w, h - header - footer);
|
|
|
|
|
grid.refresh(gui);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected int resizeHeader(GuiContainer gui) {
|
2022-05-06 22:41:45 +03:00
|
|
|
final int BUTTON_SIZE = 16;
|
|
|
|
|
int paddingLeft = 0;
|
|
|
|
|
int paddingRight = 0;
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
while (paddingLeft < w && GuiInfo.hideItemPanelSlot(
|
|
|
|
|
gui,
|
|
|
|
|
new Rectangle4i(x + paddingLeft, y, ItemsGrid.SLOT_SIZE, ItemsGrid.SLOT_SIZE))) {
|
2022-05-06 22:41:45 +03:00
|
|
|
paddingLeft += ItemsGrid.SLOT_SIZE;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
while (paddingRight < w && GuiInfo.hideItemPanelSlot(
|
|
|
|
|
gui,
|
|
|
|
|
new Rectangle4i(
|
|
|
|
|
x + w - paddingRight - ItemsGrid.SLOT_SIZE,
|
|
|
|
|
y,
|
|
|
|
|
ItemsGrid.SLOT_SIZE,
|
|
|
|
|
ItemsGrid.SLOT_SIZE))) {
|
2022-05-06 22:41:45 +03:00
|
|
|
paddingRight += ItemsGrid.SLOT_SIZE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (paddingLeft + paddingRight >= w) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pagePrev.w = pageNext.w = BUTTON_SIZE;
|
|
|
|
|
pagePrev.h = pageNext.h = BUTTON_SIZE;
|
|
|
|
|
pagePrev.y = pageNext.y = y;
|
|
|
|
|
|
|
|
|
|
pagePrev.x = x + paddingLeft;
|
|
|
|
|
pageNext.x = x + w - pageNext.w - paddingRight;
|
|
|
|
|
|
|
|
|
|
pageLabel.x = x + paddingLeft + (w - paddingLeft - paddingRight) / 2;
|
|
|
|
|
pageLabel.y = y + 5;
|
|
|
|
|
pageLabel.text = getLabelText();
|
|
|
|
|
|
|
|
|
|
return BUTTON_SIZE + 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract int resizeFooter(GuiContainer gui);
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public void setVisible() {
|
2022-05-06 22:41:45 +03:00
|
|
|
if (grid.getPerPage() > 0) {
|
|
|
|
|
LayoutManager.addWidget(pagePrev);
|
|
|
|
|
LayoutManager.addWidget(pageNext);
|
|
|
|
|
LayoutManager.addWidget(pageLabel);
|
2022-08-31 17:43:22 +09:00
|
|
|
grid.setVisible();
|
2022-05-06 22:41:45 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-10 17:38:07 +01:00
|
|
|
@Override
|
|
|
|
|
public void update() {
|
|
|
|
|
grid.update();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void draw(int mousex, int mousey) {
|
2022-05-06 22:41:45 +03:00
|
|
|
grid.draw(mousex, mousey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void postDraw(int mousex, int mousey) {
|
2022-05-06 22:41:45 +03:00
|
|
|
if (draggedStack != null) {
|
|
|
|
|
GuiContainerManager.drawItems.zLevel += 100;
|
|
|
|
|
GuiContainerManager.drawItem(mousex - 8, mousey - 8, draggedStack);
|
|
|
|
|
GuiContainerManager.drawItems.zLevel -= 100;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-10 17:38:07 +01:00
|
|
|
@Override
|
|
|
|
|
public void postDrawTooltips(int mx, int my, List<String> tooltip) {
|
|
|
|
|
grid.postDrawTooltips(mx, my, tooltip);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void mouseDragged(int mousex, int mousey, int button, long heldTime) {
|
|
|
|
|
if (mouseDownSlot >= 0 && draggedStack == null
|
|
|
|
|
&& NEIClientUtils.getHeldItem() == null
|
2022-09-18 19:08:16 +09:00
|
|
|
&& NEIClientConfig.hasSMPCounterPart()) {
|
2022-05-06 22:41:45 +03:00
|
|
|
ItemPanelSlot mouseOverSlot = getSlotMouseOver(mousex, mousey);
|
|
|
|
|
|
|
|
|
|
if (mouseOverSlot == null || mouseOverSlot.slotIndex != mouseDownSlot || heldTime > 500) {
|
|
|
|
|
draggedStack = getDraggedStackWithQuantity(mouseDownSlot);
|
|
|
|
|
mouseDownSlot = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract ItemStack getDraggedStackWithQuantity(int mouseDownSlot);
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public boolean handleClick(int mousex, int mousey, int button) {
|
2022-05-06 22:41:45 +03:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
if (handleClickExt(mousex, mousey, button)) return true;
|
2022-05-06 22:41:45 +03:00
|
|
|
|
|
|
|
|
if (NEIClientUtils.getHeldItem() != null) {
|
|
|
|
|
|
|
|
|
|
if (!grid.contains(mousex, mousey)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-19 15:03:42 +03:00
|
|
|
if (NEIClientConfig.canPerformAction("delete") && NEIClientConfig.canPerformAction("item")) {
|
|
|
|
|
if (button == 1) {
|
|
|
|
|
NEIClientUtils.decreaseSlotStack(-999);
|
|
|
|
|
} else {
|
|
|
|
|
NEIClientUtils.deleteHeldItem();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
NEIClientUtils.dropHeldItem();
|
|
|
|
|
}
|
2022-05-06 22:41:45 +03:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ItemPanelSlot hoverSlot = getSlotMouseOver(mousex, mousey);
|
|
|
|
|
if (hoverSlot != null) {
|
|
|
|
|
|
|
|
|
|
if (button == 2) {
|
|
|
|
|
|
|
|
|
|
if (hoverSlot.item != null) {
|
|
|
|
|
draggedStack = getDraggedStackWithQuantity(hoverSlot.slotIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
mouseDownSlot = hoverSlot.slotIndex;
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public boolean handleClickExt(int mouseX, int mouseY, int button) {
|
2022-05-06 22:41:45 +03:00
|
|
|
|
2022-10-13 11:06:08 +03:00
|
|
|
if (ItemPanels.itemPanel.draggedStack != null && ItemPanels.bookmarkPanel.contains(mouseX, mouseY)) {
|
|
|
|
|
ItemPanels.bookmarkPanel.addOrRemoveItem(ItemPanels.itemPanel.draggedStack, null, null, false, true);
|
|
|
|
|
ItemPanels.itemPanel.draggedStack = null;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-05-06 22:41:45 +03:00
|
|
|
|
2022-10-13 11:06:08 +03:00
|
|
|
if (ItemPanels.itemPanel.draggedStack != null) {
|
|
|
|
|
return ItemPanels.itemPanel.handleDraggedClick(mouseX, mouseY, button);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ItemPanels.bookmarkPanel.draggedStack != null) {
|
|
|
|
|
return ItemPanels.bookmarkPanel.handleDraggedClick(mouseX, mouseY, button);
|
2022-09-18 19:08:16 +09:00
|
|
|
}
|
2022-10-13 11:06:08 +03:00
|
|
|
|
2022-08-19 15:03:42 +03:00
|
|
|
if (NEIClientUtils.getHeldItem() != null) {
|
|
|
|
|
final ItemStack draggedStack = NEIClientUtils.getHeldItem().copy();
|
2022-08-23 22:15:37 +03:00
|
|
|
return handleGUIContainerClick(draggedStack, mouseX, mouseY, button);
|
2022-08-19 15:03:42 +03:00
|
|
|
}
|
|
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected boolean handleDraggedClick(int mouseX, int mouseY, int button) {
|
2022-10-13 11:06:08 +03:00
|
|
|
if (draggedStack == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (handleGUIContainerClick(draggedStack, mouseX, mouseY, button)) {
|
|
|
|
|
|
|
|
|
|
if (draggedStack.stackSize == 0) {
|
|
|
|
|
draggedStack = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final GuiContainer gui = NEIClientUtils.getGuiContainer();
|
|
|
|
|
if (mouseX < gui.guiLeft || mouseY < gui.guiTop
|
|
|
|
|
|| mouseX >= gui.guiLeft + gui.xSize
|
|
|
|
|
|| mouseY >= gui.guiTop + gui.ySize) {
|
|
|
|
|
draggedStack = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2022-05-06 22:41:45 +03:00
|
|
|
}
|
|
|
|
|
|
2022-08-19 15:03:42 +03:00
|
|
|
protected boolean handleGUIContainerClick(final ItemStack draggedStack, int mouseX, int mouseY, int button) {
|
2022-05-06 22:41:45 +03:00
|
|
|
final GuiContainer gui = NEIClientUtils.getGuiContainer();
|
|
|
|
|
boolean handled = false;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
GuiInfo.readLock.lock();
|
|
|
|
|
for (INEIGuiHandler handler : GuiInfo.guiHandlers) {
|
|
|
|
|
if (handler.handleDragNDrop(gui, mouseX, mouseY, draggedStack, button)) {
|
|
|
|
|
handled = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
GuiInfo.readLock.unlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return handled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void mouseUp(int mousex, int mousey, int button) {
|
2022-05-06 22:41:45 +03:00
|
|
|
ItemPanelSlot hoverSlot = getSlotMouseOver(mousex, mousey);
|
|
|
|
|
|
|
|
|
|
if (hoverSlot != null && hoverSlot.slotIndex == mouseDownSlot && draggedStack == null) {
|
|
|
|
|
ItemStack item = hoverSlot.item;
|
|
|
|
|
|
|
|
|
|
if (NEIController.manager.window instanceof GuiRecipe || !NEIClientConfig.canCheatItem(item)) {
|
|
|
|
|
|
|
|
|
|
if (button == 0) {
|
|
|
|
|
GuiCraftingRecipe.openRecipeGui("item", item);
|
|
|
|
|
} else if (button == 1) {
|
|
|
|
|
GuiUsageRecipe.openRecipeGui("item", item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mouseDownSlot = -1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NEIClientUtils.cheatItem(getDraggedStackWithQuantity(hoverSlot.slotIndex), button, -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mouseDownSlot = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public boolean onMouseWheel(int i, int mousex, int mousey) {
|
|
|
|
|
if (!contains(mousex, mousey)) return false;
|
2022-05-06 22:41:45 +03:00
|
|
|
|
|
|
|
|
grid.shiftPage(-i);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public boolean handleKeyPress(int keyID, char keyChar) {
|
2022-05-06 22:41:45 +03:00
|
|
|
|
2022-08-19 15:03:42 +03:00
|
|
|
if (NEIClientConfig.isKeyHashDown("gui.next")) {
|
2022-05-06 22:41:45 +03:00
|
|
|
grid.shiftPage(1);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-19 15:03:42 +03:00
|
|
|
if (NEIClientConfig.isKeyHashDown("gui.prev")) {
|
2022-05-06 22:41:45 +03:00
|
|
|
grid.shiftPage(-1);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public ItemStack getStackMouseOver(int mousex, int mousey) {
|
2022-05-06 22:41:45 +03:00
|
|
|
ItemPanelSlot slot = getSlotMouseOver(mousex, mousey);
|
|
|
|
|
return slot == null ? null : slot.item;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public ItemPanelSlot getSlotMouseOver(int mousex, int mousey) {
|
2022-05-06 22:41:45 +03:00
|
|
|
return grid.getSlotMouseOver(mousex, mousey);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public int getPage() {
|
2022-06-23 01:03:29 +03:00
|
|
|
return grid.getPage();
|
2022-05-06 22:41:45 +03:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public int getNumPages() {
|
2022-06-23 01:03:29 +03:00
|
|
|
return grid.getNumPages();
|
2022-05-06 22:41:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public boolean contains(int px, int py) {
|
2022-05-06 22:41:45 +03:00
|
|
|
return grid.contains(px, py);
|
|
|
|
|
}
|
|
|
|
|
}
|