From 2c2924a4f5af9c1202e647be2010317d2418d84e Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 22 Oct 2022 07:09:28 +0300 Subject: [PATCH 23/23] Qt: Allow toggling own Away mode from AI menu See osdn #44858 Signed-off-by: Marko Lindqvist --- client/gui-qt/plrdlg.cpp | 86 ++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/client/gui-qt/plrdlg.cpp b/client/gui-qt/plrdlg.cpp index 3e9d878fd0..ef63108865 100644 --- a/client/gui-qt/plrdlg.cpp +++ b/client/gui-qt/plrdlg.cpp @@ -724,7 +724,7 @@ plr_report::plr_report():QWidget() withdraw_but = new QPushButton; withdraw_but->setText(_("Withdraw Vision")); toggle_ai_but = new QPushButton; - toggle_ai_but->setText(_("Toggle AI Mode")); + toggle_ai_but->setText(_("AI Mode")); show_relations = new QPushButton; show_relations->setText(_("Hide Relations")); show_techs = new QPushButton; @@ -734,7 +734,6 @@ plr_report::plr_report():QWidget() meet_but->setDisabled(true); cancel_but->setDisabled(true); withdraw_but->setDisabled(true); - toggle_ai_but->setDisabled(true); v_splitter->addWidget(plr_wdg); h_splitter->addWidget(plr_label); h_splitter->addWidget(ally_label); @@ -832,38 +831,45 @@ void plr_report::req_wiithdrw_vision() **************************************************************************/ void plr_report::toggle_ai_mode() { - QAction *act; - QAction *toggle_ai_act; - QAction *ai_level_act; - QMenu ai_menu(this); - int level; - - toggle_ai_act = new QAction(_("Toggle AI Mode"), nullptr); - ai_menu.addAction(toggle_ai_act); - ai_menu.addSeparator(); - for (level = 0; level < AI_LEVEL_COUNT; level++) { - if (is_settable_ai_level(static_cast(level))) { - QString ln = ai_level_translated_name(static_cast(level)); - ai_level_act = new QAction(ln, nullptr); - ai_level_act->setData(QVariant::fromValue(level)); - ai_menu.addAction(ai_level_act); - } - } - act = 0; - act = ai_menu.exec(QCursor::pos()); - if (act == toggle_ai_act) { - send_chat_printf("/aitoggle \"%s\"", player_name(plr_wdg->other_player)); + if (plr_wdg->other_player == client_player()) { + send_chat_printf("/away \"%s\"", + player_name(plr_wdg->other_player)); return; - } - if (act && act->isVisible()) { - level = act->data().toInt(); - if (is_human(plr_wdg->other_player)) { + } else { + QMenu ai_menu(this); + QAction *toggle_ai_act; + QAction *act; + int level; + + toggle_ai_act = new QAction(_("Toggle AI Mode"), nullptr); + ai_menu.addAction(toggle_ai_act); + + ai_menu.addSeparator(); + for (level = 0; level < AI_LEVEL_COUNT; level++) { + if (is_settable_ai_level(static_cast(level))) { + QAction *ai_level_act; + QString ln = ai_level_translated_name(static_cast(level)); + + ai_level_act = new QAction(ln, nullptr); + ai_level_act->setData(QVariant::fromValue(level)); + ai_menu.addAction(ai_level_act); + } + } + act = 0; + act = ai_menu.exec(QCursor::pos()); + if (act == toggle_ai_act) { send_chat_printf("/aitoggle \"%s\"", player_name(plr_wdg->other_player)); + return; + } + if (act && act->isVisible()) { + level = act->data().toInt(); + if (is_human(plr_wdg->other_player)) { + send_chat_printf("/aitoggle \"%s\"", player_name(plr_wdg->other_player)); + } + send_chat_printf("/%s %s", ai_level_cmd(static_cast(level)), + player_name(plr_wdg->other_player)); } - send_chat_printf("/%s %s", ai_level_cmd(static_cast(level)), - player_name(plr_wdg->other_player)); } - } /************************************************************************** @@ -957,7 +963,6 @@ void plr_report::update_report(bool update_selection) meet_but->setDisabled(true); cancel_but->setDisabled(true); withdraw_but->setDisabled(true); - toggle_ai_but->setDisabled(true); plr_label->setText(plr_wdg->intel_str); ally_label->setText(plr_wdg->ally_str); tech_label->setText(plr_wdg->tech_str); @@ -966,15 +971,20 @@ void plr_report::update_report(bool update_selection) if (other_player == NULL || !can_client_issue_orders()) { return; } - if (NULL != client.conn.playing - && other_player != client.conn.playing) { + if (NULL != client.conn.playing) { + if (other_player != client.conn.playing) { - // We keep button sensitive in case of DIPL_SENATE_BLOCKING, so that player - // can request server side to check requirements of those effects with omniscience - if (pplayer_can_cancel_treaty(client_player(), other_player) != DIPL_ERROR) { - cancel_but->setEnabled(true); + // We keep button sensitive in case of DIPL_SENATE_BLOCKING, so that player + // can request server side to check requirements of those effects with omniscience + if (pplayer_can_cancel_treaty(client_player(), other_player) != DIPL_ERROR) { + cancel_but->setEnabled(true); + } + toggle_ai_but->setText(_("AI Mode")); + } else { + toggle_ai_but->setText(_("Away Mode")); } - toggle_ai_but->setEnabled(true); + } else { + toggle_ai_but->setText(_("AI Mode")); } if (gives_shared_vision(client_player(), other_player) && !players_on_same_team(client_player(), other_player)) { -- 2.35.1