Fix force-locked schemes getting unlocked when changing map types (bug 378)
authorWuzzy <Wuzzy2@mail.ru>
Thu, 03 Jan 2019 17:57:31 +0100
changeset 14518 5230c063214a
parent 14517 3b6976beb58b
child 14519 5ac181cb2396
Fix force-locked schemes getting unlocked when changing map types (bug #378)
ChangeLog.txt
QTfrontend/ui/widget/gamecfgwidget.cpp
QTfrontend/ui/widget/gamecfgwidget.h
--- a/ChangeLog.txt	Wed Jan 02 17:45:12 2019 +0100
+++ b/ChangeLog.txt	Thu Jan 03 17:57:31 2019 +0100
@@ -18,6 +18,7 @@
  * Fix poison damage not working in first round
  * Hide most HUD elements in cinematic mode
  * Don't show "F1", "F2", etc. in ammo menu if these aren't the actual slot keys
+ * Fix force-locked schemes getting unlocked when changing map types
 
 Lua API:
  + New call: SaveMissionVar(varname, value): Save value to mission variable (variable for non-campaign mission)
--- a/QTfrontend/ui/widget/gamecfgwidget.cpp	Wed Jan 02 17:45:12 2019 +0100
+++ b/QTfrontend/ui/widget/gamecfgwidget.cpp	Thu Jan 03 17:57:31 2019 +0100
@@ -545,6 +545,60 @@
     }
 }
 
+void GameCFGWidget::updateSchemeEnabledStates(int scriptIndex)
+{
+    QString scheme;
+    QString weapons;
+    if(scriptIndex > 0)
+    {
+        scheme = Scripts->itemData(scriptIndex, GameStyleModel::SchemeRole).toString();
+        weapons = Scripts->itemData(scriptIndex, GameStyleModel::WeaponsRole).toString();
+    }
+    else
+    {
+        scheme = pMapContainer->getCurrentScheme();
+        weapons = pMapContainer->getCurrentWeapons();
+    }
+    if (scheme == "locked")
+    {
+        GameSchemes->setEnabled(false);
+        goToSchemePage->setEnabled(false);
+        lblScheme->setEnabled(false);
+        GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
+    }
+    else if(m_master)
+    {
+        GameSchemes->setEnabled(true);
+        goToSchemePage->setEnabled(true);
+        lblScheme->setEnabled(true);
+        int num = GameSchemes->findText(scheme);
+        if (num != -1)
+            GameSchemes->setCurrentIndex(num);
+    }
+
+    if (weapons == "locked")
+    {
+        WeaponsName->setEnabled(false);
+        goToWeaponPage->setEnabled(false);
+        lblWeapons->setEnabled(false);
+        WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
+    }
+    else if(m_master)
+    {
+        WeaponsName->setEnabled(true);
+        goToWeaponPage->setEnabled(true);
+        lblWeapons->setEnabled(true);
+        int num = WeaponsName->findText(weapons);
+        if (num != -1)
+            WeaponsName->setCurrentIndex(num);
+    }
+
+    if (scheme != "locked" && weapons != "locked")
+        bindEntries->setEnabled(true);
+    else
+        bindEntries->setEnabled(false);
+}
+
 void GameCFGWidget::mapChanged(const QString & value)
 {
     if(isEnabled() && pMapContainer->getCurrentIsMission())
@@ -552,49 +606,7 @@
         Scripts->setEnabled(false);
         lblScript->setEnabled(false);
         Scripts->setCurrentIndex(0);
-
-        if (pMapContainer->getCurrentScheme() == "locked")
-        {
-            GameSchemes->setEnabled(false);
-            goToSchemePage->setEnabled(false);
-            lblScheme->setEnabled(false);
-            GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
-        }
-        else
-        {
-            GameSchemes->setEnabled(true);
-            goToSchemePage->setEnabled(true);
-            lblScheme->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);
-            goToWeaponPage->setEnabled(false);
-            lblWeapons->setEnabled(false);
-            WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
-        }
-        else
-        {
-            WeaponsName->setEnabled(true);
-            goToWeaponPage->setEnabled(true);
-            lblWeapons->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);
+        updateSchemeEnabledStates(0);
     }
     else
     {
@@ -671,51 +683,7 @@
 
     if(isEnabled() && index > 0)
     {
-        QString scheme = Scripts->itemData(index, GameStyleModel::SchemeRole).toString();
-        QString weapons = Scripts->itemData(index, GameStyleModel::WeaponsRole).toString();
-
-        if (scheme == "locked")
-        {
-            GameSchemes->setEnabled(false);
-            goToSchemePage->setEnabled(false);
-            lblScheme->setEnabled(false);
-            GameSchemes->setCurrentIndex(GameSchemes->findText("Default"));
-        }
-        else if (m_master)
-        {
-            GameSchemes->setEnabled(true);
-            goToSchemePage->setEnabled(true);
-            lblScheme->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);
-            goToWeaponPage->setEnabled(false);
-            lblWeapons->setEnabled(false);
-            WeaponsName->setCurrentIndex(WeaponsName->findText("Default"));
-        }
-        else if (m_master)
-        {
-            WeaponsName->setEnabled(true);
-            goToWeaponPage->setEnabled(true);
-            lblWeapons->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);
+        updateSchemeEnabledStates(index);
     }
     else
     {
@@ -744,6 +712,8 @@
 
 void GameCFGWidget::mapgenChanged(MapGenerator m)
 {
+    int scriptIndex = Scripts->currentIndex();
+    updateSchemeEnabledStates(scriptIndex);
     emit paramChanged("MAPGEN", QStringList(QString::number(m)));
 }
 
--- a/QTfrontend/ui/widget/gamecfgwidget.h	Wed Jan 02 17:45:12 2019 +0100
+++ b/QTfrontend/ui/widget/gamecfgwidget.h	Thu Jan 03 17:57:31 2019 +0100
@@ -81,6 +81,7 @@
         void jumpToSchemes();
         void jumpToWeapons();
         void mapgenChanged(MapGenerator m);
+        void updateSchemeEnabledStates(int scriptIndex);
         void maze_sizeChanged(int s);
         void slMapFeatureSizeChanged(int s);
         void onDrawnMapChanged(const QByteArray & data);