Search in sources :

Example 1 with ItemSorter

use of mcjty.rftools.blocks.storage.sorters.ItemSorter in project RFTools by McJty.

the class GuiModularStorage method getCurrentSortMode.

private int getCurrentSortMode() {
    updateTypeModule();
    String sortName = sortMode.getCurrentChoice();
    sortMode.clear();
    for (ItemSorter sorter : typeModule.getSorters()) {
        sortMode.addChoice(sorter.getName(), sorter.getTooltip(), guiElements, sorter.getU(), sorter.getV());
    }
    int sort = sortMode.findChoice(sortName);
    if (sort == -1) {
        sort = 0;
    }
    sortMode.setCurrentChoice(sort);
    return sort;
}
Also used : ItemSorter(mcjty.rftools.blocks.storage.sorters.ItemSorter)

Example 2 with ItemSorter

use of mcjty.rftools.blocks.storage.sorters.ItemSorter in project RFTools by McJty.

the class GuiModularStorage method setupModePanel.

private Panel setupModePanel() {
    filter = new TextField(mc, this).setLayoutHint(new PositionalLayout.PositionalHint(3, 3, 57, 13)).setTooltips("Name based filter for items").addTextEvent((parent, newText) -> updateSettings());
    viewMode = new ImageChoiceLabel(mc, this).setLayoutHint(new PositionalLayout.PositionalHint(4, 19, 16, 16)).setTooltips("Control how items are shown", "in the view").addChoiceEvent((parent, newChoice) -> updateSettings());
    viewMode.addChoice(VIEW_LIST, "Items are shown in a list view", guiElements, 9 * 16, 16);
    viewMode.addChoice(VIEW_COLUMNS, "Items are shown in columns", guiElements, 10 * 16, 16);
    viewMode.addChoice(VIEW_ICONS, "Items are shown with icons", guiElements, 11 * 16, 16);
    updateTypeModule();
    sortMode = new ImageChoiceLabel(mc, this).setLayoutHint(new PositionalLayout.PositionalHint(23, 19, 16, 16)).setTooltips("Control how items are sorted", "in the view").addChoiceEvent((parent, newChoice) -> updateSettings());
    for (ItemSorter sorter : typeModule.getSorters()) {
        sortMode.addChoice(sorter.getName(), sorter.getTooltip(), guiElements, sorter.getU(), sorter.getV());
    }
    groupMode = new ImageChoiceLabel(mc, this).setLayoutHint(new PositionalLayout.PositionalHint(42, 19, 16, 16)).setTooltips("If enabled it will show groups", "based on sorting criterium").addChoiceEvent((parent, newChoice) -> updateSettings());
    groupMode.addChoice("Off", "Don't show groups", guiElements, 13 * 16, 0);
    groupMode.addChoice("On", "Show groups", guiElements, 14 * 16, 0);
    amountLabel = new Label(mc, this);
    amountLabel.setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT);
    amountLabel.setLayoutHint(new PositionalLayout.PositionalHint(16, 40, 66, 12));
    amountLabel.setTooltips("Amount of stacks / maximum amount");
    amountLabel.setText("?/?");
    compactButton = new Button(mc, this).setLayoutHint(new PositionalLayout.PositionalHint(4, 39, 12, 12)).setText("z").setTooltips("Compact equal stacks").addButtonEvent(parent -> compact());
    if (tileEntity != null) {
        filter.setText(ModularStorageConfiguration.clearSearchOnOpen ? "" : tileEntity.getFilter());
        setViewMode(tileEntity.getViewMode());
        setSortMode(tileEntity.getSortMode());
        groupMode.setCurrentChoice(tileEntity.isGroupMode() ? 1 : 0);
    } else {
        ItemStack heldItem = Minecraft.getMinecraft().player.getHeldItem(EnumHand.MAIN_HAND);
        if (!heldItem.isEmpty() && heldItem.hasTagCompound()) {
            NBTTagCompound tagCompound = heldItem.getTagCompound();
            filter.setText(ModularStorageConfiguration.clearSearchOnOpen ? "" : tagCompound.getString("filter"));
            setViewMode(tagCompound.getString("viewMode"));
            setSortMode(tagCompound.getString("sortMode"));
            groupMode.setCurrentChoice(tagCompound.getBoolean("groupMode") ? 1 : 0);
        }
    }
    return new Panel(mc, this).setLayout(new PositionalLayout()).setLayoutHint(new PositionalLayout.PositionalHint(24, ySize - 80, 64, 77)).setFilledRectThickness(-2).setFilledBackground(StyleConfig.colorListBackground).addChild(filter).addChild(viewMode).addChild(sortMode).addChild(groupMode).addChild(amountLabel).addChild(compactButton);
}
Also used : GenericGuiContainer(mcjty.lib.container.GenericGuiContainer) RFToolsMessages(mcjty.rftools.network.RFToolsMessages) Rectangle(java.awt.Rectangle) mcjty.lib.gui.widgets(mcjty.lib.gui.widgets) HorizontalAlignment(mcjty.lib.gui.layout.HorizontalAlignment) Item(net.minecraft.item.Item) CraftingGridProvider(mcjty.rftools.craftinggrid.CraftingGridProvider) EnumHand(net.minecraft.util.EnumHand) Keyboard(org.lwjgl.input.Keyboard) CONTAINER_GRID(mcjty.rftools.blocks.storage.ModularStorageContainer.CONTAINER_GRID) Arguments(mcjty.lib.network.Arguments) ArrayList(java.util.ArrayList) StyleConfig(mcjty.lib.base.StyleConfig) Window(mcjty.lib.gui.Window) ItemStack(net.minecraft.item.ItemStack) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout) Block(net.minecraft.block.Block) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) DefaultTypeModule(mcjty.rftools.blocks.storage.modules.DefaultTypeModule) Minecraft(net.minecraft.client.Minecraft) Logging(mcjty.lib.varia.Logging) PositionalLayout(mcjty.lib.gui.layout.PositionalLayout) RFTools(mcjty.rftools.RFTools) GenericContainer(mcjty.lib.container.GenericContainer) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ScaledResolution(net.minecraft.client.gui.ScaledResolution) GhostOutputSlot(mcjty.lib.container.GhostOutputSlot) StorageModuleItem(mcjty.rftools.items.storage.StorageModuleItem) BlockPos(net.minecraft.util.math.BlockPos) IOException(java.io.IOException) Mouse(org.lwjgl.input.Mouse) Argument(mcjty.lib.network.Argument) List(java.util.List) Type(java.lang.reflect.Type) IInventory(net.minecraft.inventory.IInventory) Slot(net.minecraft.inventory.Slot) ResourceLocation(net.minecraft.util.ResourceLocation) ItemBlock(net.minecraft.item.ItemBlock) CommandHandler(mcjty.rftools.CommandHandler) GuiCraftingGrid(mcjty.rftools.craftinggrid.GuiCraftingGrid) Collections(java.util.Collections) TypeModule(mcjty.rftools.blocks.storage.modules.TypeModule) ItemSorter(mcjty.rftools.blocks.storage.sorters.ItemSorter) Container(net.minecraft.inventory.Container) PositionalLayout(mcjty.lib.gui.layout.PositionalLayout) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemSorter(mcjty.rftools.blocks.storage.sorters.ItemSorter) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ItemSorter

