From bb3566ac8157c44430a49765f67a1b4ee3146fdc Mon Sep 17 00:00:00 2001 From: Benau Date: Thu, 9 May 2019 10:04:19 +0800 Subject: [PATCH] Add report player function in dialog --- src/network/protocols/lobby_protocol.hpp | 3 +- .../dialogs/network_user_dialog.cpp | 44 ++++++++++++++++++- .../dialogs/network_user_dialog.hpp | 4 +- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/network/protocols/lobby_protocol.hpp b/src/network/protocols/lobby_protocol.hpp index 0075b8d50..09b710551 100644 --- a/src/network/protocols/lobby_protocol.hpp +++ b/src/network/protocols/lobby_protocol.hpp @@ -73,7 +73,8 @@ public: LE_LIVE_JOIN, // Client live join or spectate LE_LIVE_JOIN_ACK, // Server tell client live join or spectate succeed LE_KART_INFO, // Client or server exchange new kart info - LE_CLIENT_BACK_LOBBY // Client tell server to go back lobby + LE_CLIENT_BACK_LOBBY, // Client tell server to go back lobby + LE_REPORT_USER // Client report user in server (like abusive behaviour) }; enum RejectReason : uint8_t diff --git a/src/states_screens/dialogs/network_user_dialog.cpp b/src/states_screens/dialogs/network_user_dialog.cpp index 200ece162..fd8ee2733 100644 --- a/src/states_screens/dialogs/network_user_dialog.cpp +++ b/src/states_screens/dialogs/network_user_dialog.cpp @@ -24,9 +24,11 @@ #include "guiengine/widgets/icon_button_widget.hpp" #include "guiengine/widgets/label_widget.hpp" #include "guiengine/widgets/ribbon_widget.hpp" +#include "guiengine/widgets/text_box_widget.hpp" #include "online/online_profile.hpp" #include "network/protocols/lobby_protocol.hpp" #include "network/stk_host.hpp" +#include "states_screens/dialogs/general_text_field_dialog.hpp" #include "states_screens/state_manager.hpp" #include "utils/translation.hpp" @@ -78,6 +80,8 @@ void NetworkUserDialog::beforeAddingWidgets() m_kick_widget = getWidget("decline"); assert(m_kick_widget != NULL); + m_kick_widget->setImage(file_manager->getAsset(FileManager::GUI_ICON, + "remove.png"), IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE); //I18N: In the network user dialog m_kick_widget->setText(_("Kick")); @@ -123,7 +127,18 @@ void NetworkUserDialog::beforeAddingWidgets() } else getWidget("remove")->setVisible(false); - getWidget("enter")->setVisible(false); + m_report_widget = getWidget("enter"); + assert(m_report_widget != NULL); + if (m_host_id != STKHost::get()->getMyHostId()) + { + // I18N: In the network user dialog, + // report player about for example abusive behaviour in game + m_report_widget->setText(_("Report player")); + m_report_widget->setImage(file_manager->getAsset(FileManager::GUI_ICON, + "red_mark.png"), IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE); + } + else + m_report_widget->setVisible(false); } // beforeAddingWidgets // ----------------------------------------------------------------------------- @@ -145,6 +160,28 @@ void NetworkUserDialog::onUpdate(float dt) } // It's unsafe to delete from inside the event handler so we do it here + if (m_open_report_textbox) + { + // I18N: In the network player dialog, instruction for reporting player + core::stringw t = _("Tell server administrator about this player (%s):", m_name); + uint32_t host_id = m_host_id; + ModalDialog::dismiss(); + new GeneralTextFieldDialog(t.c_str(), + [] (const irr::core::stringw& text) {}, + [host_id] (GUIEngine::LabelWidget* lw, + GUIEngine::TextBoxWidget* tb)->bool + { + core::stringw info = tb->getText(); + if (info.empty()) + return false; + NetworkString report(PROTOCOL_LOBBY_ROOM); + report.addUInt8(LobbyProtocol::LE_REPORT_USER) + .addUInt32(host_id).encodeString(info); + STKHost::get()->sendToServer(&report, true/*reliable*/); + return true; + }); + return; + } if (m_self_destroy) { ModalDialog::dismiss(); @@ -165,6 +202,11 @@ GUIEngine::EventPropagation m_self_destroy = true; return GUIEngine::EVENT_BLOCK; } + else if (selection == m_report_widget->m_properties[PROP_ID]) + { + m_open_report_textbox = true; + return GUIEngine::EVENT_BLOCK; + } else if (selection == m_friend_widget->m_properties[PROP_ID]) { XMLRequest *request = new XMLRequest(); diff --git a/src/states_screens/dialogs/network_user_dialog.hpp b/src/states_screens/dialogs/network_user_dialog.hpp index e9cee5d8c..f389e0ff0 100644 --- a/src/states_screens/dialogs/network_user_dialog.hpp +++ b/src/states_screens/dialogs/network_user_dialog.hpp @@ -53,7 +53,7 @@ private: const bool m_allow_change_team; - bool m_self_destroy; + bool m_self_destroy, m_open_report_textbox; std::shared_ptr m_fetched_ranking; @@ -73,6 +73,7 @@ private: GUIEngine::IconButtonWidget* m_handicap_widget; + GUIEngine::IconButtonWidget* m_report_widget; public: NetworkUserDialog(uint32_t host_id, uint32_t online_id, uint8_t local_id, const core::stringw& name, bool allow_change_team, @@ -80,6 +81,7 @@ public: : ModalDialog(0.8f,0.8f), m_host_id(host_id), m_online_id(online_id), m_local_id(local_id), m_per_player_difficulty(d), m_name(name), m_allow_change_team(allow_change_team), m_self_destroy(false), + m_open_report_textbox(false), m_fetched_ranking(std::make_shared(false)) { loadFromFile("online/user_info_dialog.stkgui");