QTfrontend/ui/widget/selectWeapon.cpp
changeset 13852 e7c69e849005
parent 13555 43b72629d453
child 13854 ccfbc5f59c52
equal deleted inserted replaced
13851:f01798038c2e 13852:e7c69e849005
    92     }
    92     }
    93 
    93 
    94     if (!QDir(cfgdir->absolutePath() + "/Schemes").exists()) {
    94     if (!QDir(cfgdir->absolutePath() + "/Schemes").exists()) {
    95         QDir().mkdir(cfgdir->absolutePath() + "/Schemes");
    95         QDir().mkdir(cfgdir->absolutePath() + "/Schemes");
    96     }
    96     }
       
    97     QStringList defaultAmmos;
       
    98     for(int i = 0; i < cDefaultAmmos.size(); ++i)
       
    99     {
       
   100         defaultAmmos.append(cDefaultAmmos[i].first.toLower());
       
   101     }
    97     if (!QDir(cfgdir->absolutePath() + "/Schemes/Ammo").exists()) {
   102     if (!QDir(cfgdir->absolutePath() + "/Schemes/Ammo").exists()) {
    98         qDebug("No /Schemes/Ammo directory found. Trying to import weapon schemes from weapons.ini.");
   103         qDebug("No /Schemes/Ammo directory found. Trying to import weapon schemes from weapons.ini.");
    99         QDir().mkdir(cfgdir->absolutePath() + "/Schemes/Ammo");
   104         QDir().mkdir(cfgdir->absolutePath() + "/Schemes/Ammo");
   100 
   105 
   101         QSettings old_wconf(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat);
   106         QSettings old_wconf(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat);
   102 
   107 
   103         QStringList defaultAmmos;
       
   104         for(int i = 0; i < cDefaultAmmos.size(); ++i)
       
   105         {
       
   106             defaultAmmos.append(cDefaultAmmos[i].first);
       
   107         }
       
   108 
       
   109         QStringList keys = old_wconf.allKeys();
   108         QStringList keys = old_wconf.allKeys();
   110         int imported = 0;
   109         int imported = 0;
   111         for(int i = 0; i < keys.size(); i++)
   110         for(int i = 0; i < keys.size(); i++)
   112         {
   111         {
   113             if (!defaultAmmos.contains(keys[i])) {
   112             if (!defaultAmmos.contains(keys[i].toLower())) {
   114                 wconf->insert(keys[i], fixWeaponSet(old_wconf.value(keys[i]).toString()));
   113                 wconf->insert(keys[i], fixWeaponSet(old_wconf.value(keys[i]).toString()));
   115                 QFile file(cfgdir->absolutePath() + "/Schemes/Ammo/" + keys[i] + ".hwa");
   114                 QFile file(cfgdir->absolutePath() + "/Schemes/Ammo/" + keys[i] + ".hwa");
   116                 if (file.open(QIODevice::WriteOnly)) {
   115                 if (file.open(QIODevice::WriteOnly)) {
   117                     QTextStream stream( &file );
   116                     QTextStream stream( &file );
   118                     stream << old_wconf.value(keys[i]).toString() << endl;
   117                     stream << old_wconf.value(keys[i]).toString() << endl;
   138             // Chop off file name suffix
   137             // Chop off file name suffix
   139             QString schemeName = schemes[i];
   138             QString schemeName = schemes[i];
   140             if (schemeName.endsWith(".hwa", Qt::CaseInsensitive)) {
   139             if (schemeName.endsWith(".hwa", Qt::CaseInsensitive)) {
   141                 schemeName.chop(4);
   140                 schemeName.chop(4);
   142             }
   141             }
   143             wconf->insert(schemeName, fixWeaponSet(config));
   142             // Don't load weapon scheme if name collides with any default scheme
       
   143             if (!defaultAmmos.contains(schemeName.toLower()))
       
   144                 wconf->insert(schemeName, fixWeaponSet(config));
       
   145             else
       
   146                 qWarning("Weapon scheme \"%s\" not loaded from file, name collides with a default scheme!", qPrintable(schemeName));
   144         }
   147         }
   145     }
   148     }
   146 
   149 
   147     QString currentState = *cDefaultAmmoStore;
   150     QString currentState = *cDefaultAmmoStore;
   148 
   151 
   252     if (isDeleting)
   255     if (isDeleting)
   253         return;
   256         return;
   254     if (m_name->text() == "")
   257     if (m_name->text() == "")
   255         return;
   258         return;
   256 
   259 
       
   260     // Don't save an default ammo scheme
       
   261     for(int i = 0; i < cDefaultAmmos.size(); ++i)
       
   262     {
       
   263         if(curWeaponsName == cDefaultAmmos[i].first)
       
   264             return;
       
   265     }
       
   266 
   257     QString state1;
   267     QString state1;
   258     QString state2;
   268     QString state2;
   259     QString state3;
   269     QString state3;
   260     QString state4;
   270     QString state4;
   261     QString stateFull;
   271     QString stateFull;