Author: jtn
Date: Tue May 12 09:25:21 2015
New Revision: 29063

URL: http://svn.gna.org/viewcvs/freeciv?rev=29063&view=rev
Log:
Miscellaneous polish to the multipliers UI.

See gna patch #6076.

Modified:
    branches/S2_6/client/gui-gtk-2.0/gamedlgs.c
    branches/S2_6/client/gui-gtk-2.0/menu.c
    branches/S2_6/client/gui-gtk-3.0/gamedlgs.c
    branches/S2_6/client/gui-gtk-3.0/menu.c
    branches/S2_6/client/helpdata.c
    branches/S2_6/data/gtk_menus.xml
    branches/S2_6/data/helpdata.txt

Modified: branches/S2_6/client/gui-gtk-2.0/gamedlgs.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-2.0/gamedlgs.c?rev=29063&r1=29062&r2=29063&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-2.0/gamedlgs.c (original)
+++ branches/S2_6/client/gui-gtk-2.0/gamedlgs.c Tue May 12 09:25:21 2015
@@ -57,8 +57,8 @@
 static GtkWidget *rates_tax_label, *rates_lux_label, *rates_sci_label;
 static GtkObject *rates_tax_adj, *rates_lux_adj, *rates_sci_adj;
 
-GtkWidget *multiplier_dialog_shell;
-GtkWidget *multipliers_scale[MAX_NUM_MULTIPLIERS];
+static GtkWidget *multiplier_dialog_shell;
+static GtkWidget *multipliers_scale[MAX_NUM_MULTIPLIERS];
 
 static gulong     rates_tax_sig, rates_lux_sig, rates_sci_sig;
 /******************************************************************/
@@ -217,29 +217,50 @@
 }
 
 /**************************************************************************
+  Convert real multiplier value to scale value
+**************************************************************************/
+static int mult_to_scale(const struct multiplier *pmul, int val)
+{
+  return (val - pmul->start) / pmul->step;
+}
+
+/**************************************************************************
+  Convert scale units to real multiplier value
+**************************************************************************/
+static int scale_to_mult(const struct multiplier *pmul, int scale)
+{
+  return scale * pmul->step + pmul->start;
+}
+
+/**************************************************************************
+  Format value for multiplier scales
+**************************************************************************/
+static gchar *multiplier_value_callback(GtkScale *scale, gdouble value,
+                                        void *udata)
+{
+  const struct multiplier *pmul = udata;
+
+  return g_strdup_printf("%d", scale_to_mult(pmul, value));
+}
+
+/**************************************************************************
   User has responded to multipliers dialog
 **************************************************************************/
 static void multipliers_command_callback(GtkWidget *w, gint response_id)
 {
   struct packet_player_multiplier mul;
-  struct multiplier *m;
-  struct player *pplayer = client_player();
-  int i = 0;
-  int value, rvalue;
 
   if (response_id == GTK_RESPONSE_OK) {
-    for (; i < multiplier_count(); ++i) {
-      value  = gtk_range_get_value(GTK_RANGE(multipliers_scale[i]));
-      m = multiplier_by_number(i);
-      rvalue = (value - m->start) / m->step * m->step + m->start;
-      pplayer->multipliers[i] = rvalue;
-      mul.multipliers[i] = rvalue;
-    }
+    multipliers_iterate(m) {
+      Multiplier_type_id i = multiplier_index(m);
+      int value = gtk_range_get_value(GTK_RANGE(multipliers_scale[i]));
+
+      mul.multipliers[i] = scale_to_mult(m, value);
+    } multipliers_iterate_end;
     mul.count = multiplier_count();
     send_packet_player_multiplier(&client.conn, &mul);
   }
   gtk_widget_destroy(multiplier_dialog_shell);
-  multiplier_dialog_shell = NULL;
 }
 
 /****************************************************************
@@ -249,14 +270,13 @@
 {
   GtkWidget     *shell, *content;
   GtkWidget     *label, *scale;
-  int            multiplier = 0;
   struct player *pplayer = client_player();
 
   if (!can_client_issue_orders()) {
     return NULL;
   }
 
-  shell = gtk_dialog_new_with_buttons(_("Change governments modifiers"),
+  shell = gtk_dialog_new_with_buttons(_("Change policies"),
                                       NULL,
                                       0,
                                       GTK_STOCK_CANCEL,
@@ -269,11 +289,28 @@
   content = gtk_dialog_get_content_area(GTK_DIALOG(shell));
 
   multipliers_iterate(pmul) {
-    label = gtk_label_new(rule_name(&pmul->name));
-    scale = gtk_hscale_new_with_range(pmul->start, pmul->stop, pmul->step);
+    Multiplier_type_id multiplier = multiplier_index(pmul);
+
+    fc_assert(multiplier < ARRAY_SIZE(multipliers_scale));
+    label = gtk_label_new(multiplier_name_translation(pmul));
+    /* Map each multiplier step to a single step on the UI, to enforce
+     * the step size. */
+    scale = gtk_hscale_new_with_range(mult_to_scale(pmul, pmul->start),
+                                      mult_to_scale(pmul, pmul->stop), 1);
     multipliers_scale[multiplier] = scale;
