diff --git a/forge-gui-desktop/src/main/java/forge/screens/deckeditor/controllers/CStatisticsImporter.java b/forge-gui-desktop/src/main/java/forge/screens/deckeditor/controllers/CStatisticsImporter.java index a93e11ca9a6..42ddeb549ea 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/deckeditor/controllers/CStatisticsImporter.java +++ b/forge-gui-desktop/src/main/java/forge/screens/deckeditor/controllers/CStatisticsImporter.java @@ -6,17 +6,24 @@ import forge.card.CardRules; import forge.card.CardRulesPredicates; import forge.card.MagicColor; import forge.deck.CardPool; +import forge.deck.DeckRecognizer; +import forge.deck.DeckSection; import forge.item.PaperCard; import forge.itemmanager.SItemManagerUtil; import forge.screens.deckeditor.views.VStatisticsImporter; import forge.util.ItemPool; +import forge.util.Localizer; import javax.swing.*; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.List; import java.util.Map; public class CStatisticsImporter { private static CStatisticsImporter instance = null; + private int totalCardsInDecklist = 0; private CStatisticsImporter(){} @@ -26,13 +33,25 @@ public class CStatisticsImporter { return instance; } - public void updateStats(Iterable> tokenCards) { + public void updateStats(Iterable cardTokens) { + + List> tokenCards = new ArrayList(); + int totalInMain = 0; + int totalInSide = 0; + for (DeckRecognizer.Token token : cardTokens){ + if (token.getType() == DeckRecognizer.TokenType.LEGAL_CARD_REQUEST) { + tokenCards.add(new AbstractMap.SimpleEntry<>(token.getCard(), token.getNumber())); + if (token.getTokenSection().equals(DeckSection.Main)) + totalInMain += token.getNumber(); + else if (token.getTokenSection().equals(DeckSection.Sideboard)) + totalInSide += token.getNumber(); + } + } final CardPool deck = new CardPool(); deck.addAll(tokenCards); int total = deck.countAll(); - final int[] shardCount = calculateShards(deck); - + totalCardsInDecklist = total; // Hack-ish: avoid /0 cases, but still populate labels :) if (total == 0) { total = 1; } @@ -60,13 +79,15 @@ public class CStatisticsImporter { setLabelValue(VStatisticsImporter.instance().getLblCMC5(), deck, SItemManagerUtil.StatTypes.CMC_5.predicate, total); setLabelValue(VStatisticsImporter.instance().getLblCMC6(), deck, SItemManagerUtil.StatTypes.CMC_6.predicate, total); - int totShards = calculateTotalShards(shardCount); - setLabelValue(VStatisticsImporter.instance().getLblWhiteShard(), "Shards:", shardCount[0], totShards); - setLabelValue(VStatisticsImporter.instance().getLblBlueShard(), "Shards:", shardCount[1], totShards); - setLabelValue(VStatisticsImporter.instance().getLblBlackShard(), "Shards:", shardCount[2], totShards); - setLabelValue(VStatisticsImporter.instance().getLblRedShard(), "Shards:", shardCount[3], totShards); - setLabelValue(VStatisticsImporter.instance().getLblGreenShard(), "Shards:", shardCount[4], totShards); - setLabelValue(VStatisticsImporter.instance().getLblColorlessShard(), "Shards:", shardCount[5], totShards); + VStatisticsImporter.instance().getLblTotal().setText( + String.format("%s: %d", Localizer.getInstance().getMessage("lblTotalCards").toUpperCase(), + deck.countAll())); + VStatisticsImporter.instance().getLblTotalMain().setText( + String.format("%s: %d", Localizer.getInstance().getMessage("lblTotalMain").toUpperCase(), + totalInMain)); + VStatisticsImporter.instance().getLblTotalSide().setText( + String.format("%s: %d", Localizer.getInstance().getMessage("lblTotalSide").toUpperCase(), + totalInSide)); } private void setLabelValue(final JLabel label, final ItemPool deck, final Predicate predicate, final int total) { @@ -74,31 +95,9 @@ public class CStatisticsImporter { label.setText(tmp + " (" + calculatePercentage(tmp, total) + "%)"); } - private void setLabelValue(final JLabel label, final String str, final int value, final int total) { - String labelText = String.format("%s%d (%d%%)", str, value, calculatePercentage(value, total)); - label.setText(labelText); - } - public static int calculatePercentage(final int x0, final int y0) { return (int) Math.round((double) (x0 * 100) / (double) y0); } - public static int[] calculateShards(final ItemPool deck) { - final int[] counts = new int[6]; // in WUBRGC order - for (final PaperCard c : deck.toFlatList()) { - final int[] cShards = c.getRules().getManaCost().getColorShardCounts(); - for (int i = 0; i < 6; i++) { - counts[i] += cShards[i]; - } - } - return counts; - } - - public static int calculateTotalShards(int[] counts) { - int total = 0; - for (int count : counts) { - total += count; - } - return total; - } + public int getTotalCardsInDecklist(){ return this.totalCardsInDecklist; } } diff --git a/forge-gui-desktop/src/main/java/forge/screens/deckeditor/views/VStatisticsImporter.java b/forge-gui-desktop/src/main/java/forge/screens/deckeditor/views/VStatisticsImporter.java index b3058592c40..75f31f6d45b 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/deckeditor/views/VStatisticsImporter.java +++ b/forge-gui-desktop/src/main/java/forge/screens/deckeditor/views/VStatisticsImporter.java @@ -1,10 +1,8 @@ package forge.screens.deckeditor.views; -import forge.StaticData; import forge.itemmanager.SItemManagerUtil; import forge.toolbox.FLabel; -import forge.toolbox.FPanel; import forge.toolbox.FScrollPane; import forge.toolbox.FSkin; import forge.util.Localizer; @@ -18,11 +16,22 @@ public class VStatisticsImporter { private static VStatisticsImporter lastInstance = null; // Global stats - private FLabel lblCardCountHeader = new FLabel.Builder() - .text(Localizer.getInstance().getMessage("lblCardByColorTypeCMC")).tooltip(Localizer.getInstance().getMessage("lblBreakdownOfColorTypeCMC")) - .fontStyle(Font.BOLD).fontSize(11).fontStyle(Font.BOLD).build(); - private FLabel lblShardCountHeader = new FLabel.Builder() - .text(Localizer.getInstance().getMessage("lblColoredManaSymbolsINManaCost")).tooltip(Localizer.getInstance().getMessage("lblAmountOfManaSymbolsInManaCostOfCards")) + + private FLabel lblTotal = new FLabel.Builder() + .text(String.format("%s: %d", Localizer.getInstance().getMessage("lblTotalCards").toUpperCase(), 0)) + .tooltip(Localizer.getInstance().getMessage("lblTotalCards")) + .fontStyle(Font.BOLD).fontSize(10).fontStyle(Font.BOLD).build(); + private FLabel lblTotalMain = new FLabel.Builder() + .text(String.format("%s: %d", Localizer.getInstance().getMessage("lblTotalMain").toUpperCase(), 0)) + .tooltip(Localizer.getInstance().getMessage("lblTotalMain")) + .fontStyle(Font.BOLD).fontSize(10).fontStyle(Font.BOLD).build(); + private FLabel lblTotalSide = new FLabel.Builder() + .text(String.format("%s: %d", Localizer.getInstance().getMessage("lblTotalSide").toUpperCase(), 0)) + .tooltip(Localizer.getInstance().getMessage("lblTotalSide")) + .fontStyle(Font.BOLD).fontSize(10).fontStyle(Font.BOLD).build(); + private FLabel lblTitle = new FLabel.Builder() + .text(Localizer.getInstance().getMessage("lblSummaryStats")) + .tooltip(Localizer.getInstance().getMessage("lblSummaryStats")) .fontStyle(Font.BOLD).fontSize(11).fontStyle(Font.BOLD).build(); // Total and color count labels @@ -35,14 +44,6 @@ public class VStatisticsImporter { private final FLabel lblWhite = buildLabel(SItemManagerUtil.StatTypes.WHITE, false); private final FLabel lblColorless = buildLabel(SItemManagerUtil.StatTypes.COLORLESS, true); - // Colored mana symbol count labels - private final FLabel lblWhiteShard = buildLabel(SItemManagerUtil.StatTypes.WHITE, true); - private final FLabel lblBlueShard = buildLabel(SItemManagerUtil.StatTypes.BLUE, true); - private final FLabel lblBlackShard = buildLabel(SItemManagerUtil.StatTypes.BLACK, true); - private final FLabel lblRedShard = buildLabel(SItemManagerUtil.StatTypes.RED, false); - private final FLabel lblGreenShard = buildLabel(SItemManagerUtil.StatTypes.GREEN, false); - private final FLabel lblColorlessShard = buildLabel(SItemManagerUtil.StatTypes.COLORLESS, false); - // Card type labels private final FLabel lblArtifact = buildLabel(SItemManagerUtil.StatTypes.ARTIFACT, true); private final FLabel lblCreature = buildLabel(SItemManagerUtil.StatTypes.CREATURE, false); @@ -93,13 +94,6 @@ public class VStatisticsImporter { lblWhite.setToolTipText(Localizer.getInstance().getMessage("lblWhiteCardCount")); lblColorless.setToolTipText(Localizer.getInstance().getMessage("lblColorlessCardCount")); - // Colored mana symbol count stats - lblBlackShard.setToolTipText(Localizer.getInstance().getMessage("lblBlackManaSymbolCount")); - lblBlueShard.setToolTipText(Localizer.getInstance().getMessage("lblBlueManaSymbolCount")); - lblGreenShard.setToolTipText(Localizer.getInstance().getMessage("lblGreenManaSymbolCount")); - lblRedShard.setToolTipText(Localizer.getInstance().getMessage("lblRedManaSymbolCount")); - lblWhiteShard.setToolTipText(Localizer.getInstance().getMessage("lblWhiteManaSymbolCount")); - // Type stats lblArtifact.setToolTipText(Localizer.getInstance().getMessage("lblArtifactCardCount")); lblCreature.setToolTipText(Localizer.getInstance().getMessage("lblCreatureCardCount")); @@ -122,9 +116,10 @@ public class VStatisticsImporter { pnlStats.setOpaque(false); pnlStats.setLayout(new MigLayout("insets 0, gap 0, ax center, wrap 3")); + pnlStats.add(lblTitle, "w 96%!, h 20px!, span 3 1, gap 2% 0 0 0"); + // Add labels to container final String constraints = "w 35%!, h 30px!"; - pnlStats.add(lblCardCountHeader, "w 96%!, h 40px!, span 3 1, gap 2% 0 0 0"); pnlStats.add(lblMulti, constraints); pnlStats.add(lblArtifact, constraints); @@ -154,14 +149,10 @@ public class VStatisticsImporter { pnlStats.add(lblSorcery, constraints); pnlStats.add(lblCMC6, constraints); - // Shard count stats container - pnlStats.add(lblShardCountHeader, "w 96%!, h 40px!, span 3 1, gap 2% 0 0 0"); - pnlStats.add(lblWhiteShard, constraints); - pnlStats.add(lblBlueShard, constraints); - pnlStats.add(lblBlackShard, constraints); - pnlStats.add(lblRedShard, constraints); - pnlStats.add(lblGreenShard, constraints); - pnlStats.add(lblColorlessShard, constraints); + pnlStats.add(lblTotal, constraints); + pnlStats.add(lblTotalMain, constraints); + pnlStats.add(lblTotalSide, constraints); + } public static VStatisticsImporter instance() { @@ -188,18 +179,6 @@ public class VStatisticsImporter { /** @return {@link forge.toolbox.FLabel} */ public FLabel getLblColorless() { return lblColorless; } - /** @return {@link forge.toolbox.FLabel} */ - public FLabel getLblBlackShard() { return lblBlackShard; } - /** @return {@link forge.toolbox.FLabel} */ - public FLabel getLblBlueShard() { return lblBlueShard; } - /** @return {@link forge.toolbox.FLabel} */ - public FLabel getLblGreenShard() { return lblGreenShard; } - /** @return {@link forge.toolbox.FLabel} */ - public FLabel getLblRedShard() { return lblRedShard; } - /** @return {@link forge.toolbox.FLabel} */ - public FLabel getLblWhiteShard() { return lblWhiteShard; } - public FLabel getLblColorlessShard() { return lblColorlessShard; } - /** @return {@link forge.toolbox.FLabel} */ public FLabel getLblArtifact() { return lblArtifact; } /** @return {@link forge.toolbox.FLabel} */ @@ -230,6 +209,13 @@ public class VStatisticsImporter { /** @return {@link forge.toolbox.FLabel} */ public FLabel getLblCMC6() { return lblCMC6; } + /** @return {@link forge.toolbox.FLabel} */ + public FLabel getLblTotal() { return lblTotal; } + /** @return {@link forge.toolbox.FLabel} */ + public FLabel getLblTotalMain() { return lblTotalMain; } + /** @return {@link forge.toolbox.FLabel} */ + public FLabel getLblTotalSide() { return lblTotalSide; } + /** @return {@link javax.swing.JPanel} */ public JPanel getMainPanel() { return this.pnlStats; } }