From 6ca3bd086f54894a0f02ca29ea7dfcd13bc91786 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Tue, 28 May 2019 17:04:05 +0300 Subject: [PATCH 01/17] ShowMore button update --- .../Beatmaps/PaginatedBeatmapContainer.cs | 4 +- .../PaginatedMostPlayedBeatmapContainer.cs | 4 +- .../Profile/Sections/PaginatedContainer.cs | 161 +++++++++++++++--- .../Sections/Ranks/PaginatedScoreContainer.cs | 10 +- .../PaginatedRecentActivityContainer.cs | 4 +- 5 files changed, 146 insertions(+), 37 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs b/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs index 0fc1398f5d..db291d0731 100644 --- a/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs @@ -34,8 +34,8 @@ protected override void ShowMore() request = new GetUserBeatmapsRequest(User.Value.Id, type, VisiblePages++ * ItemsPerPage); request.Success += sets => Schedule(() => { - ShowMoreButton.FadeTo(sets.Count == ItemsPerPage ? 1 : 0); - ShowMoreLoading.Hide(); + MoreButton.FadeTo(sets.Count == ItemsPerPage ? 1 : 0); + MoreButton.IsLoading = false; if (!sets.Any() && VisiblePages == 1) { diff --git a/osu.Game/Overlays/Profile/Sections/Historical/PaginatedMostPlayedBeatmapContainer.cs b/osu.Game/Overlays/Profile/Sections/Historical/PaginatedMostPlayedBeatmapContainer.cs index f2eb32c53b..0f86e0900e 100644 --- a/osu.Game/Overlays/Profile/Sections/Historical/PaginatedMostPlayedBeatmapContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Historical/PaginatedMostPlayedBeatmapContainer.cs @@ -29,8 +29,8 @@ protected override void ShowMore() request = new GetUserMostPlayedBeatmapsRequest(User.Value.Id, VisiblePages++ * ItemsPerPage); request.Success += beatmaps => Schedule(() => { - ShowMoreButton.FadeTo(beatmaps.Count == ItemsPerPage ? 1 : 0); - ShowMoreLoading.Hide(); + MoreButton.FadeTo(beatmaps.Count == ItemsPerPage ? 1 : 0); + MoreButton.IsLoading = false; if (!beatmaps.Any() && VisiblePages == 1) { diff --git a/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs b/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs index 46c65b9db7..1ebc51b11f 100644 --- a/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs @@ -7,11 +7,15 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Graphics; -using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; using osu.Game.Online.API; using osu.Game.Rulesets; +using osu.Framework.Input.Events; +using System; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Sprites; +using osuTK.Graphics; using osu.Game.Users; namespace osu.Game.Overlays.Profile.Sections @@ -19,8 +23,7 @@ namespace osu.Game.Overlays.Profile.Sections public class PaginatedContainer : FillFlowContainer { protected readonly FillFlowContainer ItemsContainer; - protected readonly OsuHoverContainer ShowMoreButton; - protected readonly LoadingAnimation ShowMoreLoading; + protected readonly ShowMoreButton MoreButton; protected readonly OsuSpriteText MissingText; protected int VisiblePages; @@ -45,38 +48,25 @@ public PaginatedContainer(Bindable user, string header, string missing) new OsuSpriteText { Text = header, - Font = OsuFont.GetFont(size: 15, weight: FontWeight.Regular, italics: true), + Font = OsuFont.GetFont(size: 20, weight: FontWeight.Bold), Margin = new MarginPadding { Top = 10, Bottom = 10 }, }, ItemsContainer = new FillFlowContainer { AutoSizeAxes = Axes.Y, RelativeSizeAxes = Axes.X, - Margin = new MarginPadding { Bottom = 10 } + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 2), }, - ShowMoreButton = new OsuHoverContainer + MoreButton = new ShowMoreButton { Alpha = 0, + Margin = new MarginPadding { Top = 10 }, Action = ShowMore, - AutoSizeAxes = Axes.Both, - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - Child = new OsuSpriteText - { - Font = OsuFont.GetFont(size: 14), - Text = "show more", - Padding = new MarginPadding { Vertical = 10, Horizontal = 15 }, - } - }, - ShowMoreLoading = new LoadingAnimation - { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - Size = new Vector2(14), }, MissingText = new OsuSpriteText { - Font = OsuFont.GetFont(size: 14), + Font = OsuFont.GetFont(size: 15), Text = missing, Alpha = 0, }, @@ -97,16 +87,135 @@ private void onUserChanged(ValueChangedEvent e) { VisiblePages = 0; ItemsContainer.Clear(); - ShowMoreButton.Hide(); if (e.NewValue != null) ShowMore(); } - protected virtual void ShowMore() + protected virtual void ShowMore() => MoreButton.IsLoading = true; + + protected class ShowMoreButton : CircularContainer { - ShowMoreLoading.Show(); - ShowMoreButton.Hide(); + private const int duration = 300; + private Color4 idleColour; + private Color4 hoveredColour; + + public Action Action; + private readonly Box background; + private readonly LoadingAnimation loading; + private readonly FillFlowContainer content; + + private bool isLoading; + public bool IsLoading + { + set + { + isLoading = value; + + if (value) + { + loading.FadeIn(duration, Easing.OutQuint); + content.FadeOut(duration, Easing.OutQuint); + } + else + { + loading.FadeOut(duration, Easing.OutQuint); + content.FadeIn(duration, Easing.OutQuint); + } + } + get + { + return isLoading; + } + } + + public ShowMoreButton() + { + Anchor = Anchor.TopCentre; + Origin = Anchor.TopCentre; + Masking = true; + Size = new Vector2(140, 30); + Children = new Drawable[] + { + background = new Box + { + RelativeSizeAxes = Axes.Both, + }, + content = new FillFlowContainer + { + Alpha = 0, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(7), + Children = new Drawable[] + { + new ChevronIcon(), + new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold), + Text = "show more".ToUpper(), + }, + new ChevronIcon(), + } + }, + loading = new LoadingAnimation + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(20) + }, + }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colors) + { + background.Colour = idleColour = colors.GreySeafoam; + hoveredColour = colors.GreySeafoamLight; + } + + protected override bool OnHover(HoverEvent e) + { + background.FadeColour(hoveredColour, duration, Easing.OutQuint); + return base.OnHover(e); + } + + protected override void OnHoverLost(HoverLostEvent e) + { + background.FadeColour(idleColour, duration, Easing.OutQuint); + base.OnHoverLost(e); + } + + protected override bool OnClick(ClickEvent e) + { + Action.Invoke(); + return base.OnClick(e); + } + + private class ChevronIcon : SpriteIcon + { + private const int bottom_margin = 2; + private const int icon_size = 8; + + public ChevronIcon() + { + Anchor = Anchor.Centre; + Origin = Anchor.Centre; + Margin = new MarginPadding { Bottom = bottom_margin }; + Size = new Vector2(icon_size); + Icon = FontAwesome.Solid.ChevronDown; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colors) + { + Colour = colors.Yellow; + } + } } } } diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs b/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs index 470bed2854..1d9e3d1cc1 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Online.API.Requests; using osu.Game.Users; @@ -9,6 +8,7 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Bindables; +using osu.Framework.Graphics; namespace osu.Game.Overlays.Profile.Sections.Ranks { @@ -41,8 +41,8 @@ protected override void ShowMore() if (!scores.Any() && VisiblePages == 1) { - ShowMoreButton.Hide(); - ShowMoreLoading.Hide(); + MoreButton.Hide(); + MoreButton.IsLoading = false; MissingText.Show(); return; } @@ -63,8 +63,8 @@ protected override void ShowMore() LoadComponentsAsync(drawableScores, s => { MissingText.Hide(); - ShowMoreButton.FadeTo(scores.Count == ItemsPerPage ? 1 : 0); - ShowMoreLoading.Hide(); + MoreButton.FadeTo(scores.Count == ItemsPerPage ? 1 : 0); + MoreButton.IsLoading = false; ItemsContainer.AddRange(s); }); diff --git a/osu.Game/Overlays/Profile/Sections/Recent/PaginatedRecentActivityContainer.cs b/osu.Game/Overlays/Profile/Sections/Recent/PaginatedRecentActivityContainer.cs index 4b4acb8fbc..38134ad660 100644 --- a/osu.Game/Overlays/Profile/Sections/Recent/PaginatedRecentActivityContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Recent/PaginatedRecentActivityContainer.cs @@ -27,8 +27,8 @@ protected override void ShowMore() request = new GetUserRecentActivitiesRequest(User.Value.Id, VisiblePages++ * ItemsPerPage); request.Success += activities => Schedule(() => { - ShowMoreButton.FadeTo(activities.Count == ItemsPerPage ? 1 : 0); - ShowMoreLoading.Hide(); + MoreButton.FadeTo(activities.Count == ItemsPerPage ? 1 : 0); + MoreButton.IsLoading = false; if (!activities.Any() && VisiblePages == 1) { From 857eb9b83a5a5cfab6865d06807ad58af5aa1aa1 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Tue, 28 May 2019 17:21:34 +0300 Subject: [PATCH 02/17] Fix CI stuff --- osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs b/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs index 1ebc51b11f..7e13a90f25 100644 --- a/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs @@ -106,6 +106,7 @@ protected class ShowMoreButton : CircularContainer private readonly FillFlowContainer content; private bool isLoading; + public bool IsLoading { set @@ -123,10 +124,7 @@ public bool IsLoading content.FadeIn(duration, Easing.OutQuint); } } - get - { - return isLoading; - } + get => isLoading; } public ShowMoreButton() From 19fbab68928128641a15681a84f1611d58cf2870 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Tue, 28 May 2019 19:39:31 +0300 Subject: [PATCH 03/17] Applied suggested changes --- .../Sections/Beatmaps/PaginatedBeatmapContainer.cs | 2 -- .../Historical/PaginatedMostPlayedBeatmapContainer.cs | 2 -- .../Overlays/Profile/Sections/PaginatedContainer.cs | 10 ++++++---- .../Profile/Sections/Ranks/PaginatedScoreContainer.cs | 2 -- .../Recent/PaginatedRecentActivityContainer.cs | 2 -- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs b/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs index db291d0731..b6b0e605d7 100644 --- a/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Beatmaps/PaginatedBeatmapContainer.cs @@ -29,8 +29,6 @@ public PaginatedBeatmapContainer(BeatmapSetType type, Bindable user, strin protected override void ShowMore() { - base.ShowMore(); - request = new GetUserBeatmapsRequest(User.Value.Id, type, VisiblePages++ * ItemsPerPage); request.Success += sets => Schedule(() => { diff --git a/osu.Game/Overlays/Profile/Sections/Historical/PaginatedMostPlayedBeatmapContainer.cs b/osu.Game/Overlays/Profile/Sections/Historical/PaginatedMostPlayedBeatmapContainer.cs index 0f86e0900e..6085b0bc05 100644 --- a/osu.Game/Overlays/Profile/Sections/Historical/PaginatedMostPlayedBeatmapContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Historical/PaginatedMostPlayedBeatmapContainer.cs @@ -24,8 +24,6 @@ public PaginatedMostPlayedBeatmapContainer(Bindable user) protected override void ShowMore() { - base.ShowMore(); - request = new GetUserMostPlayedBeatmapsRequest(User.Value.Id, VisiblePages++ * ItemsPerPage); request.Success += beatmaps => Schedule(() => { diff --git a/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs b/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs index 7e13a90f25..99229a9bce 100644 --- a/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs @@ -20,7 +20,7 @@ namespace osu.Game.Overlays.Profile.Sections { - public class PaginatedContainer : FillFlowContainer + public abstract class PaginatedContainer : FillFlowContainer { protected readonly FillFlowContainer ItemsContainer; protected readonly ShowMoreButton MoreButton; @@ -92,7 +92,7 @@ private void onUserChanged(ValueChangedEvent e) ShowMore(); } - protected virtual void ShowMore() => MoreButton.IsLoading = true; + protected abstract void ShowMore(); protected class ShowMoreButton : CircularContainer { @@ -109,8 +109,11 @@ protected class ShowMoreButton : CircularContainer public bool IsLoading { + get => isLoading; set { + if (isLoading == value) + return; isLoading = value; if (value) @@ -124,7 +127,6 @@ public bool IsLoading content.FadeIn(duration, Easing.OutQuint); } } - get => isLoading; } public ShowMoreButton() @@ -141,7 +143,6 @@ public ShowMoreButton() }, content = new FillFlowContainer { - Alpha = 0, Anchor = Anchor.Centre, Origin = Anchor.Centre, AutoSizeAxes = Axes.Both, @@ -190,6 +191,7 @@ protected override void OnHoverLost(HoverLostEvent e) protected override bool OnClick(ClickEvent e) { + IsLoading = true; Action.Invoke(); return base.OnClick(e); } diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs b/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs index 1d9e3d1cc1..a149cfa12e 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs @@ -31,8 +31,6 @@ public PaginatedScoreContainer(ScoreType type, Bindable user, string heade protected override void ShowMore() { - base.ShowMore(); - request = new GetUserScoresRequest(User.Value.Id, type, VisiblePages++ * ItemsPerPage); request.Success += scores => Schedule(() => { diff --git a/osu.Game/Overlays/Profile/Sections/Recent/PaginatedRecentActivityContainer.cs b/osu.Game/Overlays/Profile/Sections/Recent/PaginatedRecentActivityContainer.cs index 38134ad660..b72aec7a44 100644 --- a/osu.Game/Overlays/Profile/Sections/Recent/PaginatedRecentActivityContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Recent/PaginatedRecentActivityContainer.cs @@ -22,8 +22,6 @@ public PaginatedRecentActivityContainer(Bindable user, string header, stri protected override void ShowMore() { - base.ShowMore(); - request = new GetUserRecentActivitiesRequest(User.Value.Id, VisiblePages++ * ItemsPerPage); request.Success += activities => Schedule(() => { From 5169e31d54ea77eeabfc4fe14333fdb91d53147e Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Tue, 28 May 2019 19:53:00 +0300 Subject: [PATCH 04/17] Fix CI issues --- osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs b/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs index 99229a9bce..6e0729c7c5 100644 --- a/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs @@ -35,7 +35,7 @@ public abstract class PaginatedContainer : FillFlowContainer protected APIRequest RetrievalRequest; protected RulesetStore Rulesets; - public PaginatedContainer(Bindable user, string header, string missing) + protected PaginatedContainer(Bindable user, string header, string missing) { User.BindTo(user); @@ -114,6 +114,7 @@ public bool IsLoading { if (isLoading == value) return; + isLoading = value; if (value) From 73fb28f9f7fbc082e2fd58b787d759c175f98b35 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Thu, 30 May 2019 22:48:27 +0300 Subject: [PATCH 05/17] Make the button inherit from OsuHoverContainer --- .../Profile/Sections/PaginatedContainer.cs | 93 +++++++++---------- 1 file changed, 42 insertions(+), 51 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs b/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs index 6e0729c7c5..504f80fc97 100644 --- a/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs @@ -12,11 +12,11 @@ using osu.Game.Online.API; using osu.Game.Rulesets; using osu.Framework.Input.Events; -using System; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; -using osuTK.Graphics; using osu.Game.Users; +using osu.Game.Graphics.Containers; +using System.Collections.Generic; namespace osu.Game.Overlays.Profile.Sections { @@ -94,17 +94,14 @@ private void onUserChanged(ValueChangedEvent e) protected abstract void ShowMore(); - protected class ShowMoreButton : CircularContainer + protected class ShowMoreButton : OsuHoverContainer { - private const int duration = 300; - private Color4 idleColour; - private Color4 hoveredColour; - - public Action Action; private readonly Box background; private readonly LoadingAnimation loading; private readonly FillFlowContainer content; + protected override IEnumerable EffectTargets => new[] { background }; + private bool isLoading; public bool IsLoading @@ -119,13 +116,13 @@ public bool IsLoading if (value) { - loading.FadeIn(duration, Easing.OutQuint); - content.FadeOut(duration, Easing.OutQuint); + loading.FadeIn(FADE_DURATION, Easing.OutQuint); + content.FadeOut(FADE_DURATION, Easing.OutQuint); } else { - loading.FadeOut(duration, Easing.OutQuint); - content.FadeIn(duration, Easing.OutQuint); + loading.FadeOut(FADE_DURATION, Easing.OutQuint); + content.FadeIn(FADE_DURATION, Easing.OutQuint); } } } @@ -134,66 +131,60 @@ public ShowMoreButton() { Anchor = Anchor.TopCentre; Origin = Anchor.TopCentre; - Masking = true; - Size = new Vector2(140, 30); + AutoSizeAxes = Axes.Both; Children = new Drawable[] { - background = new Box + new CircularContainer { - RelativeSizeAxes = Axes.Both, - }, - content = new FillFlowContainer - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Horizontal, - Spacing = new Vector2(7), + Masking = true, + Size = new Vector2(140, 30), Children = new Drawable[] { - new ChevronIcon(), - new OsuSpriteText + background = new Box + { + RelativeSizeAxes = Axes.Both, + }, + content = new FillFlowContainer { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold), - Text = "show more".ToUpper(), + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(7), + Children = new Drawable[] + { + new ChevronIcon(), + new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), + Text = "show more".ToUpper(), + }, + new ChevronIcon(), + } + }, + loading = new LoadingAnimation + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(12) }, - new ChevronIcon(), } - }, - loading = new LoadingAnimation - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = new Vector2(20) - }, + } }; } [BackgroundDependencyLoader] private void load(OsuColour colors) { - background.Colour = idleColour = colors.GreySeafoam; - hoveredColour = colors.GreySeafoamLight; - } - - protected override bool OnHover(HoverEvent e) - { - background.FadeColour(hoveredColour, duration, Easing.OutQuint); - return base.OnHover(e); - } - - protected override void OnHoverLost(HoverLostEvent e) - { - background.FadeColour(idleColour, duration, Easing.OutQuint); - base.OnHoverLost(e); + IdleColour = colors.GreySeafoam; + HoverColour = colors.GreySeafoamLight; } protected override bool OnClick(ClickEvent e) { IsLoading = true; - Action.Invoke(); return base.OnClick(e); } From 2933169614bee615d4f8e75205d3414620c00be9 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Thu, 30 May 2019 22:55:59 +0300 Subject: [PATCH 06/17] Move the button into a separate class --- .../Profile/Sections/PaginatedContainer.cs | 122 ---------------- .../Profile/Sections/ShowMoreButton.cs | 134 ++++++++++++++++++ 2 files changed, 134 insertions(+), 122 deletions(-) create mode 100644 osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs diff --git a/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs b/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs index 504f80fc97..11803b0dc1 100644 --- a/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs @@ -8,15 +8,9 @@ using osu.Framework.Graphics.Containers; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; -using osu.Game.Graphics.UserInterface; using osu.Game.Online.API; using osu.Game.Rulesets; -using osu.Framework.Input.Events; -using osu.Framework.Graphics.Shapes; -using osu.Framework.Graphics.Sprites; using osu.Game.Users; -using osu.Game.Graphics.Containers; -using System.Collections.Generic; namespace osu.Game.Overlays.Profile.Sections { @@ -93,121 +87,5 @@ private void onUserChanged(ValueChangedEvent e) } protected abstract void ShowMore(); - - protected class ShowMoreButton : OsuHoverContainer - { - private readonly Box background; - private readonly LoadingAnimation loading; - private readonly FillFlowContainer content; - - protected override IEnumerable EffectTargets => new[] { background }; - - private bool isLoading; - - public bool IsLoading - { - get => isLoading; - set - { - if (isLoading == value) - return; - - isLoading = value; - - if (value) - { - loading.FadeIn(FADE_DURATION, Easing.OutQuint); - content.FadeOut(FADE_DURATION, Easing.OutQuint); - } - else - { - loading.FadeOut(FADE_DURATION, Easing.OutQuint); - content.FadeIn(FADE_DURATION, Easing.OutQuint); - } - } - } - - public ShowMoreButton() - { - Anchor = Anchor.TopCentre; - Origin = Anchor.TopCentre; - AutoSizeAxes = Axes.Both; - Children = new Drawable[] - { - new CircularContainer - { - Masking = true, - Size = new Vector2(140, 30), - Children = new Drawable[] - { - background = new Box - { - RelativeSizeAxes = Axes.Both, - }, - content = new FillFlowContainer - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Horizontal, - Spacing = new Vector2(7), - Children = new Drawable[] - { - new ChevronIcon(), - new OsuSpriteText - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), - Text = "show more".ToUpper(), - }, - new ChevronIcon(), - } - }, - loading = new LoadingAnimation - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = new Vector2(12) - }, - } - } - }; - } - - [BackgroundDependencyLoader] - private void load(OsuColour colors) - { - IdleColour = colors.GreySeafoam; - HoverColour = colors.GreySeafoamLight; - } - - protected override bool OnClick(ClickEvent e) - { - IsLoading = true; - return base.OnClick(e); - } - - private class ChevronIcon : SpriteIcon - { - private const int bottom_margin = 2; - private const int icon_size = 8; - - public ChevronIcon() - { - Anchor = Anchor.Centre; - Origin = Anchor.Centre; - Margin = new MarginPadding { Bottom = bottom_margin }; - Size = new Vector2(icon_size); - Icon = FontAwesome.Solid.ChevronDown; - } - - [BackgroundDependencyLoader] - private void load(OsuColour colors) - { - Colour = colors.Yellow; - } - } - } } } diff --git a/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs b/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs new file mode 100644 index 0000000000..5979c971d1 --- /dev/null +++ b/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs @@ -0,0 +1,134 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Input.Events; +using osu.Game.Graphics; +using osu.Game.Graphics.Containers; +using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; +using osuTK; +using System.Collections.Generic; + +namespace osu.Game.Overlays.Profile.Sections +{ + public class ShowMoreButton : OsuHoverContainer + { + private readonly Box background; + private readonly LoadingAnimation loading; + private readonly FillFlowContainer content; + + protected override IEnumerable EffectTargets => new[] { background }; + + private bool isLoading; + + public bool IsLoading + { + get => isLoading; + set + { + if (isLoading == value) + return; + + isLoading = value; + + if (value) + { + loading.FadeIn(FADE_DURATION, Easing.OutQuint); + content.FadeOut(FADE_DURATION, Easing.OutQuint); + } + else + { + loading.FadeOut(FADE_DURATION, Easing.OutQuint); + content.FadeIn(FADE_DURATION, Easing.OutQuint); + } + } + } + + public ShowMoreButton() + { + Anchor = Anchor.TopCentre; + Origin = Anchor.TopCentre; + AutoSizeAxes = Axes.Both; + Children = new Drawable[] + { + new CircularContainer + { + Masking = true, + Size = new Vector2(140, 30), + Children = new Drawable[] + { + background = new Box + { + RelativeSizeAxes = Axes.Both, + }, + content = new FillFlowContainer + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(7), + Children = new Drawable[] + { + new ChevronIcon(), + new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), + Text = "show more".ToUpper(), + }, + new ChevronIcon(), + } + }, + loading = new LoadingAnimation + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(12) + }, + } + } + }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colors) + { + IdleColour = colors.GreySeafoam; + HoverColour = colors.GreySeafoamLight; + } + + protected override bool OnClick(ClickEvent e) + { + IsLoading = true; + return base.OnClick(e); + } + + private class ChevronIcon : SpriteIcon + { + private const int bottom_margin = 2; + private const int icon_size = 8; + + public ChevronIcon() + { + Anchor = Anchor.Centre; + Origin = Anchor.Centre; + Margin = new MarginPadding { Bottom = bottom_margin }; + Size = new Vector2(icon_size); + Icon = FontAwesome.Solid.ChevronDown; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colors) + { + Colour = colors.Yellow; + } + } + } +} From fe9e53e383e5f2d35e382daffad3f5ba1b253a53 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Thu, 30 May 2019 23:07:04 +0300 Subject: [PATCH 07/17] Add a testcase --- .../Visual/Online/TestSceneShowMoreButton.cs | 31 +++++++++ .../Graphics/Containers/OsuHoverContainer.cs | 6 +- .../Profile/Sections/PaginatedContainer.cs | 2 + .../Profile/Sections/ShowMoreButton.cs | 68 +++++++++---------- 4 files changed, 70 insertions(+), 37 deletions(-) create mode 100644 osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs diff --git a/osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs b/osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs new file mode 100644 index 0000000000..8289e4a09c --- /dev/null +++ b/osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs @@ -0,0 +1,31 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Game.Overlays.Profile.Sections; +using System; +using System.Collections.Generic; +using osu.Framework.Graphics; + +namespace osu.Game.Tests.Visual.Online +{ + public class TestSceneShowMoreButton : OsuTestScene + { + private readonly ShowMoreButton button; + + public override IReadOnlyList RequiredTypes => new[] + { + typeof(ShowMoreButton), + }; + + public TestSceneShowMoreButton() + { + Add(button = new ShowMoreButton + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }); + + AddStep("switch loading state", () => button.IsLoading = !button.IsLoading); + } + } +} diff --git a/osu.Game/Graphics/Containers/OsuHoverContainer.cs b/osu.Game/Graphics/Containers/OsuHoverContainer.cs index c4f85926ee..eb2d926424 100644 --- a/osu.Game/Graphics/Containers/OsuHoverContainer.cs +++ b/osu.Game/Graphics/Containers/OsuHoverContainer.cs @@ -24,7 +24,8 @@ public OsuHoverContainer() { Enabled.ValueChanged += e => { - if (!e.NewValue) unhover(); + if (!e.NewValue) + unhover(); }; } @@ -49,7 +50,8 @@ protected override void OnHoverLost(HoverLostEvent e) private void unhover() { - if (!isHovered) return; + if (!isHovered) + return; isHovered = false; EffectTargets.ForEach(d => d.FadeColour(IdleColour, FADE_DURATION, Easing.OutQuint)); diff --git a/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs b/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs index 11803b0dc1..8639acfc94 100644 --- a/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs @@ -54,6 +54,8 @@ protected PaginatedContainer(Bindable user, string header, string missing) }, MoreButton = new ShowMoreButton { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, Alpha = 0, Margin = new MarginPadding { Top = 10 }, Action = ShowMore, diff --git a/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs b/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs index 5979c971d1..31c73aaa96 100644 --- a/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs +++ b/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs @@ -51,49 +51,47 @@ public bool IsLoading public ShowMoreButton() { - Anchor = Anchor.TopCentre; - Origin = Anchor.TopCentre; AutoSizeAxes = Axes.Both; Children = new Drawable[] { - new CircularContainer + new CircularContainer + { + Masking = true, + Size = new Vector2(140, 30), + Children = new Drawable[] { - Masking = true, - Size = new Vector2(140, 30), - Children = new Drawable[] + background = new Box { - background = new Box + RelativeSizeAxes = Axes.Both, + }, + content = new FillFlowContainer + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(7), + Children = new Drawable[] { - RelativeSizeAxes = Axes.Both, - }, - content = new FillFlowContainer - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Horizontal, - Spacing = new Vector2(7), - Children = new Drawable[] + new ChevronIcon(), + new OsuSpriteText { - new ChevronIcon(), - new OsuSpriteText - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), - Text = "show more".ToUpper(), - }, - new ChevronIcon(), - } - }, - loading = new LoadingAnimation - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = new Vector2(12) - }, - } + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), + Text = "show more".ToUpper(), + }, + new ChevronIcon(), + } + }, + loading = new LoadingAnimation + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(12) + }, } + } }; } From cfa0ef6fd9c410cf0f2d7c32c9613daf5c179e62 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Thu, 30 May 2019 23:22:08 +0300 Subject: [PATCH 08/17] convert field to a local variable --- osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs b/osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs index 8289e4a09c..0d6d378f4c 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs @@ -10,8 +10,6 @@ namespace osu.Game.Tests.Visual.Online { public class TestSceneShowMoreButton : OsuTestScene { - private readonly ShowMoreButton button; - public override IReadOnlyList RequiredTypes => new[] { typeof(ShowMoreButton), @@ -19,6 +17,8 @@ public class TestSceneShowMoreButton : OsuTestScene public TestSceneShowMoreButton() { + ShowMoreButton button; + Add(button = new ShowMoreButton { Anchor = Anchor.Centre, From 491c9e96e078004025613c05faa97a49faa89f37 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 3 Jun 2019 16:41:27 +0900 Subject: [PATCH 09/17] Fix tests not ending execution after some exceptions --- osu.Game/Tests/Visual/OsuTestScene.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Tests/Visual/OsuTestScene.cs b/osu.Game/Tests/Visual/OsuTestScene.cs index 9b775fd498..d03b490bd4 100644 --- a/osu.Game/Tests/Visual/OsuTestScene.cs +++ b/osu.Game/Tests/Visual/OsuTestScene.cs @@ -61,7 +61,8 @@ protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing); - beatmap?.Value.Track.Stop(); + if (beatmap?.Value.TrackLoaded == true) + beatmap.Value.Track.Stop(); if (localStorage.IsValueCreated) { From 1eab4e179ddb5583ded246af115edafdc41b89c1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 3 Jun 2019 17:05:35 +0900 Subject: [PATCH 10/17] Add sample action to test so hover effect is visible --- osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs b/osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs index 0d6d378f4c..936842bdfa 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs @@ -23,6 +23,7 @@ public TestSceneShowMoreButton() { Anchor = Anchor.Centre, Origin = Anchor.Centre, + Action = () => { } }); AddStep("switch loading state", () => button.IsLoading = !button.IsLoading); From c4f4f32db8a24f97922000610172e672d5e03e48 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 3 Jun 2019 17:06:07 +0900 Subject: [PATCH 11/17] Shorten fade duration --- osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs b/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs index 31c73aaa96..6b7c37b42d 100644 --- a/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs +++ b/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs @@ -18,6 +18,8 @@ namespace osu.Game.Overlays.Profile.Sections { public class ShowMoreButton : OsuHoverContainer { + private const float fade_duration = 200; + private readonly Box background; private readonly LoadingAnimation loading; private readonly FillFlowContainer content; @@ -38,13 +40,13 @@ public bool IsLoading if (value) { - loading.FadeIn(FADE_DURATION, Easing.OutQuint); - content.FadeOut(FADE_DURATION, Easing.OutQuint); + loading.FadeIn(fade_duration, Easing.OutQuint); + content.FadeOut(fade_duration, Easing.OutQuint); } else { - loading.FadeOut(FADE_DURATION, Easing.OutQuint); - content.FadeIn(FADE_DURATION, Easing.OutQuint); + loading.FadeOut(fade_duration, Easing.OutQuint); + content.FadeIn(fade_duration, Easing.OutQuint); } } } From 633c3b74ec5b746de3565a2dfe234641cfae1bea Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 3 Jun 2019 17:10:18 +0900 Subject: [PATCH 12/17] Don't handle clicks when in a loading state --- osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs b/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs index 6b7c37b42d..328a1fa6b7 100644 --- a/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs +++ b/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs @@ -1,4 +1,4 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; @@ -38,6 +38,8 @@ public bool IsLoading isLoading = value; + Enabled.Value = !isLoading; + if (value) { loading.FadeIn(fade_duration, Easing.OutQuint); From fe6b4112c6e5244779ada7ed0eea1ca805522c50 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Tue, 4 Jun 2019 01:47:45 +0300 Subject: [PATCH 13/17] Adjust colors to match web design --- osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs b/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs index 328a1fa6b7..485595798d 100644 --- a/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs +++ b/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs @@ -102,8 +102,8 @@ public ShowMoreButton() [BackgroundDependencyLoader] private void load(OsuColour colors) { - IdleColour = colors.GreySeafoam; - HoverColour = colors.GreySeafoamLight; + IdleColour = colors.GreySeafoamDark; + HoverColour = colors.GreySeafoam; } protected override bool OnClick(ClickEvent e) From 2c713712820d9f9a3152e1fc67143eb1fb730fca Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Tue, 4 Jun 2019 02:06:15 +0300 Subject: [PATCH 14/17] Fix endless loading state --- osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs b/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs index 485595798d..82554faac8 100644 --- a/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs +++ b/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs @@ -38,8 +38,6 @@ public bool IsLoading isLoading = value; - Enabled.Value = !isLoading; - if (value) { loading.FadeIn(fade_duration, Easing.OutQuint); @@ -108,6 +106,9 @@ private void load(OsuColour colors) protected override bool OnClick(ClickEvent e) { + if (IsLoading) + return true; + IsLoading = true; return base.OnClick(e); } From d5a2ebf79f3f4b6e7633b7faf92b4a4ce35aa9c9 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Tue, 4 Jun 2019 04:04:33 +0300 Subject: [PATCH 15/17] Fix endless loading state part 2 --- .../Overlays/Profile/Sections/ShowMoreButton.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs b/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs index 82554faac8..a1dcfc036e 100644 --- a/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs +++ b/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs @@ -38,6 +38,8 @@ public bool IsLoading isLoading = value; + Enabled.Value = !isLoading; + if (value) { loading.FadeIn(fade_duration, Easing.OutQuint); @@ -106,11 +108,14 @@ private void load(OsuColour colors) protected override bool OnClick(ClickEvent e) { - if (IsLoading) - return true; + var clickResult = base.OnClick(e); - IsLoading = true; - return base.OnClick(e); + if (IsLoading) + return clickResult; + + IsLoading |= clickResult; + + return clickResult; } private class ChevronIcon : SpriteIcon From e8315085c0021a1fcdd1e2fff515673915c11ddc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 4 Jun 2019 10:26:21 +0900 Subject: [PATCH 16/17] Better handle OnClick --- .../Profile/Sections/ShowMoreButton.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs b/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs index a1dcfc036e..5ed546c62b 100644 --- a/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs +++ b/osu.Game/Overlays/Profile/Sections/ShowMoreButton.cs @@ -108,14 +108,18 @@ private void load(OsuColour colors) protected override bool OnClick(ClickEvent e) { - var clickResult = base.OnClick(e); + if (!Enabled.Value) + return false; - if (IsLoading) - return clickResult; - - IsLoading |= clickResult; - - return clickResult; + try + { + return base.OnClick(e); + } + finally + { + // run afterwards as this will disable this button. + IsLoading = true; + } } private class ChevronIcon : SpriteIcon From a5a025de6867edbfb70cf13df58353da4ea044cc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 4 Jun 2019 10:26:35 +0900 Subject: [PATCH 17/17] Add proper tests --- .../Visual/Online/TestSceneShowMoreButton.cs | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs b/osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs index 936842bdfa..bccb263600 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneShowMoreButton.cs @@ -17,16 +17,39 @@ public class TestSceneShowMoreButton : OsuTestScene public TestSceneShowMoreButton() { - ShowMoreButton button; + ShowMoreButton button = null; + + int fireCount = 0; Add(button = new ShowMoreButton { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Action = () => { } + Action = () => + { + fireCount++; + // ReSharper disable once AccessToModifiedClosure + // ReSharper disable once PossibleNullReferenceException + Scheduler.AddDelayed(() => button.IsLoading = false, 2000); + } }); - AddStep("switch loading state", () => button.IsLoading = !button.IsLoading); + AddStep("click button", () => button.Click()); + + AddAssert("action fired once", () => fireCount == 1); + AddAssert("is in loading state", () => button.IsLoading); + + AddStep("click button", () => button.Click()); + + AddAssert("action not fired", () => fireCount == 1); + AddAssert("is in loading state", () => button.IsLoading); + + AddUntilStep("wait for loaded", () => !button.IsLoading); + + AddStep("click button", () => button.Click()); + + AddAssert("action fired twice", () => fireCount == 2); + AddAssert("is in loading state", () => button.IsLoading); } } }