store belts as buildings and fix issue that belts could not be selected
This commit is contained in:
@@ -396,10 +396,6 @@ EntityId GameWorldView::buildingAtTile(QPoint tile) const
|
||||
if (cell == tile) { return b.id; }
|
||||
}
|
||||
}
|
||||
for (const BuildingSystem::BeltTileInfo& info : m_sim->buildings().allBeltTiles())
|
||||
{
|
||||
if (info.tile == tile) { return info.id; }
|
||||
}
|
||||
return kInvalidEntityId;
|
||||
}
|
||||
|
||||
@@ -542,10 +538,23 @@ void GameWorldView::drawBuildings(QPainter& painter)
|
||||
painter.fillRect(tileRect(cell), bv.fill);
|
||||
}
|
||||
|
||||
const QPointF tl = tileToWidget(b.anchor);
|
||||
const QRectF bboxRect(tl.x(), tl.y(),
|
||||
b.footprint.width() * static_cast<qreal>(tilePx()),
|
||||
b.footprint.height() * static_cast<qreal>(tilePx()));
|
||||
// Belts and splitters are 1×1 on their body cell; other buildings use
|
||||
// the full footprint bounding box for their outline and glyph.
|
||||
QRectF bboxRect;
|
||||
const bool isBeltLike = (b.type == BuildingType::Belt
|
||||
|| b.type == BuildingType::Splitter);
|
||||
if (isBeltLike && !b.bodyCells.empty())
|
||||
{
|
||||
const QPointF tl = tileToWidget(b.bodyCells[0]);
|
||||
bboxRect = QRectF(tl.x(), tl.y(), tilePx(), tilePx());
|
||||
}
|
||||
else
|
||||
{
|
||||
const QPointF tl = tileToWidget(b.anchor);
|
||||
bboxRect = QRectF(tl.x(), tl.y(),
|
||||
b.footprint.width() * static_cast<qreal>(tilePx()),
|
||||
b.footprint.height() * static_cast<qreal>(tilePx()));
|
||||
}
|
||||
|
||||
painter.setPen(QPen(bv.outline, 1));
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
@@ -576,27 +585,6 @@ void GameWorldView::drawBuildings(QPainter& painter)
|
||||
}
|
||||
}
|
||||
|
||||
// Belt and splitter tiles (stored separately from regular buildings)
|
||||
for (const BuildingSystem::BeltTileInfo& info : m_sim->buildings().allBeltTiles())
|
||||
{
|
||||
const std::map<BuildingType, BuildingVisuals>::const_iterator it =
|
||||
m_visuals->buildings.find(info.type);
|
||||
if (it == m_visuals->buildings.end()) { continue; }
|
||||
const BuildingVisuals& bv = it->second;
|
||||
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.fillRect(tileRect(info.tile), bv.fill);
|
||||
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);
|
||||
for (const ConstructionSite& s : m_sim->buildings().allSites())
|
||||
{
|
||||
@@ -782,17 +770,6 @@ void GameWorldView::drawOverlays(QPainter& painter)
|
||||
painter.fillRect(tileRect(cell), m_visuals->overlays.demolishTint);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const BuildingSystem::BeltTileInfo& info : m_sim->buildings().allBeltTiles())
|
||||
{
|
||||
if (info.id == m_demolishHoverId)
|
||||
{
|
||||
painter.fillRect(tileRect(info.tile), m_visuals->overlays.demolishTint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Box-select rectangle
|
||||
|
||||
Reference in New Issue
Block a user