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 1469aff0e4..eea8d87ac3 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 @@ -14,9 +14,8 @@ import org.mage.card.arcane.UI; import javax.swing.*; import java.awt.*; -import java.util.ArrayList; import java.util.List; -import java.util.Locale; +import java.util.*; import static mage.client.dialog.PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE; @@ -344,6 +343,9 @@ public final class GuiDisplayUtil { } buffer.append(""); + // split card rules shows up by parts, so no needs to duplicate it later (only dynamic abilities must be shown) + Set duplicatedRules = new HashSet<>(); + StringBuilder rule = new StringBuilder("
"); if (card.isSplitCard()) { rule.append(""); @@ -356,7 +358,9 @@ public final class GuiDisplayUtil { rule.append("
"); for (String ruling : card.getLeftSplitRules()) { if (ruling != null && !ruling.replace(".", "").trim().isEmpty()) { - rule.append("

").append(ruling).append("

"); + // split names must be replaced + duplicatedRules.add(ruling); + rule.append("

").append(replaceNamesInRule(ruling, card.getLeftSplitName())).append("

"); } } rule.append(""); @@ -369,13 +373,18 @@ public final class GuiDisplayUtil { rule.append("
"); for (String ruling : card.getRightSplitRules()) { if (ruling != null && !ruling.replace(".", "").trim().isEmpty()) { - rule.append("

").append(ruling).append("

"); + // split names must be replaced + duplicatedRules.add(ruling); + rule.append("

").append(replaceNamesInRule(ruling, card.getRightSplitName())).append("

"); } } } if (!textLines.getLines().isEmpty()) { for (String textLine : textLines.getLines()) { if (textLine != null && !textLine.replace(".", "").trim().isEmpty()) { + if (duplicatedRules.contains(textLine)) { + continue; + } rule.append("

").append(textLine).append("

"); } } @@ -383,8 +392,7 @@ public final class GuiDisplayUtil { String legal = rule.toString(); if (!legal.isEmpty()) { - legal = legal.replaceAll("\\{this\\}", card.getName().isEmpty() ? "this" : card.getName()); - legal = legal.replaceAll("\\{source\\}", card.getName().isEmpty() ? "this" : card.getName()); + legal = replaceNamesInRule(legal, card.getDisplayName()); // must show real display name (e.g. split part, not original card) buffer.append(ManaSymbols.replaceSymbolsWithHTML(legal, ManaSymbols.Type.TOOLTIP)); } @@ -397,6 +405,12 @@ public final class GuiDisplayUtil { return buffer; } + private static String replaceNamesInRule(String rule, String cardName) { + String res = rule.replaceAll("\\{this\\}", cardName.isEmpty() ? "this" : cardName); + res = res.replaceAll("\\{source\\}", cardName.isEmpty() ? "this" : cardName); + return res; + } + private static String getResourcePath(String image) { return GuiDisplayUtil.class.getClassLoader().getResource(image).toString(); } diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/CardRenderer.java b/Mage.Client/src/main/java/org/mage/card/arcane/CardRenderer.java index 048d4d42db..bdb099bac9 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/CardRenderer.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/CardRenderer.java @@ -140,13 +140,30 @@ public abstract class CardRenderer { break; } + // workaround to use real split card names + String realCardName = cardView.getDisplayName(); + if (cardView.isSplitCard()) { + for (String partRule : cardView.getLeftSplitRules()) { + if (partRule.equals(rule)) { + realCardName = cardView.getLeftSplitName(); + break; + } + } + for (String partRule : cardView.getRightSplitRules()) { + if (partRule.equals(rule)) { + realCardName = cardView.getRightSplitName(); + break; + } + } + } + // Kill reminder text if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_RENDERING_REMINDER_TEXT, "false").equals("false")) { rule = CardRendererUtils.killReminderText(rule).trim(); } if (!rule.isEmpty()) { - TextboxRule tbRule = TextboxRuleParser.parse(cardView, rule); + TextboxRule tbRule = TextboxRuleParser.parse(cardView, rule, realCardName); if (tbRule.type == TextboxRuleType.SIMPLE_KEYWORD) { keywords.add(tbRule); } else if (tbRule.text.isEmpty()) { diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/TextboxRuleParser.java b/Mage.Client/src/main/java/org/mage/card/arcane/TextboxRuleParser.java index a9ba60ed4f..27fc01cd62 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/TextboxRuleParser.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/TextboxRuleParser.java @@ -30,7 +30,7 @@ public final class TextboxRuleParser { // if the ability is a loyalty ability, and returning an TextboxRule // representing that information, which can be used to render the rule in // the textbox of a card. - public static TextboxRule parse(CardView source, String rule) { + public static TextboxRule parse(CardView source, String rule, String cardNameToUse) { // List of regions to apply List regions = new ArrayList<>(); @@ -104,10 +104,9 @@ public final class TextboxRuleParser { String contents = rule.substring(index + 1, closeIndex); if (contents.equals("this") || contents.equals("source")) { // Replace {this} with the card's name - String cardName = source.getName(); - build.append(cardName); + build.append(cardNameToUse); index += contents.length() + 2; - outputIndex += cardName.length(); + outputIndex += cardNameToUse.length(); } else { Image symbol = ManaSymbols.getSizedManaSymbol(contents.replace("/", ""), 10); if (symbol != null) {