diff --git a/forge-gui/src/main/java/forge/gui/toolbox/itemmanager/views/GroupDef.java b/forge-gui/src/main/java/forge/gui/toolbox/itemmanager/views/GroupDef.java index 1d31c6d6cbd..ed80412d330 100644 --- a/forge-gui/src/main/java/forge/gui/toolbox/itemmanager/views/GroupDef.java +++ b/forge-gui/src/main/java/forge/gui/toolbox/itemmanager/views/GroupDef.java @@ -66,12 +66,12 @@ public enum GroupDef { if (type.isCreature()) { return 0; } + if (type.isLand()) { //make Artifact Lands appear in Lands group + return 2; + } if (type.isArtifact() || type.isEnchantment() || type.isPlaneswalker() || type.isInstant() || type.isSorcery()) { return 1; } - if (type.isLand()) { - return 2; - } } return -1; } @@ -92,15 +92,15 @@ public enum GroupDef { public Integer apply(final InventoryItem item) { if (item instanceof PaperCard) { CardType type = ((PaperCard) item).getRules().getType(); - if (type.isLand()) { + if (type.isCreature()) { //make Artifact and Land Creatures appear in Creatures group + return 2; + } + if (type.isLand()) { //make Artifact Lands appear in Lands group return 0; } if (type.isArtifact()) { return 1; } - if (type.isCreature()) { - return 2; - } if (type.isEnchantment()) { return 3; } diff --git a/forge-gui/src/main/java/forge/gui/toolbox/itemmanager/views/ImageView.java b/forge-gui/src/main/java/forge/gui/toolbox/itemmanager/views/ImageView.java index 662af08ed27..34393679907 100644 --- a/forge-gui/src/main/java/forge/gui/toolbox/itemmanager/views/ImageView.java +++ b/forge-gui/src/main/java/forge/gui/toolbox/itemmanager/views/ImageView.java @@ -135,13 +135,28 @@ public class ImageView extends ItemView { } } }); + groups.add(new Group("")); //add default group } public GroupDef getGroupBy() { return groupBy; } public void setGroupBy(GroupDef groupBy0) { + if (groupBy == groupBy0) { return; } groupBy = groupBy0; + + groups.clear(); + + if (groupBy == null) { + groups.add(new Group("")); + } + else { + for (String groupName : groupBy.getGroups()) { + groups.add(new Group(groupName)); + } + } + + refresh(this.getSelectedItems(), this.getSelectedIndex()); } public ColumnDef getPileBy() { @@ -164,18 +179,10 @@ public class ImageView extends ItemView { @Override protected void onRefresh() { - groups.clear(); + Group otherItems = groupBy == null ? groups.get(0) : null; - Group otherItems; - if (groupBy == null) { //use single group with all items if not grouping - otherItems = new Group(""); - groups.add(otherItems); - } - else { - otherItems = null; - for (String groupName : groupBy.getGroups()) { - groups.add(new Group(groupName)); - } + for (Group group : groups) { + group.items.clear(); } for (Entry itemEntry : model.getOrderedList()) { @@ -189,14 +196,24 @@ public class ImageView extends ItemView { } else { if (otherItems == null) { - otherItems = new Group("Other"); - groups.add(otherItems); + //reuse existing Other group if possible + if (groups.size() > groupBy.getGroups().length) { + otherItems = groups.get(groups.size() - 1); + } + else { + otherItems = new Group("Other"); + groups.add(otherItems); + } } otherItems.add(new ItemInfo(item)); } } } + if (otherItems == null && groups.size() > groupBy.getGroups().length) { + groups.remove(groups.size() - 1); //remove Other group if empty + } + updateLayout(); }