Author: sveinung Date: Thu Dec 11 12:20:38 2014 New Revision: 27255 URL: http://svn.gna.org/viewcvs/freeciv?rev=27255&view=rev Log: Gtk clients: make the Help Wonder button's custom info label creation more robust.
See patch #5529 Modified: trunk/client/gui-gtk-2.0/action_dialog.c trunk/client/gui-gtk-3.0/action_dialog.c Modified: trunk/client/gui-gtk-2.0/action_dialog.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-2.0/action_dialog.c?rev=27255&r1=27254&r2=27255&view=diff ============================================================================== --- trunk/client/gui-gtk-2.0/action_dialog.c (original) +++ trunk/client/gui-gtk-2.0/action_dialog.c Thu Dec 11 12:20:38 2014 @@ -172,15 +172,22 @@ } /************************************************************************** - Returns custom information for the help build wonder button about how - many shields remains of the current production. + 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 const gchar *help_build_wonder_label_info(struct city* destcity) -{ - return g_strdup_printf(_("%d remaining"), - impr_build_shield_cost( - destcity->production.value.building) - - destcity->shield_stock); +static const gchar *city_prod_remaining(struct city* destcity) +{ + if (destcity == NULL + || city_owner(destcity) != client.conn.playing) { + /* Can't give remaining production for a foreign or non existing + * city. */ + return NULL; + } + + return g_strdup_printf(_("%d remaining"), + impr_build_shield_cost( + destcity->production.value.building) + - destcity->shield_stock); } /********************************************************************** @@ -1134,15 +1141,11 @@ NULL, data); - if (action_prob_possible(act_probs[ACTION_HELP_WONDER])) { - const gchar *wonder = help_build_wonder_label_info(target_city); - - action_entry(shl, - ACTION_HELP_WONDER, - act_probs, - wonder, - data); - } + action_entry(shl, + ACTION_HELP_WONDER, + act_probs, + city_prod_remaining(target_city), + data); /* Spy/Diplomat acting against a unit */ @@ -1266,7 +1269,7 @@ if (action_prob_possible(act_prob[act]) && act == ACTION_HELP_WONDER) { /* Add information about how far along the wonder is. */ - custom = help_build_wonder_label_info(target_city); + custom = city_prod_remaining(target_city); } else { custom = NULL; } Modified: trunk/client/gui-gtk-3.0/action_dialog.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/action_dialog.c?rev=27255&r1=27254&r2=27255&view=diff ============================================================================== --- trunk/client/gui-gtk-3.0/action_dialog.c (original) +++ trunk/client/gui-gtk-3.0/action_dialog.c Thu Dec 11 12:20:38 2014 @@ -172,15 +172,22 @@ } /************************************************************************** - Returns custom information for the help build wonder button about how - many shields remains of the current production. + 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 const gchar *help_build_wonder_label_info(struct city* destcity) -{ - return g_strdup_printf(_("%d remaining"), - impr_build_shield_cost( - destcity->production.value.building) - - destcity->shield_stock); +static const gchar *city_prod_remaining(struct city* destcity) +{ + if (destcity == NULL + || city_owner(destcity) != client.conn.playing) { + /* Can't give remaining production for a foreign or non existing + * city. */ + return NULL; + } + + return g_strdup_printf(_("%d remaining"), + impr_build_shield_cost( + destcity->production.value.building) + - destcity->shield_stock); } /********************************************************************** @@ -1144,15 +1151,11 @@ NULL, data); - if (action_prob_possible(act_probs[ACTION_HELP_WONDER])) { - const gchar *wonder = help_build_wonder_label_info(target_city); - - action_entry(shl, - ACTION_HELP_WONDER, - act_probs, - wonder, - data); - } + action_entry(shl, + ACTION_HELP_WONDER, + act_probs, + city_prod_remaining(target_city), + data); /* Spy/Diplomat acting against a unit */ @@ -1276,7 +1279,7 @@ if (action_prob_possible(act_prob[act]) && act == ACTION_HELP_WONDER) { /* Add information about how far along the wonder is. */ - custom = help_build_wonder_label_info(target_city); + custom = city_prod_remaining(target_city); } else { custom = NULL; } _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits