2022-03-29 20:36:08 +00:00
|
|
|
// 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.
|
|
|
|
|
2022-04-02 16:15:19 +00:00
|
|
|
using System;
|
2022-03-29 20:36:08 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2022-04-02 16:15:19 +00:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2022-05-02 19:57:39 +00:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2022-03-29 20:36:08 +00:00
|
|
|
using osu.Game.Online.Chat;
|
2022-05-27 05:23:03 +00:00
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2022-03-29 20:36:08 +00:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Chat
|
|
|
|
{
|
|
|
|
public class ChatTextBar : Container
|
|
|
|
{
|
|
|
|
public readonly BindableBool ShowSearch = new BindableBool();
|
|
|
|
|
2022-04-02 20:58:54 +00:00
|
|
|
public event Action<string>? OnChatMessageCommitted;
|
2022-04-02 16:15:19 +00:00
|
|
|
|
|
|
|
public event Action<string>? OnSearchTermsChanged;
|
2022-03-29 20:36:08 +00:00
|
|
|
|
2022-05-03 21:33:36 +00:00
|
|
|
public void TextBoxTakeFocus() => chatTextBox.TakeFocus();
|
|
|
|
|
|
|
|
public void TextBoxKillFocus() => chatTextBox.KillFocus();
|
|
|
|
|
2022-03-29 20:36:08 +00:00
|
|
|
[Resolved]
|
|
|
|
private Bindable<Channel> currentChannel { get; set; } = null!;
|
|
|
|
|
2022-05-02 19:57:39 +00:00
|
|
|
private Container chattingTextContainer = null!;
|
|
|
|
private OsuSpriteText chattingText = null!;
|
2022-03-29 20:36:08 +00:00
|
|
|
private Container searchIconContainer = null!;
|
2022-04-02 16:15:19 +00:00
|
|
|
private ChatTextBox chatTextBox = null!;
|
2022-03-29 20:36:08 +00:00
|
|
|
|
2022-05-06 21:56:35 +00:00
|
|
|
private const float chatting_text_width = 220;
|
2022-03-29 20:36:08 +00:00
|
|
|
private const float search_icon_width = 40;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
Height = 60;
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = colourProvider.Background5,
|
|
|
|
},
|
|
|
|
new GridContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
new Dimension(),
|
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
|
|
|
{
|
2022-05-02 19:57:39 +00:00
|
|
|
chattingTextContainer = new Container
|
2022-03-29 20:36:08 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2022-05-02 19:57:39 +00:00
|
|
|
Width = chatting_text_width,
|
|
|
|
Masking = true,
|
2022-05-03 21:32:51 +00:00
|
|
|
Padding = new MarginPadding { Right = 5 },
|
2022-05-02 19:57:39 +00:00
|
|
|
Child = chattingText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Font = OsuFont.Torus.With(size: 20),
|
|
|
|
Colour = colourProvider.Background1,
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
Truncate = true,
|
|
|
|
},
|
2022-03-29 20:36:08 +00:00
|
|
|
},
|
|
|
|
searchIconContainer = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Width = search_icon_width,
|
|
|
|
Child = new SpriteIcon
|
|
|
|
{
|
|
|
|
Icon = FontAwesome.Solid.Search,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Size = new Vector2(20),
|
|
|
|
Margin = new MarginPadding { Right = 2 },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding { Right = 5 },
|
2022-04-02 16:15:19 +00:00
|
|
|
Child = chatTextBox = new ChatTextBox
|
2022-03-29 20:36:08 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
ShowSearch = { BindTarget = ShowSearch },
|
|
|
|
HoldFocus = true,
|
|
|
|
ReleaseFocusOnCommit = false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-04-02 16:15:19 +00:00
|
|
|
chatTextBox.Current.ValueChanged += chatTextBoxChange;
|
|
|
|
chatTextBox.OnCommit += chatTextBoxCommit;
|
|
|
|
|
2022-03-29 20:36:08 +00:00
|
|
|
ShowSearch.BindValueChanged(change =>
|
|
|
|
{
|
2022-03-30 20:01:28 +00:00
|
|
|
bool showSearch = change.NewValue;
|
|
|
|
|
|
|
|
chattingTextContainer.FadeTo(showSearch ? 0 : 1);
|
|
|
|
searchIconContainer.FadeTo(showSearch ? 1 : 0);
|
2022-04-02 16:15:19 +00:00
|
|
|
|
|
|
|
// Clear search terms if any exist when switching back to chat mode
|
|
|
|
if (!showSearch)
|
|
|
|
OnSearchTermsChanged?.Invoke(string.Empty);
|
2022-03-29 20:36:08 +00:00
|
|
|
}, true);
|
|
|
|
|
|
|
|
currentChannel.BindValueChanged(change =>
|
|
|
|
{
|
|
|
|
Channel newChannel = change.NewValue;
|
2022-03-30 01:16:50 +00:00
|
|
|
|
2022-03-29 20:36:08 +00:00
|
|
|
switch (newChannel?.Type)
|
|
|
|
{
|
2022-05-27 15:06:23 +00:00
|
|
|
case null:
|
|
|
|
chattingText.Text = string.Empty;
|
2022-03-29 20:36:08 +00:00
|
|
|
break;
|
2022-03-30 01:16:50 +00:00
|
|
|
|
2022-03-29 20:36:08 +00:00
|
|
|
case ChannelType.PM:
|
2022-05-27 05:23:03 +00:00
|
|
|
chattingText.Text = ChatStrings.TalkingWith(newChannel.Name);
|
2022-03-29 20:36:08 +00:00
|
|
|
break;
|
2022-03-30 01:16:50 +00:00
|
|
|
|
2022-03-29 20:36:08 +00:00
|
|
|
default:
|
2022-05-27 15:06:23 +00:00
|
|
|
chattingText.Text = ChatStrings.TalkingIn(newChannel.Name);
|
2022-03-29 20:36:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
}
|
2022-04-02 16:15:19 +00:00
|
|
|
|
|
|
|
private void chatTextBoxChange(ValueChangedEvent<string> change)
|
|
|
|
{
|
|
|
|
if (ShowSearch.Value)
|
|
|
|
OnSearchTermsChanged?.Invoke(change.NewValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void chatTextBoxCommit(TextBox sender, bool newText)
|
|
|
|
{
|
2022-04-03 12:23:45 +00:00
|
|
|
if (ShowSearch.Value)
|
|
|
|
return;
|
2022-04-02 20:58:54 +00:00
|
|
|
|
2022-04-03 12:23:45 +00:00
|
|
|
OnChatMessageCommitted?.Invoke(sender.Text);
|
2022-04-02 20:58:54 +00:00
|
|
|
sender.Text = string.Empty;
|
2022-04-02 16:15:19 +00:00
|
|
|
}
|
2022-03-29 20:36:08 +00:00
|
|
|
}
|
|
|
|
}
|