New grid filter system, fixes #602
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
# Refined Storage Changelog
|
# Refined Storage Changelog
|
||||||
|
|
||||||
|
### 1.2.4
|
||||||
|
- Added tooltip search with # (raoulvdberge)
|
||||||
|
- Mod search can now also take mod name instead of just id (raoulvdberge)
|
||||||
|
- Fixed bug where Disk Manipulator doesn't save disks (raoulvdberge)
|
||||||
|
|
||||||
### 1.2.3
|
### 1.2.3
|
||||||
- Fixed fluid cache updating wrongly (raoulvdberge)
|
- Fixed fluid cache updating wrongly (raoulvdberge)
|
||||||
- Fixed Exporter scheduling too many crafting tasks (raoulvdberge)
|
- Fixed Exporter scheduling too many crafting tasks (raoulvdberge)
|
||||||
|
|||||||
@@ -5,11 +5,13 @@ import com.google.common.collect.ListMultimap;
|
|||||||
import com.google.common.collect.Multimaps;
|
import com.google.common.collect.Multimaps;
|
||||||
import com.raoulvdberge.refinedstorage.RS;
|
import com.raoulvdberge.refinedstorage.RS;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.grid.IItemGridHandler;
|
import com.raoulvdberge.refinedstorage.api.network.grid.IItemGridHandler;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
|
||||||
import com.raoulvdberge.refinedstorage.block.EnumGridType;
|
import com.raoulvdberge.refinedstorage.block.EnumGridType;
|
||||||
import com.raoulvdberge.refinedstorage.container.ContainerGrid;
|
import com.raoulvdberge.refinedstorage.container.ContainerGrid;
|
||||||
import com.raoulvdberge.refinedstorage.gui.GuiBase;
|
import com.raoulvdberge.refinedstorage.gui.GuiBase;
|
||||||
import com.raoulvdberge.refinedstorage.gui.Scrollbar;
|
import com.raoulvdberge.refinedstorage.gui.Scrollbar;
|
||||||
|
import com.raoulvdberge.refinedstorage.gui.grid.filtering.GridFilterMod;
|
||||||
|
import com.raoulvdberge.refinedstorage.gui.grid.filtering.GridFilterParser;
|
||||||
|
import com.raoulvdberge.refinedstorage.gui.grid.filtering.IGridFilter;
|
||||||
import com.raoulvdberge.refinedstorage.gui.grid.sorting.GridSortingName;
|
import com.raoulvdberge.refinedstorage.gui.grid.sorting.GridSortingName;
|
||||||
import com.raoulvdberge.refinedstorage.gui.grid.sorting.GridSortingQuantity;
|
import com.raoulvdberge.refinedstorage.gui.grid.sorting.GridSortingQuantity;
|
||||||
import com.raoulvdberge.refinedstorage.gui.grid.stack.ClientStackFluid;
|
import com.raoulvdberge.refinedstorage.gui.grid.stack.ClientStackFluid;
|
||||||
@@ -142,67 +144,34 @@ public class GuiGrid extends GuiBase {
|
|||||||
if (grid.isConnected()) {
|
if (grid.isConnected()) {
|
||||||
stacks.addAll(grid.getType() == EnumGridType.FLUID ? FLUIDS.values() : ITEMS.values());
|
stacks.addAll(grid.getType() == EnumGridType.FLUID ? FLUIDS.values() : ITEMS.values());
|
||||||
|
|
||||||
String query = searchField.getText().trim().toLowerCase();
|
List<IGridFilter> filters = GridFilterParser.getFilters(grid, searchField.getText());
|
||||||
|
|
||||||
Iterator<IClientStack> t = stacks.iterator();
|
Iterator<IClientStack> t = stacks.iterator();
|
||||||
|
|
||||||
while (t.hasNext()) {
|
while (t.hasNext()) {
|
||||||
IClientStack stack = t.next();
|
IClientStack stack = t.next();
|
||||||
|
|
||||||
if (grid.getType() != EnumGridType.FLUID) {
|
int accepts = 0;
|
||||||
List<GridFilteredItem> filteredItems = grid.getFilteredItems();
|
IGridFilter previous = null;
|
||||||
|
|
||||||
boolean found = filteredItems.isEmpty();
|
for (IGridFilter filter : filters) {
|
||||||
|
if (!filter.accepts(stack)) {
|
||||||
|
if (filter.isStrong() || previous instanceof GridFilterMod) {
|
||||||
|
// avoid removing twice
|
||||||
|
accepts = -1;
|
||||||
|
|
||||||
for (GridFilteredItem filteredItem : filteredItems) {
|
t.remove();
|
||||||
if (API.instance().getComparer().isEqual(((ClientStackItem) stack).getStack(), filteredItem.getStack(), filteredItem.getCompare())) {
|
|
||||||
found = true;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
accepts++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
previous = filter;
|
||||||
t.remove();
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (grid.getViewType() == TileGrid.VIEW_TYPE_NON_CRAFTABLES && ((ClientStackItem) stack).isCraftable()) {
|
|
||||||
t.remove();
|
|
||||||
|
|
||||||
continue;
|
|
||||||
} else if (grid.getViewType() == TileGrid.VIEW_TYPE_CRAFTABLES && !((ClientStackItem) stack).isCraftable()) {
|
|
||||||
t.remove();
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.startsWith("@")) {
|
if (accepts == 0) {
|
||||||
String[] parts = query.split(" ");
|
|
||||||
|
|
||||||
String modId = parts[0].substring(1);
|
|
||||||
String modIdFromItem = stack.getModId();
|
|
||||||
|
|
||||||
if (!modIdFromItem.contains(modId)) {
|
|
||||||
t.remove();
|
|
||||||
} else if (parts.length >= 2) {
|
|
||||||
StringBuilder itemFromMod = new StringBuilder();
|
|
||||||
|
|
||||||
for (int i = 1; i < parts.length; ++i) {
|
|
||||||
itemFromMod.append(parts[i]);
|
|
||||||
|
|
||||||
if (i != parts.length - 1) {
|
|
||||||
itemFromMod.append(" ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!stack.getName().toLowerCase().contains(itemFromMod.toString())) {
|
|
||||||
t.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (!stack.getName().toLowerCase().contains(query)) {
|
|
||||||
t.remove();
|
t.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.gui.grid.filtering;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.gui.grid.stack.ClientStackItem;
|
||||||
|
import com.raoulvdberge.refinedstorage.gui.grid.stack.IClientStack;
|
||||||
|
|
||||||
|
public class GridFilterCraftable implements IGridFilter {
|
||||||
|
private boolean craftable;
|
||||||
|
|
||||||
|
public GridFilterCraftable(boolean craftable) {
|
||||||
|
this.craftable = craftable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean accepts(IClientStack stack) {
|
||||||
|
return stack instanceof ClientStackItem && ((ClientStackItem) stack).isCraftable() == craftable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStrong() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.gui.grid.filtering;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
|
import com.raoulvdberge.refinedstorage.gui.grid.GridFilteredItem;
|
||||||
|
import com.raoulvdberge.refinedstorage.gui.grid.stack.ClientStackItem;
|
||||||
|
import com.raoulvdberge.refinedstorage.gui.grid.stack.IClientStack;
|
||||||
|
|
||||||
|
public class GridFilterFilteredItem implements IGridFilter {
|
||||||
|
private GridFilteredItem filteredItem;
|
||||||
|
|
||||||
|
public GridFilterFilteredItem(GridFilteredItem filteredItem) {
|
||||||
|
this.filteredItem = filteredItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean accepts(IClientStack stack) {
|
||||||
|
return API.instance().getComparer().isEqual(((ClientStackItem) stack).getStack(), filteredItem.getStack(), filteredItem.getCompare());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStrong() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.gui.grid.filtering;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.gui.grid.stack.IClientStack;
|
||||||
|
import net.minecraftforge.fml.common.Loader;
|
||||||
|
import net.minecraftforge.fml.common.ModContainer;
|
||||||
|
|
||||||
|
public class GridFilterMod implements IGridFilter {
|
||||||
|
private String modName;
|
||||||
|
|
||||||
|
public GridFilterMod(String modName) {
|
||||||
|
this.modName = modName.toLowerCase().replace(" ", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getModNameFromModId(String id) {
|
||||||
|
ModContainer container = Loader.instance().getActiveModList().stream()
|
||||||
|
.filter(m -> m.getModId().toLowerCase().equals(id))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
return container == null ? id : container.getName().toLowerCase().replace(" ", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean accepts(IClientStack stack) {
|
||||||
|
String otherModId = stack.getModId().toLowerCase();
|
||||||
|
|
||||||
|
if (!getModNameFromModId(otherModId).contains(modName)) {
|
||||||
|
return stack.getModId().contains(modName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStrong() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.gui.grid.filtering;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.gui.grid.stack.IClientStack;
|
||||||
|
|
||||||
|
public class GridFilterName implements IGridFilter {
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public GridFilterName(String name) {
|
||||||
|
this.name = name.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean accepts(IClientStack stack) {
|
||||||
|
return stack.getName().toLowerCase().contains(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStrong() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.gui.grid.filtering;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.gui.grid.GridFilteredItem;
|
||||||
|
import com.raoulvdberge.refinedstorage.tile.grid.IGrid;
|
||||||
|
import com.raoulvdberge.refinedstorage.tile.grid.TileGrid;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GridFilterParser {
|
||||||
|
public static List<IGridFilter> getFilters(IGrid grid, String query) {
|
||||||
|
List<IGridFilter> filters = new LinkedList<>();
|
||||||
|
|
||||||
|
for (String part : query.toLowerCase().trim().split(" ")) {
|
||||||
|
if (part.startsWith("@")) {
|
||||||
|
filters.add(new GridFilterMod(part.substring(1)));
|
||||||
|
} else if (part.startsWith("#")) {
|
||||||
|
filters.add(new GridFilterTooltip(part.substring(1)));
|
||||||
|
} else {
|
||||||
|
filters.add(new GridFilterName(part));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grid.getViewType() == TileGrid.VIEW_TYPE_NON_CRAFTABLES) {
|
||||||
|
filters.add(new GridFilterCraftable(false));
|
||||||
|
} else if (grid.getViewType() == TileGrid.VIEW_TYPE_CRAFTABLES) {
|
||||||
|
filters.add(new GridFilterCraftable(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (GridFilteredItem filteredItem : grid.getFilteredItems()) {
|
||||||
|
filters.add(new GridFilterFilteredItem(filteredItem));
|
||||||
|
}
|
||||||
|
|
||||||
|
return filters;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.gui.grid.filtering;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.gui.grid.stack.IClientStack;
|
||||||
|
|
||||||
|
public class GridFilterTooltip implements IGridFilter {
|
||||||
|
private String tooltip;
|
||||||
|
|
||||||
|
public GridFilterTooltip(String tooltip) {
|
||||||
|
this.tooltip = tooltip.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean accepts(IClientStack stack) {
|
||||||
|
String otherTooltip = stack.getTooltip().trim().toLowerCase();
|
||||||
|
|
||||||
|
if (!otherTooltip.contains("\n")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
otherTooltip = otherTooltip.substring(otherTooltip.indexOf('\n') + 1); // Remove the first line as that states the item name
|
||||||
|
|
||||||
|
return otherTooltip.contains(tooltip);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStrong() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.gui.grid.filtering;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.gui.grid.stack.IClientStack;
|
||||||
|
|
||||||
|
public interface IGridFilter {
|
||||||
|
boolean accepts(IClientStack stack);
|
||||||
|
|
||||||
|
boolean isStrong();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user