mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 02:38:02 +00:00
Add Set group by option
This commit is contained in:
@@ -12,6 +12,7 @@ import forge.itemmanager.GroupDef;
|
||||
import forge.itemmanager.ItemManager;
|
||||
import forge.itemmanager.ItemManagerConfig;
|
||||
import forge.itemmanager.ItemManagerModel;
|
||||
import forge.itemmanager.SItemManagerUtil;
|
||||
import forge.screens.match.controllers.CDetail;
|
||||
import forge.screens.match.controllers.CPicture;
|
||||
import forge.toolbox.*;
|
||||
@@ -43,11 +44,6 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
private static final int MIN_COLUMN_COUNT = 1;
|
||||
private static final int MAX_COLUMN_COUNT = 10;
|
||||
|
||||
private static final GroupDef[] CARD_GROUPBY_OPTIONS = { GroupDef.DEFAULT, GroupDef.CARD_TYPE, GroupDef.COLOR, GroupDef.COLOR_IDENTITY, GroupDef.CARD_RARITY };
|
||||
private static final GroupDef[] DECK_GROUPBY_OPTIONS = { GroupDef.COLOR, GroupDef.COLOR_IDENTITY };
|
||||
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 };
|
||||
|
||||
private final CardViewDisplay display;
|
||||
private final List<Integer> selectedIndices = new ArrayList<Integer>();
|
||||
private int columnCount = 4;
|
||||
@@ -142,26 +138,15 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
|
||||
public ImageView(ItemManager<T> itemManager0, ItemManagerModel<T> model0) {
|
||||
super(itemManager0, model0);
|
||||
//setup options
|
||||
boolean isDeckManager = itemManager0.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);
|
||||
}
|
||||
|
||||
SItemManagerUtil.populateImageViewOptions(itemManager0, cbGroupByOptions, cbPileByOptions);
|
||||
|
||||
for (Integer i = MIN_COLUMN_COUNT; i <= MAX_COLUMN_COUNT; i++) {
|
||||
cbColumnCount.addItem(i);
|
||||
}
|
||||
cbGroupByOptions.setMaximumRowCount(cbGroupByOptions.getItemCount());
|
||||
cbPileByOptions.setMaximumRowCount(cbPileByOptions.getItemCount());
|
||||
cbColumnCount.setMaximumRowCount(cbColumnCount.getItemCount());
|
||||
cbGroupByOptions.setSelectedIndex(0);
|
||||
cbPileByOptions.setSelectedIndex(0);
|
||||
cbColumnCount.setSelectedIndex(columnCount - MIN_COLUMN_COUNT);
|
||||
|
||||
cbGroupByOptions.addActionListener(new ActionListener() {
|
||||
|
||||
@@ -20,6 +20,7 @@ import forge.itemmanager.ItemColumn;
|
||||
import forge.itemmanager.ItemManager;
|
||||
import forge.itemmanager.ItemManagerConfig;
|
||||
import forge.itemmanager.ItemManagerModel;
|
||||
import forge.itemmanager.SItemManagerUtil;
|
||||
import forge.itemmanager.filters.ItemFilter;
|
||||
import forge.toolbox.FCardPanel;
|
||||
import forge.toolbox.FComboBox;
|
||||
@@ -54,11 +55,6 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
private static final int MIN_COLUMN_COUNT = 1;
|
||||
private static final int MAX_COLUMN_COUNT = 10;
|
||||
|
||||
private static final GroupDef[] CARD_GROUPBY_OPTIONS = { GroupDef.DEFAULT, GroupDef.CARD_TYPE, GroupDef.COLOR, GroupDef.COLOR_IDENTITY, GroupDef.CARD_RARITY };
|
||||
private static final GroupDef[] DECK_GROUPBY_OPTIONS = { GroupDef.COLOR, GroupDef.COLOR_IDENTITY };
|
||||
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 };
|
||||
|
||||
private final List<Integer> selectedIndices = new ArrayList<Integer>();
|
||||
private int columnCount = 4;
|
||||
private float scrollHeight = 0;
|
||||
@@ -146,20 +142,8 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
|
||||
public ImageView(ItemManager<T> itemManager0, ItemManagerModel<T> model0) {
|
||||
super(itemManager0, model0);
|
||||
//setup options
|
||||
boolean isDeckManager = itemManager0.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);
|
||||
|
||||
SItemManagerUtil.populateImageViewOptions(itemManager0, cbGroupByOptions, cbPileByOptions);
|
||||
|
||||
cbGroupByOptions.setChangedHandler(new FEventHandler() {
|
||||
@Override
|
||||
|
||||
@@ -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