Fix badge state regressions from tab control usage

This commit is contained in:
Dean Herbert 2019-05-22 23:44:37 +09:00
parent b588638740
commit 66f5dbaa9f
2 changed files with 79 additions and 64 deletions

View File

@ -4,6 +4,7 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
@ -23,71 +24,70 @@ namespace osu.Game.Overlays.Changelog
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 bool isActivated;
private readonly ExpandingBar expandingBar; private readonly ExpandingBar expandingBar;
private SampleChannel sampleClick; private SampleChannel sampleClick;
private SampleChannel sampleHover; private SampleChannel sampleHover;
private readonly FillFlowContainer<SpriteText> text; private readonly FillFlowContainer<SpriteText> text;
public readonly Bindable<APIUpdateStream> SelectedTab = new Bindable<APIUpdateStream>();
private readonly Container fadeContainer;
public UpdateStreamBadge(APIUpdateStream stream) public UpdateStreamBadge(APIUpdateStream stream)
: base(stream) : base(stream)
{ {
Height = badge_height; Height = badge_height;
Width = stream.IsFeatured ? badge_width * 2 : badge_width; Width = stream.IsFeatured ? badge_width * 2 : badge_width;
Padding = new MarginPadding(5); Padding = new MarginPadding(5);
isActivated = true; Child = fadeContainer = new Container
Children = new Drawable[]
{ {
text = new FillFlowContainer<SpriteText> RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{ {
AutoSizeAxes = Axes.X, text = new FillFlowContainer<SpriteText>
RelativeSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new[]
{ {
new OsuSpriteText AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new[]
{ {
Text = stream.DisplayName, new OsuSpriteText
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 12), {
Margin = new MarginPadding { Top = 6 }, Text = stream.DisplayName,
}, Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 12),
new OsuSpriteText Margin = new MarginPadding { Top = 6 },
{ },
Text = stream.LatestBuild.DisplayVersion, new OsuSpriteText
Font = OsuFont.GetFont(weight: FontWeight.Light, size: 16), {
}, Text = stream.LatestBuild.DisplayVersion,
new OsuSpriteText Font = OsuFont.GetFont(weight: FontWeight.Light, size: 16),
{ },
Text = stream.LatestBuild.Users > 0 ? $"{stream.LatestBuild.Users:N0} users online" : null, new OsuSpriteText
Font = OsuFont.GetFont(weight: FontWeight.Regular, size: 10), {
Colour = new Color4(203, 164, 218, 255), 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, expandingBar = new ExpandingBar
Colour = stream.Colour, {
ExpandedSize = 4, Anchor = Anchor.TopCentre,
CollapsedSize = 2, Colour = stream.Colour,
IsCollapsed = true ExpandedSize = 4,
}, CollapsedSize = 2,
IsCollapsed = true
},
}
}; };
SelectedTab.ValueChanged += _ => updateState();
} }
protected override void OnActivated() protected override void OnActivated() => updateState();
{
this.FadeIn(transition_duration);
expandingBar.Expand();
}
protected override void OnDeactivated() protected override void OnDeactivated() => updateState();
{
this.FadeTo(0.5f, transition_duration);
expandingBar.Collapse();
}
protected override bool OnClick(ClickEvent e) protected override bool OnClick(ClickEvent e)
{ {
@ -98,28 +98,46 @@ namespace osu.Game.Overlays.Changelog
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
sampleHover?.Play(); sampleHover?.Play();
DisableDim(); updateState();
this.FadeIn(transition_duration);
expandingBar.Expand();
return base.OnHover(e); return base.OnHover(e);
} }
protected override void OnHoverLost(HoverLostEvent e) protected override void OnHoverLost(HoverLostEvent e)
{ {
if (!isActivated) updateState();
{
this.FadeTo(0.5f, transition_duration);
expandingBar.Collapse();
}
else
EnableDim();
base.OnHoverLost(e); base.OnHoverLost(e);
} }
public void EnableDim() => text.FadeTo(0.5f, transition_duration); private void updateState()
{
if (Active.Value || IsHovered || SelectedTab.Value == null)
{
expandingBar.Expand();
fadeContainer.FadeTo(1, transition_duration);
}
else
{
expandingBar.Collapse();
fadeContainer.FadeTo(0.5f, transition_duration);
}
public void DisableDim() => text.FadeIn(transition_duration); text.FadeTo(externalDimRequested && !IsHovered ? 0.5f : 1, transition_duration);
}
private bool externalDimRequested;
public void EnableDim()
{
externalDimRequested = true;
updateState();
}
public void DisableDim()
{
externalDimRequested = false;
updateState();
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(AudioManager audio) private void load(AudioManager audio)

View File

@ -14,9 +14,6 @@ namespace osu.Game.Overlays.Changelog
{ {
public class UpdateStreamBadgeArea : TabControl<APIUpdateStream> public class UpdateStreamBadgeArea : TabControl<APIUpdateStream>
{ {
private const float vertical_padding = 20;
private const float horizontal_padding = 85;
public UpdateStreamBadgeArea() public UpdateStreamBadgeArea()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
@ -65,8 +62,8 @@ namespace osu.Game.Overlays.Changelog
flow.AllowMultiline = true; flow.AllowMultiline = true;
flow.Padding = new MarginPadding flow.Padding = new MarginPadding
{ {
Vertical = vertical_padding, Vertical = 20,
Horizontal = horizontal_padding, Horizontal = 85,
}; };
return flow; return flow;
@ -75,6 +72,6 @@ namespace osu.Game.Overlays.Changelog
protected override Dropdown<APIUpdateStream> CreateDropdown() => null; protected override Dropdown<APIUpdateStream> CreateDropdown() => null;
protected override TabItem<APIUpdateStream> CreateTabItem(APIUpdateStream value) => protected override TabItem<APIUpdateStream> CreateTabItem(APIUpdateStream value) =>
new UpdateStreamBadge(value); new UpdateStreamBadge(value) { SelectedTab = { BindTarget = Current } };
} }
} }