GUI: added mana and other symbols support in choose spell dialog (closes #12155)

This commit is contained in:
Oleg Agafonov 2024-07-27 10:17:22 +04:00
parent 521a0f6e32
commit 2bf6e3e3a2
7 changed files with 26 additions and 36 deletions

View file

@ -7,15 +7,13 @@ import mage.client.components.ColorPane;
import mage.client.dialog.MageDialog; import mage.client.dialog.MageDialog;
import mage.client.game.GamePanel; import mage.client.game.GamePanel;
import mage.client.util.ImageHelper; import mage.client.util.ImageHelper;
import mage.remote.Session; import mage.util.CardUtil;
import mage.view.AbilityPickerView; import mage.view.AbilityPickerView;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdesktop.layout.GroupLayout; import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle; import org.jdesktop.layout.LayoutStyle;
import org.jdesktop.swingx.JXPanel; import org.jdesktop.swingx.JXPanel;
import org.jsoup.Jsoup;
import org.mage.card.arcane.ManaSymbols; import org.mage.card.arcane.ManaSymbols;
import org.mage.card.arcane.UI;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -24,12 +22,14 @@ import java.util.List;
import java.util.*; import java.util.*;
/** /**
* GUI: Dialog for choosing abilities (list) * GUI: dialog for choosing abilities (list). Example: ability for activate/cast
* *
* @author nantuko, JayDi85 * @author nantuko, JayDi85
*/ */
public class AbilityPicker extends JXPanel implements MouseWheelListener { public class AbilityPicker extends JXPanel implements MouseWheelListener {
// TODO: add gui scale support (form file lost, so it's ok for scale, see PlayerPanelExt)
private static final String DEFAULT_MESSAGE = "Choose spell or ability to play (single-click)"; private static final String DEFAULT_MESSAGE = "Choose spell or ability to play (single-click)";
private static final int DIALOG_WIDTH = 440; private static final int DIALOG_WIDTH = 440;
private static final int DIALOG_HEIGHT = 260; private static final int DIALOG_HEIGHT = 260;
@ -100,7 +100,8 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
boolean wasCancelButton = false; boolean wasCancelButton = false;
for (Map.Entry<UUID, String> choice : choices.getChoices().entrySet()) { for (Map.Entry<UUID, String> choice : choices.getChoices().entrySet()) {
wasCancelButton = wasCancelButton || choice.getKey().equals(Modes.CHOOSE_OPTION_CANCEL_ID); wasCancelButton = wasCancelButton || choice.getKey().equals(Modes.CHOOSE_OPTION_CANCEL_ID);
this.choices.add(new AbilityPickerAction(choice.getKey(), choice.getValue())); String htmlText = "<html>" + ManaSymbols.replaceSymbolsWithHTML(CardUtil.getTextWithFirstCharUpperCase(choice.getValue()), ManaSymbols.Type.TABLE);
this.choices.add(new AbilityPickerAction(choice.getKey(), htmlText));
} }
if (!wasCancelButton) { if (!wasCancelButton) {
this.choices.add(new AbilityPickerAction(null, "Cancel")); this.choices.add(new AbilityPickerAction(null, "Cancel"));
@ -190,7 +191,7 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
layout.createSequentialGroup().add(title).addPreferredGap(LayoutStyle.RELATED, 5, Short.MAX_VALUE).add(1, 1, 1)).add( layout.createSequentialGroup().add(title).addPreferredGap(LayoutStyle.RELATED, 5, Short.MAX_VALUE).add(1, 1, 1)).add(
GroupLayout.LEADING, GroupLayout.LEADING,
layout.createSequentialGroup().add(layout.createParallelGroup(GroupLayout.LEADING) layout.createSequentialGroup().add(layout.createParallelGroup(GroupLayout.LEADING)
) )
.addPreferredGap(LayoutStyle.RELATED) .addPreferredGap(LayoutStyle.RELATED)
.add( .add(
layout.createParallelGroup(GroupLayout.TRAILING) layout.createParallelGroup(GroupLayout.TRAILING)
@ -199,16 +200,16 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.LEADING).add( layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.LEADING).add(
layout.createSequentialGroup().add( layout.createSequentialGroup().add(
layout.createParallelGroup(GroupLayout.LEADING).add( layout.createParallelGroup(GroupLayout.LEADING).add(
layout.createSequentialGroup().add(title, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE) layout.createSequentialGroup().add(title, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE)
.add(5, 5, 5) .add(5, 5, 5)
.add( .add(
layout.createParallelGroup(GroupLayout.BASELINE) layout.createParallelGroup(GroupLayout.BASELINE)
) )
).add(layout.createSequentialGroup().add(8, 8, 8))) ).add(layout.createSequentialGroup().add(8, 8, 8)))
.addPreferredGap(LayoutStyle.RELATED).add(layout.createParallelGroup(GroupLayout.BASELINE)).addPreferredGap(LayoutStyle.RELATED).add( .addPreferredGap(LayoutStyle.RELATED).add(layout.createParallelGroup(GroupLayout.BASELINE)).addPreferredGap(LayoutStyle.RELATED).add(
layout.createParallelGroup(GroupLayout.BASELINE)).addPreferredGap(LayoutStyle.RELATED).add(layout.createParallelGroup(GroupLayout.LEADING)).addPreferredGap( layout.createParallelGroup(GroupLayout.BASELINE)).addPreferredGap(LayoutStyle.RELATED).add(layout.createParallelGroup(GroupLayout.LEADING)).addPreferredGap(
LayoutStyle.RELATED).add(jScrollPane2, GroupLayout.PREFERRED_SIZE, 180, GroupLayout.PREFERRED_SIZE).addContainerGap(23, Short.MAX_VALUE))); LayoutStyle.RELATED).add(jScrollPane2, GroupLayout.PREFERRED_SIZE, 180, GroupLayout.PREFERRED_SIZE).addContainerGap(23, Short.MAX_VALUE)));
} }
@Override @Override
@ -355,15 +356,7 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
public AbilityPickerAction(UUID id, String choice) { public AbilityPickerAction(UUID id, String choice) {
this.id = id; this.id = id;
putValue(Action.NAME, capitalizeFirstLetter(choice)); putValue(Action.NAME, choice);
}
private String capitalizeFirstLetter(String choice) {
if (choice == null || choice.isEmpty()) {
return choice;
}
choice = Jsoup.parse(choice).text(); // decode HTML entities and strip tags
return choice.substring(0, 1).toUpperCase(Locale.ENGLISH) + choice.substring(1);
} }
@Override @Override

View file

@ -1520,8 +1520,7 @@ public class CardView extends SimpleCardView {
} }
public String getColorText() { public String getColorText() {
String colorText = getColor().getDescription(); return CardUtil.getTextWithFirstCharUpperCase(getColor().getDescription());
return colorText.substring(0, 1).toUpperCase(Locale.ENGLISH) + colorText.substring(1);
} }
public String getTypeText() { public String getTypeText() {

View file

@ -6,6 +6,7 @@ import mage.abilities.effects.Effect;
import mage.constants.Duration; import mage.constants.Duration;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.util.CardUtil;
import java.util.Locale; import java.util.Locale;
@ -53,7 +54,7 @@ public class ReflexiveTriggeredAbility extends DelayedTriggeredAbility {
if (text == null) { if (text == null) {
return super.getRule(); return super.getRule();
} }
return text.substring(0, 1).toUpperCase(Locale.ENGLISH) + text.substring(1) + '.'; return CardUtil.getTextWithFirstCharUpperCase(text) + '.';
} }
@Override @Override

View file

@ -15,6 +15,7 @@ import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent; import mage.game.events.ZoneChangeEvent;
import mage.players.Player; import mage.players.Player;
import mage.util.CardUtil;
/** /**
* @author LevelX2 * @author LevelX2
@ -47,7 +48,7 @@ public class EnterBattlefieldPayCostOrPutGraveyardEffect extends ReplacementEffe
boolean replace = true; boolean replace = true;
if (cost.canPay(source, source, player.getId(), game)) { if (cost.canPay(source, source, player.getId(), game)) {
if (player.chooseUse(outcome, if (player.chooseUse(outcome,
cost.getText().substring(0, 1).toUpperCase(Locale.ENGLISH) + cost.getText().substring(1) CardUtil.getTextWithFirstCharUpperCase(cost.getText())
+ "? (otherwise " + sourceObject.getLogName() + " is put into graveyard)", source, game)) { + "? (otherwise " + sourceObject.getLogName() + " is put into graveyard)", source, game)) {
cost.clearPaid(); cost.clearPaid();
replace = !cost.pay(source, game, source, source.getControllerId(), false, null); replace = !cost.pay(source, game, source, source.getControllerId(), false, null);

View file

@ -62,7 +62,7 @@ public class SacrificeSourceUnlessPaysEffect extends OneShotEffect {
message += "Pay " + costValueMessage; message += "Pay " + costValueMessage;
logMessage += "pay " + costValueMessage; logMessage += "pay " + costValueMessage;
} else if (costValueMessage.length() > 1) { } else if (costValueMessage.length() > 1) {
message += costValueMessage.substring(0, 1).toUpperCase() + costValueMessage.substring(1); message += CardUtil.getTextWithFirstCharUpperCase(costValueMessage);
logMessage += costValueMessage; logMessage += costValueMessage;
} }
message += '?'; message += '?';

View file

@ -65,7 +65,7 @@ public class AddCounterChoiceSourceEffect extends OneShotEffect {
counterChoice.setChoices( counterChoice.setChoices(
this.counterTypes this.counterTypes
.stream() .stream()
.map(counterType -> AddCounterChoiceSourceEffect.capitalize(counterType.getName())) .map(counterType -> CardUtil.getTextWithFirstCharUpperCase(counterType.getName()))
.collect(Collectors.toSet()) .collect(Collectors.toSet())
); );
@ -82,10 +82,6 @@ public class AddCounterChoiceSourceEffect extends OneShotEffect {
return permanent.addCounters(counter, source.getControllerId(), source, game); return permanent.addCounters(counter, source.getControllerId(), source, game);
} }
private static String capitalize(String string) {
return string != null ? string.substring(0, 1).toUpperCase(Locale.ENGLISH) + string.substring(1) : null;
}
@Override @Override
public AddCounterChoiceSourceEffect copy() { public AddCounterChoiceSourceEffect copy() {
return new AddCounterChoiceSourceEffect(this); return new AddCounterChoiceSourceEffect(this);

View file

@ -983,7 +983,7 @@ public final class CardUtil {
} }
public static String getTextWithFirstCharUpperCase(String text) { public static String getTextWithFirstCharUpperCase(String text) {
if (text != null && text.length() >= 1) { if (text != null && !text.isEmpty()) {
return Character.toUpperCase(text.charAt(0)) + text.substring(1); return Character.toUpperCase(text.charAt(0)) + text.substring(1);
} else { } else {
return text; return text;
@ -991,7 +991,7 @@ public final class CardUtil {
} }
public static String getTextWithFirstCharLowerCase(String text) { public static String getTextWithFirstCharLowerCase(String text) {
if (text != null && text.length() >= 1) { if (text != null && !text.isEmpty()) {
return Character.toLowerCase(text.charAt(0)) + text.substring(1); return Character.toLowerCase(text.charAt(0)) + text.substring(1);
} else { } else {
return text; return text;