move the debug stats panel out of the renderer

This commit is contained in:
2026-08-05 21:27:21 +02:00
parent e5dcb9de5f
commit f39fe9a118
5 changed files with 57 additions and 64 deletions

View File

@@ -27,6 +27,7 @@
#include <QPen>
#include <QPixmap>
#include <QRadialGradient>
#include <QFontMetrics>
#include <QStringList>
#include <QTimer>
@@ -405,6 +406,7 @@ void GameWorldView::paintGL()
// Screen-anchored chrome over the finished world.
drawScreenSpace(painter);
if (m_debugDraw) { drawDebugOverlay(painter); }
drawPauseBorder(painter);
drawDeconstructBorder(painter);
drawReplayOverlay(painter);
@@ -821,6 +823,51 @@ void GameWorldView::applyBeltDragPath()
// ---------------------------------------------------------------------------
void GameWorldView::drawDebugOverlay(QPainter& painter)
{
const QStringList lines = {
tr("Accumulated Threat Level: %1")
.arg(m_sim->getThreatLevel(), 0, 'f', 1),
tr("Time until Wave: %1s")
.arg(ticksToSeconds(m_sim->getNormalGapRemainingTicks()), 0, 'f', 1),
tr("Threat Accumulation Rate: %1 threat/s")
.arg(m_sim->getThreatAccumulationRate(), 0, 'f', 1),
tr("Max Factory Production: %1 threat/s")
.arg(m_sim->getMaxFactoryProductionThreatRate(), 0, 'f', 1),
tr("Current Factory Production: %1 threat/s")
.arg(m_sim->getCurrentFactoryProductionThreatRate(), 0, 'f', 1),
};
QFont font = painter.font();
font.setPointSize(m_visuals->toast.fontSize);
painter.setFont(font);
const QFontMetrics fm = painter.fontMetrics();
const int lineH = fm.height();
const int padding = 8;
const int spacing = 4;
int textW = 0;
for (const QString& line : lines)
{
textW = std::max(textW, fm.horizontalAdvance(line));
}
const int bgW = textW + padding * 2;
const int bgH = lineH * lines.size() + spacing * (lines.size() - 1) + padding * 2;
const QRect bgRect(padding, padding, bgW, bgH);
painter.fillRect(bgRect, QColor(0, 0, 0, 160));
painter.setPen(Qt::white);
int y = padding * 2;
for (const QString& line : lines)
{
const QRect textRect(padding * 2, y, textW, lineH);
painter.drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, line);
y += lineH + spacing;
}
}
void GameWorldView::drawScreenSpace(QPainter& /*painter*/)
{
}