-    gtk_range_set_value(GTK_RANGE(multipliers_scale[multiplier]), 
pplayer->multipliers[multiplier]);
-    multiplier++;
+    gtk_range_set_increments(GTK_RANGE(multipliers_scale[multiplier]),
+                             1, MAX(2, mult_to_scale(pmul, pmul->stop) / 10));
+    fc_assert(scale_to_mult(pmul,
+                            mult_to_scale(pmul,
+                                          pplayer->multipliers[multiplier]))
+              == pplayer->multipliers[multiplier]);
+    gtk_range_set_value(GTK_RANGE(multipliers_scale[multiplier]),
+                        mult_to_scale(pmul, pplayer->multipliers[multiplier]));
+    g_signal_connect(multipliers_scale[multiplier], "format-value",
+                     G_CALLBACK(multiplier_value_callback), pmul);
+    g_signal_connect(multipliers_scale[multiplier], "destroy",
+                     G_CALLBACK(gtk_widget_destroyed),
+                     &multipliers_scale[multiplier]);
     gtk_box_pack_start( GTK_BOX( content ), label, TRUE, TRUE, 5 );
     gtk_box_pack_start( GTK_BOX( content ), scale, TRUE, TRUE, 5 );
   } multipliers_iterate_end;

Modified: branches/S2_6/client/gui-gtk-2.0/menu.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-2.0/menu.c?rev=29063&r1=29062&r2=29063&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-2.0/menu.c     (original)
+++ branches/S2_6/client/gui-gtk-2.0/menu.c     Tue May 12 09:25:21 2015
@@ -1750,8 +1750,8 @@
       /* Civilization menu. */
       {"TAX_RATE", NULL, _("_Tax Rates..."),
        "<Control>t", NULL, G_CALLBACK(tax_rate_callback)},
-       {"POLICIES", NULL, _("Policies"),
-       NULL, NULL, G_CALLBACK(multiplier_callback)},
+      {"POLICIES", NULL, _("Policies..."),
+       "<Shift><Control>p", NULL, G_CALLBACK(multiplier_callback)},
       /* Civilization/Government menu. */
       {"START_REVOLUTION", NULL, _("_Revolution..."),
        "<Shift><Control>r", NULL, G_CALLBACK(government_callback)},
@@ -2596,6 +2596,8 @@
   menus_set_sensitive(playing_group, "TAX_RATE",
                       game.info.changable_tax
                       && can_client_issue_orders());
+  menus_set_sensitive(playing_group, "POLICIES",
+                      multiplier_count() > 0);
 
   menus_set_active(safe_group, "SHOW_CITY_OUTLINES", 
options.draw_city_outlines);
   menus_set_active(safe_group, "SHOW_CITY_OUTPUT", options.draw_city_output);

Modified: branches/S2_6/client/gui-gtk-3.0/gamedlgs.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/gamedlgs.c?rev=29063&r1=29062&r2=29063&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.0/gamedlgs.c (original)
+++ branches/S2_6/client/gui-gtk-3.0/gamedlgs.c Tue May 12 09:25:21 2015
@@ -55,8 +55,8 @@
 static GtkWidget *rates_tax_label, *rates_lux_label, *rates_sci_label;
 static GtkWidget *rates_tax_scale, *rates_lux_scale, *rates_sci_scale;
 
-GtkWidget *multiplier_dialog_shell;
-GtkWidget *multipliers_scale[MAX_NUM_MULTIPLIERS];
+static GtkWidget *multiplier_dialog_shell;
+static GtkWidget *multipliers_scale[MAX_NUM_MULTIPLIERS];
 
 static gulong     rates_tax_sig, rates_lux_sig, rates_sci_sig;
 /******************************************************************/
@@ -215,29 +215,50 @@
 }
 
 /**************************************************************************
+  Convert real multiplier value to scale value
+**************************************************************************/
+static int mult_to_scale(const struct multiplier *pmul, int val)
+{
+  return (val - pmul->start) / pmul->step;
+}
+
+/**************************************************************************
+  Convert scale units to real multiplier value
+**************************************************************************/
+static int scale_to_mult(const struct multiplier *pmul, int scale)
+{
+  return scale * pmul->step + pmul->start;
+}
+
+/**************************************************************************
+  Format value for multiplier scales
+**************************************************************************/
+static gchar *multiplier_value_callback(GtkScale *scale, gdouble value,
+                                        void *udata)
+{
+  const struct multiplier *pmul = udata;
+
+  return g_strdup_printf("%d", scale_to_mult(pmul, value));
+}
+
+/**************************************************************************
   User has responded to multipliers dialog
 **************************************************************************/
 static void multipliers_command_callback(GtkWidget *w, gint response_id)
 {
   struct packet_player_multiplier mul;
-  struct multiplier *m;
-  struct player *pplayer = client_player();
-  int i = 0;
-  int value, rvalue;
 
   if (response_id == GTK_RESPONSE_OK) {
-    for (; i < multiplier_count(); ++i) {
-      value  = gtk_range_get_value(GTK_RANGE(multipliers_scale[i]));
-      m = multiplier_by_number(i);
-      rvalue = (value - m->start)  / m->step * m->step + m->start;
-      pplayer->multipliers[i] = rvalue;
-      mul.multipliers[i] = rvalue;
-    }
+    multipliers_iterate(m) {
+      Multiplier_type_id i = multiplier_index(m);
+      int value = gtk_range_get_value(GTK_RANGE(multipliers_scale[i]));
+
+      mul.multipliers[i] = scale_to_mult(m, value);
+    } multipliers_iterate_end;
     mul.count = multiplier_count();
     send_packet_player_multiplier(&client.conn, &mul);
   }
   gtk_widget_destroy(multiplier_dialog_shell);
-  multiplier_dialog_shell = NULL;
 }
 
 /****************************************************************
@@ -247,14 +268,13 @@
 {
   GtkWidget     *shell, *content;
   GtkWidget     *label, *scale;
-  int            multiplier = 0;
   struct player *pplayer = client_player();
 
   if (!can_client_issue_orders()) {
     return NULL;
   }
 
-  shell = gtk_dialog_new_with_buttons(_("Change governments modifiers"),
+  shell = gtk_dialog_new_with_buttons(_("Change policies"),
                                       NULL,
                                       0,
                                       GTK_STOCK_CANCEL,
@@ -267,11 +287,29 @@
   content = gtk_dialog_get_content_area(GTK_DIALOG(shell));
 
   multipliers_iterate(pmul) {
-    label = gtk_label_new(rule_name(&pmul->name));
-    scale = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, pmul->start, 
pmul->stop, pmul->step);
+    Multiplier_type_id multiplier = multiplier_index(pmul);
+
+    fc_assert(multiplier < ARRAY_SIZE(multipliers_scale));
+    label = gtk_label_new(multiplier_name_translation(pmul));
+    /* Map each multiplier step to a single step on the UI, to enforce
+     * the step size. */
+    scale = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL,
+                                     mult_to_scale(pmul, pmul->start),
+                                     mult_to_scale(pmul, pmul->stop), 1);
     multipliers_scale[multiplier] = scale;
-    gtk_range_set_value(GTK_RANGE(multipliers_scale[multiplier]), 
pplayer->multipliers[multiplier]);
-    multiplier++;
+    gtk_range_set_increments(GTK_RANGE(multipliers_scale[multiplier]),
+                             1, MAX(2, mult_to_scale(pmul, pmul->stop) / 10));
+    fc_assert(scale_to_mult(pmul,
+                            mult_to_scale(pmul,
+                                          pplayer->multipliers[multiplier]))
+              == pplayer->multipliers[multiplier]);
+    gtk_range_set_value(GTK_RANGE(multipliers_scale[multiplier]),
+                        mult_to_scale(pmul, pplayer->multipliers[multiplier]));
+    g_signal_connect(multipliers_scale[multiplier], "format-value",
+                     G_CALLBACK(multiplier_value_callback), pmul);
+    g_signal_connect(multipliers_scale[multiplier], "destroy",
+                     G_CALLBACK(gtk_widget_destroyed),
+                     &multipliers_scale[multiplier]);
     gtk_box_pack_start( GTK_BOX( content ), label, TRUE, TRUE, 5 );
     gtk_box_pack_start( GTK_BOX( content ), scale, TRUE, TRUE, 5 );
   } multipliers_iterate_end;

Modified: branches/S2_6/client/gui-gtk-3.0/menu.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/menu.c?rev=29063&r1=29062&r2=29063&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.0/menu.c     (original)
+++ branches/S2_6/client/gui-gtk-3.0/menu.c     Tue May 12 09:25:21 2015
@@ -1751,12 +1751,12 @@
       /* Civilization menu. */
       {"TAX_RATE", NULL, _("_Tax Rates..."),
        "<Control>t", NULL, G_CALLBACK(tax_rate_callback)},
