[Freeciv-Dev] [patch] xaw citydlg: s/999/never/ (PR#1296)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
The attached patch makes the s/999/never/ change for the xaw citydlg
worklist and selection windows.
In the process, I've done some additional cleanups:
- Created function get_city_dialog_production_full. The name is less
than ideal. I had the parameters match those from
get_city_dialog_production_row, which this function closely corresponds to.
- Moved the code from gui-xaw/citydlg.c to citydlg_common.c. This
function can now be used by other GUI's that need this data. In
general, a GUI can probably use either ***_row or ***_full. Currently
mui and beos use neither.
- Changed capitalization to say N/turn.
The difference between ***_full and ***_row is that ***_row creates an
array of text values for the name/info/cost/turns of the production,
while ***_full puts this all into one string. The former is good for
"advanced" GUI frontends that use table structures to show the data
(like GTK), the latter for simpler GUI interfaces that prefer to use
straight text values. Unfortunately, the two functions really can't be
combined because they use different syntax for the turns entry.
After this change (or one like it) the only code that does not
special-case 999 will be the some MUI code. This code can probably use
one of these two functions, but I really can't figure it out enough to
tell how. Therefore I sent another patch (separately) to change this to
just handle it locally.
jason
Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.5
diff -u -r1.5 citydlg_common.c
--- client/citydlg_common.c 2002/03/04 09:01:14 1.5
+++ client/citydlg_common.c 2002/03/04 10:06:33
@@ -147,6 +147,51 @@
/**************************************************************************
+ Pretty sprints the info about a production (name, info, cost, turns to
+ build) into a single text string.
+
+ This is very similar to get_city_dialog_production_row; the difference is
+ that instead of placing the data into an array of strings it all goes
+ into one long string. This means it can be used by frontends that do not
+ use a tabled structure, but it also gives less flexibility. You might
+ think the two functions could be combined, but they really can't since
+ the syntax is different.
+**************************************************************************/
+void get_city_dialog_production_full(char *buffer, size_t buffer_len,
+ int id, bool is_unit,
+ struct city *pcity)
+{
+ if (!is_unit && id == B_CAPITAL) {
+ my_snprintf(buffer, buffer_len,
+ "%s (XX) %d/turn",
+ get_impr_name_ex(pcity, id),
+ pcity->shield_surplus);
+ } else {
+ int turns = city_turns_to_build(pcity, id, is_unit, TRUE);
+ char *name;
+ int cost;
+
+ if (is_unit) {
+ name = get_unit_name(id);
+ cost = get_unit_type(id)->build_cost;
+ } else {
+ name = get_impr_name_ex(pcity, id);
+ cost = get_improvement_type(id)->build_cost;
+ }
+
+ if (turns < 999) {
+ my_snprintf(buffer, buffer_len,
+ PL_("%s (%d) %d turn", "%s (%d) %d turns", turns),
+ name, cost, turns);
+ } else {
+ my_snprintf(buffer, buffer_len,
+ "%s (%d) never", name, cost);
+ }
+ }
+}
+
+
+/**************************************************************************
Pretty sprints the info about a production in 4 columns (name, info,
cost, turns to build). The columns must each have a size of
column_size bytes.
Index: client/citydlg_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.h,v
retrieving revision 1.3
diff -u -r1.3 citydlg_common.h
--- client/citydlg_common.h 2002/03/04 09:01:14 1.3
+++ client/citydlg_common.h 2002/03/04 10:06:33
@@ -21,6 +21,9 @@
void get_city_dialog_production(struct city *pcity,
char *buffer, size_t buffer_len);
+void get_city_dialog_production_full(char *buffer, size_t buffer_len,
+ int id, bool is_unit,
+ struct city *pcity);
void get_city_dialog_production_row(char *buf[], size_t column_size, int id,
bool is_unit, struct city *pcity);
Index: client/gui-xaw/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/citydlg.c,v
retrieving revision 1.69
diff -u -r1.69 citydlg.c
--- client/gui-xaw/citydlg.c 2002/03/01 10:22:57 1.69
+++ client/gui-xaw/citydlg.c 2002/03/04 10:06:34
@@ -48,7 +48,7 @@
#include "support.h"
#include "cityrep.h"
-#include "clinet.h"
+#include "citydlg.h"
#include "colors.h"
#include "control.h" /* request_xxx and set_unit_focus */
#include "dialogs.h"
@@ -60,13 +60,14 @@
#include "mapctrl.h"
#include "mapview.h"
#include "optiondlg.h" /* for toggle_callback */
-#include "options.h"
#include "repodlgs.h"
-#include "tilespec.h"
#include "wldlg.h"
-#include "climisc.h"
-#include "citydlg.h"
+#include "citydlg_common.h"
+#include "climisc.h"
+#include "clinet.h"
+#include "options.h"
+#include "tilespec.h"
#include "cityicon.ico"
@@ -2243,7 +2244,7 @@
Position x, y;
Dimension width, height;
struct city_dialog *pdialog;
- int i, n, turns;
+ int i, n;
pdialog=(struct city_dialog *)client_data;
@@ -2316,19 +2317,9 @@
for(i=0, n=0; i<game.num_impr_types; i++)
if(can_build_improvement(pdialog->pcity, i)) {
- if (i==B_CAPITAL) {
- my_snprintf(pdialog->change_list_names[n],
- sizeof(pdialog->change_list_names[n]),
- "%s (XX)",
- get_impr_name_ex(pdialog->pcity, i));
- } else {
- turns = city_turns_to_build(pdialog->pcity, i, FALSE, TRUE);
- my_snprintf(pdialog->change_list_names[n],
- sizeof(pdialog->change_list_names[n]),
- PL_("%s (%d) %d turn", "%s (%d) %d turns", turns),
- get_impr_name_ex(pdialog->pcity, i),
- get_improvement_type(i)->build_cost, turns);
- }
+ get_city_dialog_production_full(pdialog->change_list_names[n],
+ sizeof(pdialog->change_list_names[n]),
+ i, FALSE, pdialog->pcity);
pdialog->change_list_names_ptrs[n]=pdialog->change_list_names[n];
pdialog->change_list_ids[n++]=i;
}
@@ -2338,11 +2329,9 @@
for(i=0; i<game.num_unit_types; i++)
if(can_build_unit(pdialog->pcity, i)) {
- turns = city_turns_to_build(pdialog->pcity, i, TRUE, TRUE);
- my_snprintf(pdialog->change_list_names[n],
- sizeof(pdialog->change_list_names[n]),
- PL_("%s (%d) %d turn", "%s (%d) %d turns", turns),
- get_unit_name(i), get_unit_type(i)->build_cost, turns);
+ get_city_dialog_production_full(pdialog->change_list_names[n],
+ sizeof(pdialog->change_list_names[n]),
+ i, TRUE, pdialog->pcity);
pdialog->change_list_names_ptrs[n]=pdialog->change_list_names[n];
pdialog->change_list_ids[n++]=i;
}
- [Freeciv-Dev] [patch] xaw citydlg: s/999/never/ (PR#1296),
jdorje <=
|
|