QTfrontend/ui/widget/selectWeapon.cpp
changeset 13555 43b72629d453
parent 13320 b024cf25bde1
child 13873 e7c69e849005
equal deleted inserted replaced
13554:a5a8488e2485 13555:43b72629d453
   249     //If an entry is deleted, this code would just re-add the deleted
   249     //If an entry is deleted, this code would just re-add the deleted
   250     //item. We use isDeleted to check if we are currently deleting to
   250     //item. We use isDeleted to check if we are currently deleting to
   251     //prevent this.
   251     //prevent this.
   252     if (isDeleting)
   252     if (isDeleting)
   253         return;
   253         return;
   254     // TODO make this return if success or not, so that the page can react
       
   255     // properly and not goBack if saving failed
       
   256     if (m_name->text() == "")
   254     if (m_name->text() == "")
   257         return;
   255         return;
   258 
   256 
   259     QString state1;
   257     QString state1;
   260     QString state2;
   258     QString state2;
   275         state4.append(QString::number(am));
   273         state4.append(QString::number(am));
   276     }
   274     }
   277 
   275 
   278     stateFull = state1 + state2 + state3 + state4;
   276     stateFull = state1 + state2 + state3 + state4;
   279 
   277 
   280     for(int i = 0; i < cDefaultAmmos.size(); i++)
   278     // Check for duplicates
   281     {
   279     QString inputNameLower = m_name->text().toLower();
   282         // Don't allow same name as default weapon set, even case-insensitively.
   280     QString curWeaponsNameLower = curWeaponsName.toLower();
       
   281     QStringList keys = wconf->keys();
       
   282     for(int i = 0; i < keys.size(); i++)
       
   283     {
       
   284         QString compName = keys[i];
       
   285         QString compNameLower = compName.toLower();
       
   286         // Don't allow same name as other weapon set, even case-insensitively.
   283         // This prevents some problems with saving/loading.
   287         // This prevents some problems with saving/loading.
   284         if (cDefaultAmmos[i].first.toLower().compare(m_name->text().toLower()) == 0)
   288         if ((compNameLower == inputNameLower) && (compNameLower != curWeaponsNameLower))
   285         {
   289         {
   286             // don't show warning if no change
   290             // Discard changed made to current weapon scheme if there's a duplicate
   287             if (cDefaultAmmos[i].second.compare(stateFull) == 0)
       
   288                 return;
       
   289 
       
   290             m_name->setText(curWeaponsName);
   291             m_name->setText(curWeaponsName);
   291             QMessageBox deniedMsg(this);
   292             QMessageBox deniedMsg(this);
   292             deniedMsg.setIcon(QMessageBox::Warning);
   293             deniedMsg.setIcon(QMessageBox::Warning);
   293             deniedMsg.setWindowTitle(QMessageBox::tr("Weapons - Warning"));
   294             deniedMsg.setWindowTitle(QMessageBox::tr("Weapons - Warning"));
   294             deniedMsg.setText(QMessageBox::tr("Cannot overwrite default weapon set '%1'!").arg(cDefaultAmmos[i].first));
   295             deniedMsg.setText(QMessageBox::tr("A weapon scheme with the name '%1' already exists. Changes made to the weapon scheme have been discarded.").arg(compName));
   295             deniedMsg.setWindowModality(Qt::WindowModal);
   296             deniedMsg.setWindowModality(Qt::WindowModal);
   296             deniedMsg.exec();
   297             deniedMsg.exec();
   297             return;
   298             return;
   298         }
   299         }
   299     }
   300     }