Author: cazfi
Date: Sat Aug 13 18:14:53 2016
New Revision: 33589

URL: http://svn.gna.org/viewcvs/freeciv?rev=33589&view=rev
Log:
Made it possible to edit requirement value, if requirement kind is "tech"

See patch #7592

Modified:
    trunk/tools/ruledit/req_edit.cpp
    trunk/tools/ruledit/req_edit.h
    trunk/tools/ruledit/univ_value.c
    trunk/tools/ruledit/univ_value.h

Modified: trunk/tools/ruledit/req_edit.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/req_edit.cpp?rev=33589&r1=33588&r2=33589&view=diff
==============================================================================
--- trunk/tools/ruledit/req_edit.cpp    (original)
+++ trunk/tools/ruledit/req_edit.cpp    Sat Aug 13 18:14:53 2016
@@ -18,6 +18,7 @@
 // Qt
 #include <QGridLayout>
 #include <QLabel>
+#include <QLineEdit>
 #include <QMenu>
 #include <QPushButton>
 
@@ -75,8 +76,23 @@
   } universals_iterate_end;
   active_layout->addWidget(edit_type_button, 1, 0);
 
+  lbl = new QLabel(R__("Value:"));
+  active_layout->addWidget(lbl, 2, 0);
+  edit_value_enum_button = new QToolButton();
+  edit_value_enum_menu = new QMenu();
+  edit_value_enum_button->setToolButtonStyle(Qt::ToolButtonTextOnly);
+  edit_value_enum_button->setPopupMode(QToolButton::MenuButtonPopup);
+  connect(edit_value_enum_menu, SIGNAL(triggered(QAction *)),
+          this, SLOT(univ_value_enum_menu(QAction *)));
+  edit_value_enum_button->setMenu(edit_value_enum_menu);
+  edit_value_enum_menu->setVisible(false);
+  active_layout->addWidget(edit_value_enum_button, 3, 0);
+  edit_value_nbr_field = new QLineEdit();
+  edit_value_nbr_field->setVisible(false);
+  active_layout->addWidget(edit_value_nbr_field, 4,0 );
+
   lbl = new QLabel(R__("Range:"));
-  active_layout->addWidget(lbl, 2, 0);
+  active_layout->addWidget(lbl, 5, 0);
   edit_range_button = new QToolButton();
   menu = new QMenu();
   edit_range_button->setToolButtonStyle(Qt::ToolButtonTextOnly);
@@ -86,7 +102,7 @@
   req_range_iterate(range_id) {
     menu->addAction(req_range_name(range_id));
   } req_range_iterate_end;
-  active_layout->addWidget(edit_range_button, 3, 0);
+  active_layout->addWidget(edit_range_button, 6, 0);
 
   main_layout->addLayout(active_layout);
 
@@ -129,6 +145,9 @@
       universal_name_translation(&preq->source, buf, sizeof(buf));
       item = new QListWidgetItem(QString::fromUtf8(buf));
       req_list->insertItem(i++, item);
+      if (selected == preq) {
+        item->setSelected(true);
+      }
     }
   } requirement_vector_iterate_end;
 
@@ -159,13 +178,47 @@
   } requirement_vector_iterate_end;
 }
 
+struct uvb_data
+{
+  QLineEdit *number;
+  QToolButton *enum_button;
+  QMenu *menu;
+};
+
+/**************************************************************************
+  Callback for filling menu values
+**************************************************************************/
+static void universal_value_cb(const char *value, bool current, void *cbdata)
+{
+  struct uvb_data *data = (struct uvb_data *)cbdata;
+  
+  if (value == NULL) {
+    data->number->setVisible(true);
+  } else {
+    data->enum_button->setVisible(true);
+    data->menu->addAction(value);
+    if (current) {
+      data->enum_button->setText(value);
+    }
+  }
+}
+
 /**************************************************************************
   Fill active menus from selected req.
 **************************************************************************/
 void req_edit::fill_active()
 {
   if (selected != nullptr) {
+    struct uvb_data data;
+
     edit_type_button->setText(universals_n_name(selected->source.kind));
+    data.number = edit_value_nbr_field;
+    data.enum_button = edit_value_enum_button;
+    data.menu = edit_value_enum_menu;
+    edit_value_enum_menu->clear();
+    edit_value_enum_button->setVisible(false);
+    edit_value_nbr_field->setVisible(false);
+    universal_kind_values(&selected->source, universal_value_cb, &data);
     edit_range_button->setText(req_range_name(selected->range));
   }
 }
