1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 12:07:25 +08:00
osu-lazer/osu.Game/Overlays/Profile/Header/PreviousUsernamesContainer.cs

176 lines
5.8 KiB
C#
Raw Normal View History

2019-08-02 02:26:59 +08: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.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Users;
using osuTK;
using System;
using System.Linq;
namespace osu.Game.Overlays.Profile.Header
{
2019-08-02 12:41:11 +08:00
public class PreviousUsernamesContainer : CompositeDrawable
2019-08-02 02:26:59 +08:00
{
private const int duration = 200;
private const int margin = 10;
2019-08-02 12:41:11 +08:00
private const int width = 310;
private const int move_offset = 15;
2019-08-02 02:26:59 +08:00
public readonly Bindable<User> User = new Bindable<User>();
private readonly ContentContainer contentContainer;
public PreviousUsernamesContainer()
{
2019-08-02 04:04:18 +08:00
HoverIconContainer hoverIcon;
2019-08-02 02:26:59 +08:00
AutoSizeAxes = Axes.Y;
Width = width;
2019-08-02 12:41:11 +08:00
AddRangeInternal(new Drawable[]
2019-08-02 02:26:59 +08:00
{
contentContainer = new ContentContainer(),
hoverIcon = new HoverIconContainer(),
2019-08-02 12:41:11 +08:00
});
2019-08-02 02:26:59 +08:00
hoverIcon.ActivateHover += () =>
{
contentContainer.Show();
this.MoveToY(-move_offset, duration, Easing.OutQuint);
};
2019-08-02 12:41:11 +08:00
}
2019-08-02 02:26:59 +08:00
2019-08-02 12:41:11 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
User.BindValueChanged(onUserChanged, true);
2019-08-02 02:26:59 +08:00
}
private void onUserChanged(ValueChangedEvent<User> user)
{
2019-08-02 12:41:11 +08:00
contentContainer.Text = string.Empty;
2019-08-02 02:26:59 +08:00
2019-08-02 12:41:11 +08:00
var usernames = user.NewValue?.PreviousUsernames;
2019-08-02 02:26:59 +08:00
2019-08-02 12:41:11 +08:00
if (usernames?.Any() ?? false)
2019-08-02 02:26:59 +08:00
{
2019-08-02 12:41:11 +08:00
contentContainer.Text = string.Join(", ", usernames);
2019-08-02 02:26:59 +08:00
Show();
return;
}
Hide();
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
contentContainer.Hide();
this.MoveToY(0, duration, Easing.OutQuint);
}
private class ContentContainer : VisibilityContainer
{
2019-08-02 12:41:11 +08:00
private const int header_height = 20;
private const int content_padding = 40;
2019-08-02 02:26:59 +08:00
2019-08-02 12:41:11 +08:00
public string Text
{
set => usernames.Text = value;
}
2019-08-02 02:26:59 +08:00
2019-08-02 12:41:11 +08:00
private readonly TextFlowContainer usernames;
2019-08-02 02:26:59 +08:00
private readonly Box background;
public ContentContainer()
{
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
Masking = true;
AlwaysPresent = true;
CornerRadius = 5;
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5),
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.X,
Height = header_height,
Children = new Drawable[]
{
new SpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Padding = new MarginPadding { Left = content_padding },
Text = @"formerly known as",
2019-08-02 12:41:11 +08:00
Font = OsuFont.GetFont(size: 10, italics: true)
2019-08-02 02:26:59 +08:00
}
}
},
2019-08-02 12:41:11 +08:00
usernames = new TextFlowContainer(s => s.Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold, italics: true))
2019-08-02 02:26:59 +08:00
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Full,
2019-08-02 12:41:11 +08:00
Spacing = new Vector2(0, 5),
2019-08-02 02:26:59 +08:00
Padding = new MarginPadding { Left = content_padding, Bottom = margin },
},
}
}
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
background.Colour = colours.GreySeafoamDarker;
}
protected override void PopIn() => this.FadeIn(duration, Easing.OutQuint);
protected override void PopOut() => this.FadeOut(duration, Easing.OutQuint);
}
private class HoverIconContainer : Container
{
public Action ActivateHover;
public HoverIconContainer()
{
AutoSizeAxes = Axes.Both;
Child = new SpriteIcon
{
Margin = new MarginPadding(margin) { Top = 6 },
2019-08-02 12:41:11 +08:00
Size = new Vector2(15),
2019-08-02 02:26:59 +08:00
Icon = FontAwesome.Solid.IdCard,
};
}
protected override bool OnHover(HoverEvent e)
{
ActivateHover?.Invoke();
return base.OnHover(e);
}
}
}
}