From 0017519a2f22bbd507f1b9c95f06e67fc300f34d Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 17 Mar 2024 21:27:08 +0200
Subject: [PATCH 34/34] Ruledit: Add extra native_to editing

See RM #316

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 tools/ruledit/edit_extra.cpp | 28 +++++++++++++++++++++++++++-
 tools/ruledit/edit_extra.h   |  3 +++
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/tools/ruledit/edit_extra.cpp b/tools/ruledit/edit_extra.cpp
index f22931f6e7..a6799a64dc 100644
--- a/tools/ruledit/edit_extra.cpp
+++ b/tools/ruledit/edit_extra.cpp
@@ -16,12 +16,14 @@
 #endif
 
 // Qt
+#include <QCheckBox>
 #include <QGridLayout>
 #include <QLineEdit>
 #include <QToolButton>
 
 // common
 #include "extras.h"
+#include "game.h"
 
 // ruledit
 #include "ruledit.h"
@@ -35,7 +37,7 @@
 edit_extra::edit_extra(ruledit_gui *ui_in, struct extra_type *extra_in)
   : QDialog()
 {
-  QVBoxLayout *main_layout = new QVBoxLayout(this);
+  QHBoxLayout *main_layout = new QHBoxLayout(this);
   QGridLayout *extra_layout = new QGridLayout();
   QLabel *label;
   int row = 0;
@@ -43,6 +45,8 @@ edit_extra::edit_extra(ruledit_gui *ui_in, struct extra_type *extra_in)
   ui = ui_in;
   extra = extra_in;
 
+  natives_layout = new QGridLayout();
+
   setWindowTitle(QString::fromUtf8(extra_rule_name(extra)));
 
   label = new QLabel(QString::fromUtf8(R__("Graphics tag")));
@@ -117,9 +121,22 @@ edit_extra::edit_extra(ruledit_gui *ui_in, struct extra_type *extra_in)
   extra_layout->addWidget(label, row, 0);
   extra_layout->addWidget(rmact_gfx_alt2, row++, 1);
 
+  label = new QLabel(QString::fromUtf8(R__("Native to")));
+  natives_layout->addWidget(label, 0, 0);
+  for (int i = 0; i < game.control.num_unit_classes; i++) {
+    QCheckBox *check = new QCheckBox();
+
+    label = new QLabel(uclass_rule_name(uclass_by_number(i)));
+    natives_layout->addWidget(label, i + 1, 0);
+
+    check->setChecked(BV_ISSET(extra->native_to, i));
+    natives_layout->addWidget(check, i + 1, 1);
+  }
+
   refresh();
 
   main_layout->addLayout(extra_layout);
+  main_layout->addLayout(natives_layout);
 
   setLayout(main_layout);
 }
@@ -139,6 +156,15 @@ void edit_extra::closeEvent(QCloseEvent *cevent)
   rmact_gfx_alt_given();
   rmact_gfx_alt2_given();
 
+  BV_CLR_ALL(extra->native_to);
+  for (int i = 0; i < game.control.num_unit_classes; i++) {
+    QCheckBox *check = static_cast<QCheckBox *>(natives_layout->itemAtPosition(i + 1, 1)->widget());
+
+    if (check->isChecked()) {
+      BV_SET(extra->native_to, i);
+    }
+  }
+
   extra->ruledit_dlg = nullptr;
 }
 
diff --git a/tools/ruledit/edit_extra.h b/tools/ruledit/edit_extra.h
index 6baa2d315f..d9bb469b09 100644
--- a/tools/ruledit/edit_extra.h
+++ b/tools/ruledit/edit_extra.h
@@ -21,6 +21,7 @@
 // Qt
 #include <QDialog>
 
+class QGridLayout;
 class QLineEdit;
 class QSpinBox;
 
@@ -46,6 +47,8 @@ class edit_extra : public QDialog
     QLineEdit *rmact_gfx_alt;
     QLineEdit *rmact_gfx_alt2;
 
+    QGridLayout *natives_layout;
+
   protected:
     void closeEvent(QCloseEvent *cevent);
 
-- 
2.43.0

