# HG changeset patch # User Wuzzy # Date 1521124469 -3600 # Node ID d0647647a6975ca45f83d7994bafe55a45820bed # Parent 1357dfbfa29c76a6490c68949e8380a0e1d05c4d Make chart in stats screen support negative numbers. Fixes e.g. Mutant diff -r 1357dfbfa29c -r d0647647a697 ChangeLog.txt --- a/ChangeLog.txt Thu Mar 15 14:51:07 2018 +0100 +++ b/ChangeLog.txt Thu Mar 15 15:34:29 2018 +0100 @@ -24,6 +24,7 @@ + Add default directory DrawnMaps for hand-drawn maps + Lead player to training missions when starting Hedgewars the first time * Fix broken preview of team hats (e.g. cap_team) + * Fix chart in stats screen not supporting negative numbers Content: + New scenarios: Bazooka Battlefield, Tentacle Terror diff -r 1357dfbfa29c -r d0647647a697 QTfrontend/ui/page/pagegamestats.cpp --- a/QTfrontend/ui/page/pagegamestats.cpp Thu Mar 15 14:51:07 2018 +0100 +++ b/QTfrontend/ui/page/pagegamestats.cpp Thu Mar 15 15:34:29 2018 +0100 @@ -174,9 +174,14 @@ graphic->setScene(Q_NULLPTR); m_scene.reset(new QGraphicsScene(this)); - quint32 maxValue = 0; + // min and max value across the entire chart + qint32 minValue = 0; + qint32 maxValue = 0; + bool minMaxValuesInitialized = false; + + // max data points per clan int maxDataPoints = 0; - for(QMap >::const_iterator i = healthPoints.constBegin(); i != healthPoints.constEnd(); ++i) + for(QMap >::const_iterator i = healthPoints.constBegin(); i != healthPoints.constEnd(); ++i) { maxDataPoints = qMax(maxDataPoints, i.value().size()); } @@ -189,20 +194,30 @@ return; } - QMap >::const_iterator i = healthPoints.constBegin(); + QMap >::const_iterator i = healthPoints.constBegin(); while (i != healthPoints.constEnd()) { - quint32 c = i.key(); - const QVector& hps = i.value(); + qint32 c = i.key(); + const QVector& hps = i.value(); QPainterPath path; - if (hps.size()) + if (hps.size()) { path.moveTo(0, hps[0]); + if(minMaxValuesInitialized) { + minValue = qMin(minValue, hps[0]); + maxValue = qMax(maxValue, hps[0]); + } else { + minValue = hps[0]; + maxValue = hps[0]; + minMaxValuesInitialized = true; + } + } for(int t = 0; t < hps.size(); ++t) { path.lineTo(t, hps[t]); maxValue = qMax(maxValue, hps[t]); + minValue = qMin(minValue, hps[t]); } QPen pen(c); @@ -214,7 +229,19 @@ } graphic->setScene(m_scene.data()); - graphic->setSceneRect(0, 0, maxDataPoints-1, qMax(maxValue, (quint32) 1)); + + // Calculate the bounding box of the final chart + qint32 sceneMinY = minValue; + qint32 sceneMaxY = maxValue; + // If all values are 0 or greater, make sure to include 0 at the bottom. + if(sceneMinY >= 0 && sceneMaxY >= 0) + sceneMinY = 0; + // If all values are equal, we must increase sceneMaxY, otherwise the scene rect + // would have a height of 0 and will screw up + if(sceneMinY == sceneMaxY) + sceneMaxY++; + graphic->setSceneRect(0, sceneMinY, maxDataPoints-1, sceneMaxY - sceneMinY); + graphic->fitInView(graphic->sceneRect()); graphic->show(); @@ -258,7 +285,7 @@ { int i = info.indexOf(' '); quint32 clan = info.left(i).toInt(); - quint32 hp = info.mid(i + 1).toUInt(); + qint32 hp = info.mid(i + 1).toInt(); healthPoints[clan].append(hp); break; } diff -r 1357dfbfa29c -r d0647647a697 QTfrontend/ui/page/pagegamestats.h --- a/QTfrontend/ui/page/pagegamestats.h Thu Mar 15 14:51:07 2018 +0100 +++ b/QTfrontend/ui/page/pagegamestats.h Thu Mar 15 15:34:29 2018 +0100 @@ -66,7 +66,7 @@ private: void AddStatText(const QString & msg); - QMap > healthPoints; + QMap > healthPoints; unsigned int playerPosition; quint32 lastColor; bool defaultGraphTitle;