122 lines
3.9 KiB
C++
122 lines
3.9 KiB
C++
#include "SchematicChoiceDialog.h"
|
|
|
|
#include <QHBoxLayout>
|
|
#include <QLabel>
|
|
#include <QPushButton>
|
|
#include <QStringList>
|
|
#include <QVBoxLayout>
|
|
|
|
SchematicChoiceDialog::SchematicChoiceDialog(
|
|
const std::vector<SchematicChoiceOption>& options,
|
|
QWidget* parent)
|
|
: QDialog(parent)
|
|
, m_chosenIndex(0)
|
|
{
|
|
setWindowTitle(tr("Schematic Drop"));
|
|
setWindowFlags(windowFlags() & ~Qt::WindowCloseButtonHint);
|
|
setModal(true);
|
|
|
|
QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
|
|
|
QLabel* titleLabel = new QLabel(tr("Choose a schematic to unlock:"), this);
|
|
QFont titleFont = titleLabel->font();
|
|
titleFont.setPointSize(titleFont.pointSize() + 2);
|
|
titleFont.setBold(true);
|
|
titleLabel->setFont(titleFont);
|
|
titleLabel->setAlignment(Qt::AlignCenter);
|
|
mainLayout->addWidget(titleLabel);
|
|
|
|
QHBoxLayout* optionsLayout = new QHBoxLayout();
|
|
mainLayout->addLayout(optionsLayout);
|
|
|
|
for (int i = 0; i < static_cast<int>(options.size()); ++i)
|
|
{
|
|
const SchematicChoiceOption& option = options[static_cast<std::size_t>(i)];
|
|
|
|
QWidget* card = new QWidget(this);
|
|
QVBoxLayout* cardLayout = new QVBoxLayout(card);
|
|
card->setStyleSheet("QWidget { border: 1px solid gray; padding: 8px; }");
|
|
|
|
QLabel* nameLabel = new QLabel(QString::fromStdString(option.displayName), card);
|
|
QFont nameFont = nameLabel->font();
|
|
nameFont.setPointSize(nameFont.pointSize() + 1);
|
|
nameFont.setBold(true);
|
|
nameLabel->setFont(nameFont);
|
|
nameLabel->setAlignment(Qt::AlignCenter);
|
|
cardLayout->addWidget(nameLabel);
|
|
|
|
if (option.type == SchematicType::Artifact)
|
|
{
|
|
QLabel* artifactTypeLabel = new QLabel(tr("Artifact"), card);
|
|
artifactTypeLabel->setAlignment(Qt::AlignCenter);
|
|
cardLayout->addWidget(artifactTypeLabel);
|
|
}
|
|
else
|
|
{
|
|
QString typeText;
|
|
if (option.type == SchematicType::Ship)
|
|
{
|
|
typeText = tr("Ship");
|
|
}
|
|
else if (option.type == SchematicType::Module)
|
|
{
|
|
typeText = tr("Module");
|
|
}
|
|
else
|
|
{
|
|
typeText = tr("Recipe");
|
|
}
|
|
QLabel* typeLabel = new QLabel(typeText, card);
|
|
typeLabel->setAlignment(Qt::AlignCenter);
|
|
cardLayout->addWidget(typeLabel);
|
|
|
|
QLabel* unlocksHeaderLabel = new QLabel(tr("Unlocks recipes for:"), card);
|
|
QFont unlocksHeaderFont = unlocksHeaderLabel->font();
|
|
unlocksHeaderFont.setBold(true);
|
|
unlocksHeaderLabel->setFont(unlocksHeaderFont);
|
|
unlocksHeaderLabel->setAlignment(Qt::AlignCenter);
|
|
cardLayout->addWidget(unlocksHeaderLabel);
|
|
|
|
QString unlocksText;
|
|
if (option.newlyUnlockedItemNames.empty())
|
|
{
|
|
unlocksText = tr("None");
|
|
}
|
|
else
|
|
{
|
|
QStringList itemLines;
|
|
for (const std::string& itemName : option.newlyUnlockedItemNames)
|
|
{
|
|
itemLines << QString::fromStdString(itemName);
|
|
}
|
|
unlocksText = itemLines.join("\n");
|
|
}
|
|
QLabel* unlocksLabel = new QLabel(unlocksText, card);
|
|
unlocksLabel->setAlignment(Qt::AlignCenter);
|
|
cardLayout->addWidget(unlocksLabel);
|
|
}
|
|
|
|
QPushButton* selectButton = new QPushButton(tr("Select"), card);
|
|
cardLayout->addWidget(selectButton);
|
|
|
|
const int index = i;
|
|
connect(selectButton, &QPushButton::clicked, this, [this, index]()
|
|
{
|
|
onOptionClicked(index);
|
|
});
|
|
|
|
optionsLayout->addWidget(card);
|
|
}
|
|
}
|
|
|
|
int SchematicChoiceDialog::getChosenIndex() const
|
|
{
|
|
return m_chosenIndex;
|
|
}
|
|
|
|
void SchematicChoiceDialog::onOptionClicked(int index)
|
|
{
|
|
m_chosenIndex = index;
|
|
accept();
|
|
}
|