implement debug draw mode

This commit is contained in:
2026-04-27 22:25:42 +02:00
parent 990703bd5b
commit 22e273f971
2 changed files with 43 additions and 0 deletions

View File

@@ -117,6 +117,7 @@ GameWorldView::GameWorldView(Simulation* sim, const GameConfig* config,
, m_dragging(false)
, m_demolishMode(false)
, m_demolishHoverId(kInvalidEntityId)
, m_debugDraw(false)
, m_boxSelecting(false)
, m_scrollLeft(false)
, m_scrollRight(false)
@@ -246,6 +247,7 @@ void GameWorldView::paintGL()
drawBuildings(painter);
drawBeltItems(painter);
drawScrap(painter);
if (m_debugDraw) { drawDebugSensorRanges(painter); }
drawShips(painter);
drawBeams(painter);
drawOverlays(painter);
@@ -775,6 +777,42 @@ void GameWorldView::drawShips(QPainter& painter)
}
}
void GameWorldView::drawDebugSensorRanges(QPainter& painter)
{
painter.setBrush(Qt::NoBrush);
for (const Ship& ship : m_sim->ships().allShips())
{
const ShipRole role = shipRole(ship);
const std::map<ShipRole, ShipVisuals>::const_iterator it =
m_visuals->ships.find(role);
if (it == m_visuals->ships.end()) { continue; }
float range = 0.0f;
if (ship.weapon.has_value())
{
range = ship.weapon->range;
}
else if (ship.repairTool.has_value())
{
range = ship.repairTool->range;
}
else if (ship.cargo.has_value())
{
range = ship.cargo->collectionRange * 5.0f;
}
else
{
continue;
}
const QPointF center = worldToWidget(ship.position);
const qreal radiusPx = static_cast<qreal>(range)
* static_cast<qreal>(tilePx());
painter.setPen(QPen(it->second.outline, 1));
painter.drawEllipse(center, radiusPx, radiusPx);
}
}
void GameWorldView::drawBeams(QPainter& painter)
{
painter.setPen(QPen(m_visuals->beams.color, m_visuals->beams.widthPx));
@@ -996,6 +1034,9 @@ void GameWorldView::keyPressEvent(QKeyEvent* event)
case Qt::Key_Backspace:
toggleDemolishMode();
break;
case Qt::Key_M:
m_debugDraw = !m_debugDraw;
break;
default:
QOpenGLWidget::keyPressEvent(event);
break;