Author: sveinung
Date: Thu Dec 11 12:20:28 2014
New Revision: 27254

URL: http://svn.gna.org/viewcvs/freeciv?rev=27254&view=rev
Log:
Qt client: make the Help Wonder button's custom info label creation more robust.

See patch #5528

Modified:
    trunk/client/gui-qt/dialogs.cpp

Modified: trunk/client/gui-qt/dialogs.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/dialogs.cpp?rev=27254&r1=27253&r2=27254&view=diff
==============================================================================
--- trunk/client/gui-qt/dialogs.cpp     (original)
+++ trunk/client/gui-qt/dialogs.cpp     Thu Dec 11 12:20:28 2014
@@ -1208,16 +1208,21 @@
 }
 
 /**************************************************************************
-  Returns custom information for the help build wonder button about how
-  many shields remains of the current production.
-***************************************************************************/
-static QString label_help_wonder_rem(struct city *target_city)
-{
-  QString label = QString(_("%1 remaining")).arg(
-      impr_build_shield_cost(target_city->production.value.building)
-      - target_city->shield_stock);
-
-  return label;
+  Returns a string with how many shields remains of the current production.
+  This is useful as custom information on the help build wonder button.
+***************************************************************************/
+static QString city_prod_remaining(struct city *target_city)
+{
+  if (target_city == nullptr
+      || city_owner(target_city) != client.conn.playing) {
+    /* Can't give remaining production for a foreign or non existing
+     * city. */
+    return "";
+  }
+
+  return QString(_("%1 remaining")).arg(
+        impr_build_shield_cost(target_city->production.value.building)
+        - target_city->shield_stock);
 }
 
 /**************************************************************************
@@ -1369,13 +1374,11 @@
                "",
                qv1, qv2);
 
-  if (action_prob_possible(act_probs[ACTION_HELP_WONDER])) {
-    action_entry(cd,
-                 ACTION_HELP_WONDER,
-                 act_probs,
-                 label_help_wonder_rem(target_city),
-                 qv1, qv2);
-  }
+  action_entry(cd,
+               ACTION_HELP_WONDER,
+               act_probs,
+               city_prod_remaining(target_city),
+               qv1, qv2);
 
   /* Spy/Diplomat acting against a unit */
 
@@ -2141,7 +2144,7 @@
     if (action_prob_possible(act_prob[act])
         && act == ACTION_HELP_WONDER) {
       /* Add information about how far along the wonder is. */
-      custom = label_help_wonder_rem(target_city);
+      custom = city_prod_remaining(target_city);
     } else {
       custom = "";
     }


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

Reply via email to