diff --git a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java index 84123e4d0b..709afd22be 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java +++ b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java @@ -273,8 +273,8 @@ public class MageActionCallback implements ActionCallback { } ); - } catch (Exception e) { - e.printStackTrace(); + } catch (InterruptedException e) { + logger.warn(e.getMessage()); } } }); diff --git a/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java b/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java index 996df1d2d3..6c065431cf 100644 --- a/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java +++ b/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java @@ -1,21 +1,27 @@ package mage.client.util.gui; import java.awt.*; +import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.SwingConstants; import mage.constants.CardType; +import mage.constants.MageObjectType; import mage.utils.CardUtil; import mage.view.CardView; +import mage.view.CounterView; +import mage.view.PermanentView; import org.jdesktop.swingx.JXPanel; +import org.mage.card.arcane.ManaSymbols; +import org.mage.card.arcane.UI; public class GuiDisplayUtil { private static final Font cardNameFont = new Font("Calibri", Font.BOLD, 15); - private static Insets DEFAULT_INSETS = new Insets(0, 0, 70, 25); - private static Insets COMPONENT_INSETS = new Insets(0, 0, 40, 40); + private static final Insets DEFAULT_INSETS = new Insets(0, 0, 70, 25); + private static final Insets COMPONENT_INSETS = new Insets(0, 0, 40, 40); public static JXPanel getDescription(CardView card, int width, int height) { JXPanel descriptionPanel = new JXPanel(); @@ -32,56 +38,14 @@ public class GuiDisplayUtil { j.setBackground(Color.black); j.setLayout(null); - JLabel name = new JLabel("Wrath of God"); - name.setBounds(5, 5, width - 90, 20); - name.setForeground(Color.white); - name.setFont(cardNameFont); - //name.setBorder(BorderFactory.createLineBorder(Color.green)); - j.add(name); - - JLabel cost = new JLabel("B R G W U"); - cost.setBounds(width - 85, 5, 77, 20); - cost.setForeground(Color.white); - cost.setFont(cardNameFont); - //cost.setBorder(BorderFactory.createLineBorder(Color.green)); - cost.setHorizontalAlignment(SwingConstants.RIGHT); - j.add(cost); - - JLabel type = new JLabel("Creature - Goblin Shaman"); - type.setBounds(5, 70, width - 8, 20); - type.setForeground(Color.white); - type.setFont(cardNameFont); - //type.setBorder(BorderFactory.createLineBorder(Color.green)); - j.add(type); - JLabel cardText = new JLabel(); - cardText.setBounds(5, 100, width - 8, 260); + cardText.setBounds(5, 5, width - 10, height - 10); cardText.setForeground(Color.white); cardText.setFont(cardNameFont); cardText.setVerticalAlignment(SwingConstants.TOP); - //cardText.setBorder(new EtchedBorder()); j.add(cardText); - - name.setText(card.getName()); - cost.setText(card.getManaCost().toString()); - String typeText = ""; - String delimiter = card.getCardTypes().size() > 1 ? " - " : ""; - for (CardType t : card.getCardTypes()) { - typeText += t; - typeText += delimiter; - delimiter = " "; // next delimiters are just spaces - } - type.setText(typeText); - cardText.setText(""+card.getRules()+""); - - if (CardUtil.isCreature(card)) { - JLabel pt = new JLabel(card.getPower() + "/" + card.getToughness()); - pt.setBounds(width - 50, height - 30, 40, 20); - pt.setForeground(Color.white); - pt.setFont(cardNameFont); - pt.setHorizontalAlignment(JLabel.RIGHT); - j.add(pt); - } + + cardText.setText(getRulefromCardView(card).toString()); descriptionPanel.add(j); @@ -89,13 +53,13 @@ public class GuiDisplayUtil { } public static String cleanString(String in) { - StringBuffer out = new StringBuffer(); + StringBuilder out = new StringBuilder(); char c; for (int i = 0; i < in.length(); i++) { c = in.charAt(i); - if (c == ' ' || c == '-') + if (c == ' ' || c == '-') { out.append('_'); - else if (Character.isLetterOrDigit(c)) { + } else if (Character.isLetterOrDigit(c)) { out.append(c); } } @@ -140,4 +104,194 @@ public class GuiDisplayUtil { return l; } + + public static StringBuilder getRulefromCardView(CardView card) { + String manaCost = ""; + for (String m : card.getManaCost()) { + manaCost += m; + } + String castingCost = UI.getDisplayManaCost(manaCost); + castingCost = ManaSymbols.replaceSymbolsWithHTML(castingCost, ManaSymbols.Type.CARD); + + int symbolCount = 0; + int offset = 0; + while ((offset = castingCost.indexOf(" rulings = new ArrayList<>(card.getRules()); + + if (card.getMageObjectType().equals(MageObjectType.PERMANENT)) { + if (card.getPairedCard() != null) { + rulings.add("Paired with another creature"); + } + } + if (card.getMageObjectType().canHaveCounters()) { + ArrayList counters = new ArrayList<>(); + if (card instanceof PermanentView) { + if (((PermanentView) card).getCounters() != null) { + counters = new ArrayList<>(((PermanentView) card).getCounters()); + } + } else { + if (card.getCounters() != null) { + counters = new ArrayList<>(card.getCounters()); + } + } + if (!counters.isEmpty()) { + StringBuilder sb = new StringBuilder(); + int index = 0; + for (CounterView counter : counters) { + if (counter.getCount() > 0) { + if (index == 0) { + sb.append("Counters: "); + } else { + sb.append(", "); + } + sb.append(counter.getCount()).append(" x ").append(counter.getName()).append(""); + index++; + } + } + rulings.add(sb.toString()); + } + } + if (card.getMageObjectType().isPermanent() && card instanceof PermanentView) { + int damage = ((PermanentView)card).getDamage(); + if (damage > 0) { + rulings.add("Damage dealt: " + damage + ""); + } + } + + int fontSize = 11; + + String fontFamily = "tahoma"; + /*if (prefs.fontFamily == CardFontFamily.arial) + fontFamily = "arial"; + else if (prefs.fontFamily == CardFontFamily.verdana) { + fontFamily = "verdana"; + }*/ + + final StringBuilder buffer = new StringBuilder(512); + buffer.append(""); + buffer.append(""); + buffer.append("
"); + buffer.append(card.getDisplayName()); + buffer.append(""); + if (!card.isSplitCard()) { + buffer.append(castingCost); + } + buffer.append("
"); + buffer.append("
"); + buffer.append(getTypes(card)); + buffer.append(""); + switch (card.getRarity()) { + case RARE: + buffer.append(""); + break; + case UNCOMMON: + buffer.append(""); + break; + case COMMON: + buffer.append(""); + break; + case MYTHIC: + buffer.append(""); + break; + } + String rarity = card.getRarity().getCode(); + if (card.getExpansionSetCode() != null) { + buffer.append(ManaSymbols.replaceSetCodeWithHTML(card.getExpansionSetCode().toUpperCase(), rarity)); + } + buffer.append("
"); + + String pt = ""; + if (CardUtil.isCreature(card)) { + pt = card.getPower() + "/" + card.getToughness(); + } else if (CardUtil.isPlaneswalker(card)) { + pt = card.getLoyalty().toString(); + } + + buffer.append(""); + buffer.append(""); + buffer.append("
"); + buffer.append(pt).append(""); + if (!card.isControlledByOwner()) { + buffer.append("[only controlled] "); + } + buffer.append(card.getMageObjectType().toString()).append("
"); + + StringBuilder rule = new StringBuilder("
"); + if (card.isSplitCard()) { + rule.append(""); + rule.append("
"); + rule.append(card.getLeftSplitName()); + rule.append(""); + rule.append(card.getLeftSplitCosts().getText()); + rule.append("
"); + for (String ruling : card.getLeftSplitRules()) { + if (ruling != null && !ruling.replace(".", "").trim().isEmpty()) { + rule.append("

").append(ruling).append("

"); + } + } + rule.append(""); + rule.append("
"); + rule.append(card.getRightSplitName()); + rule.append(""); + rule.append(card.getRightSplitCosts().getText()); + rule.append("
"); + for (String ruling : card.getRightSplitRules()) { + if (ruling != null && !ruling.replace(".", "").trim().isEmpty()) { + rule.append("

").append(ruling).append("

"); + } + } + } + if (rulings.size() > 0) { + for (String ruling : rulings) { + if (ruling != null && !ruling.replace(".", "").trim().isEmpty()) { + rule.append("

").append(ruling).append("

"); + } + } + } + + String legal = rule.toString(); + if (legal.length() > 0) { +// this 2 replaces were only done with the empty string, is it any longer needed? (LevelX2) +// legal = legal.replaceAll("#([^#]+)#", "$1"); +// legal = legal.replaceAll("\\s*//\\s*", "
"); +// legal = legal.replace("\r\n", "
"); + legal = legal.replaceAll("\\{this\\}", card.getName()); + legal = legal.replaceAll("\\{source\\}", card.getName()); + buffer.append(ManaSymbols.replaceSymbolsWithHTML(legal, ManaSymbols.Type.CARD)); + } + + buffer.append("
"); + return buffer; + } + + private static String getTypes(CardView card) { + String types = ""; + for (String superType : card.getSuperTypes()) { + types += superType + " "; + } + for (CardType cardType : card.getCardTypes()) { + types += cardType.toString() + " "; + } + if (card.getSubTypes().size() > 0) { + types += "- "; + } + for (String subType : card.getSubTypes()) { + types += subType + " "; + } + return types.trim(); + } } diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/info/CardInfoPaneImpl.java b/Mage.Client/src/main/java/org/mage/plugins/card/info/CardInfoPaneImpl.java index 18b1b87545..a7c587853d 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/info/CardInfoPaneImpl.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/info/CardInfoPaneImpl.java @@ -1,21 +1,15 @@ package org.mage.plugins.card.info; +import java.awt.Color; +import java.awt.Component; +import javax.swing.JEditorPane; +import javax.swing.SwingUtilities; +import mage.client.util.gui.GuiDisplayUtil; import mage.components.CardInfoPane; -import mage.constants.CardType; -import mage.utils.CardUtil; import mage.utils.ThreadUtils; import mage.view.CardView; -import mage.view.CounterView; -import mage.view.PermanentView; -import org.mage.card.arcane.ManaSymbols; import org.mage.card.arcane.UI; -import javax.swing.*; -import java.awt.*; -import java.util.ArrayList; -import java.util.List; -import mage.constants.MageObjectType; - /** * Card info pane for displaying card rules. * Supports drawing mana symbols. @@ -46,180 +40,15 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane { try { if (!card.equals(currentCard)) { return; - } - - String manaCost = ""; - for (String m : card.getManaCost()) { - manaCost += m; - } - String castingCost = UI.getDisplayManaCost(manaCost); - castingCost = ManaSymbols.replaceSymbolsWithHTML(castingCost, ManaSymbols.Type.CARD); - - int symbolCount = 0; - int offset = 0; - while ((offset = castingCost.indexOf(" rules = card.getRules(); - List rulings = new ArrayList(rules); - - if (card.getMageObjectType().equals(MageObjectType.PERMANENT)) { - if (card.getPairedCard() != null) { - rulings.add("Paired with another creature"); - } - } - if (card.getMageObjectType().canHaveCounters()) { - List counters; - if (card instanceof PermanentView) { - counters = ((PermanentView) card).getCounters(); - } else { - counters = ((CardView) card).getCounters(); - } - int count = counters != null ? counters.size() : 0; - if (count > 0) { - StringBuilder sb = new StringBuilder(); - int index = 0; - for (CounterView counter : counters) { - if (counter.getCount() > 0) { - if (index == 0) { - sb.append("Counters: "); - } else { - sb.append(", "); - } - sb.append(counter.getCount()).append(" x ").append(counter.getName()).append(""); - index++; - } - } - rulings.add(sb.toString()); - } - } - if (card.getMageObjectType().isPermanent() && card instanceof PermanentView) { - int damage = ((PermanentView)card).getDamage(); - if (damage > 0) { - rulings.add("Damage dealt: " + damage + ""); - } - } - - int fontSize = 11; - - String fontFamily = "tahoma"; - /*if (prefs.fontFamily == CardFontFamily.arial) - fontFamily = "arial"; - else if (prefs.fontFamily == CardFontFamily.verdana) { - fontFamily = "verdana"; - }*/ - - final StringBuilder buffer = new StringBuilder(512); - buffer.append(""); - buffer.append(""); - buffer.append("
"); - buffer.append(card.getDisplayName()); - buffer.append(""); - if (!card.isSplitCard()) { - buffer.append(castingCost); - } - buffer.append("
"); - buffer.append("
"); - buffer.append(getTypes(card)); - buffer.append(""); - switch (card.getRarity()) { - case RARE: - buffer.append(""); - break; - case UNCOMMON: - buffer.append(""); - break; - case COMMON: - buffer.append(""); - break; - case MYTHIC: - buffer.append(""); - break; - } - String rarity = card.getRarity().getCode(); - if (card.getExpansionSetCode() != null) { - buffer.append(ManaSymbols.replaceSetCodeWithHTML(card.getExpansionSetCode().toUpperCase(), rarity)); - } - buffer.append("
"); - - String pt = ""; - if (CardUtil.isCreature(card)) { - pt = card.getPower() + "/" + card.getToughness(); - } else if (CardUtil.isPlaneswalker(card)) { - pt = card.getLoyalty().toString(); - } - - buffer.append(""); - buffer.append(""); - buffer.append("
"); - buffer.append(pt).append(""); - if (!card.isControlledByOwner()) { - buffer.append("[only controlled] "); - } - buffer.append(card.getMageObjectType().toString()).append("
"); - - StringBuilder rule = new StringBuilder("
"); - if (card.isSplitCard()) { - rule.append(""); - rule.append("
"); - rule.append(card.getLeftSplitName()); - rule.append(""); - rule.append(card.getLeftSplitCosts().getText()); - rule.append("
"); - for (String ruling : card.getLeftSplitRules()) { - if (ruling != null && !ruling.replace(".", "").trim().isEmpty()) { - rule.append("

").append(ruling).append("

"); - } - } - rule.append(""); - rule.append("
"); - rule.append(card.getRightSplitName()); - rule.append(""); - rule.append(card.getRightSplitCosts().getText()); - rule.append("
"); - for (String ruling : card.getRightSplitRules()) { - if (ruling != null && !ruling.replace(".", "").trim().isEmpty()) { - rule.append("

").append(ruling).append("

"); - } - } - } - if (rulings.size() > 0) { - for (String ruling : rulings) { - if (ruling != null && !ruling.replace(".", "").trim().isEmpty()) { - rule.append("

").append(ruling).append("

"); - } - } - } - - String legal = rule.toString(); - if (legal.length() > 0) { -// this 2 replaces were only done with the empty string, is it any longer needed? (LevelX2) -// legal = legal.replaceAll("#([^#]+)#", "$1"); -// legal = legal.replaceAll("\\s*//\\s*", "
"); -// legal = legal.replace("\r\n", "
"); - legal = legal.replaceAll("\\{this\\}", card.getName()); - legal = legal.replaceAll("\\{source\\}", card.getName()); - buffer.append(ManaSymbols.replaceSymbolsWithHTML(legal, ManaSymbols.Type.CARD)); - } - - buffer.append("
"); - + } + SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { if (!card.equals(currentCard)) { return; } + StringBuilder buffer = GuiDisplayUtil.getRulefromCardView(card); resizeTooltipIfNeeded(buffer, container); setText(buffer.toString()); setCaretPosition(0); @@ -260,23 +89,7 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane { } } - private String getTypes(CardView card) { - String types = ""; - for (String superType : card.getSuperTypes()) { - types += superType + " "; - } - for (CardType cardType : card.getCardTypes()) { - types += cardType.toString() + " "; - } - if (card.getSubTypes().size() > 0) { - types += "- "; - } - for (String subType : card.getSubTypes()) { - types += subType + " "; - } - return types.trim(); - } - + @Override public boolean isCurrentCard(CardView card) { return currentCard != null && card.equals(currentCard); }