mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
small cleanups in DragCardGrid
This commit is contained in:
parent
8cf681dff2
commit
872eea7326
1 changed files with 75 additions and 88 deletions
|
@ -6,6 +6,7 @@ import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -35,18 +36,12 @@ import org.mage.card.arcane.CardRenderer;
|
||||||
*/
|
*/
|
||||||
public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarget {
|
public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarget {
|
||||||
|
|
||||||
private final static Logger LOGGER = Logger.getLogger(DragCardGrid.class);
|
private static final Logger LOGGER = Logger.getLogger(DragCardGrid.class);
|
||||||
private Constants.DeckEditorMode mode;
|
private Constants.DeckEditorMode mode;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<CardView> dragCardList() {
|
public Collection<CardView> dragCardList() {
|
||||||
ArrayList<CardView> selectedCards = new ArrayList<>();
|
return allCards.stream().filter(CardView::isSelected).collect(Collectors.toCollection(ArrayList::new));
|
||||||
for (CardView card : allCards) {
|
|
||||||
if (card.isSelected()) {
|
|
||||||
selectedCards.add(card);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return selectedCards;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -62,8 +57,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
// Don't remove the cards, no target
|
// Don't remove the cards, no target
|
||||||
} else {
|
} else {
|
||||||
// Remove dragged cards
|
// Remove dragged cards
|
||||||
for (ArrayList<ArrayList<CardView>> gridRow : cardGrid) {
|
for (List<List<CardView>> gridRow : cardGrid) {
|
||||||
for (ArrayList<CardView> stack : gridRow) {
|
for (List<CardView> stack : gridRow) {
|
||||||
for (int i = 0; i < stack.size(); ++i) {
|
for (int i = 0; i < stack.size(); ++i) {
|
||||||
CardView card = stack.get(i);
|
CardView card = stack.get(i);
|
||||||
if (card.isSelected()) {
|
if (card.isSelected()) {
|
||||||
|
@ -160,7 +155,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the appropirate stack
|
// Get the appropirate stack
|
||||||
ArrayList<CardView> stack;
|
List<CardView> stack;
|
||||||
if (rowIndex < cardGrid.size() && col < cardGrid.get(0).size()) {
|
if (rowIndex < cardGrid.size() && col < cardGrid.get(0).size()) {
|
||||||
stack = cardGrid.get(rowIndex).get(col);
|
stack = cardGrid.get(rowIndex).get(col);
|
||||||
} else {
|
} else {
|
||||||
|
@ -200,8 +195,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
// If we're dragging onto ourself, erase the old cards (just null them out, we will
|
// If we're dragging onto ourself, erase the old cards (just null them out, we will
|
||||||
// compact the grid removing the null gaps / empty rows & cols later)
|
// compact the grid removing the null gaps / empty rows & cols later)
|
||||||
if (source == this) {
|
if (source == this) {
|
||||||
for (ArrayList<ArrayList<CardView>> gridRow : cardGrid) {
|
for (List<List<CardView>> gridRow : cardGrid) {
|
||||||
for (ArrayList<CardView> stack : gridRow) {
|
for (List<CardView> stack : gridRow) {
|
||||||
for (int i = 0; i < stack.size(); ++i) {
|
for (int i = 0; i < stack.size(); ++i) {
|
||||||
if (cards.contains(stack.get(i))) {
|
if (cards.contains(stack.get(i))) {
|
||||||
stack.set(i, null);
|
stack.set(i, null);
|
||||||
|
@ -241,7 +236,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
|
|
||||||
// Add a new row if needed
|
// Add a new row if needed
|
||||||
if (rowIndex >= cardGrid.size()) {
|
if (rowIndex >= cardGrid.size()) {
|
||||||
ArrayList<ArrayList<CardView>> newRow = new ArrayList<>();
|
List<List<CardView>> newRow = new ArrayList<>();
|
||||||
if (!cardGrid.isEmpty()) {
|
if (!cardGrid.isEmpty()) {
|
||||||
for (int colIndex = 0; colIndex < cardGrid.get(0).size(); ++colIndex) {
|
for (int colIndex = 0; colIndex < cardGrid.get(0).size(); ++colIndex) {
|
||||||
newRow.add(new ArrayList<>());
|
newRow.add(new ArrayList<>());
|
||||||
|
@ -286,7 +281,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
|
|
||||||
// Add a new row if needed
|
// Add a new row if needed
|
||||||
if (rowIndex >= cardGrid.size()) {
|
if (rowIndex >= cardGrid.size()) {
|
||||||
ArrayList<ArrayList<CardView>> newRow = new ArrayList<>();
|
List<List<CardView>> newRow = new ArrayList<>();
|
||||||
if (!cardGrid.isEmpty()) {
|
if (!cardGrid.isEmpty()) {
|
||||||
for (int colIndex = 0; colIndex < cardGrid.get(0).size(); ++colIndex) {
|
for (int colIndex = 0; colIndex < cardGrid.get(0).size(); ++colIndex) {
|
||||||
newRow.add(new ArrayList<>());
|
newRow.add(new ArrayList<>());
|
||||||
|
@ -304,7 +299,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the appropirate stack
|
// Get the appropirate stack
|
||||||
ArrayList<CardView> stack = cardGrid.get(rowIndex).get(col);
|
List<CardView> stack = cardGrid.get(rowIndex).get(col);
|
||||||
|
|
||||||
// Figure out position in the stack based on the offsetIntoRow
|
// Figure out position in the stack based on the offsetIntoRow
|
||||||
int stackInsertIndex = (offsetIntoStack + cardTopHeight / 2) / cardTopHeight;
|
int stackInsertIndex = (offsetIntoStack + cardTopHeight / 2) / cardTopHeight;
|
||||||
|
@ -375,8 +370,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSelection() {
|
public void removeSelection() {
|
||||||
for (ArrayList<ArrayList<CardView>> gridRow : cardGrid) {
|
for (List<List<CardView>> gridRow : cardGrid) {
|
||||||
for (ArrayList<CardView> stack : gridRow) {
|
for (List<CardView> stack : gridRow) {
|
||||||
for (int i = 0; i < stack.size(); ++i) {
|
for (int i = 0; i < stack.size(); ++i) {
|
||||||
CardView card = stack.get(i);
|
CardView card = stack.get(i);
|
||||||
if (card.isSelected()) {
|
if (card.isSelected()) {
|
||||||
|
@ -394,11 +389,11 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
|
|
||||||
public DeckCardLayout getCardLayout() {
|
public DeckCardLayout getCardLayout() {
|
||||||
// 2D Array to put entries into
|
// 2D Array to put entries into
|
||||||
java.util.List<java.util.List<java.util.List<DeckCardInfo>>> info = new ArrayList<>();
|
List<List<List<DeckCardInfo>>> info = new ArrayList<>();
|
||||||
for (ArrayList<ArrayList<CardView>> gridRow : cardGrid) {
|
for (List<List<CardView>> gridRow : cardGrid) {
|
||||||
java.util.List<java.util.List<DeckCardInfo>> row = new ArrayList<>();
|
List<List<DeckCardInfo>> row = new ArrayList<>();
|
||||||
info.add(row);
|
info.add(row);
|
||||||
for (ArrayList<CardView> stack : gridRow) {
|
for (List<CardView> stack : gridRow) {
|
||||||
row.add(stack.stream()
|
row.add(stack.stream()
|
||||||
.map(card -> new DeckCardInfo(card.getName(), card.getCardNumber(), card.getExpansionSetCode()))
|
.map(card -> new DeckCardInfo(card.getName(), card.getCardNumber(), card.getExpansionSetCode()))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
|
@ -544,12 +539,12 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
public static final int COUNT_LABEL_HEIGHT = 20;
|
public static final int COUNT_LABEL_HEIGHT = 20;
|
||||||
public static final int GRID_PADDING = 10;
|
public static final int GRID_PADDING = 10;
|
||||||
|
|
||||||
private final static ImageIcon INSERT_ROW_ICON = new ImageIcon(DragCardGrid.class.getClassLoader().getResource("editor_insert_row.png"));
|
private static final ImageIcon INSERT_ROW_ICON = new ImageIcon(DragCardGrid.class.getClassLoader().getResource("editor_insert_row.png"));
|
||||||
private final static ImageIcon INSERT_COL_ICON = new ImageIcon(DragCardGrid.class.getClassLoader().getResource("editor_insert_col.png"));
|
private static final ImageIcon INSERT_COL_ICON = new ImageIcon(DragCardGrid.class.getClassLoader().getResource("editor_insert_col.png"));
|
||||||
|
|
||||||
// All of the current card views
|
// All of the current card views
|
||||||
private final Map<UUID, MageCard> cardViews = new LinkedHashMap<>();
|
private final Map<UUID, MageCard> cardViews = new LinkedHashMap<>();
|
||||||
private final ArrayList<CardView> allCards = new ArrayList<>();
|
private final List<CardView> allCards = new ArrayList<>();
|
||||||
|
|
||||||
// Card listeners
|
// Card listeners
|
||||||
private final CardEventSource eventSource = new CardEventSource();
|
private final CardEventSource eventSource = new CardEventSource();
|
||||||
|
@ -578,8 +573,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
final JSlider cardSizeSlider;
|
final JSlider cardSizeSlider;
|
||||||
final JLabel cardSizeSliderLabel;
|
final JLabel cardSizeSliderLabel;
|
||||||
|
|
||||||
final Map<Sort, AbstractButton> sortButtons = new HashMap<>();
|
final Map<Sort, AbstractButton> sortButtons = new EnumMap<>(Sort.class);
|
||||||
final HashMap<CardType, AbstractButton> selectByTypeButtons = new HashMap<>();
|
final Map<CardType, AbstractButton> selectByTypeButtons = new EnumMap<>(CardType.class);
|
||||||
|
|
||||||
final JLabel deckNameAndCountLabel;
|
final JLabel deckNameAndCountLabel;
|
||||||
final JLabel landCountLabel;
|
final JLabel landCountLabel;
|
||||||
|
@ -611,11 +606,11 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
// The outermost array contains multiple rows of stacks of cards
|
// The outermost array contains multiple rows of stacks of cards
|
||||||
// The next inner array represents a row of stacks of cards
|
// The next inner array represents a row of stacks of cards
|
||||||
// The innermost array represents a single vertical stack of cards
|
// The innermost array represents a single vertical stack of cards
|
||||||
private ArrayList<ArrayList<ArrayList<CardView>>> cardGrid;
|
private List<List<List<CardView>>> cardGrid;
|
||||||
private ArrayList<Integer> maxStackSize = new ArrayList<>();
|
private List<Integer> maxStackSize = new ArrayList<>();
|
||||||
private final ArrayList<ArrayList<JLabel>> stackCountLabels = new ArrayList<>();
|
private final List<List<JLabel>> stackCountLabels = new ArrayList<>();
|
||||||
private Sort cardSort = Sort.CMC;
|
private Sort cardSort = Sort.CMC;
|
||||||
private final ArrayList<CardType> selectByTypeSelected = new ArrayList<>();
|
private final List<CardType> selectByTypeSelected = new ArrayList<>();
|
||||||
private boolean separateCreatures = true;
|
private boolean separateCreatures = true;
|
||||||
|
|
||||||
public enum Role {
|
public enum Role {
|
||||||
|
@ -639,7 +634,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
public boolean separateCreatures;
|
public boolean separateCreatures;
|
||||||
public int cardSize;
|
public int cardSize;
|
||||||
|
|
||||||
private final static Pattern parser = Pattern.compile("\\(([^,]*),([^,]*),([^)]*)\\)");
|
private static final Pattern parser = Pattern.compile("\\(([^,]*),([^,]*),([^)]*)\\)");
|
||||||
|
|
||||||
public static Settings parse(String str) {
|
public static Settings parse(String str) {
|
||||||
Matcher m = parser.matcher(str);
|
Matcher m = parser.matcher(str);
|
||||||
|
@ -917,7 +912,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
ButtonGroup selectByTypeModeGroup = new ButtonGroup();
|
ButtonGroup selectByTypeModeGroup = new ButtonGroup();
|
||||||
for (final CardType cardType : CardType.values()) {
|
for (final CardType cardType : CardType.values()) {
|
||||||
|
|
||||||
if (cardType == cardType.CONSPIRACY) {
|
if (cardType == CardType.CONSPIRACY) {
|
||||||
multiplesButton = new JToggleButton("Multiples");
|
multiplesButton = new JToggleButton("Multiples");
|
||||||
selectByTypeButtons.put(cardType, multiplesButton);
|
selectByTypeButtons.put(cardType, multiplesButton);
|
||||||
selectByTypeMode.add(multiplesButton);
|
selectByTypeMode.add(multiplesButton);
|
||||||
|
@ -1045,8 +1040,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
* Deselect all cards in this DragCardGrid
|
* Deselect all cards in this DragCardGrid
|
||||||
*/
|
*/
|
||||||
public void deselectAll() {
|
public void deselectAll() {
|
||||||
for (ArrayList<ArrayList<CardView>> gridRow : cardGrid) {
|
for (List<List<CardView>> gridRow : cardGrid) {
|
||||||
for (ArrayList<CardView> stack : gridRow) {
|
for (List<CardView> stack : gridRow) {
|
||||||
for (CardView card : stack) {
|
for (CardView card : stack) {
|
||||||
if (card.isSelected()) {
|
if (card.isSelected()) {
|
||||||
card.setSelected(false);
|
card.setSelected(false);
|
||||||
|
@ -1166,9 +1161,9 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
} else {
|
} else {
|
||||||
stackEndIndex = (y2 - curY) / cardTopHeight;
|
stackEndIndex = (y2 - curY) / cardTopHeight;
|
||||||
}
|
}
|
||||||
ArrayList<ArrayList<CardView>> gridRow = cardGrid.get(rowIndex);
|
List<List<CardView>> gridRow = cardGrid.get(rowIndex);
|
||||||
for (int col = 0; col < gridRow.size(); ++col) {
|
for (int col = 0; col < gridRow.size(); ++col) {
|
||||||
ArrayList<CardView> stack = gridRow.get(col);
|
List<CardView> stack = gridRow.get(col);
|
||||||
int stackBottomBegin = curY + cardTopHeight * (stack.size());
|
int stackBottomBegin = curY + cardTopHeight * (stack.size());
|
||||||
int stackBottomEnd = curY + cardTopHeight * (stack.size() - 1) + cardHeight;
|
int stackBottomEnd = curY + cardTopHeight * (stack.size() - 1) + cardHeight;
|
||||||
for (int i = 0; i < stack.size(); ++i) {
|
for (int i = 0; i < stack.size(); ++i) {
|
||||||
|
@ -1201,8 +1196,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
// Resort the existing cards based on the current sort
|
// Resort the existing cards based on the current sort
|
||||||
public void resort() {
|
public void resort() {
|
||||||
// First null out the grid and trim it down
|
// First null out the grid and trim it down
|
||||||
for (ArrayList<ArrayList<CardView>> gridRow : cardGrid) {
|
for (List<List<CardView>> gridRow : cardGrid) {
|
||||||
for (ArrayList<CardView> stack : gridRow) {
|
for (List<CardView> stack : gridRow) {
|
||||||
stack.clear();
|
stack.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1243,8 +1238,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
if (cardType == CardType.CONSPIRACY) {
|
if (cardType == CardType.CONSPIRACY) {
|
||||||
HashMap<String, CardView> cardNames = new HashMap<>();
|
HashMap<String, CardView> cardNames = new HashMap<>();
|
||||||
|
|
||||||
for (ArrayList<ArrayList<CardView>> gridRow : cardGrid) {
|
for (List<List<CardView>> gridRow : cardGrid) {
|
||||||
for (ArrayList<CardView> stack : gridRow) {
|
for (List<CardView> stack : gridRow) {
|
||||||
for (CardView card : stack) {
|
for (CardView card : stack) {
|
||||||
if (cardNames.get(card.getName()) == null) {
|
if (cardNames.get(card.getName()) == null) {
|
||||||
cardNames.put(card.getName(), card);
|
cardNames.put(card.getName(), card);
|
||||||
|
@ -1262,8 +1257,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ArrayList<ArrayList<CardView>> gridRow : cardGrid) {
|
for (List<List<CardView>> gridRow : cardGrid) {
|
||||||
for (ArrayList<CardView> stack : gridRow) {
|
for (List<CardView> stack : gridRow) {
|
||||||
for (CardView card : stack) {
|
for (CardView card : stack) {
|
||||||
boolean s = card.isSelected() | card.getCardTypes().contains(cardType);
|
boolean s = card.isSelected() | card.getCardTypes().contains(cardType);
|
||||||
card.setSelected(s);
|
card.setSelected(s);
|
||||||
|
@ -1276,13 +1271,13 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useText) {
|
if (useText) {
|
||||||
for (ArrayList<ArrayList<CardView>> gridRow : cardGrid) {
|
for (List<List<CardView>> gridRow : cardGrid) {
|
||||||
for (ArrayList<CardView> stack : gridRow) {
|
for (List<CardView> stack : gridRow) {
|
||||||
for (CardView card : stack) {
|
for (CardView card : stack) {
|
||||||
boolean s = card.isSelected();
|
boolean s = card.isSelected();
|
||||||
// Name
|
// Name
|
||||||
if (!s) {
|
if (!s) {
|
||||||
s |= card.getName().toLowerCase(Locale.ENGLISH).contains(searchStr);
|
s = card.getName().toLowerCase(Locale.ENGLISH).contains(searchStr);
|
||||||
}
|
}
|
||||||
// Sub & Super Types
|
// Sub & Super Types
|
||||||
if (!s) {
|
if (!s) {
|
||||||
|
@ -1354,21 +1349,13 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
qtys.put("wastes", 0);
|
qtys.put("wastes", 0);
|
||||||
manaCounts = new HashMap<>();
|
manaCounts = new HashMap<>();
|
||||||
|
|
||||||
for (ArrayList<ArrayList<CardView>> gridRow : cardGrid) {
|
for (List<List<CardView>> gridRow : cardGrid) {
|
||||||
for (ArrayList<CardView> stack : gridRow) {
|
for (List<CardView> stack : gridRow) {
|
||||||
for (CardView card : stack) {
|
for (CardView card : stack) {
|
||||||
// Type line
|
// Type line
|
||||||
String t = "";
|
String t = card.getCardTypes().stream().map(CardType::toString).collect(Collectors.joining(" "));
|
||||||
for (CardType type : card.getCardTypes()) {
|
t += card.getSuperTypes().stream().map(st -> st.toString().toLowerCase(Locale.ENGLISH)).collect(Collectors.joining(" "));
|
||||||
t += ' ' + type.toString();
|
t += card.getSubTypes().stream().map(st -> st.toString().toLowerCase(Locale.ENGLISH)).collect(Collectors.joining(" "));
|
||||||
}
|
|
||||||
// Sub & Super Types
|
|
||||||
for (SuperType type : card.getSuperTypes()) {
|
|
||||||
t += ' ' + type.toString().toLowerCase(Locale.ENGLISH);
|
|
||||||
}
|
|
||||||
for (SubType str : card.getSubTypes()) {
|
|
||||||
t += " " + str.toString().toLowerCase(Locale.ENGLISH);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String qty : qtys.keySet()) {
|
for (String qty : qtys.keySet()) {
|
||||||
int value = qtys.get(qty);
|
int value = qtys.get(qty);
|
||||||
|
@ -1494,7 +1481,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
}
|
}
|
||||||
|
|
||||||
public void blingDeck() {
|
public void blingDeck() {
|
||||||
if (!(this.mode == Constants.DeckEditorMode.FREE_BUILDING)) {
|
if (this.mode != Constants.DeckEditorMode.FREE_BUILDING) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1503,8 +1490,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMap<String, Integer> pimpedSets = new HashMap<>();
|
Map<String, Integer> pimpedSets = new HashMap<>();
|
||||||
HashMap<CardView, Integer> pimpedCards = new HashMap<>();
|
Map<CardView, Integer> pimpedCards = new HashMap<>();
|
||||||
pimpedSets.put("CP", 1);
|
pimpedSets.put("CP", 1);
|
||||||
pimpedSets.put("JR", 1);
|
pimpedSets.put("JR", 1);
|
||||||
pimpedSets.put("MPS", 1);
|
pimpedSets.put("MPS", 1);
|
||||||
|
@ -1529,8 +1516,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
String[] sets = pimpedSets.keySet().toArray(new String[pimpedSets.keySet().size()]);
|
String[] sets = pimpedSets.keySet().toArray(new String[pimpedSets.keySet().size()]);
|
||||||
Boolean didModify = false;
|
Boolean didModify = false;
|
||||||
|
|
||||||
for (ArrayList<ArrayList<CardView>> gridRow : cardGrid) {
|
for (List<List<CardView>> gridRow : cardGrid) {
|
||||||
for (ArrayList<CardView> stack : gridRow) {
|
for (List<CardView> stack : gridRow) {
|
||||||
for (CardView card : stack) {
|
for (CardView card : stack) {
|
||||||
if (card.getSuperTypes().contains(SuperType.BASIC)) {
|
if (card.getSuperTypes().contains(SuperType.BASIC)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -1580,9 +1567,9 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
// Remove all of the cards not in the cardsView
|
// Remove all of the cards not in the cardsView
|
||||||
boolean didModify = false; // Until contested
|
boolean didModify = false; // Until contested
|
||||||
for (int i = 0; i < cardGrid.size(); ++i) {
|
for (int i = 0; i < cardGrid.size(); ++i) {
|
||||||
ArrayList<ArrayList<CardView>> gridRow = cardGrid.get(i);
|
List<List<CardView>> gridRow = cardGrid.get(i);
|
||||||
for (int j = 0; j < gridRow.size(); ++j) {
|
for (int j = 0; j < gridRow.size(); ++j) {
|
||||||
ArrayList<CardView> stack = gridRow.get(j);
|
List<CardView> stack = gridRow.get(j);
|
||||||
for (int k = 0; k < stack.size(); ++k) {
|
for (int k = 0; k < stack.size(); ++k) {
|
||||||
CardView card = stack.get(k);
|
CardView card = stack.get(k);
|
||||||
if (!cardsView.containsKey(card.getId())) {
|
if (!cardsView.containsKey(card.getId())) {
|
||||||
|
@ -1626,21 +1613,21 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
loadSettings(Settings.parse(layout.getSettings()));
|
loadSettings(Settings.parse(layout.getSettings()));
|
||||||
|
|
||||||
// Traverse the cards once and track them so we can pick ones to insert into the grid
|
// Traverse the cards once and track them so we can pick ones to insert into the grid
|
||||||
Map<String, Map<String, ArrayList<CardView>>> trackedCards = new HashMap<>();
|
Map<String, Map<String, List<CardView>>> trackedCards = new HashMap<>();
|
||||||
for (CardView newCard : cardsView.values()) {
|
for (CardView newCard : cardsView.values()) {
|
||||||
if (!cardViews.containsKey(newCard.getId())) {
|
if (!cardViews.containsKey(newCard.getId())) {
|
||||||
// Add the new card
|
// Add the new card
|
||||||
addCardView(newCard, false);
|
addCardView(newCard, false);
|
||||||
|
|
||||||
// Add the new card to tracking
|
// Add the new card to tracking
|
||||||
Map<String, ArrayList<CardView>> forSetCode;
|
Map<String, List<CardView>> forSetCode;
|
||||||
if (trackedCards.containsKey(newCard.getExpansionSetCode())) {
|
if (trackedCards.containsKey(newCard.getExpansionSetCode())) {
|
||||||
forSetCode = trackedCards.get(newCard.getExpansionSetCode());
|
forSetCode = trackedCards.get(newCard.getExpansionSetCode());
|
||||||
} else {
|
} else {
|
||||||
forSetCode = new HashMap<>();
|
forSetCode = new HashMap<>();
|
||||||
trackedCards.put(newCard.getExpansionSetCode(), forSetCode);
|
trackedCards.put(newCard.getExpansionSetCode(), forSetCode);
|
||||||
}
|
}
|
||||||
ArrayList<CardView> list;
|
List<CardView> list;
|
||||||
if (forSetCode.containsKey(newCard.getCardNumber())) {
|
if (forSetCode.containsKey(newCard.getCardNumber())) {
|
||||||
list = forSetCode.get(newCard.getCardNumber());
|
list = forSetCode.get(newCard.getCardNumber());
|
||||||
} else {
|
} else {
|
||||||
|
@ -1654,16 +1641,16 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
// Now go through the layout and use it to build the cardGrid
|
// Now go through the layout and use it to build the cardGrid
|
||||||
cardGrid = new ArrayList<>();
|
cardGrid = new ArrayList<>();
|
||||||
maxStackSize = new ArrayList<>();
|
maxStackSize = new ArrayList<>();
|
||||||
for (java.util.List<java.util.List<DeckCardInfo>> row : layout.getCards()) {
|
for (List<List<DeckCardInfo>> row : layout.getCards()) {
|
||||||
ArrayList<ArrayList<CardView>> gridRow = new ArrayList<>();
|
List<List<CardView>> gridRow = new ArrayList<>();
|
||||||
int thisMaxStackSize = 0;
|
int thisMaxStackSize = 0;
|
||||||
cardGrid.add(gridRow);
|
cardGrid.add(gridRow);
|
||||||
for (java.util.List<DeckCardInfo> stack : row) {
|
for (List<DeckCardInfo> stack : row) {
|
||||||
ArrayList<CardView> gridStack = new ArrayList<>();
|
ArrayList<CardView> gridStack = new ArrayList<>();
|
||||||
gridRow.add(gridStack);
|
gridRow.add(gridStack);
|
||||||
for (DeckCardInfo info : stack) {
|
for (DeckCardInfo info : stack) {
|
||||||
if (trackedCards.containsKey(info.getSetCode()) && trackedCards.get(info.getSetCode()).containsKey(info.getCardNum())) {
|
if (trackedCards.containsKey(info.getSetCode()) && trackedCards.get(info.getSetCode()).containsKey(info.getCardNum())) {
|
||||||
ArrayList<CardView> candidates
|
List<CardView> candidates
|
||||||
= trackedCards.get(info.getSetCode()).get(info.getCardNum());
|
= trackedCards.get(info.getSetCode()).get(info.getCardNum());
|
||||||
if (!candidates.isEmpty()) {
|
if (!candidates.isEmpty()) {
|
||||||
gridStack.add(candidates.remove(0));
|
gridStack.add(candidates.remove(0));
|
||||||
|
@ -1678,8 +1665,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
// Check that there aren't any "orphans" not referenced in the layout. There should
|
// Check that there aren't any "orphans" not referenced in the layout. There should
|
||||||
// never be any under normal operation, but as a failsafe in case the user screwed with
|
// never be any under normal operation, but as a failsafe in case the user screwed with
|
||||||
// the file in an invalid way, sort them into the grid so that they aren't just left hanging.
|
// the file in an invalid way, sort them into the grid so that they aren't just left hanging.
|
||||||
for (Map<String, ArrayList<CardView>> tracked : trackedCards.values()) {
|
for (Map<String, List<CardView>> tracked : trackedCards.values()) {
|
||||||
for (ArrayList<CardView> orphans : tracked.values()) {
|
for (List<CardView> orphans : tracked.values()) {
|
||||||
for (CardView orphan : orphans) {
|
for (CardView orphan : orphans) {
|
||||||
LOGGER.info("Orphan when setting with layout: ");
|
LOGGER.info("Orphan when setting with layout: ");
|
||||||
sortIntoGrid(orphan);
|
sortIntoGrid(orphan);
|
||||||
|
@ -1733,7 +1720,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
AbstractButton button = selectByTypeButtons.get(cardType);
|
AbstractButton button = selectByTypeButtons.get(cardType);
|
||||||
String text = cardType.toString();
|
String text = cardType.toString();
|
||||||
int numCards = getCount(cardType);
|
int numCards = getCount(cardType);
|
||||||
if (cardType == cardType.CONSPIRACY) {
|
if (cardType == CardType.CONSPIRACY) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1908,7 +1895,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
maxStackSize.add(0, 0);
|
maxStackSize.add(0, 0);
|
||||||
}
|
}
|
||||||
// What row to add it to?
|
// What row to add it to?
|
||||||
ArrayList<ArrayList<CardView>> targetRow;
|
List<List<CardView>> targetRow;
|
||||||
if (separateCreatures && !newCard.isCreature()) {
|
if (separateCreatures && !newCard.isCreature()) {
|
||||||
// Ensure row 2 exists
|
// Ensure row 2 exists
|
||||||
if (cardGrid.size() < 2) {
|
if (cardGrid.size() < 2) {
|
||||||
|
@ -1929,7 +1916,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
for (int currentColumn = 0; currentColumn < cardGrid.get(0).size(); ++currentColumn) {
|
for (int currentColumn = 0; currentColumn < cardGrid.get(0).size(); ++currentColumn) {
|
||||||
// Find an item from this column
|
// Find an item from this column
|
||||||
CardView cardInColumn = null;
|
CardView cardInColumn = null;
|
||||||
for (ArrayList<ArrayList<CardView>> gridRow : cardGrid) {
|
for (List<List<CardView>> gridRow : cardGrid) {
|
||||||
for (CardView card : gridRow.get(currentColumn)) {
|
for (CardView card : gridRow.get(currentColumn)) {
|
||||||
cardInColumn = card;
|
cardInColumn = card;
|
||||||
break;
|
break;
|
||||||
|
@ -1974,9 +1961,9 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
private void trimGrid() {
|
private void trimGrid() {
|
||||||
// Compact stacks and rows
|
// Compact stacks and rows
|
||||||
for (int rowIndex = 0; rowIndex < cardGrid.size(); ++rowIndex) {
|
for (int rowIndex = 0; rowIndex < cardGrid.size(); ++rowIndex) {
|
||||||
ArrayList<ArrayList<CardView>> gridRow = cardGrid.get(rowIndex);
|
List<List<CardView>> gridRow = cardGrid.get(rowIndex);
|
||||||
int rowMaxStackSize = 0;
|
int rowMaxStackSize = 0;
|
||||||
for (ArrayList<CardView> stack : gridRow) {
|
for (List<CardView> stack : gridRow) {
|
||||||
// Clear out nulls in the stack
|
// Clear out nulls in the stack
|
||||||
for (int i = 0; i < stack.size(); ++i) {
|
for (int i = 0; i < stack.size(); ++i) {
|
||||||
if (stack.get(i) == null) {
|
if (stack.get(i) == null) {
|
||||||
|
@ -2000,15 +1987,15 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
if (!cardGrid.isEmpty()) {
|
if (!cardGrid.isEmpty()) {
|
||||||
for (int colIndex = 0; colIndex < cardGrid.get(0).size(); ++colIndex) {
|
for (int colIndex = 0; colIndex < cardGrid.get(0).size(); ++colIndex) {
|
||||||
boolean hasContent = false; // Until contested
|
boolean hasContent = false; // Until contested
|
||||||
for (int rowIndex = 0; rowIndex < cardGrid.size(); ++rowIndex) {
|
for (List<List<CardView>> aCardGrid : cardGrid) {
|
||||||
if (!cardGrid.get(rowIndex).get(colIndex).isEmpty()) {
|
if (!aCardGrid.get(colIndex).isEmpty()) {
|
||||||
hasContent = true;
|
hasContent = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hasContent) {
|
if (!hasContent) {
|
||||||
for (int rowIndex = 0; rowIndex < cardGrid.size(); ++rowIndex) {
|
for (List<List<CardView>> aCardGrid : cardGrid) {
|
||||||
cardGrid.get(rowIndex).remove(colIndex);
|
aCardGrid.remove(colIndex);
|
||||||
}
|
}
|
||||||
--colIndex;
|
--colIndex;
|
||||||
}
|
}
|
||||||
|
@ -2017,13 +2004,13 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
|
|
||||||
// Clean up extra column header count labels
|
// Clean up extra column header count labels
|
||||||
while (stackCountLabels.size() > cardGrid.size()) {
|
while (stackCountLabels.size() > cardGrid.size()) {
|
||||||
ArrayList<JLabel> labels = stackCountLabels.remove(cardGrid.size());
|
List<JLabel> labels = stackCountLabels.remove(cardGrid.size());
|
||||||
for (JLabel label : labels) {
|
for (JLabel label : labels) {
|
||||||
cardContent.remove(label);
|
cardContent.remove(label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int colCount = cardGrid.isEmpty() ? 0 : cardGrid.get(0).size();
|
int colCount = cardGrid.isEmpty() ? 0 : cardGrid.get(0).size();
|
||||||
for (ArrayList<JLabel> labels : stackCountLabels) {
|
for (List<JLabel> labels : stackCountLabels) {
|
||||||
while (labels.size() > colCount) {
|
while (labels.size() > colCount) {
|
||||||
cardContent.remove(labels.remove(colCount));
|
cardContent.remove(labels.remove(colCount));
|
||||||
}
|
}
|
||||||
|
@ -2056,9 +2043,9 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
int maxWidth = 0;
|
int maxWidth = 0;
|
||||||
for (int rowIndex = 0; rowIndex < cardGrid.size(); ++rowIndex) {
|
for (int rowIndex = 0; rowIndex < cardGrid.size(); ++rowIndex) {
|
||||||
int rowMaxStackSize = 0;
|
int rowMaxStackSize = 0;
|
||||||
ArrayList<ArrayList<CardView>> gridRow = cardGrid.get(rowIndex);
|
List<List<CardView>> gridRow = cardGrid.get(rowIndex);
|
||||||
for (int colIndex = 0; colIndex < gridRow.size(); ++colIndex) {
|
for (int colIndex = 0; colIndex < gridRow.size(); ++colIndex) {
|
||||||
ArrayList<CardView> stack = gridRow.get(colIndex);
|
List<CardView> stack = gridRow.get(colIndex);
|
||||||
|
|
||||||
// Stack count label
|
// Stack count label
|
||||||
if (stackCountLabels.size() <= rowIndex) {
|
if (stackCountLabels.size() <= rowIndex) {
|
||||||
|
|
Loading…
Reference in a new issue