1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 18:52:55 +08:00

Forward action in saner way

This commit is contained in:
Dean Herbert 2017-07-19 18:22:46 +09:00
parent b6b7ae47db
commit 2c5019ff7c

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
@ -11,6 +12,7 @@ using OpenTK.Graphics;
using osu.Framework.Graphics.Effects;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Allocation;
using osu.Game.Users;
namespace osu.Game.Overlays.Chat
{
@ -62,7 +64,8 @@ namespace osu.Game.Overlays.Chat
private const float message_padding = 200;
private const float text_size = 20;
private UserProfileOverlay profileOverlay;
private Action<User> loadProfile;
private Color4 customUsernameColour;
public ChatLine(Message message)
@ -76,9 +79,10 @@ namespace osu.Game.Overlays.Chat
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
private void load(OsuColour colours, UserProfileOverlay profile)
{
customUsernameColour = colours.ChatBlue;
loadProfile = u => profile?.ShowUser(u);
}
protected override void LoadComplete()
@ -88,8 +92,6 @@ namespace osu.Game.Overlays.Chat
bool hasBackground = !string.IsNullOrEmpty(Message.Sender.Colour);
Drawable username = new OsuSpriteText
{
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
Font = @"Exo2.0-BoldItalic",
Text = $@"{Message.Sender.Username}" + (hasBackground ? "" : ":"),
Colour = hasBackground ? customUsernameColour : username_colours[Message.UserId % username_colours.Length],
@ -133,7 +135,7 @@ namespace osu.Game.Overlays.Chat
new Container
{
Size = new Vector2(message_padding, text_size),
Children = new[]
Children = new Drawable[]
{
new OsuSpriteText
{
@ -150,8 +152,8 @@ namespace osu.Game.Overlays.Chat
AutoSizeAxes = Axes.Both,
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
Child = username
Action = () => profileOverlay?.ShowUser(Message.Sender),
Child = username,
Action = () => loadProfile(Message.Sender),
},
}
},
@ -173,11 +175,5 @@ namespace osu.Game.Overlays.Chat
}
};
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(UserProfileOverlay profileOverlay)
{
this.profileOverlay = profileOverlay;
}
}
}