use of mage.view.CardView in project mage by magefree.
the class SelectionBox method selectByName.
public void selectByName(List<String> cardNames) {
for (List<List<CardView>> gridRow : cardGrid) {
for (List<CardView> stack : gridRow) {
for (CardView card : stack) {
if (cardNames.contains(card.getName())) {
card.setSelected(true);
cardViews.get(card.getId()).update(card);
}
}
}
}
}
use of mage.view.CardView in project mage by magefree.
the class SelectionBox method updateSelectionDrag.
private void updateSelectionDrag(int x, int y) {
// Coords
int cardWidth = getCardWidth();
int cardHeight = getCardHeight();
int cardTopHeight = CardRenderer.getCardTopHeight(cardWidth);
int x1 = Math.min(x, selectionDragStartX);
int x2 = Math.max(x, selectionDragStartX);
int y1 = Math.min(y, selectionDragStartY);
int y2 = Math.max(y, selectionDragStartY);
// Update selection panel size
selectionPanel.setLocation(x1, y1);
selectionPanel.setSize(x2 - x1, y2 - y1);
// First and last cols
int col1 = x1 / (cardWidth + GRID_PADDING);
int col2 = x2 / (cardWidth + GRID_PADDING);
int offsetIntoCol2 = x2 % (cardWidth + GRID_PADDING);
if (offsetIntoCol2 < GRID_PADDING) {
--col2;
}
int curY = COUNT_LABEL_HEIGHT;
for (int rowIndex = 0; rowIndex < cardGrid.size(); ++rowIndex) {
int stackStartIndex;
if (y1 < curY) {
stackStartIndex = 0;
} else {
stackStartIndex = (y1 - curY) / cardTopHeight;
}
int stackEndIndex;
if (y2 < curY) {
stackEndIndex = -1;
} else {
stackEndIndex = (y2 - curY) / cardTopHeight;
}
List<List<CardView>> gridRow = cardGrid.get(rowIndex);
for (int col = 0; col < gridRow.size(); ++col) {
List<CardView> stack = gridRow.get(col);
int stackBottomBegin = curY + cardTopHeight * (stack.size());
int stackBottomEnd = curY + cardTopHeight * (stack.size() - 1) + cardHeight;
for (int i = 0; i < stack.size(); ++i) {
CardView card = stack.get(i);
MageCard view = cardViews.get(card.getId());
boolean inBoundsX = (col >= col1 && col <= col2);
boolean inBoundsY = (i >= stackStartIndex && i <= stackEndIndex);
boolean lastCard = (i == stack.size() - 1);
boolean inSeletionDrag = inBoundsX && (inBoundsY || (lastCard && (y2 >= stackBottomBegin && y1 <= stackBottomEnd)));
if (inSeletionDrag || selectionDragStartCards != null && selectionDragStartCards.contains(card)) {
if (!card.isSelected()) {
card.setSelected(true);
view.update(card);
}
} else if (card.isSelected()) {
card.setSelected(false);
view.update(card);
}
}
}
curY += cardTopHeight * (maxStackSize.get(rowIndex) - 1) + cardHeight + COUNT_LABEL_HEIGHT;
}
}
use of mage.view.CardView in project mage by magefree.
the class SelectionBox method selectCard.
private void selectCard(CardView targetCard) {
// Set the selected card to the target card
for (CardView card : allCards) {
if (card == targetCard) {
if (!card.isSelected()) {
card.setSelected(true);
cardViews.get(card.getId()).update(card);
}
} else if (card.isSelected()) {
card.setSelected(false);
cardViews.get(card.getId()).update(card);
}
}
}
use of mage.view.CardView in project mage by magefree.
the class SelectionBox method resort.
// Resort the existing cards based on the current sort
public void resort() {
// clear grid
for (List<List<CardView>> gridRow : cardGrid) {
for (List<CardView> stack : gridRow) {
stack.clear();
}
}
trimGrid();
// sort
allCards.sort(new CardViewNameComparator());
// re-insert
for (CardView card : allCards) {
sortIntoGrid(card);
}
trimGrid();
// Deselect everything
deselectAll();
// render new grid
layoutGrid();
repaintGrid();
}
use of mage.view.CardView in project mage by magefree.
the class SelectionBox method getCardLayout.
public DeckCardLayout getCardLayout() {
// 2D Array to put entries into
List<List<List<DeckCardInfo>>> info = new ArrayList<>();
for (List<List<CardView>> gridRow : cardGrid) {
List<List<DeckCardInfo>> row = new ArrayList<>();
info.add(row);
for (List<CardView> stack : gridRow) {
row.add(stack.stream().map(card -> new DeckCardInfo(card.getName(), card.getCardNumber(), card.getExpansionSetCode())).collect(Collectors.toList()));
}
}
// Store layout and settings then return them
return new DeckCardLayout(info, saveSettings().toString());
}
Aggregations