Author: cazfi
Date: Sun Nov  1 21:48:10 2015
New Revision: 30365

URL: http://svn.gna.org/viewcvs/freeciv?rev=30365&view=rev
Log:
Do not show nonsensical progress percentage for IF_GOLD build targets in 
sdl-clients' worklist
editor.

See patch #6510

Modified:
    branches/S2_5/client/gui-sdl/wldlg.c

Modified: branches/S2_5/client/gui-sdl/wldlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-sdl/wldlg.c?rev=30365&r1=30364&r2=30365&view=diff
==============================================================================
--- branches/S2_5/client/gui-sdl/wldlg.c        (original)
+++ branches/S2_5/client/gui-sdl/wldlg.c        Sun Nov  1 21:48:10 2015
@@ -859,19 +859,20 @@
   }
 }
 
-/*
- * return progress icon (bar) of current production state
- * stock - current shielsd stocks
- * cost - unit/imprv. cost
- * function return in "proggres" pointer (0 - 100 %) progress in numbers
-*/
+/**************************************************************************
+  Return progress icon (bar) of current production state
+  stock - current shields stocks
+  cost - unit/imprv. cost
+  function return in "progress" pointer (0 - 100 %) progress in numbers
+**************************************************************************/
 static SDL_Surface * get_progress_icon(int stock, int cost, int *progress)
 {
   SDL_Surface *pIcon = NULL;
   int width;
+
   fc_assert_ret_val(progress != NULL, NULL);
-  
-  if(stock < cost) {
+
+  if (stock < cost) {
     width = ((float)stock / cost) * adj_size(116.0);
     *progress = ((float)stock / cost) * 100.0;
     if(!width && stock) {
@@ -904,27 +905,26 @@
   int cost, turns;
   char cBuf[64];
   SDL_Rect area;
+  bool gold_prod = 
improvement_has_flag(pEditor->currently_building.value.building, IF_GOLD);
   const char *name = get_production_name(pEditor->pCity,
-                               pEditor->currently_building, &cost);
-
-  if (VUT_IMPROVEMENT == pEditor->currently_building.kind
-     && improvement_has_flag(pEditor->currently_building.value.building, 
IF_GOLD))
-  {
+                                         pEditor->currently_building, &cost);
+
+  if (VUT_IMPROVEMENT == pEditor->currently_building.kind && gold_prod) {
     int gold = MAX(0, pEditor->pCity->surplus[O_SHIELD]);
+
     fc_snprintf(cBuf, sizeof(cBuf),
                 PL_("%s\n%d gold per turn",
                     "%s\n%d gold per turn", gold),
                 name, gold);
   } else {
-    if(stock < cost) {
+    if (stock < cost) {
       turns = city_turns_to_build(pEditor->pCity,
-                                 pEditor->currently_building, TRUE);
-      if(turns == 999)
-      {
+                                  pEditor->currently_building, TRUE);
+      if (turns == 999) {
         fc_snprintf(cBuf, sizeof(cBuf), _("%s\nblocked!"), name);
       } else {
         fc_snprintf(cBuf, sizeof(cBuf), _("%s\n%d %s"),
-                   name, turns, PL_("turn", "turns", turns));
+                    name, turns, PL_("turn", "turns", turns));
       }
     } else {
       fc_snprintf(cBuf, sizeof(cBuf), _("%s\nfinished!"), name);
@@ -936,8 +936,8 @@
   remake_label_size(pEditor->pProduction_Name);
   
   pEditor->pProduction_Name->size.x = pEditor->pEndWidgetList->area.x +
-    (adj_size(130) - pEditor->pProduction_Name->size.w)/2;
-  
+    (adj_size(130) - pEditor->pProduction_Name->size.w) / 2;
+
   area.x = pEditor->pEndWidgetList->area.x;
   area.y = pEditor->pProduction_Name->size.y;
   area.w = adj_size(130);
@@ -946,15 +946,19 @@
   if (get_wflags(pEditor->pProduction_Name) & WF_RESTORE_BACKGROUND) {
     refresh_widget_background(pEditor->pProduction_Name);
   }
-  
+
   widget_redraw(pEditor->pProduction_Name);
   sdl_dirty_rect(area);
-  
+
   FREESURFACE(pEditor->pProduction_Progres->theme);
   pEditor->pProduction_Progres->theme =
-                 get_progress_icon(stock, cost, &cost);
-    
-  fc_snprintf(cBuf, sizeof(cBuf), "%d%%" , cost);
+    get_progress_icon(stock, cost, &cost);
+
+  if (!gold_prod) {
+    fc_snprintf(cBuf, sizeof(cBuf), "%d%%" , cost);
+  } else {
+    fc_snprintf(cBuf, sizeof(cBuf), "-" );
+  }
   copy_chars_to_string16(pEditor->pProduction_Progres->string16, cBuf);
   widget_redraw(pEditor->pProduction_Progres);
   widget_mark_dirty(pEditor->pProduction_Progres);
@@ -1106,24 +1110,25 @@
     /* count == cost */
     /* turns == progress */
     const char *name = city_production_name_translation(pCity);
+    bool gold_prod = city_production_has_flag(pCity, IF_GOLD);
+
     count = city_production_build_shield_cost(pCity);
-    
-    if (city_production_has_flag(pCity, IF_GOLD))
-    {
+
+    if (gold_prod) {
       int gold = MAX(0, pCity->surplus[O_SHIELD]);
+
       fc_snprintf(cBuf, sizeof(cBuf),
                   PL_("%s\n%d gold per turn",
                       "%s\n%d gold per turn", gold),
                   name, gold);
     } else {
-      if(pCity->shield_stock < count) {
+      if (pCity->shield_stock < count) {
         turns = city_production_turns_to_build(pCity, TRUE);
-        if(turns == 999)
-        {
+        if (turns == 999) {
           fc_snprintf(cBuf, sizeof(cBuf), _("%s\nblocked!"), name);
         } else {
           fc_snprintf(cBuf, sizeof(cBuf), _("%s\n%d %s"),
-                   name, turns, PL_("turn", "turns", turns));
+                      name, turns, PL_("turn", "turns", turns));
         }
       } else {
         fc_snprintf(cBuf, sizeof(cBuf), _("%s\nfinished!"), name);
@@ -1132,19 +1137,23 @@
     pStr = create_str16_from_char(cBuf, adj_font(10));
     pStr->style |= SF_CENTER;
     pBuf = create_iconlabel(NULL, pWindow->dst, pStr, WF_RESTORE_BACKGROUND);
-    
+
     pEditor->pProduction_Name = pBuf;
     add_to_gui_list(ID_LABEL, pBuf);
-    
+
     pIcon = get_progress_icon(pCity->shield_stock, count, &turns);
-    
-    fc_snprintf(cBuf, sizeof(cBuf), "%d%%" , turns);
+
+    if (!gold_prod) {
+      fc_snprintf(cBuf, sizeof(cBuf), "%d%%" , turns);
+    } else {
+      fc_snprintf(cBuf, sizeof(cBuf), "-");
+    }
     pStr = create_str16_from_char(cBuf, adj_font(12));
     pStr->style |= (TTF_STYLE_BOLD|SF_CENTER);
-    
+
     pBuf = create_iconlabel(pIcon, pWindow->dst, pStr,
-               (WF_RESTORE_BACKGROUND|WF_ICON_CENTER|WF_FREE_THEME));
-    
+                            
(WF_RESTORE_BACKGROUND|WF_ICON_CENTER|WF_FREE_THEME));
+
     pIcon = NULL;
     turns = 0;
     pEditor->pProduction_Progres = pBuf;
@@ -1155,7 +1164,7 @@
                                   adj_size(120), WF_RESTORE_BACKGROUND);
     pBuf->action = rename_worklist_editor_callback;
     set_wstate(pBuf, FC_WS_NORMAL);
-    
+
     add_to_gui_list(ID_EDIT, pBuf);
   }
   


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

Reply via email to