From f0300c3ff4f02f238fdc98c2140f1e5531f9a4d4 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 8 Apr 2023 08:30:30 +0300 Subject: [PATCH 31/31] gtk3.22: Add "Clean" action and activity support - Add "Clean Nuisance" menu, from which exact clean target can be selected - Turn "Clean Pollution" to just "Clean" and make it clean Fallout too - Drop separate "Clean Fallout" See osdn #47799 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.22/menu.c | 115 +++++++++++++++++++++++++++---------- data/gtk3.22_menus.xml | 12 ++-- data/helpdata.txt | 4 +- 3 files changed, 94 insertions(+), 37 deletions(-) diff --git a/client/gui-gtk-3.22/menu.c b/client/gui-gtk-3.22/menu.c index 958690ee96..4b3b13039d 100644 --- a/client/gui-gtk-3.22/menu.c +++ b/client/gui-gtk-3.22/menu.c @@ -255,8 +255,7 @@ static void connect_rail_callback(GtkMenuItem *item, gpointer data); static void connect_maglev_callback(GtkMenuItem *item, gpointer data); static void connect_irrigation_callback(GtkMenuItem *item, gpointer data); static void transform_terrain_callback(GtkMenuItem *item, gpointer data); -static void clean_pollution_callback(GtkMenuItem *item, gpointer data); -static void clean_fallout_callback(GtkMenuItem *item, gpointer data); +static void clean_nuisance_callback(GtkMenuItem *item, gpointer data); static void fortify_callback(GtkMenuItem *item, gpointer data); static void build_fortress_callback(GtkMenuItem *item, gpointer data); static void build_airbase_callback(GtkMenuItem *item, gpointer data); @@ -516,6 +515,7 @@ static struct menu_entry_info menu_entries[] = { "MENU_COMBAT", N_("_Combat"), 0, 0, NULL, MGROUP_UNIT }, { "MENU_BUILD_BASE", N_("Build _Base"), 0, 0, NULL, MGROUP_UNIT }, { "MENU_BUILD_PATH", N_("Build _Path"), 0, 0, NULL, MGROUP_UNIT }, + { "MENU_CLEAN", N_("_Clean Nuisance"), 0, 0, NULL, MGROUP_UNIT }, { "SELECT_SINGLE", N_("_Single Unit (Unselect Others)"), GDK_KEY_z, 0, G_CALLBACK(select_single_callback), MGROUP_UNIT }, { "SELECT_ALL_ON_TILE", N_("_All On Tile"), GDK_KEY_v, 0, @@ -589,10 +589,8 @@ static struct menu_entry_info menu_entries[] = G_CALLBACK(connect_irrigation_callback), MGROUP_UNIT }, { "TRANSFORM_TERRAIN", N_("Transf_orm Terrain"), GDK_KEY_o, 0, G_CALLBACK(transform_terrain_callback), MGROUP_UNIT }, - { "CLEAN_POLLUTION", N_("Clean _Pollution"), GDK_KEY_p, 0, - G_CALLBACK(clean_pollution_callback), MGROUP_UNIT }, - { "CLEAN_FALLOUT", N_("Clean _Nuclear Fallout"), GDK_KEY_n, 0, - G_CALLBACK(clean_fallout_callback), MGROUP_UNIT }, + { "CLEAN", N_("_Clean"), GDK_KEY_p, 0, + G_CALLBACK(clean_nuisance_callback), MGROUP_UNIT }, { "FORTIFY", N_("Fortify"), GDK_KEY_f, 0, G_CALLBACK(fortify_callback), MGROUP_UNIT }, { "BUILD_FORTRESS", N_("Build Fortress"), GDK_KEY_f, GDK_SHIFT_MASK, @@ -1905,28 +1903,11 @@ static void transform_terrain_callback(GtkMenuItem *action, gpointer data) } /************************************************************************//** - Action "CLEAN_POLLUTION" callback. + Action "CLEAN" callback. ****************************************************************************/ -static void clean_pollution_callback(GtkMenuItem *action, gpointer data) +static void clean_nuisance_callback(GtkMenuItem *action, gpointer data) { - unit_list_iterate(get_units_in_focus(), punit) { - struct extra_type *pextra; - - pextra = prev_extra_in_tile(unit_tile(punit), ERM_CLEANPOLLUTION, - unit_owner(punit), punit); - - if (pextra != NULL) { - request_new_unit_activity_targeted(punit, ACTIVITY_POLLUTION, pextra); - } - } unit_list_iterate_end; -} - -/************************************************************************//** - Action "CLEAN_FALLOUT" callback. -****************************************************************************/ -static void clean_fallout_callback(GtkMenuItem *action, gpointer data) -{ - key_unit_fallout(); + key_unit_clean(); } /************************************************************************//** @@ -2028,6 +2009,29 @@ static void road_callback(GtkMenuItem *item, gpointer data) } unit_list_iterate_end; } +/************************************************************************//** + The player has chosen a nuisance to clean from the menu. +****************************************************************************/ +static void clean_callback(GtkMenuItem *item, gpointer data) +{ + struct extra_type *pextra = data; + + unit_list_iterate(get_units_in_focus(), punit) { + if (can_unit_do_activity_targeted(punit, ACTIVITY_CLEAN, pextra)) { + request_new_unit_activity_targeted(punit, ACTIVITY_CLEAN, + pextra); + } else if (can_unit_do_activity_targeted(punit, ACTIVITY_POLLUTION, + pextra)) { + request_new_unit_activity_targeted(punit, ACTIVITY_POLLUTION, + pextra); + } else if (can_unit_do_activity_targeted(punit, ACTIVITY_FALLOUT, + pextra)) { + request_new_unit_activity_targeted(punit, ACTIVITY_FALLOUT, + pextra); + } + } unit_list_iterate_end; +} + /************************************************************************//** Action "CENTER_VIEW" callback. ****************************************************************************/ @@ -2503,6 +2507,30 @@ void real_menus_update(void) g_list_free(list); } + /* Set cleaning menu sensitivity. */ + if ((menu = find_menu("/CLEAN"))) { + GList *list, *iter; + struct extra_type *pextra; + + list = gtk_container_get_children(GTK_CONTAINER(menu)); + for (iter = list; NULL != iter; iter = g_list_next(iter)) { + pextra = g_object_get_data(G_OBJECT(iter->data), "nuisance"); + if (NULL != pextra) { + gtk_widget_set_sensitive(GTK_WIDGET(iter->data), + can_units_do_activity_targeted(punits, + ACTIVITY_CLEAN, + pextra) + || can_units_do_activity_targeted(punits, + ACTIVITY_POLLUTION, + pextra) + || can_units_do_activity_targeted(punits, + ACTIVITY_FALLOUT, + pextra)); + } + } + g_list_free(list); + } + /* Set Go to and... action visibility. */ if ((menu = find_menu("/GOTO_AND"))) { GList *list, *iter; @@ -2561,10 +2589,9 @@ void real_menus_update(void) can_units_do_base_gui(punits, BASE_GUI_FORTRESS)); menu_entry_set_sensitive("BUILD_AIRBASE", can_units_do_base_gui(punits, BASE_GUI_AIRBASE)); - menu_entry_set_sensitive("CLEAN_POLLUTION", - can_units_do_activity(punits, ACTIVITY_POLLUTION)); - menu_entry_set_sensitive("CLEAN_FALLOUT", - can_units_do_activity(punits, ACTIVITY_FALLOUT)); + menu_entry_set_sensitive("CLEAN", + can_units_do_activity(punits, ACTIVITY_POLLUTION) + || can_units_do_activity(punits, ACTIVITY_FALLOUT)); menu_entry_set_sensitive("UNIT_SENTRY", can_units_do_activity(punits, ACTIVITY_SENTRY)); menu_entry_set_sensitive("DO_PARADROP", @@ -2994,6 +3021,34 @@ void real_menus_init(void) } extra_type_by_cause_iterate_end; } + if ((menu = find_menu("/CLEAN"))) { + GList *list, *iter; + GtkWidget *item; + + /* Remove previous cleaning entries. */ + list = gtk_container_get_children(GTK_CONTAINER(menu)); + for (iter = list; NULL != iter; iter = g_list_next(iter)) { + gtk_widget_destroy(GTK_WIDGET(iter->data)); + } + g_list_free(list); + + /* Add new cleaning entries. */ + extra_type_by_rmcause_iterate(ERM_CLEANPOLLUTION, pextra) { + item = gtk_menu_item_new_with_label(extra_name_translation(pextra)); + g_object_set_data(G_OBJECT(item), "nuisance", pextra); + g_signal_connect(item, "activate", G_CALLBACK(clean_callback), pextra); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); + gtk_widget_show(item); + } extra_type_by_rmcause_iterate_end; + extra_type_by_rmcause_iterate(ERM_CLEANFALLOUT, pextra) { + item = gtk_menu_item_new_with_label(extra_name_translation(pextra)); + g_object_set_data(G_OBJECT(item), "nuisance", pextra); + g_signal_connect(item, "activate", G_CALLBACK(clean_callback), pextra); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); + gtk_widget_show(item); + } extra_type_by_rmcause_iterate_end; + } + /* Initialize the Go to and... actions. */ if ((menu = find_menu("/GOTO_AND"))) { GtkWidget *item; diff --git a/data/gtk3.22_menus.xml b/data/gtk3.22_menus.xml index fb4172e223..8a72347444 100644 --- a/data/gtk3.22_menus.xml +++ b/data/gtk3.22_menus.xml @@ -353,6 +353,13 @@ + + + + + + + @@ -387,10 +394,7 @@ - - - - + diff --git a/data/helpdata.txt b/data/helpdata.txt index 1638c6e84d..a6e9d359e8 100644 --- a/data/helpdata.txt +++ b/data/helpdata.txt @@ -391,8 +391,7 @@ safe neighboring tiles when the conversion is complete.\ Units may also be able to destroy terrain alterations, by pillaging; \ typically more kinds of unit can pillage an improvement than \ could build it in the first place. Some tile features can only be \ -removed by specialized units, with the \"clean pollution\" or \ -\"clean fallout\" orders.\ +removed by specialized units, with the \"clean\" order.\ "), _("\ Terrain conversions cannot be undone in this way; for example, in the \ classic ruleset, if a Forest tile has been irrigated to convert it into \ @@ -1658,7 +1657,6 @@ Unit Orders:\n\ m: build (m)ine (settler/worker units)\n\ M: change terrain by planting\n\ Ctrl+M: connect current and target tile with M)aglev\n\ - n: clean (n)uclear fallout\n\ N: explode (N)uclear\n\ o: transf(o)rm terrain (engineer unit)\n\ O: c(O)nvert to another kind of unit\n\ -- 2.39.2