show ports
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <QColor>
|
||||
#include <QFont>
|
||||
#include <QKeyEvent>
|
||||
#include <QMessageBox>
|
||||
#include <QMouseEvent>
|
||||
@@ -84,6 +86,18 @@ QString toDisplayName(const std::string& id)
|
||||
return result;
|
||||
}
|
||||
|
||||
QPoint portBodyTile(QPoint portTile, Rotation direction)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case Rotation::East: return portTile + QPoint(-1, 0);
|
||||
case Rotation::West: return portTile + QPoint( 1, 0);
|
||||
case Rotation::North: return portTile + QPoint( 0, 1);
|
||||
case Rotation::South: return portTile + QPoint( 0, -1);
|
||||
}
|
||||
return portTile;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -452,6 +466,40 @@ void GameWorldView::placeAtTile(QPoint tile)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Port glyph helper
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void GameWorldView::drawPortGlyph(QPainter& painter, QPoint bodyTile,
|
||||
Rotation direction, const QColor& color)
|
||||
{
|
||||
const float px = tilePx();
|
||||
const QRectF tr = tileRect(bodyTile);
|
||||
const QPointF center(tr.x() + static_cast<qreal>(px) * 0.5,
|
||||
tr.y() + static_cast<qreal>(px) * 0.5);
|
||||
|
||||
QPointF offset;
|
||||
const char* ch;
|
||||
switch (direction)
|
||||
{
|
||||
case Rotation::East: offset = QPointF(px * 0.25f, 0); ch = ">"; break;
|
||||
case Rotation::West: offset = QPointF(-px * 0.25f, 0); ch = "<"; break;
|
||||
case Rotation::North: offset = QPointF(0, -px * 0.25f); ch = "^"; break;
|
||||
case Rotation::South: offset = QPointF(0, px * 0.25f); ch = "v"; break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
const qreal half = static_cast<qreal>(px) * 0.3;
|
||||
const QPointF pos = center + offset;
|
||||
const QRectF textRect(pos.x() - half, pos.y() - half, half * 2.0, half * 2.0);
|
||||
|
||||
QFont f = painter.font();
|
||||
f.setPixelSize(std::max(6, static_cast<int>(px * 0.4f)));
|
||||
painter.setFont(f);
|
||||
painter.setPen(color);
|
||||
painter.drawText(textRect, Qt::AlignCenter, QString::fromLatin1(ch));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Rendering
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -505,6 +553,12 @@ void GameWorldView::drawBuildings(QPainter& painter)
|
||||
painter.drawText(bboxRect, Qt::AlignCenter, bv.glyph);
|
||||
}
|
||||
|
||||
for (const Port& port : b.outputPorts)
|
||||
{
|
||||
drawPortGlyph(painter, portBodyTile(port.tile, port.direction),
|
||||
port.direction, bv.outline);
|
||||
}
|
||||
|
||||
bool selected = false;
|
||||
for (EntityId selId : m_selectedIds)
|
||||
{
|
||||
@@ -531,6 +585,12 @@ void GameWorldView::drawBuildings(QPainter& painter)
|
||||
painter.setPen(QPen(bv.outline, 1));
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
painter.drawRect(tileRect(info.tile));
|
||||
|
||||
drawPortGlyph(painter, info.tile, info.directionA, bv.outline);
|
||||
if (info.type == BuildingType::Splitter)
|
||||
{
|
||||
drawPortGlyph(painter, info.tile, info.directionB, bv.outline);
|
||||
}
|
||||
}
|
||||
|
||||
painter.setOpacity(0.5);
|
||||
@@ -553,6 +613,19 @@ void GameWorldView::drawBuildings(QPainter& painter)
|
||||
painter.setPen(QPen(bv.outline, 1, Qt::DashLine));
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
painter.drawRect(bboxRect);
|
||||
|
||||
const BuildingDef* siteDef = findBuildingDef(s.type);
|
||||
if (siteDef)
|
||||
{
|
||||
const ParsedSurfaceMask siteMask =
|
||||
parseSurfaceMask(siteDef->surfaceMask, s.rotation);
|
||||
for (const Port& port : siteMask.outputPorts)
|
||||
{
|
||||
const QPoint absBody = s.anchor
|
||||
+ portBodyTile(port.tile, port.direction);
|
||||
drawPortGlyph(painter, absBody, port.direction, bv.outline);
|
||||
}
|
||||
}
|
||||
}
|
||||
painter.setOpacity(1.0);
|
||||
}
|
||||
@@ -655,6 +728,12 @@ void GameWorldView::drawOverlays(QPainter& painter)
|
||||
{
|
||||
painter.fillRect(tileRect(m_ghostTile + cell), ghostColor);
|
||||
}
|
||||
for (const Port& port : parsed.outputPorts)
|
||||
{
|
||||
const QPoint absBody = m_ghostTile
|
||||
+ portBodyTile(port.tile, port.direction);
|
||||
drawPortGlyph(painter, absBody, port.direction, Qt::white);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user