fix issue where construction sites could not be selected
This commit is contained in:
@@ -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]++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user