Prevent auto-expanding groups when filters change

Fix how multi-type cards are grouped
This commit is contained in:
drdev
2014-02-04 03:04:41 +00:00
parent 075a01e3ae
commit 4aa2dd4471
2 changed files with 37 additions and 20 deletions

View File

@@ -66,12 +66,12 @@ public enum GroupDef {
if (type.isCreature()) { if (type.isCreature()) {
return 0; 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()) { if (type.isArtifact() || type.isEnchantment() || type.isPlaneswalker() || type.isInstant() || type.isSorcery()) {
return 1; return 1;
} }
if (type.isLand()) {
return 2;
}
} }
return -1; return -1;
} }
@@ -92,15 +92,15 @@ public enum GroupDef {
public Integer apply(final InventoryItem item) { public Integer apply(final InventoryItem item) {
if (item instanceof PaperCard) { if (item instanceof PaperCard) {
CardType type = ((PaperCard) item).getRules().getType(); 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; return 0;
} }
if (type.isArtifact()) { if (type.isArtifact()) {
return 1; return 1;
} }
if (type.isCreature()) {
return 2;
}
if (type.isEnchantment()) { if (type.isEnchantment()) {
return 3; return 3;
} }

View File

@@ -135,13 +135,28 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
} }
} }
}); });
groups.add(new Group("")); //add default group
} }
public GroupDef getGroupBy() { public GroupDef getGroupBy() {
return groupBy; return groupBy;
} }
public void setGroupBy(GroupDef groupBy0) { public void setGroupBy(GroupDef groupBy0) {
if (groupBy == groupBy0) { return; }
groupBy = groupBy0; 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() { public ColumnDef getPileBy() {
@@ -164,18 +179,10 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
@Override @Override
protected void onRefresh() { protected void onRefresh() {
groups.clear(); Group otherItems = groupBy == null ? groups.get(0) : null;
Group otherItems; for (Group group : groups) {
if (groupBy == null) { //use single group with all items if not grouping group.items.clear();
otherItems = new Group("");
groups.add(otherItems);
}
else {
otherItems = null;
for (String groupName : groupBy.getGroups()) {
groups.add(new Group(groupName));
}
} }
for (Entry<T, Integer> itemEntry : model.getOrderedList()) { for (Entry<T, Integer> itemEntry : model.getOrderedList()) {
@@ -189,14 +196,24 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
} }
else { else {
if (otherItems == null) { if (otherItems == null) {
//reuse existing Other group if possible
if (groups.size() > groupBy.getGroups().length) {
otherItems = groups.get(groups.size() - 1);
}
else {
otherItems = new Group("Other"); otherItems = new Group("Other");
groups.add(otherItems); groups.add(otherItems);
} }
}
otherItems.add(new ItemInfo(item)); otherItems.add(new ItemInfo(item));
} }
} }
} }
if (otherItems == null && groups.size() > groupBy.getGroups().length) {
groups.remove(groups.size() - 1); //remove Other group if empty
}
updateLayout(); updateLayout();
} }