QTfrontend/gamecfgwidget.cpp
changeset 4513 1dd97c710f5a
parent 4511 df827e70ae63
child 4525 0a81be113e21
--- a/QTfrontend/gamecfgwidget.cpp	Mon Dec 13 01:24:06 2010 +0100
+++ b/QTfrontend/gamecfgwidget.cpp	Mon Dec 13 04:52:23 2010 +0100
@@ -47,46 +47,90 @@
 
     QGridLayout *GBoxOptionsLayout = new QGridLayout(GBoxOptions);
 
-    GameSchemes = new QComboBox(GBoxOptions);
-    GBoxOptionsLayout->addWidget(GameSchemes, 0, 2);
+    GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Gameplay"), GBoxOptions), 0, 0);
+
+    Scripts = new QComboBox(GBoxOptions);
+    GBoxOptionsLayout->addWidget(Scripts, 0, 1);
+
+    Scripts->addItem(QComboBox::tr("Normal"));
+    Scripts->insertSeparator(1);
+
+    for (int i = 0; i < scriptList->size(); ++i) {
+        QString script = (*scriptList)[i].remove(".lua", Qt::CaseInsensitive);
+        QList<QVariant> scriptInfo;
+        QFile scriptCfgFile(QString("%1/Scripts/Multiplayer/%2.cfg").arg(datadir->absolutePath()).arg(script));
+        if (scriptCfgFile.exists() && scriptCfgFile.open(QFile::ReadOnly)) {
+            QString scheme;
+            QString weapons;
+            QTextStream input(&scriptCfgFile);
+            input >> scheme;
+            input >> weapons;
+            if (scheme.isEmpty())
+                scheme = "locked";
+            scheme.replace("_", " ");
+            if (weapons.isEmpty())
+                weapons = "locked";
+            weapons.replace("_", " ");
+            scriptInfo.push_back(scheme);
+            scriptInfo.push_back(weapons);
+            scriptCfgFile.close();
+        }
+        else
+        {
+            scriptInfo.push_back("locked");
+            scriptInfo.push_back("locked");
+        }
+        Scripts->addItem(script, scriptInfo);
+    }
+
+    connect(Scripts, SIGNAL(currentIndexChanged(int)), this, SLOT(scriptChanged(int)));
+
+    QWidget *SchemeWidget = new QWidget(GBoxOptions);
+    GBoxOptionsLayout->addWidget(SchemeWidget, 1, 0, 1, 2);
+
+    QGridLayout *SchemeWidgetLayout = new QGridLayout(SchemeWidget);
+    SchemeWidgetLayout->setMargin(0);
+
+    GameSchemes = new QComboBox(SchemeWidget);
+    SchemeWidgetLayout->addWidget(GameSchemes, 0, 2);
     connect(GameSchemes, SIGNAL(currentIndexChanged(int)), this, SLOT(schemeChanged(int)));
 
-    GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Game scheme"), GBoxOptions), 0, 0);
+    SchemeWidgetLayout->addWidget(new QLabel(QLabel::tr("Game scheme"), SchemeWidget), 0, 0);
 
     QPixmap pmEdit(":/res/edit.png");
     
-    QPushButton * goToSchemePage = new QPushButton(GBoxOptions);
+    QPushButton * goToSchemePage = new QPushButton(SchemeWidget);
     goToSchemePage->setToolTip(tr("Edit schemes"));
     goToSchemePage->setIconSize(pmEdit.size());
     goToSchemePage->setIcon(pmEdit);
     goToSchemePage->setMaximumWidth(pmEdit.width() + 6);
-    GBoxOptionsLayout->addWidget(goToSchemePage, 0, 3);
+    SchemeWidgetLayout->addWidget(goToSchemePage, 0, 3);
     connect(goToSchemePage, SIGNAL(clicked()), this, SLOT(jumpToSchemes()));
 
-    GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Weapons"), GBoxOptions), 1, 0);
+    SchemeWidgetLayout->addWidget(new QLabel(QLabel::tr("Weapons"), SchemeWidget), 1, 0);
 
-    WeaponsName = new QComboBox(GBoxOptions);
-    GBoxOptionsLayout->addWidget(WeaponsName, 1, 2);
+    WeaponsName = new QComboBox(SchemeWidget);
+    SchemeWidgetLayout->addWidget(WeaponsName, 1, 2);
 
     connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int)));
 
-    QPushButton * goToWeaponPage = new QPushButton(GBoxOptions);
+    QPushButton * goToWeaponPage = new QPushButton(SchemeWidget);
     goToWeaponPage->setToolTip(tr("Edit weapons"));
     goToWeaponPage->setIconSize(pmEdit.size());
     goToWeaponPage->setIcon(pmEdit);
     goToWeaponPage->setMaximumWidth(pmEdit.width() + 6);
-    GBoxOptionsLayout->addWidget(goToWeaponPage, 1, 3);
+    SchemeWidgetLayout->addWidget(goToWeaponPage, 1, 3);
     connect(goToWeaponPage, SIGNAL(clicked()), this, SLOT(jumpToWeapons()));
 
     //GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Bind schemes with weapons"), GBoxOptions), 2, 0);
 
