# HG changeset patch # User Wuzzy # Date 1532607503 -7200 # Node ID ea05d4b0b6b0e3331e9aa01a5d6a5edc3826cff4 # Parent 0c8deb3389902c49d90db265d55b2156569d1087 Prevent saving weapon scheme if name was already taken This is case-insensitive. diff -r 0c8deb338990 -r ea05d4b0b6b0 ChangeLog.txt --- a/ChangeLog.txt Thu Jul 26 14:18:23 2018 +0200 +++ b/ChangeLog.txt Thu Jul 26 14:18:23 2018 +0200 @@ -5,6 +5,7 @@ * Fix crash when starting game with 2 controllers or more * Fix insane amount of droplets appearing when shooting minigun into ocean world edge * Limit number of droplets to 50 (temporary bugfix) + * Prevent creation of schemes with same name as an existing scheme * Fix teleport tooltip claiming it doesn't end turn in hog placing phase with inf. attack + Add default controls for controllers (see README) diff -r 0c8deb338990 -r ea05d4b0b6b0 QTfrontend/ui/widget/selectWeapon.cpp --- a/QTfrontend/ui/widget/selectWeapon.cpp Thu Jul 26 14:18:23 2018 +0200 +++ b/QTfrontend/ui/widget/selectWeapon.cpp Thu Jul 26 14:18:23 2018 +0200 @@ -251,8 +251,6 @@ //prevent this. if (isDeleting) return; - // TODO make this return if success or not, so that the page can react - // properly and not goBack if saving failed if (m_name->text() == "") return; @@ -277,21 +275,24 @@ stateFull = state1 + state2 + state3 + state4; - for(int i = 0; i < cDefaultAmmos.size(); i++) + // Check for duplicates + QString inputNameLower = m_name->text().toLower(); + QString curWeaponsNameLower = curWeaponsName.toLower(); + QStringList keys = wconf->keys(); + for(int i = 0; i < keys.size(); i++) { - // Don't allow same name as default weapon set, even case-insensitively. + QString compName = keys[i]; + QString compNameLower = compName.toLower(); + // Don't allow same name as other weapon set, even case-insensitively. // This prevents some problems with saving/loading. - if (cDefaultAmmos[i].first.toLower().compare(m_name->text().toLower()) == 0) + if ((compNameLower == inputNameLower) && (compNameLower != curWeaponsNameLower)) { - // don't show warning if no change - if (cDefaultAmmos[i].second.compare(stateFull) == 0) - return; - + // Discard changed made to current weapon scheme if there's a duplicate m_name->setText(curWeaponsName); QMessageBox deniedMsg(this); deniedMsg.setIcon(QMessageBox::Warning); deniedMsg.setWindowTitle(QMessageBox::tr("Weapons - Warning")); - deniedMsg.setText(QMessageBox::tr("Cannot overwrite default weapon set '%1'!").arg(cDefaultAmmos[i].first)); + deniedMsg.setText(QMessageBox::tr("A weapon scheme with the name '%1' already exists. Changes made to the weapon scheme have been discarded.").arg(compName)); deniedMsg.setWindowModality(Qt::WindowModal); deniedMsg.exec(); return;