mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Add Set group by option
This commit is contained in:
@@ -6,6 +6,7 @@ public interface IComboBox<E> {
|
||||
boolean isVisible();
|
||||
void setVisible(boolean b0);
|
||||
void setSelectedItem(E item);
|
||||
void setSelectedIndex(int index);
|
||||
void addItem(E item);
|
||||
void removeAllItems();
|
||||
}
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package forge.itemmanager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardType;
|
||||
import forge.card.ColorSet;
|
||||
import forge.deck.DeckProxy;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.PaperCard;
|
||||
import forge.model.FModel;
|
||||
|
||||
public enum GroupDef {
|
||||
COLOR("Color", getColorGroups(),
|
||||
@@ -47,6 +52,25 @@ public enum GroupDef {
|
||||
return -1;
|
||||
}
|
||||
}),
|
||||
SET("Set", getSetGroups(),
|
||||
new Function<Integer, ColumnDef>() {
|
||||
@Override
|
||||
public ColumnDef apply(final Integer groupIndex) {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
new Function<InventoryItem, Integer>() {
|
||||
@Override
|
||||
public Integer apply(final InventoryItem item) {
|
||||
if (item instanceof PaperCard) {
|
||||
return getSetGroup(((PaperCard) item).getEdition());
|
||||
}
|
||||
else if (item instanceof DeckProxy) {
|
||||
return getSetGroup(((DeckProxy) item).getEdition().getCode());
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}),
|
||||
DEFAULT("Default",
|
||||
new String[] { "Creatures", "Spells", "Lands" },
|
||||
new Function<Integer, ColumnDef>() {
|
||||
@@ -214,4 +238,27 @@ public enum GroupDef {
|
||||
}
|
||||
return -1; //shouldn't happen
|
||||
}
|
||||
|
||||
private static Map<String, Integer> setGroupMap;
|
||||
|
||||
private static String[] getSetGroups() {
|
||||
setGroupMap = new HashMap<String, Integer>(); //cache mappings to make lookup quicker later
|
||||
|
||||
int groupNum = 0;
|
||||
String[] setGroups = new String[FModel.getMagicDb().getEditions().size()];
|
||||
for (CardEdition edition : FModel.getMagicDb().getEditions()) {
|
||||
setGroups[groupNum] = edition.getName();
|
||||
setGroupMap.put(edition.getCode(), groupNum);
|
||||
groupNum++;
|
||||
}
|
||||
return setGroups;
|
||||
}
|
||||
|
||||
private static Integer getSetGroup(String set) {
|
||||
Integer groupNum = setGroupMap.get(set);
|
||||
if (groupNum == null) {
|
||||
groupNum = -1;
|
||||
}
|
||||
return groupNum;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package forge.itemmanager;
|
||||
import forge.assets.FSkinProp;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardRulesPredicates;
|
||||
import forge.deck.DeckProxy;
|
||||
import forge.interfaces.IComboBox;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.util.ComparableOp;
|
||||
|
||||
@@ -137,4 +139,25 @@ public final class SItemManagerUtil {
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static final GroupDef[] CARD_GROUPBY_OPTIONS = { GroupDef.DEFAULT, GroupDef.CARD_TYPE, GroupDef.COLOR, GroupDef.COLOR_IDENTITY, GroupDef.SET, GroupDef.CARD_RARITY };
|
||||
private static final GroupDef[] DECK_GROUPBY_OPTIONS = { GroupDef.COLOR, GroupDef.COLOR_IDENTITY, GroupDef.SET };
|
||||
private static final ColumnDef[] CARD_PILEBY_OPTIONS = { ColumnDef.CMC, ColumnDef.COLOR, ColumnDef.NAME, ColumnDef.COST, ColumnDef.TYPE, ColumnDef.RARITY, ColumnDef.SET };
|
||||
private static final ColumnDef[] DECK_PILEBY_OPTIONS = { ColumnDef.DECK_COLOR, ColumnDef.DECK_FOLDER, ColumnDef.NAME, ColumnDef.DECK_FORMAT, ColumnDef.DECK_EDITION };
|
||||
|
||||
public static void populateImageViewOptions(IItemManager<?> itemManager, IComboBox<Object> cbGroupByOptions, IComboBox<Object> cbPileByOptions) {
|
||||
boolean isDeckManager = itemManager.getGenericType().equals(DeckProxy.class);
|
||||
GroupDef[] groupByOptions = isDeckManager ? DECK_GROUPBY_OPTIONS : CARD_GROUPBY_OPTIONS;
|
||||
ColumnDef[] pileByOptions = isDeckManager ? DECK_PILEBY_OPTIONS : CARD_PILEBY_OPTIONS;
|
||||
cbGroupByOptions.addItem("(none)");
|
||||
cbPileByOptions.addItem("(none)");
|
||||
for (GroupDef option : groupByOptions) {
|
||||
cbGroupByOptions.addItem(option);
|
||||
}
|
||||
for (ColumnDef option : pileByOptions) {
|
||||
cbPileByOptions.addItem(option);
|
||||
}
|
||||
cbGroupByOptions.setSelectedIndex(0);
|
||||
cbPileByOptions.setSelectedIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user