allow to unlock modules when destroying defence stations
This commit is contained in:
@@ -387,10 +387,14 @@ ShipLayoutDialog::ShipLayoutDialog(const GameConfig* config,
|
||||
const std::string& shipId,
|
||||
const ShipLayoutConfig& currentLayout,
|
||||
std::vector<ShipLayoutBlueprint>& allBlueprints,
|
||||
std::set<std::string> unlockedModuleIds,
|
||||
std::map<std::string, int> moduleLevels,
|
||||
QWidget* parent)
|
||||
: QDialog(parent)
|
||||
, m_config(config)
|
||||
, m_shipId(shipId)
|
||||
, m_unlockedModuleIds(std::move(unlockedModuleIds))
|
||||
, m_moduleLevels(std::move(moduleLevels))
|
||||
, m_rows(0)
|
||||
, m_cols(0)
|
||||
, m_placedModules(currentLayout.placedModules)
|
||||
@@ -469,6 +473,11 @@ ShipLayoutDialog::ShipLayoutDialog(const GameConfig* config,
|
||||
for (int i = 0; i < static_cast<int>(config->modules.modules.size()); ++i)
|
||||
{
|
||||
const ModuleDef& def = config->modules.modules[i];
|
||||
if (m_unlockedModuleIds.count(def.id) == 0)
|
||||
{
|
||||
m_moduleButtons.push_back(nullptr);
|
||||
continue;
|
||||
}
|
||||
const QString label = displayName(def.id)
|
||||
+ "\n" + QString::fromStdString(def.glyph);
|
||||
QPushButton* btn = new QPushButton(label, this);
|
||||
@@ -509,7 +518,7 @@ ShipLayoutDialog::ShipLayoutDialog(const GameConfig* config,
|
||||
{
|
||||
for (QPushButton* btn : m_moduleButtons)
|
||||
{
|
||||
btn->setChecked(false);
|
||||
if (btn) { btn->setChecked(false); }
|
||||
}
|
||||
m_activeModuleIndex = -1;
|
||||
m_removeButton->setChecked(true);
|
||||
@@ -628,14 +637,14 @@ void ShipLayoutDialog::onModuleButtonClicked(int index)
|
||||
{
|
||||
if (m_activeModuleIndex == index)
|
||||
{
|
||||
m_moduleButtons[index]->setChecked(false);
|
||||
if (m_moduleButtons[index]) { m_moduleButtons[index]->setChecked(false); }
|
||||
m_activeModuleIndex = -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < static_cast<int>(m_moduleButtons.size()); ++i)
|
||||
{
|
||||
m_moduleButtons[i]->setChecked(i == index);
|
||||
if (m_moduleButtons[i]) { m_moduleButtons[i]->setChecked(i == index); }
|
||||
}
|
||||
m_removeButton->setChecked(false);
|
||||
m_activeModuleIndex = index;
|
||||
@@ -717,7 +726,7 @@ void ShipLayoutDialog::updateStats()
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_statsPanel->refresh(m_shipId, level, m_placedModules);
|
||||
m_statsPanel->refresh(m_shipId, level, m_placedModules, m_moduleLevels);
|
||||
}
|
||||
|
||||
bool ShipLayoutDialog::canPlaceModule(const ModuleDef& def, QPoint position,
|
||||
@@ -779,13 +788,13 @@ void ShipLayoutDialog::loadLayoutBlueprint(const std::vector<PlacedModule>& modu
|
||||
|
||||
for (const PlacedModule& pm : modules)
|
||||
{
|
||||
// Validate module type exists.
|
||||
// Validate module type exists and is unlocked.
|
||||
const ModuleDef* def = nullptr;
|
||||
for (const ModuleDef& d : m_config->modules.modules)
|
||||
{
|
||||
if (d.id == pm.moduleId) { def = &d; break; }
|
||||
}
|
||||
if (!def) { continue; }
|
||||
if (!def || m_unlockedModuleIds.count(def->id) == 0) { continue; }
|
||||
|
||||
const std::vector<std::string> mask = rotatedMask(*def, pm.rotation);
|
||||
bool valid = true;
|
||||
|
||||
Reference in New Issue
Block a user