use of mcjty.rftools.blocks.storage.sorters.ItemSorter in project RFTools by McJty.

the class GuiModularStorage method updateList.

private void updateList() {
    itemList.removeChildren();
    if (tileEntity != null && !inventorySlots.getSlot(ModularStorageContainer.SLOT_STORAGE_MODULE).getHasStack()) {
        amountLabel.setText("(empty)");
        compactButton.setEnabled(false);
        cycleButton.setEnabled(false);
        return;
    }
    cycleButton.setEnabled(isTabletWithRemote() || isRemote());
    String filterText = filter.getText().toLowerCase().trim();
    String view = viewMode.getCurrentChoice();
    int numcolumns;
    int labelWidth;
    int spacing;
    if (VIEW_LIST.equals(view)) {
        numcolumns = 1;
        labelWidth = 210;
        spacing = 5;
    } else if (VIEW_COLUMNS.equals(view)) {
        numcolumns = 2;
        labelWidth = 86;
        spacing = 5;
    } else {
        numcolumns = 12;
        labelWidth = 0;
        spacing = 3;
    }
    int max;
    List<Pair<ItemStack, Integer>> items = new ArrayList<>();
    if (tileEntity != null) {
        for (int i = ModularStorageContainer.SLOT_STORAGE; i < tileEntity.getSizeInventory(); i++) {
            ItemStack stack = tileEntity.getStackInSlot(i);
            if (!stack.isEmpty()) {
                String displayName = stack.getDisplayName();
                if (filterText.isEmpty() || displayName.toLowerCase().contains(filterText)) {
                    items.add(Pair.of(stack, i));
                }
            }
        }
        max = tileEntity.getSizeInventory() - ModularStorageContainer.SLOT_STORAGE;
    } else {
        // Also works for ModularStorageItemContainer
        for (int i = 0; i < RemoteStorageItemContainer.MAXSIZE_STORAGE; i++) {
            Slot slot = inventorySlots.getSlot(i);
            ItemStack stack = slot.getStack();
            if (!stack.isEmpty()) {
                String displayName = stack.getDisplayName();
                if (filterText.isEmpty() || displayName.toLowerCase().contains(filterText)) {
                    items.add(Pair.of(stack, i));
                }
            }
        }
        ItemStack heldItem = mc.player.getHeldItem(EnumHand.MAIN_HAND);
        if (!heldItem.isEmpty() && heldItem.hasTagCompound()) {
            max = heldItem.getTagCompound().getInteger("maxSize");
        } else {
            max = 0;
        }
    }
    amountLabel.setText(items.size() + "/" + max);
    compactButton.setEnabled(max > 0);
    int sort = getCurrentSortMode();
    boolean dogroups = groupMode.getCurrentChoiceIndex() == 1;
    ItemSorter itemSorter = typeModule.getSorters().get(sort);
    Collections.sort(items, itemSorter.getComparator());
    Pair<Panel, Integer> currentPos = MutablePair.of(null, 0);
    Pair<ItemStack, Integer> prevItem = null;
    for (Pair<ItemStack, Integer> item : items) {
        currentPos = addItemToList(item.getKey(), itemList, currentPos, numcolumns, labelWidth, spacing, item.getValue(), dogroups && (prevItem == null || !itemSorter.isSameGroup(prevItem, item)), itemSorter.getGroupName(item));
        prevItem = item;
    }
    int newfirst = -1;
    if (itemList.getCountSelected() == 0) {
        if (itemList.getBounds() != null) {
            itemList.setFirstSelected(0);
            newfirst = itemList.getChildCount() - itemList.getCountSelected();
            if (newfirst < 0) {
                newfirst = 0;
            }
        }
    } else if (itemList.getFirstSelected() > (itemList.getChildCount() - itemList.getCountSelected())) {
        newfirst = itemList.getChildCount() - itemList.getCountSelected();
    }
    if (newfirst >= 0) {
        itemList.setFirstSelected(newfirst);
    }
}
Also used : ArrayList(java.util.ArrayList) GhostOutputSlot(mcjty.lib.container.GhostOutputSlot) Slot(net.minecraft.inventory.Slot) ItemSorter(mcjty.rftools.blocks.storage.sorters.ItemSorter) ItemStack(net.minecraft.item.ItemStack) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

ItemSorter (mcjty.rftools.blocks.storage.sorters.ItemSorter)3 ArrayList (java.util.ArrayList)2 GhostOutputSlot (mcjty.lib.container.GhostOutputSlot)2 Slot (net.minecraft.inventory.Slot)2 ItemStack (net.minecraft.item.ItemStack)2 MutablePair (org.apache.commons.lang3.tuple.MutablePair)2 Pair (org.apache.commons.lang3.tuple.Pair)2 Rectangle (java.awt.Rectangle)1 IOException (java.io.IOException)1 Type (java.lang.reflect.Type)1 Collections (java.util.Collections)1 List (java.util.List)1 StyleConfig (mcjty.lib.base.StyleConfig)1 GenericContainer (mcjty.lib.container.GenericContainer)1 GenericGuiContainer (mcjty.lib.container.GenericGuiContainer)1 Window (mcjty.lib.gui.Window)1 HorizontalAlignment (mcjty.lib.gui.layout.HorizontalAlignment)1 HorizontalLayout (mcjty.lib.gui.layout.HorizontalLayout)1 PositionalLayout (mcjty.lib.gui.layout.PositionalLayout)1 mcjty.lib.gui.widgets (mcjty.lib.gui.widgets)1