From d64a7a5dd94dc4243656ae6da67db828d6b8243a Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Mon, 27 Apr 2026 22:06:44 +0200 Subject: [PATCH] fix issue where construction sites could not be selected --- src/ui/GameWorldView.cpp | 18 ++++++++- src/ui/SelectedBuildingPanel.cpp | 65 ++++++++++++++++++++++++++++++-- 2 files changed, 78 insertions(+), 5 deletions(-) diff --git a/src/ui/GameWorldView.cpp b/src/ui/GameWorldView.cpp index ca13d26..0ae6735 100644 --- a/src/ui/GameWorldView.cpp +++ b/src/ui/GameWorldView.cpp @@ -1067,7 +1067,11 @@ void GameWorldView::mousePressEvent(QMouseEvent* event) } else { - const EntityId id = buildingAtTile(tile); + EntityId id = buildingAtTile(tile); + if (id == kInvalidEntityId) + { + id = siteAtTile(tile); + } if (id != kInvalidEntityId) { if (event->modifiers() & Qt::ControlModifier) @@ -1162,6 +1166,18 @@ void GameWorldView::mouseReleaseEvent(QMouseEvent* event) } } } + for (const ConstructionSite& s : m_sim->buildings().allSites()) + { + for (const QPoint& cell : s.bodyCells) + { + if (cell.x() >= x0 && cell.x() <= x1 + && cell.y() >= y0 && cell.y() <= y1) + { + boxSel.push_back(s.id); + break; + } + } + } if (!(event->modifiers() & Qt::ControlModifier)) { diff --git a/src/ui/SelectedBuildingPanel.cpp b/src/ui/SelectedBuildingPanel.cpp index a522286..51e4e93 100644 --- a/src/ui/SelectedBuildingPanel.cpp +++ b/src/ui/SelectedBuildingPanel.cpp @@ -168,7 +168,43 @@ void SelectedBuildingPanel::buildSingle(EntityId id) const Building* b = m_sim->buildings().findBuilding(id); if (!b) { - buildEmpty(); + const ConstructionSite* s = m_sim->buildings().findSite(id); + if (!s) + { + buildEmpty(); + return; + } + + QString progress; + if (s->completesAt == 0) + { + progress = "Queued"; + } + else + { + const BuildingDef* def = nullptr; + for (const BuildingDef& d : m_config->buildings.buildings) + { + if (d.type == s->type) { def = &d; break; } + } + if (def && def->constructionTimeSeconds > 0) + { + const Tick duration = secondsToTicks(def->constructionTimeSeconds); + const Tick elapsed = m_sim->currentTick() - (s->completesAt - duration); + const int pct = static_cast( + std::max(Tick(0), std::min(duration, elapsed)) * 100 / duration); + progress = QString::number(pct) + "% complete"; + } + else + { + progress = "Building..."; + } + } + + m_titleLabel->setText("(Building) " + buildingTypeName(s->type)); + m_titleLabel->show(); + m_buffersLabel->setText(progress); + m_buffersLabel->show(); return; } @@ -367,12 +403,27 @@ void SelectedBuildingPanel::onStateUpdated(Tick /*tick*/, int /*blocks*/, double { if (m_singleId == kInvalidEntityId) { return; } const Building* b = m_sim->buildings().findBuilding(m_singleId); - if (!b) + if (b) { - buildEmpty(); + // If the panel was last showing this id as a construction site, the + // full building UI (recipe combo, ports, etc.) hasn't been built yet. + if (m_titleLabel->text().startsWith("(Building) ")) + { + rebuild(); + } + else + { + refreshBuffers(b); + } return; } - refreshBuffers(b); + const ConstructionSite* s = m_sim->buildings().findSite(m_singleId); + if (s) + { + rebuild(); + return; + } + buildEmpty(); } void SelectedBuildingPanel::buildMulti(const std::vector& ids) @@ -393,6 +444,12 @@ void SelectedBuildingPanel::buildMulti(const std::vector& ids) if (b) { counts[b->type]++; + continue; + } + const ConstructionSite* s = m_sim->buildings().findSite(id); + if (s) + { + counts[s->type]++; } }