@@ -199,6 +252,18 @@
   }
 
   refresh();
+}
+
+/**************************************************************************
+  User selected value for the requirement.
+**************************************************************************/
+void req_edit::univ_value_enum_menu(QAction *action)
+{
+  if (selected != nullptr) {
+    universal_value_from_str(&selected->source, 
action->text().toUtf8().data());
+
+    refresh();
+  }
 }
 
 /**************************************************************************
@@ -234,6 +299,8 @@
 
     requirement_vector_reserve(req_vector, end);
 
+    selected = nullptr;
+
     refresh();
   }
 }

Modified: trunk/tools/ruledit/req_edit.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/req_edit.h?rev=33589&r1=33588&r2=33589&view=diff
==============================================================================
--- trunk/tools/ruledit/req_edit.h      (original)
+++ trunk/tools/ruledit/req_edit.h      Sat Aug 13 18:14:53 2016
@@ -44,6 +44,9 @@
     struct requirement *selected;
 
     QToolButton *edit_type_button;
+    QToolButton *edit_value_enum_button;
+    QMenu *edit_value_enum_menu;
+    QLineEdit *edit_value_nbr_field;
     QToolButton *edit_range_button;
 
   private slots:
@@ -55,6 +58,7 @@
 
     void req_type_menu(QAction *action);
     void req_range_menu(QAction *action);
+    void univ_value_enum_menu(QAction *action);
 };
 
 #endif // FC__REQ_EDIT_H

Modified: trunk/tools/ruledit/univ_value.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/univ_value.c?rev=33589&r1=33588&r2=33589&view=diff
==============================================================================
--- trunk/tools/ruledit/univ_value.c    (original)
+++ trunk/tools/ruledit/univ_value.c    Sat Aug 13 18:14:53 2016
@@ -201,3 +201,27 @@
 
   return FALSE;
 }
+
+/************************************************************************
+  Call cb for each value possible for the universal kind.
+************************************************************************/
+void universal_kind_values(struct universal *univ,
+                           univ_kind_values_cb cb, void *data)
+{
+  switch (univ->kind) {
+  case VUT_NONE:
+    break;
+  case VUT_ADVANCE:
+    advance_active_iterate(padv) {
+      cb(advance_rule_name(padv), univ->value.advance == padv, data);
+    } advance_active_iterate_end;
+    break;
+#ifdef INTEGER_UNIV_VALUES
+  case VUT_MINSIZE:
+    cb(NULL, data);
+    break;
+#endif
+  default:
+    break;
+  }
+}

Modified: trunk/tools/ruledit/univ_value.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/univ_value.h?rev=33589&r1=33588&r2=33589&view=diff
==============================================================================
--- trunk/tools/ruledit/univ_value.h    (original)
+++ trunk/tools/ruledit/univ_value.h    Sat Aug 13 18:14:53 2016
@@ -17,7 +17,10 @@
 extern "C" {
 #endif /* __cplusplus */
 
+typedef void (*univ_kind_values_cb)(const char *value, bool current, void 
*data);
+
 bool universal_value_initial(struct universal *src);
+void universal_kind_values(struct universal *univ, univ_kind_values_cb cb, 
void *data);
 
 #ifdef __cplusplus
 }


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

Reply via email to