From 5b05997bf2d8dfff9345442676e0a48b8ce10aa1 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 5c50bcff7e..a13db87d88 100644
--- a/common/counters.c
+++ b/common/counters.c
@@ -71,6 +71,8 @@ struct counter *counter_by_id(int id)
 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 394c1e1e83..2912f853e8 100644
--- a/common/counters.h
+++ b/common/counters.h
@@ -17,6 +17,8 @@
 extern "C" {
 #endif /* __cplusplus */
 
+#include "support.h"
+
 /* common */
 #include "name_translation.h"
 
@@ -34,6 +36,7 @@ enum counter_target { CTGT_CITY };
 struct counter
 {
   struct name_translation name;
+  bool ruledit_disabled;
   enum counter_behaviour type;
   enum counter_target target;
   int checkpoint;
@@ -70,6 +73,20 @@ void attach_city_counter(struct counter *counter);
 #define city_counters_iterate_end } \
    }
 
+
+#define city_counters_re_iterate(pcount) { \
+   int _i_##pcount; \
+   struct counter *pcount; \
+   int _ccounter_count_##pcount = counters_get_city_counters_count(); { \
+   for (_i_##pcount = 0; _i_##pcount < _ccounter_count_##pcount; _i_##pcount++) { \
+      pcount = counter_by_index(_i_##pcount, CTGT_CITY); \
+      if ( ! pcount -> ruledit_disabled ) { 
+
+#define city_counters_re_iterate_end } \
+          } \
+      } \
+   }
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/tools/ruledit/tab_misc.cpp b/tools/ruledit/tab_misc.cpp
index 57090667eb..0f36c2668c 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"
@@ -197,6 +198,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("-");
@@ -390,6 +395,13 @@ void tab_misc::refresh_stats()
 
   stats->item(row++, 4)->setText(QString::number(game.control.num_disaster_types));
 
+  count = 0;
+  city_counters_re_iterate(pcount) {
+    count++;
+  } city_counters_re_iterate_end;
+  stats->item(row++, 4)->setText(QString::number(count));
+
+
   // Third column
   row = 0;
 
-- 
2.39.0

