fix issue where construction sites could not be selected

This commit is contained in:
2026-04-27 22:06:44 +02:00
parent 559dde96cf
commit d64a7a5dd9
2 changed files with 78 additions and 5 deletions

View File

@@ -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))
{

View File

@@ -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<int>(
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<EntityId>& ids)
@@ -393,6 +444,12 @@ void SelectedBuildingPanel::buildMulti(const std::vector<EntityId>& ids)
if (b)
{
counts[b->type]++;
continue;
}
const ConstructionSite* s = m_sim->buildings().findSite(id);
if (s)
{
counts[s->type]++;
}
}