mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 20:22:55 +08:00
Added ability to report chat
This commit is contained in:
parent
ca8d2bec9d
commit
b37f1cce3f
@ -30,6 +30,8 @@ using osu.Game.Overlays.Chat.Listing;
|
|||||||
using osu.Game.Overlays.Chat.ChannelList;
|
using osu.Game.Overlays.Chat.ChannelList;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Online
|
namespace osu.Game.Tests.Visual.Online
|
||||||
{
|
{
|
||||||
@ -530,6 +532,42 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestChatReport()
|
||||||
|
{
|
||||||
|
AddStep("Show overlay with channel", () =>
|
||||||
|
{
|
||||||
|
chatOverlay.Show();
|
||||||
|
channelManager.CurrentChannel.Value = channelManager.JoinChannel(testChannel1);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("Overlay is visible", () => chatOverlay.State.Value == Visibility.Visible);
|
||||||
|
waitForChannel1Visible();
|
||||||
|
|
||||||
|
AddStep("Right click username", () =>
|
||||||
|
{
|
||||||
|
var username = this.ChildrenOfType<DrawableUsername>().First();
|
||||||
|
InputManager.MoveMouseTo(username);
|
||||||
|
InputManager.Click(MouseButton.Right);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("Click report", () =>
|
||||||
|
{
|
||||||
|
var btn = this.ChildrenOfType<OsuSpriteText>().First(x => x.Text == "Report");
|
||||||
|
InputManager.MoveMouseTo(btn);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("Try to report", () =>
|
||||||
|
{
|
||||||
|
var btn = this.ChildrenOfType<ReportChatPopover>().Single().ChildrenOfType<RoundedButton>().Single();
|
||||||
|
InputManager.MoveMouseTo(btn);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("Report message sended", () => channelManager.CurrentChannel.Value.Messages.Any(x => x.Content.Contains("!report")));
|
||||||
|
}
|
||||||
|
|
||||||
private void joinTestChannel(int i)
|
private void joinTestChannel(int i)
|
||||||
{
|
{
|
||||||
AddStep($"Join test channel {i}", () => channelManager.JoinChannel(testChannels[i]));
|
AddStep($"Join test channel {i}", () => channelManager.JoinChannel(testChannels[i]));
|
||||||
|
36
osu.Game/Overlays/Chat/ChatReportReason.cs
Normal file
36
osu.Game/Overlays/Chat/ChatReportReason.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.ComponentModel;
|
||||||
|
using osu.Framework.Localisation;
|
||||||
|
using osu.Game.Resources.Localisation.Web;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Chat
|
||||||
|
{
|
||||||
|
public enum ChatReportReason
|
||||||
|
{
|
||||||
|
[Description("Insulting People")]
|
||||||
|
[LocalisableDescription(typeof(UsersStrings), nameof(UsersStrings.ReportOptionsInsults))]
|
||||||
|
Insults,
|
||||||
|
|
||||||
|
[Description("Spam")]
|
||||||
|
[LocalisableDescription(typeof(UsersStrings), nameof(UsersStrings.ReportOptionsSpam))]
|
||||||
|
Spam,
|
||||||
|
|
||||||
|
[Description("Cheating")]
|
||||||
|
[LocalisableDescription(typeof(UsersStrings), nameof(UsersStrings.ReportOptionsCheating))]
|
||||||
|
FoulPlay,
|
||||||
|
|
||||||
|
[Description("Unwanted Content")]
|
||||||
|
[LocalisableDescription(typeof(UsersStrings), nameof(UsersStrings.ReportOptionsUnwantedContent))]
|
||||||
|
UnwantedContent,
|
||||||
|
|
||||||
|
[Description("Nonsense")]
|
||||||
|
[LocalisableDescription(typeof(UsersStrings), nameof(UsersStrings.ReportOptionsNonsense))]
|
||||||
|
Nonsense,
|
||||||
|
|
||||||
|
[Description("Other")]
|
||||||
|
[LocalisableDescription(typeof(UsersStrings), nameof(UsersStrings.ReportOptionsOther))]
|
||||||
|
Other
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -25,7 +26,7 @@ using osuTK.Graphics;
|
|||||||
|
|
||||||
namespace osu.Game.Overlays.Chat
|
namespace osu.Game.Overlays.Chat
|
||||||
{
|
{
|
||||||
public partial class DrawableUsername : OsuClickableContainer, IHasContextMenu
|
public partial class DrawableUsername : OsuClickableContainer, IHasContextMenu, IHasPopover
|
||||||
{
|
{
|
||||||
public Color4 AccentColour { get; }
|
public Color4 AccentColour { get; }
|
||||||
|
|
||||||
@ -152,12 +153,20 @@ namespace osu.Game.Overlays.Chat
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!user.Equals(api.LocalUser.Value))
|
if (!user.Equals(api.LocalUser.Value))
|
||||||
|
{
|
||||||
items.Add(new OsuMenuItem("Start Chat", MenuItemType.Standard, openUserChannel));
|
items.Add(new OsuMenuItem("Start Chat", MenuItemType.Standard, openUserChannel));
|
||||||
|
items.Add(new OsuMenuItem("Report", MenuItemType.Destructive, this.ShowPopover));
|
||||||
|
}
|
||||||
|
|
||||||
return items.ToArray();
|
return items.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void report(ChatReportReason reason, string comments)
|
||||||
|
{
|
||||||
|
chatManager?.PostMessage($"!report {user.Username} ({reason.GetDescription()}): {comments}");
|
||||||
|
}
|
||||||
|
|
||||||
private void openUserChannel()
|
private void openUserChannel()
|
||||||
{
|
{
|
||||||
chatManager?.OpenPrivateChannel(user);
|
chatManager?.OpenPrivateChannel(user);
|
||||||
@ -221,5 +230,10 @@ namespace osu.Game.Overlays.Chat
|
|||||||
Color4Extensions.FromHex("812a96"),
|
Color4Extensions.FromHex("812a96"),
|
||||||
Color4Extensions.FromHex("992861"),
|
Color4Extensions.FromHex("992861"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public Popover GetPopover() => new ReportChatPopover(user)
|
||||||
|
{
|
||||||
|
Action = report
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
106
osu.Game/Overlays/Chat/ReportChatPopover.cs
Normal file
106
osu.Game/Overlays/Chat/ReportChatPopover.cs
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Audio;
|
||||||
|
using osu.Framework.Extensions;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Game.Resources.Localisation.Web;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Chat
|
||||||
|
{
|
||||||
|
public partial class ReportChatPopover : OsuPopover
|
||||||
|
{
|
||||||
|
public Action<ChatReportReason, string>? Action;
|
||||||
|
|
||||||
|
private readonly APIUser? user;
|
||||||
|
|
||||||
|
private OsuEnumDropdown<ChatReportReason> reasonDropdown = null!;
|
||||||
|
private OsuTextBox commentsTextBox = null!;
|
||||||
|
|
||||||
|
public ReportChatPopover(APIUser? user)
|
||||||
|
{
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuColour colours, AudioManager audio)
|
||||||
|
{
|
||||||
|
Child = new ReverseChildIDFillFlowContainer<Drawable>
|
||||||
|
{
|
||||||
|
Direction = FillDirection.Vertical,
|
||||||
|
Width = 500,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
Spacing = new Vector2(7),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new SpriteIcon
|
||||||
|
{
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Icon = FontAwesome.Solid.ExclamationTriangle,
|
||||||
|
Size = new Vector2(36),
|
||||||
|
},
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Text = ReportStrings.UserTitle(user?.Username ?? @"Someone"),
|
||||||
|
Font = OsuFont.Torus.With(size: 25),
|
||||||
|
Margin = new MarginPadding { Bottom = 10 }
|
||||||
|
},
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Text = UsersStrings.ReportReason,
|
||||||
|
},
|
||||||
|
new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
Height = 40,
|
||||||
|
Child = reasonDropdown = new OsuEnumDropdown<ChatReportReason>
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Text = UsersStrings.ReportComments,
|
||||||
|
},
|
||||||
|
commentsTextBox = new OsuTextBox
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
PlaceholderText = UsersStrings.ReportPlaceholder,
|
||||||
|
},
|
||||||
|
new RoundedButton
|
||||||
|
{
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Width = 200,
|
||||||
|
BackgroundColour = colours.Red3,
|
||||||
|
Text = UsersStrings.ReportActionsSend,
|
||||||
|
Action = () =>
|
||||||
|
{
|
||||||
|
Action?.Invoke(reasonDropdown.Current.Value, commentsTextBox.Text);
|
||||||
|
this.HidePopover();
|
||||||
|
},
|
||||||
|
Margin = new MarginPadding { Bottom = 5, Top = 10 },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,7 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Cursor;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
@ -122,7 +123,7 @@ namespace osu.Game.Overlays
|
|||||||
RelativeSizeAxes = Axes.Y,
|
RelativeSizeAxes = Axes.Y,
|
||||||
Width = side_bar_width,
|
Width = side_bar_width,
|
||||||
},
|
},
|
||||||
new Container
|
new PopoverContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Anchor = Anchor.TopRight,
|
Anchor = Anchor.TopRight,
|
||||||
|
Loading…
Reference in New Issue
Block a user