d&d to search input; fix giveStack; change grid size

This commit is contained in:
Serghei Borovetchi authored and Jason Mitchell committed 2022-01-03 09:44:33 -08:00
1 parent 5dde7cad8b
commit 98c9f03e74
4 files changed
+31 -49

No files matched your search

@@ -88,7 +88,6 @@ public class BookmarkPanel extends ItemPanel
{
realItems.add(stackA);
metadata.add(meta);
needRefresh = true;
}
public void replaceItem(int idx, ItemStack stack)
@@ -127,7 +126,6 @@ public class BookmarkPanel extends ItemPanel
{
realItems.remove(idx);
metadata.remove(idx);
needRefresh = true;
return true;
}
@@ -153,7 +151,6 @@ public class BookmarkPanel extends ItemPanel
{
realItems.add(dst, realItems.remove(src));
metadata.add(dst, metadata.remove(src));
needRefresh = true;
}
@Override
+27 -1
View File
@@ -14,7 +14,10 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;
import static codechicken.nei.LayoutManager.searchField;
import java.util.ArrayList;
import java.util.regex.Pattern;
public class ItemPanel extends Widget
{
@@ -38,6 +41,8 @@ public class ItemPanel extends Widget
@Deprecated
public ArrayList<ItemStack> realItems = new ArrayList<>();
protected Pattern SPECIAL_REGEX_CHARS = Pattern.compile("[{}()\\[\\].+*?^$\\\\|]");
public static class ItemPanelSlot
{
public ItemStack item;
@@ -64,7 +69,6 @@ public class ItemPanel extends Widget
public void setItems(ArrayList<ItemStack> items)
{
newItems = items;
needRefresh = true;
}
public void refresh(GuiContainer gui)
@@ -320,6 +324,10 @@ public class ItemPanel extends Widget
return true;
}
if (handleSearchInputClick(mouseX, mouseY, button)) {
return true;
}
if (handleGUIContainerClick(mouseX, mouseY, button)) {
return true;
}
@@ -442,6 +450,24 @@ public class ItemPanel extends Widget
return false;
}
protected boolean handleSearchInputClick(int mouseX, int mouseY, int button)
{
if (searchField.contains(mouseX, mouseY)) {
final FluidStack fluidStack = StackInfo.getFluid(draggedStack);
if (fluidStack != null) {
searchField.setText(SPECIAL_REGEX_CHARS.matcher(fluidStack.getLocalizedName()).replaceAll("\\\\$0"));
} else {
searchField.setText(SPECIAL_REGEX_CHARS.matcher(draggedStack.getDisplayName()).replaceAll("\\\\$0"));
}
return true;
}
return false;
}
@Override
public void mouseUp(int mousex, int mousey, int button) {
ItemPanelSlot hoverSlot = getSlotMouseOver(mousex, mousey);
@@ -36,11 +36,6 @@ public class ItemsGrid
protected boolean[] validSlotMap;
protected boolean[] invalidSlotMap;
private int[] guiSize;
protected boolean needRefresh = false;
public ArrayList<ItemStack> getItems()
{
return realItems;
@@ -107,8 +102,6 @@ public class ItemsGrid
columns = width / SLOT_SIZE;
rows = height / SLOT_SIZE;
needRefresh = true;
}
}
@@ -134,51 +127,14 @@ public class ItemsGrid
}
page = Math.max(0, Math.min(page, numPages - 1));
needRefresh = true;
}
public void refresh(GuiContainer gui)
{
if (!needRefresh(gui)) {
return;
}
updateGuiOverlapSlots(gui);
shiftPage(0);
needRefresh = false;
}
private boolean needRefresh(GuiContainer gui)
{
if (needRefresh == true) {
return true;
}
if (gui == null && guiSize == null) {
return false;
}
if (gui == null) {
guiSize = null;
return true;
}
if (guiSize == null) {
guiSize = new int[]{ gui.guiLeft, gui.guiTop, gui.width, gui.height };
return true;
}
if (gui.guiLeft != guiSize[0] || gui.guiTop != guiSize[1] || gui.width != guiSize[2] || gui.height != guiSize[3]) {
guiSize = new int[]{ gui.guiLeft, gui.guiTop, gui.width, gui.height };
return true;
}
return false;
}
private void updateGuiOverlapSlots(GuiContainer gui)
{
invalidSlotMap = new boolean[rows * columns];
@@ -157,7 +157,10 @@ public class NEIClientUtils extends NEIServerUtils
final List<Iterable<Integer>> handlerSlots;
try {
GuiInfo.readLock.lock();
handlerSlots = GuiInfo.guiHandlers.stream().map(handler -> handler.getItemSpawnSlots(gui, typestack)).collect(Collectors.toCollection(LinkedList::new));
handlerSlots = GuiInfo.guiHandlers.stream()
.map(handler -> handler.getItemSpawnSlots(gui, typestack))
.filter(x -> x != null)
.collect(Collectors.toCollection(LinkedList::new));
} finally {
GuiInfo.readLock.unlock();
}