mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Refactor Sections to Groups and create enum for grouping items
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -15688,6 +15688,7 @@ forge-gui/src/main/java/forge/gui/toolbox/itemmanager/package-info.java -text
|
||||
forge-gui/src/main/java/forge/gui/toolbox/itemmanager/views/ColorSetRenderer.java -text
|
||||
forge-gui/src/main/java/forge/gui/toolbox/itemmanager/views/ColumnDef.java -text
|
||||
forge-gui/src/main/java/forge/gui/toolbox/itemmanager/views/DeckQuantityRenderer.java -text
|
||||
forge-gui/src/main/java/forge/gui/toolbox/itemmanager/views/GroupDef.java -text
|
||||
forge-gui/src/main/java/forge/gui/toolbox/itemmanager/views/ImageView.java -text
|
||||
forge-gui/src/main/java/forge/gui/toolbox/itemmanager/views/IntegerRenderer.java -text
|
||||
forge-gui/src/main/java/forge/gui/toolbox/itemmanager/views/ItemCellRenderer.java -text
|
||||
|
||||
@@ -13,6 +13,7 @@ import forge.Singletons;
|
||||
import forge.StaticData;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.ColorSet;
|
||||
import forge.card.MagicColor;
|
||||
import forge.deck.CardPool;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckGroup;
|
||||
@@ -44,6 +45,7 @@ public class DeckProxy implements InventoryItem {
|
||||
|
||||
// cached values
|
||||
protected ColorSet color;
|
||||
protected ColorSet colorIdentity;
|
||||
protected Iterable<GameFormat> formats;
|
||||
private int mainSize = Integer.MIN_VALUE;
|
||||
private int sbSize = Integer.MIN_VALUE;
|
||||
@@ -103,6 +105,7 @@ public class DeckProxy implements InventoryItem {
|
||||
|
||||
public void invalidateCache() {
|
||||
color = null;
|
||||
colorIdentity = null;
|
||||
formats = null;
|
||||
edition = null;
|
||||
mainSize = Integer.MIN_VALUE;
|
||||
@@ -116,6 +119,28 @@ public class DeckProxy implements InventoryItem {
|
||||
return color;
|
||||
}
|
||||
|
||||
public ColorSet getColorIdentity() {
|
||||
if (colorIdentity == null) {
|
||||
byte colorProfile = MagicColor.COLORLESS;
|
||||
|
||||
for (Entry<DeckSection, CardPool> deckEntry : getDeck()) {
|
||||
switch (deckEntry.getKey()) {
|
||||
case Main:
|
||||
case Sideboard:
|
||||
case Commander:
|
||||
for (Entry<PaperCard, Integer> poolEntry : deckEntry.getValue()) {
|
||||
colorProfile |= poolEntry.getKey().getRules().getColorIdentity().getColor();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break; //ignore other sections
|
||||
}
|
||||
}
|
||||
colorIdentity = ColorSet.fromMask(colorProfile);
|
||||
}
|
||||
return colorIdentity;
|
||||
}
|
||||
|
||||
public Iterable<GameFormat> getFormats() {
|
||||
if (formats == null) {
|
||||
formats = Singletons.getModel().getFormats().getAllFormatsOfDeck(getDeck());
|
||||
|
||||
@@ -42,13 +42,6 @@ import forge.item.InventoryItemFromSet;
|
||||
import forge.item.PaperCard;
|
||||
import forge.limited.DraftRankCache;
|
||||
|
||||
/**
|
||||
* A column object in a EditorTableModel in the card editor.
|
||||
* Requires a sorting function and a display function
|
||||
* (to extract information as appropriate for table row data).
|
||||
*
|
||||
* @param <T> a generic type
|
||||
*/
|
||||
public enum ColumnDef {
|
||||
STRING("", "", 0, -1, -1, SortState.ASC, new ItemCellRenderer(),
|
||||
new Function<Entry<InventoryItem, Integer>, Comparable<?>>() {
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
package forge.gui.toolbox.itemmanager.views;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.card.CardType;
|
||||
import forge.card.ColorSet;
|
||||
import forge.gui.deckeditor.DeckProxy;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.PaperCard;
|
||||
|
||||
public enum GroupDef {
|
||||
COLOR("Color", getColorGroups(),
|
||||
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 getColorGroup(((PaperCard) item).getRules().getColor());
|
||||
}
|
||||
else if (item instanceof DeckProxy) {
|
||||
return getColorGroup(((DeckProxy) item).getColor());
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}),
|
||||
COLOR_IDENTITY("Color", getColorGroups(),
|
||||
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 getColorGroup(((PaperCard) item).getRules().getColorIdentity());
|
||||
}
|
||||
else if (item instanceof DeckProxy) {
|
||||
return getColorGroup(((DeckProxy) item).getColorIdentity());
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}),
|
||||
CREATURE_SPELL_LAND("Creatures/Spells/Lands",
|
||||
new String[] { "Creatures", "Spells", "Lands" },
|
||||
new Function<Integer, ColumnDef>() {
|
||||
@Override
|
||||
public ColumnDef apply(final Integer groupIndex) {
|
||||
if (groupIndex == 2) {
|
||||
return ColumnDef.NAME; //pile lands by name regardless
|
||||
}
|
||||
return null;
|
||||
}
|
||||
},
|
||||
new Function<InventoryItem, Integer>() {
|
||||
@Override
|
||||
public Integer apply(final InventoryItem item) {
|
||||
if (item instanceof PaperCard) {
|
||||
CardType type = ((PaperCard) item).getRules().getType();
|
||||
if (type.isCreature()) {
|
||||
return 0;
|
||||
}
|
||||
if (type.isArtifact() || type.isEnchantment() || type.isPlaneswalker() || type.isInstant() || type.isSorcery()) {
|
||||
return 1;
|
||||
}
|
||||
if (type.isLand()) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}),
|
||||
CARD_TYPE("Card Type",
|
||||
new String[] { "Lands", "Artifacts", "Creatures", "Enchantments", "Planeswalkers", "Instants", "Sorceries" },
|
||||
new Function<Integer, ColumnDef>() {
|
||||
@Override
|
||||
public ColumnDef apply(final Integer groupIndex) {
|
||||
if (groupIndex == 0) {
|
||||
return ColumnDef.NAME; //pile lands by name regardless
|
||||
}
|
||||
return null;
|
||||
}
|
||||
},
|
||||
new Function<InventoryItem, Integer>() {
|
||||
@Override
|
||||
public Integer apply(final InventoryItem item) {
|
||||
if (item instanceof PaperCard) {
|
||||
CardType type = ((PaperCard) item).getRules().getType();
|
||||
if (type.isLand()) {
|
||||
return 0;
|
||||
}
|
||||
if (type.isArtifact()) {
|
||||
return 1;
|
||||
}
|
||||
if (type.isCreature()) {
|
||||
return 2;
|
||||
}
|
||||
if (type.isEnchantment()) {
|
||||
return 3;
|
||||
}
|
||||
if (type.isPlaneswalker()) {
|
||||
return 4;
|
||||
}
|
||||
if (type.isInstant()) {
|
||||
return 5;
|
||||
}
|
||||
if (type.isSorcery()) {
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
|
||||
GroupDef(String name0, String[] groups0, Function<Integer, ColumnDef> fnGetPileByOverride0, Function<InventoryItem, Integer> fnGroupItem0) {
|
||||
this.name = name0;
|
||||
this.groups = groups0;
|
||||
this.fnGetPileByOverride = fnGetPileByOverride0;
|
||||
this.fnGroupItem = fnGroupItem0;
|
||||
}
|
||||
|
||||
private final String name;
|
||||
private final String[] groups;
|
||||
private final Function<Integer, ColumnDef> fnGetPileByOverride;
|
||||
private final Function<InventoryItem, Integer> fnGroupItem;
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String[] getGroups() {
|
||||
return this.groups;
|
||||
}
|
||||
|
||||
public ColumnDef getGroupPileBy(int groupIndex, ColumnDef defaultPileBy) {
|
||||
ColumnDef pileBy = this.fnGetPileByOverride.apply(groupIndex);
|
||||
if (pileBy == null) {
|
||||
return defaultPileBy;
|
||||
}
|
||||
return pileBy;
|
||||
}
|
||||
|
||||
public int getItemGroupIndex(InventoryItem item) {
|
||||
return this.fnGroupItem.apply(item);
|
||||
}
|
||||
|
||||
private static String[] getColorGroups() {
|
||||
//TODO: Support breaking up Multicolor into separate groups for each color combination
|
||||
return new String[] { "Colorless", "White", "Blue", "Black", "Red", "Green", "Multicolor" };
|
||||
}
|
||||
|
||||
private static Integer getColorGroup(ColorSet color) {
|
||||
if (color.isColorless()) {
|
||||
return 0;
|
||||
}
|
||||
if (color.isMulticolor()) {
|
||||
return 6;
|
||||
}
|
||||
if (color.hasWhite()) {
|
||||
return 1;
|
||||
}
|
||||
if (color.hasBlue()) {
|
||||
return 2;
|
||||
}
|
||||
if (color.hasBlack()) {
|
||||
return 3;
|
||||
}
|
||||
if (color.hasRed()) {
|
||||
return 4;
|
||||
}
|
||||
if (color.hasGreen()) {
|
||||
return 5;
|
||||
}
|
||||
return -1; //shouldn't happen
|
||||
}
|
||||
}
|
||||
@@ -38,16 +38,12 @@ import forge.view.arcane.CardPanel;
|
||||
public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
private static final float GAP_SCALE_FACTOR = 0.04f;
|
||||
|
||||
public enum LayoutType {
|
||||
Spreadsheet,
|
||||
Piles
|
||||
}
|
||||
|
||||
private final CardViewDisplay display;
|
||||
private List<Integer> selectedIndices = new ArrayList<Integer>();
|
||||
private int imageScaleFactor = 3;
|
||||
private boolean allowMultipleSelections;
|
||||
private LayoutType layoutType = LayoutType.Spreadsheet;
|
||||
private ColumnDef pileBy = null;
|
||||
private GroupDef groupBy = null;
|
||||
|
||||
public ImageView(ItemManager<T> itemManager0, ItemManagerModel<T> model0) {
|
||||
super(itemManager0, model0);
|
||||
@@ -118,7 +114,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
|
||||
@Override
|
||||
protected void onResize() {
|
||||
if (this.layoutType == LayoutType.Spreadsheet) {
|
||||
if (this.pileBy == null) {
|
||||
display.refresh(); //need to refresh to adjust wrapping of items
|
||||
}
|
||||
}
|
||||
@@ -275,7 +271,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
display.scrollRectToVisible(new Rectangle(x, y, width, height));
|
||||
}
|
||||
}
|
||||
private class Section extends DisplayArea {
|
||||
private class Group extends DisplayArea {
|
||||
private final List<Pile> piles = new ArrayList<Pile>();
|
||||
private boolean isCollapsed;
|
||||
}
|
||||
@@ -304,7 +300,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
private Point hoverScrollPos;
|
||||
private ItemInfo hoveredItem;
|
||||
private List<ItemInfo> items = new ArrayList<ItemInfo>();
|
||||
private List<Section> sections = new ArrayList<Section>();
|
||||
private List<Group> sections = new ArrayList<Group>();
|
||||
|
||||
private CardViewDisplay() {
|
||||
this.setOpaque(false);
|
||||
@@ -326,13 +322,11 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
this.sections.clear();
|
||||
|
||||
if (!this.items.isEmpty()) {
|
||||
switch (ImageView.this.layoutType) {
|
||||
case Spreadsheet:
|
||||
if (ImageView.this.pileBy == null) {
|
||||
buildSpreadsheet();
|
||||
break;
|
||||
case Piles:
|
||||
}
|
||||
else {
|
||||
buildPiles();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,10 +336,10 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
|
||||
private ItemInfo getItemAtPoint(Point p) {
|
||||
for (int i = this.sections.size() - 1; i >= 0; i--) {
|
||||
Section section = this.sections.get(i);
|
||||
if (!section.isCollapsed && section.getBounds().contains(p)) {
|
||||
for (int j = section.piles.size() - 1; j >= 0; j--) {
|
||||
Pile pile = section.piles.get(j);
|
||||
Group group = this.sections.get(i);
|
||||
if (!group.isCollapsed && group.getBounds().contains(p)) {
|
||||
for (int j = group.piles.size() - 1; j >= 0; j--) {
|
||||
Pile pile = group.piles.get(j);
|
||||
if (pile.getBounds().contains(p)) {
|
||||
for (int k = pile.items.size() - 1; k >= 0; k--) {
|
||||
ItemInfo item = pile.items.get(k);
|
||||
@@ -378,7 +372,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
private void buildSpreadsheet() {
|
||||
ImageView.this.getScroller().setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
|
||||
Section section = new Section();
|
||||
Group group = new Group();
|
||||
|
||||
final int itemAreaWidth = getVisibleSize().width;
|
||||
int itemWidth = 50 * imageScaleFactor;
|
||||
@@ -407,16 +401,16 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
|
||||
if (pile.items.size() == 0) {
|
||||
pile.setBounds(0, y, itemAreaWidth, dy);
|
||||
section.piles.add(pile);
|
||||
group.piles.add(pile);
|
||||
}
|
||||
pile.items.add(itemInfo);
|
||||
x += dx;
|
||||
}
|
||||
|
||||
section.setBounds(0, 0, itemAreaWidth, y + itemHeight + CardArea.GUTTER_Y);
|
||||
this.setPreferredSize(section.getBounds().getSize());
|
||||
group.setBounds(0, 0, itemAreaWidth, y + itemHeight + CardArea.GUTTER_Y);
|
||||
this.setPreferredSize(group.getBounds().getSize());
|
||||
|
||||
this.sections.add(section);
|
||||
this.sections.add(group);
|
||||
}
|
||||
|
||||
private void buildPiles() {
|
||||
@@ -458,26 +452,25 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
int sectionIdx = 0, pileIdx = 0;
|
||||
final int scrollTop = ImageView.this.getScroller().getVerticalScrollBar().getValue();
|
||||
final int scrollBottom = scrollTop + getVisibleSize().height;
|
||||
switch (ImageView.this.layoutType) {
|
||||
case Spreadsheet:
|
||||
if (ImageView.this.pileBy == null) {
|
||||
pileIdx = scrollTop / this.sections.get(0).piles.get(0).getBounds().height;
|
||||
break;
|
||||
case Piles:
|
||||
break;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
for (; sectionIdx < this.sections.size(); sectionIdx++, pileIdx = 0) {
|
||||
Section section = this.sections.get(sectionIdx);
|
||||
if (section.getBounds().y >= scrollBottom) {
|
||||
Group group = this.sections.get(sectionIdx);
|
||||
if (group.getBounds().y >= scrollBottom) {
|
||||
break;
|
||||
}
|
||||
if (this.sections.size() > 1) {
|
||||
//TODO: Draw section name/border
|
||||
if (section.isCollapsed) {
|
||||
//TODO: Draw group name/border
|
||||
if (group.isCollapsed) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (; pileIdx < section.piles.size(); pileIdx++) {
|
||||
Pile pile = section.piles.get(pileIdx);
|
||||
for (; pileIdx < group.piles.size(); pileIdx++) {
|
||||
Pile pile = group.piles.get(pileIdx);
|
||||
if (pile.getBounds().y >= scrollBottom) {
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user