From 2624b5009ffbdcfe4111875229254bac44778c41 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 28 Nov 2022 23:05:24 +0200 Subject: [PATCH 32/32] gtk4: Add "Clean" menu entry See osdn #46138 Signed-off-by: Marko Lindqvist --- client/control.c | 39 ++++++++++++++++++++---- client/control.h | 1 + client/gui-gtk-4.0/menu.c | 63 +++++++++++++++------------------------ 3 files changed, 59 insertions(+), 44 deletions(-) diff --git a/client/control.c b/client/control.c index 330358f673..d8d28d0a87 100644 --- a/client/control.c +++ b/client/control.c @@ -124,7 +124,7 @@ static int action_selection_in_progress_for = IDENTITY_NUMBER_ZERO; */ bool non_ai_unit_focus; -static void key_unit_clean(enum unit_activity act, enum extra_rmcause rmcause); +static void key_unit_gen_clean(enum unit_activity act, enum extra_rmcause rmcause); /*************************************************************************/ @@ -3406,7 +3406,7 @@ void key_unit_convert(void) **************************************************************************/ void key_unit_fallout(void) { - key_unit_clean(ACTIVITY_FALLOUT, ERM_CLEANFALLOUT); + key_unit_gen_clean(ACTIVITY_FALLOUT, ERM_CLEANFALLOUT); } /**********************************************************************//** @@ -3466,9 +3466,10 @@ static void key_unit_extra(enum unit_activity act, enum extra_cause cause) } /**********************************************************************//** - Handle user extra cleaning input of given type + Handle user extra cleaning input of given class **************************************************************************/ -static void key_unit_clean(enum unit_activity act, enum extra_rmcause rmcause) +static void key_unit_gen_clean(enum unit_activity act, + enum extra_rmcause rmcause) { unit_list_iterate(get_units_in_focus(), punit) { struct extra_type *tgt = prev_extra_in_tile(unit_tile(punit), @@ -3535,12 +3536,40 @@ void key_unit_pillage(void) } unit_list_iterate_end; } +/**********************************************************************//** + Handle user 'clean' input +**************************************************************************/ +void key_unit_clean(void) +{ + unit_list_iterate(get_units_in_focus(), punit) { + struct extra_type *tgt = prev_extra_in_tile(unit_tile(punit), + ERM_CLEANPOLLUTION, + unit_owner(punit), + punit); + + if (tgt != NULL + && can_unit_do_activity_targeted(punit, ACTIVITY_POLLUTION, tgt)) { + request_new_unit_activity_targeted(punit, ACTIVITY_POLLUTION, tgt); + } else { + tgt = prev_extra_in_tile(unit_tile(punit), + ERM_CLEANFALLOUT, + unit_owner(punit), + punit); + + if (tgt != NULL + && can_unit_do_activity_targeted(punit, ACTIVITY_FALLOUT, tgt)) { + request_new_unit_activity_targeted(punit, ACTIVITY_FALLOUT, tgt); + } + } + } unit_list_iterate_end; +} + /**********************************************************************//** Handle user 'clean pollution' input **************************************************************************/ void key_unit_pollution(void) { - key_unit_clean(ACTIVITY_POLLUTION, ERM_CLEANPOLLUTION); + key_unit_gen_clean(ACTIVITY_POLLUTION, ERM_CLEANPOLLUTION); } /**********************************************************************//** diff --git a/client/control.h b/client/control.h index 7fb5f3f236..047013718a 100644 --- a/client/control.h +++ b/client/control.h @@ -239,6 +239,7 @@ void key_unit_connect(enum unit_activity activity, struct extra_type *tgt); void key_unit_action_select(void); void key_unit_action_select_tgt(void); +void key_unit_clean(void); void key_unit_convert(void); void key_unit_done(void); void key_unit_fallout(void); diff --git a/client/gui-gtk-4.0/menu.c b/client/gui-gtk-4.0/menu.c index db02ed2b7c..00d758d669 100644 --- a/client/gui-gtk-4.0/menu.c +++ b/client/gui-gtk-4.0/menu.c @@ -372,6 +372,9 @@ static void pillage_callback(GSimpleAction *action, static void transform_terrain_callback(GSimpleAction *action, GVariant *parameter, gpointer data); +static void clean_callback(GSimpleAction *action, + GVariant *parameter, + gpointer data); #ifdef MENUS_GTK3 static void build_road_callback(GtkMenuItem *item, gpointer data); @@ -380,8 +383,6 @@ static void build_mine_callback(GtkMenuItem *item, gpointer data); static void connect_road_callback(GtkMenuItem *item, gpointer data); static void connect_rail_callback(GtkMenuItem *item, gpointer data); static void connect_irrigation_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 build_fortress_callback(GtkMenuItem *item, gpointer data); static void build_airbase_callback(GtkMenuItem *item, gpointer data); static void diplomat_action_callback(GtkMenuItem *item, gpointer data); @@ -494,6 +495,9 @@ static struct menu_entry_info menu_entries[] = { "TRANSFORM_TERRAIN", N_("Transf_orm Terrain"), "transform_terrain", "o", MGROUP_UNIT, NULL, FALSE }, + { "CLEAN", N_("_Clean"), + "clean", "p", MGROUP_UNIT, + NULL, FALSE }, /* Combat menu */ { "FORTIFY", N_("Fortify"), @@ -790,10 +794,6 @@ static struct menu_entry_info menu_entries[] = { "CONNECT_IRRIGATION", N_("Connect With Irri_gation"), GDK_KEY_i, GDK_CONTROL_MASK, G_CALLBACK(connect_irrigation_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 }, { "BUILD_FORTRESS", N_("Build Fortress"), GDK_KEY_f, GDK_SHIFT_MASK, G_CALLBACK(build_fortress_callback), MGROUP_UNIT }, { "BUILD_AIRBASE", N_("Build Airbase"), GDK_KEY_e, GDK_SHIFT_MASK, @@ -844,6 +844,7 @@ const GActionEntry acts[] = { { "cultivate", cultivate_callback }, { "plant", plant_callback }, { "transform_terrain", transform_terrain_callback }, + { "clean", clean_callback }, { "fortify", fortify_callback }, { "paradrop", paradrop_callback }, @@ -2140,32 +2141,17 @@ static void transform_terrain_callback(GSimpleAction *action, key_unit_transform(); } -#ifdef MENUS_GTK3 -/************************************************************************//** - Action "CLEAN_POLLUTION" callback. -****************************************************************************/ -static void clean_pollution_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. + Action "CLEAN" callback. ****************************************************************************/ -static void clean_fallout_callback(GtkMenuItem *action, gpointer data) +static void clean_callback(GSimpleAction *action, + GVariant *parameter, + gpointer data) { - key_unit_fallout(); + key_unit_clean(); } +#ifdef MENUS_GTK3 /************************************************************************//** Action "BUILD_FORTRESS" callback. ****************************************************************************/ @@ -2311,9 +2297,9 @@ static void mine_callback(GSimpleAction *action, /************************************************************************//** The player has chosen an extra to clean from the menu. ****************************************************************************/ -static void clean_callback(GSimpleAction *action, - GVariant *parameter, - gpointer data) +static void clean_menu_callback(GSimpleAction *action, + GVariant *parameter, + gpointer data) { struct extra_type *pextra = data; @@ -2612,11 +2598,12 @@ static GMenu *setup_menus(GtkApplication *app) submenu = g_menu_new(); g_menu_append_submenu(work_menu, _("Build _Mine"), G_MENU_MODEL(submenu)); submenu = g_menu_new(); - g_menu_append_submenu(work_menu, _("_Clean"), G_MENU_MODEL(submenu)); + g_menu_append_submenu(work_menu, _("_Clean Nuisance"), G_MENU_MODEL(submenu)); menu_entry_init(work_menu, "CULTIVATE"); menu_entry_init(work_menu, "PLANT"); menu_entry_init(work_menu, "TRANSFORM_TERRAIN"); + menu_entry_init(work_menu, "CLEAN"); g_menu_append_submenu(menubar, _("_Work"), G_MENU_MODEL(work_menu)); @@ -3108,7 +3095,7 @@ void real_menus_update(void) ACTIVITY_POLLUTION, pextra)); g_action_map_add_action(map, G_ACTION(act)); - g_signal_connect(act, "activate", G_CALLBACK(clean_callback), pextra); + g_signal_connect(act, "activate", G_CALLBACK(clean_menu_callback), pextra); fc_snprintf(actname, sizeof(actname), "app.clean_%d", i++); item = g_menu_item_new(extra_name_translation(pextra), actname); @@ -3127,7 +3114,7 @@ void real_menus_update(void) ACTIVITY_FALLOUT, pextra)); g_action_map_add_action(map, G_ACTION(act)); - g_signal_connect(act, "activate", G_CALLBACK(clean_callback), pextra); + g_signal_connect(act, "activate", G_CALLBACK(clean_menu_callback), pextra); fc_snprintf(actname, sizeof(actname), "app.clean_%d", i++); item = g_menu_item_new(extra_name_translation(pextra), actname); @@ -3135,7 +3122,7 @@ void real_menus_update(void) } extra_type_by_rmcause_iterate_end; g_menu_remove(work_menu, 5); - g_menu_insert_submenu(work_menu, 5, _("_Clean"), G_MENU_MODEL(submenu)); + g_menu_insert_submenu(work_menu, 5, _("_Clean Nuicanse"), G_MENU_MODEL(submenu)); submenu = g_menu_new(); @@ -3350,17 +3337,15 @@ void real_menus_update(void) can_units_do(punits, can_unit_paradrop)); menu_entry_set_sensitive(map, "PILLAGE", can_units_do_activity(punits, ACTIVITY_PILLAGE)); + menu_entry_set_sensitive(map, "CLEAN", + can_units_do_activity(punits, ACTIVITY_POLLUTION) + || can_units_do_activity(punits, ACTIVITY_FALLOUT)); #ifdef MENUS_GTK3 menu_entry_set_sensitive("BUILD_FORTRESS", 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) - || can_units_do(punits, can_unit_paradrop))); - menu_entry_set_sensitive("CLEAN_FALLOUT", - can_units_do_activity(punits, ACTIVITY_FALLOUT)); #endif /* MENUS_GTK3 */ menu_entry_set_sensitive(map, "UNIT_SENTRY", -- 2.35.1