From 62629faa5dad7fcd7e4f7fb8d157d22f097af59a Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 19 Dec 2021 11:59:07 +0200 Subject: [PATCH 48/48] gtk: Make Upgrade buttons insensitive on no-upgrades ruleset Reported by ihnatus See osdn #43424 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.22/citydlg.c | 1 + client/gui-gtk-3.22/repodlgs.c | 1 + client/gui-gtk-4.0/citydlg.c | 1 + client/gui-gtk-4.0/repodlgs.c | 1 + common/actions.c | 9 +++++++++ common/actions.h | 2 ++ 6 files changed, 15 insertions(+) diff --git a/client/gui-gtk-3.22/citydlg.c b/client/gui-gtk-3.22/citydlg.c index 4a0ca7652f..fd2b31b72b 100644 --- a/client/gui-gtk-3.22/citydlg.c +++ b/client/gui-gtk-3.22/citydlg.c @@ -2575,6 +2575,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 44b6eb782f..125d20b087 100644 --- a/client/gui-gtk-3.22/repodlgs.c +++ b/client/gui-gtk-3.22/repodlgs.c @@ -1489,6 +1489,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-4.0/citydlg.c b/client/gui-gtk-4.0/citydlg.c index fddd01a001..d5d265ebd3 100644 --- a/client/gui-gtk-4.0/citydlg.c +++ b/client/gui-gtk-4.0/citydlg.c @@ -2584,6 +2584,7 @@ static gboolean present_unit_callback(GtkWidget *w, GdkEvent *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-4.0/repodlgs.c b/client/gui-gtk-4.0/repodlgs.c index 16d4a95422..d02024af3f 100644 --- a/client/gui-gtk-4.0/repodlgs.c +++ b/client/gui-gtk-4.0/repodlgs.c @@ -1490,6 +1490,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 4a8c76c854..047d309eb1 100644 --- a/common/actions.c +++ b/common/actions.c @@ -9482,3 +9482,12 @@ action_post_success_forced_ruleset_var_name(const struct action *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 80876f14fe..0b524636ba 100644 --- a/common/actions.h +++ b/common/actions.h @@ -736,6 +736,8 @@ const char *action_blocked_by_ruleset_var_name(const struct action *act); const char * action_post_success_forced_ruleset_var_name(const struct action *act); +bool action_ever_possible(action_id action); + struct action_enabler_list * action_enablers_for_action(action_id action); -- 2.34.1