<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40697 >
This transaction appears to have no content
Hi, I have made a patch for the gtk client of freeciv adding a TradeRoute tab in the CityDialog. The patch was made on rev 15454 of trunk 3 files attached : - A svn diff patch for updated files (client/gui-gtk-2.0/Makefile.am, client/gui-gtk-2.0/gui_main.c, client/gui-gtk-2.0/citydlg.c) - A new file client/gui-gtk-2.0/trade.c implementing the trade tab - A new file client/gui-gtk-2.0/trade.h for the header Could you have a look to it ? ThanksHi,
I have made a patch for the gtk client of freeciv adding a TradeRoute tab in the CityDialog.
The patch was made on rev 15454 of trunk
3 files attached :
- A svn diff patch for updated files (client/gui-gtk-2.0/Makefile.am, client/gui-gtk-2.0/gui_main.c, client/gui-gtk-2.0/citydlg.c)
- A new file client/gui-gtk-2.0/trade.c implementing the trade tab
- A new file client/gui-gtk-2.0/trade.h for the header
Could you have a look to it ?
Thanks
Index: client/gui-gtk-2.0/citydlg.c =================================================================== --- client/gui-gtk-2.0/citydlg.c (révision 15454) +++ client/gui-gtk-2.0/citydlg.c (copie de travail) @@ -53,6 +53,7 @@ #include "options.h" #include "repodlgs.h" #include "tilespec.h" +#include "trade.h" #include "wldlg.h" #include "log.h" #include "text.h" @@ -96,7 +97,7 @@ #define NUM_CITIZENS_SHOWN 23 #define NUM_INFO_FIELDS 11 /* number of fields in city_info */ -#define NUM_PAGES 6 /* the number of pages in city dialog notebook +#define NUM_PAGES 7 /* the number of pages in city dialog notebook * (+1) if you change this, you must add an * entry to misc_whichtab_label[] */ @@ -154,6 +155,8 @@ struct cma_dialog *cma_editor; + struct trade_dialog *trade; + struct { GtkWidget *rename_command; GtkWidget *new_citizens_radio[3]; @@ -198,6 +201,7 @@ static void create_and_append_worklist_page(struct city_dialog *pdialog); static void create_and_append_happiness_page(struct city_dialog *pdialog); static void create_and_append_cma_page(struct city_dialog *pdialog); +static void create_and_append_trade_page(struct city_dialog *pdialog); static void create_and_append_settings_page(struct city_dialog *pdialog); static struct city_dialog *create_city_dialog(struct city *pcity); @@ -387,6 +391,8 @@ refresh_cma_dialog(pdialog->pcity, REFRESH_ALL); + refresh_trade_dialog(pdialog->pcity); + gtk_widget_set_sensitive(pdialog->show_units_command, can_client_issue_orders() && have_present_units); @@ -1020,6 +1026,26 @@ } /**************************************************************** + **** Trade Page **** +*****************************************************************/ +static void create_and_append_trade_page(struct city_dialog *pdialog) +{ + GtkWidget *page, *label; + const char *tab_title = _("City _Traderoutes"); + + page = gtk_vbox_new(FALSE, 0); + + label = gtk_label_new_with_mnemonic(tab_title); + + gtk_notebook_append_page(GTK_NOTEBOOK(pdialog->notebook), page, label); + + pdialog->trade = create_trade_dialog(pdialog->pcity); + gtk_box_pack_start(GTK_BOX(page), pdialog->trade->shell, TRUE, TRUE, 0); + + gtk_widget_show(page); +} + +/**************************************************************** **** Misc. Settings Page **** *****************************************************************/ static void create_and_append_settings_page(struct city_dialog *pdialog) @@ -1043,6 +1069,7 @@ N_("Production page"), N_("Happiness page"), N_("Governor page"), + N_("City Traderoutes page"), N_("This Settings page"), N_("Last active page") }; @@ -1238,6 +1265,7 @@ || city_owner(pcity) == client.conn.playing) { create_and_append_happiness_page(pdialog); create_and_append_cma_page(pdialog); + create_and_append_trade_page(pdialog); } if (city_owner(pcity) == client.conn.playing) { @@ -2756,6 +2784,7 @@ close_happiness_dialog(pdialog->pcity); close_cma_dialog(pdialog->pcity); + close_trade_dialog(pdialog->pcity); citydialog_height = pdialog->shell->allocation.height; citydialog_width = pdialog->shell->allocation.width; @@ -2878,13 +2907,14 @@ /* cleanup happiness dialog */ close_happiness_dialog(pdialog->pcity); - + pdialog->pcity = new_pcity; - /* reinitialize happiness, and cma dialogs */ + /* reinitialize happiness, cma, and trade dialogs */ gtk_box_pack_start(GTK_BOX(pdialog->happiness.widget), get_top_happiness_display(pdialog->pcity), TRUE, TRUE, 0); pdialog->cma_editor->pcity = new_pcity; + pdialog->trade->pcity = new_pcity; reset_worklist(pdialog->production.worklist, &pdialog->pcity->worklist, pdialog->pcity); Index: client/gui-gtk-2.0/gui_main.c =================================================================== --- client/gui-gtk-2.0/gui_main.c (révision 15454) +++ client/gui-gtk-2.0/gui_main.c (copie de travail) @@ -81,8 +81,8 @@ #include "resources.h" #include "text.h" #include "tilespec.h" +#include "trade.h" - const char *client_string = "gui-gtk-2.0"; GtkWidget *map_canvas; /* GtkDrawingArea */ @@ -1577,6 +1577,7 @@ cma_fe_init(); diplomacy_dialog_init(); happiness_dialog_init(); + trade_dialog_init(); intel_dialog_init(); spaceship_dialog_init(); @@ -1600,6 +1601,7 @@ spaceship_dialog_done(); intel_dialog_done(); happiness_dialog_done(); + trade_dialog_done(); diplomacy_dialog_done(); cma_fe_done(); tileset_free_tiles(tileset); Index: client/gui-gtk-2.0/Makefile.am =================================================================== --- client/gui-gtk-2.0/Makefile.am (révision 15454) +++ client/gui-gtk-2.0/Makefile.am (copie de travail) @@ -95,5 +95,7 @@ theme_dlg.c \ themes.c \ tileset_dlg.c \ + trade.c \ + trade.h \ wldlg.c \ wldlg.h
/********************************************************************** Freeciv - Copyright (C) 2001 - R. Falke, M. Kaufman This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ***********************************************************************/ #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <assert.h> #include <gdk/gdkkeysyms.h> /* common */ #include "events.h" #include "fcintl.h" #include "game.h" #include "mem.h" #include "support.h" /* client */ #include "chatline_g.h" #include "citydlg_g.h" #include "client_main.h" #include "gui_stuff.h" #include "messagewin_g.h" #include "plrdlg.h" /* for get_flag() */ #include "trade.h" #define BUFFER_SIZE 64 #define SPECLIST_TAG dialog #define SPECLIST_TYPE struct trade_dialog #include "speclist.h" #define dialog_list_iterate(dialoglist, pdialog) \ TYPED_LIST_ITERATE(struct trade_dialog, dialoglist, pdialog) #define dialog_list_iterate_end LIST_ITERATE_END static struct dialog_list *dialog_list; static struct trade_dialog *get_trade_dialog(struct city *pcity); static void update_trade_list(struct trade_dialog *pdialog); /**************************************************************** ... *****************************************************************/ void trade_dialog_init() { dialog_list = dialog_list_new(); } /**************************************************************** ... *****************************************************************/ void trade_dialog_done() { dialog_list_free(dialog_list); } /***************************************************************** only called when the city dialog is closed. ******************************************************************/ void close_trade_dialog(struct city *pcity) { struct trade_dialog *pdialog = get_trade_dialog(pcity); if (pdialog == NULL) { /* A city which is being investigated doesn't contain trade dialog */ return; } gtk_widget_destroy(pdialog->shell); } /**************************************************************** return the trade_dialog for a given city. *****************************************************************/ struct trade_dialog *get_trade_dialog(struct city *pcity) { dialog_list_iterate(dialog_list, pdialog) { if (pdialog->pcity == pcity) { return pdialog; } } dialog_list_iterate_end; return NULL; } /***************************************************************** instantiates a new struct for each city_dialog window that is open. ******************************************************************/ struct trade_dialog *create_trade_dialog(struct city *pcity) { struct trade_dialog *pdialog; GtkWidget *page, *label; GtkWidget *vbox, *sw; GtkListStore *store; GtkCellRenderer *rend; GtkWidget *view; GtkTreeViewColumn *column; char buf[BUFFER_SIZE]; pdialog = fc_malloc(sizeof(struct trade_dialog)); pdialog->pcity = pcity; pdialog->shell = gtk_vbox_new(FALSE, 8); gtk_container_set_border_width(GTK_CONTAINER(pdialog->shell), 8); page = gtk_hbox_new(FALSE, 12); gtk_box_pack_start(GTK_BOX(pdialog->shell), page, TRUE, TRUE, 0); vbox = gtk_vbox_new(FALSE, 2); gtk_box_pack_start(GTK_BOX(page), vbox, TRUE, TRUE, 0); sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_ETCHED_IN); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); store = gtk_list_store_new(6, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT,G_TYPE_INT); pdialog->store = store; gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), 5, GTK_SORT_DESCENDING); view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); g_object_unref(store); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), TRUE); pdialog->trade_list = view; pdialog->selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); rend = gtk_cell_renderer_pixbuf_new(); column = gtk_tree_view_column_new_with_attributes(_("Flag"), rend, "pixbuf", 0, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); rend = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(_("Nation"), rend, "text", 1, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); rend = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(_("City"), rend, "text", 2, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); rend = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(_("Size"), rend, "text", 3, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); rend = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(_("Distance"), rend, "text", 4, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); rend = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(_("Trade"), rend, "text", 5, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); my_snprintf(buf, sizeof(buf), _("A maximum of %d traderoutes can be established in a city :"), NUM_TRADEROUTES); label = g_object_new(GTK_TYPE_LABEL, "use-underline", TRUE, "mnemonic-widget", view, "label", buf, "xalign", 0.0, "yalign", 0.5, NULL); gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); gtk_container_add(GTK_CONTAINER(sw), view); gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); pdialog->total_trade_label = g_object_new(GTK_TYPE_LABEL, "use-underline", TRUE, "mnemonic-widget", view, "label", NULL, "xalign", 0.0, "yalign", 0.5, NULL); gtk_box_pack_start(GTK_BOX(vbox), pdialog->total_trade_label , FALSE, FALSE, 0); gtk_widget_show_all(pdialog->shell); dialog_list_prepend(dialog_list, pdialog); update_trade_list(pdialog); gtk_tree_view_focus(GTK_TREE_VIEW(view)); /* refresh is done in refresh_city_dialog */ return pdialog; } /****************************************************************** refreshes the trade dialog *******************************************************************/ void refresh_trade_dialog(struct city *pcity) { struct trade_dialog *pdialog = get_trade_dialog(pcity); gtk_widget_queue_draw(pdialog->trade_list); update_trade_list(pdialog); } /****************************************************************** fills in the trade list *******************************************************************/ static void update_trade_list(struct trade_dialog *pdialog) { GdkPixbuf *img; GValue value = { 0, }; GtkTreeIter it; int i, total_trade=0; struct city *pcity; char buf[BUFFER_SIZE]; /* Fill trade list */ gtk_list_store_clear(pdialog->store); /* Append the trade list */ for (i = 0; i < NUM_TRADEROUTES; i++) { if (pdialog->pcity->trade[i] <= 0 && pdialog->pcity->trade_value[i] <= 0) { continue; } /* Display infos of the dest city trade */ pcity = game_find_city_by_number(pdialog->pcity->trade[i]); gtk_list_store_append(pdialog->store, &it); gtk_list_store_set(pdialog->store, &it, 2, pcity->name, 3, pcity->size, 4, map_distance(pdialog->pcity->tile, pcity->tile), 5, pdialog->pcity->trade_value[i], -1); total_trade += pdialog->pcity->trade_value[i]; /* Get Nation name and flag */ g_value_init(&value, G_TYPE_STRING); g_value_set_static_string(&value, nation_adjective_translation(pcity->owner->nation)); gtk_list_store_set_value(pdialog->store, &it, 1, &value); g_value_unset(&value); img = get_flag(pcity->owner->nation); if (img != NULL) { gtk_list_store_set(pdialog->store, &it, 0, img, -1); g_object_unref(img); } } /* Total trade if exist */ if (total_trade != 0) { my_snprintf(buf, sizeof(buf), _("Total trade : %d"), total_trade); } else { my_snprintf(buf, sizeof(buf),_("There is no traderoute in this city")); } gtk_label_set_markup(GTK_LABEL(pdialog->total_trade_label), buf); }
/********************************************************************** Freeciv - Copyright (C) 2001 - R. Falke This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ***********************************************************************/ #ifndef FC__GTK_TRADE_H #define FC__GTK_TRADE_H #include <gtk/gtk.h> #include "fc_types.h" struct trade_dialog { struct city *pcity; GtkWidget *shell; GtkListStore *store; GtkWidget *trade_list; GtkWidget *total_trade_label; GtkTreeSelection *selection; }; void trade_dialog_init(void); void trade_dialog_done(void); struct trade_dialog *create_trade_dialog(struct city *pcity); void close_trade_dialog(struct city *pcity); void refresh_trade_dialog(struct city *pcity); #endif
_______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev