forked from External/mage
* added power level info in deck validation panel; * added detail calculation info (hint with cards and their power levels); * fixed that deck's edh power level ignore individual card's levels and used only commanders; * removed outdated deck restrictions by commander colors; * now players can really limit allowed decks by edh power level;
This commit is contained in:
parent
11dcc18049
commit
f3ba897536
9 changed files with 235 additions and 76 deletions
|
|
@ -0,0 +1,76 @@
|
|||
package mage.client.components;
|
||||
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.client.util.GUISizeHelper;
|
||||
import mage.client.util.gui.GuiDisplayUtil;
|
||||
import mage.deck.Commander;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Inject power level info inside validation panel
|
||||
*
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class EdhPowerLevelLegalityLabel extends LegalityLabel {
|
||||
|
||||
private final Commander commanderDeckType = new Commander();
|
||||
private final List<String> foundPowerCards = new ArrayList<>();
|
||||
|
||||
public EdhPowerLevelLegalityLabel() {
|
||||
super("EDH Power Level: ?", null);
|
||||
setPreferredSize(DIM_PREFERRED_X3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> selectCards() {
|
||||
// choose cards with power level
|
||||
return this.foundPowerCards;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateDeck(Deck deck) {
|
||||
// find and save power level and card hints
|
||||
|
||||
List<String> foundInfo = new ArrayList<>();
|
||||
int level = this.commanderDeckType.getEdhPowerLevel(deck, foundPowerCards, foundInfo);
|
||||
this.setText(String.format("EDH Power Level: %d", level));
|
||||
|
||||
// sort by score "+5 from xxx"
|
||||
Pattern pattern = Pattern.compile("\\+(\\d+)");
|
||||
foundInfo.sort((o1, o2) -> {
|
||||
Matcher matcher = pattern.matcher(o1);
|
||||
int score1 = matcher.find() ? Integer.parseInt(matcher.group(1)) : 0;
|
||||
matcher = pattern.matcher(o2);
|
||||
int score2 = matcher.find() ? Integer.parseInt(matcher.group(1)) : 0;
|
||||
if (score1 != score2) {
|
||||
return Integer.compare(score2, score1);
|
||||
}
|
||||
return o1.compareTo(o2);
|
||||
});
|
||||
|
||||
showStateInfo(formatCardsInfoTooltip(level, foundInfo));
|
||||
}
|
||||
|
||||
private String formatCardsInfoTooltip(int level, List<String> foundInfo) {
|
||||
// use 60% font for better and compatible list
|
||||
int infoFontSize = Math.round(GUISizeHelper.cardTooltipFont.getSize() * 0.6f);
|
||||
int maxLimit = 25;
|
||||
String extraInfo = this.foundPowerCards.size() <= maxLimit ? "" : String.format("<li style=\"margin-bottom: 2px;\">and %d more cards</li>", maxLimit - this.foundPowerCards.size());
|
||||
return foundInfo.stream()
|
||||
.limit(maxLimit)
|
||||
.reduce("<html><body>"
|
||||
+ "<p>EDH Power Level: <span style='color:#b8860b;font-weight:bold;'>" + level + "</span></p>"
|
||||
+ "<br>"
|
||||
+ "<u>Found <span style='font-weight:bold;'>" + this.foundPowerCards.size() + "</span> cards with power levels (click to select it)</u>"
|
||||
+ "<br>"
|
||||
+ "<ul style=\"font-size: " + infoFontSize + "px; width: " + TOOLTIP_TABLE_WIDTH + "px; padding-left: 10px; margin: 0;\">",
|
||||
(str, info) -> str + String.format("<li style=\"margin-bottom: 2px;\">%s</li>", info), String::concat)
|
||||
+ extraInfo
|
||||
+ "</ul>"
|
||||
+ "</body></html>";
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue