1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 16:27:26 +08:00

Implement DaySeparator class

This commit is contained in:
Andrei Zavatski 2019-10-22 01:30:37 +03:00
parent 75f444e431
commit d19041fa53
2 changed files with 81 additions and 11 deletions

View File

@ -124,6 +124,14 @@ namespace osu.Game.Online.Chat
protected override ChatLine CreateChatLine(Message m) => CreateChatLineAction(m);
protected override DaySeparator CreateDaySeparator(DateTimeOffset time) => new DaySeparator(time)
{
Colour = Color4.White,
TextSize = 14,
LineHeight = 1,
Margin = new MarginPadding { Horizontal = 10 }
};
public StandAloneDrawableChannel(Channel channel)
: base(channel)
{

View File

@ -14,6 +14,9 @@ using osu.Game.Graphics.Cursor;
using osu.Game.Online.Chat;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Graphics;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics.Sprites;
namespace osu.Game.Overlays.Chat
{
@ -23,6 +26,9 @@ namespace osu.Game.Overlays.Chat
protected ChatLineContainer ChatLineFlow;
private OsuScrollContainer scroll;
[Resolved]
private OsuColour colours { get; set; }
public DrawableChannel(Channel channel)
{
Channel = channel;
@ -76,16 +82,9 @@ namespace osu.Game.Overlays.Chat
protected virtual ChatLine CreateChatLine(Message m) => new ChatLine(m);
protected virtual Drawable CreateDaySeparator(DateTimeOffset time) => new Container
protected virtual DaySeparator CreateDaySeparator(DateTimeOffset time) => new DaySeparator(time)
{
Margin = new MarginPadding { Vertical = 5 },
RelativeSizeAxes = Axes.X,
Height = 2,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
}
Colour = colours.ChatBlue.Lighten(0.7f)
};
private void newMessagesArrived(IEnumerable<Message> newMessages)
@ -95,11 +94,11 @@ namespace osu.Game.Overlays.Chat
var existingChatLines = getChatLines();
Message lastMessage = existingChatLines.Any() ? existingChatLines.First().Message : null;
Message lastMessage = existingChatLines.Any() ? existingChatLines.Last().Message : null;
displayMessages.ForEach(m =>
{
if (lastMessage == null || lastMessage.Timestamp.ToLocalTime().Date != m.Timestamp.ToLocalTime().Date)
if (lastMessage == null || lastMessage.Timestamp.ToLocalTime().Day != m.Timestamp.ToLocalTime().Day)
ChatLineFlow.Add(CreateDaySeparator(m.Timestamp));
ChatLineFlow.Add(CreateChatLine(m));
@ -158,5 +157,68 @@ namespace osu.Game.Overlays.Chat
return base.Compare(x, y);
}
}
protected class DaySeparator : GridContainer
{
public float TextSize
{
get => text.Font.Size;
set => text.Font = text.Font.With(size: value);
}
private float lineHeight = 2;
public float LineHeight
{
get => LineHeight;
set { lineHeight = leftBox.Height = rightBox.Height = value; }
}
private readonly SpriteText text;
private readonly Box leftBox;
private readonly Box rightBox;
public DaySeparator(DateTimeOffset time)
{
Margin = new MarginPadding { Vertical = 10 };
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
ColumnDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
};
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
};
Content = new[]
{
new Drawable[]
{
leftBox = new Box
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
Height = lineHeight,
},
text = new SpriteText
{
Margin = new MarginPadding { Horizontal = 10 },
Text = time.ToLocalTime().ToString("dd MMM yyyy"),
},
rightBox = new Box
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
Height = lineHeight,
},
}
};
}
}
}
}