allow to unlock modules when destroying defence stations
This commit is contained in:
@@ -194,16 +194,19 @@ void GameWorldView::onFrame()
|
||||
m_sim->drainSchematicDropEvents();
|
||||
for (const SchematicDropEvent& ev : drops)
|
||||
{
|
||||
const QString shipName = toDisplayName(ev.schematicId);
|
||||
const QString name = toDisplayName(ev.schematicId);
|
||||
ToastEntry toast;
|
||||
if (ev.wasNewUnlock)
|
||||
if (ev.isModuleSchematic)
|
||||
{
|
||||
toast.text = "Schematic unlocked: " + shipName;
|
||||
toast.text = ev.wasNewUnlock
|
||||
? tr("Module unlocked: ") + name
|
||||
: name + tr(" production level -> ") + QString::number(ev.newLevel);
|
||||
}
|
||||
else
|
||||
{
|
||||
toast.text = shipName + " production level -> "
|
||||
+ QString::number(ev.newLevel);
|
||||
toast.text = ev.wasNewUnlock
|
||||
? tr("Schematic unlocked: ") + name
|
||||
: name + tr(" production level -> ") + QString::number(ev.newLevel);
|
||||
}
|
||||
toast.createdWallMs = m_wallMs;
|
||||
m_toasts.push_back(toast);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "MainWindow.h"
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCloseEvent>
|
||||
#include <QFile>
|
||||
@@ -233,8 +236,22 @@ void MainWindow::onLayoutDialogRequested(BuildingId shipyardId)
|
||||
currentLayout = *b->shipLayout;
|
||||
}
|
||||
|
||||
std::set<std::string> unlockedModuleIds;
|
||||
std::map<std::string, int> moduleLevels;
|
||||
for (const ModuleDef& def : m_sim->config().modules.modules)
|
||||
{
|
||||
if (m_sim->isModuleSchematicUnlocked(def.id))
|
||||
{
|
||||
unlockedModuleIds.insert(def.id);
|
||||
}
|
||||
moduleLevels[def.id] = m_sim->moduleSchematicLevel(def.id);
|
||||
}
|
||||
|
||||
ShipLayoutDialog dialog(&m_sim->config(), b->recipeId, currentLayout,
|
||||
m_layoutBlueprints, this);
|
||||
m_layoutBlueprints,
|
||||
std::move(unlockedModuleIds),
|
||||
std::move(moduleLevels),
|
||||
this);
|
||||
if (dialog.exec() == QDialog::Accepted && dialog.result().has_value())
|
||||
{
|
||||
m_sim->buildings().setShipLayout(shipyardId, *dialog.result());
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -24,6 +26,8 @@ public:
|
||||
const std::string& shipId,
|
||||
const ShipLayoutConfig& currentLayout,
|
||||
std::vector<ShipLayoutBlueprint>& allBlueprints,
|
||||
std::set<std::string> unlockedModuleIds,
|
||||
std::map<std::string, int> moduleLevels,
|
||||
QWidget* parent = nullptr);
|
||||
|
||||
std::optional<ShipLayoutConfig> result() const;
|
||||
@@ -57,6 +61,8 @@ private:
|
||||
|
||||
const GameConfig* m_config;
|
||||
std::string m_shipId;
|
||||
std::set<std::string> m_unlockedModuleIds;
|
||||
std::map<std::string, int> m_moduleLevels;
|
||||
std::vector<std::string> m_shipLayout;
|
||||
int m_rows;
|
||||
int m_cols;
|
||||
|
||||
@@ -108,9 +108,11 @@ ShipStatsPanel::ShipStatsPanel(const GameConfig* config, QWidget* parent)
|
||||
|
||||
void ShipStatsPanel::refresh(const std::string& shipId,
|
||||
int level,
|
||||
const std::vector<PlacedModule>& modules)
|
||||
const std::vector<PlacedModule>& modules,
|
||||
const std::map<std::string, int>& moduleLevelOverrides)
|
||||
{
|
||||
const ShipStats stats = calculateShipStats(*m_config, shipId, level, modules);
|
||||
const ShipStats stats = calculateShipStats(*m_config, shipId, level, modules,
|
||||
moduleLevelOverrides);
|
||||
const QString hpText = tr("HP: %1").arg(static_cast<int>(stats.hp + 0.5f));
|
||||
applyStats(stats, hpText);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -20,7 +21,8 @@ public:
|
||||
|
||||
void refresh(const std::string& shipId,
|
||||
int level,
|
||||
const std::vector<PlacedModule>& modules);
|
||||
const std::vector<PlacedModule>& modules,
|
||||
const std::map<std::string, int>& moduleLevelOverrides = {});
|
||||
|
||||
void refreshFromLive(const ShipStats& stats, float currentHp);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user