Improve design as requested

This commit is contained in:
Thomas Müller 2017-07-18 12:26:05 +03:00
parent 52acd23a5a
commit e58ea97604

View File

@ -8,8 +8,9 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Allocation;
namespace osu.Game.Overlays.Chat namespace osu.Game.Overlays.Chat
{ {
@ -61,6 +62,8 @@ namespace osu.Game.Overlays.Chat
private const float message_padding = 200; private const float message_padding = 200;
private const float text_size = 20; private const float text_size = 20;
private Color4 customUsernameColour;
public ChatLine(Message message) public ChatLine(Message message)
{ {
Message = message; Message = message;
@ -69,33 +72,58 @@ namespace osu.Game.Overlays.Chat
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
Padding = new MarginPadding { Left = padding, Right = padding }; Padding = new MarginPadding { Left = padding, Right = padding };
}
bool hasBackground = !string.IsNullOrEmpty(message.Sender?.Colour); [BackgroundDependencyLoader]
private void load(OsuColour colours)
{
customUsernameColour = colours.ChatBlue;
}
protected override void LoadComplete()
{
base.LoadComplete();
bool hasBackground = !string.IsNullOrEmpty(Message.Sender?.Colour);
Drawable username = new OsuSpriteText Drawable username = new OsuSpriteText
{ {
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Font = @"Exo2.0-BoldItalic", Font = @"Exo2.0-BoldItalic",
Text = $@"{Message.Sender.Username}:", Text = $@"{Message.Sender.Username}" + (hasBackground ? "" : ":"),
Colour = hasBackground ? Color4.Black : username_colours[message.UserId % username_colours.Length], Colour = hasBackground ? customUsernameColour : username_colours[Message.UserId % username_colours.Length],
TextSize = text_size, TextSize = text_size,
}; };
if (hasBackground) if (hasBackground)
{ {
// Background effect
username = username.WithEffect(new EdgeEffect username = username.WithEffect(new EdgeEffect
{ {
CornerRadius = 4, CornerRadius = 4,
Parameters = new EdgeEffectParameters Parameters = new EdgeEffectParameters
{ {
Radius = 1, Radius = 1,
Colour = OsuColour.FromHex(message.Sender.Colour), Colour = OsuColour.FromHex(Message.Sender.Colour),
Type = EdgeEffectType.Shadow, Type = EdgeEffectType.Shadow,
} }
}, d => }, d =>
{ {
d.Padding = new MarginPadding { Top = -2 }; d.Padding = new MarginPadding { Left = 3, Right = 3, Bottom = 1, Top = -3 };
d.Y = 2; d.Y = 3;
})
// Drop shadow effect
.WithEffect(new EdgeEffect
{
CornerRadius = 4,
Parameters = new EdgeEffectParameters
{
Roundness = 1,
Offset = new Vector2(0, 3),
Radius = 3,
Colour = Color4.Black.Opacity(0.3f),
Type = EdgeEffectType.Shadow,
}
}); });
} }
@ -104,7 +132,7 @@ namespace osu.Game.Overlays.Chat
new Container new Container
{ {
Size = new Vector2(message_padding, text_size), Size = new Vector2(message_padding, text_size),
Children = new Drawable[] Children = new[]
{ {
new OsuSpriteText new OsuSpriteText
{ {