? diff Index: client/cityrepdata.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/cityrepdata.c,v retrieving revision 1.10 diff -u -r1.10 cityrepdata.c --- client/cityrepdata.c 2001/06/26 18:04:01 1.10 +++ client/cityrepdata.c 2001/09/15 22:20:20 @@ -214,13 +214,13 @@ FUNC_TAG(output) }, { 0, 1, 1, N_("n"), N_("T"), N_("Number of Trade Routes"), FUNC_TAG(num_trade) }, - { 1, 7, 1, N_("Food"), N_("Stock"), N_("Food Stock"), + { 1, 7, 1, N_("Food"), N_("Stock/Limit"), N_("Food Stock"), FUNC_TAG(food) }, { 0, 3, 1, NULL, N_("Pol"), N_("Pollution"), FUNC_TAG(pollution) }, { 0, 3, 1, NULL, N_("Cor"), N_("Corruption"), FUNC_TAG(corruption) }, - { 1, 0, 1, N_("Currently Building"), N_("(Stock,Target,Turns,Buy)"), + { 1, 0, 1, N_("Currently Building"), N_("Name (Stock,Target,Turns,Buy)"), N_("Currently Building"), FUNC_TAG(building) } }; Index: client/gui-gtk/cityrep.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/cityrep.c,v retrieving revision 1.41 diff -u -r1.41 cityrep.c --- client/gui-gtk/cityrep.c 2001/09/15 19:47:04 1.41 +++ client/gui-gtk/cityrep.c 2001/09/15 22:20:21 @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -42,6 +43,7 @@ #include "options.h" #include "repodlgs.h" #include "climisc.h" +#include "log.h" #include "cityrep.h" @@ -82,57 +84,163 @@ static GtkWidget *city_select_command; static int city_dialog_shell_is_modal; +static int sorting = 0; -/* - * Sort cities by column... - */ -static void sort_cities_callback( GtkButton *button, gpointer *data ) +static gint my_sort(GtkCList * clist, + gconstpointer ptr1, gconstpointer ptr2) { - int sort_column = GPOINTER_TO_INT( data ); + int sort_item = sorting / 2; + GtkCListRow *row1 = (GtkCListRow *) ptr1; + GtkCListRow *row2 = (GtkCListRow *) ptr2; + struct city *pcity1 = (struct city *) row1->data; + struct city *pcity2 = (struct city *) row2->data; + char buffer1[200], buffer2[200]; + char items1[10][100], items2[10][100]; + int items1_used, items2_used; + int scanned1, scanned2, number1, number2; + int result; + + if (!pcity1 || !pcity2) + return 0; + freelog(LOG_DEBUG, " '%s' <-> '%s'", pcity1->name, pcity2->name); + + mystrlcpy(buffer1, + city_report_specs[GTK_CLIST(city_list)-> + sort_column].func(pcity1), sizeof(buffer1)); + + mystrlcpy(buffer2, + city_report_specs[GTK_CLIST(city_list)-> + sort_column].func(pcity2), sizeof(buffer2)); - if ( sort_column == GTK_CLIST( city_list )->sort_column ) + freelog(LOG_DEBUG, " '%s' <-> '%s'", buffer1, buffer2); + { - if ( GTK_CLIST( city_list )->sort_type == GTK_SORT_ASCENDING ) - gtk_clist_set_sort_type( GTK_CLIST( city_list ), GTK_SORT_DESCENDING ); - else - gtk_clist_set_sort_type( GTK_CLIST( city_list ), GTK_SORT_ASCENDING ); - gtk_clist_sort( GTK_CLIST( city_list ) ); + char *tok, *s = buffer1; + items1_used = 0; + while ((tok = strtok(s, "/(),")) != NULL) { + mystrlcpy(items1[items1_used], tok, sizeof(items1[0])); + items1_used++; + s = NULL; + } } - else + { - gtk_clist_set_sort_column( GTK_CLIST( city_list ), sort_column ); - gtk_clist_sort( GTK_CLIST( city_list ) ); + char *tok, *s = buffer2; + items2_used = 0; + while ((tok = strtok(s, "/(),")) != NULL) { + mystrlcpy(items2[items2_used], tok, sizeof(items2[0])); + items2_used++; + s = NULL; + } + } + + assert(items1_used == items2_used); + + scanned1 = sscanf(items1[sort_item % items1_used], "%d", &number1); + scanned2 = sscanf(items2[sort_item % items2_used], "%d", &number2); + + freelog(LOG_DEBUG, " %d %d <-> %d %d", scanned1, number1, scanned2, + number2); + + if (scanned1 == 1 && scanned2 == 1) { + if (number1 != number2) { + result = number1 - number2; + } else { + result = strcmp(buffer1, buffer2); + } + } else if (scanned1 == 0 && scanned2 == 0) { + result = strcmp(buffer1, buffer2); + } else { + result = -1; } + + if (sorting % 2) + result = -result; + return result; } /**************************************************************** - Create the text for a line in the city report +... *****************************************************************/ -static void get_city_text(struct city *pcity, char *buf[], int n) +static void refresh_city_table_header(GtkCList * clist) { struct city_report_spec *spec; - int i; + int i, sort_column = clist->sort_column; + char buffer[200], second_line[200]; - for(i=0, spec=city_report_specs; ishow) continue; + for (i = 0, spec = city_report_specs; i < NUM_CREPORT_COLS; i++, spec++) { + char *tok, buffer2[200], *s; + int items, j; + + if (!_(spec->title2)) { + second_line[0] = 0; + } else { + mystrlcpy(buffer2, _(spec->title2), sizeof(buffer2)); + s = buffer2; + items = 0; + while ((tok = strtok(s, "/(),")) != NULL) { + items++; + s = NULL; + } + + mystrlcpy(buffer2, _(spec->title2), sizeof(buffer2)); + s = buffer2; + j = 0; + second_line[0] = 0; + while ((tok = strtok(s, "/(),")) != NULL) { + mystrlcat(second_line, tok, sizeof(second_line)); + mystrlcat(second_line, " ", sizeof(second_line)); + if (i == sort_column && j == ((sorting / 2) % items)) { + mystrlcat(second_line, sorting % 2 ? _("^") : _("v"), + sizeof(second_line)); + } else { + mystrlcat(second_line, " ", sizeof(second_line)); + } + j++; + if (j < items) { + mystrlcat(second_line, "/", sizeof(second_line)); + } + s = NULL; + } + } + my_snprintf(buffer, sizeof(buffer), "%*s\n%*s", + NEG_VAL(spec->width), spec->title1 ? _(spec->title1) : "", + NEG_VAL(spec->width), second_line); + gtk_clist_set_column_title(clist, i, buffer); + } +} - my_snprintf(buf[i], n, "%*s", NEG_VAL(spec->width), (spec->func)(pcity)); +/* + * Sort cities by column... + */ +static void sort_cities_callback(GtkButton * button, gpointer * data) +{ + int sort_column = GPOINTER_TO_INT(data); + + if (sort_column == GTK_CLIST(city_list)->sort_column) { + sorting++; + } else { + gtk_clist_set_sort_column(GTK_CLIST(city_list), sort_column); + sorting = 0; } + + gtk_clist_sort(GTK_CLIST(city_list)); + refresh_city_table_header(GTK_CLIST(city_list)); } /**************************************************************** - Return text line for the column headers for the city report + Create the text for a line in the city report *****************************************************************/ -static void get_city_table_header(char *text[], int n) +static void get_city_text(struct city *pcity, char *buf[], int n) { struct city_report_spec *spec; int i; for(i=0, spec=city_report_specs; iwidth), spec->title1 ? _(spec->title1) : "", - NEG_VAL(spec->width), spec->title2 ? _(spec->title2) : ""); + buf[i][0]='\0'; + if(!spec->show) continue; + + my_snprintf(buf[i], n, "%*s", NEG_VAL(spec->width), (spec->func)(pcity)); } } @@ -418,9 +526,6 @@ *****************************************************************/ static void create_city_report_dialog(int make_modal) { - static char *titles [NUM_CREPORT_COLS]; - static char buf [NUM_CREPORT_COLS][64]; - GtkWidget *close_command, *scrolled; int i; GtkAccelGroup *accel=gtk_accel_group_new(); @@ -431,16 +536,14 @@ gtk_accel_group_attach(accel, GTK_OBJECT(city_dialog_shell)); gtk_window_set_title(GTK_WINDOW(city_dialog_shell),_("Cities")); - - for (i=0;i