Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2005:
[Freeciv-Dev] (PR#13663) better science dialog progressbar text
Home

[Freeciv-Dev] (PR#13663) better science dialog progressbar text

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13663) better science dialog progressbar text
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 12 Aug 2005 20:58:43 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch adds the turns-to-complete info to the text in the science 
dialog progress bar.

-jason

Index: client/text.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/text.c,v
retrieving revision 1.45
diff -p -u -r1.45 text.c
--- client/text.c       22 Jul 2005 01:44:59 -0000      1.45
+++ client/text.c       13 Aug 2005 03:55:31 -0000
@@ -416,6 +416,43 @@ const char *science_dialog_text(void)
 }
 
 /****************************************************************************
+  Get the short science-target text.  This is usually shown directly in
+  the progress bar.
+
+     5/28 - 3 turns
+
+  The "percent" value, if given, will be set to the completion percentage
+  of the research target (actually it's a [0,1] scale not a percent).
+****************************************************************************/
+const char *get_science_target_text(double *percent)
+{
+  struct player_research *research = get_player_research(game.player_ptr);
+  static struct astring str = ASTRING_INIT;
+
+  astr_clear(&str);
+  if (research->researching == A_UNSET) {
+    astr_add(&str, _("%d/- (never)"), research->bulbs_researched);
+    if (percent) {
+      *percent = 0.0;
+    }
+  } else {
+    int total = total_bulbs_required(game.player_ptr);
+    int done = research->bulbs_researched;
+    int perturn = get_bulbs_per_turn(NULL, NULL);
+    int turns = (total - done + perturn - 1) / perturn;
+
+    astr_add(&str, PL_("%d/%d (%d turn)", "%d/%d (%d turns)", turns),
+            done, total, turns);
+    if (percent) {
+      *percent = (double)done / (double)total;
+      *percent = CLIP(0.0, *percent, 1.0);
+    }
+  }
+
+  return str.str;
+}
+
+/****************************************************************************
   Set the science-goal-label text as if we're researching the given goal.
 ****************************************************************************/
 const char *get_science_goal_text(Tech_type_id goal)
Index: client/text.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/text.h,v
retrieving revision 1.13
diff -p -u -r1.13 text.h
--- client/text.h       5 May 2005 20:26:13 -0000       1.13
+++ client/text.h       13 Aug 2005 03:55:31 -0000
@@ -27,6 +27,7 @@ const char *concat_tile_activity_text(st
 const char *get_nearest_city_text(struct city *pcity, int sq_dist);
 const char *unit_description(struct unit *punit);
 const char *science_dialog_text(void);
+const char *get_science_target_text(double *percent);
 const char *get_science_goal_text(Tech_type_id goal);
 const char *get_info_label_text(void);
 const char *get_bulb_tooltip(void);
Index: client/gui-gtk-2.0/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/repodlgs.c,v
retrieving revision 1.96
diff -p -u -r1.96 repodlgs.c
--- client/gui-gtk-2.0/repodlgs.c       11 Aug 2005 04:43:25 -0000      1.96
+++ client/gui-gtk-2.0/repodlgs.c       13 Aug 2005 03:55:31 -0000
@@ -339,20 +339,8 @@ void create_science_dialog(bool make_mod
 ****************************************************************************/
 static void update_science_text(void)
 {
-  char text[512];
-  gdouble pct;
-  struct player_research *research = get_player_research(game.player_ptr);
-
-  if (research->researching == A_UNSET) {
-    my_snprintf(text, sizeof(text), "%d/-", research->bulbs_researched);
-    pct = 0.0;
-  } else {
-    my_snprintf(text, sizeof(text), "%d/%d",
-               research->bulbs_researched,
-               total_bulbs_required(game.player_ptr));
-    pct = CLAMP((gdouble) research->bulbs_researched
-               / total_bulbs_required(game.player_ptr), 0.0, 1.0);
-  }
+  double pct;
+  const char *text = get_science_target_text(&pct);
 
   gtk_progress_bar_set_text(GTK_PROGRESS_BAR(science_current_label), text);
   gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(science_current_label), pct);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13663) better science dialog progressbar text, Jason Short <=