2019-05-13 16:14:52 +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.
|
2018-07-18 07:35:06 +08:00
|
|
|
|
|
2019-05-23 11:41:45 +08:00
|
|
|
|
using Humanizer;
|
2018-07-19 01:32:15 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-05-22 22:44:37 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-07-18 07:35:06 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-10-19 02:56:43 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-07-20 01:07:24 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2019-05-22 18:51:16 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2019-05-19 01:09:08 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2019-05-22 15:33:50 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-05-23 11:41:45 +08:00
|
|
|
|
using osuTK;
|
2018-07-18 07:35:06 +08:00
|
|
|
|
|
2018-07-20 01:07:24 +08:00
|
|
|
|
namespace osu.Game.Overlays.Changelog
|
2018-07-18 07:35:06 +08:00
|
|
|
|
{
|
2019-05-22 18:51:16 +08:00
|
|
|
|
public class UpdateStreamBadge : TabItem<APIUpdateStream>
|
2018-07-18 07:35:06 +08:00
|
|
|
|
{
|
2018-07-19 01:32:15 +08:00
|
|
|
|
private const float badge_width = 100;
|
2018-07-18 07:35:06 +08:00
|
|
|
|
private const float transition_duration = 100;
|
|
|
|
|
|
2019-05-22 22:44:37 +08:00
|
|
|
|
public readonly Bindable<APIUpdateStream> SelectedTab = new Bindable<APIUpdateStream>();
|
|
|
|
|
|
2020-02-21 23:12:23 +08:00
|
|
|
|
private readonly APIUpdateStream stream;
|
|
|
|
|
|
|
|
|
|
private FillFlowContainer<SpriteText> text;
|
|
|
|
|
private ExpandingBar expandingBar;
|
2019-05-22 22:44:37 +08:00
|
|
|
|
|
2019-05-22 18:51:16 +08:00
|
|
|
|
public UpdateStreamBadge(APIUpdateStream stream)
|
|
|
|
|
: base(stream)
|
2018-07-18 07:35:06 +08:00
|
|
|
|
{
|
2020-02-21 23:12:23 +08:00
|
|
|
|
this.stream = stream;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(stream.IsFeatured ? badge_width * 2 : badge_width, 60);
|
2018-07-25 20:58:18 +08:00
|
|
|
|
Padding = new MarginPadding(5);
|
2019-05-23 11:41:45 +08:00
|
|
|
|
|
2020-02-21 23:12:23 +08:00
|
|
|
|
AddRange(new Drawable[]
|
2018-07-18 07:35:06 +08:00
|
|
|
|
{
|
2020-02-27 20:33:01 +08:00
|
|
|
|
text = new FillFlowContainer<SpriteText>
|
2018-07-18 07:35:06 +08:00
|
|
|
|
{
|
2020-02-27 20:33:01 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Margin = new MarginPadding { Top = 6 },
|
|
|
|
|
Children = new[]
|
2018-07-18 07:35:06 +08:00
|
|
|
|
{
|
2020-02-27 20:33:01 +08:00
|
|
|
|
new OsuSpriteText
|
2018-07-18 07:35:06 +08:00
|
|
|
|
{
|
2020-02-27 20:33:01 +08:00
|
|
|
|
Text = stream.DisplayName,
|
|
|
|
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Black),
|
2020-02-21 23:12:23 +08:00
|
|
|
|
},
|
2020-02-27 20:33:01 +08:00
|
|
|
|
new OsuSpriteText
|
2020-02-21 23:12:23 +08:00
|
|
|
|
{
|
2020-02-27 20:33:01 +08:00
|
|
|
|
Text = stream.LatestBuild.DisplayVersion,
|
|
|
|
|
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Regular),
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = stream.LatestBuild.Users > 0 ? $"{"user".ToQuantity(stream.LatestBuild.Users, "N0")} online" : null,
|
|
|
|
|
Font = OsuFont.GetFont(size: 10),
|
|
|
|
|
Colour = colourProvider.Foreground1
|
2020-02-21 23:12:23 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-02-27 20:33:01 +08:00
|
|
|
|
expandingBar = new ExpandingBar
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Colour = stream.Colour,
|
|
|
|
|
ExpandedSize = 4,
|
|
|
|
|
CollapsedSize = 2,
|
2020-03-02 19:16:58 +08:00
|
|
|
|
Expanded = true
|
2020-02-27 20:33:01 +08:00
|
|
|
|
},
|
2020-02-21 23:12:23 +08:00
|
|
|
|
new HoverClickSounds()
|
|
|
|
|
});
|
2018-07-18 07:35:06 +08:00
|
|
|
|
|
2019-05-31 12:03:35 +08:00
|
|
|
|
SelectedTab.BindValueChanged(_ => updateState(), true);
|
2018-07-18 07:35:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-22 22:44:37 +08:00
|
|
|
|
protected override void OnActivated() => updateState();
|
|
|
|
|
|
|
|
|
|
protected override void OnDeactivated() => updateState();
|
2018-07-18 07:35:06 +08:00
|
|
|
|
|
2018-10-19 02:56:43 +08:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-07-18 07:35:06 +08:00
|
|
|
|
{
|
2019-05-22 22:44:37 +08:00
|
|
|
|
updateState();
|
2018-10-19 02:56:43 +08:00
|
|
|
|
return base.OnHover(e);
|
2018-07-18 07:35:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-19 02:56:43 +08:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-07-18 07:35:06 +08:00
|
|
|
|
{
|
2019-05-22 22:44:37 +08:00
|
|
|
|
updateState();
|
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
|
{
|
2020-03-02 19:16:58 +08:00
|
|
|
|
// highlighted regardless if we are hovered
|
|
|
|
|
bool textHighlighted = IsHovered;
|
|
|
|
|
bool barExpanded = IsHovered;
|
|
|
|
|
|
|
|
|
|
if (SelectedTab.Value == null)
|
2018-07-18 07:35:06 +08:00
|
|
|
|
{
|
2020-03-02 19:16:58 +08:00
|
|
|
|
// at listing, all badges are highlighted when user is not hovering any badge.
|
|
|
|
|
textHighlighted |= !userHoveringArea;
|
|
|
|
|
barExpanded |= !userHoveringArea;
|
2018-07-18 07:35:06 +08:00
|
|
|
|
}
|
2020-03-02 19:16:58 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// bar is always expanded when active
|
|
|
|
|
barExpanded |= Active.Value;
|
2019-05-12 23:36:05 +08:00
|
|
|
|
|
2020-03-02 19:16:58 +08:00
|
|
|
|
// text is highlighted only when hovered or active (but not if in selection mode)
|
|
|
|
|
textHighlighted |= Active.Value && !userHoveringArea;
|
|
|
|
|
}
|
2020-02-28 17:48:06 +08:00
|
|
|
|
|
2020-03-02 19:16:58 +08:00
|
|
|
|
expandingBar.Expanded = barExpanded;
|
|
|
|
|
text.FadeTo(textHighlighted ? 1 : 0.5f, transition_duration, Easing.OutQuint);
|
2018-07-18 07:35:06 +08:00
|
|
|
|
}
|
2018-07-19 01:32:15 +08:00
|
|
|
|
|
2020-03-02 19:16:58 +08:00
|
|
|
|
private bool userHoveringArea;
|
2019-05-22 22:44:37 +08:00
|
|
|
|
|
2020-03-02 19:16:58 +08:00
|
|
|
|
public bool UserHoveringArea
|
2019-05-22 22:44:37 +08:00
|
|
|
|
{
|
2020-03-02 18:51:06 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2020-03-02 19:16:58 +08:00
|
|
|
|
if (value == userHoveringArea)
|
2020-03-02 18:51:06 +08:00
|
|
|
|
return;
|
2018-07-21 04:13:10 +08:00
|
|
|
|
|
2020-03-02 19:16:58 +08:00
|
|
|
|
userHoveringArea = value;
|
2020-03-02 18:51:06 +08:00
|
|
|
|
updateState();
|
|
|
|
|
}
|
2019-05-22 22:44:37 +08:00
|
|
|
|
}
|
2018-07-18 07:35:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|