1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 00:42:55 +08:00

Initial clean-up pass of breadcrumb and header

This commit is contained in:
Dean Herbert 2019-05-15 17:55:26 +09:00
parent d7098e2066
commit f49b0dc16d
7 changed files with 89 additions and 123 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Overlays.Changelog.Header; using osu.Game.Overlays.Changelog.Header;
@ -13,7 +14,7 @@ namespace osu.Game.Tests.Visual
{ {
public TestCaseTextBadgePair() public TestCaseTextBadgePair()
{ {
TextBadgePair textBadgePair; Breadcrumb breadcrumb;
Add(new Container Add(new Container
{ {
@ -29,7 +30,7 @@ namespace osu.Game.Tests.Visual
Alpha = 0.5f, Alpha = 0.5f,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}, },
textBadgePair = new TextBadgePair(Color4.DeepSkyBlue, "Test") breadcrumb = new TestBadgePair(Color4.DeepSkyBlue, "Test")
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -37,12 +38,20 @@ namespace osu.Game.Tests.Visual
} }
}); });
AddStep(@"Deactivate", textBadgePair.Deactivate); AddStep(@"Deactivate", breadcrumb.Deactivate);
AddStep(@"Activate", textBadgePair.Activate); AddStep(@"Activate", breadcrumb.Activate);
AddStep(@"Hide text", () => textBadgePair.HideText(200)); AddStep(@"Hide text", () => breadcrumb.HideText(200));
AddStep(@"Show text", () => textBadgePair.ShowText(200)); AddStep(@"Show text", () => breadcrumb.ShowText(200));
AddStep(@"Different text", () => textBadgePair.ChangeText(200, "This one's a little bit wider")); AddStep(@"Different text", () => breadcrumb.ShowText(200, "This one's a little bit wider"));
AddStep(@"Different text", () => textBadgePair.ChangeText(200, "Ok?..")); AddStep(@"Different text", () => breadcrumb.ShowText(200, "Ok?.."));
}
private class TestBadgePair : Breadcrumb
{
public TestBadgePair(ColourInfo badgeColour, string displayText = "Listing", bool startCollapsed = true)
: base(badgeColour, displayText, startCollapsed)
{
}
} }
} }
} }

View File

@ -12,9 +12,8 @@ using osuTK.Graphics;
namespace osu.Game.Overlays.Changelog namespace osu.Game.Overlays.Changelog
{ {
public class ChangelogBadges : Container public class BadgeDisplay : CompositeDrawable
{ {
private const float container_height = 106.5f;
private const float vertical_padding = 20; private const float vertical_padding = 20;
private const float horizontal_padding = 85; private const float horizontal_padding = 85;
@ -25,11 +24,11 @@ namespace osu.Game.Overlays.Changelog
private readonly FillFlowContainer<StreamBadge> badgesContainer; private readonly FillFlowContainer<StreamBadge> badgesContainer;
private long selectedStreamId = -1; private long selectedStreamId = -1;
public ChangelogBadges() public BadgeDisplay()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
Children = new Drawable[] InternalChildren = new Drawable[]
{ {
new Box new Box
{ {

View File

@ -9,7 +9,6 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Overlays.Changelog.Header; using osu.Game.Overlays.Changelog.Header;
using System;
using osu.Game.Graphics; using osu.Game.Graphics;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -19,9 +18,9 @@ namespace osu.Game.Overlays.Changelog
public class ChangelogHeader : Container public class ChangelogHeader : Container
{ {
private OsuSpriteText titleStream; private OsuSpriteText titleStream;
private TextBadgePairListing listing; private BreadcrumbListing listing;
private SpriteIcon chevron; private SpriteIcon chevron;
private TextBadgePairRelease releaseStream; private BreadcrumbRelease releaseStream;
public delegate void ListingSelectedEventHandler(); public delegate void ListingSelectedEventHandler();
@ -130,7 +129,10 @@ namespace osu.Game.Overlays.Changelog
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
Children = new Drawable[] Children = new Drawable[]
{ {
listing = new TextBadgePairListing(colours.Violet), listing = new BreadcrumbListing(colours.Violet)
{
Action = () => ListingSelected?.Invoke()
},
new Container // without a container, moving the chevron wont work new Container // without a container, moving the chevron wont work
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
@ -156,7 +158,10 @@ namespace osu.Game.Overlays.Changelog
}, },
}, },
}, },
releaseStream = new TextBadgePairRelease(colours.Violet, "Lazer") releaseStream = new BreadcrumbRelease(colours.Violet, "Lazer")
{
Action = () => titleStream.FlashColour(Color4.White, 500, Easing.OutQuad)
}
}, },
}, },
new Box new Box
@ -168,15 +173,12 @@ namespace osu.Game.Overlays.Changelog
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
}, },
}; };
listing.Activated += OnListingSelected;
releaseStream.Activated += OnReleaseSelected;
} }
public void ShowBuild(string displayName, string displayVersion) public void ShowBuild(string displayName, string displayVersion)
{ {
listing.Deactivate(); listing.Deactivate();
releaseStream.Activate($"{displayName} {displayVersion}"); releaseStream.ShowBuild($"{displayName} {displayVersion}");
titleStream.Text = displayName; titleStream.Text = displayName;
titleStream.FlashColour(Color4.White, 500, Easing.OutQuad); titleStream.FlashColour(Color4.White, 500, Easing.OutQuad);
chevron.MoveToX(0, 100).FadeIn(100); chevron.MoveToX(0, 100).FadeIn(100);
@ -190,15 +192,5 @@ namespace osu.Game.Overlays.Changelog
titleStream.FlashColour(Color4.White, 500, Easing.OutQuad); titleStream.FlashColour(Color4.White, 500, Easing.OutQuad);
chevron.MoveToX(-20, 100).FadeOut(100); chevron.MoveToX(-20, 100).FadeOut(100);
} }
protected virtual void OnListingSelected(object source, EventArgs e)
{
ListingSelected?.Invoke();
}
protected virtual void OnReleaseSelected(object source, EventArgs e)
{
titleStream.FlashColour(Color4.White, 500, Easing.OutQuad);
}
} }
} }

