From 0ba4f20e7c0249abb76a7133f4ab733790fbfaf7 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 19 Dec 2021 12:13:46 +0200 Subject: [PATCH 13/13] gtk: Make Upgrade buttons insensitive on no-upgrades ruleset Reported by ihnatus See osdn #43424 Signed-off-by: Marko Lindqvist --- client/gui-gtk-2.0/citydlg.c | 1 + client/gui-gtk-2.0/repodlgs.c | 1 + client/gui-gtk-3.0/citydlg.c | 1 + client/gui-gtk-3.0/repodlgs.c | 1 + client/gui-gtk-3.22/citydlg.c | 1 + client/gui-gtk-3.22/repodlgs.c | 1 + common/actions.c | 9 +++++++++ common/actions.h | 2 ++ 8 files changed, 17 insertions(+) diff --git a/client/gui-gtk-2.0/citydlg.c b/client/gui-gtk-2.0/citydlg.c index d249082407..f811c92c4b 100644 --- a/client/gui-gtk-2.0/citydlg.c +++ b/client/gui-gtk-2.0/citydlg.c @@ -2304,6 +2304,7 @@ static gboolean present_unit_callback(GtkWidget * w, GdkEventButton * ev, gtk_widget_set_sensitive(item, can_unit_change_homecity_to(punit, pcity)); item = gtk_menu_item_new_with_mnemonic(_("U_pgrade unit")); + gtk_widget_set_sensitive(item, action_ever_possible(ACTION_UPGRADE_UNIT)); g_signal_connect(item, "activate", G_CALLBACK(unit_upgrade_callback), GINT_TO_POINTER(punit->id)); diff --git a/client/gui-gtk-2.0/repodlgs.c b/client/gui-gtk-2.0/repodlgs.c index 040a8be0da..21d6b520a5 100644 --- a/client/gui-gtk-2.0/repodlgs.c +++ b/client/gui-gtk-2.0/repodlgs.c @@ -1439,6 +1439,7 @@ static void units_report_selection_callback(GtkTreeSelection *selection, gui_dialog_set_response_sensitive(preport->shell, URD_RES_NEAREST, TRUE); gui_dialog_set_response_sensitive(preport->shell, URD_RES_UPGRADE, (can_client_issue_orders() + && action_ever_possible(ACTION_UPGRADE_UNIT) && NULL != can_upgrade_unittype(client_player(), utype))); } } diff --git a/client/gui-gtk-3.0/citydlg.c b/client/gui-gtk-3.0/citydlg.c index 1dc54aafbb..1a9c2a47e8 100644 --- a/client/gui-gtk-3.0/citydlg.c +++ b/client/gui-gtk-3.0/citydlg.c @@ -2553,6 +2553,7 @@ static gboolean present_unit_callback(GtkWidget * w, GdkEventButton * ev, gtk_widget_set_sensitive(item, can_unit_change_homecity_to(punit, pcity)); item = gtk_menu_item_new_with_mnemonic(_("U_pgrade unit")); + gtk_widget_set_sensitive(item, action_ever_possible(ACTION_UPGRADE_UNIT)); g_signal_connect(item, "activate", G_CALLBACK(unit_upgrade_callback), GINT_TO_POINTER(punit->id)); diff --git a/client/gui-gtk-3.0/repodlgs.c b/client/gui-gtk-3.0/repodlgs.c index c3909b1478..2b4e94de88 100644 --- a/client/gui-gtk-3.0/repodlgs.c +++ b/client/gui-gtk-3.0/repodlgs.c @@ -1488,6 +1488,7 @@ static void units_report_selection_callback(GtkTreeSelection *selection, gui_dialog_set_response_sensitive(preport->shell, URD_RES_NEAREST, TRUE); gui_dialog_set_response_sensitive(preport->shell, URD_RES_UPGRADE, (can_client_issue_orders() + && action_ever_possible(ACTION_UPGRADE_UNIT) && NULL != can_upgrade_unittype(client_player(), utype))); } } diff --git a/client/gui-gtk-3.22/citydlg.c b/client/gui-gtk-3.22/citydlg.c index 5b2c71afdc..a5cf882672 100644 --- a/client/gui-gtk-3.22/citydlg.c +++ b/client/gui-gtk-3.22/citydlg.c @@ -2586,6 +2586,7 @@ static gboolean present_unit_callback(GtkWidget * w, GdkEventButton * ev, gtk_widget_set_sensitive(item, can_unit_change_homecity_to(punit, pcity)); item = gtk_menu_item_new_with_mnemonic(_("U_pgrade unit")); + gtk_widget_set_sensitive(item, action_ever_possible(ACTION_UPGRADE_UNIT)); g_signal_connect(item, "activate", G_CALLBACK(unit_upgrade_callback), GINT_TO_POINTER(punit->id)); diff --git a/client/gui-gtk-3.22/repodlgs.c b/client/gui-gtk-3.22/repodlgs.c index cb93627c34..0125690d7d 100644 --- a/client/gui-gtk-3.22/repodlgs.c +++ b/client/gui-gtk-3.22/repodlgs.c @@ -1488,6 +1488,7 @@ static void units_report_selection_callback(GtkTreeSelection *selection, gui_dialog_set_response_sensitive(preport->shell, URD_RES_NEAREST, TRUE); gui_dialog_set_response_sensitive(preport->shell, URD_RES_UPGRADE, (can_client_issue_orders() + && action_ever_possible(ACTION_UPGRADE_UNIT) && NULL != can_upgrade_unittype(client_player(), utype))); } } diff --git a/common/actions.c b/common/actions.c index 3e05ef9bdb..eb5f7b748a 100644 --- a/common/actions.c +++ b/common/actions.c @@ -5374,3 +5374,12 @@ const char *action_ui_name_default(int act) return NULL; } + +/**********************************************************************//** + Is the action ever possible? Currently just checks that there's any + action enablers for the action. +**************************************************************************/ +bool action_ever_possible(action_id action) +{ + return action_enabler_list_size(action_enablers_for_action(action)) > 0; +} diff --git a/common/actions.h b/common/actions.h index e0714cdb9d..5ecdfda4d5 100644 --- a/common/actions.h +++ b/common/actions.h @@ -453,6 +453,8 @@ const char *action_prepare_ui_name(action_id act_id, const char* mnemonic, const char *action_ui_name_ruleset_var_name(int act); const char *action_ui_name_default(int act); +bool action_ever_possible(action_id action); + struct action_enabler_list * action_enablers_for_action(action_id action); -- 2.34.1