From 7d2bd4aee0e6a4fc3d3a9fb994e247243211e268 Mon Sep 17 00:00:00 2001 From: fwcd Date: Thu, 13 Feb 2020 20:32:01 +0100 Subject: [PATCH 1/5] Add .settings, .project and .vscode to Gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 35f9337f7..0bb620f36 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,9 @@ *.ipr *.iws eclipse/ +.vscode/ +.settings/ +.project out/ bin/ .idea/ From 9ae77c0d88484715e1c909a781c001ba59f76f87 Mon Sep 17 00:00:00 2001 From: fwcd Date: Mon, 17 Feb 2020 00:53:29 +0100 Subject: [PATCH 2/5] Update CTM to 1.0.1.30 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7d8affc1e..736cc9bbd 100644 --- a/build.gradle +++ b/build.gradle @@ -95,7 +95,7 @@ dependencies { deobfCompile "cofh:RedstoneFlux:${redstoneflux_version}" deobfCompile "net.darkhax.tesla:Tesla-${tesla_version}" //deobfCompile "pl.asie.charset:charset:0.5.0.164" - compile "team.chisel.ctm:CTM:MC1.12-0.2.3.12" + compile "team.chisel.ctm:CTM:MC1.12.2-1.0.1.30" deobfCompile "com.github.mcjty:intwheel:${intwheel_version}" if (!project.hasProperty("singleproject")) { From 5c33a1d0b496eccdaf83b3aa9a5c53b141cdc3a0 Mon Sep 17 00:00:00 2001 From: fwcd Date: Mon, 17 Feb 2020 00:54:34 +0100 Subject: [PATCH 3/5] Add .classpath and *.launch to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 0bb620f36..a63c9c268 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ eclipse/ .vscode/ .settings/ .project +.classpath +*.launch out/ bin/ .idea/ From 92a2391b48b844c872cb6ded29a9992279f12b37 Mon Sep 17 00:00:00 2001 From: fwcd Date: Mon, 17 Feb 2020 01:43:39 +0100 Subject: [PATCH 4/5] Add sort button to Storage Scanner GUI --- .../storagemonitor/GuiStorageScanner.java | 40 +++++++++++++++++-- .../StorageScannerTileEntity.java | 20 +++++++++- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/main/java/mcjty/rftools/blocks/storagemonitor/GuiStorageScanner.java b/src/main/java/mcjty/rftools/blocks/storagemonitor/GuiStorageScanner.java index ebaca9a4d..213b7393a 100644 --- a/src/main/java/mcjty/rftools/blocks/storagemonitor/GuiStorageScanner.java +++ b/src/main/java/mcjty/rftools/blocks/storagemonitor/GuiStorageScanner.java @@ -17,6 +17,9 @@ import mcjty.lib.varia.Logging; import mcjty.rftools.setup.CommandHandler; import mcjty.rftools.RFTools; +import mcjty.rftools.blocks.storage.sorters.CountItemSorter; +import mcjty.rftools.blocks.storage.sorters.ItemSorter; +import mcjty.rftools.blocks.storage.sorters.NameItemSorter; import mcjty.rftools.craftinggrid.GuiCraftingGrid; import mcjty.rftools.setup.GuiProxy; import mcjty.rftools.network.RFToolsMessages; @@ -55,6 +58,7 @@ public class GuiStorageScanner extends GenericGuiContainer updateSortMode()); Panel searchPanel = new Panel(mc, this) .setLayoutHint(new PositionalLayout.PositionalHint(8, 142, 256 - 11, 18)) .setLayout(new HorizontalLayout()).setDesiredHeight(18) .addChild(new Label(mc, this).setText("Search:")) - .addChild(searchField); + .addChild(searchField) + .addChild(sortMode); Slider radiusSlider = new Slider(mc, this) .setHorizontal() @@ -272,6 +280,14 @@ private void toggleView() { .put(PARAM_VIEW, openViewButton.isPressed()) .build()); } + + private void updateSortMode() { + tileEntity.setSortMode(sortMode.getCurrentChoice()); + sendServerCommand(RFToolsMessages.INSTANCE, StorageScannerTileEntity.CMD_UPDATESORTMODE, + TypedMap.builder() + .put(PARAM_SORTMODE, sortMode.getCurrentChoice()) + .build()); + } @Override protected void mouseClicked(int x, int y, int button) throws IOException { @@ -412,8 +428,9 @@ private void updateContentsList() { int numcolumns = openViewButton.isPressed() ? 5 : 9; int spacing = 3; -// Collections.sort(fromServer_inventory, (o1, o2) -> o1.stackSize == o2.stackSize ? 0 : o1.stackSize < o2.stackSize ? -1 : 1); - Collections.sort(fromServer_inventory, Comparator.comparing(ItemStack::getDisplayName)); + ItemSorter sorter = getCurrentSorter(); + Comparator> comparator = sorter.getComparator(); + Collections.sort(fromServer_inventory, (l, r) -> comparator.compare(Pair.of(l, 0), Pair.of(r, 0))); String filterText = searchField.getText().toLowerCase(); Predicate matcher = StorageScannerTileEntity.getMatcher(filterText); @@ -425,6 +442,23 @@ private void updateContentsList() { } } } + + private ItemSorter getCurrentSorter() { + String sortName = sortMode.getCurrentChoice(); + sortMode.clear(); + + ItemSorter[] sorters = {new CountItemSorter(), new NameItemSorter()}; + for (ItemSorter sorter : sorters) { + 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 sorters[sort]; + } private Pair addItemToList(ItemStack item, WidgetList itemList, Pair currentPos, int numcolumns, int spacing) { Panel panel = currentPos.getKey(); diff --git a/src/main/java/mcjty/rftools/blocks/storagemonitor/StorageScannerTileEntity.java b/src/main/java/mcjty/rftools/blocks/storagemonitor/StorageScannerTileEntity.java index e0b077660..c7f8e1363 100644 --- a/src/main/java/mcjty/rftools/blocks/storagemonitor/StorageScannerTileEntity.java +++ b/src/main/java/mcjty/rftools/blocks/storagemonitor/StorageScannerTileEntity.java @@ -61,10 +61,12 @@ public class StorageScannerTileEntity extends GenericEnergyReceiverTileEntity im public static final String CMD_REMOVE = "scanner.remove"; public static final String CMD_TOGGLEROUTABLE = "scanner.toggleRoutable"; public static final String CMD_SETVIEW = "scanner.setView"; + public static final String CMD_UPDATESORTMODE = "scanner.updateSortMode"; public static final Key PARAM_INDEX = new Key<>("index", Type.INTEGER); public static final Key PARAM_POS = new Key<>("pos", Type.BLOCKPOS); public static final Key PARAM_VIEW = new Key<>("view", Type.BOOLEAN); + public static final Key PARAM_SORTMODE = new Key<>("sortmode", Type.STRING); public static final String ACTION_CLEARGRID = "clearGrid"; @@ -74,6 +76,8 @@ public class StorageScannerTileEntity extends GenericEnergyReceiverTileEntity im // Client side data returned by CMD_SCANNER_INFO public static long rfReceived = 0; public static boolean exportToCurrentReceived = false; + + private String sortMode = ""; @Override public IAction[] getActions() { @@ -479,7 +483,7 @@ private static Predicate makeSearchPredicate(String split) { return s -> s.getDisplayName().toLowerCase().contains(split); } } - + public int getRadius() { return radius; } @@ -1030,6 +1034,7 @@ public void readRestorableFromNBT(NBTTagCompound tagCompound) { readBufferFromNBT(tagCompound, inventoryHelper); radius = tagCompound.getInteger("radius"); exportToCurrent = tagCompound.getBoolean("exportC"); + sortMode = tagCompound.getString("sortMode"); if (tagCompound.hasKey("wideview")) { openWideView = tagCompound.getBoolean("wideview"); } else { @@ -1069,6 +1074,7 @@ public void writeRestorableToNBT(NBTTagCompound tagCompound) { tagCompound.setInteger("radius", radius); tagCompound.setBoolean("exportC", exportToCurrent); tagCompound.setBoolean("wideview", openWideView); + tagCompound.setString("sortMode", sortMode); tagCompound.setTag("grid", craftingGrid.writeToNBT()); } @@ -1107,6 +1113,9 @@ public boolean execute(EntityPlayerMP playerMP, String command, TypedMap params) } else if (CMD_SETVIEW.equals(command)) { setOpenWideView(params.get(PARAM_VIEW)); return true; + } else if (CMD_UPDATESORTMODE.equals(command)) { + setSortMode(params.get(PARAM_SORTMODE)); + return true; } return false; } @@ -1225,4 +1234,13 @@ public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direct public int[] getSlotsForFace(EnumFacing side) { return SLOTS; } + + public String getSortMode() { + return sortMode; + } + + public void setSortMode(String sortMode) { + this.sortMode = sortMode; + markDirty(); + } } From 4b05a96d3bd73c17146f5cfea8367ec385bfb751 Mon Sep 17 00:00:00 2001 From: fwcd Date: Mon, 17 Feb 2020 02:01:59 +0100 Subject: [PATCH 5/5] Specify width and height of sort button in StorageScanner GUI --- .../blocks/storagemonitor/GuiStorageScanner.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/mcjty/rftools/blocks/storagemonitor/GuiStorageScanner.java b/src/main/java/mcjty/rftools/blocks/storagemonitor/GuiStorageScanner.java index 213b7393a..f963c9378 100644 --- a/src/main/java/mcjty/rftools/blocks/storagemonitor/GuiStorageScanner.java +++ b/src/main/java/mcjty/rftools/blocks/storagemonitor/GuiStorageScanner.java @@ -48,6 +48,8 @@ public class GuiStorageScanner extends GenericGuiContainer updateSortMode()); + for (ItemSorter sorter : itemSorters) { + sortMode.addChoice(sorter.getName(), sorter.getTooltip(), guielements, sorter.getU(), sorter.getV()); + } Panel searchPanel = new Panel(mc, this) .setLayoutHint(new PositionalLayout.PositionalHint(8, 142, 256 - 11, 18)) .setLayout(new HorizontalLayout()).setDesiredHeight(18) @@ -447,8 +454,7 @@ private ItemSorter getCurrentSorter() { String sortName = sortMode.getCurrentChoice(); sortMode.clear(); - ItemSorter[] sorters = {new CountItemSorter(), new NameItemSorter()}; - for (ItemSorter sorter : sorters) { + for (ItemSorter sorter : itemSorters) { sortMode.addChoice(sorter.getName(), sorter.getTooltip(), guielements, sorter.getU(), sorter.getV()); } @@ -457,7 +463,7 @@ private ItemSorter getCurrentSorter() { sort = 0; } sortMode.setCurrentChoice(sort); - return sorters[sort]; + return itemSorters[sort]; } private Pair addItemToList(ItemStack item, WidgetList itemList, Pair currentPos, int numcolumns, int spacing) {