View File

@ -15,20 +15,19 @@ using osu.Game.Graphics;
namespace osu.Game.Overlays.Changelog.Header namespace osu.Game.Overlays.Changelog.Header
{ {
public class TextBadgePair : Container public abstract class Breadcrumb : Container
{ {
protected SpriteText Text; protected SpriteText Text;
protected LineBadge LineBadge; protected LineBadge LineBadge;
public bool IsActivated { get; protected set; } public bool IsActivated { get; protected set; }
public delegate void ActivatedEventHandler(object source, EventArgs args); public Action Action;
public event ActivatedEventHandler Activated;
private SampleChannel sampleHover; private SampleChannel sampleHover;
private SampleChannel sampleActivate; private SampleChannel sampleActivate;
public TextBadgePair(ColourInfo badgeColour, string displayText = "Listing", bool startCollapsed = true) protected Breadcrumb(ColourInfo badgeColour, string displayText = "Listing", bool startCollapsed = true)
{ {
AutoSizeAxes = Axes.X; AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
@ -53,42 +52,24 @@ namespace osu.Game.Overlays.Changelog.Header
}; };
} }
/// <param name="duration">
/// The duration of popping in and popping out not combined.
/// Full change takes double this time.</param>
/// <param name="displayText"></param>
/// <param name="easing"></param>
public void ChangeText(double duration = 0, string displayText = null, Easing easing = Easing.InOutCubic)
{
LineBadge.Collapse();
Text.MoveToY(20, duration, easing)
.FadeOut(duration, easing)
.Then()
.MoveToY(0, duration, easing)
.FadeIn(duration, easing);
// since using .finally/.oncomplete after first fadeout made the badge not hide
// sometimes in visual tests (https://streamable.com/0qssq), I'm using a scheduler here
Scheduler.AddDelayed(() =>
{
if (!string.IsNullOrEmpty(displayText))
Text.Text = displayText;
LineBadge.Uncollapse();
}, duration);
}
public virtual void Deactivate() public virtual void Deactivate()
{ {
if (!IsActivated)
return;
IsActivated = false; IsActivated = false;
LineBadge.Collapse(); LineBadge.Collapse();
Text.Font = "Exo2.0-Regular"; Text.Font = Text.Font.With(weight: FontWeight.Regular);
} }
public virtual void Activate() public virtual void Activate()
{ {
if (IsActivated)
return;
IsActivated = true; IsActivated = true;
LineBadge.Uncollapse(); LineBadge.Uncollapse();
Text.Font = "Exo2.0-Bold"; Text.Font = Text.Font.With(weight: FontWeight.Bold);
} }
public void SetTextColour(ColourInfo newColour, double duration = 0, Easing easing = Easing.None) public void SetTextColour(ColourInfo newColour, double duration = 0, Easing easing = Easing.None)
@ -96,11 +77,6 @@ namespace osu.Game.Overlays.Changelog.Header
Text.FadeColour(newColour, duration, easing); Text.FadeColour(newColour, duration, easing);
} }
public void SetBadgeColour(ColourInfo newColour, double duration = 0, Easing easing = Easing.None)
{
LineBadge.FadeColour(newColour, duration, easing);
}
public void HideText(double duration = 0, Easing easing = Easing.InOutCubic) public void HideText(double duration = 0, Easing easing = Easing.InOutCubic)
{ {
LineBadge.Collapse(); LineBadge.Collapse();
@ -110,11 +86,18 @@ namespace osu.Game.Overlays.Changelog.Header
public void ShowText(double duration = 0, string displayText = null, Easing easing = Easing.InOutCubic) public void ShowText(double duration = 0, string displayText = null, Easing easing = Easing.InOutCubic)
{ {
LineBadge.Uncollapse(); LineBadge.Collapse();
if (!string.IsNullOrEmpty(displayText)) Text.MoveToY(20, duration, easing)
Text.Text = displayText; .FadeOut(duration, easing)
Text.MoveToY(0, duration, easing) .Then()
.MoveToY(0, duration, easing)
.FadeIn(duration, easing); .FadeIn(duration, easing);
Scheduler.AddDelayed(() =>
{
Text.Text = displayText;
LineBadge.Uncollapse();
}, duration);
} }
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
@ -126,14 +109,11 @@ namespace osu.Game.Overlays.Changelog.Header
protected override bool OnClick(ClickEvent e) protected override bool OnClick(ClickEvent e)
{ {
OnActivated(); Action?.Invoke();
Activate();
sampleActivate?.Play(); sampleActivate?.Play();
return base.OnClick(e);
}
protected virtual void OnActivated() return true;
{
Activated?.Invoke(this, EventArgs.Empty);
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]

View File

@ -4,31 +4,32 @@
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Colour;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Overlays.Changelog.Header namespace osu.Game.Overlays.Changelog.Header
{ {
public class TextBadgePairListing : TextBadgePair public class BreadcrumbListing : Breadcrumb
{ {
private readonly ColourInfo badgeColour; private readonly ColourInfo badgeColour;
public TextBadgePairListing(ColourInfo badgeColour) public BreadcrumbListing(ColourInfo badgeColour)
: base(badgeColour, "Listing", false) : base(badgeColour, "Listing", false)
{ {
IsActivated = true;
this.badgeColour = badgeColour; this.badgeColour = badgeColour;
Text.Font = "Exo2.0-Bold"; Text.Font = Text.Font.With(weight: FontWeight.Bold);
Text.Anchor = Anchor.TopCentre; Text.Anchor = Anchor.TopCentre;
Text.Origin = Anchor.TopCentre; Text.Origin = Anchor.TopCentre;
// I'm using this for constant badge width here, so that the whole AutoSizeAxes = Axes.None;
// thing doesn't jump left/right when listing's size changes }
// due to different font weight (and thus width)
LineBadge.RelativeSizeAxes = Axes.None;
// this doesn't work without the scheduler protected override void LoadComplete()
// (because the text isn't yet fully drawn when it's loaded?) {
Text.OnLoadComplete += d => Scheduler.Add(UpdateBadgeWidth); base.LoadComplete();
Activate();
Width = Text.DrawWidth;
} }
public override void Activate() public override void Activate()
@ -36,24 +37,17 @@ namespace osu.Game.Overlays.Changelog.Header
if (IsActivated) if (IsActivated)
return; return;
IsActivated = true; base.Activate();
LineBadge.Uncollapse();
Text.Font = "Exo2.0-Bold";
SetTextColour(Color4.White, 100); SetTextColour(Color4.White, 100);
} }
public override void Deactivate() public override void Deactivate()
{ {
IsActivated = false; if (!IsActivated)
LineBadge.Collapse(); return;
Text.Font = "Exo2.0-Regular";
SetTextColour(badgeColour, 100);
}
protected override bool OnClick(ClickEvent e) base.Deactivate();
{ SetTextColour(badgeColour, 100);
Activate();
return base.OnClick(e);
} }
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
@ -68,7 +62,5 @@ namespace osu.Game.Overlays.Changelog.Header
LineBadge.Collapse(); LineBadge.Collapse();
base.OnHoverLost(e); base.OnHoverLost(e);
} }
public void UpdateBadgeWidth() => LineBadge.ResizeWidthTo(Text.DrawWidth);
} }
} }

