osu/osu.Game/Overlays/Changelog/UpdateStreamBadge.cs

150 lines
5.0 KiB
C#
Raw Normal View History

2019-05-13 08:14:52 +00: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-17 23:35:06 +00:00
2018-07-18 17:32:15 +00:00
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
2018-07-17 23:35:06 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
2018-07-19 17:07:24 +00:00
using osu.Game.Graphics;
using osu.Game.Online.API.Requests.Responses;
2019-05-22 10:51:16 +00:00
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.Sprites;
2019-05-22 07:33:50 +00:00
using osu.Game.Graphics.UserInterface;
2019-05-12 15:36:05 +00:00
using osuTK.Graphics;
2018-07-17 23:35:06 +00:00
2018-07-19 17:07:24 +00:00
namespace osu.Game.Overlays.Changelog
2018-07-17 23:35:06 +00:00
{
2019-05-22 10:51:16 +00:00
public class UpdateStreamBadge : TabItem<APIUpdateStream>
2018-07-17 23:35:06 +00:00
{
private const float badge_height = 66.5f;
2018-07-18 17:32:15 +00:00
private const float badge_width = 100;
2018-07-17 23:35:06 +00:00
private const float transition_duration = 100;
2019-05-22 07:33:50 +00:00
private readonly ExpandingBar expandingBar;
private SampleChannel sampleClick;
2018-07-18 17:32:15 +00:00
private SampleChannel sampleHover;
private readonly FillFlowContainer<SpriteText> text;
2018-07-17 23:35:06 +00:00
public readonly Bindable<APIUpdateStream> SelectedTab = new Bindable<APIUpdateStream>();
private readonly Container fadeContainer;
2019-05-22 10:51:16 +00:00
public UpdateStreamBadge(APIUpdateStream stream)
: base(stream)
2018-07-17 23:35:06 +00:00
{
2018-07-18 17:32:15 +00:00
Height = badge_height;
Width = stream.IsFeatured ? badge_width * 2 : badge_width;
Padding = new MarginPadding(5);
Child = fadeContainer = new Container
2018-07-17 23:35:06 +00:00
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
2018-07-17 23:35:06 +00:00
{
text = new FillFlowContainer<SpriteText>
2018-07-17 23:35:06 +00:00
{
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new[]
2018-07-17 23:35:06 +00:00
{
new OsuSpriteText
{
Text = stream.DisplayName,
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 12),
Margin = new MarginPadding { Top = 6 },
},
new OsuSpriteText
{
Text = stream.LatestBuild.DisplayVersion,
Font = OsuFont.GetFont(weight: FontWeight.Light, size: 16),
},
new OsuSpriteText
{
Text = stream.LatestBuild.Users > 0 ? $"{stream.LatestBuild.Users:N0} users online" : null,
Font = OsuFont.GetFont(weight: FontWeight.Regular, size: 10),
Colour = new Color4(203, 164, 218, 255),
},
}
},
expandingBar = new ExpandingBar
{
Anchor = Anchor.TopCentre,
Colour = stream.Colour,
ExpandedSize = 4,
CollapsedSize = 2,
IsCollapsed = true
},
}
2018-07-17 23:35:06 +00:00
};
SelectedTab.ValueChanged += _ => updateState();
2018-07-17 23:35:06 +00:00
}
protected override void OnActivated() => updateState();
protected override void OnDeactivated() => updateState();
2018-07-17 23:35:06 +00:00
protected override bool OnClick(ClickEvent e)
2018-07-17 23:35:06 +00:00
{
sampleClick?.Play();
return base.OnClick(e);
2018-07-17 23:35:06 +00:00
}
protected override bool OnHover(HoverEvent e)
2018-07-17 23:35:06 +00:00
{
sampleHover?.Play();
updateState();
return base.OnHover(e);
2018-07-17 23:35:06 +00:00
}
protected override void OnHoverLost(HoverLostEvent e)
2018-07-17 23:35:06 +00:00
{
updateState();
base.OnHoverLost(e);
}
private void updateState()
{
if (Active.Value || IsHovered || SelectedTab.Value == null)
2018-07-17 23:35:06 +00:00
{
expandingBar.Expand();
fadeContainer.FadeTo(1, transition_duration);
2018-07-17 23:35:06 +00:00
}
else
{
expandingBar.Collapse();
fadeContainer.FadeTo(0.5f, transition_duration);
}
2019-05-12 15:36:05 +00:00
text.FadeTo(externalDimRequested && !IsHovered ? 0.5f : 1, transition_duration);
2018-07-17 23:35:06 +00:00
}
2018-07-18 17:32:15 +00:00
private bool externalDimRequested;
public void EnableDim()
{
externalDimRequested = true;
updateState();
}
public void DisableDim()
{
externalDimRequested = false;
updateState();
}
2018-07-18 17:32:15 +00:00
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleClick = audio.Sample.Get(@"UI/generic-select-soft");
2018-07-18 17:32:15 +00:00
sampleHover = audio.Sample.Get(@"UI/generic-hover-soft");
}
2018-07-17 23:35:06 +00:00
}
}