Author: sveinung
Date: Tue Oct 18 14:09:52 2016
New Revision: 34164

URL: http://svn.gna.org/viewcvs/freeciv?rev=34164&view=rev
Log:
ruledit enabler type change: add obligatory.

Modify an action enabler's requirements on action type change to make them
satisfy the new action's obligatory hard requirements.

Confirmation dialog wording allows action_enabler_obligatory_reqs_add() to
start removing conflicting requirements.

See patch #7822

Modified:
    trunk/tools/ruledit/tab_enablers.cpp

Modified: trunk/tools/ruledit/tab_enablers.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/tab_enablers.cpp?rev=34164&r1=34163&r2=34164&view=diff
==============================================================================
--- trunk/tools/ruledit/tab_enablers.cpp        (original)
+++ trunk/tools/ruledit/tab_enablers.cpp        Tue Oct 18 14:09:52 2016
@@ -20,6 +20,7 @@
 #include <QLineEdit>
 #include <QListWidget>
 #include <QMenu>
+#include <QMessageBox>
 #include <QPushButton>
 #include <QRadioButton>
 #include <QToolButton>
@@ -227,11 +228,42 @@
   paction = action_by_rule_name(action->text().toUtf8().data());
 
   if (selected != nullptr && paction != nullptr) {
+    /* Store the old action so it can be changed back. */
+    const enum gen_action old_action = selected->action;
+
+    /* Handle the new action's hard obligatory requirements. */
+    selected->action = paction->id;
+    if (action_enabler_obligatory_reqs_missing(selected)) {
+      /* At least one hard obligatory requirement is missing. */
+
+      QMessageBox *box = new QMessageBox();
+
+      box->setWindowTitle(_("Obligatory hard requirements"));
+
+      box->setText(
+            QString(_("Changing action to %1 will modify enabler "
+                      "requirements. Continue?"))
+                   .arg(action_name_translation(paction)));
+      box->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+      box->exec();
+
+      if (box->result() == QMessageBox::Yes) {
+        /* Add obligatory requirements. */
+        action_enabler_obligatory_reqs_add(selected);
+      } else {
+        /* The user don't want to add the requirements. Cancel. */
+        selected->action = old_action;
+        return;
+      }
+    }
+
     /* Must remove and add back because enablers are stored by action. */
+    selected->action = old_action;
     action_enabler_remove(selected);
     selected->action = paction->id;
     action_enabler_add(selected);
 
+    /* Show the changes. */
     update_enabler_info(selected);
     refresh();
   }


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to