Added condition hints for cards

This commit is contained in:
Oleg Agafonov 2019-02-05 02:43:13 +04:00
parent 13ed3c6dbd
commit 2a63314714
6 changed files with 105 additions and 15 deletions

View file

@ -0,0 +1,59 @@
package mage.abilities.hint;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.game.Game;
import java.awt.*;
/**
* @author JayDi85
*/
public class ConditionHint implements Hint {
private Condition condition;
private String trueText;
private Color trueColor;
private String falseText;
private Color falseColor;
private Boolean useIcons;
public ConditionHint(Condition condition, String textWithIcons) {
this(condition, textWithIcons, null, textWithIcons, null, true);
}
public ConditionHint(Condition condition, String trueText, Color trueColor, String falseText, Color falseColor, Boolean useIcons) {
this.condition = condition;
this.trueText = trueText;
this.trueColor = trueColor;
this.falseText = falseText;
this.falseColor = falseColor;
this.useIcons = useIcons;
}
private ConditionHint(final ConditionHint hint) {
this.condition = hint.condition;
this.trueText = hint.trueText;
this.trueColor = hint.trueColor;
this.falseText = hint.falseText;
this.falseColor = hint.falseColor;
this.useIcons = hint.useIcons;
}
@Override
public String getText(Game game, Ability ability) {
String icon;
if (condition.apply(game, ability)) {
icon = this.useIcons ? HintUtils.HINT_ICON_GOOD : null;
return HintUtils.prepareText(this.trueText, this.trueColor, icon);
} else {
icon = this.useIcons ? HintUtils.HINT_ICON_BAD : null;
return HintUtils.prepareText(this.falseText, this.falseColor, icon);
}
}
@Override
public Hint copy() {
return new ConditionHint(this);
}
}

View file

@ -1,16 +1,16 @@
package mage.abilities.hint;
import mage.abilities.Ability;
import mage.game.Game;
import java.io.Serializable;
import java.util.UUID;
/**
* @author JayDi85
*/
public interface Hint extends Serializable {
String getText(Game game, UUID sourceId);
String getText(Game game, Ability ability);
Hint copy();
}

View file

@ -0,0 +1,35 @@
package mage.abilities.hint;
import java.awt.*;
/**
* @author JayDi85
*/
public class HintUtils {
public static final String HINT_ICON_GOOD = " GOOD_ICON "; // TODO: icon
public static final String HINT_ICON_BAD = " BAD_ICON "; // TODO: icon
public static String prepareText(String text, Color color) {
return prepareText(text, color, null);
}
public static String prepareText(String text, Color color, String icon) {
String res;
// text
if (text != null && color != null) {
String hex = String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getGreen());
res = String.format("<font color=%s>%s</font>", hex, text);
} else {
res = text;
}
// icon
if (res != null && icon != null) {
res = icon + res;
}
return res;
}
}

View file

@ -1,9 +1,9 @@
package mage.abilities.hint;
import mage.abilities.Ability;
import mage.game.Game;
import java.awt.*;
import java.util.UUID;
/**
* @author JayDi85
@ -17,22 +17,18 @@ public class StaticHint implements Hint {
}
public StaticHint(String text, Color color) {
if (color != null) {
String hex = String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getGreen());
this.text = String.format("<font color=%s>%s</font>", hex, text);
} else {
this.text = text;
}
}
public String getText(Game game, UUID sourceId) {
return text;
this.text = HintUtils.prepareText(text, color);
}
private StaticHint(final StaticHint hint) {
this.text = hint.text;
}
@Override
public String getText(Game game, Ability ability) {
return text;
}
@Override
public Hint copy() {
return new StaticHint(this);

View file

@ -257,7 +257,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
// extra hints
for (Ability ability : abilities) {
for (Hint hint : ability.getHints()) {
String s = hint.getText(game, objectId);
String s = hint.getText(game, ability);
if (s != null && !s.isEmpty()) {
rules.add(s);
}

View file

@ -248,7 +248,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
// extra hints
for (Ability ability : abilities) {
for (Hint hint : ability.getHints()) {
String s = hint.getText(game, objectId);
String s = hint.getText(game, ability);
if (s != null && !s.isEmpty()) {
rules.add(s);
}