2022-03-30 04:36:08 +08: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-03 00:15:19 +08:00
|
|
|
using System;
|
2022-03-30 04:36:08 +08: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-03 00:15:19 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2022-05-03 03:57:39 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2022-03-30 04:36:08 +08:00
|
|
|
using osu.Game.Online.Chat;
|
2022-05-27 13:23:03 +08:00
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2022-03-30 04:36:08 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Chat
|
|
|
|
{
|
|
|
|
public partial class ChatTextBar : Container
|
|
|
|
{
|
|
|
|
public readonly BindableBool ShowSearch = new BindableBool();
|
|
|
|
|
2022-04-03 04:58:54 +08:00
|
|
|
public event Action<string>? OnChatMessageCommitted;
|
2022-04-03 00:15:19 +08:00
|
|
|
|
|
|
|
public event Action<string>? OnSearchTermsChanged;
|
2022-03-30 04:36:08 +08:00
|
|
|
|
2022-05-04 05:33:36 +08:00
|
|
|
public void TextBoxTakeFocus() => chatTextBox.TakeFocus();
|
|
|
|
|
|
|
|
public void TextBoxKillFocus() => chatTextBox.KillFocus();
|
|
|
|
|
2022-03-30 04:36:08 +08:00
|
|
|
[Resolved]
|
|
|
|
private Bindable<Channel> currentChannel { get; set; } = null!;
|
|
|
|
|
2022-05-03 03:57:39 +08:00
|
|
|
private Container chattingTextContainer = null!;
|
|
|
|
private OsuSpriteText chattingText = null!;
|
2022-03-30 04:36:08 +08:00
|
|
|
private Container searchIconContainer = null!;
|
2022-04-03 00:15:19 +08:00
|
|
|
private ChatTextBox chatTextBox = null!;
|
2022-03-30 04:36:08 +08:00
|
|
|
|
2022-05-07 05:56:35 +08:00
|
|
|
private const float chatting_text_width = 220;
|
2022-03-30 04:36:08 +08: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-03 03:57:39 +08:00
|
|
|
chattingTextContainer = new Container
|
2022-03-30 04:36:08 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2022-05-03 03:57:39 +08:00
|
|
|
Width = chatting_text_width,
|
|
|
|
Masking = true,
|
2022-05-04 05:32:51 +08:00
|
|
|
Padding = new MarginPadding { Right = 5 },
|
2022-05-03 03:57:39 +08:00
|
|
|
Child = chattingText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Font = OsuFont.Torus.With(size: 20),
|
|
|
|
Colour = colourProvider.Background1,
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
Truncate = true,
|
|
|
|
},
|
2022-03-30 04:36:08 +08: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-03 00:15:19 +08:00
|
|
|
Child = chatTextBox = new ChatTextBox
|
2022-03-30 04:36:08 +08: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-03 00:15:19 +08:00
|
|
|
chatTextBox.Current.ValueChanged += chatTextBoxChange;
|
|
|
|
chatTextBox.OnCommit += chatTextBoxCommit;
|
|
|
|
|
2022-03-30 04:36:08 +08:00
|
|
|
ShowSearch.BindValueChanged(change =>
|
|
|
|
{
|
2022-03-31 04:01:28 +08:00
|
|
|
bool showSearch = change.NewValue;
|
|
|
|
|
|
|
|
chattingTextContainer.FadeTo(showSearch ? 0 : 1);
|
|
|
|
searchIconContainer.FadeTo(showSearch ? 1 : 0);
|
2022-04-03 00:15:19 +08:00
|
|
|
|
|
|
|
// Clear search terms if any exist when switching back to chat mode
|
|
|
|
if (!showSearch)
|
|
|
|
OnSearchTermsChanged?.Invoke(string.Empty);
|
2022-03-30 04:36:08 +08:00
|
|
|
}, true);
|
|
|
|
|
|
|
|
currentChannel.BindValueChanged(change =>
|
|
|
|
{
|
|
|
|
Channel newChannel = change.NewValue;
|
2022-03-30 09:16:50 +08:00
|
|
|
|
2022-03-30 04:36:08 +08:00
|
|
|
switch (newChannel?.Type)
|
|
|
|
{
|
2022-05-27 23:06:23 +08:00
|
|
|
case null:
|
|
|
|
chattingText.Text = string.Empty;
|
2022-03-30 04:36:08 +08:00
|
|
|
break;
|
2022-03-30 09:16:50 +08:00
|
|
|
|
2022-03-30 04:36:08 +08:00
|
|
|
case ChannelType.PM:
|
2022-05-27 13:23:03 +08:00
|
|
|
chattingText.Text = ChatStrings.TalkingWith(newChannel.Name);
|
2022-03-30 04:36:08 +08:00
|
|
|
break;
|
2022-03-30 09:16:50 +08:00
|
|
|
|
2022-03-30 04:36:08 +08:00
|
|
|
default:
|
2022-05-27 23:06:23 +08:00
|
|
|
chattingText.Text = ChatStrings.TalkingIn(newChannel.Name);
|
2022-03-30 04:36:08 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
}
|
2022-04-03 00:15:19 +08:00
|
|
|
|
|
|
|
private void chatTextBoxChange(ValueChangedEvent<string> change)
|
|
|
|
{
|
|
|
|
if (ShowSearch.Value)
|
|
|
|
OnSearchTermsChanged?.Invoke(change.NewValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void chatTextBoxCommit(TextBox sender, bool newText)
|
|
|
|
{
|
2022-04-03 20:23:45 +08:00
|
|
|
if (ShowSearch.Value)
|
|
|
|
return;
|
2022-04-03 04:58:54 +08:00
|
|
|
|
2022-04-03 20:23:45 +08:00
|
|
|
OnChatMessageCommitted?.Invoke(sender.Text);
|
2022-04-03 04:58:54 +08:00
|
|
|
sender.Text = string.Empty;
|
2022-04-03 00:15:19 +08:00
|
|
|
}
|
2022-03-30 04:36:08 +08:00
|
|
|
}
|
|
|
|
}
|