From f402c489e57a48a265214b2e4cc74bde00a7c604 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 17 Feb 2023 23:00:21 +0200 Subject: [PATCH 16/16] gtk: Hide Production tab from diplomat investigate city dialog It was empty, but still present. See osdn #45318 Signed-off-by: Marko Lindqvist --- client/gui-gtk-2.0/citydlg.c | 43 +++++++++++++++++++++-------------- client/gui-gtk-3.0/citydlg.c | 20 ++++++++++------ client/gui-gtk-3.22/citydlg.c | 19 ++++++++++------ 3 files changed, 51 insertions(+), 31 deletions(-) diff --git a/client/gui-gtk-2.0/citydlg.c b/client/gui-gtk-2.0/citydlg.c index f811c92c4b..083a6c3709 100644 --- a/client/gui-gtk-2.0/citydlg.c +++ b/client/gui-gtk-2.0/citydlg.c @@ -1288,9 +1288,9 @@ static void create_and_append_settings_page(struct city_dialog *pdialog) static struct city_dialog *create_city_dialog(struct city *pcity) { struct city_dialog *pdialog; - GtkWidget *close_command; GtkWidget *vbox, *hbox, *cbox, *ebox; + struct player *owner; if (!city_dialogs_have_been_initialised) { initialize_city_dialogs(); @@ -1304,9 +1304,12 @@ static struct city_dialog *create_city_dialog(struct city *pcity) pdialog->happiness.map_canvas.ebox = NULL; /* ditto */ pdialog->happiness.map_canvas.pixmap = NULL; /* ditto */ pdialog->happiness.citizens = NULL; /* ditto */ + pdialog->production.buy_command = NULL; + pdialog->production.production_label = NULL; + pdialog->production.production_bar = NULL; pdialog->cma_editor = NULL; pdialog->map_canvas_store = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, - CITYMAP_WIDTH, CITYMAP_HEIGHT); + CITYMAP_WIDTH, CITYMAP_HEIGHT); pdialog->map_pixbuf_unscaled = NULL; pdialog->map_canvas_store_unscaled = gdk_pixmap_new(root_window, canvas_width, canvas_height, -1); @@ -1373,14 +1376,16 @@ static struct city_dialog *create_city_dialog(struct city *pcity) gtk_box_pack_start(GTK_BOX(vbox), pdialog->notebook, TRUE, TRUE, 0); create_and_append_overview_page(pdialog); - create_and_append_worklist_page(pdialog); - /* only create these tabs if not a spy */ - if (!client_has_player() || city_owner(pcity) == client_player()) { + owner = city_owner(pcity); + + /* Only create these tabs if not a spy */ + if (owner == client_player() || client_is_global_observer()) { + create_and_append_worklist_page(pdialog); create_and_append_happiness_page(pdialog); } - if (city_owner(pcity) == client_player() + if (owner == client_player() && !client_is_observer()) { create_and_append_cma_page(pdialog); create_and_append_settings_page(pdialog); @@ -1412,14 +1417,14 @@ static struct city_dialog *create_city_dialog(struct city *pcity) _("_Next city")); gtk_dialog_add_action_widget(GTK_DIALOG(pdialog->shell), pdialog->next_command, 2); - - if (city_owner(pcity) != client.conn.playing) { + + if (owner != client_player()) { gtk_widget_set_sensitive(pdialog->prev_command, FALSE); gtk_widget_set_sensitive(pdialog->next_command, FALSE); } close_command = gtk_dialog_add_button(GTK_DIALOG(pdialog->shell), - GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); + GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); gtk_dialog_set_default_response(GTK_DIALOG(pdialog->shell), GTK_RESPONSE_CLOSE); @@ -1697,10 +1702,12 @@ static void city_dialog_update_building(struct city_dialog *pdialog) int cost = city_production_build_shield_cost(pcity); gtk_widget_set_sensitive(pdialog->overview.buy_command, sensitive); - gtk_widget_set_sensitive(pdialog->production.buy_command, sensitive); + if (pdialog->production.buy_command != NULL) { + gtk_widget_set_sensitive(pdialog->production.buy_command, sensitive); + } /* Make sure build slots info is up to date */ - { + if (pdialog->production.production_label != NULL) { int build_slots = city_build_slots(pcity); /* Only display extra info if more than one slot is available */ if (build_slots > 1) { @@ -1734,12 +1741,14 @@ static void city_dialog_update_building(struct city_dialog *pdialog) gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR(pdialog->overview.production_bar), pct); - fc_snprintf(buf2, sizeof(buf2), "%s%s: %s", descr, - worklist_is_empty(&pcity->worklist) ? "" : " (+)", buf); - gtk_progress_bar_set_text( - GTK_PROGRESS_BAR(pdialog->production.production_bar), buf2); - gtk_progress_bar_set_fraction( - GTK_PROGRESS_BAR(pdialog->production.production_bar), pct); + if (pdialog->production.production_bar != NULL) { + fc_snprintf(buf2, sizeof(buf2), "%s%s: %s", descr, + worklist_is_empty(&pcity->worklist) ? "" : " (+)", buf); + gtk_progress_bar_set_text( + GTK_PROGRESS_BAR(pdialog->production.production_bar), buf2); + gtk_progress_bar_set_fraction( + GTK_PROGRESS_BAR(pdialog->production.production_bar), pct); + } store = pdialog->overview.change_production_store; gtk_combo_box_set_active(GTK_COMBO_BOX(pdialog->overview.production_combo), diff --git a/client/gui-gtk-3.0/citydlg.c b/client/gui-gtk-3.0/citydlg.c index 3ae5ef8e23..6944d73b39 100644 --- a/client/gui-gtk-3.0/citydlg.c +++ b/client/gui-gtk-3.0/citydlg.c @@ -1511,6 +1511,7 @@ static struct city_dialog *create_city_dialog(struct city *pcity) GtkWidget *vbox, *hbox, *cbox, *ebox; int citizen_bar_width; int citizen_bar_height; + struct player *owner; if (!city_dialogs_have_been_initialised) { initialize_city_dialogs(); @@ -1524,10 +1525,13 @@ static struct city_dialog *create_city_dialog(struct city *pcity) pdialog->happiness.map_canvas.ebox = NULL; /* ditto */ pdialog->happiness.map_canvas.darea = NULL; /* ditto */ pdialog->happiness.citizens = NULL; /* ditto */ + pdialog->production.buy_command = NULL; + pdialog->production.production_label = NULL; + pdialog->production.production_bar = NULL; pdialog->cma_editor = NULL; pdialog->map_canvas_store_unscaled = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, - canvas_width, canvas_height); + canvas_width, canvas_height); pdialog->shell = gtk_dialog_new(); gtk_window_set_title(GTK_WINDOW(pdialog->shell), city_name_get(pcity)); @@ -1607,14 +1611,16 @@ static struct city_dialog *create_city_dialog(struct city *pcity) create_and_append_overview_page(pdialog); create_and_append_map_page(pdialog); create_and_append_buildings_page(pdialog); - create_and_append_worklist_page(pdialog); - /* only create these tabs if not a spy */ - if (!client_has_player() || city_owner(pcity) == client_player()) { + owner = city_owner(pcity); + + /* Only create these tabs if not a spy */ + if (owner == client_player() || client_is_global_observer()) { + create_and_append_worklist_page(pdialog); create_and_append_happiness_page(pdialog); } - if (city_owner(pcity) == client_player() + if (owner == client_player() && !client_is_observer()) { create_and_append_cma_page(pdialog); create_and_append_settings_page(pdialog); @@ -1642,8 +1648,8 @@ static struct city_dialog *create_city_dialog(struct city *pcity) _("_Next city")); gtk_dialog_add_action_widget(GTK_DIALOG(pdialog->shell), pdialog->next_command, 2); - - if (city_owner(pcity) != client.conn.playing) { + + if (owner != client_player()) { gtk_widget_set_sensitive(pdialog->prev_command, FALSE); gtk_widget_set_sensitive(pdialog->next_command, FALSE); } diff --git a/client/gui-gtk-3.22/citydlg.c b/client/gui-gtk-3.22/citydlg.c index 3fc2a89460..b26e88efe9 100644 --- a/client/gui-gtk-3.22/citydlg.c +++ b/client/gui-gtk-3.22/citydlg.c @@ -1545,11 +1545,11 @@ static void create_and_append_settings_page(struct city_dialog *pdialog) static struct city_dialog *create_city_dialog(struct city *pcity) { struct city_dialog *pdialog; - GtkWidget *close_command; GtkWidget *vbox, *hbox, *cbox, *ebox; int citizen_bar_width; int citizen_bar_height; + struct player *owner; if (!city_dialogs_have_been_initialised) { initialize_city_dialogs(); @@ -1563,10 +1563,13 @@ static struct city_dialog *create_city_dialog(struct city *pcity) pdialog->happiness.map_canvas.ebox = NULL; /* ditto */ pdialog->happiness.map_canvas.darea = NULL; /* ditto */ pdialog->happiness.citizens = NULL; /* ditto */ + pdialog->production.buy_command = NULL; + pdialog->production.production_label = NULL; + pdialog->production.production_bar = NULL; pdialog->cma_editor = NULL; pdialog->map_canvas_store_unscaled = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, - canvas_width, canvas_height); + canvas_width, canvas_height); pdialog->shell = gtk_dialog_new(); gtk_window_set_title(GTK_WINDOW(pdialog->shell), city_name_get(pcity)); @@ -1646,14 +1649,16 @@ static struct city_dialog *create_city_dialog(struct city *pcity) create_and_append_overview_page(pdialog); create_and_append_map_page(pdialog); create_and_append_buildings_page(pdialog); - create_and_append_worklist_page(pdialog); - /* only create these tabs if not a spy */ - if (!client_has_player() || city_owner(pcity) == client_player()) { + owner = city_owner(pcity); + + /* Only create these tabs if not a spy */ + if (owner == client_player() || client_is_global_observer()) { + create_and_append_worklist_page(pdialog); create_and_append_happiness_page(pdialog); } - if (city_owner(pcity) == client_player() + if (owner == client_player() && !client_is_observer()) { create_and_append_cma_page(pdialog); create_and_append_settings_page(pdialog); @@ -1680,7 +1685,7 @@ static struct city_dialog *create_city_dialog(struct city *pcity) gtk_dialog_add_action_widget(GTK_DIALOG(pdialog->shell), GTK_WIDGET(pdialog->next_command), 2); - if (city_owner(pcity) != client.conn.playing) { + if (owner != client_player()) { gtk_widget_set_sensitive(GTK_WIDGET(pdialog->prev_command), FALSE); gtk_widget_set_sensitive(GTK_WIDGET(pdialog->next_command), FALSE); } -- 2.39.1