1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 05:37:24 +08:00
osu-lazer/osu.Game/Overlays/Profile/Header/Components/PreviousUsernamesDisplay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

176 lines
5.9 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.
2019-08-13 13:07:40 +08:00
using System;
using System.Linq;
2019-08-02 02:26:59 +08:00
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;
2019-11-25 10:30:55 +08:00
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses;
2021-07-17 21:18:45 +08:00
using osu.Game.Resources.Localisation.Web;
2019-08-02 02:26:59 +08:00
using osuTK;
2019-08-13 13:07:40 +08:00
namespace osu.Game.Overlays.Profile.Header.Components
2019-08-02 02:26:59 +08:00
{
public partial class PreviousUsernamesDisplay : CompositeDrawable
2019-08-02 02:26:59 +08:00
{
private const int duration = 200;
private const int margin = 10;
private const int width = 300;
2019-08-02 12:41:11 +08:00
private const int move_offset = 15;
private const int base_y_offset = -3; // eye balled to make it look good
2019-08-02 02:26:59 +08:00
2022-12-30 20:17:59 +08:00
public readonly Bindable<APIUser?> User = new Bindable<APIUser?>();
2019-08-02 02:26:59 +08:00
2019-08-03 10:34:14 +08:00
private readonly TextFlowContainer text;
private readonly Box background;
private readonly SpriteText header;
2019-08-02 02:26:59 +08:00
public PreviousUsernamesDisplay()
2019-08-02 02:26:59 +08:00
{
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-03 10:34:14 +08:00
Masking = true;
CornerRadius = 6;
Y = base_y_offset;
2019-08-02 12:41:11 +08:00
AddRangeInternal(new Drawable[]
2019-08-02 02:26:59 +08:00
{
2019-08-03 10:34:14 +08:00
background = new Box
{
RelativeSizeAxes = Axes.Both,
},
new GridContainer
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize)
},
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
2021-07-05 23:52:39 +08:00
new Dimension()
2019-08-03 10:34:14 +08:00
},
Content = new[]
{
new Drawable[]
{
hoverIcon = new HoverIconContainer(),
2019-11-25 10:30:55 +08:00
header = new OsuSpriteText
2019-08-03 10:34:14 +08:00
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
2021-07-17 21:18:45 +08:00
Text = UsersStrings.ShowPreviousUsernames,
2019-08-03 10:34:14 +08:00
Font = OsuFont.GetFont(size: 10, italics: true)
}
},
new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
},
text = new TextFlowContainer(s => s.Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold, italics: true))
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Full,
2023-09-12 14:46:05 +08:00
// Prevents the tooltip of having a sudden size reduction and flickering when the text is being faded out.
// Also prevents a potential OnHover/HoverLost feedback loop.
AlwaysPresent = true,
2019-08-03 10:49:01 +08:00
Margin = new MarginPadding { Bottom = margin, Top = margin / 2f }
2019-08-03 10:34:14 +08:00
}
}
}
}
2019-08-02 12:41:11 +08:00
});
2019-08-02 02:26:59 +08:00
2019-08-03 10:34:14 +08:00
hoverIcon.ActivateHover += showContent;
hideContent();
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colours)
2019-08-03 10:34:14 +08:00
{
background.Colour = colours.Background6;
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
}
2022-12-30 20:17:59 +08:00
private void onUserChanged(ValueChangedEvent<APIUser?> user)
2019-08-02 02:26:59 +08:00
{
2019-08-03 10:34:14 +08:00
text.Text = string.Empty;
2019-08-02 02:26:59 +08:00
2022-12-30 20:17:59 +08:00
string[]? 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-03 10:34:14 +08:00
text.Text = string.Join(", ", usernames);
2019-08-02 02:26:59 +08:00
Show();
return;
}
Hide();
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
2019-08-03 10:34:14 +08:00
hideContent();
2019-08-02 02:26:59 +08:00
}
2019-08-03 10:34:14 +08:00
private void showContent()
2019-08-02 02:26:59 +08:00
{
2019-08-03 10:34:14 +08:00
text.FadeIn(duration, Easing.OutQuint);
header.FadeIn(duration, Easing.OutQuint);
background.FadeIn(duration, Easing.OutQuint);
this.MoveToY(base_y_offset - move_offset, duration, Easing.OutQuint);
2019-08-03 10:34:14 +08:00
}
2019-08-02 02:26:59 +08:00
2019-08-03 10:34:14 +08:00
private void hideContent()
{
text.FadeOut(duration, Easing.OutQuint);
header.FadeOut(duration, Easing.OutQuint);
background.FadeOut(duration, Easing.OutQuint);
this.MoveToY(base_y_offset, duration, Easing.OutQuint);
2019-08-02 02:26:59 +08:00
}
private partial class HoverIconContainer : Container
{
2022-12-30 20:17:59 +08:00
public Action? ActivateHover;
2019-08-02 02:26:59 +08:00
public HoverIconContainer()
{
AutoSizeAxes = Axes.Both;
Child = new SpriteIcon
{
2019-08-03 10:34:14 +08:00
Margin = new MarginPadding { Top = 6, Left = margin, Right = margin * 2 },
2019-08-02 12:41:11 +08:00
Size = new Vector2(15),
Icon = FontAwesome.Solid.AddressCard,
2019-08-02 02:26:59 +08:00
};
}
protected override bool OnHover(HoverEvent e)
{
ActivateHover?.Invoke();
return base.OnHover(e);
}
}
}
}