mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
Fixes following review
Add missing mod to CMap in checkRequiredMods
This commit is contained in:
@@ -22,8 +22,6 @@
|
||||
PlayerSelectionDialog::PlayerSelectionDialog(MainWindow * mainWindow)
|
||||
: QDialog(mainWindow), selectedPlayer(PlayerColor::NEUTRAL)
|
||||
{
|
||||
assert(mainWindow);
|
||||
|
||||
setupDialogComponents();
|
||||
|
||||
int maxPlayers = 0;
|
||||
@@ -88,22 +86,9 @@ void PlayerSelectionDialog::addRadioButton(QAction * action, PlayerColor player)
|
||||
selectedPlayer = player;
|
||||
}
|
||||
|
||||
radioButton->setToolTip(tr("Shortcut: %1").arg(action->shortcut().toString()));
|
||||
buttonGroup->addButton(radioButton, player.getNum());
|
||||
|
||||
auto * shortcutLabel = new QLabel(action->shortcut().toString(), this);
|
||||
QFont shortcutFont = font;
|
||||
shortcutFont.setPointSize(9);
|
||||
shortcutFont.setItalic(true);
|
||||
shortcutLabel->setFont(shortcutFont);
|
||||
shortcutLabel->setAlignment(Qt::AlignCenter | Qt::AlignVCenter);
|
||||
shortcutLabel->setContentsMargins(0, 0, 6, 0); // Italic text was trimmed at the end
|
||||
|
||||
auto * rowWidget = new QWidget(this);
|
||||
auto * rowLayout = new QGridLayout(rowWidget);
|
||||
rowLayout->setContentsMargins(0, 0, 0, 0);
|
||||
rowLayout->addWidget(radioButton, 0, 0, Qt::AlignCenter | Qt::AlignVCenter);
|
||||
rowLayout->addWidget(shortcutLabel, 0, 1, Qt::AlignCenter | Qt::AlignVCenter);
|
||||
radioButtonsLayout.addWidget(rowWidget);
|
||||
radioButtonsLayout.addWidget(radioButton);
|
||||
|
||||
connect(radioButton, &QRadioButton::clicked, this, [this, player]()
|
||||
{
|
||||
|
||||
@@ -26,13 +26,13 @@ class PlayerSelectionDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PlayerSelectionDialog(MainWindow * mainWindow = nullptr);
|
||||
explicit PlayerSelectionDialog(MainWindow * mainWindow);
|
||||
PlayerColor getSelectedPlayer() const;
|
||||
|
||||
private:
|
||||
const int dialogWidth = 320;
|
||||
|
||||
QButtonGroup * buttonGroup = nullptr;
|
||||
QButtonGroup * buttonGroup;
|
||||
PlayerColor selectedPlayer;
|
||||
|
||||
QFont font;
|
||||
|
||||
@@ -601,20 +601,15 @@ bool MapController::checkRequiredMods(const CGObjectInstance * obj, QString & er
|
||||
{
|
||||
if(!_map->mods.count(mod.first))
|
||||
{
|
||||
QString submod;
|
||||
if(!mod.second.parent.empty())
|
||||
submod = tr(" (submod of %1)").arg(QString::fromStdString(mod.second.parent));
|
||||
|
||||
auto reply = QMessageBox::question(main,
|
||||
tr("Missing Required Mod"),
|
||||
tr("This object is from the mod '%1'%2.\n\n"
|
||||
"The mod is currently not in the map's required modifications list.\n\n"
|
||||
"Do you want to add this mod to the required modifications?\n")
|
||||
.arg(QString::fromStdString(LIBRARY->modh->getModInfo(mod.first).getVerificationInfo().name), submod),
|
||||
tr("Missing Required Mod"), modMissingMessage(mod.second) + tr("\n\nDo you want to do that now ?"),
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
|
||||
if(reply == QMessageBox::Yes)
|
||||
{
|
||||
_map->mods[mod.first] = LIBRARY->modh->getModInfo(mod.first).getVerificationInfo();
|
||||
Q_EMIT requestModsUpdate(modsInfo, true); // signal for MapSettings
|
||||
}
|
||||
else
|
||||
{
|
||||
error = tr("This object's mod is mandatory for map to remain valid.");
|
||||
@@ -625,6 +620,19 @@ bool MapController::checkRequiredMods(const CGObjectInstance * obj, QString & er
|
||||
return true;
|
||||
}
|
||||
|
||||
QString MapController::modMissingMessage(const ModVerificationInfo & info)
|
||||
{
|
||||
QString modName = QString::fromStdString(info.name);
|
||||
QString submod;
|
||||
if(!info.parent.empty())
|
||||
submod = QObject::tr(" (submod of %1)").arg(QString::fromStdString(info.parent));
|
||||
|
||||
return QObject::tr("The mod '%1'%2, is required by an object on the map.\n"
|
||||
"Add it to the map's required mods in Map->General settings.",
|
||||
"should be consistent with Map->General menu entry translation")
|
||||
.arg(modName, submod);
|
||||
}
|
||||
|
||||
void MapController::undo()
|
||||
{
|
||||
_map->getEditManager()->getUndoManager().undo();
|
||||
|
||||
@@ -79,6 +79,10 @@ public:
|
||||
static ModCompatibilityInfo modAssessmentAll();
|
||||
static ModCompatibilityInfo modAssessmentMap(const CMap & map);
|
||||
|
||||
/// Returns formatted message string describing a missing mod requirement for the map.
|
||||
/// Used in both warnings and confirmations related to required mod dependencies.
|
||||
static QString modMissingMessage(const ModVerificationInfo & info);
|
||||
|
||||
void undo();
|
||||
void redo();
|
||||
|
||||
|
||||
@@ -171,16 +171,7 @@ std::set<Validator::Issue> Validator::validate(const CMap * map)
|
||||
for(auto & mod : MapController::modAssessmentMap(*map))
|
||||
{
|
||||
if(!map->mods.count(mod.first))
|
||||
{
|
||||
QString submod;
|
||||
if(!mod.second.parent.empty())
|
||||
submod = tr(" (submod of %1").arg(QString::fromStdString(mod.second.parent));
|
||||
|
||||
issues.insert({
|
||||
tr("Map contains object(s) from mod '%1'%2, but the mod is missing from the map's required mods list."
|
||||
" Add it to the map's required mods in Map->General settings.", "should be consistent with Map->General menu entry translation")
|
||||
.arg(QString::fromStdString(LIBRARY->modh->getModInfo(mod.first).getVerificationInfo().name), submod), true });
|
||||
}
|
||||
issues.insert({ MapController::modMissingMessage(mod.second), true });
|
||||
}
|
||||
}
|
||||
catch(const std::exception & e)
|
||||
@@ -211,7 +202,7 @@ void Validator::showValidationResults(const CMap * map)
|
||||
|
||||
if(ui->listWidget->count() == 0)
|
||||
{
|
||||
QPixmap greenTick = QPixmap(":/icons/mod-enabled.png");
|
||||
QPixmap greenTick(":/icons/mod-enabled.png");
|
||||
QString validMessage = tr("The map is valid and has no issues.");
|
||||
auto * item = new QListWidgetItem(QIcon(greenTick), validMessage, ui->listWidget);
|
||||
ui->listWidget->addItem(item);
|
||||
|
||||
@@ -47,32 +47,32 @@ public:
|
||||
private:
|
||||
Ui::Validator *ui;
|
||||
|
||||
QRect screenGeometry;
|
||||
QRect screenGeometry;
|
||||
|
||||
void showValidationResults(const CMap * map);
|
||||
void adjustWindowSize();
|
||||
void adjustWindowSize();
|
||||
};
|
||||
|
||||
class ValidatorItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
explicit ValidatorItemDelegate(QObject * parent = nullptr) : QStyledItemDelegate(parent)
|
||||
{
|
||||
screenGeometry = QApplication::primaryScreen()->availableGeometry();
|
||||
}
|
||||
explicit ValidatorItemDelegate(QObject * parent = nullptr) : QStyledItemDelegate(parent)
|
||||
{
|
||||
screenGeometry = QApplication::primaryScreen()->availableGeometry();
|
||||
}
|
||||
|
||||
int itemPaddingBottom = 14;
|
||||
int iconPadding = 4;
|
||||
int textOffsetForIcon = 30;
|
||||
int itemPaddingBottom = 14;
|
||||
int iconPadding = 4;
|
||||
int textOffsetForIcon = 30;
|
||||
int textPaddingRight = 10;
|
||||
int minItemWidth = 350;
|
||||
int screenMargin = 350; // some reserved space from screenWidth; used if text.width > screenWidth - screenMargin
|
||||
int minItemWidth = 350;
|
||||
int screenMargin = 350; // some reserved space from screenWidth; used if text.width > screenWidth - screenMargin
|
||||
|
||||
const int offsetForIcon = iconPadding + textOffsetForIcon;
|
||||
|
||||
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
|
||||
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
|
||||
QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const override;
|
||||
|
||||
private:
|
||||
QRect screenGeometry;
|
||||
QRect screenGeometry;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user