split the selection panel into one card per kind of selection

This commit is contained in:
2026-08-07 18:38:55 +02:00
parent cc0ef856e3
commit 2289277e12
60 changed files with 3014 additions and 1559 deletions

View File

@@ -0,0 +1,95 @@
#include "BufferSection.h"
#include <QLabel>
#include <QVBoxLayout>
#include "Building.h"
namespace
{
// One "<item>: <count>[/<per cycle>]" entry.
QString formatEntry(const std::string& itemId, int count, int perCycle)
{
QString text = QString::fromStdString(itemId) + ": " + QString::number(count);
if (perCycle > 0)
{
text += "/" + QString::number(perCycle);
}
return text + " ";
}
int findPerCycle(const std::map<std::string, int>& perCycle, const std::string& itemId)
{
const std::map<std::string, int>::const_iterator it = perCycle.find(itemId);
return (it != perCycle.end()) ? it->second : 0;
}
} // namespace
BufferSection::BufferSection(QWidget* parent)
: QWidget(parent)
{
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
m_label = new QLabel(this);
m_label->setWordWrap(true);
layout->addWidget(m_label);
}
void BufferSection::setBuffers(const Building& building,
const std::map<std::string, int>& perCycleInputs,
const std::map<std::string, int>& perCycleOutputs)
{
QString text;
if (!building.inputBuffer.counts.empty())
{
text += tr("Input: ");
for (const std::pair<const ItemType, int>& entry : building.inputBuffer.counts)
{
text += formatEntry(entry.first.id, entry.second,
findPerCycle(perCycleInputs, entry.first.id));
}
text += "\n";
}
// Output-side items are the buffered ones plus those still emerging onto the output
// belts: an emerging item still belongs to the output buffer (REQ-MAT-OUTPUT-EMERGE),
// so leaving it out would make it vanish from the panel while it animates.
std::map<std::string, int> outputCounts;
for (const Item& item : building.outputBuffer.items)
{
outputCounts[item.type.id]++;
}
for (const std::vector<BeltItemSlot>& lane : building.emergingItems)
{
for (const BeltItemSlot& slot : lane)
{
outputCounts[slot.item.type.id]++;
}
}
// A configured building lists every item its cycle produces, so an output the player
// is waiting for shows as 0 rather than being absent.
for (const std::pair<const std::string, int>& entry : perCycleOutputs)
{
outputCounts.emplace(entry.first, 0);
}
if (!outputCounts.empty())
{
text += tr("Output: ");
for (const std::pair<const std::string, int>& entry : outputCounts)
{
text += formatEntry(entry.first, entry.second,
findPerCycle(perCycleOutputs, entry.first));
}
}
m_label->setText(text.trimmed());
setVisible(!text.trimmed().isEmpty());
}