mirror of
https://github.com/correl/mage.git
synced 2024-11-29 03:00:12 +00:00
* UI: split cards - fixed wrong card names in rules text and hints (#6549);
This commit is contained in:
parent
0c2e08f54e
commit
0be7d6579b
3 changed files with 41 additions and 11 deletions
|
@ -14,9 +14,8 @@ import org.mage.card.arcane.UI;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.*;
|
||||||
|
|
||||||
import static mage.client.dialog.PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE;
|
import static mage.client.dialog.PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE;
|
||||||
|
|
||||||
|
@ -344,6 +343,9 @@ public final class GuiDisplayUtil {
|
||||||
}
|
}
|
||||||
buffer.append("</td></tr></table>");
|
buffer.append("</td></tr></table>");
|
||||||
|
|
||||||
|
// split card rules shows up by parts, so no needs to duplicate it later (only dynamic abilities must be shown)
|
||||||
|
Set<String> duplicatedRules = new HashSet<>();
|
||||||
|
|
||||||
StringBuilder rule = new StringBuilder("<br/>");
|
StringBuilder rule = new StringBuilder("<br/>");
|
||||||
if (card.isSplitCard()) {
|
if (card.isSplitCard()) {
|
||||||
rule.append("<table cellspacing=0 cellpadding=0 border=0 width='100%'>");
|
rule.append("<table cellspacing=0 cellpadding=0 border=0 width='100%'>");
|
||||||
|
@ -356,7 +358,9 @@ public final class GuiDisplayUtil {
|
||||||
rule.append("</td></tr></table>");
|
rule.append("</td></tr></table>");
|
||||||
for (String ruling : card.getLeftSplitRules()) {
|
for (String ruling : card.getLeftSplitRules()) {
|
||||||
if (ruling != null && !ruling.replace(".", "").trim().isEmpty()) {
|
if (ruling != null && !ruling.replace(".", "").trim().isEmpty()) {
|
||||||
rule.append("<p style='margin: 2px'>").append(ruling).append("</p>");
|
// split names must be replaced
|
||||||
|
duplicatedRules.add(ruling);
|
||||||
|
rule.append("<p style='margin: 2px'>").append(replaceNamesInRule(ruling, card.getLeftSplitName())).append("</p>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rule.append("<table cellspacing=0 cellpadding=0 border=0 width='100%'>");
|
rule.append("<table cellspacing=0 cellpadding=0 border=0 width='100%'>");
|
||||||
|
@ -369,13 +373,18 @@ public final class GuiDisplayUtil {
|
||||||
rule.append("</td></tr></table>");
|
rule.append("</td></tr></table>");
|
||||||
for (String ruling : card.getRightSplitRules()) {
|
for (String ruling : card.getRightSplitRules()) {
|
||||||
if (ruling != null && !ruling.replace(".", "").trim().isEmpty()) {
|
if (ruling != null && !ruling.replace(".", "").trim().isEmpty()) {
|
||||||
rule.append("<p style='margin: 2px'>").append(ruling).append("</p>");
|
// split names must be replaced
|
||||||
|
duplicatedRules.add(ruling);
|
||||||
|
rule.append("<p style='margin: 2px'>").append(replaceNamesInRule(ruling, card.getRightSplitName())).append("</p>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!textLines.getLines().isEmpty()) {
|
if (!textLines.getLines().isEmpty()) {
|
||||||
for (String textLine : textLines.getLines()) {
|
for (String textLine : textLines.getLines()) {
|
||||||
if (textLine != null && !textLine.replace(".", "").trim().isEmpty()) {
|
if (textLine != null && !textLine.replace(".", "").trim().isEmpty()) {
|
||||||
|
if (duplicatedRules.contains(textLine)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
rule.append("<p style='margin: 2px'>").append(textLine).append("</p>");
|
rule.append("<p style='margin: 2px'>").append(textLine).append("</p>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -383,8 +392,7 @@ public final class GuiDisplayUtil {
|
||||||
|
|
||||||
String legal = rule.toString();
|
String legal = rule.toString();
|
||||||
if (!legal.isEmpty()) {
|
if (!legal.isEmpty()) {
|
||||||
legal = legal.replaceAll("\\{this\\}", card.getName().isEmpty() ? "this" : card.getName());
|
legal = replaceNamesInRule(legal, card.getDisplayName()); // must show real display name (e.g. split part, not original card)
|
||||||
legal = legal.replaceAll("\\{source\\}", card.getName().isEmpty() ? "this" : card.getName());
|
|
||||||
buffer.append(ManaSymbols.replaceSymbolsWithHTML(legal, ManaSymbols.Type.TOOLTIP));
|
buffer.append(ManaSymbols.replaceSymbolsWithHTML(legal, ManaSymbols.Type.TOOLTIP));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,6 +405,12 @@ public final class GuiDisplayUtil {
|
||||||
return buffer;
|
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) {
|
private static String getResourcePath(String image) {
|
||||||
return GuiDisplayUtil.class.getClassLoader().getResource(image).toString();
|
return GuiDisplayUtil.class.getClassLoader().getResource(image).toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,13 +140,30 @@ public abstract class CardRenderer {
|
||||||
break;
|
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
|
// Kill reminder text
|
||||||
if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_RENDERING_REMINDER_TEXT, "false").equals("false")) {
|
if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_RENDERING_REMINDER_TEXT, "false").equals("false")) {
|
||||||
rule = CardRendererUtils.killReminderText(rule).trim();
|
rule = CardRendererUtils.killReminderText(rule).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rule.isEmpty()) {
|
if (!rule.isEmpty()) {
|
||||||
TextboxRule tbRule = TextboxRuleParser.parse(cardView, rule);
|
TextboxRule tbRule = TextboxRuleParser.parse(cardView, rule, realCardName);
|
||||||
if (tbRule.type == TextboxRuleType.SIMPLE_KEYWORD) {
|
if (tbRule.type == TextboxRuleType.SIMPLE_KEYWORD) {
|
||||||
keywords.add(tbRule);
|
keywords.add(tbRule);
|
||||||
} else if (tbRule.text.isEmpty()) {
|
} else if (tbRule.text.isEmpty()) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ public final class TextboxRuleParser {
|
||||||
// if the ability is a loyalty ability, and returning an TextboxRule
|
// if the ability is a loyalty ability, and returning an TextboxRule
|
||||||
// representing that information, which can be used to render the rule in
|
// representing that information, which can be used to render the rule in
|
||||||
// the textbox of a card.
|
// 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 of regions to apply
|
||||||
List<TextboxRule.AttributeRegion> regions = new ArrayList<>();
|
List<TextboxRule.AttributeRegion> regions = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -104,10 +104,9 @@ public final class TextboxRuleParser {
|
||||||
String contents = rule.substring(index + 1, closeIndex);
|
String contents = rule.substring(index + 1, closeIndex);
|
||||||
if (contents.equals("this") || contents.equals("source")) {
|
if (contents.equals("this") || contents.equals("source")) {
|
||||||
// Replace {this} with the card's name
|
// Replace {this} with the card's name
|
||||||
String cardName = source.getName();
|
build.append(cardNameToUse);
|
||||||
build.append(cardName);
|
|
||||||
index += contents.length() + 2;
|
index += contents.length() + 2;
|
||||||
outputIndex += cardName.length();
|
outputIndex += cardNameToUse.length();
|
||||||
} else {
|
} else {
|
||||||
Image symbol = ManaSymbols.getSizedManaSymbol(contents.replace("/", ""), 10);
|
Image symbol = ManaSymbols.getSizedManaSymbol(contents.replace("/", ""), 10);
|
||||||
if (symbol != null) {
|
if (symbol != null) {
|
||||||
|
|
Loading…
Reference in a new issue