From fa709716a0610a19ca28123e232c6c6c2519d7c8 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 19 Dec 2021 11:59:07 +0200 Subject: [PATCH 42/42] gtk: Make Upgrade buttons insensitive on no-upgrades ruleset Reported by ihnatus See osdn #43424 Signed-off-by: Marko Lindqvist --- 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 + client/gui-gtk-4.0/citydlg.c | 1 + client/gui-gtk-4.0/repodlgs.c | 1 + common/actions.c | 9 +++++++++ common/actions.h | 2 ++ 8 files changed, 17 insertions(+) diff --git a/client/gui-gtk-3.0/citydlg.c b/client/gui-gtk-3.0/citydlg.c index ae86089126..dc93782c2d 100644 --- a/client/gui-gtk-3.0/citydlg.c +++ b/client/gui-gtk-3.0/citydlg.c @@ -2558,6 +2558,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 be61b1e9c4..015c1b0a7b 100644 --- a/client/gui-gtk-3.0/repodlgs.c +++ b/client/gui-gtk-3.0/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-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 b41a4a17a9..3ab8436d1b 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/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 da7fa6d6ce..eea7d1d723 100644 --- a/client/gui-gtk-4.0/repodlgs.c +++ b/client/gui-gtk-4.0/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/common/actions.c b/common/actions.c index 629727d81f..5a880e99fb 100644 --- a/common/actions.c +++ b/common/actions.c @@ -9227,3 +9227,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 f68f8d9447..c3dc43a15e 100644 --- a/common/actions.h +++ b/common/actions.h @@ -717,6 +717,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