mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
GUI: added mana and other symbols support in choose spell dialog (closes #12155)
This commit is contained in:
parent
521a0f6e32
commit
2bf6e3e3a2
7 changed files with 26 additions and 36 deletions
|
|
@ -7,15 +7,13 @@ import mage.client.components.ColorPane;
|
|||
import mage.client.dialog.MageDialog;
|
||||
import mage.client.game.GamePanel;
|
||||
import mage.client.util.ImageHelper;
|
||||
import mage.remote.Session;
|
||||
import mage.util.CardUtil;
|
||||
import mage.view.AbilityPickerView;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jdesktop.layout.GroupLayout;
|
||||
import org.jdesktop.layout.LayoutStyle;
|
||||
import org.jdesktop.swingx.JXPanel;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.mage.card.arcane.ManaSymbols;
|
||||
import org.mage.card.arcane.UI;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
|
@ -24,12 +22,14 @@ import java.util.List;
|
|||
import java.util.*;
|
||||
|
||||
/**
|
||||
* GUI: Dialog for choosing abilities (list)
|
||||
* GUI: dialog for choosing abilities (list). Example: ability for activate/cast
|
||||
*
|
||||
* @author nantuko, JayDi85
|
||||
*/
|
||||
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 int DIALOG_WIDTH = 440;
|
||||
private static final int DIALOG_HEIGHT = 260;
|
||||
|
|
@ -100,7 +100,8 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
|
|||
boolean wasCancelButton = false;
|
||||
for (Map.Entry<UUID, String> choice : choices.getChoices().entrySet()) {
|
||||
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) {
|
||||
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(
|
||||
GroupLayout.LEADING,
|
||||
layout.createSequentialGroup().add(layout.createParallelGroup(GroupLayout.LEADING)
|
||||
)
|
||||
)
|
||||
.addPreferredGap(LayoutStyle.RELATED)
|
||||
.add(
|
||||
layout.createParallelGroup(GroupLayout.TRAILING)
|
||||
|
|
@ -199,16 +200,16 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
|
|||
|
||||
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.LEADING).add(
|
||||
layout.createSequentialGroup().add(
|
||||
layout.createParallelGroup(GroupLayout.LEADING).add(
|
||||
layout.createSequentialGroup().add(title, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE)
|
||||
.add(5, 5, 5)
|
||||
.add(
|
||||
layout.createParallelGroup(GroupLayout.BASELINE)
|
||||
)
|
||||
).add(layout.createSequentialGroup().add(8, 8, 8)))
|
||||
layout.createParallelGroup(GroupLayout.LEADING).add(
|
||||
layout.createSequentialGroup().add(title, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE)
|
||||
.add(5, 5, 5)
|
||||
.add(
|
||||
layout.createParallelGroup(GroupLayout.BASELINE)
|
||||
)
|
||||
).add(layout.createSequentialGroup().add(8, 8, 8)))
|
||||
.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(
|
||||
LayoutStyle.RELATED).add(jScrollPane2, GroupLayout.PREFERRED_SIZE, 180, GroupLayout.PREFERRED_SIZE).addContainerGap(23, Short.MAX_VALUE)));
|
||||
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)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -355,15 +356,7 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
|
|||
|
||||
public AbilityPickerAction(UUID id, String choice) {
|
||||
this.id = id;
|
||||
putValue(Action.NAME, capitalizeFirstLetter(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);
|
||||
putValue(Action.NAME, choice);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1520,8 +1520,7 @@ public class CardView extends SimpleCardView {
|
|||
}
|
||||
|
||||
public String getColorText() {
|
||||
String colorText = getColor().getDescription();
|
||||
return colorText.substring(0, 1).toUpperCase(Locale.ENGLISH) + colorText.substring(1);
|
||||
return CardUtil.getTextWithFirstCharUpperCase(getColor().getDescription());
|
||||
}
|
||||
|
||||
public String getTypeText() {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import mage.abilities.effects.Effect;
|
|||
import mage.constants.Duration;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
|
|
@ -53,7 +54,7 @@ public class ReflexiveTriggeredAbility extends DelayedTriggeredAbility {
|
|||
if (text == null) {
|
||||
return super.getRule();
|
||||
}
|
||||
return text.substring(0, 1).toUpperCase(Locale.ENGLISH) + text.substring(1) + '.';
|
||||
return CardUtil.getTextWithFirstCharUpperCase(text) + '.';
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import mage.game.Game;
|
|||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
* @author LevelX2
|
||||
|
|
@ -47,7 +48,7 @@ public class EnterBattlefieldPayCostOrPutGraveyardEffect extends ReplacementEffe
|
|||
boolean replace = true;
|
||||
if (cost.canPay(source, source, player.getId(), game)) {
|
||||
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)) {
|
||||
cost.clearPaid();
|
||||
replace = !cost.pay(source, game, source, source.getControllerId(), false, null);
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class SacrificeSourceUnlessPaysEffect extends OneShotEffect {
|
|||
message += "Pay " + costValueMessage;
|
||||
logMessage += "pay " + costValueMessage;
|
||||
} else if (costValueMessage.length() > 1) {
|
||||
message += costValueMessage.substring(0, 1).toUpperCase() + costValueMessage.substring(1);
|
||||
message += CardUtil.getTextWithFirstCharUpperCase(costValueMessage);
|
||||
logMessage += costValueMessage;
|
||||
}
|
||||
message += '?';
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public class AddCounterChoiceSourceEffect extends OneShotEffect {
|
|||
counterChoice.setChoices(
|
||||
this.counterTypes
|
||||
.stream()
|
||||
.map(counterType -> AddCounterChoiceSourceEffect.capitalize(counterType.getName()))
|
||||
.map(counterType -> CardUtil.getTextWithFirstCharUpperCase(counterType.getName()))
|
||||
.collect(Collectors.toSet())
|
||||
);
|
||||
|
||||
|
|
@ -82,10 +82,6 @@ public class AddCounterChoiceSourceEffect extends OneShotEffect {
|
|||
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
|
||||
public AddCounterChoiceSourceEffect copy() {
|
||||
return new AddCounterChoiceSourceEffect(this);
|
||||
|
|
|
|||
|
|
@ -983,7 +983,7 @@ public final class CardUtil {
|
|||
}
|
||||
|
||||
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);
|
||||
} else {
|
||||
return text;
|
||||
|
|
@ -991,7 +991,7 @@ public final class CardUtil {
|
|||
}
|
||||
|
||||
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);
|
||||
} else {
|
||||
return text;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue