QTfrontend/gamecfgwidget.cpp
changeset 6101 5a4ea2c7b9df
parent 5801 531f64292489
parent 6100 e6426c6b2882
child 6102 97565ab4afe9
equal deleted inserted replaced
5801:531f64292489 6101:5a4ea2c7b9df
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2006-2011 Andrey Korotaev <unC0Rr@gmail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
       
    17  */
       
    18 
       
    19 #include <QResizeEvent>
       
    20 #include <QGroupBox>
       
    21 #include <QCheckBox>
       
    22 #include <QGridLayout>
       
    23 #include <QSpinBox>
       
    24 #include <QLabel>
       
    25 #include <QMessageBox>
       
    26 #include <QTableView>
       
    27 #include <QPushButton>
       
    28 
       
    29 #include "gamecfgwidget.h"
       
    30 #include "igbox.h"
       
    31 #include "hwconsts.h"
       
    32 #include "ammoSchemeModel.h"
       
    33 #include "proto.h"
       
    34 
       
    35 GameCFGWidget::GameCFGWidget(QWidget* parent) :
       
    36   QGroupBox(parent)
       
    37   , mainLayout(this)
       
    38   , seedRegexp("\\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\}")
       
    39 {
       
    40     mainLayout.setMargin(0);
       
    41 //  mainLayout.setSizeConstraint(QLayout::SetMinimumSize);
       
    42 
       
    43     pMapContainer = new HWMapContainer(this);
       
    44     mainLayout.addWidget(pMapContainer, 0, 0);
       
    45 
       
    46     IconedGroupBox *GBoxOptions = new IconedGroupBox(this);
       
    47     GBoxOptions->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
       
    48     mainLayout.addWidget(GBoxOptions, 1, 0);
       
    49 
       
    50     QGridLayout *GBoxOptionsLayout = new QGridLayout(GBoxOptions);
       
    51 
       
    52     QLabel *titleLabel = new QLabel(QLabel::tr("Game Options"), GBoxOptions);
       
    53     titleLabel->setMargin(7);    // TODO: make the text larger/richer!!!!
       
    54     GBoxOptionsLayout->addWidget(titleLabel, 0, 0, 1, 0, Qt::AlignHCenter);
       
    55     GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Style"), GBoxOptions), 1, 0);
       
    56 
       
    57     Scripts = new QComboBox(GBoxOptions);
       
    58     GBoxOptionsLayout->addWidget(Scripts, 1, 1);
       
    59 
       
    60     Scripts->addItem("Normal");
       
    61     Scripts->insertSeparator(1);
       
    62 
       
    63     for (int i = 0; i < scriptList->size(); ++i) {
       
    64         QString script = (*scriptList)[i].remove(".lua", Qt::CaseInsensitive);
       
    65         QList<QVariant> scriptInfo;
       
    66         scriptInfo.push_back(script);
       
    67         QFile scriptCfgFile;
       
    68         scriptCfgFile.setFileName(QString("%1/Data/Scripts/Multiplayer/%2.cfg").arg(cfgdir->absolutePath()).arg(script));
       
    69         if (!scriptCfgFile.exists()) scriptCfgFile.setFileName(QString("%1/Scripts/Multiplayer/%2.cfg").arg(datadir->absolutePath()).arg(script));
       
    70         if (scriptCfgFile.exists() && scriptCfgFile.open(QFile::ReadOnly)) {
       
    71             QString scheme;
       
    72             QString weapons;
       
    73             QTextStream input(&scriptCfgFile);
       
    74             input >> scheme;
       
    75             input >> weapons;
       
    76             if (scheme.isEmpty())
       
    77                 scheme = "locked";
       
    78             scheme.replace("_", " ");
       
    79             if (weapons.isEmpty())
       
    80                 weapons = "locked";
       
    81             weapons.replace("_", " ");
       
    82             scriptInfo.push_back(scheme);
       
    83             scriptInfo.push_back(weapons);
       
    84             scriptCfgFile.close();
       
    85         }
       
    86         else
       
    87         {
       
    88             scriptInfo.push_back("locked");
       
    89             scriptInfo.push_back("locked");
       
    90         }
       
    91         Scripts->addItem(script.replace("_", " "), scriptInfo);
       
    92     }
       
    93 
       
    94     connect(Scripts, SIGNAL(currentIndexChanged(int)), this, SLOT(scriptChanged(int)));
       
    95 
       
    96     QWidget *SchemeWidget = new QWidget(GBoxOptions);
       
    97     GBoxOptionsLayout->addWidget(SchemeWidget, 2, 0, 1, 2);
       
    98 
       
    99     QGridLayout *SchemeWidgetLayout = new QGridLayout(SchemeWidget);
       
   100     SchemeWidgetLayout->setMargin(0);
       
   101 
       
   102     GameSchemes = new QComboBox(SchemeWidget);
       
   103     SchemeWidgetLayout->addWidget(GameSchemes, 0, 2);
       
   104     connect(GameSchemes, SIGNAL(currentIndexChanged(int)), this, SLOT(schemeChanged(int)));
       
   105 
       
   106     SchemeWidgetLayout->addWidget(new QLabel(QLabel::tr("Scheme"), SchemeWidget), 0, 0);
       
   107 
       
   108     QPixmap pmEdit(":/res/edit.png");
       
   109     
       
   110     QPushButton * goToSchemePage = new QPushButton(SchemeWidget);
       
   111     goToSchemePage->setToolTip(tr("Edit schemes"));
       
   112     goToSchemePage->setIconSize(pmEdit.size());
       
   113     goToSchemePage->setIcon(pmEdit);
       
   114     goToSchemePage->setMaximumWidth(pmEdit.width() + 6);
       
   115     SchemeWidgetLayout->addWidget(goToSchemePage, 0, 3);
       
   116     connect(goToSchemePage, SIGNAL(clicked()), this, SLOT(jumpToSchemes()));
       
   117 
       
   118     SchemeWidgetLayout->addWidget(new QLabel(QLabel::tr("Weapons"), SchemeWidget), 1, 0);
       
   119 
       
   120     WeaponsName = new QComboBox(SchemeWidget);
       
   121     SchemeWidgetLayout->addWidget(WeaponsName, 1, 2);
       
   122 
       
   123     connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int)));
       
   124 
       
   125     QPushButton * goToWeaponPage = new QPushButton(SchemeWidget);
       
   126     goToWeaponPage->setToolTip(tr("Edit weapons"));
       
   127     goToWeaponPage->setIconSize(pmEdit.size());
       
   128     goToWeaponPage->setIcon(pmEdit);
       
   129     goToWeaponPage->setMaximumWidth(pmEdit.width() + 6);
       
   130     SchemeWidgetLayout->addWidget(goToWeaponPage, 1, 3);
       
   131     connect(goToWeaponPage, SIGNAL(clicked()), this, SLOT(jumpToWeapons()));
       
   132 
       
   133     bindEntries = new QCheckBox(SchemeWidget);
       
   134     bindEntries->setToolTip(tr("When this option is enabled selecting a game scheme will auto-select a weapon"));
       
   135     bindEntries->setChecked(true);
       
   136     bindEntries->setMaximumWidth(42);
       
   137     bindEntries->setStyleSheet( "QCheckBox::indicator:checked   { image: url(\":/res/lock.png\"); }"
       
   138                                 "QCheckBox::indicator:unchecked { image: url(\":/res/unlock.png\");   }" );
       
   139     SchemeWidgetLayout->addWidget(bindEntries, 0, 1, 0, 1, Qt::AlignVCenter);
       
   140 
       
   141     connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(seedChanged(const QString &)));
       
   142     connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SLOT(mapChanged(const QString &)));
       
   143     connect(pMapContainer, SIGNAL(mapgenChanged(MapGenerator)), this, SLOT(mapgenChanged(MapGenerator)));
       
   144     connect(pMapContainer, SIGNAL(mazeSizeChanged(int)), this, SLOT(maze_sizeChanged(int)));
       
   145     connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SLOT(themeChanged(const QString &)));
       
   146     connect(pMapContainer, SIGNAL(newTemplateFilter(int)), this, SLOT(templateFilterChanged(int)));
       
   147     connect(pMapContainer, SIGNAL(drawMapRequested()), this, SIGNAL(goToDrawMap()));
       
   148     connect(pMapContainer, SIGNAL(drawnMapChanged(const QByteArray &)), this, SLOT(onDrawnMapChanged(const QByteArray &)));
       
   149 }
       
   150 
       
   151 void GameCFGWidget::jumpToSchemes()
       
   152 {
       
   153     emit goToSchemes(GameSchemes->currentIndex());
       
   154 }
       
   155 
       
   156 void GameCFGWidget::jumpToWeapons()
       
   157 {
       
   158     emit goToWeapons(WeaponsName->currentIndex());
       
   159 }
       
   160 
       
   161 QVariant GameCFGWidget::schemeData(int column) const
       
   162 {
       
   163     return GameSchemes->model()->data(GameSchemes->model()->index(GameSchemes->currentIndex(), column));
       
   164 }
       
   165 
       
   166 quint32 GameCFGWidget::getGameFlags() const
       
   167 {
       
   168     quint32 result = 0;
       
   169 
       
   170     if (schemeData(1).toBool())
       
   171         result |= 0x00001000;       // fort
       
   172     if (schemeData(2).toBool())
       
   173         result |= 0x00000010;       // divide teams
       
   174     if (schemeData(3).toBool())
       
   175         result |= 0x00000004;       // solid land
       
   176     if (schemeData(4).toBool())
       
   177         result |= 0x00000008;       // border
       
   178     if (schemeData(5).toBool())
       
   179         result |= 0x00000020;       // low gravity
       
   180     if (schemeData(6).toBool())
       
   181         result |= 0x00000040;       // laser sight
       
   182     if (schemeData(7).toBool())
       
   183         result |= 0x00000080;       // invulnerable
       
   184     if (schemeData(8).toBool())
       
   185         result |= 0x00000100;       // mines
       
   186     if (schemeData(9).toBool())
       
   187         result |= 0x00000200;       // vampirism
       
   188     if (schemeData(10).toBool())
       
   189         result |= 0x00000400;       // karma
       
   190     if (schemeData(11).toBool())
       
   191         result |= 0x00000800;       // artillery
       
   192     if (schemeData(12).toBool())
       
   193         result |= 0x00002000;       // random
       
   194     if (schemeData(13).toBool())
       
   195         result |= 0x00004000;       // king
       
   196     if (schemeData(14).toBool())
       
   197         result |= 0x00008000;       // place hogs
       
   198     if (schemeData(15).toBool())
       
   199         result |= 0x00010000;       // shared ammo
       
   200     if (schemeData(16).toBool())
       
   201         result |= 0x00020000;       // disable girders
       
   202     if (schemeData(17).toBool())
       
   203         result |= 0x00040000;       // disable land obj
       
   204     if (schemeData(18).toBool())
       
   205         result |= 0x00080000;       // ai survival
       
   206     if (schemeData(19).toBool())
       
   207         result |= 0x00100000;       // infinite attacks
       
   208     if (schemeData(20).toBool())
       
   209         result |= 0x00200000;       // reset weaps
       
   210     if (schemeData(21).toBool())
       
   211         result |= 0x00400000;       // per hog ammo
       
   212     if (schemeData(22).toBool())
       
   213         result |= 0x00800000;       // no wind
       
   214     if (schemeData(23).toBool())
       
   215         result |= 0x01000000;       // more wind
       
   216     if (schemeData(24).toBool())
       
   217         result |= 0x02000000;       // tag team
       
   218     if (schemeData(25).toBool())
       
   219         result |= 0x04000000;       // bottom border
       
   220 
       
   221     return result;
       
   222 }
       
   223 
       
   224 quint32 GameCFGWidget::getInitHealth() const
       
   225 {
       
   226     return schemeData(28).toInt();
       
   227 }
       
   228 
       
   229 QByteArray GameCFGWidget::getFullConfig() const
       
   230 {
       
   231     QList<QByteArray> bcfg;
       
   232     int mapgen = pMapContainer->get_mapgen();
       
   233 
       
   234     QString currentMap = pMapContainer->getCurrentMap();
       
   235     if (currentMap.size() > 0)
       
   236     {
       
   237         bcfg << QString("emap " + currentMap).toUtf8();
       
   238         if(pMapContainer->getCurrentIsMission())
       
   239             bcfg << QString("escript Maps/%1/map.lua").arg(currentMap).toUtf8();
       
   240     }
       
   241     bcfg << QString("etheme " + pMapContainer->getCurrentTheme()).toUtf8();
       
   242 
       
   243     if (Scripts->currentIndex() > 0)
       
   244     {
       
   245         bcfg << QString("escript Scripts/Multiplayer/%1.lua").arg(Scripts->itemData(Scripts->currentIndex()).toList()[0].toString()).toUtf8();
       
   246     }
       
   247 
       
   248     bcfg << QString("eseed " + pMapContainer->getCurrentSeed()).toUtf8();
       
   249     bcfg << QString("e$gmflags %1").arg(getGameFlags()).toUtf8();
       
   250     bcfg << QString("e$damagepct %1").arg(schemeData(26).toInt()).toUtf8();
       
   251     bcfg << QString("e$turntime %1").arg(schemeData(27).toInt() * 1000).toUtf8();
       
   252     bcfg << QString("e$sd_turns %1").arg(schemeData(29).toInt()).toUtf8();
       
   253     bcfg << QString("e$casefreq %1").arg(schemeData(30).toInt()).toUtf8();
       
   254     bcfg << QString("e$minestime %1").arg(schemeData(31).toInt() * 1000).toUtf8();
       
   255     bcfg << QString("e$minesnum %1").arg(schemeData(32).toInt()).toUtf8();
       
   256     bcfg << QString("e$minedudpct %1").arg(schemeData(33).toInt()).toUtf8();
       
   257     bcfg << QString("e$explosives %1").arg(schemeData(34).toInt()).toUtf8();
       
   258     bcfg << QString("e$healthprob %1").arg(schemeData(35).toInt()).toUtf8();
       
   259     bcfg << QString("e$hcaseamount %1").arg(schemeData(36).toInt()).toUtf8();
       
   260     bcfg << QString("e$waterrise %1").arg(schemeData(37).toInt()).toUtf8();
       
   261     bcfg << QString("e$healthdec %1").arg(schemeData(38).toInt()).toUtf8();
       
   262     bcfg << QString("e$ropepct %1").arg(schemeData(39).toInt()).toUtf8();
       
   263     bcfg << QString("e$getawaytime %1").arg(schemeData(40).toInt()).toUtf8();
       
   264     bcfg << QString("e$template_filter %1").arg(pMapContainer->getTemplateFilter()).toUtf8();
       
   265     bcfg << QString("e$mapgen %1").arg(mapgen).toUtf8();
       
   266 
       
   267     switch (mapgen)
       
   268     {
       
   269         case MAPGEN_MAZE:
       
   270             bcfg << QString("e$maze_size %1").arg(pMapContainer->getMazeSize()).toUtf8();
       
   271             break;
       
   272 
       
   273         case MAPGEN_DRAWN:
       
   274         {
       
   275             QByteArray data = pMapContainer->getDrawnMapData();
       
   276             while(data.size() > 0)
       
   277             {
       
   278                 QByteArray tmp = data;
       
   279                 tmp.truncate(200);
       
   280                 tmp.prepend("edraw ");
       
   281                 bcfg << tmp;
       
   282                 data.remove(0, 200);
       
   283             }
       
   284             break;
       
   285         }
       
   286         default: ;
       
   287     }
       
   288 
       
   289     QByteArray result;
       
   290 
       
   291     foreach(QByteArray ba, bcfg)
       
   292         HWProto::addByteArrayToBuffer(result, ba);
       
   293 
       
   294     return result;
       
   295 }
       
   296 
       
   297 void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo)
       
   298 {
       
   299     bool illegal = ammo.size() != cDefaultAmmoStore->size();
       
   300     if (illegal)
       
   301         QMessageBox::critical(this, tr("Error"), tr("Illegal ammo scheme"));
       
   302 
       
   303     int pos = WeaponsName->findText(name);
       
   304     if ((pos == -1) || illegal) { // prevent from overriding schemes with bad ones
       
   305         WeaponsName->addItem(name, ammo);
       
   306         WeaponsName->setCurrentIndex(WeaponsName->count() - 1);
       
   307     } else {
       
   308         WeaponsName->setItemData(pos, ammo);
       
   309         WeaponsName->setCurrentIndex(pos);
       
   310     }
       
   311 }
       
   312 
       
   313 void GameCFGWidget::fullNetConfig()
       
   314 {
       
   315     ammoChanged(WeaponsName->currentIndex());
       
   316 
       
   317     seedChanged(pMapContainer->getCurrentSeed());
       
   318     templateFilterChanged(pMapContainer->getTemplateFilter());
       
   319     themeChanged(pMapContainer->getCurrentTheme());
       
   320 
       
   321     schemeChanged(GameSchemes->currentIndex());
       
   322     scriptChanged(Scripts->currentIndex());
       
   323 
       
   324     mapgenChanged(pMapContainer->get_mapgen());
       
   325     maze_sizeChanged(pMapContainer->getMazeSize());
       
   326 
       
   327     // map must be the last
       
   328     QString map = pMapContainer->getCurrentMap();
       
   329     if (map.size())
       
   330         mapChanged(map);
       
   331 }
       
   332 
       
   333 void GameCFGWidget::setParam(const QString & param, const QStringList & slValue)
       
   334 {
       
   335     if (slValue.size() == 1)
       
   336     {
       
   337         QString value = slValue[0];
       
   338         if (param == "MAP") {
       
   339             pMapContainer->setMap(value);
       
   340             return;
       
   341         }
       
   342         if (param == "SEED") {
       
   343             pMapContainer->setSeed(value);
       
   344             if (!seedRegexp.exactMatch(value)) {
       
   345                 pMapContainer->seedEdit->setVisible(true);
       
   346                 }
       
   347             return;
       
   348         }
       
   349         if (param == "THEME") {
       
   350             pMapContainer->setTheme(value);
       
   351             return;
       
   352         }
       
   353         if (param == "TEMPLATE") {
       
   354             pMapContainer->setTemplateFilter(value.toUInt());
       
   355             return;
       
   356         }
       
   357         if (param == "MAPGEN") {
       
   358             pMapContainer->setMapgen((MapGenerator)value.toUInt());
       
   359             return;
       
   360         }
       
   361         if (param == "MAZE_SIZE") {
       
   362             pMapContainer->setMazeSize(value.toUInt());
       
   363             return;
       
   364         }
       
   365         if (param == "SCRIPT") {
       
   366             Scripts->setCurrentIndex(Scripts->findText(value));
       
   367             return;
       
   368         }
       
   369         if (param == "DRAWNMAP") {
       
   370             pMapContainer->setDrawnMapData(qUncompress(QByteArray::fromBase64(slValue[0].toLatin1())));
       
   371             return;
       
   372         }
       
   373     }
       
   374 
       
   375     if (slValue.size() == 2)
       
   376     {
       
   377         if (param == "AMMO") {
       
   378             setNetAmmo(slValue[0], slValue[1]);
       
   379             return;
       
   380         }
       
   381     }
       
   382 
       
   383     if (slValue.size() == 5)
       
   384     {
       
   385         if (param == "FULLMAPCONFIG")
       
   386         {
       
   387             QString seed = slValue[3];
       
   388             if (!seedRegexp.exactMatch(seed))
       
   389                 pMapContainer->seedEdit->setVisible(true);
       
   390 
       
   391             pMapContainer->setAllMapParameters(
       
   392                     slValue[0],
       
   393                     (MapGenerator)slValue[1].toUInt(),
       
   394                     slValue[2].toUInt(),
       
   395                     seed,
       
   396                     slValue[4].toUInt()
       
   397                     );
       
   398             return;
       
   399         }
       
   400     }
       
   401 
       
   402     qWarning("Got bad config param from net");
       
   403 }
       
   404 
       
   405 void GameCFGWidget::ammoChanged(int index)
       
   406 {
       
   407     if (index >= 0) {
       
   408         emit paramChanged(
       
   409             "AMMO",
       
   410             QStringList() << WeaponsName->itemText(index) << WeaponsName->itemData(index).toString()
       
   411         );
       
   412     }
       
   413 }
       
   414 
       
   415 void GameCFGWidget::mapChanged(const QString & value)
       
   416 {
       
   417     if(isEnabled() && pMapContainer->getCurrentIsMission())
       
   418     {
       
   419         Scripts->setEnabled(false);
       
   420         Scripts->setCurrentIndex(0);
       
   421 
       
   422         if (pMapContainer->getCurrentScheme() == "locked")
       
   423         {
       
   424             GameSchemes->setEnabled(false);
       
   425             GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
       
   426         }
       
   427         else
       
   428         {
       
   429             GameSchemes->setEnabled(true);
       
   430             int num = GameSchemes->findText(pMapContainer->getCurrentScheme());
       
   431             if (num != -1)
       
   432                 GameSchemes->setCurrentIndex(num);
       
   433             else
       
   434                 GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
       
   435         }
       
   436 
       
   437         if (pMapContainer->getCurrentWeapons() == "locked")
       
   438         {
       
   439             WeaponsName->setEnabled(false);
       
   440             WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
       
   441         }
       
   442         else
       
   443         {
       
   444             WeaponsName->setEnabled(true);
       
   445             int num = WeaponsName->findText(pMapContainer->getCurrentWeapons());
       
   446             if (num != -1)
       
   447                 WeaponsName->setCurrentIndex(num);
       
   448             else
       
   449                 WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
       
   450         }
       
   451 
       
   452         if (pMapContainer->getCurrentScheme() != "locked" && pMapContainer->getCurrentWeapons() != "locked")
       
   453             bindEntries->setEnabled(true);
       
   454         else
       
   455             bindEntries->setEnabled(false);
       
   456     }
       
   457     else
       
   458     {
       
   459         Scripts->setEnabled(true);
       
   460         GameSchemes->setEnabled(true);
       
   461         WeaponsName->setEnabled(true);
       
   462         bindEntries->setEnabled(true);
       
   463     }
       
   464     emit paramChanged("MAP", QStringList(value));
       
   465 }
       
   466 
       
   467 void GameCFGWidget::templateFilterChanged(int value)
       
   468 {
       
   469     emit paramChanged("TEMPLATE", QStringList(QString::number(value)));
       
   470 }
       
   471 
       
   472 void GameCFGWidget::seedChanged(const QString & value)
       
   473 {
       
   474     emit paramChanged("SEED", QStringList(value));
       
   475 }
       
   476 
       
   477 void GameCFGWidget::themeChanged(const QString & value)
       
   478 {
       
   479     emit paramChanged("THEME", QStringList(value));
       
   480 }
       
   481 
       
   482 void GameCFGWidget::schemeChanged(int index)
       
   483 {
       
   484     QStringList sl;
       
   485 
       
   486     int size = GameSchemes->model()->columnCount();
       
   487     for(int i = 0; i < size; ++i)
       
   488         sl << schemeData(i).toString();
       
   489 
       
   490     emit paramChanged("SCHEME", sl);
       
   491 
       
   492     if (isEnabled() && bindEntries->isEnabled() && bindEntries->isChecked()) {
       
   493         QString schemeName = GameSchemes->itemText(index);
       
   494         for (int i = 0; i < WeaponsName->count(); i++) {
       
   495              QString weapName = WeaponsName->itemText(i);
       
   496              int res = QString::compare(weapName, schemeName, Qt::CaseSensitive);
       
   497              if (0 == res) {
       
   498                  WeaponsName->setCurrentIndex(i);
       
   499                  emit ammoChanged(i);
       
   500                  break;
       
   501              }
       
   502         }
       
   503     }
       
   504 }
       
   505 
       
   506 void GameCFGWidget::scriptChanged(int index)
       
   507 {
       
   508     if(isEnabled() && index > 0)
       
   509     {
       
   510         QString scheme = Scripts->itemData(Scripts->currentIndex()).toList()[1].toString();
       
   511         QString weapons = Scripts->itemData(Scripts->currentIndex()).toList()[2].toString();
       
   512 
       
   513         if (scheme == "locked")
       
   514         {
       
   515             GameSchemes->setEnabled(false);
       
   516             GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
       
   517         }
       
   518         else
       
   519         {
       
   520             GameSchemes->setEnabled(true);
       
   521             int num = GameSchemes->findText(scheme);
       
   522             if (num != -1)
       
   523                 GameSchemes->setCurrentIndex(num);
       
   524             else
       
   525                 GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
       
   526         }
       
   527 
       
   528         if (weapons == "locked")
       
   529         {
       
   530             WeaponsName->setEnabled(false);
       
   531             WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
       
   532         }
       
   533         else
       
   534         {
       
   535             WeaponsName->setEnabled(true);
       
   536             int num = WeaponsName->findText(weapons);
       
   537             if (num != -1)
       
   538                 WeaponsName->setCurrentIndex(num);
       
   539             else
       
   540                 WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
       
   541         }
       
   542 
       
   543         if (scheme != "locked" && weapons != "locked")
       
   544             bindEntries->setEnabled(true);
       
   545         else
       
   546             bindEntries->setEnabled(false);
       
   547     }
       
   548     else
       
   549     {
       
   550         GameSchemes->setEnabled(true);
       
   551         WeaponsName->setEnabled(true);
       
   552         bindEntries->setEnabled(true);
       
   553     }
       
   554     emit paramChanged("SCRIPT", QStringList(Scripts->itemText(index)));
       
   555 }
       
   556 
       
   557 void GameCFGWidget::mapgenChanged(MapGenerator m)
       
   558 {
       
   559     emit paramChanged("MAPGEN", QStringList(QString::number(m)));
       
   560 }
       
   561 
       
   562 void GameCFGWidget::maze_sizeChanged(int s)
       
   563 {
       
   564     emit paramChanged("MAZE_SIZE", QStringList(QString::number(s)));
       
   565 }
       
   566 
       
   567 void GameCFGWidget::resendSchemeData()
       
   568 {
       
   569     schemeChanged(GameSchemes->currentIndex());
       
   570 }
       
   571 
       
   572 void GameCFGWidget::onDrawnMapChanged(const QByteArray & data)
       
   573 {
       
   574     emit paramChanged("DRAWNMAP", QStringList(qCompress(data, 9).toBase64()));
       
   575 }