mirror of
https://github.com/ppy/osu.git
synced 2025-02-20 04:23:14 +08:00
Split out chat component into reusable piece
This commit is contained in:
parent
bb4b54799f
commit
a7c82c9741
@ -1,59 +1,23 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Tournament.IPC;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Tournament.Components
|
||||
{
|
||||
public class MatchChatDisplay : CompositeDrawable
|
||||
public class MatchChatDisplay : StandAloneChatDisplay
|
||||
{
|
||||
private Channel lastChannel;
|
||||
public readonly Bindable<Channel> Channel = new Bindable<Channel>();
|
||||
private readonly FillFlowContainer messagesFlow;
|
||||
|
||||
public MatchChatDisplay()
|
||||
{
|
||||
CornerRadius = 10;
|
||||
Masking = true;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
Colour = Color4.Black,
|
||||
Alpha = 0.8f,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
messagesFlow = new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
LayoutEasing = Easing.Out,
|
||||
LayoutDuration = 500,
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
Direction = FillDirection.Vertical,
|
||||
},
|
||||
};
|
||||
|
||||
Channel.BindValueChanged(channelChanged);
|
||||
}
|
||||
|
||||
private readonly Bindable<string> chatChannel = new Bindable<string>();
|
||||
|
||||
protected override Drawable CreateMessage(Message message) => new MatchMessage(message);
|
||||
|
||||
private ChannelManager manager;
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
@ -92,132 +56,26 @@ namespace osu.Game.Tournament.Components
|
||||
}
|
||||
}
|
||||
|
||||
private void channelChanged(Channel channel)
|
||||
protected class MatchMessage : StandAloneMessage
|
||||
{
|
||||
if (lastChannel != null)
|
||||
lastChannel.NewMessagesArrived -= newMessages;
|
||||
|
||||
lastChannel = channel;
|
||||
messagesFlow.Clear();
|
||||
|
||||
if (channel == null) return;
|
||||
|
||||
channel.NewMessagesArrived += newMessages;
|
||||
}
|
||||
|
||||
private void newMessages(IEnumerable<Message> messages)
|
||||
{
|
||||
var excessChildren = messagesFlow.Children.Count - 10;
|
||||
if (excessChildren > 0)
|
||||
{
|
||||
foreach (var c in messagesFlow.Children.Take(excessChildren))
|
||||
c.Expire();
|
||||
}
|
||||
|
||||
foreach (var message in messages)
|
||||
{
|
||||
var formatted = MessageFormatter.FormatMessage(message);
|
||||
messagesFlow.Add(new MatchMessage(formatted) { Y = messagesFlow.Height });
|
||||
}
|
||||
}
|
||||
|
||||
private class MatchMessage : CompositeDrawable
|
||||
{
|
||||
private readonly Message message;
|
||||
|
||||
public MatchMessage(Message message)
|
||||
: base(message)
|
||||
{
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
private readonly Color4 red = new Color4(186, 0, 18, 255);
|
||||
private readonly Color4 blue = new Color4(17, 136, 170, 255);
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(LadderInfo info)
|
||||
{
|
||||
Circle colourBox;
|
||||
|
||||
Margin = new MarginPadding(3);
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
|
||||
OsuSpriteText senderText;
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Width = 0.2f,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
senderText = new OsuSpriteText
|
||||
{
|
||||
Font = @"Exo2.0-Bold",
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
Text = message.Sender.ToString()
|
||||
}
|
||||
}
|
||||
},
|
||||
new Container
|
||||
{
|
||||
Size = new Vector2(8, OsuSpriteText.FONT_SIZE),
|
||||
Margin = new MarginPadding { Horizontal = 3 },
|
||||
Children = new Drawable[]
|
||||
{
|
||||
colourBox = new Circle
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(8),
|
||||
},
|
||||
}
|
||||
},
|
||||
new OsuTextFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Width = 0.5f,
|
||||
Text = message.DisplayContent
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
if (info.CurrentMatch.Value.Team1.Value.Players.Any(u => u.Id == message.Sender.Id))
|
||||
{
|
||||
colourBox.Colour = red;
|
||||
}
|
||||
else if (info.CurrentMatch.Value.Team2.Value.Players.Any(u => u.Id == message.Sender.Id))
|
||||
{
|
||||
colourBox.Colour = blue;
|
||||
}
|
||||
else if (message.Sender.Colour != null)
|
||||
{
|
||||
senderText.Colour = colourBox.Colour = OsuColour.FromHex(message.Sender.Colour);
|
||||
}
|
||||
if (info.CurrentMatch.Value.Team1.Value.Players.Any(u => u.Id == Message.Sender.Id))
|
||||
ColourBox.Colour = red;
|
||||
else if (info.CurrentMatch.Value.Team2.Value.Players.Any(u => u.Id == Message.Sender.Id))
|
||||
ColourBox.Colour = blue;
|
||||
else if (Message.Sender.Colour != null)
|
||||
SenderText.Colour = ColourBox.Colour = OsuColour.FromHex(Message.Sender.Colour);
|
||||
}
|
||||
}
|
||||
|
||||
public void Contract()
|
||||
{
|
||||
this.FadeIn(300);
|
||||
this.MoveToY(0, 500, Easing.OutQuint);
|
||||
}
|
||||
|
||||
public void Expand()
|
||||
{
|
||||
this.FadeOut(200);
|
||||
this.MoveToY(100, 500, Easing.In);
|
||||
private readonly Color4 red = new Color4(186, 0, 18, 255);
|
||||
private readonly Color4 blue = new Color4(17, 136, 170, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user