QTfrontend/ui/widget/selectWeapon.cpp
branchsdl2transition
changeset 11342 ed5a6478e710
parent 11046 47a8c19ecb60
child 11768 59e979b1408f
equal deleted inserted replaced
11340:31570b766315 11342:ed5a6478e710
     1 /*
     1 /*
     2  * Hedgewars, a free turn based strategy game
     2  * Hedgewars, a free turn based strategy game
     3  * Copyright (c) 2006-2008 Igor Ulyanov <iulyanov@gmail.com>
     3  * Copyright (c) 2006-2008 Igor Ulyanov <iulyanov@gmail.com>
     4  * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com>
     4  * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
     5  *
     5  *
     6  * This program is free software; you can redistribute it and/or modify
     6  * This program is free software; you can redistribute it and/or modify
     7  * it under the terms of the GNU General Public License as published by
     7  * it under the terms of the GNU General Public License as published by
     8  * the Free Software Foundation; version 2 of the License
     8  * the Free Software Foundation; version 2 of the License
     9  *
     9  *
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  * GNU General Public License for more details.
    13  * GNU General Public License for more details.
    14  *
    14  *
    15  * You should have received a copy of the GNU General Public License
    15  * You should have received a copy of the GNU General Public License
    16  * along with this program; if not, write to the Free Software
    16  * along with this program; if not, write to the Free Software
    17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18  */
    18  */
    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"
    91 
    91 
    92     QStringList keys = wconf->allKeys();
    92     QStringList keys = wconf->allKeys();
    93     for(int i = 0; i < keys.size(); i++)
    93     for(int i = 0; i < keys.size(); i++)
    94     {
    94     {
    95         if (wconf->value(keys[i]).toString().size() != cDefaultAmmoStore->size())
    95         if (wconf->value(keys[i]).toString().size() != cDefaultAmmoStore->size())
    96             wconf->remove(keys[i]);
    96             wconf->setValue(keys[i], fixWeaponSet(wconf->value(keys[i]).toString()));
    97     }
    97     }
    98 
    98 
    99     QString currentState = *cDefaultAmmoStore;
    99     QString currentState = *cDefaultAmmoStore;
   100 
   100 
   101     QTabWidget * tbw = new QTabWidget(this);
   101     QTabWidget * tbw = new QTabWidget(this);
   320 void SelWeaponWidget::copy()
   320 void SelWeaponWidget::copy()
   321 {
   321 {
   322     if(wconf->contains(curWeaponsName))
   322     if(wconf->contains(curWeaponsName))
   323     {
   323     {
   324         QString ammo = getWeaponsString(curWeaponsName);
   324         QString ammo = getWeaponsString(curWeaponsName);
   325         QString newName = tr("copy of") + " " + curWeaponsName;
   325         QString newName = tr("copy of %1").arg(curWeaponsName);
   326         if(wconf->contains(newName))
   326         if(wconf->contains(newName))
   327         {
   327         {
   328             //name already used -> look for an appropriate name:
   328             //name already used -> look for an appropriate name:
   329             int i=2;
   329             int i=2;
   330             while(wconf->contains(newName = tr("copy of") + " " + curWeaponsName+QString::number(i++))) ;
   330             while(wconf->contains(newName = tr("copy of %1").arg(curWeaponsName+QString::number(i++))));
   331         }
   331         }
   332         setWeaponsName(newName);
   332         setWeaponsName(newName);
   333         setWeapons(ammo);
   333         setWeapons(ammo);
   334     }
   334     }
   335 }
   335 }
       
   336 
       
   337 QString SelWeaponWidget::fixWeaponSet(const QString &s)
       
   338 {
       
   339     int neededLength = cDefaultAmmoStore->size() / 4;
       
   340     int thisSetLength = s.size() / 4;
       
   341 
       
   342     QStringList sl;
       
   343     sl
       
   344             << s.left(thisSetLength)
       
   345             << s.mid(thisSetLength, thisSetLength)
       
   346             << s.mid(thisSetLength * 2, thisSetLength)
       
   347             << s.right(thisSetLength)
       
   348                ;
       
   349 
       
   350     for(int i = sl.length() - 1; i >= 0; --i)
       
   351         sl[i] = sl[i].leftJustified(neededLength, '0', true);
       
   352 
       
   353     return sl.join(QString());
       
   354 }