From d0174254d5ab53bf5f01dc956c6774090ddb1179 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C5=82awomir=20Lach?= <slawek@lach.art.pl>
Date: Thu, 17 Nov 2022 16:15:49 +0100
Subject: [PATCH] =?UTF-8?q?!OSDN:=20Ticket:=20#45891=20:=20S=C5=82awomir?=
 =?UTF-8?q?=20Lach=20<slawek@lach.art.pl>?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

ruledit will show counter count in selected ruleset

diff --git a/common/counters.c b/common/counters.c
index f17eaa6d9f..b18334009f 100644
--- a/common/counters.c
+++ b/common/counters.c
@@ -84,6 +84,7 @@ void attach_city_counter(struct counter *counter)
 {
   counters_city[number_city_counters] = counter;
   counters_city[number_city_counters]->index = number_city_counters;
+  counters_city[number_city_counters]->ruledit_disabled = FALSE;
   number_city_counters++;
 }
 
diff --git a/common/counters.h b/common/counters.h
index d5cadf0205..fd332b5033 100644
--- a/common/counters.h
+++ b/common/counters.h
@@ -17,6 +17,9 @@
 extern "C" {
 #endif /* __cplusplus */
 
+/* utility */
+#include "support.h"
+
 /* common */
 #include "name_translation.h"
 
@@ -25,6 +28,7 @@ extern "C" {
 struct counter
 {
   struct name_translation name;
+  bool ruledit_disabled;
   enum counter_behaviour type;
   enum counter_target target;
   int checkpoint;
@@ -61,6 +65,18 @@ void attach_city_counter(struct counter *counter);
 #define city_counters_iterate_end } \
    }
 
+#define counters_re_iterate(pcount) { \
+   int _i_##pcount; \
+   struct counter *pcount; \
+   int _ccounter_count_##pcount = game.control.num_counters; { \
+   for (_i_##pcount = 0; _i_##pcount < _ccounter_count_##pcount; _i_##pcount++) { \
+      pcount = counter_by_id(_i_##pcount); \
+      if ( ! pcount -> ruledit_disabled ) {
+
+#define counters_re_iterate_end } \
+          } \
+      } \
+   }
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/tools/ruledit/tab_misc.cpp b/tools/ruledit/tab_misc.cpp
index 1ec9724d2b..7a3902beb0 100644
--- a/tools/ruledit/tab_misc.cpp
+++ b/tools/ruledit/tab_misc.cpp
@@ -35,6 +35,7 @@
 
 // common
 #include "achievements.h"
+#include "counters.h"
 #include "game.h"
 #include "government.h"
 #include "specialist.h"
@@ -199,6 +200,10 @@ tab_misc::tab_misc(ruledit_gui *ui_in) : QWidget()
   stats->setItem(5, 3, item);
   item = new QTableWidgetItem("-");
   stats->setItem(5, 4, item);
+  item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Counters")));
+  stats->setItem(6, 3, item);
+  item = new QTableWidgetItem("-");
+  stats->setItem(6, 4, item);
   item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Achievements")));
   stats->setItem(0, 6, item);
   item = new QTableWidgetItem("-");
@@ -391,6 +396,11 @@ void tab_misc::refresh_stats()
   stats->item(row++, 4)->setText(QString::number(count));
 
   stats->item(row++, 4)->setText(QString::number(game.control.num_disaster_types));
+  count = 0;
+  counters_re_iterate(pcount) {
+    count++;
+  } counters_re_iterate_end;
+  stats->item(row++, 4)->setText(QString::number(count));
 
   // Third column
   row = 0;
-- 
2.39.0

