From 4ae5ac129d771029ab1eabd750dd488183128aba Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 27 Nov 2014 15:20:45 +0100 Subject: [PATCH] Some tweaking to the size of the card popup window. --- .../mage/client/util/gui/GuiDisplayUtil.java | 71 +++++++++++-------- 1 file changed, 43 insertions(+), 28 deletions(-) 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 c3075ed050e..3c861fc89ca 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 @@ -19,6 +19,12 @@ public class GuiDisplayUtil { 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 class TextLines { + + public int basicTextLength; + public ArrayList lines; + } + public static JXPanel getDescription(CardView card, int width, int height) { JXPanel descriptionPanel = new JXPanel(); @@ -40,8 +46,9 @@ public class GuiDisplayUtil { cardText.setFont(cardNameFont); cardText.setVerticalAlignment(SwingConstants.TOP); j.add(cardText); - - cardText.setText(getRulefromCardView(card).toString()); + + TextLines textLines = GuiDisplayUtil.getTextLinesfromCardView(card); + cardText.setText(getRulefromCardView(card, textLines).toString()); descriptionPanel.add(j); @@ -100,27 +107,17 @@ public class GuiDisplayUtil { return l; } - - public static StringBuilder getRulefromCardView(CardView card) { - String manaCost = ""; - for (String m : card.getManaCost()) { - manaCost += m; + + public static TextLines getTextLinesfromCardView(CardView card) { + TextLines textLines = new TextLines(); + textLines.lines = new ArrayList<>(card.getRules()); + for (String rule: card.getRules()) { + textLines.basicTextLength +=rule.length(); } - 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"); + textLines.lines.add("Paired with another creature"); + textLines.basicTextLength += 30; } } if (card.getMageObjectType().canHaveCounters()) { @@ -128,7 +125,7 @@ public class GuiDisplayUtil { 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()); @@ -148,15 +145,33 @@ public class GuiDisplayUtil { index++; } } - rulings.add(sb.toString()); + textLines.lines.add(sb.toString()); + textLines.basicTextLength += 50; } } if (card.getMageObjectType().isPermanent() && card instanceof PermanentView) { int damage = ((PermanentView)card).getDamage(); if (damage > 0) { - rulings.add("Damage dealt: " + damage + ""); + textLines.lines.add("Damage dealt: " + damage + ""); + textLines.basicTextLength += 50; } } + return textLines; + } + + public static StringBuilder getRulefromCardView(CardView card, TextLines textLines) { + 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(""); @@ -257,10 +272,10 @@ public class GuiDisplayUtil { } } } - if (rulings.size() > 0) { - for (String ruling : rulings) { - if (ruling != null && !ruling.replace(".", "").trim().isEmpty()) { - rule.append("

").append(ruling).append("

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

").append(textLine).append("

"); } } }