2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
2023-09-25 00:34:42 +02:00
|
|
|
import codechicken.lib.vec.Rectangle4i;
|
2014-04-29 10:54:20 +10:00
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
2023-09-25 00:34:42 +02:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
import static codechicken.lib.gui.GuiDraw.drawRect;
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public class ItemPanel extends PanelWidget {
|
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
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
public Button more;
|
|
|
|
|
public Button less;
|
|
|
|
|
public ItemQuantityField quantity;
|
2022-01-03 16:55:39 +02:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public static class ItemPanelSlot {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public ItemStack item;
|
2014-04-29 10:54:20 +10:00
|
|
|
public int slotIndex;
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public ItemPanelSlot(int idx, ItemStack stack) {
|
2022-01-02 23:30:54 +02:00
|
|
|
slotIndex = idx;
|
|
|
|
|
item = stack;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Deprecated
|
2022-06-24 12:32:13 +01:00
|
|
|
public ItemPanelSlot(int idx) {
|
2022-01-02 23:30:54 +02:00
|
|
|
this(idx, ItemPanels.itemPanel.getGrid().getItem(idx));
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected static class ItemPanelGrid extends ItemsGrid {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
public ArrayList<ItemStack> newItems;
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public void setItems(ArrayList<ItemStack> items) {
|
2022-01-02 23:30:54 +02:00
|
|
|
newItems = items;
|
|
|
|
|
}
|
2019-12-24 13:37:41 -08:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public void refresh(GuiContainer gui) {
|
2019-12-24 13:37:41 -08:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
if (newItems != null) {
|
2022-10-13 11:06:08 +03:00
|
|
|
realItems = newItems;
|
2022-01-02 23:30:54 +02:00
|
|
|
newItems = null;
|
2022-06-23 01:03:29 +03:00
|
|
|
onGridChanged();
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
super.refresh(gui);
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2022-02-06 17:42:11 +02:00
|
|
|
@Override
|
2022-05-27 07:42:41 -04:00
|
|
|
protected void drawSlotOutline(@Nullable ItemPanelSlot focused, int slotIdx, Rectangle4i rect) {
|
|
|
|
|
if (PresetsWidget.inEditMode()) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (!PresetsWidget.isHidden(getItem(slotIdx))) drawRect(rect.x, rect.y, rect.w, rect.h, 0xee555555);
|
2022-05-27 07:42:41 -04:00
|
|
|
} else {
|
|
|
|
|
super.drawSlotOutline(focused, slotIdx, rect);
|
2022-02-06 17:42:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
2022-08-31 17:43:22 +09:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getMessageOnEmpty() {
|
|
|
|
|
return ItemList.loadFinished ? null : NEIClientUtils.translate("itempanel.loading");
|
|
|
|
|
}
|
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() {
|
2022-05-06 22:41:45 +03:00
|
|
|
grid = new ItemPanelGrid();
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public static void updateItemList(ArrayList<ItemStack> newItems) {
|
2022-01-02 23:30:54 +02:00
|
|
|
((ItemPanelGrid) ItemPanels.itemPanel.getGrid()).setItems(newItems);
|
|
|
|
|
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
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
more = new Button("+") {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
@Override
|
2019-12-24 13:37:41 -08:00
|
|
|
public boolean onButtonPress(boolean rightclick) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (rightclick) return false;
|
2022-05-06 22:41:45 +03:00
|
|
|
|
|
|
|
|
int modifier = NEIClientUtils.controlKey() ? 64 : NEIClientUtils.shiftKey() ? 10 : 1;
|
|
|
|
|
int quantity = NEIClientConfig.getItemQuantity() + modifier;
|
|
|
|
|
|
|
|
|
|
if (quantity < 0) {
|
|
|
|
|
quantity = 0;
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
ItemPanels.itemPanel.quantity.setText(Integer.toString(quantity));
|
|
|
|
|
return true;
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
};
|
2022-06-24 12:32:13 +01:00
|
|
|
less = new Button("-") {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
@Override
|
2019-12-24 13:37:41 -08:00
|
|
|
public boolean onButtonPress(boolean rightclick) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (rightclick) return false;
|
2022-05-06 22:41:45 +03:00
|
|
|
|
|
|
|
|
int modifier = NEIClientUtils.controlKey() ? -64 : NEIClientUtils.shiftKey() ? -10 : -1;
|
|
|
|
|
int quantity = NEIClientConfig.getItemQuantity() + modifier;
|
|
|
|
|
|
|
|
|
|
if (quantity < 0) {
|
|
|
|
|
quantity = 0;
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
ItemPanels.itemPanel.quantity.setText(Integer.toString(quantity));
|
|
|
|
|
return true;
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
quantity = new ItemQuantityField("quantity");
|
2020-02-04 20:11:17 -08:00
|
|
|
}
|
|
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
@Deprecated
|
2022-06-24 12:32:13 +01:00
|
|
|
public void scroll(int i) {
|
2022-05-06 22:41:45 +03:00
|
|
|
grid.shiftPage(i);
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
|
|
|
|
public String getLabelText() {
|
2022-05-06 22:41:45 +03: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
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected int resizeFooter(GuiContainer gui) {
|
2023-04-01 16:16:18 -05:00
|
|
|
if (!NEIClientConfig.showItemQuantityWidget() && NEIClientConfig.isSearchWidgetCentered()) return 0;
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2023-04-01 16:16:18 -05:00
|
|
|
final int BUTTON_SIZE = 20;
|
2022-05-06 22:41:45 +03:00
|
|
|
more.w = less.w = BUTTON_SIZE;
|
2023-04-01 16:16:18 -05:00
|
|
|
quantity.h = BUTTON_SIZE;
|
|
|
|
|
|
|
|
|
|
if (NEIClientConfig.isSearchWidgetCentered()) {
|
|
|
|
|
more.h = less.h = BUTTON_SIZE;
|
|
|
|
|
more.x = x + w - BUTTON_SIZE;
|
|
|
|
|
more.y = less.y = quantity.y = y + h - BUTTON_SIZE;
|
|
|
|
|
less.x = x;
|
|
|
|
|
quantity.x = x + BUTTON_SIZE + 2;
|
|
|
|
|
quantity.w = more.x - quantity.x - 2;
|
|
|
|
|
} else {
|
|
|
|
|
quantity.x = (int) (x + (w * 0.7)) + 3;
|
|
|
|
|
quantity.y = y + h - BUTTON_SIZE;
|
|
|
|
|
quantity.w = (int) ((w * 0.3) - BUTTON_SIZE - 1);
|
|
|
|
|
|
|
|
|
|
more.h = less.h = BUTTON_SIZE / 2;
|
|
|
|
|
more.y = y + h - (more.h * 2);
|
|
|
|
|
|
|
|
|
|
less.x = more.x = quantity.x + quantity.w;
|
|
|
|
|
less.y = more.y + more.h;
|
|
|
|
|
}
|
2022-05-06 22:41:45 +03:00
|
|
|
|
|
|
|
|
return BUTTON_SIZE + 2;
|
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
|
|
|
|
2022-08-19 15:03:42 +03:00
|
|
|
if (grid.getPerPage() > 0 && NEIClientConfig.showItemQuantityWidget()) {
|
2022-05-06 22:41:45 +03:00
|
|
|
LayoutManager.addWidget(more);
|
|
|
|
|
LayoutManager.addWidget(less);
|
|
|
|
|
LayoutManager.addWidget(quantity);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected ItemStack getDraggedStackWithQuantity(int mouseDownSlot) {
|
2022-01-02 23:30:54 +02:00
|
|
|
ItemStack stack = grid.getItem(mouseDownSlot);
|
|
|
|
|
|
|
|
|
|
if (stack != null) {
|
2022-08-19 15:03:42 +03:00
|
|
|
int amount = NEIClientConfig.showItemQuantityWidget() ? NEIClientConfig.getItemQuantity() : 0;
|
2022-01-02 23:30:54 +02:00
|
|
|
|
|
|
|
|
if (amount == 0) {
|
|
|
|
|
amount = stack.getMaxStackSize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NEIServerUtils.copyStack(stack, amount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|