Adjust StreamBadgeArea

This commit is contained in:
Andrei Zavatski 2020-02-21 18:12:23 +03:00
parent 71623067e3
commit 8593642a04
2 changed files with 64 additions and 74 deletions

View File

@ -3,8 +3,6 @@
using Humanizer; using Humanizer;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -16,33 +14,37 @@ using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osuTK; using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays.Changelog namespace osu.Game.Overlays.Changelog
{ {
public class UpdateStreamBadge : TabItem<APIUpdateStream> public class UpdateStreamBadge : TabItem<APIUpdateStream>
{ {
private const float badge_height = 66.5f;
private const float badge_width = 100; private const float badge_width = 100;
private const float transition_duration = 100; private const float transition_duration = 100;
private readonly ExpandingBar expandingBar;
private SampleChannel sampleClick;
private SampleChannel sampleHover;
private readonly FillFlowContainer<SpriteText> text;
public readonly Bindable<APIUpdateStream> SelectedTab = new Bindable<APIUpdateStream>(); public readonly Bindable<APIUpdateStream> SelectedTab = new Bindable<APIUpdateStream>();
private readonly Container fadeContainer; private readonly APIUpdateStream stream;
private Container fadeContainer;
private FillFlowContainer<SpriteText> text;
private ExpandingBar expandingBar;
public UpdateStreamBadge(APIUpdateStream stream) public UpdateStreamBadge(APIUpdateStream stream)
: base(stream) : base(stream)
{ {
Size = new Vector2(stream.IsFeatured ? badge_width * 2 : badge_width, badge_height); this.stream = stream;
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
Size = new Vector2(stream.IsFeatured ? badge_width * 2 : badge_width, 60);
Padding = new MarginPadding(5); Padding = new MarginPadding(5);
Child = fadeContainer = new Container AddRange(new Drawable[]
{
fadeContainer = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Children = new Drawable[] Children = new Drawable[]
@ -52,24 +54,24 @@ namespace osu.Game.Overlays.Changelog
AutoSizeAxes = Axes.X, AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
Margin = new MarginPadding { Top = 6 },
Children = new[] Children = new[]
{ {
new OsuSpriteText new OsuSpriteText
{ {
Text = stream.DisplayName, Text = stream.DisplayName,
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 12), Font = OsuFont.GetFont(size: 12, weight: FontWeight.Black),
Margin = new MarginPadding { Top = 6 },
}, },
new OsuSpriteText new OsuSpriteText
{ {
Text = stream.LatestBuild.DisplayVersion, Text = stream.LatestBuild.DisplayVersion,
Font = OsuFont.GetFont(weight: FontWeight.Light, size: 16), Font = OsuFont.GetFont(size: 16, weight: FontWeight.Regular),
}, },
new OsuSpriteText new OsuSpriteText
{ {
Text = stream.LatestBuild.Users > 0 ? $"{stream.LatestBuild.Users:N0} {"user".Pluralize(stream.LatestBuild.Users == 1)} online" : null, Text = stream.LatestBuild.Users > 0 ? $"{stream.LatestBuild.Users:N0} {"user".Pluralize(stream.LatestBuild.Users == 1)} online" : null,
Font = OsuFont.GetFont(weight: FontWeight.Regular, size: 10), Font = OsuFont.GetFont(size: 10),
Colour = new Color4(203, 164, 218, 255), Colour = colourProvider.Foreground1
}, },
} }
}, },
@ -82,33 +84,20 @@ namespace osu.Game.Overlays.Changelog
IsCollapsed = true IsCollapsed = true
}, },
} }
}; },
new HoverClickSounds()
});
SelectedTab.BindValueChanged(_ => updateState(), true); SelectedTab.BindValueChanged(_ => updateState(), true);
} }
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleClick = audio.Samples.Get(@"UI/generic-select-soft");
sampleHover = audio.Samples.Get(@"UI/generic-hover-soft");
}
protected override void OnActivated() => updateState(); protected override void OnActivated() => updateState();
protected override void OnDeactivated() => updateState(); protected override void OnDeactivated() => updateState();
protected override bool OnClick(ClickEvent e)
{
sampleClick?.Play();
return base.OnClick(e);
}
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
sampleHover?.Play();
updateState(); updateState();
return base.OnHover(e); return base.OnHover(e);
} }

View File

@ -9,33 +9,34 @@ using System.Linq;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osuTK.Graphics; using osuTK.Graphics;
using osu.Framework.Allocation;
namespace osu.Game.Overlays.Changelog namespace osu.Game.Overlays.Changelog
{ {
public class UpdateStreamBadgeArea : TabControl<APIUpdateStream> public class UpdateStreamBadgeArea : TabControl<APIUpdateStream>
{ {
public UpdateStreamBadgeArea() [BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
AddInternal(new Box AddInternal(new Box
{ {
Colour = Color4.Black,
Alpha = 0.12f,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background5,
}); });
} }
public void Populate(List<APIUpdateStream> streams) public void Populate(List<APIUpdateStream> streams)
{ {
foreach (APIUpdateStream updateStream in streams) foreach (var updateStream in streams)
AddItem(updateStream); AddItem(updateStream);
} }
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
foreach (UpdateStreamBadge streamBadge in TabContainer.Children.OfType<UpdateStreamBadge>()) foreach (var streamBadge in TabContainer.Children.OfType<UpdateStreamBadge>())
streamBadge.EnableDim(); streamBadge.EnableDim();
return base.OnHover(e); return base.OnHover(e);
@ -43,7 +44,7 @@ namespace osu.Game.Overlays.Changelog
protected override void OnHoverLost(HoverLostEvent e) protected override void OnHoverLost(HoverLostEvent e)
{ {
foreach (UpdateStreamBadge streamBadge in TabContainer.Children.OfType<UpdateStreamBadge>()) foreach (var streamBadge in TabContainer.Children.OfType<UpdateStreamBadge>())
streamBadge.DisableDim(); streamBadge.DisableDim();
base.OnHoverLost(e); base.OnHoverLost(e);