diff --git a/src/ui/GameWorldView.cpp b/src/ui/GameWorldView.cpp index b5bb1c2..d9c1d33 100644 --- a/src/ui/GameWorldView.cpp +++ b/src/ui/GameWorldView.cpp @@ -18,6 +18,7 @@ #include #include +#include "AttackBehavior.h" #include "BeltSystem.h" #include "Building.h" #include "BuildingSystem.h" @@ -248,6 +249,7 @@ void GameWorldView::paintGL() if (m_debugDraw) { drawDebugSensorRanges(painter); + drawDebugTargetLines(painter); drawDebugOverlay(painter); } drawShips(painter); @@ -921,6 +923,29 @@ void GameWorldView::drawDebugSensorRanges(QPainter& painter) }); } +void GameWorldView::drawDebugTargetLines(QPainter& painter) +{ + m_sim->admin().forEach( + [&](entt::entity /*e*/, const ShipIdentityComponent& si, + const PositionComponent& pos, const AttackBehavior& attack) + { + if (!attack.currentTarget.has_value()) { return; } + + const std::optional targetPos = + entityPosition(*attack.currentTarget); + if (!targetPos.has_value()) { return; } + + const std::map::const_iterator it = + m_visuals->ships.find(si.schematicId); + if (it == m_visuals->ships.end()) { return; } + + QColor lineColor = it->second.fill; + lineColor.setAlpha(128); + painter.setPen(QPen(lineColor, 1)); + painter.drawLine(worldToWidget(pos.value), worldToWidget(*targetPos)); + }); +} + void GameWorldView::drawDebugOverlay(QPainter& painter) { painter.resetTransform(); diff --git a/src/ui/GameWorldView.h b/src/ui/GameWorldView.h index 7c83e9b..0601597 100644 --- a/src/ui/GameWorldView.h +++ b/src/ui/GameWorldView.h @@ -99,6 +99,7 @@ private: void drawScrap(QPainter& painter); void drawShips(QPainter& painter); void drawDebugSensorRanges(QPainter& painter); + void drawDebugTargetLines(QPainter& painter); void drawDebugOverlay(QPainter& painter); void drawBeams(QPainter& painter); void drawOverlays(QPainter& painter);