QTfrontend/ui/widget/selectWeapon.cpp
changeset 12922 c0320d66310d
parent 12763 ad67a3804981
child 12923 305f3667af20
equal deleted inserted replaced
12921:684621f7eab3 12922:c0320d66310d
    19 
    19 
    20 #include "selectWeapon.h"
    20 #include "selectWeapon.h"
    21 #include "weaponItem.h"
    21 #include "weaponItem.h"
    22 #include "hwconsts.h"
    22 #include "hwconsts.h"
    23 
    23 
       
    24 #include <QDebug>
    24 #include <QPushButton>
    25 #include <QPushButton>
    25 #include <QGridLayout>
    26 #include <QGridLayout>
    26 #include <QHBoxLayout>
    27 #include <QHBoxLayout>
    27 #include <QLabel>
    28 #include <QLabel>
    28 #include <QBitmap>
    29 #include <QBitmap>
    82 
    83 
    83 SelWeaponWidget::SelWeaponWidget(int numItems, QWidget* parent) :
    84 SelWeaponWidget::SelWeaponWidget(int numItems, QWidget* parent) :
    84     QFrame(parent),
    85     QFrame(parent),
    85     m_numItems(numItems)
    86     m_numItems(numItems)
    86 {
    87 {
    87     wconf = new QSettings(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat, this);
    88     if (!QDir(cfgdir->absolutePath() + "/Weapon Settings").exists()) {
    88 
    89         QDir().mkdir(cfgdir->absolutePath() + "/Weapon Settings");
    89     for(int i = 0; i < cDefaultAmmos.size(); ++i)
    90         wconf = new QSettings(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat, this);
    90         wconf->setValue(cDefaultAmmos[i].first, cDefaultAmmos[i].second);
    91 
    91 
    92         for(int i = 0; i < cDefaultAmmos.size(); ++i)
    92     QStringList keys = wconf->allKeys();
    93             wconf->setValue(cDefaultAmmos[i].first, cDefaultAmmos[i].second);
    93     for(int i = 0; i < keys.size(); i++)
    94 
    94     {
    95         QStringList keys = wconf->allKeys();
    95         if (wconf->value(keys[i]).toString().size() != cDefaultAmmoStore->size())
    96         for(int i = 0; i < keys.size(); i++)
    96             wconf->setValue(keys[i], fixWeaponSet(wconf->value(keys[i]).toString()));
    97         {
       
    98             if (wconf->value(keys[i]).toString().size() != cDefaultAmmoStore->size())
       
    99                 wconf->setValue(keys[i], fixWeaponSet(wconf->value(keys[i]).toString()));
       
   100 
       
   101             QFile file(cfgdir->absolutePath() + "/Weapon Settings/" + keys[i] + ".hww");
       
   102             if (file.open(QIODevice::WriteOnly)) {
       
   103                 QTextStream stream( &file );
       
   104                 stream << wconf->value(keys[i]).toString() << endl;
       
   105             }
       
   106         }
       
   107     } else {
       
   108         wconf = new QSettings("Hedgewars", "Hedgewars");
       
   109         wconf->clear();
       
   110 
       
   111         QStringList schemes = QDir(cfgdir->absolutePath() + "/Weapon Settings").entryList();
       
   112 
       
   113         for(int i = 0; i < schemes.size(); i++)
       
   114         {
       
   115             if (schemes[i] == "." || schemes[i] == "..") continue;
       
   116 
       
   117             QFile file(cfgdir->absolutePath() + "/Weapon Settings/" + schemes[i]);
       
   118             QString config;
       
   119 
       
   120             if (file.open(QIODevice::ReadOnly)) {
       
   121                 QTextStream stream( &file );
       
   122                 stream >> config;
       
   123             }
       
   124 
       
   125             wconf->setValue(schemes[i].remove(".hww"), fixWeaponSet(config));
       
   126         }
    97     }
   127     }
    98 
   128 
    99     QString currentState = *cDefaultAmmoStore;
   129     QString currentState = *cDefaultAmmoStore;
   100 
   130 
   101     QTabWidget * tbw = new QTabWidget(this);
   131     QTabWidget * tbw = new QTabWidget(this);
   249     {
   279     {
   250         // remove old entry
   280         // remove old entry
   251         wconf->remove(curWeaponsName);
   281         wconf->remove(curWeaponsName);
   252     }
   282     }
   253     wconf->setValue(m_name->text(), stateFull);
   283     wconf->setValue(m_name->text(), stateFull);
       
   284     QFile file(cfgdir->absolutePath() + "/Weapon Settings/" + m_name->text()+ ".hww");
       
   285     if (file.open(QIODevice::WriteOnly)) {
       
   286         QTextStream stream( &file );
       
   287         stream << stateFull << endl;
       
   288     }
   254     emit weaponsEdited(curWeaponsName, m_name->text(), stateFull);
   289     emit weaponsEdited(curWeaponsName, m_name->text(), stateFull);
   255 }
   290 }
   256 
   291 
   257 int SelWeaponWidget::operator [] (unsigned int weaponIndex) const
   292 int SelWeaponWidget::operator [] (unsigned int weaponIndex) const
   258 {
   293 {
   291 
   326 
   292     if (reallyDeleteMsg.exec() == QMessageBox::Ok)
   327     if (reallyDeleteMsg.exec() == QMessageBox::Ok)
   293     {
   328     {
   294         isDeleting = true;
   329         isDeleting = true;
   295         wconf->remove(delWeaponsName);
   330         wconf->remove(delWeaponsName);
       
   331         QFile(cfgdir->absolutePath() + "/Weapon Settings/" + curWeaponsName + ".hww").remove();
   296         emit weaponsDeleted(delWeaponsName);
   332         emit weaponsDeleted(delWeaponsName);
   297     }
   333     }
   298 }
   334 }
   299 
   335 
   300 void SelWeaponWidget::newWeaponsName()
   336 void SelWeaponWidget::newWeaponsName()