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;
}
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);
}
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);
}
}
Aggregations