Added "Last modified" sorting option

This commit is contained in:
raoulvdberge
2017-11-25 12:47:44 +01:00
parent b16b441e5a
commit 4b68fbf977
7 changed files with 39 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
### 1.5.24
- The Grid now displays last modified information (player name and date) and size on tooltips of stacks (raoulvdberge)
- Added "Last modified" sorting option in the Grid (raoulvdberge)
- Removed craft-only mode for the Exporter (raoulvdberge)
- Fixed Exporter with Stack Upgrade not working correctly in Regulator Mode (raoulvdberge)

View File

@@ -26,6 +26,7 @@ public interface IGrid {
int SORTING_TYPE_NAME = 1;
int SORTING_TYPE_ID = 2;
int SORTING_TYPE_INVENTORYTWEAKS = 3;
int SORTING_TYPE_LAST_MODIFIED = 4;
int SEARCH_BOX_MODE_NORMAL = 0;
int SEARCH_BOX_MODE_NORMAL_AUTOSELECTED = 1;
@@ -232,7 +233,11 @@ public interface IGrid {
}
static boolean isValidSortingType(int type) {
return type == SORTING_TYPE_QUANTITY || type == SORTING_TYPE_NAME || type == SORTING_TYPE_ID || type == SORTING_TYPE_INVENTORYTWEAKS;
return type == SORTING_TYPE_QUANTITY ||
type == SORTING_TYPE_NAME ||
type == SORTING_TYPE_ID ||
type == SORTING_TYPE_INVENTORYTWEAKS ||
type == SORTING_TYPE_LAST_MODIFIED;
}
static boolean isValidSortingDirection(int direction) {

View File

@@ -10,6 +10,7 @@ public class GridSortingID extends GridSorting {
public int compare(IGridStack left, IGridStack right) {
int x = left.getHash();
int y = right.getHash();
if (left.getIngredient() instanceof ItemStack && right.getIngredient() instanceof ItemStack) {
x = Item.getIdFromItem(((ItemStack) left.getIngredient()).getItem());
y = Item.getIdFromItem(((ItemStack) right.getIngredient()).getItem());

View File

@@ -0,0 +1,23 @@
package com.raoulvdberge.refinedstorage.gui.grid.sorting;
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
import com.raoulvdberge.refinedstorage.gui.grid.stack.IGridStack;
public class GridSortingLastModified extends GridSorting {
@Override
public int compare(IGridStack left, IGridStack right) {
long lt = left.getTrackerEntry() != null ? left.getTrackerEntry().getTime() : 0;
long rt = right.getTrackerEntry() != null ? right.getTrackerEntry().getTime() : 0;
if (lt != rt) {
// For "last modified" the comparison is reversed
if (sortingDirection == IGrid.SORTING_DIRECTION_DESCENDING) {
return Long.compare(rt, lt);
} else if (sortingDirection == IGrid.SORTING_DIRECTION_ASCENDING) {
return Long.compare(lt, rt);
}
}
return 0;
}
}

View File

@@ -16,6 +16,7 @@ public class Sorter implements Runnable {
private static final GridSorting SORTING_NAME = new GridSortingName();
private static final GridSorting SORTING_ID = new GridSortingID();
private static final GridSorting SORTING_INVENTORYTWEAKS = new GridSortingInventoryTweaks();
private static final GridSorting SORTING_LAST_MODIFIED = new GridSortingLastModified();
private boolean done;
private boolean started;
@@ -59,6 +60,7 @@ public class Sorter implements Runnable {
SORTING_QUANTITY.setSortingDirection(grid.getSortingDirection());
SORTING_ID.setSortingDirection(grid.getSortingDirection());
SORTING_INVENTORYTWEAKS.setSortingDirection(grid.getSortingDirection());
SORTING_LAST_MODIFIED.setSortingDirection(grid.getSortingDirection());
stacks.sort(SORTING_NAME);
@@ -68,6 +70,8 @@ public class Sorter implements Runnable {
stacks.sort(SORTING_ID);
} else if (grid.getSortingType() == IGrid.SORTING_TYPE_INVENTORYTWEAKS) {
stacks.sort(SORTING_INVENTORYTWEAKS);
} else if (grid.getSortingType() == IGrid.SORTING_TYPE_LAST_MODIFIED) {
stacks.sort(SORTING_LAST_MODIFIED);
}
}

View File

@@ -35,11 +35,13 @@ public class SideButtonGridSortingType extends SideButton {
type = IGrid.SORTING_TYPE_NAME;
} else if (type == IGrid.SORTING_TYPE_NAME) {
if (grid.getType() == GridType.FLUID) {
type = IGrid.SORTING_TYPE_QUANTITY;
type = IGrid.SORTING_TYPE_LAST_MODIFIED;
} else {
type = IGrid.SORTING_TYPE_ID;
}
} else if (type == IGrid.SORTING_TYPE_ID) {
type = IGrid.SORTING_TYPE_LAST_MODIFIED;
} else if (type == NetworkNodeGrid.SORTING_TYPE_LAST_MODIFIED) {
if (grid.getType() == GridType.FLUID || !Loader.isModLoaded(GridSortingInventoryTweaks.MOD_ID)) {
type = IGrid.SORTING_TYPE_QUANTITY;
} else {

View File

@@ -147,6 +147,7 @@ sidebutton.refinedstorage:grid.sorting.type.0=Quantity
sidebutton.refinedstorage:grid.sorting.type.1=Name
sidebutton.refinedstorage:grid.sorting.type.2=ID
sidebutton.refinedstorage:grid.sorting.type.3=InventoryTweaks
sidebutton.refinedstorage:grid.sorting.type.4=Last modified
sidebutton.refinedstorage:grid.search_box_mode=Search box mode
sidebutton.refinedstorage:grid.search_box_mode.0=Normal
sidebutton.refinedstorage:grid.search_box_mode.1=Normal (autoselected)