View File

@ -5,11 +5,11 @@ using osu.Framework.Graphics.Colour;
namespace osu.Game.Overlays.Changelog.Header namespace osu.Game.Overlays.Changelog.Header
{ {
public class TextBadgePairRelease : TextBadgePair public class BreadcrumbRelease : Breadcrumb
{ {
private const float transition_duration = 125; private const float transition_duration = 125;
public TextBadgePairRelease(ColourInfo badgeColour, string displayText) public BreadcrumbRelease(ColourInfo badgeColour, string displayText)
: base(badgeColour, displayText) : base(badgeColour, displayText)
{ {
Text.Font = "Exo2.0-Bold"; Text.Font = "Exo2.0-Bold";
@ -17,24 +17,17 @@ namespace osu.Game.Overlays.Changelog.Header
Text.Alpha = 0; Text.Alpha = 0;
} }
public void SetText(string displayText) => Text.Text = displayText; public void ShowBuild(string displayText = null)
public void Activate(string displayText = null)
{ {
if (IsActivated)
{
if (displayText != Text.Text)
ChangeText(transition_duration, displayText);
}
else
ShowText(transition_duration, displayText); ShowText(transition_duration, displayText);
IsActivated = true; IsActivated = true;
} }
public override void Deactivate() public override void Deactivate()
{ {
IsActivated = false; if (!IsActivated)
return;
HideText(transition_duration); HideText(transition_duration);
} }
} }

View File

@ -23,7 +23,7 @@ namespace osu.Game.Overlays
{ {
private ChangelogHeader header; private ChangelogHeader header;
private ChangelogBadges badges; private BadgeDisplay badgeDisplay;
private ChangelogContent listing; private ChangelogContent listing;
private ChangelogContent content; private ChangelogContent content;
@ -66,15 +66,16 @@ namespace osu.Game.Overlays
Children = new Drawable[] Children = new Drawable[]
{ {
header = new ChangelogHeader(), header = new ChangelogHeader(),
badges = new ChangelogBadges(), badgeDisplay = new BadgeDisplay(),
listing = new ChangelogContent(), listing = new ChangelogContent(),
content = new ChangelogContent() content = new ChangelogContent()
}, },
}, },
}, },
}; };
header.ListingSelected += ShowListing; header.ListingSelected += ShowListing;
badges.Selected += onBuildSelected; badgeDisplay.Selected += onBuildSelected;
listing.BuildSelected += onBuildSelected; listing.BuildSelected += onBuildSelected;
content.BuildSelected += onBuildSelected; content.BuildSelected += onBuildSelected;
@ -137,11 +138,11 @@ namespace osu.Game.Overlays
isAtListing = true; isAtListing = true;
var req = new GetChangelogRequest(); var req = new GetChangelogRequest();
badges.SelectNone(); badgeDisplay.SelectNone();
req.Success += res => req.Success += res =>
{ {
listing.ShowListing(res.Builds); listing.ShowListing(res.Builds);
badges.Populate(res.Streams); badgeDisplay.Populate(res.Streams);
}; };
API.Queue(req); API.Queue(req);
@ -157,7 +158,7 @@ namespace osu.Game.Overlays
isAtListing = true; isAtListing = true;
content.Hide(); content.Hide();
listing.Show(); listing.Show();
badges.SelectNone(); badgeDisplay.SelectNone();
listing.Show(); listing.Show();
scroll.ScrollTo(savedScrollPosition); scroll.ScrollTo(savedScrollPosition);
} }
@ -180,7 +181,7 @@ namespace osu.Game.Overlays
req.Success += res => header.ShowBuild(res.UpdateStream.DisplayName, res.DisplayVersion); req.Success += res => header.ShowBuild(res.UpdateStream.DisplayName, res.DisplayVersion);
if (updateBadges) if (updateBadges)
badges.SelectUpdateStream(build.UpdateStream.Name); badgeDisplay.SelectUpdateStream(build.UpdateStream.Name);
req.Success += apiChangelog => req.Success += apiChangelog =>
{ {