use of mage.view.CardView in project mage by magefree.
the class UpdateDeckTask method moveSelectorCardToDeck.
private void moveSelectorCardToDeck(Event event) {
SimpleCardView cardView = (SimpleCardView) event.getSource();
Card card = null;
boolean gameMode = mode != DeckEditorMode.FREE_BUILDING;
if (gameMode) {
// game: use existing real cards
for (Card sideCard : deck.getSideboard()) {
if (sideCard.getId().equals(cardView.getId())) {
card = sideCard;
break;
}
}
} else {
// editor: create mock card
CardInfo cardInfo = CardRepository.instance.findCard(cardView.getExpansionSetCode(), cardView.getCardNumber());
card = cardInfo != null ? cardInfo.getMockCard() : null;
}
if (card != null) {
deck.getCards().add(card);
if (gameMode) {
// game: move card from another board
deck.getSideboard().remove(card);
cardSelector.removeCard(card.getId());
cardSelector.setCardCount(deck.getSideboard().size());
cardSelector.refresh();
}
// card hint update
if (cardInfoPane instanceof CardInfoPane) {
((CardInfoPane) cardInfoPane).setCard(new CardView(card), null);
}
hidePopup();
}
}
use of mage.view.CardView in project mage by magefree.
the class DraftGrid method loadBooster.
public void loadBooster(CardsView booster, BigCard bigCard) {
if (booster != null && booster.isEmpty()) {
emptyGrid = true;
} else {
if (!emptyGrid) {
AudioManager.playOnDraftSelect();
}
emptyGrid = false;
}
this.bigCard = bigCard;
this.removeAll();
int maxRows = 4;
int numColumns = 5;
int curColumn = 0;
int curRow = 0;
int offsetX = 5;
int offsetY = 3;
CardDimensions cardDimension = null;
int maxCards;
double scale;
for (int i = 1; i < maxRows; i++) {
scale = (double) (this.getHeight() / i) / Constants.FRAME_MAX_HEIGHT;
cardDimension = new CardDimensions(scale);
maxCards = this.getWidth() / (cardDimension.getFrameWidth() + offsetX);
if ((maxCards * i) >= booster.size()) {
numColumns = booster.size() / i;
if (booster.size() % i > 0) {
numColumns++;
}
break;
}
}
if (cardDimension != null) {
Rectangle rectangle = new Rectangle(cardDimension.getFrameWidth(), cardDimension.getFrameHeight());
Dimension dimension = new Dimension(cardDimension.getFrameWidth(), cardDimension.getFrameHeight());
List<CardView> sortedCards = new ArrayList<>(booster.values());
sortedCards.sort(new CardViewRarityComparator());
for (CardView card : sortedCards) {
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, new CardIconRenderSettings(), dimension, null, true, true, PreferencesDialog.getRenderMode(), true);
cardImg.setCardContainerRef(this);
cardImg.update(card);
this.add(cardImg);
rectangle.setLocation(curColumn * (cardDimension.getFrameWidth() + offsetX) + offsetX, curRow * (rectangle.height + offsetY) + offsetY);
cardImg.setCardBounds(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
curColumn++;
if (curColumn == numColumns) {
curColumn = 0;
curRow++;
}
}
repaint();
} else {
logger.warn("Draft Grid - no possible fit of cards");
}
}
use of mage.view.CardView in project mage by magefree.
the class SelectionBox method removeSelection.
public void removeSelection() {
for (List<List<CardView>> gridRow : cardGrid) {
for (List<CardView> stack : gridRow) {
for (int i = 0; i < stack.size(); ++i) {
CardView card = stack.get(i);
if (card.isSelected()) {
eventSource.fireEvent(card, ClientEventType.DECK_REMOVE_SPECIFIC_CARD);
stack.set(i, null);
removeCardView(card);
}
}
}
}
trimGrid();
layoutGrid();
repaintGrid();
}
use of mage.view.CardView in project mage by magefree.
the class SelectionBox method analyseDeck.
public void analyseDeck() {
Map<String, Integer> qtys = new HashMap<>();
Map<String, Integer> pips = new HashMap<>();
Map<String, Integer> pips_at_cmcs = new HashMap<>();
Map<String, Integer> sourcePips = new HashMap<>();
Map<String, Integer> manaCounts = new HashMap<>();
pips.put("#w}", 0);
pips.put("#u}", 0);
pips.put("#b}", 0);
pips.put("#r}", 0);
pips.put("#g}", 0);
pips.put("#c}", 0);
qtys.put("plains", 0);
qtys.put("island", 0);
qtys.put("swamp", 0);
qtys.put("mountain", 0);
qtys.put("forest", 0);
qtys.put("basic", 0);
qtys.put("wastes", 0);
manaCounts = new HashMap<>();
for (List<List<CardView>> gridRow : cardGrid) {
for (List<CardView> stack : gridRow) {
for (CardView card : stack) {
// Type line
String t = card.getCardTypes().stream().map(CardType::toString).collect(Collectors.joining(" "));
t += card.getSuperTypes().stream().map(st -> st.toString().toLowerCase(Locale.ENGLISH)).collect(Collectors.joining(" "));
t += card.getSubTypes().stream().map(st -> st.toString().toLowerCase(Locale.ENGLISH)).collect(Collectors.joining(" "));
for (String qty : qtys.keySet()) {
int value = qtys.get(qty);
if (t.toLowerCase(Locale.ENGLISH).contains(qty)) {
qtys.put(qty, ++value);
}
// Rules
for (String str : card.getRules()) {
if (str.toLowerCase(Locale.ENGLISH).contains(qty)) {
qtys.put(qty, ++value);
}
}
}
// Wastes (special case)
if (card.getName().equals("Wastes")) {
int value = qtys.get("wastes");
qtys.put("wastes", ++value);
}
// Mana Cost
String mc = card.getManaCostStr();
mc = mc.replaceAll("\\{([WUBRG]).([WUBRG])\\}", "{$1}{$2}");
mc = mc.replaceAll("\\{", "#");
mc = mc.replaceAll("#2\\/", "#");
mc = mc.replaceAll("p}", "}");
mc = mc.toLowerCase(Locale.ENGLISH);
int cmc = card.getManaValue();
// Do colorless mana pips
Pattern regex = Pattern.compile("#([0-9]+)}");
Matcher regexMatcher = regex.matcher(mc);
while (regexMatcher.find()) {
String val = regexMatcher.group(1);
int colorless_val = Integer.parseInt(val);
int total_c_pip = 0;
if (pips.get("#c}") != null) {
total_c_pip = pips.get("#c}");
}
pips.put("#c}", colorless_val + total_c_pip);
int cmc_pip_value = 0;
if (pips_at_cmcs.get(cmc + "##c}") != null) {
cmc_pip_value = pips_at_cmcs.get(cmc + "##c}");
}
pips_at_cmcs.put(cmc + "##c}", colorless_val + cmc_pip_value);
}
for (String pip : pips.keySet()) {
int value = pips.get(pip);
while (mc.toLowerCase(Locale.ENGLISH).contains(pip)) {
pips.put(pip, ++value);
int pip_value = 0;
if (pips_at_cmcs.get(cmc + "#" + pip) != null) {
pip_value = pips_at_cmcs.get(cmc + "#" + pip);
}
pips_at_cmcs.put(cmc + "#" + pip, ++pip_value);
mc = mc.replaceFirst(pip, "");
}
}
// Adding mana
for (String str : card.getRules()) {
Matcher m = pattern.matcher(str);
// ".*Add(.*)(\\{[WUBRGXC]\\})(.*)"
while (m.find()) {
str = "Add" + m.group(1);
int num = 1;
if (manaCounts.get(m.group(2)) != null) {
num = manaCounts.get(m.group(2));
num++;
}
manaCounts.put(m.group(2), num);
m = pattern.matcher(str);
}
}
}
}
}
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
JPanel panel2 = new JPanel();
panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS));
ManaPieChart chart = new ManaPieChart(pips.get("#w}"), pips.get("#u}"), pips.get("#b}"), pips.get("#r}"), pips.get("#g}"), pips.get("#c}"));
chart.setMinimumSize(new Dimension(200, 200));
panel2.add(new JLabel("Casting Costs found:"));
panel2.add(chart);
JPanel panel3 = new JPanel();
panel3.setLayout(new BoxLayout(panel3, BoxLayout.Y_AXIS));
ManaPieChart chart2 = new ManaPieChart(qtys.get("plains"), qtys.get("island"), qtys.get("swamp"), qtys.get("mountain"), qtys.get("forest"), qtys.get("wastes"));
chart2.setMinimumSize(new Dimension(200, 200));
panel3.add(new JLabel("Basic Land types found:"));
panel3.add(chart2);
JPanel panel4 = new JPanel();
panel4.setLayout(new BoxLayout(panel4, BoxLayout.Y_AXIS));
ManaPieChart chart3 = new ManaPieChart(manaCounts.get("{W}"), manaCounts.get("{U}"), manaCounts.get("{B}"), manaCounts.get("{R}"), manaCounts.get("{G}"), manaCounts.get("{C}"));
chart3.setMinimumSize(new Dimension(200, 200));
panel4.add(new JLabel("Mana sources found:"));
panel4.add(chart3);
JPanel panel5 = new JPanel();
panel5.setLayout(new BoxLayout(panel5, BoxLayout.Y_AXIS));
ManaBarChart chart4 = new ManaBarChart(pips_at_cmcs);
chart4.setMinimumSize(new Dimension(200, 200));
panel5.add(new JLabel("Mana distribution:"));
panel5.add(chart4);
panel.add(panel2);
panel.add(panel3);
panel.add(panel4);
panel.add(panel5);
JFrame frame = new JFrame("JOptionPane showMessageDialog component example");
JOptionPane.showMessageDialog(frame, panel, "This is the distribution of colors found", JOptionPane.INFORMATION_MESSAGE);
}
use of mage.view.CardView in project mage by magefree.
the class SelectionBox method setCards.
// Update the contents of the card grid
public void setCards(CardsView cardsView, DeckCardLayout layout, BigCard bigCard) {
if (bigCard != null) {
lastBigCard = bigCard;
}
// Remove all of the cards not in the cardsView
// Until contested
boolean didModify = false;
for (int i = 0; i < cardGrid.size(); ++i) {
List<List<CardView>> gridRow = cardGrid.get(i);
for (int j = 0; j < gridRow.size(); ++j) {
List<CardView> stack = gridRow.get(j);
for (int k = 0; k < stack.size(); ++k) {
CardView card = stack.get(k);
if (!cardsView.containsKey(card.getId())) {
// Remove it
removeCardView(card);
stack.remove(k--);
// Mark
didModify = true;
}
}
}
}
// clear grid from empty rows
if (didModify) {
trimGrid();
}
if (layout == null) {
// No layout -> add any new card views one at a time as par the current sort
for (CardView newCard : cardsView.values()) {
if (!cardViews.containsKey(newCard.getId())) {
// Is a new card
addCardView(newCard, false);
// Put it into the appropirate place in the grid given the current sort
sortIntoGrid(newCard);
// Mark
didModify = true;
}
}
} else {
// Layout given -> Build card grid using layout, and set sort / separate
// Always modify when given a layout
didModify = true;
// Load in settings
loadSettings(Settings.parse(layout.getSettings()));
// Traverse the cards once and track them so we can pick ones to insert into the grid
Map<String, Map<String, List<CardView>>> trackedCards = new HashMap<>();
for (CardView newCard : cardsView.values()) {
if (!cardViews.containsKey(newCard.getId())) {
// Add the new card
addCardView(newCard, false);
// Add the new card to tracking
Map<String, List<CardView>> forSetCode;
if (trackedCards.containsKey(newCard.getExpansionSetCode())) {
forSetCode = trackedCards.get(newCard.getExpansionSetCode());
} else {
forSetCode = new HashMap<>();
trackedCards.put(newCard.getExpansionSetCode(), forSetCode);
}
List<CardView> list;
if (forSetCode.containsKey(newCard.getCardNumber())) {
list = forSetCode.get(newCard.getCardNumber());
} else {
list = new ArrayList<>();
forSetCode.put(newCard.getCardNumber(), list);
}
list.add(newCard);
}
}
// Now go through the layout and use it to build the cardGrid
cardGrid = new ArrayList<>();
maxStackSize = new ArrayList<>();
for (List<List<DeckCardInfo>> row : layout.getCards()) {
List<List<CardView>> gridRow = new ArrayList<>();
int thisMaxStackSize = 0;
cardGrid.add(gridRow);
for (List<DeckCardInfo> stack : row) {
List<CardView> gridStack = new ArrayList<>();
gridRow.add(gridStack);
for (DeckCardInfo info : stack) {
if (trackedCards.containsKey(info.getSetCode()) && trackedCards.get(info.getSetCode()).containsKey(info.getCardNum())) {
List<CardView> candidates = trackedCards.get(info.getSetCode()).get(info.getCardNum());
if (!candidates.isEmpty()) {
gridStack.add(candidates.remove(0));
thisMaxStackSize = Math.max(thisMaxStackSize, gridStack.size());
}
}
}
}
maxStackSize.add(thisMaxStackSize);
}
// the file in an invalid way, sort them into the grid so that they aren't just left hanging.
for (Map<String, List<CardView>> tracked : trackedCards.values()) {
for (List<CardView> orphans : tracked.values()) {
for (CardView orphan : orphans) {
logger.info("Orphan when setting with layout: ");
sortIntoGrid(orphan);
}
}
}
}
if (didModify) {
// clear grid from empty rows
trimGrid();
// Update layout
layoutGrid();
repaintGrid();
}
}
Aggregations