2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
2023-09-25 00:34:42 +02:00
|
|
|
import java.util.ArrayList;
|
2024-07-26 18:44:54 +03:00
|
|
|
import java.util.List;
|
2025-04-24 18:48:40 +03:00
|
|
|
import java.util.Map;
|
2023-09-25 00:35:24 +02:00
|
|
|
|
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
2024-08-17 23:24:27 +03:00
|
|
|
import codechicken.lib.gui.GuiDraw;
|
2025-04-24 18:48:40 +03:00
|
|
|
import codechicken.nei.ItemsPanelGrid.ItemsPanelGridSlot;
|
|
|
|
|
import codechicken.nei.util.NEIMouseUtils;
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public class ItemPanel extends PanelWidget<ItemsPanelGrid> {
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2020-01-20 09:42:39 -08:00
|
|
|
/**
|
|
|
|
|
* Backwards compat :-/
|
|
|
|
|
*/
|
2022-05-16 19:03:09 +02:00
|
|
|
@SuppressWarnings("unused")
|
2022-01-02 23:30:54 +02:00
|
|
|
@Deprecated
|
|
|
|
|
private int itemsPerPage = 0;
|
|
|
|
|
|
|
|
|
|
@Deprecated
|
2020-01-20 09:42:39 -08:00
|
|
|
public static ArrayList<ItemStack> items = new ArrayList<>();
|
|
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
@Deprecated
|
2020-01-20 09:42:39 -08:00
|
|
|
public ArrayList<ItemStack> realItems = new ArrayList<>();
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-05-16 19:03:09 +02:00
|
|
|
public ItemStack getStackMouseOver(int mousex, int mousey) {
|
|
|
|
|
// *looks angrily at AppleCore*
|
|
|
|
|
return super.getStackMouseOver(mousex, mousey);
|
2022-06-24 12:32:13 +01:00
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public ItemHistoryPanel historyPanel = new ItemHistoryPanel();
|
2024-07-26 18:44:54 +03:00
|
|
|
public Button toggleGroups;
|
2022-01-03 16:55:39 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
@Deprecated
|
|
|
|
|
public static class ItemPanelSlot extends ItemsPanelGridSlot {
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
@Deprecated
|
|
|
|
|
public ItemPanelSlot(int idx, ItemStack item) {
|
|
|
|
|
this(idx, 0, item);
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Deprecated
|
2022-06-24 12:32:13 +01:00
|
|
|
public ItemPanelSlot(int idx) {
|
2025-04-24 18:48:40 +03:00
|
|
|
this(idx, 0, ItemPanels.itemPanel.getGrid().getItem(idx));
|
2024-07-26 18:44:54 +03:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
private ItemPanelSlot(int slotIndex, int itemIndex, ItemStack item) {
|
|
|
|
|
super(slotIndex, itemIndex, item);
|
2024-07-26 18:44:54 +03:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
protected static ItemPanelSlot of(ItemsPanelGridSlot slot) {
|
2024-07-26 18:44:54 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (slot != null) {
|
|
|
|
|
ItemPanelSlot customSlot = new ItemPanelSlot(slot.slotIndex, slot.itemIndex, slot.item);
|
|
|
|
|
customSlot.groupIndex = slot.groupIndex;
|
|
|
|
|
customSlot.displayName = slot.displayName;
|
|
|
|
|
customSlot.bgItemStack = slot.bgItemStack;
|
|
|
|
|
customSlot.groupSize = slot.groupSize;
|
|
|
|
|
customSlot.extended = slot.extended;
|
|
|
|
|
customSlot.bgColor = slot.bgColor;
|
|
|
|
|
return customSlot;
|
2024-07-26 18:44:54 +03:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
return null;
|
2022-08-31 17:43:22 +09:00
|
|
|
}
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public ItemPanel() {
|
2025-04-24 18:48:40 +03:00
|
|
|
this.grid = new ItemsPanelGrid();
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public static void updateItemList(ArrayList<ItemStack> newItems) {
|
2025-04-24 18:48:40 +03:00
|
|
|
ItemPanels.itemPanel.getGrid().setItems(newItems);
|
2022-01-02 23:30:54 +02:00
|
|
|
ItemPanels.itemPanel.realItems = newItems;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void init() {
|
2022-05-06 22:41:45 +03:00
|
|
|
super.init();
|
2019-12-24 13:37:41 -08:00
|
|
|
|
2024-07-26 18:44:54 +03:00
|
|
|
toggleGroups = new Button("G") {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getButtonTip() {
|
|
|
|
|
return NEIClientUtils.translate("itempanel.collapsed.button.tip");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onButtonPress(boolean rightclick) {
|
2024-12-05 21:25:17 +02:00
|
|
|
CollapsibleItems.toggleGroups(rightclick ? false : null);
|
2024-07-26 18:44:54 +03:00
|
|
|
ItemList.updateFilter.restart();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-04 20:11:17 -08:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
@Override
|
|
|
|
|
public ItemPanelSlot getSlotMouseOver(int mousex, int mousey) {
|
|
|
|
|
// use ItemPanelSlot for Backwards compat
|
|
|
|
|
return ItemPanelSlot.of(this.grid.getSlotMouseOver(mousex, mousey));
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
|
|
|
|
public String getLabelText() {
|
2024-02-04 14:09:24 +02:00
|
|
|
return String.format("%d/%d", getPage(), Math.max(1, getNumPages()));
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected String getPositioningSettingName() {
|
2022-05-06 22:41:45 +03:00
|
|
|
return "world.panels.items";
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public int getMarginLeft(GuiContainer gui) {
|
2022-05-06 22:41:45 +03:00
|
|
|
return (gui.width + gui.xSize) / 2 + PADDING;
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public int getMarginTop(GuiContainer gui) {
|
2022-05-06 22:41:45 +03:00
|
|
|
return PADDING;
|
2020-01-20 09:42:39 -08:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public int getWidth(GuiContainer gui) {
|
2022-05-06 22:41:45 +03:00
|
|
|
return gui.width - (gui.xSize + gui.width) / 2 - PADDING * 2;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public int getHeight(GuiContainer gui) {
|
2022-05-06 22:41:45 +03:00
|
|
|
return gui.height - getMarginTop(gui) - PADDING;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
2024-07-26 18:44:54 +03:00
|
|
|
@Override
|
|
|
|
|
protected int resizeHeader(GuiContainer gui) {
|
|
|
|
|
int marginTop = super.resizeHeader(gui);
|
|
|
|
|
|
|
|
|
|
toggleGroups.w = pageNext.w;
|
|
|
|
|
toggleGroups.h = pageNext.h;
|
|
|
|
|
toggleGroups.y = pageNext.y;
|
|
|
|
|
toggleGroups.x = pageNext.x - toggleGroups.w - 2;
|
|
|
|
|
|
|
|
|
|
return marginTop;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected int resizeFooter(GuiContainer gui) {
|
2024-03-07 04:01:02 -06:00
|
|
|
if (!NEIClientConfig.showItemQuantityWidget() && NEIClientConfig.isSearchWidgetCentered()
|
|
|
|
|
&& !NEIClientConfig.showHistoryPanelWidget()) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2024-02-21 18:12:28 +02:00
|
|
|
if (NEIClientConfig.showHistoryPanelWidget()) {
|
|
|
|
|
historyPanel.x = x;
|
|
|
|
|
historyPanel.w = w;
|
2025-04-24 18:48:40 +03:00
|
|
|
historyPanel.h = 8 + ItemsGrid.SLOT_SIZE * NEIClientConfig.getIntSetting("inventory.history.useRows");
|
2024-03-07 05:32:08 -06:00
|
|
|
|
2024-03-07 04:01:02 -06:00
|
|
|
if (NEIClientConfig.showItemQuantityWidget() || !NEIClientConfig.isSearchWidgetCentered()) {
|
2025-01-16 22:12:26 +02:00
|
|
|
historyPanel.y = LayoutManager.quantity.y - historyPanel.h - PanelWidget.PADDING;
|
|
|
|
|
return LayoutManager.quantity.h + historyPanel.h + PanelWidget.PADDING * 2;
|
2024-03-07 04:01:02 -06:00
|
|
|
} else {
|
2024-03-07 05:32:08 -06:00
|
|
|
historyPanel.y = y + h - historyPanel.h;
|
|
|
|
|
return historyPanel.h + PanelWidget.PADDING;
|
2024-03-07 04:01:02 -06:00
|
|
|
}
|
2024-02-21 18:12:28 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-16 22:12:26 +02:00
|
|
|
return LayoutManager.quantity.h + PanelWidget.PADDING;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void setVisible() {
|
2022-05-06 22:41:45 +03:00
|
|
|
super.setVisible();
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2024-02-21 18:12:28 +02:00
|
|
|
if (grid.getPerPage() > 0) {
|
2025-01-09 09:53:27 +02:00
|
|
|
if (!CollapsibleItems.isEmpty() && !grid.isEmpty()) {
|
2024-07-26 18:44:54 +03:00
|
|
|
LayoutManager.addWidget(toggleGroups);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-09 09:53:27 +02:00
|
|
|
if (NEIClientConfig.showHistoryPanelWidget() && (!grid.isEmpty() || !historyPanel.isEmpty())) {
|
2024-02-21 18:12:28 +02:00
|
|
|
LayoutManager.addWidget(historyPanel);
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-21 18:12:28 +02:00
|
|
|
@Override
|
|
|
|
|
public void resize(GuiContainer gui) {
|
|
|
|
|
super.resize(gui);
|
|
|
|
|
historyPanel.resize(gui);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
protected ItemStack getDraggedStackWithQuantity(ItemStack itemStack) {
|
|
|
|
|
return ItemQuantityField.prepareStackWithQuantity(itemStack, 0);
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
2024-07-26 18:44:54 +03:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<String> handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey,
|
|
|
|
|
List<String> currenttip) {
|
2025-04-24 18:48:40 +03:00
|
|
|
|
|
|
|
|
if (!this.grid.forceExpand && !currenttip.isEmpty()) {
|
|
|
|
|
final ItemsPanelGridSlot hoverSlot = this.grid.getSlotMouseOver(mousex, mousey);
|
|
|
|
|
|
|
|
|
|
if (hoverSlot != null && hoverSlot.groupIndex >= 0
|
|
|
|
|
&& NEIClientConfig.getBooleanSetting("inventory.collapsibleItems.customName")
|
|
|
|
|
&& !hoverSlot.extended
|
|
|
|
|
&& !"".equals(hoverSlot.displayName)) {
|
|
|
|
|
currenttip.clear();
|
|
|
|
|
currenttip.add(hoverSlot.displayName + GuiDraw.TOOLTIP_LINESPACE);
|
2024-07-26 18:44:54 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-17 23:24:27 +03:00
|
|
|
return super.handleItemTooltip(gui, itemstack, mousex, mousey, currenttip);
|
2024-07-26 18:44:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean handleClick(int mousex, int mousey, int button) {
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (button == 0 && !this.grid.forceExpand && NEIClientUtils.altKey()) {
|
|
|
|
|
final ItemsPanelGridSlot hoverSlot = this.grid.getSlotMouseOver(mousex, mousey);
|
2024-07-26 18:44:54 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (hoverSlot != null && hoverSlot.groupIndex >= 0) {
|
|
|
|
|
CollapsibleItems.setExpanded(hoverSlot.groupIndex, !hoverSlot.extended);
|
|
|
|
|
this.grid.setItems(this.grid.rawItems);
|
|
|
|
|
NEIClientUtils.playClickSound();
|
|
|
|
|
return true;
|
2024-07-26 18:44:54 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return super.handleClick(mousex, mousey, button);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
@Override
|
|
|
|
|
public Map<String, String> handleHotkeys(GuiContainer gui, int mousex, int mousey, Map<String, String> hotkeys) {
|
|
|
|
|
final ItemsPanelGridSlot hoverSlot = this.grid.getSlotMouseOver(mousex, mousey);
|
|
|
|
|
|
|
|
|
|
if (!this.grid.forceExpand && hoverSlot != null && hoverSlot.groupIndex >= 0 && hoverSlot.groupSize > 1) {
|
|
|
|
|
final String message = hoverSlot.extended ? "itempanel.collapsed.hint.collapse"
|
|
|
|
|
: "itempanel.collapsed.hint.expand";
|
|
|
|
|
hotkeys.put(
|
|
|
|
|
NEIClientUtils.getKeyName(NEIClientUtils.ALT_HASH, NEIMouseUtils.MOUSE_BTN_LMB),
|
|
|
|
|
NEIClientUtils.translate(message, hoverSlot.groupSize));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hotkeys;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|