Author: sveinung
Date: Wed Nov 26 11:04:18 2014
New Revision: 27131

URL: http://svn.gna.org/viewcvs/freeciv?rev=27131&view=rev
Log:
Make it possible for the client to insert custom text in an action UI name.

Some clients adds extra information to caravan actions. Make it possible to keep
doing this when caravan actions are action enabler controlled.

See patch #5458

Modified:
    trunk/client/gui-gtk-2.0/action_dialog.c
    trunk/client/gui-gtk-3.0/action_dialog.c
    trunk/client/gui-qt/dialogs.cpp
    trunk/client/gui-sdl/action_dialog.c
    trunk/client/gui-sdl2/action_dialog.c
    trunk/client/gui-xaw/action_dialog.c
    trunk/common/actions.c
    trunk/common/actions.h

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=27131&r1=27130&r2=27131&view=diff
==============================================================================
--- trunk/client/gui-gtk-2.0/action_dialog.c    (original)
+++ trunk/client/gui-gtk-2.0/action_dialog.c    Wed Nov 26 11:04:18 2014
@@ -998,7 +998,7 @@
   }
 
   label = action_prepare_ui_name(action_id, "_",
-                                 action_probabilities[action_id]);
+                                 action_probabilities[action_id], NULL);
 
   tooltip = action_get_tool_tip(action_id,
                                 action_probabilities[action_id]);
@@ -1026,7 +1026,7 @@
 
   /* The probability may have changed. */
   label = action_prepare_ui_name(action_id, "_",
-                                 act_prob[action_id]);
+                                 act_prob[action_id], NULL);
 
   tooltip = action_get_tool_tip(action_id,
                                 act_prob[action_id]);

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=27131&r1=27130&r2=27131&view=diff
==============================================================================
--- trunk/client/gui-gtk-3.0/action_dialog.c    (original)
+++ trunk/client/gui-gtk-3.0/action_dialog.c    Wed Nov 26 11:04:18 2014
@@ -1008,7 +1008,7 @@
   }
 
   label = action_prepare_ui_name(action_id, "_",
-                                 action_probabilities[action_id]);
+                                 action_probabilities[action_id], NULL);
 
   tooltip = action_get_tool_tip(action_id,
                                 action_probabilities[action_id]);
@@ -1036,7 +1036,7 @@
 
   /* The probability may have changed. */
   label = action_prepare_ui_name(action_id, "_",
-                                 act_prob[action_id]);
+                                 act_prob[action_id], NULL);
 
   tooltip = action_get_tool_tip(action_id,
                                 act_prob[action_id]);

Modified: trunk/client/gui-qt/dialogs.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/dialogs.cpp?rev=27131&r1=27130&r2=27131&view=diff
==============================================================================
--- trunk/client/gui-qt/dialogs.cpp     (original)
+++ trunk/client/gui-qt/dialogs.cpp     Wed Nov 26 11:04:18 2014
@@ -1419,7 +1419,7 @@
   }
 
   title = QString(action_prepare_ui_name(act, "&",
-                                         action_probabilities[act]));
+                                         action_probabilities[act], NULL));
 
   tool_tip = QString(action_get_tool_tip(act, action_probabilities[act]));
 
@@ -1443,7 +1443,7 @@
 
   /* The probability may have changed. */
   title = QString(action_prepare_ui_name(act, "&",
-                                         act_prob[act]));
+                                         act_prob[act], NULL));
 
   tool_tip = QString(action_get_tool_tip(act, act_prob[act]));
 

Modified: trunk/client/gui-sdl/action_dialog.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl/action_dialog.c?rev=27131&r1=27130&r2=27131&view=diff
==============================================================================
--- trunk/client/gui-sdl/action_dialog.c        (original)
+++ trunk/client/gui-sdl/action_dialog.c        Wed Nov 26 11:04:18 2014
@@ -727,7 +727,8 @@
     return;
   }
 
-  ui_name = action_prepare_ui_name(act, "", action_probabilities[act]);
+  ui_name = action_prepare_ui_name(act, "",
+                                   action_probabilities[act], NULL);
 
   create_active_iconlabel(pBuf, pWindow->dst, pStr,
                           ui_name, af_map[act]);

Modified: trunk/client/gui-sdl2/action_dialog.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/action_dialog.c?rev=27131&r1=27130&r2=27131&view=diff
==============================================================================
--- trunk/client/gui-sdl2/action_dialog.c       (original)
+++ trunk/client/gui-sdl2/action_dialog.c       Wed Nov 26 11:04:18 2014
@@ -735,7 +735,8 @@
     return;
   }
 
-  ui_name = action_prepare_ui_name(act, "", action_probabilities[act]);
+  ui_name = action_prepare_ui_name(act, "",
+                                   action_probabilities[act], NULL);
 
   create_active_iconlabel(pBuf, pWindow->dst, pStr,
                           ui_name, af_map[act]);

Modified: trunk/client/gui-xaw/action_dialog.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-xaw/action_dialog.c?rev=27131&r1=27130&r2=27131&view=diff
==============================================================================
--- trunk/client/gui-xaw/action_dialog.c        (original)
+++ trunk/client/gui-xaw/action_dialog.c        Wed Nov 26 11:04:18 2014
@@ -823,7 +823,7 @@
 
   XtSetArg(arglist[0], "label",
            action_prepare_ui_name(action_id, "",
-                                  action_probabilities[action_id]));
+                                  action_probabilities[action_id], NULL));
   XtSetValues(w, arglist, XtNumber(arglist));
 }
 

Modified: trunk/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=27131&r1=27130&r2=27131&view=diff
==============================================================================
--- trunk/common/actions.c      (original)
+++ trunk/common/actions.c      Wed Nov 26 11:04:18 2014
@@ -190,19 +190,24 @@
 **************************************************************************/
 const char *action_get_ui_name(int action_id)
 {
-  return action_prepare_ui_name(action_id, "", ACTPROB_NA);
+  return action_prepare_ui_name(action_id, "", ACTPROB_NA, NULL);
 }
 
 /**************************************************************************
   Get the UI name ready to show the action in the UI. It is possible to
   add a client specific mnemonic. Success probability information is
-  interpreted and added to the text.
+  interpreted and added to the text. A custom text can be inserted before
+  the probability information.
 **************************************************************************/
 const char *action_prepare_ui_name(int action_id, const char* mnemonic,
-                                   const action_probability prob)
+                                   const action_probability prob,
+                                   const char* custom)
 {
   static struct astring str = ASTRING_INIT;
   static struct astring chance = ASTRING_INIT;
+
+  /* Text representation of the probability. */
+  const char* probtxt;
 
   /* How to interpret action probabilities like prob is documented in
    * actions.h */
@@ -210,16 +215,20 @@
   case ACTPROB_NOT_KNOWN:
     /* Unknown because the player don't have the required knowledge to
      * determine the probability of success for this action. */
+
     /* TRANS: the chance of a diplomat action succeeding is unknown. */
-    astr_set(&chance, _(" (?%%)"));
+    probtxt = _("?%");
+
     break;
   case ACTPROB_NOT_IMPLEMENTED:
     /* Unknown because of missing server support. */
-    astr_clear(&chance);
+    probtxt = NULL;
+
     break;
   case ACTPROB_NA:
     /* Should not exist */
-    astr_clear(&chance);
+    probtxt = NULL;
+
     break;
   case ACTPROB_IMPOSSIBLE:
     /* ACTPROB_IMPOSSIBLE is a 0% probability of success */
@@ -229,8 +238,25 @@
                   "Diplomat action probability out of range");
 
     /* TRANS: the probability that a diplomat action will succeed. */
-    astr_set(&chance, _(" (%.1f%%)"), (double)prob / 2);
-    break;
+    astr_set(&chance, _("%.1f%%"), (double)prob / 2);
+    probtxt = astr_str(&chance);
+
+    break;
+  }
+
+  /* Format the info part of the action's UI name. */
+  if (probtxt != NULL && custom != NULL) {
+    /* TRANS: action UI name's info part with custom info and probabilty. */
+    astr_set(&chance, _(" (%s; %s)"), custom, probtxt);
+  } else if (probtxt != NULL) {
+    /* TRANS: action UI name's info part with probabilty. */
+    astr_set(&chance, _(" (%s)"), probtxt);
+  } else if (custom != NULL) {
+    /* TRANS: action UI name's info part with custom info. */
+    astr_set(&chance, _(" (%s)"), custom);
+  } else {
+    /* No info part to display. */
+    astr_clear(&chance);
   }
 
   fc_assert_msg(actions[action_id], "Action %d don't exist.", action_id);

Modified: trunk/common/actions.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.h?rev=27131&r1=27130&r2=27131&view=diff
==============================================================================
--- trunk/common/actions.h      (original)
+++ trunk/common/actions.h      Wed Nov 26 11:04:18 2014
@@ -168,7 +168,8 @@
 const char *action_get_rule_name(int action_id);
 const char *action_get_ui_name(int action_id);
 const char *action_prepare_ui_name(int action_id, const char* mnemonic,
-                                   const action_probability prob);
+                                   const action_probability prob,
+                                   const char *custom);
 const char *action_get_tool_tip(const int action_id,
                                 const action_probability act_prob);
 


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

Reply via email to