--- ./client/gui-gtk/wldlg.c.orig Mon Jun 12 09:05:25 2000 +++ ./client/gui-gtk/wldlg.c Sun Jun 11 22:12:11 2000 @@ -27,6 +27,7 @@ #include "gui_stuff.h" #include "helpdlg.h" #include "inputdlg.h" +#include "log.h" #include "mem.h" #include "packets.h" #include "worklist.h" @@ -55,6 +56,13 @@ int wl_idx; }; +/* Type of thing to build from Available Targets */ +typedef enum { + WorklistAvailTypeUnit, + WorklistAvailTypeImprovement, + WorklistAvailTypeWorklist +} WorklistAvailType; + /* The Worklist dialog is the dialog with which the player edits a particular worklist. The worklist dialog is popped-up from either @@ -62,7 +70,8 @@ */ struct worklist_dialog { GtkWidget *worklist, *avail; - GtkWidget *btn_prepend, *btn_insert, *btn_delete, *btn_up, *btn_down; + GtkWidget *btn_prepend, *btn_append, *btn_insert, *btn_delete; + GtkWidget *btn_up, *btn_down; GtkWidget *toggle_show_advanced; GtkWidget *shell; @@ -77,11 +86,11 @@ char *worklist_names_ptrs[MAX_LEN_WORKLIST+1]; char worklist_names[MAX_LEN_WORKLIST][200]; int worklist_ids[MAX_LEN_WORKLIST]; + /* Available Targets list: */ char *worklist_avail_names_ptrs[B_LAST+1+U_LAST+1+MAX_NUM_WORKLISTS+1+1]; char worklist_avail_names[B_LAST+1+U_LAST+1+MAX_NUM_WORKLISTS+1][200]; + WorklistAvailType worklist_avail_type[B_LAST+1+U_LAST+1+MAX_NUM_WORKLISTS+1]; int worklist_avail_ids[B_LAST+1+U_LAST+1+MAX_NUM_WORKLISTS+1]; - int worklist_avail_num_improvements; - int worklist_avail_num_targets; }; static GtkWidget *worklist_report_shell = NULL; @@ -103,12 +112,13 @@ /* Callbacks for the worklist dialog */ static void worklist_list_callback(GtkWidget *w, gint row, gint column, - GdkEventButton *e, gpointer data); + GdkEvent *ev, gpointer data); static void worklist_avail_callback(GtkWidget *w, gint row, gint column, - GdkEventButton *e, gpointer data); + GdkEvent *ev, gpointer data); static void insert_into_worklist(struct worklist_dialog *pdialog, int before, int id); static void worklist_prepend_callback(GtkWidget *w, gpointer data); +static void worklist_append_callback(GtkWidget *w, gpointer data); static void worklist_insert_callback(GtkWidget *w, gpointer data); static void worklist_insert_common_callback(struct worklist_dialog *pdialog, GList *availSelection, @@ -372,6 +382,13 @@ GTK_SIGNAL_FUNC(worklist_prepend_callback), pdialog); + button = gtk_button_new_with_label(_("Append")); + pdialog->btn_append = button; + gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); + gtk_signal_connect(GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(worklist_append_callback), + pdialog); + button = gtk_button_new_with_label(_("Insert")); pdialog->btn_insert = button; gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); @@ -401,6 +418,7 @@ pdialog); gtk_widget_set_sensitive(pdialog->btn_prepend, FALSE); + gtk_widget_set_sensitive(pdialog->btn_append, FALSE); gtk_widget_set_sensitive(pdialog->btn_insert, FALSE); gtk_widget_set_sensitive(pdialog->btn_delete, FALSE); gtk_widget_set_sensitive(pdialog->btn_up, FALSE); @@ -743,10 +761,16 @@ User selected one of the worklist items *****************************************************************/ void worklist_list_callback(GtkWidget *w, gint row, gint column, - GdkEventButton *e, gpointer data) + GdkEvent *ev, gpointer data) { GList *selection; struct worklist_dialog *pdialog; + + if (ev && ev->type == GDK_2BUTTON_PRESS) { + /* Double-click to remove item from worklist */ + worklist_delete_callback(w, data); + return; + } pdialog=(struct worklist_dialog *)data; @@ -768,27 +792,36 @@ User selected one of the available items *****************************************************************/ void worklist_avail_callback(GtkWidget *w, gint row, gint column, - GdkEventButton *e, gpointer data) + GdkEvent *ev, gpointer data) { struct worklist_dialog *pdialog; GList *selection; - pdialog=(struct worklist_dialog *)data; + if (ev && ev->type == GDK_2BUTTON_PRESS) { + /* Double-click to insert item in worklist */ + worklist_insert_callback(w, data); + } + pdialog=(struct worklist_dialog *)data; selection = GTK_CLIST(pdialog->avail)->selection; if (! selection) { /* Deselected */ gtk_widget_set_sensitive(pdialog->btn_prepend, FALSE); + gtk_widget_set_sensitive(pdialog->btn_append, FALSE); gtk_widget_set_sensitive(pdialog->btn_insert, FALSE); } else { gtk_widget_set_sensitive(pdialog->btn_prepend, TRUE); + gtk_widget_set_sensitive(pdialog->btn_append, TRUE); gtk_widget_set_sensitive(pdialog->btn_insert, TRUE); } } /**************************************************************** - + Insert unit, building or wonder into Current worklist of city. + When id >= B_LAST, a unit is inserted, otherwise a building or + wonder. *****************************************************************/ void insert_into_worklist(struct worklist_dialog *pdialog, int before, int id) @@ -871,6 +904,23 @@ } /**************************************************************** + Append the selected build target to the worklist. +*****************************************************************/ +void worklist_append_callback(GtkWidget *w, gpointer data) +{ + struct worklist_dialog *pdialog = (struct worklist_dialog *)data; + GList *availSelection = GTK_CLIST(pdialog->avail)->selection; + + worklist_insert_common_callback(pdialog, availSelection, MAX_LEN_WORKLIST); + + if (pdialog->worklist_ids[1] != WORKLIST_END) { + gtk_widget_set_sensitive(pdialog->btn_delete, TRUE); + gtk_widget_set_sensitive(pdialog->btn_up, TRUE); + gtk_widget_set_sensitive(pdialog->btn_down, TRUE); + } +} + +/**************************************************************** Insert the selected build target into the worklist. *****************************************************************/ void worklist_insert_callback(GtkWidget *w, gpointer data) @@ -890,6 +940,8 @@ /**************************************************************** Do the actual UI work of inserting a target into the worklist. + availSelection == selected item to insert into worklist + where == index of currently selected item in worklist *****************************************************************/ void worklist_insert_common_callback(struct worklist_dialog *pdialog, GList *availSelection, @@ -907,7 +959,8 @@ /* Pick out the target and its type. */ target = pdialog->worklist_avail_ids[idx]; - if (idx >= pdialog->worklist_avail_num_targets) { + switch (pdialog->worklist_avail_type[idx]) { + case WorklistAvailTypeWorklist: { /* target is a global worklist id */ struct player *pplr = city_owner(pdialog->pcity); int wl_idx = pdialog->worklist_avail_ids[idx]; @@ -918,14 +971,23 @@ if (where < MAX_LEN_WORKLIST) where++; } - } else if (idx >= pdialog->worklist_avail_num_improvements) { - /* target is an improvement or wonder */ + break; + } + case WorklistAvailTypeUnit: { + /* target is a unit */ insert_into_worklist(pdialog, where, target+B_LAST); where++; - } else { - /* target is a unit */ + break; + } + case WorklistAvailTypeImprovement: { + /* target is an improvement or wonder */ insert_into_worklist(pdialog, where, target); where++; + break; + } + default: + freelog(LOG_FATAL, "Unknown type (%i) in worklist\n", + pdialog->worklist_avail_type[idx]); } /* Update the list with the actual data */ @@ -1145,8 +1207,9 @@ selection = GTK_CLIST(pdialog->avail)->selection; if(selection) { - id = pdialog->worklist_avail_ids[(int)selection->data]; - is_unit = (int)selection->data >= pdialog->worklist_avail_num_improvements; + int idx = (int)selection->data; + id = pdialog->worklist_avail_ids[idx]; + is_unit = (pdialog->worklist_avail_type[idx] == WorklistAvailTypeUnit); } else { id = -1; } @@ -1247,7 +1310,19 @@ else advanced_tech = FALSE; - /* + First, improvements and Wonders. */ + /* + The global worklists. */ + if (pdialog->pcity) { + /* Now fill in the global worklists. */ + for (i = 0; i < MAX_NUM_WORKLISTS; i++) + if (pplr->worklists[i].is_valid) { + strcpy(pdialog->worklist_avail_names[n], pplr->worklists[i].name); + pdialog->worklist_avail_names_ptrs[n]=pdialog->worklist_avail_names[n]; + pdialog->worklist_avail_type[n] = WorklistAvailTypeWorklist; + pdialog->worklist_avail_ids[n++]=i; + } + } + + /* + Improvements and Wonders. */ for(i=0; iworklist_avail_names[n], i, 0, pdialog->pcity); pdialog->worklist_avail_names_ptrs[n]=pdialog->worklist_avail_names[n]; + pdialog->worklist_avail_type[n] = WorklistAvailTypeImprovement; pdialog->worklist_avail_ids[n++]=i; } } - pdialog->worklist_avail_num_improvements=n; - /* + Second, units. */ + /* + Units. */ for(i=0; iworklist_avail_names[n], i, 1, pdialog->pcity); pdialog->worklist_avail_names_ptrs[n]=pdialog->worklist_avail_names[n]; + pdialog->worklist_avail_type[n] = WorklistAvailTypeUnit; pdialog->worklist_avail_ids[n++]=i; } - } - pdialog->worklist_avail_num_targets=n; - - /* + Finally, the global worklists. */ - if (pdialog->pcity) { - /* Now fill in the global worklists. */ - for (i = 0; i < MAX_NUM_WORKLISTS; i++) - if (pplr->worklists[i].is_valid) { - strcpy(pdialog->worklist_avail_names[n], pplr->worklists[i].name); - pdialog->worklist_avail_names_ptrs[n]=pdialog->worklist_avail_names[n]; - pdialog->worklist_avail_ids[n++]=i; - } } pdialog->worklist_avail_names_ptrs[n]=0;