-    bindEntries = new QCheckBox(GBoxOptions);
+    bindEntries = new QCheckBox(SchemeWidget);
     bindEntries->setToolTip(tr("When this option is enabled selecting a game scheme will auto-select a weapon"));
     bindEntries->setChecked(true);
     bindEntries->setMaximumWidth(42);
     bindEntries->setStyleSheet( "QCheckBox::indicator:checked   { image: url(\":/res/lock.png\"); }"
                                 "QCheckBox::indicator:unchecked { image: url(\":/res/unlock.png\");   }" );
-    GBoxOptionsLayout->addWidget(bindEntries, 0, 1, 0, 1, Qt::AlignVCenter);
+    SchemeWidgetLayout->addWidget(bindEntries, 0, 1, 0, 1, Qt::AlignVCenter);
     //GBoxOptionsLayout->addWidget(bindEntries, 2, 2);
 
     connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(seedChanged(const QString &)));
@@ -224,6 +268,11 @@
     }
     bcfg << QString("etheme " + pMapContainer->getCurrentTheme()).toUtf8();
 
+    if (Scripts->currentIndex() > 0)
+    {
+        bcfg << QString("escript Scripts/Multiplayer/%1.lua").arg(Scripts->currentText()).toUtf8();
+    }
+
     QByteArray result;
 
     foreach(QByteArray ba, bcfg)
@@ -257,6 +306,7 @@
     themeChanged(pMapContainer->getCurrentTheme());
 
     schemeChanged(GameSchemes->currentIndex());
+    scriptChanged(Scripts->currentIndex());
 
     mapgenChanged(pMapContainer->get_mapgen());
     maze_sizeChanged(pMapContainer->get_maze_size());
@@ -296,6 +346,10 @@
             pMapContainer->setMaze_size(value.toUInt());
             return;
         }
+        if (param == "SCRIPT") {
+            Scripts->setCurrentIndex(Scripts->findText(value));
+            return;
+        }
     }
 
     if (slValue.size() == 2)
@@ -323,14 +377,47 @@
 {
     if(pMapContainer->getCurrentIsMission())
     {
-        GameSchemes->setEnabled(false);
-        WeaponsName->setEnabled(false);
-        bindEntries->setEnabled(false);
-        GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
-        WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
+        Scripts->setEnabled(false);
+        Scripts->setCurrentIndex(0);
+
+        if (pMapContainer->getCurrentScheme() == "locked")
+        {
+            GameSchemes->setEnabled(false);
+            GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
+        }
+        else
+        {
+            GameSchemes->setEnabled(true);
+            int num = GameSchemes->findText(pMapContainer->getCurrentScheme());
+            if (num != -1)
+                GameSchemes->setCurrentIndex(num);
+            else
+                GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
+        }
+
+        if (pMapContainer->getCurrentWeapons() == "locked")
+        {
+            WeaponsName->setEnabled(false);
+            WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
+        }
+        else
+        {
+            WeaponsName->setEnabled(true);
+            int num = WeaponsName->findText(pMapContainer->getCurrentWeapons());
+            if (num != -1)
+                WeaponsName->setCurrentIndex(num);
+            else
+                WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
+        }
+
+        if (pMapContainer->getCurrentScheme() != "locked" && pMapContainer->getCurrentWeapons() != "locked")
+            bindEntries->setEnabled(true);
+        else
+            bindEntries->setEnabled(false);
     }
     else
     {
+        Scripts->setEnabled(true);
         GameSchemes->setEnabled(true);
         WeaponsName->setEnabled(true);
         bindEntries->setEnabled(true);
@@ -363,7 +450,7 @@
 
     emit paramChanged("SCHEME", sl);
 
-    if (bindEntries->isChecked() == true) {
+    if (bindEntries->isEnabled() && bindEntries->isChecked()) {
         QString schemeName = GameSchemes->itemText(index);
         for (int i = 0; i < WeaponsName->count(); i++) {
              QString weapName = WeaponsName->itemText(i);
@@ -377,6 +464,57 @@
     }
 }
 
+void GameCFGWidget::scriptChanged(int index)
+{
+    if(index > 0)
+    {
+        QString scheme = Scripts->itemData(Scripts->currentIndex()).toList()[0].toString();
+        QString weapons = Scripts->itemData(Scripts->currentIndex()).toList()[1].toString();
+
+        if (scheme == "locked")
+        {
+            GameSchemes->setEnabled(false);
+            GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
+        }
+        else
+        {
+            GameSchemes->setEnabled(true);
+            int num = GameSchemes->findText(scheme);
+            if (num != -1)
+                GameSchemes->setCurrentIndex(num);
+            else
+                GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
+        }
+
+        if (weapons == "locked")
+        {
+            WeaponsName->setEnabled(false);
+            WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
+        }
+        else
+        {
+            WeaponsName->setEnabled(true);
+            int num = WeaponsName->findText(weapons);
+            if (num != -1)
+                WeaponsName->setCurrentIndex(num);
+            else
+                WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
+        }
+
+        if (scheme != "locked" && weapons != "locked")
+            bindEntries->setEnabled(true);
+        else
+            bindEntries->setEnabled(false);
+    }
+    else
+    {
+        GameSchemes->setEnabled(true);
+        WeaponsName->setEnabled(true);
+        bindEntries->setEnabled(true);
+    }
+    emit paramChanged("SCRIPT", QStringList(Scripts->itemText(index)));
+}
+
 void GameCFGWidget::mapgenChanged(MapGenerator m)
 {
     emit paramChanged("MAPGEN", QStringList(QString::number(m)));