mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
Added condition hints for cards
This commit is contained in:
parent
13ed3c6dbd
commit
2a63314714
6 changed files with 105 additions and 15 deletions
59
Mage/src/main/java/mage/abilities/hint/ConditionHint.java
Normal file
59
Mage/src/main/java/mage/abilities/hint/ConditionHint.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,16 +1,16 @@
|
||||||
package mage.abilities.hint;
|
package mage.abilities.hint;
|
||||||
|
|
||||||
|
import mage.abilities.Ability;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author JayDi85
|
* @author JayDi85
|
||||||
*/
|
*/
|
||||||
public interface Hint extends Serializable {
|
public interface Hint extends Serializable {
|
||||||
|
|
||||||
String getText(Game game, UUID sourceId);
|
String getText(Game game, Ability ability);
|
||||||
|
|
||||||
Hint copy();
|
Hint copy();
|
||||||
}
|
}
|
35
Mage/src/main/java/mage/abilities/hint/HintUtils.java
Normal file
35
Mage/src/main/java/mage/abilities/hint/HintUtils.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
package mage.abilities.hint;
|
package mage.abilities.hint;
|
||||||
|
|
||||||
|
import mage.abilities.Ability;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author JayDi85
|
* @author JayDi85
|
||||||
|
@ -17,22 +17,18 @@ public class StaticHint implements Hint {
|
||||||
}
|
}
|
||||||
|
|
||||||
public StaticHint(String text, Color color) {
|
public StaticHint(String text, Color color) {
|
||||||
if (color != null) {
|
this.text = HintUtils.prepareText(text, color);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private StaticHint(final StaticHint hint) {
|
private StaticHint(final StaticHint hint) {
|
||||||
this.text = hint.text;
|
this.text = hint.text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getText(Game game, Ability ability) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Hint copy() {
|
public Hint copy() {
|
||||||
return new StaticHint(this);
|
return new StaticHint(this);
|
||||||
|
|
|
@ -257,7 +257,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
|
||||||
// extra hints
|
// extra hints
|
||||||
for (Ability ability : abilities) {
|
for (Ability ability : abilities) {
|
||||||
for (Hint hint : ability.getHints()) {
|
for (Hint hint : ability.getHints()) {
|
||||||
String s = hint.getText(game, objectId);
|
String s = hint.getText(game, ability);
|
||||||
if (s != null && !s.isEmpty()) {
|
if (s != null && !s.isEmpty()) {
|
||||||
rules.add(s);
|
rules.add(s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,7 +248,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
||||||
// extra hints
|
// extra hints
|
||||||
for (Ability ability : abilities) {
|
for (Ability ability : abilities) {
|
||||||
for (Hint hint : ability.getHints()) {
|
for (Hint hint : ability.getHints()) {
|
||||||
String s = hint.getText(game, objectId);
|
String s = hint.getText(game, ability);
|
||||||
if (s != null && !s.isEmpty()) {
|
if (s != null && !s.isEmpty()) {
|
||||||
rules.add(s);
|
rules.add(s);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue