Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2006:
[Freeciv-Dev] (PR#15566) add missing helptext
Home

[Freeciv-Dev] (PR#15566) add missing helptext

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#15566) add missing helptext
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 15 Feb 2006 01:14:32 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=15566 >

This patch improves the quality of helptext to some degree.

The existing function, insert_allows, is meant to add the text for all 
targets that are allowed by the passed-in source.  So for instance for 
the Factory helptext, the source is Factory and it adds text "Allows 
Manufacturing plant (with Robotics)" since Manufacturing plant is a 
target that's allowed by Factory.  Ideally it should work for all 
possible targets and all possible sources.

There are, however, several drawbacks.

1.  For each source type we have to call insert_allows separately.  This 
patch fixes this for the most part, by calling it for techs, 
governments, and terrains.  We don't call it for units, specialists, 
nations, which is fine.  We don't call it for specials because there's 
no helptext_special().  And as a side note, there's no such thing as a 
resource requirement yet.

2.  For each target type we have to have code in insert_allows for it. 
Currently only buildings are added since these are the only ones that 
use the reqs vector.  Originally I was waiting to add the others (techs, 
units, governments) until they used the reqs vector as well.  However 
this isn't going to happen for 2.1 (not for units and techs anyway). 
This patch does *not* fix that, but it will have to be fixed.

3.  The text is not linkable.  The client already has its own gui-built 
requires/allows system, that does have links.  This is a major problem 
since the current insert_allows() provides no way around it.  The 
solution is to change insert_allows so that instead of returning text it 
returns a complex data array that gives the list of allowances and 
coreqs.  It is then a trivial matter to assemble the text from this (a 
separate helper function can do that) or to put all the allowances and 
coreqs into a GUI display format (except that the GUI code for the 
helpdlg is beyond me).

Incidentally, this will break all guis except gui-gtk-2.0.  This is 
because it no longer uses long_buffer.  Ideally we can get rid of 
long_buffer entirely.

-jason

Index: client/gui-gtk-2.0/helpdlg.c
===================================================================
--- client/gui-gtk-2.0/helpdlg.c        (revision 11589)
+++ client/gui-gtk-2.0/helpdlg.c        (working copy)
@@ -882,7 +882,7 @@
 {
   int j;
   GtkWidget *w, *hbox;
-  char *buf = &long_buffer[0];
+  char buf[4096];
 
   create_help_page(HELP_TECH);
 
@@ -900,7 +900,7 @@
     gtk_widget_show(help_tree_sw);
     gtk_widget_show(help_tree_buttons_hbox);
 
-    helptext_tech(buf, i, pitem->text);
+    helptext_tech(buf, sizeof(buf), i, pitem->text);
     len = strlen(buf);
     my_chomp(buf, len);
 
@@ -1028,7 +1028,7 @@
 static void help_update_terrain(const struct help_item *pitem,
                                char *title, struct terrain *pterrain)
 {
-  char *buf = &long_buffer[0];
+  char buf[4096];
 
   create_help_page(HELP_TERRAIN);
 
@@ -1109,7 +1109,7 @@
     gtk_label_set_text(GTK_LABEL(help_tlabel[3][4]), buf);
   }
 
-  helptext_terrain(buf, pterrain, pitem->text);
+  helptext_terrain(buf, sizeof(buf), pterrain, pitem->text);
   
   gtk_text_buffer_set_text(help_text, buf, -1);
   gtk_widget_show(help_text_sw);
@@ -1123,12 +1123,12 @@
 static void help_update_government(const struct help_item *pitem,
                                   char *title, struct government *gov)
 {
-  char *buf = &long_buffer[0];
+  char buf[4096];
 
   if (!gov) {
     strcat(buf, pitem->text);
   } else {
-    helptext_government(buf, gov, pitem->text);
+    helptext_government(buf, sizeof(buf), gov, pitem->text);
   }
   create_help_page(HELP_TEXT);
   gtk_text_buffer_set_text(help_text, buf, -1);
Index: client/helpdata.c
===================================================================
--- client/helpdata.c   (revision 11589)
+++ client/helpdata.c   (working copy)
@@ -1076,8 +1076,12 @@
 /****************************************************************
   Append misc dynamic text for techs.
 *****************************************************************/
-void helptext_tech(char *buf, int i, const char *user_text)
+void helptext_tech(char *buf, size_t bufsz, int i, const char *user_text)
 {
+  struct req_source source = {
+    .type = REQ_TECH,
+    .value = {.tech = i}
+  };
   assert(buf&&user_text);
   strcpy(buf, user_text);
 
@@ -1114,15 +1118,9 @@
     }
   }
 
-  government_iterate(g) {
-    /* FIXME: this should tell the other requirements. */
-    requirement_vector_iterate(&g->reqs, preq) {
-      if (preq->source.type == REQ_TECH && preq->source.value.tech == i) {
-       sprintf(buf + strlen(buf), _("* Allows changing government to %s.\n"),
-               g->name);
-      }
-    } requirement_vector_iterate_end;
-  } government_iterate_end;
+  sprintf(buf + strlen(buf), "\n");
+  insert_allows(&source, buf + strlen(buf), bufsz);
+
   if (tech_flag(i, TF_BONUS_TECH)) {
     sprintf(buf + strlen(buf), _("* The first player to research %s gets "
                                 "an immediate advance.\n"),
@@ -1186,9 +1184,13 @@
 /****************************************************************
   Append text for terrain.
 *****************************************************************/
-void helptext_terrain(char *buf, const struct terrain *pterrain,
+void helptext_terrain(char *buf, size_t bufsz, struct terrain *pterrain,
                      const char *user_text)
 {
+  struct req_source source = {
+    .type = REQ_TERRAIN,
+    .value = {.terrain = pterrain}
+  };
   buf[0] = '\0';
   
   if (!pterrain) {
@@ -1196,6 +1198,7 @@
     return;
   }
 
+  insert_allows(&source, buf + strlen(buf), bufsz - strlen(buf));
   if (terrain_has_flag(pterrain, TER_NO_POLLUTION)) {
     sprintf(buf + strlen(buf),
            _("* Pollution cannot be generated on this terrain."));
@@ -1242,10 +1245,9 @@
   TODO: Generalize the effects code for use elsewhere. Add
   other requirements.
 *****************************************************************/
-void helptext_government(char *buf, struct government *gov,
+void helptext_government(char *buf, size_t bufsz, struct government *gov,
                         const char *user_text)
 {
-  const size_t bufsz = 64000; /* FIXME: should be passed in */
   struct req_source source = {
     .type = REQ_GOV,
     .value = {.gov = gov }
@@ -1264,6 +1266,7 @@
 
   /* Effects */
   sprintf(buf + strlen(buf), _("Features:\n"));
+  insert_allows(&source, buf, bufsz);
   effect_list_iterate(get_req_source_effects(&source), peffect) {
     Output_type_id output_type = O_LAST;
     struct unit_class *unitclass = NULL;
Index: client/helpdata.h
===================================================================
--- client/helpdata.h   (revision 11589)
+++ client/helpdata.h   (working copy)
@@ -42,10 +42,10 @@
                        const char *user_text);
 void helptext_unit(char *buf, struct unit_type *punittype,
                   const char *user_text);
-void helptext_tech(char *buf, int i, const char *user_text);
-void helptext_terrain(char *buf, const struct terrain *pterrain,
+void helptext_tech(char *buf, size_t bufsz, int i, const char *user_text);
+void helptext_terrain(char *buf, size_t bufsz, struct terrain *pterrain,
                      const char *user_text);
-void helptext_government(char *buf, struct government *gov,
+void helptext_government(char *buf, size_t bufsz, struct government *gov,
                         const char *user_text);
 
 char *helptext_unit_upkeep_str(struct unit_type *punittype);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#15566) add missing helptext, Jason Short <=