draw debug lines to repair and salvage behavior targets
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <cctype>
|
||||
#include <climits>
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
@@ -31,6 +32,8 @@
|
||||
#include "GameOverEvent.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "PositionComponent.h"
|
||||
#include "RepairBehavior.h"
|
||||
#include "SalvageScrapBehavior.h"
|
||||
#include "ScrapSystem.h"
|
||||
#include "SelectionChangedEvent.h"
|
||||
#include "SensorRangeComponent.h"
|
||||
@@ -927,6 +930,22 @@ void GameWorldView::drawDebugSensorRanges(QPainter& painter)
|
||||
|
||||
void GameWorldView::drawDebugTargetLines(QPainter& painter)
|
||||
{
|
||||
// Draw a thin translucent line from a ship to a target, colored by the ship's
|
||||
// own schematic fill. Shared by the attack, repair and salvage target lines.
|
||||
const std::function<void(const std::string&, const QVector2D&, const QVector2D&)>
|
||||
drawTargetLine = [&](const std::string& schematicId, const QVector2D& from,
|
||||
const QVector2D& to)
|
||||
{
|
||||
const std::map<std::string, ShipVisuals>::const_iterator it =
|
||||
m_visuals->ships.find(schematicId);
|
||||
if (it == m_visuals->ships.end()) { return; }
|
||||
|
||||
QColor lineColor = it->second.fill;
|
||||
lineColor.setAlpha(128);
|
||||
painter.setPen(QPen(lineColor, 1));
|
||||
painter.drawLine(worldToWidget(from), worldToWidget(to));
|
||||
};
|
||||
|
||||
m_sim->admin().forEach<ShipIdentityComponent, PositionComponent, AttackBehavior>(
|
||||
[&](entt::entity /*e*/, const ShipIdentityComponent& si,
|
||||
const PositionComponent& pos, const AttackBehavior& attack)
|
||||
@@ -937,14 +956,29 @@ void GameWorldView::drawDebugTargetLines(QPainter& painter)
|
||||
entityPosition(*attack.currentTarget);
|
||||
if (!targetPos.has_value()) { return; }
|
||||
|
||||
const std::map<std::string, ShipVisuals>::const_iterator it =
|
||||
m_visuals->ships.find(si.schematicId);
|
||||
if (it == m_visuals->ships.end()) { return; }
|
||||
drawTargetLine(si.schematicId, pos.value, *targetPos);
|
||||
});
|
||||
|
||||
QColor lineColor = it->second.fill;
|
||||
lineColor.setAlpha(128);
|
||||
painter.setPen(QPen(lineColor, 1));
|
||||
painter.drawLine(worldToWidget(pos.value), worldToWidget(*targetPos));
|
||||
m_sim->admin().forEach<ShipIdentityComponent, PositionComponent, RepairBehavior>(
|
||||
[&](entt::entity /*e*/, const ShipIdentityComponent& si,
|
||||
const PositionComponent& pos, const RepairBehavior& repair)
|
||||
{
|
||||
if (!repair.currentTarget.has_value()) { return; }
|
||||
|
||||
const std::optional<QVector2D> targetPos =
|
||||
entityPosition(*repair.currentTarget);
|
||||
if (!targetPos.has_value()) { return; }
|
||||
|
||||
drawTargetLine(si.schematicId, pos.value, *targetPos);
|
||||
});
|
||||
|
||||
m_sim->admin().forEach<ShipIdentityComponent, PositionComponent, SalvageScrapBehavior>(
|
||||
[&](entt::entity /*e*/, const ShipIdentityComponent& si,
|
||||
const PositionComponent& pos, const SalvageScrapBehavior& salvage)
|
||||
{
|
||||
if (!salvage.scrapTarget.has_value()) { return; }
|
||||
|
||||
drawTargetLine(si.schematicId, pos.value, *salvage.scrapTarget);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user