Add report player function in dialog

This commit is contained in:
Benau 2019-05-09 10:04:19 +08:00
parent e97e84f194
commit bb3566ac81
3 changed files with 48 additions and 3 deletions

View File

@ -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

View File

@ -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<IconButtonWidget>("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<IconButtonWidget>("remove")->setVisible(false);
getWidget<IconButtonWidget>("enter")->setVisible(false);
m_report_widget = getWidget<IconButtonWidget>("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();

View File

@ -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<bool> 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<bool>(false))
{
loadFromFile("online/user_info_dialog.stkgui");