2019-01-24 08:43:03 +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.
|
2018-12-20 07:50:38 +00:00
|
|
|
|
2018-12-21 08:54:12 +00:00
|
|
|
using System;
|
2018-12-20 07:50:38 +00:00
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
using osu.Framework.Bindables;
|
2018-12-20 07:50:38 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-12-20 09:21:37 +00:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2019-10-22 15:24:08 +00:00
|
|
|
using osu.Game.Graphics;
|
2018-12-20 09:21:37 +00:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-12-21 08:54:12 +00:00
|
|
|
using osu.Game.Overlays.Chat;
|
2018-12-20 07:50:38 +00:00
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Online.Chat
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Display a chat channel in an insolated region.
|
|
|
|
/// </summary>
|
|
|
|
public class StandAloneChatDisplay : CompositeDrawable
|
|
|
|
{
|
2018-12-21 08:54:12 +00:00
|
|
|
public readonly Bindable<Channel> Channel = new Bindable<Channel>();
|
2018-12-20 07:50:38 +00:00
|
|
|
|
2018-12-20 09:21:37 +00:00
|
|
|
private readonly FocusedTextBox textbox;
|
|
|
|
|
|
|
|
protected ChannelManager ChannelManager;
|
|
|
|
|
2020-03-23 03:03:33 +00:00
|
|
|
private StandAloneDrawableChannel drawableChannel;
|
2018-12-21 08:54:12 +00:00
|
|
|
|
2018-12-25 08:14:56 +00:00
|
|
|
private readonly bool postingTextbox;
|
|
|
|
|
2018-12-21 08:54:12 +00:00
|
|
|
private const float textbox_height = 30;
|
|
|
|
|
2018-12-20 09:21:37 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Construct a new instance.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="postingTextbox">Whether a textbox for posting new messages should be displayed.</param>
|
|
|
|
public StandAloneChatDisplay(bool postingTextbox = false)
|
2018-12-20 07:50:38 +00:00
|
|
|
{
|
2018-12-21 08:54:12 +00:00
|
|
|
this.postingTextbox = postingTextbox;
|
2018-12-20 07:50:38 +00:00
|
|
|
CornerRadius = 10;
|
|
|
|
Masking = true;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.Black,
|
|
|
|
Alpha = 0.8f,
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-12-20 09:21:37 +00:00
|
|
|
if (postingTextbox)
|
|
|
|
{
|
|
|
|
AddInternal(textbox = new FocusedTextBox
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Height = textbox_height,
|
|
|
|
PlaceholderText = "type your message",
|
|
|
|
OnCommit = postMessage,
|
|
|
|
ReleaseFocusOnCommit = false,
|
|
|
|
HoldFocus = true,
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-20 07:50:38 +00:00
|
|
|
Channel.BindValueChanged(channelChanged);
|
|
|
|
}
|
|
|
|
|
2018-12-20 09:21:37 +00:00
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
private void load(ChannelManager manager)
|
|
|
|
{
|
2020-06-03 07:48:44 +00:00
|
|
|
ChannelManager ??= manager;
|
2018-12-20 09:21:37 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 03:03:33 +00:00
|
|
|
protected virtual StandAloneDrawableChannel CreateDrawableChannel(Channel channel) =>
|
|
|
|
new StandAloneDrawableChannel(channel);
|
|
|
|
|
2018-12-20 09:21:37 +00:00
|
|
|
private void postMessage(TextBox sender, bool newtext)
|
|
|
|
{
|
|
|
|
var text = textbox.Text.Trim();
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(text))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (text[0] == '/')
|
2019-02-21 09:56:34 +00:00
|
|
|
ChannelManager?.PostCommand(text.Substring(1), Channel.Value);
|
2018-12-20 09:21:37 +00:00
|
|
|
else
|
2019-02-21 09:56:34 +00:00
|
|
|
ChannelManager?.PostMessage(text, target: Channel.Value);
|
2018-12-20 09:21:37 +00:00
|
|
|
|
|
|
|
textbox.Text = string.Empty;
|
|
|
|
}
|
|
|
|
|
2018-12-21 08:54:12 +00:00
|
|
|
protected virtual ChatLine CreateMessage(Message message) => new StandAloneMessage(message);
|
2018-12-20 07:50:38 +00:00
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
private void channelChanged(ValueChangedEvent<Channel> e)
|
2018-12-20 07:50:38 +00:00
|
|
|
{
|
2018-12-21 08:54:12 +00:00
|
|
|
drawableChannel?.Expire();
|
2018-12-20 07:50:38 +00:00
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
if (e.NewValue == null) return;
|
2018-12-20 07:50:38 +00:00
|
|
|
|
2020-03-23 03:03:33 +00:00
|
|
|
drawableChannel = CreateDrawableChannel(e.NewValue);
|
|
|
|
drawableChannel.CreateChatLineAction = CreateMessage;
|
|
|
|
drawableChannel.Padding = new MarginPadding { Bottom = postingTextbox ? textbox_height : 0 };
|
|
|
|
|
|
|
|
AddInternal(drawableChannel);
|
2018-12-20 07:50:38 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 03:03:33 +00:00
|
|
|
public class StandAloneDrawableChannel : DrawableChannel
|
2018-12-20 07:50:38 +00:00
|
|
|
{
|
2019-02-28 04:31:40 +00:00
|
|
|
public Func<Message, ChatLine> CreateChatLineAction;
|
2018-12-21 08:54:12 +00:00
|
|
|
|
|
|
|
protected override ChatLine CreateChatLine(Message m) => CreateChatLineAction(m);
|
2018-12-20 07:50:38 +00:00
|
|
|
|
2019-10-22 15:24:08 +00:00
|
|
|
protected override DaySeparator CreateDaySeparator(DateTimeOffset time) => new CustomDaySeparator(time);
|
2019-10-21 22:30:37 +00:00
|
|
|
|
2018-12-21 08:54:12 +00:00
|
|
|
public StandAloneDrawableChannel(Channel channel)
|
|
|
|
: base(channel)
|
2019-06-20 14:01:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
2018-12-20 07:50:38 +00:00
|
|
|
{
|
2018-12-21 08:54:12 +00:00
|
|
|
ChatLineFlow.Padding = new MarginPadding { Horizontal = 0 };
|
2018-12-20 07:50:38 +00:00
|
|
|
}
|
2019-10-22 15:24:08 +00:00
|
|
|
|
|
|
|
private class CustomDaySeparator : DaySeparator
|
|
|
|
{
|
2019-10-22 15:26:47 +00:00
|
|
|
public CustomDaySeparator(DateTimeOffset time)
|
|
|
|
: base(time)
|
2019-10-22 15:24:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
Colour = colours.Yellow;
|
|
|
|
TextSize = 14;
|
|
|
|
LineHeight = 1;
|
|
|
|
Padding = new MarginPadding { Horizontal = 10 };
|
|
|
|
Margin = new MarginPadding { Vertical = 5 };
|
|
|
|
}
|
|
|
|
}
|
2018-12-20 07:50:38 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 08:54:12 +00:00
|
|
|
protected class StandAloneMessage : ChatLine
|
2018-12-20 07:50:38 +00:00
|
|
|
{
|
2018-12-21 08:54:12 +00:00
|
|
|
protected override float TextSize => 15;
|
2018-12-20 07:50:38 +00:00
|
|
|
|
2018-12-21 08:54:12 +00:00
|
|
|
protected override float HorizontalPadding => 10;
|
|
|
|
protected override float MessagePadding => 120;
|
2019-10-01 16:18:03 +00:00
|
|
|
protected override float TimestampPadding => 50;
|
2018-12-20 07:50:38 +00:00
|
|
|
|
2019-02-28 04:31:40 +00:00
|
|
|
public StandAloneMessage(Message message)
|
|
|
|
: base(message)
|
2018-12-20 07:50:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|