QTfrontend/gamecfgwidget.cpp
changeset 4237 ef9b201c97fe
parent 4225 ce9e2b05e9c1
child 4248 e127b3d26248
child 4324 43e3f1eeceb5
--- a/QTfrontend/gamecfgwidget.cpp	Wed Nov 10 19:43:13 2010 +0100
+++ b/QTfrontend/gamecfgwidget.cpp	Thu Nov 11 00:38:12 2010 +0100
@@ -78,6 +78,13 @@
 
     connect(goToWeaponPage, SIGNAL(clicked()), this, SLOT(jumpToWeapons()));
 
+    GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Bind schemes and weapons"), GBoxOptions), 2, 0);
+
+    bindEntries = new QCheckBox(GBoxOptions);
+    bindEntries->setToolTip(tr("When this option is enabled selecting a game scheme will auto-select a weapon (and viceversa)"));
+    bindEntries->setChecked(true);
+    GBoxOptionsLayout->addWidget(bindEntries, 2, 2);
+
     connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(seedChanged(const QString &)));
     connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SLOT(mapChanged(const QString &)));
     connect(pMapContainer, SIGNAL(mapgenChanged(MapGenerator)), this, SLOT(mapgenChanged(MapGenerator)));
@@ -263,11 +270,23 @@
 
 void GameCFGWidget::ammoChanged(int index)
 {
-    if (index >= 0)
+    if (index >= 0) {
         emit paramChanged(
             "AMMO",
             QStringList() << WeaponsName->itemText(index) << WeaponsName->itemData(index).toString()
         );
+        if (bindEntries->isChecked() == true) {
+            QString weapName = WeaponsName->itemText(index);
+            for (int i = 0; i < GameSchemes->count(); i++) {
+                 QString schemeName = GameSchemes->itemText(i);
+                 int res = QString::compare(weapName, schemeName, Qt::CaseSensitive);
+                 if (0 == res) {
+                     GameSchemes->setCurrentIndex(i);
+                     break;
+                 }
+            }
+        }
+    }
 }
 
 void GameCFGWidget::mapChanged(const QString & value)
@@ -276,6 +295,7 @@
     {
         GameSchemes->setEnabled(false);
         WeaponsName->setEnabled(false);
+        bindEntries->setEnabled(false);
         GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
         WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
     }
@@ -283,6 +303,7 @@
     {
         GameSchemes->setEnabled(true);
         WeaponsName->setEnabled(true);
+        bindEntries->setEnabled(true);
     }
     emit paramChanged("MAP", QStringList(value));
 }
@@ -302,7 +323,7 @@
     emit paramChanged("THEME", QStringList(value));
 }
 
-void GameCFGWidget::schemeChanged(int value)
+void GameCFGWidget::schemeChanged(int index)
 {
     QStringList sl;
 
@@ -311,6 +332,18 @@
         sl << schemeData(i).toString();
 
     emit paramChanged("SCHEME", sl);
+
+    if (bindEntries->isChecked() == true) {
+        QString schemeName = GameSchemes->itemText(index);
+        for (int i = 0; i < WeaponsName->count(); i++) {
+             QString weapName = WeaponsName->itemText(i);
+             int res = QString::compare(weapName, schemeName, Qt::CaseSensitive);
+             if (0 == res) {
+                 WeaponsName->setCurrentIndex(i);
+                 break;
+             }
+        }
+    }
 }
 
 void GameCFGWidget::mapgenChanged(MapGenerator m)