Skip to content

Commit

Permalink
Merge pull request #22262 from Joehuu/chat-mention-user
Browse files Browse the repository at this point in the history
Add ability to easily mention users in chat by right clicking username
  • Loading branch information
peppy authored Jan 18, 2023
2 parents 736ff41 + dfea42f commit f7c4199
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions osu.Game/Localisation/ChatStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public static class ChatStrings
/// </summary>
public static LocalisableString HeaderDescription => new TranslatableString(getKey(@"header_description"), @"join the real-time discussion");

/// <summary>
/// "Mention"
/// </summary>
public static LocalisableString MentionUser => new TranslatableString(getKey(@"mention_user"), @"Mention");

private static string getKey(string key) => $"{prefix}:{key}";
}
}
1 change: 1 addition & 0 deletions osu.Game/Online/Chat/StandAloneChatDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace osu.Game.Online.Chat
/// </summary>
public partial class StandAloneChatDisplay : CompositeDrawable
{
[Cached]
public readonly Bindable<Channel> Channel = new Bindable<Channel>();

protected readonly ChatTextBox TextBox;
Expand Down
13 changes: 13 additions & 0 deletions osu.Game/Overlays/Chat/DrawableUsername.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
Expand All @@ -24,6 +25,7 @@
using osu.Game.Resources.Localisation.Web;
using osuTK;
using osuTK.Graphics;
using ChatStrings = osu.Game.Localisation.ChatStrings;

namespace osu.Game.Overlays.Chat
{
Expand Down Expand Up @@ -65,6 +67,9 @@ public override float Width
[Resolved(canBeNull: true)]
private UserProfileOverlay? profileOverlay { get; set; }

[Resolved]
private Bindable<Channel?>? currentChannel { get; set; }

private readonly APIUser user;
private readonly OsuSpriteText drawableText;

Expand Down Expand Up @@ -156,6 +161,14 @@ public MenuItem[] ContextMenuItems
if (!user.Equals(api.LocalUser.Value))
items.Add(new OsuMenuItem(UsersStrings.CardSendMessage, MenuItemType.Standard, openUserChannel));

if (currentChannel?.Value != null)
{
items.Add(new OsuMenuItem(ChatStrings.MentionUser, MenuItemType.Standard, () =>
{
currentChannel.Value.TextBoxMessage.Value += $"@{user.Username} ";
}));
}

return items.ToArray();
}
}
Expand Down

0 comments on commit f7c4199

Please sign in to comment.