? client/agents/.deps ? client/agents/Makefile ? data/macroisotrident/Makefile ? data/stdsounds/Makefile Index: client/gui-gtk/repodlgs.c =================================================================== RCS file: /cvsroot/freeciv-test/freeciv-test/client/gui-gtk/repodlgs.c,v retrieving revision 1.3 diff -u -r1.3 repodlgs.c --- client/gui-gtk/repodlgs.c 27 Feb 2002 02:26:25 -0000 1.3 +++ client/gui-gtk/repodlgs.c 13 Mar 2002 18:56:02 -0000 @@ -23,6 +23,10 @@ #include #include +#include "common/mem.h" +#include "common/unit.h" + +#include "control.h" #include "fcintl.h" #include "game.h" #include "government.h" @@ -37,6 +41,7 @@ #include "gui_main.h" #include "gui_stuff.h" #include "helpdlg.h" +#include "mapview_g.h" #include "optiondlg.h" #include "repodlgs.h" @@ -79,11 +84,22 @@ static void activeunits_refresh_callback(GtkWidget * w, gpointer data); static void activeunits_list_callback(GtkWidget * w, gint row, gint column); static void activeunits_list_ucallback(GtkWidget * w, gint row, gint column); +static void activeunits_change_prod_callback(GtkWidget *widget, gpointer data); +static void activeunits_find_nearest_callback(GtkWidget *widget, gpointer data); +static void awaken_all_callback(GtkWidget *widget, gpointer data); + + static int activeunits_type[U_LAST]; +static int activeunits_change_in_prod_up=0; +static int activeunits_starting_find_x, activeunits_starting_find_y; + static GtkWidget *activeunits_dialog_shell = NULL; static GtkWidget *activeunits_label2; static GtkWidget *activeunits_list; -static GtkWidget *upgrade_command; +static GtkWidget *upgrade_command, *change_prod_command; +static GtkWidget *find_nearest_command, *awaken_all_command; +static GtkWidget *activeunits_table; + static int activeunits_dialog_shell_is_modal; /******************************************************************/ @@ -844,23 +860,49 @@ gtk_box_pack_start( GTK_BOX( GTK_DIALOG(activeunits_dialog_shell)->vbox ), activeunits_label2, FALSE, FALSE, 0 ); - close_command = gtk_button_new_with_label(_("Close")); + activeunits_table=gtk_table_new(3, 2, FALSE); + gtk_box_pack_start( GTK_BOX( GTK_DIALOG(activeunits_dialog_shell)->action_area ), - close_command, TRUE, TRUE, 0 ); + activeunits_table, TRUE, TRUE, 0 ); + + close_command = gtk_button_new_with_label(_("Close")); + gtk_table_attach(GTK_TABLE(activeunits_table), close_command, + 0, 1, 1, 2, + GTK_EXPAND | GTK_FILL,GTK_EXPAND | GTK_FILL, 0, 0); GTK_WIDGET_SET_FLAGS( close_command, GTK_CAN_DEFAULT ); gtk_widget_grab_default( close_command ); upgrade_command = gtk_button_new_with_label(_("Upgrade")); gtk_widget_set_sensitive(upgrade_command, FALSE); - gtk_box_pack_start( GTK_BOX( GTK_DIALOG(activeunits_dialog_shell)->action_area ), - upgrade_command, TRUE, TRUE, 0 ); + gtk_table_attach(GTK_TABLE(activeunits_table), upgrade_command, + 1, 2, 0, 1, + GTK_EXPAND | GTK_FILL,GTK_EXPAND | GTK_FILL, 0, 0); GTK_WIDGET_SET_FLAGS( upgrade_command, GTK_CAN_DEFAULT ); refresh_command = gtk_button_new_with_label(_("Refresh")); - gtk_box_pack_start( GTK_BOX( GTK_DIALOG(activeunits_dialog_shell)->action_area ), - refresh_command, TRUE, TRUE, 0 ); + gtk_table_attach(GTK_TABLE(activeunits_table), refresh_command, + 0, 1, 0, 1, + GTK_EXPAND | GTK_FILL,GTK_EXPAND | GTK_FILL, 0, 0); GTK_WIDGET_SET_FLAGS( refresh_command, GTK_CAN_DEFAULT ); + find_nearest_command = gtk_button_new_with_label(_("Find Nearest")); + gtk_table_attach(GTK_TABLE(activeunits_table), find_nearest_command, + 2, 3, 0, 1, + GTK_EXPAND | GTK_FILL,GTK_EXPAND | GTK_FILL, 0, 0); + GTK_WIDGET_SET_FLAGS( find_nearest_command, GTK_CAN_DEFAULT ); + + change_prod_command = gtk_button_new_with_label(_("Change Building")); + gtk_table_attach(GTK_TABLE(activeunits_table), change_prod_command, + 1, 2, 1, 2, + GTK_EXPAND | GTK_FILL,GTK_EXPAND | GTK_FILL, 0, 0); + GTK_WIDGET_SET_FLAGS( change_prod_command, GTK_CAN_DEFAULT ); + + awaken_all_command = gtk_button_new_with_label(_("Wake Sentried")); + gtk_table_attach(GTK_TABLE(activeunits_table), awaken_all_command, + 2, 3, 1, 2, + GTK_EXPAND | GTK_FILL,GTK_EXPAND | GTK_FILL, 0, 0); + GTK_WIDGET_SET_FLAGS( awaken_all_command, GTK_CAN_DEFAULT ); + gtk_signal_connect(GTK_OBJECT(activeunits_list), "select_row", GTK_SIGNAL_FUNC(activeunits_list_callback), NULL); gtk_signal_connect(GTK_OBJECT(activeunits_list), "unselect_row", @@ -871,7 +913,13 @@ GTK_SIGNAL_FUNC(activeunits_upgrade_callback), NULL); gtk_signal_connect(GTK_OBJECT(refresh_command), "clicked", GTK_SIGNAL_FUNC(activeunits_refresh_callback), NULL); - + gtk_signal_connect(GTK_OBJECT(change_prod_command), "clicked", + GTK_SIGNAL_FUNC(activeunits_change_prod_callback), NULL); + gtk_signal_connect(GTK_OBJECT(awaken_all_command), "clicked", + GTK_SIGNAL_FUNC(awaken_all_callback), NULL); + gtk_signal_connect(GTK_OBJECT(find_nearest_command), "clicked", + GTK_SIGNAL_FUNC(activeunits_find_nearest_callback), NULL); + gtk_widget_show_all( GTK_DIALOG(activeunits_dialog_shell)->vbox ); gtk_widget_show_all( GTK_DIALOG(activeunits_dialog_shell)->action_area ); @@ -886,9 +934,20 @@ *****************************************************************/ void activeunits_list_callback(GtkWidget *w, gint row, gint column) { + char *tmp; if ((unit_type_exists(activeunits_type[row])) && - (can_upgrade_unittype(game.player_ptr, activeunits_type[row]) != -1)) + (can_upgrade_unittype(game.player_ptr, activeunits_type[row]) != -1)){ gtk_widget_set_sensitive(upgrade_command, TRUE); + } + gtk_clist_get_text(GTK_CLIST(w), row, 2, &tmp); + if (atoi(tmp) && !activeunits_change_in_prod_up){ + gtk_widget_set_sensitive(change_prod_command, TRUE); + } + gtk_clist_get_text(GTK_CLIST(w), row, 3, &tmp); + if (atoi(tmp)){ + gtk_widget_set_sensitive(find_nearest_command, TRUE); + gtk_widget_set_sensitive(awaken_all_command, TRUE); + } } /**************************************************************** @@ -897,6 +956,290 @@ void activeunits_list_ucallback(GtkWidget *w, gint row, gint column) { gtk_widget_set_sensitive(upgrade_command, FALSE); + gtk_widget_set_sensitive(change_prod_command, FALSE); + gtk_widget_set_sensitive(awaken_all_command, FALSE); + gtk_widget_destroy(find_nearest_command); + find_nearest_command=gtk_button_new_with_label(_("Find Nearest")); + gtk_table_attach(GTK_TABLE(activeunits_table), find_nearest_command, + 2, 3, 0, 1, + GTK_EXPAND | GTK_FILL,GTK_EXPAND | GTK_FILL, 0, 0); + gtk_signal_connect(GTK_OBJECT(find_nearest_command), "clicked", + GTK_SIGNAL_FUNC(activeunits_find_nearest_callback), NULL); + GTK_WIDGET_SET_FLAGS( find_nearest_command, GTK_CAN_DEFAULT ); + gtk_widget_show(find_nearest_command); + gtk_widget_set_sensitive(find_nearest_command, FALSE); +} + + +/**************************************************************** +... +*****************************************************************/ +static void awaken_all_callback(GtkWidget *w, gpointer data){ + int i,which=activeunits_type[(gint)(GTK_CLIST( activeunits_list )->selection->data)]; + struct unit* nit; + if (which>=U_LAST) + which-=U_LAST; + for(i=0; iunits)); i++){ + nit=unit_list_get(&(game.player_ptr->units), i); + if (nit->type==which){ + request_unit_wakeup(nit); + } + } +} + +/**************************************************************** +... +*****************************************************************/ +gint unit_present(Unit_Type_id which,gint x, gint y){ + struct unit_list list; + gint i; + if (!is_normal_map_pos(x,y)) + return(0); + list=map_get_tile(x,y)->units; + for(i=0;itype==which && + unit_list_get(&list,i)->owner==game.player_idx) + return(1); + } + return(0); +} + + +/**************************************************************** +... +*****************************************************************/ +void activeunits_find_next_callback(GtkWidget *w,gpointer data){ + static gint x, y, r, side, which; + which=activeunits_type[(gint)(GTK_CLIST( activeunits_list )->selection->data)]; + if (which>=U_LAST) + which-=U_LAST; + if (data){ + x=activeunits_starting_find_x; + y=activeunits_starting_find_y; + r=0; + side=1; + } + while(1){ + switch (side){ + case 1: + ++y; + if (y-activeunits_starting_find_y>=r) side=2; + break; + case 2: + --x; + if (activeunits_starting_find_x-x>=r) side=3; + break; + case 3: + --y; + if (activeunits_starting_find_y-y>=r) side=4; + break; + case 4: + ++x; + if (x-activeunits_starting_find_x>=r){ + side=1; + ++r; + } + break; + } + if (unit_present(which,x,y)){ + center_tile_mapcanvas(x,y); + put_cross_overlay_tile(x,y); + return; + } + if (r>map.xsize && r>map.ysize){ + r=0; + x=activeunits_starting_find_x; + y=activeunits_starting_find_y; + } + } +} + +/**************************************************************** +... +*****************************************************************/ +void activeunits_find_nearest_callback(GtkWidget *w,gpointer data){ + get_center_tile_mapcanvas(&activeunits_starting_find_x, + &activeunits_starting_find_y); + gtk_widget_destroy(find_nearest_command); + find_nearest_command=gtk_button_new_with_label(_("Find Next")); + gtk_table_attach(GTK_TABLE(activeunits_table), find_nearest_command, + 2, 3, 0, 1, + GTK_EXPAND | GTK_FILL,GTK_EXPAND | GTK_FILL, 0, 0); + gtk_signal_connect(GTK_OBJECT(find_nearest_command), "clicked", + GTK_SIGNAL_FUNC(activeunits_find_next_callback), NULL); + GTK_WIDGET_SET_FLAGS( find_nearest_command, GTK_CAN_DEFAULT ); + gtk_widget_show(find_nearest_command); + activeunits_find_next_callback(w,(gpointer)TRUE); + return; +} + + +/**************************************************************** +... +*****************************************************************/ +void activeunits_change_prod_close_callback(GtkWidget *w, gpointer data){ + activeunits_change_in_prod_up=FALSE; + if (GTK_CLIST(activeunits_list)->selection) + activeunits_list_callback(activeunits_list, + (gint)(GTK_CLIST(activeunits_list)->selection->data), + 0); + free(data); +} + +/**************************************************************** +... +*****************************************************************/ +void activeunits_change_prod_close_button_callback(GtkWidget *w,gpointer data){ + gtk_widget_destroy((GtkWidget*)data); +} + + +/**************************************************************** +... +*****************************************************************/ +void activeunits_change_prod_change_callback(GtkWidget *w, gpointer data){ + gint i; + struct city *pcity; + + gpointer* tofromanddlg; + gint from, row, to; + GtkWidget *tosel, *dlg; + + tofromanddlg = (gpointer*)data; + from = (gint)tofromanddlg[0]; + tosel = (GtkWidget*)tofromanddlg[1]; + dlg = (GtkWidget*)tofromanddlg[2]; + + if (!(GTK_CLIST(tosel)->selection)){ + gtk_widget_destroy(dlg); + return; + } + row=(gint)(GTK_CLIST(tosel)->selection->data); + to=(gint)gtk_clist_get_row_data(GTK_CLIST(tosel), row); + + for(i=0, pcity=city_list_get(&game.player_ptr->cities, 0); + pcity; + pcity=city_list_get(&game.player_ptr->cities,i++)){ + if ((pcity->is_building_unit) && (pcity->currently_building == from)){ + struct packet_city_request packet; + packet.city_id=pcity->id; + packet.name[0]='\0'; + packet.worklist.name[0] = '\0'; + packet.build_id=to; + packet.is_build_id_unit_id=1; + send_packet_city_request(&aconnection, &packet, PACKET_CITY_CHANGE); + } + } + gtk_clist_unselect_row(GTK_CLIST(activeunits_list), + (gint)(GTK_CLIST(activeunits_list)->selection->data), + 0); + gtk_widget_destroy(dlg); /*the destroy handler will de-allocate data*/ +} + + +/**************************************************************** +... +*****************************************************************/ +int unit_is_obsolete(int id){ + while(unit_type_exists((id = unit_types[id].obsoleted_by))) + if (get_invention(game.player_ptr,unit_types[id].tech_requirement)==TECH_KNOWN) + return(TRUE); + return(FALSE); +} + + +/**************************************************************** +... +*****************************************************************/ +void activeunits_change_prod_callback(GtkWidget *w, gpointer data) +{ + char buf[512]; + int from, i; + GList *selection; + gint row; + GtkWidget *dlg, *lab, *sel, *ok, *canc; + gchar *rowbuf[3], rowbufcontents[2][64]; + /*We'll need to send it from, to, and the window to close*/ + gpointer *passeddata=(gpointer*)fc_malloc(3*sizeof(gpointer)); + + rowbuf[1]=rowbufcontents[0]; + rowbuf[2]=rowbufcontents[1]; + + activeunits_change_in_prod_up=TRUE; + gtk_widget_set_sensitive(w, FALSE);/*Don't let it call us twice*/ + + if ( !( selection = GTK_CLIST( activeunits_list )->selection ) ) + return; + + row = (gint)selection->data; + from = activeunits_type[row]; + + + if (from>=U_LAST) + from-=U_LAST; /*if none have been built yet, this is nessesary*/ + if (!(unit_type_exists (from))) + return; + + my_snprintf(buf, sizeof(buf), + _("Convert %s to..."), unit_types[from].name); + + dlg=gtk_dialog_new(); + gtk_window_set_title(GTK_WINDOW(GTK_DIALOG(dlg)), "Change production to..."); + + gtk_signal_connect(GTK_OBJECT(dlg), "destroy", + GTK_SIGNAL_FUNC(activeunits_change_prod_close_callback), + passeddata); + + lab=gtk_label_new(buf); + sel=gtk_clist_new(3); + for(i=0; i<3; i++){ + gtk_clist_set_column_auto_resize(GTK_CLIST(sel),i,TRUE); + } + gtk_clist_set_column_justification(GTK_CLIST(sel),1,GTK_JUSTIFY_RIGHT); + gtk_clist_set_column_justification(GTK_CLIST(sel),2,GTK_JUSTIFY_RIGHT); + for(i=0; iaction_area), ok, TRUE, FALSE, 0); + passeddata[0]=(gpointer)from; /*And I'm doing it again*/ + passeddata[1]=(gpointer)sel; + passeddata[2]=(gpointer)dlg; + gtk_signal_connect(GTK_OBJECT(ok),"clicked", + GTK_SIGNAL_FUNC(activeunits_change_prod_change_callback), + (gpointer)passeddata); + canc=gtk_button_new_with_label("Cancel"); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->action_area), canc, TRUE, FALSE, 0); + gtk_signal_connect(GTK_OBJECT(canc),"clicked", + GTK_SIGNAL_FUNC(activeunits_change_prod_close_button_callback), dlg); + + + + gtk_widget_set_usize(sel, 180, 0); + gtk_widget_show(sel); + + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), lab, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), sel, FALSE, FALSE, 0); + + gtk_widget_show(lab); + gtk_widget_show(ok); + gtk_widget_show(canc); + gtk_widget_show(dlg); } /**************************************************************** @@ -1030,7 +1373,8 @@ gtk_clist_append( GTK_CLIST( activeunits_list ), row ); - activeunits_type[k]=(unitarray[i].active_count > 0) ? i : U_LAST; + /*Using U_LAST+i is still invalid, but it preserves the information*/ + activeunits_type[k]=(unitarray[i].active_count > 0) ? i : U_LAST+i; k++; unittotals.active_count += unitarray[i].active_count; unittotals.upkeep_shield += unitarray[i].upkeep_shield;