From 98f21eb456b7ab577fe69ed96168ccadd0566884 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 10 Dec 2022 12:35:19 +0200 Subject: [PATCH 47/47] sdl2: Add "Clean" action button See osdn #46241 Signed-off-by: Marko Lindqvist --- client/gui-sdl2/gui_id.h | 1 + client/gui-sdl2/gui_tilespec.c | 1 + client/gui-sdl2/gui_tilespec.h | 3 +- client/gui-sdl2/menu.c | 53 ++++++++++++++++--- .../gui-sdl2/human/theme_orders_buttons.tspec | 5 +- 5 files changed, 52 insertions(+), 11 deletions(-) diff --git a/client/gui-sdl2/gui_id.h b/client/gui-sdl2/gui_id.h index 4f9c0ccce8..3d883463f8 100644 --- a/client/gui-sdl2/gui_id.h +++ b/client/gui-sdl2/gui_id.h @@ -97,6 +97,7 @@ enum GUI_ID { ID_UNIT_ORDER_AIRBASE, ID_UNIT_ORDER_POLLUTION, ID_UNIT_ORDER_PARADROP, + ID_UNIT_ORDER_CLEAN, ID_UNIT_ORDER_FALLOUT, ID_UNIT_ORDER_SENTRY, ID_UNIT_ORDER_PILLAGE, diff --git a/client/gui-sdl2/gui_tilespec.c b/client/gui-sdl2/gui_tilespec.c index 514a2bd0cb..695365f4c6 100644 --- a/client/gui-sdl2/gui_tilespec.c +++ b/client/gui-sdl2/gui_tilespec.c @@ -347,6 +347,7 @@ void tilespec_setup_theme(void) load_order_theme_surface(buf, o_unload_icon, "theme.order_unload"); load_order_theme_surface(buf, o_wait_icon, "theme.order_wait"); load_order_theme_surface(buf, o_fortress_icon, "theme.order_build_fortress"); + load_order_theme_surface(buf, o_clean_icon, "theme.order_clean"); load_order_theme_surface(buf, o_fallout_icon, "theme.order_clean_fallout"); load_order_theme_surface(buf, o_pollution_icon, "theme.order_clean_pollution"); load_order_theme_surface(buf, o_airbase_icon, "theme.order_build_airbase"); diff --git a/client/gui-sdl2/gui_tilespec.h b/client/gui-sdl2/gui_tilespec.h index 4abbee09b8..825296daf7 100644 --- a/client/gui-sdl2/gui_tilespec.h +++ b/client/gui-sdl2/gui_tilespec.h @@ -132,6 +132,7 @@ struct theme_icons { SDL_Surface *o_paradrop_icon; SDL_Surface *o_nuke_icon; SDL_Surface *o_fortress_icon; + SDL_Surface *o_clean_icon; SDL_Surface *o_fallout_icon; SDL_Surface *o_pollution_icon; SDL_Surface *o_airbase_icon; @@ -271,4 +272,4 @@ static inline SDL_Surface *get_tax_surface(Output_type_id otype) return adj_surf(GET_SURF(get_tax_sprite(tileset, otype))); } -#endif /* FC__GUI_TILESPEC_H */ +#endif /* FC__GUI_TILESPEC_H */ diff --git a/client/gui-sdl2/menu.c b/client/gui-sdl2/menu.c index dd766f2a99..12a2536730 100644 --- a/client/gui-sdl2/menu.c +++ b/client/gui-sdl2/menu.c @@ -65,6 +65,7 @@ extern struct widget *options_button; static struct widget *begin_order_widget_list; static struct widget *end_order_widget_list; +static struct widget *order_clean_button; static struct widget *order_fallout_button; static struct widget *order_pollution_button; static struct widget *order_airbase_button; @@ -141,6 +142,9 @@ static int unit_order_callback(struct widget *order_widget) case ID_UNIT_ORDER_AIRBASE: key_unit_airbase(); break; + case ID_UNIT_ORDER_CLEAN: + key_unit_clean(); + break; case ID_UNIT_ORDER_POLLUTION: key_unit_pollution(); break; @@ -771,6 +775,20 @@ void create_units_order_widgets(void) add_to_gui_list(ID_UNIT_ORDER_POLLUTION, buf); /* --------- */ + /* Generic Clean */ + /* Label will be replaced by real_menus_update() before it's seen */ + fc_snprintf(cbuf, sizeof(cbuf), "placeholder"); + buf = create_themeicon(current_theme->o_clean_icon, main_data.gui, + WF_HIDDEN | WF_RESTORE_BACKGROUND + | WF_WIDGET_HAS_INFO_LABEL); + set_wstate(buf, FC_WS_NORMAL); + buf->action = unit_order_callback; + buf->info_label = create_utf8_from_char(cbuf, adj_font(10)); + /* buf->key = SDLK_p; */ + order_clean_button = buf; + add_to_gui_list(ID_UNIT_ORDER_CLEAN, buf); + /* --------- */ + /* Build Airbase */ /* Label will be replaced by real_menus_update() before it's seen */ fc_snprintf(cbuf, sizeof(cbuf), "placeholder"); @@ -1089,6 +1107,7 @@ void real_menus_update(void) struct terrain *pterrain = tile_terrain(ptile); struct base_type *pbase; struct extra_type *pextra; + struct extra_type *clean_target = NULL; if (!counter) { local_show(ID_UNIT_ORDER_GOTO); @@ -1288,15 +1307,16 @@ void real_menus_update(void) set_wflag(order_airbase_button, WF_HIDDEN); } - pextra = prev_extra_in_tile(ptile, ERM_CLEANPOLLUTION, - unit_owner(punit), punit); - if (pextra != NULL - && can_unit_do_activity_targeted(punit, ACTIVITY_POLLUTION, pextra)) { - time = turns_to_activity_done(ptile, ACTIVITY_POLLUTION, pextra, - punit); + clean_target = prev_extra_in_tile(ptile, ERM_CLEANPOLLUTION, + unit_owner(punit), punit); + if (clean_target != NULL + && can_unit_do_activity_targeted(punit, ACTIVITY_POLLUTION, + clean_target)) { + time = turns_to_activity_done(ptile, ACTIVITY_POLLUTION, + clean_target, punit); /* TRANS: "Clean Pollution (P) 3 turns" */ fc_snprintf(cbuf, sizeof(cbuf), _("Clean %s (%s) %d %s"), - extra_name_translation(pextra), "P", time, + extra_name_translation(clean_target), "P", time, PL_("turn", "turns", time)); copy_chars_to_utf8_str(order_pollution_button->info_label, cbuf); clear_wflag(order_pollution_button, WF_HIDDEN); @@ -1326,6 +1346,25 @@ void real_menus_update(void) set_wflag(order_fallout_button, WF_HIDDEN); } + if (clean_target == NULL) { + clean_target = pextra; + } + if (clean_target != NULL + && can_unit_do_activity_targeted(punit, ACTIVITY_CLEAN, + clean_target)) { + time = turns_to_activity_done(ptile, ACTIVITY_CLEAN, + clean_target, punit); + /* FIXME: No key assigned for this at the moment */ + /* TRANS: "Clean Pollution 3 turns" */ + fc_snprintf(cbuf, sizeof(cbuf), _("Clean %s %d %s"), + extra_name_translation(clean_target), time, + PL_("turn", "turns", time)); + copy_chars_to_utf8_str(order_clean_button->info_label, cbuf); + clear_wflag(order_clean_button, WF_HIDDEN); + } else { + set_wflag(order_clean_button, WF_HIDDEN); + } + if (can_unit_do_activity(punit, ACTIVITY_SENTRY)) { local_show(ID_UNIT_ORDER_SENTRY); } else { diff --git a/data/themes/gui-sdl2/human/theme_orders_buttons.tspec b/data/themes/gui-sdl2/human/theme_orders_buttons.tspec index 22daa82b0f..f6603339d9 100644 --- a/data/themes/gui-sdl2/human/theme_orders_buttons.tspec +++ b/data/themes/gui-sdl2/human/theme_orders_buttons.tspec @@ -26,7 +26,7 @@ dx = 120 dy = 30 pixel_border = 1 -tiles = { "row", "column","tag" +tiles = { "row", "column", "tag" ; terrain 1, 0, "theme.order_auto_connect" @@ -54,7 +54,7 @@ tiles = { "row", "column","tag" 23, 0, "theme.order_wait" 24, 0, "theme.order_build_fortress" 25, 0, "theme.order_clean_fallout" - 26, 0, "theme.order_clean_pollution" + 26, 0, "theme.order_clean", "theme.order_clean_pollution" 27, 0, "theme.order_build_airbase" 28, 0, "theme.order_transform" 29, 0, "theme.order_add_to_city" @@ -68,5 +68,4 @@ tiles = { "row", "column","tag" ; 37, 0, "theme.order_" ; 38, 0, "theme.order_" 39, 0, "theme.order_empty" - } -- 2.35.1