From abe49da542de937cb53a15994e54b7c81f8a37cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C5=82awomir=20Lach?= <slawek@lach.art.pl>
Date: Thu, 20 Apr 2023 14:33:47 +0200
Subject: [PATCH] =?UTF-8?q?!OSDN:=20#47887:=20S=C5=82awomir=20Lach=20<slaw?=
 =?UTF-8?q?ek@lach.art.pl>?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add counters tab for city dialog.

diff --git a/client/gui-gtk-3.22/citydlg.c b/client/gui-gtk-3.22/citydlg.c
index f6e17cf2d8..2dc0f45b42 100644
--- a/client/gui-gtk-3.22/citydlg.c
+++ b/client/gui-gtk-3.22/citydlg.c
@@ -32,6 +32,7 @@
 
 /* common */
 #include "city.h"
+#include "counters.h"
 #include "game.h"
 #include "map.h"
 #include "movement.h"
@@ -184,6 +185,11 @@ struct city_dialog {
     GtkWidget *citizens;
   } happiness;
 
+  struct {
+    GtkWidget *container;
+    GtkWidget *widget;
+  } counters;
+
   struct cma_dialog *cma_editor;
 
   struct {
@@ -242,6 +248,7 @@ static void create_and_append_map_page(struct city_dialog *pdialog);
 static void create_and_append_buildings_page(struct city_dialog *pdialog);
 static void create_and_append_worklist_page(struct city_dialog *pdialog);
 static void create_and_append_happiness_page(struct city_dialog *pdialog);
+static void create_and_append_counters_page(struct city_dialog *pdialog);
 static void create_and_append_cma_page(struct city_dialog *pdialog);
 static void create_and_append_settings_page(struct city_dialog *pdialog);
 
@@ -249,6 +256,7 @@ static struct city_dialog *create_city_dialog(struct city *pcity);
 
 static void city_dialog_update_title(struct city_dialog *pdialog);
 static void city_dialog_update_citizens(struct city_dialog *pdialog);
+static void city_dialog_update_counters(struct city_dialog *pdialog);
 static void city_dialog_update_information(GtkWidget **info_ebox,
                                            GtkWidget **info_label,
                                            struct city_dialog *pdialog);
@@ -503,6 +511,7 @@ void real_city_dialog_refresh(struct city *pcity)
   city_dialog_update_improvement_list(pdialog);
   city_dialog_update_supported_units(pdialog);
   city_dialog_update_present_units(pdialog);
+  city_dialog_update_counters(pdialog);
 
   if (!client_has_player() || city_owner(pcity) == client_player()) {
     bool have_present_units = (unit_list_size(pcity->tile->units) > 0);
@@ -1295,6 +1304,24 @@ static void create_and_append_worklist_page(struct city_dialog *pdialog)
   gtk_widget_show_all(page);
 }
 
+
+/**********************************************************************//**
+  Creates counters page
+**************************************************************************/
+
+static void create_and_append_counters_page(struct city_dialog *pdialog)
+{
+  GtkWidget *page = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+  GtkLabel *label =  (GtkLabel*) gtk_label_new(_("Counters"));
+  city_dialog_update_counters(pdialog);
+
+  gtk_container_add((GtkContainer*) page, pdialog->counters.container);
+
+  gtk_notebook_append_page(GTK_NOTEBOOK(pdialog->notebook), page, (GtkWidget*)label);
+
+  gtk_widget_show_all(page);
+}
+
 /**********************************************************************//**
                      **** Happiness Page ****
  +- GtkWidget *page ----------+-------------------------------------------+
@@ -1647,6 +1674,7 @@ static struct city_dialog *create_city_dialog(struct city *pcity)
   create_and_append_overview_page(pdialog);
   create_and_append_map_page(pdialog);
   create_and_append_buildings_page(pdialog);
+  create_and_append_counters_page(pdialog);
 
   owner = city_owner(pcity);
 
@@ -2248,6 +2276,74 @@ static void city_dialog_update_supported_units(struct city_dialog *pdialog)
   g_free(buf);
 }
 
+
+/**********************************************************************//**
+  Update counters tab  in city dialog
+**************************************************************************/
+static void city_dialog_update_counters(struct city_dialog *pdialog)
+{
+  GtkBox *counterInfo, *valueData;
+  GtkLabel *counterName;
+  GtkLabel *counterValue;
+  GtkLabel *counterDescription;
+  char  int_val[101];
+  char *text;
+  int text_size;
+
+  if (NULL != pdialog->counters.widget) {
+    gtk_widget_destroy(pdialog->counters.widget);
+  }
+
+  if (NULL == pdialog->counters.container) {
+    pdialog->counters.container = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+  }
+
+  pdialog->counters.widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+  city_counters_iterate(pcount) {
+    counterInfo = (GtkBox*) gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+
+    counterName = (GtkLabel*) gtk_label_new(name_translation_get(&pcount->name));
+    gtk_container_add((GtkContainer*)counterInfo, (GtkWidget*)counterName);
+    valueData = (GtkBox*) gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+    counterValue = (GtkLabel*) gtk_label_new(_("Current value is: "));
+    gtk_container_add((GtkContainer*)valueData, (GtkWidget*)counterValue);
+    snprintf(int_val, sizeof(int_val), "%d", pdialog->pcity->counter_values[counter_index(pcount)]);
+    counterValue = (GtkLabel*) gtk_label_new(int_val);
+    gtk_container_add((GtkContainer*)valueData, (GtkWidget*)counterValue);
+    gtk_container_add((GtkContainer*)counterInfo, (GtkWidget*)valueData);
+
+    valueData = (GtkBox*) gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+    counterValue =(GtkLabel*)  gtk_label_new(_("Activated once value equal or higher than: "));
+    gtk_container_add((GtkContainer*)valueData, (GtkWidget*)counterValue);
+    snprintf(int_val, sizeof(int_val), "%d", pcount->checkpoint);
+    counterValue = (GtkLabel*) gtk_label_new(int_val);
+    gtk_container_add((GtkContainer*)valueData, (GtkWidget*)counterValue);
+    gtk_container_add((GtkContainer*)counterInfo, (GtkWidget*)valueData);
+
+    text_size = 0;
+    if (NULL != pcount->helptext) {
+      strvec_iterate(pcount->helptext, text_) {
+        text_size += strlen(text_);
+      } strvec_iterate_end;
+    }
+    if (0 < text_size) {
+      text = malloc(text_size+1);
+      text_size = 0;
+      strvec_iterate(pcount->helptext, text_) {
+        strcpy(&text[text_size], text_);
+        text_size += strlen(text_);
+      } strvec_iterate_end;
+      counterDescription = (GtkLabel*) gtk_label_new(text);
+      free(text);
+      gtk_container_add((GtkContainer*)counterInfo,(GtkWidget*)counterDescription);
+    }
+    gtk_container_add((GtkContainer*)pdialog->counters.widget, (GtkWidget*) counterInfo);
+  } city_counters_iterate_end;
+
+  gtk_container_add((GtkContainer*)pdialog->counters.container, pdialog->counters.widget);
+  gtk_widget_show_all(pdialog->counters.container);
+}
+
 /**********************************************************************//**
   Update list of present units in city dialog
 **************************************************************************/
-- 
2.40.0

