diff --git a/cockatrice/src/client/ui/widgets/deck_analytics/mana_base_widget.cpp b/cockatrice/src/client/ui/widgets/deck_analytics/mana_base_widget.cpp index 5fed47171..c9183d7ee 100644 --- a/cockatrice/src/client/ui/widgets/deck_analytics/mana_base_widget.cpp +++ b/cockatrice/src/client/ui/widgets/deck_analytics/mana_base_widget.cpp @@ -50,9 +50,11 @@ void ManaBaseWidget::updateDisplay() delete item; } - int totalSum = 0; + int highestEntry = 0; for (auto entry : manaBaseMap) { - totalSum += entry; + if (entry > highestEntry) { + highestEntry = entry; + } } // Define color mapping for mana types @@ -66,7 +68,7 @@ void ManaBaseWidget::updateDisplay() for (auto manaColor : manaBaseMap.keys()) { QColor barColor = manaColors.contains(manaColor) ? manaColors[manaColor] : Qt::gray; - BarWidget *barWidget = new BarWidget(QString(manaColor), manaBaseMap[manaColor], totalSum, barColor, this); + BarWidget *barWidget = new BarWidget(QString(manaColor), manaBaseMap[manaColor], highestEntry, barColor, this); barLayout->addWidget(barWidget); } diff --git a/cockatrice/src/client/ui/widgets/deck_analytics/mana_curve_widget.cpp b/cockatrice/src/client/ui/widgets/deck_analytics/mana_curve_widget.cpp index 407283b12..45322d731 100644 --- a/cockatrice/src/client/ui/widgets/deck_analytics/mana_curve_widget.cpp +++ b/cockatrice/src/client/ui/widgets/deck_analytics/mana_curve_widget.cpp @@ -77,9 +77,11 @@ void ManaCurveWidget::updateDisplay() } } - int totalSum = 0; + int highestEntry = 0; for (const auto &entry : manaCurveMap) { - totalSum += entry.second; + if (entry.second > highestEntry) { + highestEntry = entry.second; + } } // Convert unordered_map to ordered map to ensure sorting by CMC @@ -88,7 +90,7 @@ void ManaCurveWidget::updateDisplay() // Add new widgets to the layout in sorted order for (const auto &entry : sortedManaCurve) { BarWidget *barWidget = - new BarWidget(QString::number(entry.first), entry.second, totalSum, QColor(11, 11, 11), this); + new BarWidget(QString::number(entry.first), entry.second, highestEntry, QColor(11, 11, 11), this); barLayout->addWidget(barWidget); } diff --git a/cockatrice/src/client/ui/widgets/deck_analytics/mana_devotion_widget.cpp b/cockatrice/src/client/ui/widgets/deck_analytics/mana_devotion_widget.cpp index c21c0ccc6..50b241a2a 100644 --- a/cockatrice/src/client/ui/widgets/deck_analytics/mana_devotion_widget.cpp +++ b/cockatrice/src/client/ui/widgets/deck_analytics/mana_devotion_widget.cpp @@ -77,9 +77,11 @@ void ManaDevotionWidget::updateDisplay() delete item; } - int totalSum = 0; + int highestEntry = 0; for (auto entry : manaDevotionMap) { - totalSum += entry.second; + if (highestEntry < entry.second) { + highestEntry = entry.second; + } } // Define color mapping for devotion bars @@ -89,14 +91,13 @@ void ManaDevotionWidget::updateDisplay() for (auto entry : manaDevotionMap) { QColor barColor = manaColors.count(entry.first) ? manaColors[entry.first] : Qt::gray; - BarWidget *barWidget = new BarWidget(QString(entry.first), entry.second, totalSum, barColor, this); + BarWidget *barWidget = new BarWidget(QString(entry.first), entry.second, highestEntry, barColor, this); barLayout->addWidget(barWidget); } update(); // Update the widget display } -// Function to count mana symbols W, U, B, R, G in the input string std::unordered_map ManaDevotionWidget::countManaSymbols(const QString &manaString) { std::unordered_map manaCounts = {{'W', 0}, {'U', 0}, {'B', 0}, {'R', 0}, {'G', 0}}; @@ -114,15 +115,23 @@ std::unordered_map ManaDevotionWidget::countManaSymbols(const QString char mana2 = manaString[i].toLatin1(); manaCounts[mana1]++; manaCounts[mana2]++; + } else { + // Handle cases like "{W/}" where second part is invalid + manaCounts[mana1]++; } } else { manaCounts[mana1]++; } } + // Ensure we always skip to the closing '}' while (i < len && manaString[i] != '}') { - ++i; // Skip to closing '}' + ++i; } } + // Check if the character is a standalone mana symbol (not inside {}) + else if (manaCounts.find(manaString[i].toLatin1()) != manaCounts.end()) { + manaCounts[manaString[i].toLatin1()]++; + } } return manaCounts;