Sort grid items on demand, fixes #247
This commit is contained in:
@@ -13,12 +13,8 @@ import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
|||||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||||
import refinedstorage.gui.grid.ClientStack;
|
|
||||||
import refinedstorage.proxy.CommonProxy;
|
import refinedstorage.proxy.CommonProxy;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Mod(modid = RefinedStorage.ID, version = RefinedStorage.VERSION)
|
@Mod(modid = RefinedStorage.ID, version = RefinedStorage.VERSION)
|
||||||
public final class RefinedStorage {
|
public final class RefinedStorage {
|
||||||
public static final String ID = "refinedstorage";
|
public static final String ID = "refinedstorage";
|
||||||
@@ -44,8 +40,6 @@ public final class RefinedStorage {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public List<ClientStack> items = new ArrayList<>();
|
|
||||||
|
|
||||||
public int controllerBaseUsage;
|
public int controllerBaseUsage;
|
||||||
public int cableUsage;
|
public int cableUsage;
|
||||||
public int constructorUsage;
|
public int constructorUsage;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package refinedstorage.gui.grid;
|
package refinedstorage.gui.grid;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import net.minecraft.client.gui.GuiTextField;
|
import net.minecraft.client.gui.GuiTextField;
|
||||||
@@ -10,7 +11,6 @@ import net.minecraft.item.Item;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import refinedstorage.RefinedStorage;
|
import refinedstorage.RefinedStorage;
|
||||||
import refinedstorage.api.network.GridExtractFlags;
|
import refinedstorage.api.network.GridExtractFlags;
|
||||||
import refinedstorage.api.storage.CompareUtils;
|
import refinedstorage.api.storage.CompareUtils;
|
||||||
@@ -34,13 +34,15 @@ import java.io.IOException;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class GuiGrid extends GuiBase {
|
public class GuiGrid extends GuiBase {
|
||||||
private GridSortingQuantity quantitySorting = new GridSortingQuantity();
|
public static final GridSortingQuantity SORTING_QUANTITY = new GridSortingQuantity();
|
||||||
private GridSortingName nameSorting = new GridSortingName();
|
public static final GridSortingName SORTING_NAME = new GridSortingName();
|
||||||
|
|
||||||
|
public static List<ClientStack> ITEMS = new ArrayList<>();
|
||||||
|
public static List<ClientStack> SORTED_ITEMS = new ArrayList<>();
|
||||||
|
|
||||||
private GuiTextField searchField;
|
private GuiTextField searchField;
|
||||||
|
|
||||||
private ContainerGrid container;
|
private ContainerGrid container;
|
||||||
private List<ClientStack> items = new ArrayList<>();
|
|
||||||
private IGrid grid;
|
private IGrid grid;
|
||||||
|
|
||||||
private int slotNumber;
|
private int slotNumber;
|
||||||
@@ -80,27 +82,38 @@ public class GuiGrid extends GuiBase {
|
|||||||
addSideButton(new SideButtonGridSortingDirection(grid));
|
addSideButton(new SideButtonGridSortingDirection(grid));
|
||||||
addSideButton(new SideButtonGridSortingType(grid));
|
addSideButton(new SideButtonGridSortingType(grid));
|
||||||
addSideButton(new SideButtonGridSearchBoxMode(this));
|
addSideButton(new SideButtonGridSearchBoxMode(this));
|
||||||
|
|
||||||
|
sortItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IGrid getGrid() {
|
public IGrid getGrid() {
|
||||||
return grid;
|
return grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static void sortItems() {
|
||||||
public void update(int x, int y) {
|
GuiScreen screen = Minecraft.getMinecraft().currentScreen;
|
||||||
items.clear();
|
|
||||||
|
|
||||||
if (grid.isConnected()) {
|
if (!(screen instanceof GuiGrid)) {
|
||||||
items.addAll(RefinedStorage.INSTANCE.items);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String query = searchField.getText().trim().toLowerCase();
|
GuiGrid gui = (GuiGrid) screen;
|
||||||
|
|
||||||
Iterator<ClientStack> t = items.iterator();
|
System.out.println("Resorting!");
|
||||||
|
|
||||||
|
SORTED_ITEMS.clear();
|
||||||
|
|
||||||
|
if (gui.getGrid().isConnected()) {
|
||||||
|
SORTED_ITEMS.addAll(ITEMS);
|
||||||
|
|
||||||
|
String query = gui.searchField.getText().trim().toLowerCase();
|
||||||
|
|
||||||
|
Iterator<ClientStack> t = SORTED_ITEMS.iterator();
|
||||||
|
|
||||||
while (t.hasNext()) {
|
while (t.hasNext()) {
|
||||||
ClientStack stack = t.next();
|
ClientStack stack = t.next();
|
||||||
|
|
||||||
List<GridFilteredItem> filteredItems = grid.getFilteredItems();
|
List<GridFilteredItem> filteredItems = gui.getGrid().getFilteredItems();
|
||||||
|
|
||||||
boolean found = filteredItems.isEmpty();
|
boolean found = filteredItems.isEmpty();
|
||||||
|
|
||||||
@@ -118,11 +131,11 @@ public class GuiGrid extends GuiBase {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grid.getViewType() == TileGrid.VIEW_TYPE_NON_CRAFTABLES && stack.isCraftable()) {
|
if (gui.getGrid().getViewType() == TileGrid.VIEW_TYPE_NON_CRAFTABLES && stack.isCraftable()) {
|
||||||
t.remove();
|
t.remove();
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
} else if (grid.getViewType() == TileGrid.VIEW_TYPE_CRAFTABLES && !stack.isCraftable()) {
|
} else if (gui.getGrid().getViewType() == TileGrid.VIEW_TYPE_CRAFTABLES && !stack.isCraftable()) {
|
||||||
t.remove();
|
t.remove();
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@@ -151,30 +164,27 @@ public class GuiGrid extends GuiBase {
|
|||||||
t.remove();
|
t.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (query.startsWith("#")) {
|
|
||||||
String tooltip = query.substring(1);
|
|
||||||
String tooltipFromItem = StringUtils.join(stack.getStack().getTooltip(container.getPlayer(), true), "\n");
|
|
||||||
|
|
||||||
if (!tooltipFromItem.contains(tooltip)) {
|
|
||||||
t.remove();
|
|
||||||
}
|
|
||||||
} else if (!stack.getStack().getDisplayName().toLowerCase().contains(query)) {
|
} else if (!stack.getStack().getDisplayName().toLowerCase().contains(query)) {
|
||||||
t.remove();
|
t.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nameSorting.setSortingDirection(grid.getSortingDirection());
|
SORTING_NAME.setSortingDirection(gui.getGrid().getSortingDirection());
|
||||||
quantitySorting.setSortingDirection(grid.getSortingDirection());
|
SORTING_QUANTITY.setSortingDirection(gui.getGrid().getSortingDirection());
|
||||||
|
|
||||||
Collections.sort(items, nameSorting);
|
Collections.sort(SORTED_ITEMS, SORTING_NAME);
|
||||||
|
|
||||||
if (grid.getSortingType() == TileGrid.SORTING_TYPE_QUANTITY) {
|
if (gui.getGrid().getSortingType() == TileGrid.SORTING_TYPE_QUANTITY) {
|
||||||
Collections.sort(items, quantitySorting);
|
Collections.sort(SORTED_ITEMS, SORTING_QUANTITY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getScrollbar().setCanScroll(getRows() > getVisibleRows());
|
gui.getScrollbar().setCanScroll(gui.getRows() > gui.getVisibleRows());
|
||||||
getScrollbar().setScrollDelta((float) getScrollbar().getScrollbarHeight() / (float) getRows());
|
gui.getScrollbar().setScrollDelta((float) gui.getScrollbar().getScrollbarHeight() / (float) gui.getRows());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getOffset() {
|
private int getOffset() {
|
||||||
@@ -182,13 +192,13 @@ public class GuiGrid extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getRows() {
|
private int getRows() {
|
||||||
int max = (int) Math.ceil((float) items.size() / 9f);
|
int max = (int) Math.ceil((float) SORTED_ITEMS.size() / 9f);
|
||||||
|
|
||||||
return max < 0 ? 0 : max;
|
return max < 0 ? 0 : max;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOverSlotWithItem() {
|
private boolean isOverSlotWithItem() {
|
||||||
return grid.isConnected() && isOverSlot() && slotNumber < items.size();
|
return grid.isConnected() && isOverSlot() && slotNumber < SORTED_ITEMS.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOverSlot() {
|
private boolean isOverSlot() {
|
||||||
@@ -266,8 +276,8 @@ public class GuiGrid extends GuiBase {
|
|||||||
this.slotNumber = slot;
|
this.slotNumber = slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slot < items.size()) {
|
if (slot < SORTED_ITEMS.size()) {
|
||||||
drawItem(x, y, items.get(slot).getStack(), true, formatQuantity(items.get(slot).getStack().stackSize, slot));
|
drawItem(x, y, SORTED_ITEMS.get(slot).getStack(), true, formatQuantity(SORTED_ITEMS.get(slot).getStack().stackSize, slot));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inBounds(x, y, 16, 16, mouseX, mouseY) || !grid.isConnected()) {
|
if (inBounds(x, y, 16, 16, mouseX, mouseY) || !grid.isConnected()) {
|
||||||
@@ -295,7 +305,7 @@ public class GuiGrid extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isOverSlotWithItem()) {
|
if (isOverSlotWithItem()) {
|
||||||
drawTooltip(mouseX, mouseY, items.get(slotNumber).getStack());
|
drawTooltip(mouseX, mouseY, SORTED_ITEMS.get(slotNumber).getStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isOverClear(mouseX, mouseY)) {
|
if (isOverClear(mouseX, mouseY)) {
|
||||||
@@ -335,6 +345,8 @@ public class GuiGrid extends GuiBase {
|
|||||||
searchField.setText("");
|
searchField.setText("");
|
||||||
searchField.setFocused(true);
|
searchField.setFocused(true);
|
||||||
|
|
||||||
|
sortItems();
|
||||||
|
|
||||||
updateJEI();
|
updateJEI();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,8 +369,8 @@ public class GuiGrid extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isOverSlotWithItem() && (held == null || (held != null && clickedButton == 2))) {
|
if (isOverSlotWithItem() && (held == null || (held != null && clickedButton == 2))) {
|
||||||
if (items.get(slotNumber).isCraftable() && (items.get(slotNumber).getStack().stackSize == 0 || (GuiScreen.isShiftKeyDown() && GuiScreen.isCtrlKeyDown()))) {
|
if (SORTED_ITEMS.get(slotNumber).isCraftable() && (SORTED_ITEMS.get(slotNumber).getStack().stackSize == 0 || (GuiScreen.isShiftKeyDown() && GuiScreen.isCtrlKeyDown()))) {
|
||||||
FMLCommonHandler.instance().showGuiScreen(new GuiCraftingSettings(this, container.getPlayer(), items.get(slotNumber)));
|
FMLCommonHandler.instance().showGuiScreen(new GuiCraftingSettings(this, container.getPlayer(), SORTED_ITEMS.get(slotNumber)));
|
||||||
} else {
|
} else {
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
|
|
||||||
@@ -374,7 +386,7 @@ public class GuiGrid extends GuiBase {
|
|||||||
flags |= GridExtractFlags.EXTRACT_SINGLE;
|
flags |= GridExtractFlags.EXTRACT_SINGLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefinedStorage.INSTANCE.network.sendToServer(new MessageGridPull(items.get(slotNumber).getId(), flags));
|
RefinedStorage.INSTANCE.network.sendToServer(new MessageGridPull(SORTED_ITEMS.get(slotNumber).getId(), flags));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -390,6 +402,8 @@ public class GuiGrid extends GuiBase {
|
|||||||
// NO OP
|
// NO OP
|
||||||
} else if (searchField.textboxKeyTyped(character, keyCode)) {
|
} else if (searchField.textboxKeyTyped(character, keyCode)) {
|
||||||
updateJEI();
|
updateJEI();
|
||||||
|
|
||||||
|
sortItems();
|
||||||
} else {
|
} else {
|
||||||
super.keyTyped(character, keyCode);
|
super.keyTyped(character, keyCode);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||||
import refinedstorage.RefinedStorage;
|
|
||||||
import refinedstorage.api.network.INetworkMaster;
|
import refinedstorage.api.network.INetworkMaster;
|
||||||
import refinedstorage.gui.grid.ClientStack;
|
import refinedstorage.gui.grid.ClientStack;
|
||||||
|
import refinedstorage.gui.grid.GuiGrid;
|
||||||
|
|
||||||
public class MessageGridDelta implements IMessage, IMessageHandler<MessageGridDelta, IMessage> {
|
public class MessageGridDelta implements IMessage, IMessageHandler<MessageGridDelta, IMessage> {
|
||||||
private INetworkMaster network;
|
private INetworkMaster network;
|
||||||
@@ -39,19 +39,22 @@ public class MessageGridDelta implements IMessage, IMessageHandler<MessageGridDe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMessage onMessage(MessageGridDelta message, MessageContext ctx) {
|
public IMessage onMessage(MessageGridDelta message, MessageContext ctx) {
|
||||||
for (ClientStack stack : RefinedStorage.INSTANCE.items) {
|
for (ClientStack stack : GuiGrid.ITEMS) {
|
||||||
if (stack.equals(message.clientStack)) {
|
if (stack.equals(message.clientStack)) {
|
||||||
if (stack.getStack().stackSize + message.delta == 0 && !message.clientStack.isCraftable()) {
|
if (stack.getStack().stackSize + message.delta == 0 && !message.clientStack.isCraftable()) {
|
||||||
RefinedStorage.INSTANCE.items.remove(stack);
|
GuiGrid.ITEMS.remove(stack);
|
||||||
} else {
|
} else {
|
||||||
stack.getStack().stackSize += message.delta;
|
stack.getStack().stackSize += message.delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
GuiGrid.sortItems();
|
||||||
}
|
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
RefinedStorage.INSTANCE.items.add(message.clientStack);
|
}
|
||||||
|
|
||||||
|
GuiGrid.ITEMS.add(message.clientStack);
|
||||||
|
GuiGrid.sortItems();
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||||
import refinedstorage.RefinedStorage;
|
|
||||||
import refinedstorage.api.network.INetworkMaster;
|
import refinedstorage.api.network.INetworkMaster;
|
||||||
import refinedstorage.gui.grid.ClientStack;
|
import refinedstorage.gui.grid.ClientStack;
|
||||||
|
import refinedstorage.gui.grid.GuiGrid;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -43,7 +43,8 @@ public class MessageGridUpdate implements IMessage, IMessageHandler<MessageGridU
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMessage onMessage(MessageGridUpdate message, MessageContext ctx) {
|
public IMessage onMessage(MessageGridUpdate message, MessageContext ctx) {
|
||||||
RefinedStorage.INSTANCE.items = message.items;
|
GuiGrid.ITEMS = message.items;
|
||||||
|
GuiGrid.sortItems();
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public abstract class TileMultipartNode extends TileNode implements IMicroblockC
|
|||||||
|
|
||||||
if (network != null) {
|
if (network != null) {
|
||||||
NetworkUtils.rebuildGraph(network);
|
NetworkUtils.rebuildGraph(network);
|
||||||
} else {
|
} else if (worldObj != null) {
|
||||||
RefinedStorageBlocks.CABLE.attemptConnect(worldObj, pos);
|
RefinedStorageBlocks.CABLE.attemptConnect(worldObj, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -375,7 +375,7 @@ public class TileGrid extends TileNode implements IGrid {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSearchBoxMode() {
|
public int getSearchBoxMode() {
|
||||||
return worldObj.isRemote ? SEARCH_BOX_MODE.getValue() : searchBoxMode;
|
return (worldObj != null && worldObj.isRemote) ? SEARCH_BOX_MODE.getValue() : searchBoxMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user