QTfrontend/ui/widget/selectWeapon.cpp
changeset 13315 3546bb36c8fb
parent 13314 fe85ba81b01b
child 13320 b024cf25bde1
equal deleted inserted replaced
13314:fe85ba81b01b 13315:3546bb36c8fb
    85     QFrame(parent),
    85     QFrame(parent),
    86     m_numItems(numItems)
    86     m_numItems(numItems)
    87 {
    87 {
    88     wconf = new QMap<QString, QString>();
    88     wconf = new QMap<QString, QString>();
    89     for(int i = 0; i < cDefaultAmmos.size(); ++i)
    89     for(int i = 0; i < cDefaultAmmos.size(); ++i)
       
    90     {
    90         wconf->insert(cDefaultAmmos[i].first, cDefaultAmmos[i].second);
    91         wconf->insert(cDefaultAmmos[i].first, cDefaultAmmos[i].second);
       
    92     }
    91 
    93 
    92     if (!QDir(cfgdir->absolutePath() + "/Schemes").exists()) {
    94     if (!QDir(cfgdir->absolutePath() + "/Schemes").exists()) {
    93         QDir().mkdir(cfgdir->absolutePath() + "/Schemes");
    95         QDir().mkdir(cfgdir->absolutePath() + "/Schemes");
    94     }
    96     }
    95     if (!QDir(cfgdir->absolutePath() + "/Schemes/Ammo").exists()) {
    97     if (!QDir(cfgdir->absolutePath() + "/Schemes/Ammo").exists()) {
    97         QDir().mkdir(cfgdir->absolutePath() + "/Schemes/Ammo");
    99         QDir().mkdir(cfgdir->absolutePath() + "/Schemes/Ammo");
    98 
   100 
    99         QSettings old_wconf(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat);
   101         QSettings old_wconf(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat);
   100 
   102 
   101         QStringList defaultAmmos;
   103         QStringList defaultAmmos;
   102         for(int i = 0; i < cDefaultAmmos.size(); ++i) 
   104         for(int i = 0; i < cDefaultAmmos.size(); ++i)
   103             defaultAmmos.append(cDefaultAmmos[i].first);        
   105         {
       
   106             defaultAmmos.append(cDefaultAmmos[i].first);
       
   107         }
   104 
   108 
   105         QStringList keys = old_wconf.allKeys();
   109         QStringList keys = old_wconf.allKeys();
   106         int imported = 0;
   110         int imported = 0;
   107         for(int i = 0; i < keys.size(); i++)
   111         for(int i = 0; i < keys.size(); i++)
   108         {
   112         {
   116                 }
   120                 }
   117                 imported++;
   121                 imported++;
   118             }
   122             }
   119         }
   123         }
   120         qDebug("%d weapon scheme(s) imported.", imported);
   124         qDebug("%d weapon scheme(s) imported.", imported);
   121     } else {        
   125     } else {
   122         QStringList schemes = QDir(cfgdir->absolutePath() + "/Schemes/Ammo").entryList();
   126         QStringList schemes = QDir(cfgdir->absolutePath() + "/Schemes/Ammo").entryList();
   123 
   127 
   124         for(int i = 0; i < schemes.size(); i++)
   128         for(int i = 0; i < schemes.size(); i++)
   125         {
   129         {
   126             if (schemes[i] == "." || schemes[i] == "..") continue;
   130             if (schemes[i] == "." || schemes[i] == "..") continue;
   203 
   207 
   204 void SelWeaponWidget::setWeapons(const QString& ammo)
   208 void SelWeaponWidget::setWeapons(const QString& ammo)
   205 {
   209 {
   206     bool enable = true;
   210     bool enable = true;
   207     for(int i = 0; i < cDefaultAmmos.size(); i++)
   211     for(int i = 0; i < cDefaultAmmos.size(); i++)
       
   212     {
   208         if (!cDefaultAmmos[i].first.compare(m_name->text()))
   213         if (!cDefaultAmmos[i].first.compare(m_name->text()))
   209         {
   214         {
   210             enable = false;
   215             enable = false;
   211         }
   216             break;
       
   217         }
       
   218     }
   212     for(int i = 0; i < m_numItems; ++i)
   219     for(int i = 0; i < m_numItems; ++i)
   213     {
   220     {
   214         twi::iterator it = weaponItems.find(i);
   221         twi::iterator it = weaponItems.find(i);
   215         if (it == weaponItems.end()) continue;
   222         if (it == weaponItems.end()) continue;
   216         it.value()[0]->setItemsNum(ammo[i].digitValue());
   223         it.value()[0]->setItemsNum(ammo[i].digitValue());
   226 }
   233 }
   227 
   234 
   228 void SelWeaponWidget::setDefault()
   235 void SelWeaponWidget::setDefault()
   229 {
   236 {
   230     for(int i = 0; i < cDefaultAmmos.size(); i++)
   237     for(int i = 0; i < cDefaultAmmos.size(); i++)
       
   238     {
   231         if (!cDefaultAmmos[i].first.compare(m_name->text()))
   239         if (!cDefaultAmmos[i].first.compare(m_name->text()))
   232         {
   240         {
   233             return;
   241             return;
   234         }
   242         }
       
   243     }
   235     setWeapons(*cDefaultAmmoStore);
   244     setWeapons(*cDefaultAmmoStore);
   236 }
   245 }
   237 
   246 
   238 //Save current weapons set.
   247 //Save current weapons set.
   239 void SelWeaponWidget::save()
   248 void SelWeaponWidget::save()
   321 {
   330 {
   322     QString delWeaponsName = curWeaponsName;
   331     QString delWeaponsName = curWeaponsName;
   323     if (delWeaponsName == "") return;
   332     if (delWeaponsName == "") return;
   324 
   333 
   325     for(int i = 0; i < cDefaultAmmos.size(); i++)
   334     for(int i = 0; i < cDefaultAmmos.size(); i++)
       
   335     {
   326         if (!cDefaultAmmos[i].first.compare(delWeaponsName))
   336         if (!cDefaultAmmos[i].first.compare(delWeaponsName))
   327         {
   337         {
   328             QMessageBox deniedMsg(this);
   338             QMessageBox deniedMsg(this);
   329             deniedMsg.setIcon(QMessageBox::Warning);
   339             deniedMsg.setIcon(QMessageBox::Warning);
   330             deniedMsg.setWindowTitle(QMessageBox::tr("Weapons - Warning"));
   340             deniedMsg.setWindowTitle(QMessageBox::tr("Weapons - Warning"));
   331             deniedMsg.setText(QMessageBox::tr("Cannot delete default weapon set '%1'!").arg(cDefaultAmmos[i].first));
   341             deniedMsg.setText(QMessageBox::tr("Cannot delete default weapon set '%1'!").arg(cDefaultAmmos[i].first));
   332             deniedMsg.setWindowModality(Qt::WindowModal);
   342             deniedMsg.setWindowModality(Qt::WindowModal);
   333             deniedMsg.exec();
   343             deniedMsg.exec();
   334             return;
   344             return;
   335         }
   345         }
       
   346     }
   336 
   347 
   337     QMessageBox reallyDeleteMsg(this);
   348     QMessageBox reallyDeleteMsg(this);
   338     reallyDeleteMsg.setIcon(QMessageBox::Question);
   349     reallyDeleteMsg.setIcon(QMessageBox::Question);
   339     reallyDeleteMsg.setWindowTitle(QMessageBox::tr("Weapons - Are you sure?"));
   350     reallyDeleteMsg.setWindowTitle(QMessageBox::tr("Weapons - Are you sure?"));
   340     reallyDeleteMsg.setText(QMessageBox::tr("Do you really want to delete the weapon set '%1'?").arg(delWeaponsName));
   351     reallyDeleteMsg.setText(QMessageBox::tr("Do you really want to delete the weapon set '%1'?").arg(delWeaponsName));
   425             << s.mid(thisSetLength * 2, thisSetLength)
   436             << s.mid(thisSetLength * 2, thisSetLength)
   426             << s.right(thisSetLength)
   437             << s.right(thisSetLength)
   427                ;
   438                ;
   428 
   439 
   429     for(int i = sl.length() - 1; i >= 0; --i)
   440     for(int i = sl.length() - 1; i >= 0; --i)
       
   441     {
   430         sl[i] = sl[i].leftJustified(neededLength, '0', true);
   442         sl[i] = sl[i].leftJustified(neededLength, '0', true);
       
   443     }
   431 
   444 
   432     return sl.join(QString());
   445     return sl.join(QString());
   433 }
   446 }
   434 
   447 
   435 void SelWeaponWidget::deletionDone()
   448 void SelWeaponWidget::deletionDone()