From 7f6fe0c61a248fd2423ad709cb5e847ad4dc2f11 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 30 Apr 2023 01:18:43 +0300 Subject: [PATCH 36/36] Qt: Migrate to using "Clean" activity See osdn #47837 Signed-off-by: Marko Lindqvist --- client/gui-qt/citydlg.cpp | 19 +++++----------- client/gui-qt/dialogs.cpp | 32 +++++--------------------- client/gui-qt/hudwidget.cpp | 8 +++---- client/gui-qt/menu.cpp | 45 +++++++++++++++++-------------------- client/gui-qt/menu.h | 4 +--- client/gui-qt/shortcuts.cpp | 2 +- 6 files changed, 36 insertions(+), 74 deletions(-) diff --git a/client/gui-qt/citydlg.cpp b/client/gui-qt/citydlg.cpp index d3b2755730..9ec62881bd 100644 --- a/client/gui-qt/citydlg.cpp +++ b/client/gui-qt/citydlg.cpp @@ -1337,8 +1337,7 @@ void city_map::context_menu(QPoint point) QAction *con_mine = nullptr; QAction *con_road = nullptr; QAction *con_trfrm = nullptr; - QAction *con_pollution = nullptr; - QAction *con_fallout = nullptr; + QAction *con_clean = nullptr; QAction *con_clear = nullptr; QMenu *con_menu; QWidgetAction *wid_act; @@ -1399,14 +1398,9 @@ void city_map::context_menu(QPoint point) con_road = con_menu->addAction(_("Road")); } - if (prev_extra_in_tile(ptile, ERM_CLEANPOLLUTION, + if (prev_extra_in_tile(ptile, ERM_CLEAN, city_owner(mcity), NULL) != NULL) { - con_pollution = con_menu->addAction(_("Clean Pollution")); - } - - if (prev_extra_in_tile(ptile, ERM_CLEANFALLOUT, - city_owner(mcity), NULL) != NULL) { - con_fallout = con_menu->addAction(_("Clean Fallout")); + con_clean = con_menu->addAction(_("Clean")); } if (ptask != NULL) { @@ -1440,11 +1434,8 @@ void city_map::context_menu(QPoint point) task.activity = ACTIVITY_CULTIVATE; } else if (act == con_trfrm) { task.activity = ACTIVITY_TRANSFORM; - } else if (act == con_pollution) { - task.activity = ACTIVITY_POLLUTION; - target = TRUE; - } else if (act == con_fallout) { - task.activity = ACTIVITY_FALLOUT; + } else if (act == con_clean) { + task.activity = ACTIVITY_CLEAN; target = TRUE; } else if (act == con_clear) { task.activity = ACTIVITY_LAST; diff --git a/client/gui-qt/dialogs.cpp b/client/gui-qt/dialogs.cpp index 9a74218e9d..da4fa3756b 100644 --- a/client/gui-qt/dialogs.cpp +++ b/client/gui-qt/dialogs.cpp @@ -127,8 +127,7 @@ static void transform_terrain(QVariant data1, QVariant data2); static void cultivate(QVariant data1, QVariant data2); static void plant(QVariant data1, QVariant data2); static void pillage(QVariant data1, QVariant data2); -static void clean_pollution(QVariant data1, QVariant data2); -static void clean_fallout(QVariant data1, QVariant data2); +static void clean(QVariant data1, QVariant data2); static void road(QVariant data1, QVariant data2); static void base(QVariant data1, QVariant data2); static void mine(QVariant data1, QVariant data2); @@ -293,8 +292,7 @@ static const QHash af_map_init(void) action_function[ACTION_CULTIVATE] = cultivate; action_function[ACTION_PLANT] = plant; action_function[ACTION_PILLAGE] = pillage; - action_function[ACTION_CLEAN_POLLUTION] = clean_pollution; - action_function[ACTION_CLEAN_FALLOUT] = clean_fallout; + action_function[ACTION_CLEAN] = clean; action_function[ACTION_ROAD] = road; action_function[ACTION_BASE] = base; action_function[ACTION_MINE] = mine; @@ -2887,36 +2885,16 @@ static void pillage(QVariant data1, QVariant data2) } /***********************************************************************//** - Action "Clean Pollution" for choice dialog + Action "Clean" for choice dialog ***************************************************************************/ -static void clean_pollution(QVariant data1, QVariant data2) +static void clean(QVariant data1, QVariant data2) { int actor_id = data1.toInt(); int target_id = data2.toInt(); if (NULL != game_unit_by_number(actor_id) && NULL != index_to_tile(&(wld.map), target_id)) { - request_do_action(ACTION_CLEAN_POLLUTION, - actor_id, target_id, - /* FIXME: will cause problems if more than - * one action selection dialog at a time - * becomes supported. */ - action_selection_target_extra(), - ""); - } -} - -/***********************************************************************//** - Action "Clean Fallout" for choice dialog -***************************************************************************/ -static void clean_fallout(QVariant data1, QVariant data2) -{ - int actor_id = data1.toInt(); - int target_id = data2.toInt(); - - if (NULL != game_unit_by_number(actor_id) - && NULL != index_to_tile(&(wld.map), target_id)) { - request_do_action(ACTION_CLEAN_FALLOUT, + request_do_action(ACTION_CLEAN, actor_id, target_id, /* FIXME: will cause problems if more than * one action selection dialog at a time diff --git a/client/gui-qt/hudwidget.cpp b/client/gui-qt/hudwidget.cpp index cc37cb5e7c..4e56bbd844 100644 --- a/client/gui-qt/hudwidget.cpp +++ b/client/gui-qt/hudwidget.cpp @@ -1119,11 +1119,11 @@ int unit_actions::update_actions() actions.append(a); } - // Clean pollution - if (can_unit_do_activity(current_unit, ACTIVITY_POLLUTION)) { + // Clean + if (can_unit_do_activity(current_unit, ACTIVITY_CLEAN)) { a = new hud_action(this); - a->action_shortcut = SC_PARADROP; - a->set_pixmap(fc_icons::instance()->get_pixmap("pollution")); + a->action_shortcut = SC_CLEAN; + a->set_pixmap(fc_icons::instance()->get_pixmap("clean")); actions.append(a); } diff --git a/client/gui-qt/menu.cpp b/client/gui-qt/menu.cpp index 6f4ee9fef6..ef3ac0a70c 100644 --- a/client/gui-qt/menu.cpp +++ b/client/gui-qt/menu.cpp @@ -1356,15 +1356,11 @@ void mr_menu::setup_menus() act->setShortcut(QKeySequence(shortcut_to_string( fc_shortcuts::sc()->get_shortcut(SC_TRANSFORM)))); connect(act, &QAction::triggered, this, &mr_menu::slot_transform); - act = main_menu->addAction(_("Clean Pollution")); + act = main_menu->addAction(_("Clean")); menu_list.insert(CLEAN, act); act->setShortcut(QKeySequence(shortcut_to_string( fc_shortcuts::sc()->get_shortcut(SC_CLEAN)))); - connect(act, &QAction::triggered, this, &mr_menu::slot_clean_pollution); - act = main_menu->addAction(_("Clean Nuclear Fallout")); - menu_list.insert(FALLOUT, act); - act->setShortcut(QKeySequence(tr("n"))); - connect(act, &QAction::triggered, this, &mr_menu::slot_clean_fallout); + connect(act, &QAction::triggered, this, &mr_menu::slot_clean); act = main_menu->addAction(QString(action_id_name_translation(ACTION_HELP_WONDER)) .replace("&", "&&")); act->setShortcut(QKeySequence(tr("b"))); @@ -2348,13 +2344,7 @@ void mr_menu::menus_sensitive() break; case CLEAN: - if (can_units_do_activity(punits, ACTIVITY_POLLUTION)) { - i.value()->setEnabled(true); - } - break; - - case FALLOUT: - if (can_units_do_activity(punits, ACTIVITY_FALLOUT)) { + if (can_units_do_activity(punits, ACTIVITY_CLEAN)) { i.value()->setEnabled(true); } break; @@ -2591,25 +2581,30 @@ void mr_menu::slot_build_city() } /**********************************************************************//** - Action "CLEAN FALLOUT" -**************************************************************************/ -void mr_menu::slot_clean_fallout() -{ - key_unit_fallout(); -} - -/**********************************************************************//** - Action "CLEAN POLLUTION" + Action "CLEAN" **************************************************************************/ -void mr_menu::slot_clean_pollution() +void mr_menu::slot_clean() { unit_list_iterate(get_units_in_focus(), punit) { struct extra_type *pextra; - pextra = prev_extra_in_tile(unit_tile(punit), ERM_CLEANPOLLUTION, + pextra = prev_extra_in_tile(unit_tile(punit), ERM_CLEAN, unit_owner(punit), punit); + if (pextra != NULL) { - request_new_unit_activity_targeted(punit, ACTIVITY_POLLUTION, pextra); + request_new_unit_activity_targeted(punit, ACTIVITY_CLEAN, pextra); + } else { + 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); + } else { + pextra = prev_extra_in_tile(unit_tile(punit), ERM_CLEANFALLOUT, + unit_owner(punit), punit); + if (pextra != NULL) { + request_new_unit_activity_targeted(punit, ACTIVITY_FALLOUT, pextra); + } + } } } unit_list_iterate_end; } diff --git a/client/gui-qt/menu.h b/client/gui-qt/menu.h index 2f3c83179d..716b82ffab 100644 --- a/client/gui-qt/menu.h +++ b/client/gui-qt/menu.h @@ -57,7 +57,6 @@ enum munit { FORTRESS, AIRBASE, CLEAN, - FALLOUT, SENTRY, HOMECITY, WAKEUP, @@ -326,8 +325,7 @@ private slots: void slot_conn_maglev(); void slot_conn_irrigation(); void slot_transform(); - void slot_clean_pollution(); - void slot_clean_fallout(); + void slot_clean(); // Used by unit menu void slot_unit_sentry(); diff --git a/client/gui-qt/shortcuts.cpp b/client/gui-qt/shortcuts.cpp index 91adbf9bdb..94b0b5c959 100644 --- a/client/gui-qt/shortcuts.cpp +++ b/client/gui-qt/shortcuts.cpp @@ -149,7 +149,7 @@ fc_shortcut default_shortcuts[] = { {SC_AUTOMATE, Qt::Key_A, Qt::AllButtons, Qt::NoModifier, _("Auto worker") }, {SC_CLEAN, Qt::Key_P, Qt::AllButtons, Qt::NoModifier, - _("Clean pollution") }, + _("Clean") }, {SC_POPUP_COMB_INF, Qt::Key_F1, Qt::AllButtons, Qt::ControlModifier, _("Popup combat information") }, {SC_RELOAD_THEME, Qt::Key_F5, Qt::AllButtons, Qt::ControlModifier -- 2.39.2