Move to ItemsGrid

This commit is contained in:
miozune committed 2022-08-29 17:40:41 +09:00
1 parent 763aa134bc
commit 683d1ea11a
4 files changed
+32 -16

No files matched your search

+7 -3
View File
@@ -37,6 +37,11 @@ public class ItemList {
private static final HashSet<Item> erroredItems = new HashSet<>();
private static final HashSet<String> stackTraces = new HashSet<>();
/**
* Unlike {@link LayoutManager#itemsLoaded}, this indicates whether item loading is
* actually finished or not.
*/
public static boolean loadFinished;
public static class EverythingItemFilter implements ItemFilter {
@Override
@@ -179,8 +184,7 @@ public class ItemList {
public void execute() {
// System.out.println("Executing NEI Item Loading");
ThreadOperationTimer timer = getTimer(NEIClientConfig.getItemLoadingTimeout());
ItemPanels.itemPanel.setLoading(true);
loadFinished = false;
LinkedList<ItemStack> items = new LinkedList<>();
LinkedList<ItemStack> permutations = new LinkedList<>();
@@ -221,7 +225,7 @@ public class ItemList {
updateFilter.restart();
ItemPanels.itemPanel.setLoading(false);
loadFinished = true;
}
};
+5 -13
View File
@@ -32,8 +32,6 @@ public class ItemPanel extends PanelWidget {
public Button less;
public ItemQuantityField quantity;
private Label loadingLabel;
public static class ItemPanelSlot {
public ItemStack item;
public int slotIndex;
@@ -75,6 +73,11 @@ public class ItemPanel extends PanelWidget {
super.drawSlotOutline(focused, slotIdx, rect);
}
}
@Override
public String getMessageOnEmpty() {
return ItemList.loadFinished ? null : NEIClientUtils.translate("itempanel.loading");
}
}
public ItemPanel() {
@@ -124,8 +127,6 @@ public class ItemPanel extends PanelWidget {
};
quantity = new ItemQuantityField("quantity");
loadingLabel = new Label(NEIClientUtils.translate("itempanel.loading"), true);
}
@Deprecated
@@ -172,9 +173,6 @@ public class ItemPanel extends PanelWidget {
quantity.x = x + BUTTON_SIZE + 2;
quantity.w = more.x - quantity.x - 2;
loadingLabel.x = x + (w / 2);
loadingLabel.y = y + (h / 2);
return BUTTON_SIZE + 2;
}
@@ -187,8 +185,6 @@ public class ItemPanel extends PanelWidget {
LayoutManager.addWidget(less);
LayoutManager.addWidget(quantity);
}
LayoutManager.addWidget(loadingLabel);
}
protected ItemStack getDraggedStackWithQuantity(int mouseDownSlot) {
@@ -206,8 +202,4 @@ public class ItemPanel extends PanelWidget {
return null;
}
public void setLoading(boolean loading) {
loadingLabel.setVisible(loading);
}
}
@@ -2,6 +2,7 @@ package codechicken.nei;
import static codechicken.lib.gui.GuiDraw.drawRect;
import codechicken.lib.gui.GuiDraw;
import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.ItemPanel.ItemPanelSlot;
import codechicken.nei.api.GuiInfo;
@@ -303,12 +304,21 @@ public class ItemsGrid {
drawSlotOutlines(mousex, mousey);
drawItems();
}
drawMessage();
}
protected void drawItem(Rectangle4i rect, int idx) {
GuiContainerManager.drawItem(rect.x + 1, rect.y + 1, getItem(idx));
}
protected void drawMessage() {
if (getItems().isEmpty() && getMessageOnEmpty() != null) {
GuiDraw.drawStringC(
getMessageOnEmpty(), marginLeft + paddingLeft + width / 2, marginTop + height / 2, 0xFFFFFFFF);
}
}
public ItemPanelSlot getSlotMouseOver(int mousex, int mousey) {
if (!contains(mousex, mousey)) {
return null;
@@ -345,4 +355,8 @@ public class ItemsGrid {
return r >= rows || c >= columns || !isInvalidSlot(slt);
}
public String getMessageOnEmpty() {
return null;
}
}
@@ -112,6 +112,12 @@ public class LayoutManager
public static HashMap<Integer, LayoutStyle> layoutStyles = new HashMap<>();
/**
* This is set to true immediately after item loading thread is started,
* to prevent duplicated loading thread from being executed.
* If you want to know if item list is actually finished loading,
* Use {@link ItemList#loadFinished} instead.
*/
public static boolean itemsLoaded = false;
/**