diff -Nur -Xfreeciv/diff_ignore freeciv/client/gui-gtk/citydlg.c newcitydlg/client/gui-gtk/citydlg.c --- freeciv/client/gui-gtk/citydlg.c Sat Dec 8 09:15:51 2001 +++ newcitydlg/client/gui-gtk/citydlg.c Fri Dec 28 14:00:25 2001 @@ -309,8 +309,7 @@ gpointer data); static void close_city_dialog(struct city_dialog *pdialog); static void close_callback(GtkWidget * w, gpointer data); -static void prev_callback(GtkWidget * w, gpointer data); -static void next_callback(GtkWidget * w, gpointer data); +static void switch_city_callback(GtkWidget * w, gpointer data); /**************************************************************** ... @@ -1529,10 +1528,10 @@ GTK_SIGNAL_FUNC(close_callback), pdialog); gtk_signal_connect(GTK_OBJECT(pdialog->prev_command), "clicked", - GTK_SIGNAL_FUNC(prev_callback), pdialog); + GTK_SIGNAL_FUNC(switch_city_callback), pdialog); gtk_signal_connect(GTK_OBJECT(pdialog->next_command), "clicked", - GTK_SIGNAL_FUNC(next_callback), pdialog); + GTK_SIGNAL_FUNC(switch_city_callback), pdialog); gtk_widget_add_accelerator(close_command, "clicked", pdialog->accel, GDK_Return, 0, 0); @@ -3657,13 +3656,14 @@ city_dialog_update_prev_next(); } -/**************************************************************** -... -*****************************************************************/ -static void prev_callback(GtkWidget * w, gpointer data) +/************************************************************************ + callback for the prev/next buttons. switches to the previous/next city +*************************************************************************/ +static void switch_city_callback(GtkWidget *w, gpointer data) { struct city_dialog *pdialog = (struct city_dialog *) data; - int i, j, size = city_list_size(&game.player_ptr->cities); + int i, j, dir; + int size = city_list_size(&game.player_ptr->cities); struct city *new_pcity = NULL; assert(city_dialogs_have_been_initialised); @@ -3672,64 +3672,13 @@ if (size == 1) return; - for (i = 0; i < size; i++) { - struct city *pcity = city_list_get(&game.player_ptr->cities, i); - - if (pdialog->pcity == pcity) { - break; - } - } - - assert(i < size); - - for (j = 1; j < size; j++) { - struct city *pcity2 = - city_list_get(&game.player_ptr->cities, (i - j + size) % size); - struct city_dialog *pdialog2 = get_city_dialog(pcity2); - - assert(pdialog2 != pdialog); - if (!pdialog2) { - new_pcity = pcity2; - break; - } - } - - if (!new_pcity) - return; - - if (pdialog->wl_editor->changed - && pdialog->pcity->owner == game.player_idx) { - commit_worklist(pdialog->wl_editor); - } - close_happiness_dialog(pdialog->pcity); - pdialog->pcity = new_pcity; - gtk_box_pack_start(GTK_BOX(pdialog->happiness.widget), - get_top_happiness_display(pdialog->pcity), TRUE, TRUE, - 0); - pdialog->wl_editor->pcity = new_pcity; - pdialog->wl_editor->pwl = new_pcity->worklist; - pdialog->wl_editor->user_data = (void *) pdialog; - update_worklist_editor(pdialog->wl_editor); - center_tile_mapcanvas(pdialog->pcity->x, pdialog->pcity->y); - set_cityopt_values(pdialog); /* perhaps this should be in refresh_? */ - refresh_city_dialog(pdialog->pcity); - select_impr_list_callback(NULL, 0, 0, NULL, pdialog); /* unselects clist */ -} - -/**************************************************************** -... -*****************************************************************/ -static void next_callback(GtkWidget * w, gpointer data) -{ - struct city_dialog *pdialog = (struct city_dialog *) data; - int i, j, size = city_list_size(&game.player_ptr->cities); - struct city *new_pcity = NULL; - - assert(city_dialogs_have_been_initialised); - assert(size >= 1); - - if (size == 1) - return; + /* dir = 1 will advance the city, dir = -1 will get previous */ + if(w == pdialog->next_command) + dir = 1; + else if(w == pdialog->prev_command) + dir = -1; + else + assert(0); for (i = 0; i < size; i++) { struct city *pcity = city_list_get(&game.player_ptr->cities, i); @@ -3743,7 +3692,7 @@ for (j = 1; j < size; j++) { struct city *pcity2 = - city_list_get(&game.player_ptr->cities, (i + j + size) % size); + city_list_get(&game.player_ptr->cities, (i + dir * j + size) % size); struct city_dialog *pdialog2 = get_city_dialog(pcity2); assert(pdialog2 != pdialog);