+       /* Civilization/Policies menu */
+      {"POLICIES", NULL, _("_Policies..."),
+       "<Shift><Control>p", NULL, G_CALLBACK(multiplier_callback)},
       /* Civilization/Government menu. */
       {"START_REVOLUTION", NULL, _("_Revolution..."),
        "<Shift><Control>r", NULL, G_CALLBACK(government_callback)},
-       /* Civilization/Policies menu */
-       {"POLICIES", NULL, _("_Policies"),
-        "<Shift><Control>p", NULL, G_CALLBACK(multiplier_callback)},
     };
 
     group = gtk_action_group_new("PlayingGroup");
@@ -2597,6 +2597,8 @@
   menus_set_sensitive(playing_group, "TAX_RATE",
                       game.info.changable_tax
                       && can_client_issue_orders());
+  menus_set_sensitive(playing_group, "POLICIES",
+                      multiplier_count() > 0);
 
   menus_set_active(safe_group, "SHOW_CITY_OUTLINES", 
options.draw_city_outlines);
   menus_set_active(safe_group, "SHOW_CITY_OUTPUT", options.draw_city_output);

Modified: branches/S2_6/client/helpdata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/helpdata.c?rev=29063&r1=29062&r2=29063&view=diff
==============================================================================
--- branches/S2_6/client/helpdata.c     (original)
+++ branches/S2_6/client/helpdata.c     Tue May 12 09:25:21 2015
@@ -3036,9 +3036,14 @@
               fc_snprintf(name, sizeof(name), "%*s%s", level, "",
                           name_translation(&pmul->name));
               pitem->topic = fc_strdup(name);
-              strvec_iterate(pmul->helptext, text) {
-                cat_snprintf(help_text_buffer, MAX_LEN_PACKET, "%s\n\n", text);
-              } strvec_iterate_end;
+              if (pmul->helptext) {
+                const char *sep = "";
+                strvec_iterate(pmul->helptext, text) {
+                  cat_snprintf(help_text_buffer, sizeof(help_text_buffer),
+                               "%s%s", sep, text);
+                  sep = "\n\n";
+                } strvec_iterate_end;
+              }
               pitem->text = fc_strdup(help_text_buffer);
               help_list_append(help_nodes, pitem);
             } multipliers_iterate_end;

Modified: branches/S2_6/data/gtk_menus.xml
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/gtk_menus.xml?rev=29063&r1=29062&r2=29063&view=diff
==============================================================================
--- branches/S2_6/data/gtk_menus.xml    (original)
+++ branches/S2_6/data/gtk_menus.xml    Tue May 12 09:25:21 2015
@@ -167,7 +167,6 @@
     <menu action="MENU_HELP">
       <menuitem action="HELP_OVERVIEW" />
       <menuitem action="HELP_PLAYING" />
-      <menuitem action="HELP_POLICIES" />
       <menuitem action="HELP_TERRAIN" />
       <menuitem action="HELP_ECONOMY" />
       <menuitem action="HELP_CITIES" />
@@ -177,6 +176,7 @@
       <menuitem action="HELP_COMBAT" />
       <menuitem action="HELP_ZOC" />
       <menuitem action="HELP_GOVERNMENT" />
+      <menuitem action="HELP_POLICIES" />
       <menuitem action="HELP_DIPLOMACY" />
       <menuitem action="HELP_TECH" />
       <menuitem action="HELP_SPACE_RACE" />

Modified: branches/S2_6/data/helpdata.txt
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/helpdata.txt?rev=29063&r1=29062&r2=29063&view=diff
==============================================================================
--- branches/S2_6/data/helpdata.txt     (original)
+++ branches/S2_6/data/helpdata.txt     Tue May 12 09:25:21 2015
@@ -1398,6 +1398,13 @@
 cities are immune from civil war. However, this is a server \
 option ('civilwarsize'), and may vary upwards from a minimum of 6.\
 ")
+
+[help_policies]
+name = _("Policies")
+text = _("Policies are changable values, which define your civilization's 
rights.")
+
+[help_gen_policies]
+generate = " Multipliers"
 
 [help_diplomacy]
 name = _("Diplomacy")
@@ -1919,13 +1926,6 @@
 from the City Overview window.\
 ")
 
-[help_multipiers]
-name = _("Policies")
-text = _("Policies are changable values, which define your civilization's 
rights.")
-
-[help_gen_multipiers]
-generate = " Multipliers"
-
 [help_languages]
 name = _("Languages")
 text = _("\


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

Reply via email to