From e94425f311d2c3f844bf37c90d038513a192563c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 12 Jun 2017 16:40:53 +0900 Subject: [PATCH] Improve the loading animation and use it in multiple places - Supersedes https://github.com/ppy/osu/pull/926. - [ ] Depends on https://github.com/ppy/osu-framework/pull/817. --- osu-framework | 2 +- .../UserInterface/LoadingAnimation.cs | 41 +++++++++++++++++-- osu.Game/Overlays/ChatOverlay.cs | 29 ++++++------- osu.Game/Overlays/DialogOverlay.cs | 2 +- osu.Game/Overlays/SocialOverlay.cs | 13 +++++- .../Toolbar/ToolbarOverlayToggleButton.cs | 2 +- osu.Game/Screens/Select/BeatmapDetails.cs | 12 ++++-- .../Select/Leaderboards/Leaderboard.cs | 13 +++++- 8 files changed, 86 insertions(+), 28 deletions(-) diff --git a/osu-framework b/osu-framework index 83ee0bf599..fafadf5e8e 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 83ee0bf59995a4399dd7c2ee676cdac6ac1669f8 +Subproject commit fafadf5e8e204c971c56b3141ce0e1388cfce62d diff --git a/osu.Game/Graphics/UserInterface/LoadingAnimation.cs b/osu.Game/Graphics/UserInterface/LoadingAnimation.cs index 61ec859b44..27a888f0b5 100644 --- a/osu.Game/Graphics/UserInterface/LoadingAnimation.cs +++ b/osu.Game/Graphics/UserInterface/LoadingAnimation.cs @@ -1,15 +1,48 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using OpenTK; namespace osu.Game.Graphics.UserInterface { - public class LoadingAnimation : SpriteText + public class LoadingAnimation : VisibilityContainer { + private readonly TextAwesome spinner; + public LoadingAnimation() { - Text = "Loading"; + Size = new Vector2(20); + + Anchor = Anchor.Centre; + Origin = Anchor.Centre; + + Children = new Drawable[] + { + spinner = new TextAwesome + { + TextSize = 20, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Icon = FontAwesome.fa_spinner + } + }; } + + protected override void LoadComplete() + { + base.LoadComplete(); + + spinner.RotateTo(360, 2000); + using (spinner.BeginDelayedSequence(2000)) + spinner.Loop(); + } + + private const float transition_duration = 500; + + protected override void PopIn() => FadeIn(transition_duration * 5, EasingTypes.OutQuint); + + protected override void PopOut() => FadeOut(transition_duration, EasingTypes.OutQuint); } -} \ No newline at end of file +} diff --git a/osu.Game/Overlays/ChatOverlay.cs b/osu.Game/Overlays/ChatOverlay.cs index 08b40b6079..4f51575da3 100644 --- a/osu.Game/Overlays/ChatOverlay.cs +++ b/osu.Game/Overlays/ChatOverlay.cs @@ -12,7 +12,6 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Threading; -using osu.Game.Graphics.Sprites; using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.Chat; @@ -33,7 +32,9 @@ public class ChatOverlay : FocusedOverlayContainer, IOnlineComponent private ScheduledDelegate messageRequest; - private readonly Container currentChannelContainer; + private readonly Container currentChannelContainer; + + private readonly LoadingAnimation loading; private readonly FocusedTextBox inputTextBox; @@ -104,7 +105,7 @@ public ChatOverlay() { RelativeSizeAxes = Axes.Both, }, - currentChannelContainer = new Container + currentChannelContainer = new Container { RelativeSizeAxes = Axes.Both, Padding = new MarginPadding @@ -138,7 +139,8 @@ public ChatOverlay() HoldFocus = true, } } - } + }, + loading = new LoadingAnimation(), } }, new Container @@ -274,14 +276,7 @@ private void load(APIAccess api, OsuConfigManager config, OsuColour colours) private void initializeChannels() { - SpriteText loading; - Add(loading = new OsuSpriteText - { - Text = @"initialising chat...", - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - TextSize = 40, - }); + loading.Show(); messageRequest?.Cancel(); @@ -290,9 +285,6 @@ private void initializeChannels() { Scheduler.Add(delegate { - loading.FadeOut(100); - loading.Expire(); - addChannel(channels.Find(c => c.Name == @"#lazer")); addChannel(channels.Find(c => c.Name == @"#osu")); addChannel(channels.Find(c => c.Name == @"#lobby")); @@ -336,13 +328,17 @@ protected Channel CurrentChannel if (loaded == null) { currentChannelContainer.FadeOut(500, EasingTypes.OutQuint); + loading.Show(); loaded = new DrawableChannel(currentChannel); loadedChannels.Add(loaded); LoadComponentAsync(loaded, l => { + if (currentChannel.Messages.Any()) + loading.Hide(); + currentChannelContainer.Clear(false); - currentChannelContainer.Add(l); + currentChannelContainer.Add(loaded); currentChannelContainer.FadeIn(500, EasingTypes.OutQuint); }); } @@ -386,6 +382,7 @@ private void fetchInitialMessages(Channel channel) req.Success += delegate (List messages) { + loading.Hide(); channel.AddNewMessages(messages.ToArray()); Debug.Write("success!"); }; diff --git a/osu.Game/Overlays/DialogOverlay.cs b/osu.Game/Overlays/DialogOverlay.cs index 9454272728..461eb2595a 100644 --- a/osu.Game/Overlays/DialogOverlay.cs +++ b/osu.Game/Overlays/DialogOverlay.cs @@ -29,7 +29,7 @@ public void Push(PopupDialog dialog) State = Visibility.Visible; } - private void onDialogOnStateChanged(OverlayContainer dialog, Visibility v) + private void onDialogOnStateChanged(VisibilityContainer dialog, Visibility v) { if (v != Visibility.Hidden) return; diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index 97c27a9ea9..c6ce20f5cf 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -9,6 +9,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Graphics; +using osu.Game.Graphics.UserInterface; using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Overlays.SearchableList; @@ -29,6 +30,8 @@ public class SocialOverlay : SearchableListOverlay CreateFilterControl() => new FilterControl(); private IEnumerable users; + private readonly LoadingAnimation loading; + public IEnumerable Users { get { return users; } @@ -68,6 +71,8 @@ public SocialOverlay() Spacing = new Vector2(10f), }, }; + + Add(loading = new LoadingAnimation()); } [BackgroundDependencyLoader] @@ -83,8 +88,14 @@ private void reloadUsers(APIAccess api) // no this is not the correct data source, but it's something. var request = new GetUsersRequest(); - request.Success += res => Users = res.Select(e => e.User); + request.Success += res => + { + Users = res.Select(e => e.User); + loading.Hide(); + }; + api.Queue(request); + loading.Show(); } public void APIStateChanged(APIAccess api, APIState state) diff --git a/osu.Game/Overlays/Toolbar/ToolbarOverlayToggleButton.cs b/osu.Game/Overlays/Toolbar/ToolbarOverlayToggleButton.cs index fa668bad60..976164a53e 100644 --- a/osu.Game/Overlays/Toolbar/ToolbarOverlayToggleButton.cs +++ b/osu.Game/Overlays/Toolbar/ToolbarOverlayToggleButton.cs @@ -45,7 +45,7 @@ protected override void Dispose(bool isDisposing) stateContainer.StateChanged -= stateChanged; } - private void stateChanged(OverlayContainer c, Visibility state) + private void stateChanged(VisibilityContainer c, Visibility state) { switch (state) { diff --git a/osu.Game/Screens/Select/BeatmapDetails.cs b/osu.Game/Screens/Select/BeatmapDetails.cs index 2aec489508..aefb9901b6 100644 --- a/osu.Game/Screens/Select/BeatmapDetails.cs +++ b/osu.Game/Screens/Select/BeatmapDetails.cs @@ -80,8 +80,8 @@ private void updateStats() lookup.Success += res => { if (beatmap != requestedBeatmap) - //the beatmap has been changed since we started the lookup. - return; + //the beatmap has been changed since we started the lookup. + return; requestedBeatmap.Metrics = res; Schedule(() => updateMetrics(res)); @@ -89,6 +89,7 @@ private void updateStats() lookup.Failure += e => updateMetrics(null); api.Queue(lookup); + loading.Show(); } updateMetrics(requestedBeatmap.Metrics, false); @@ -104,6 +105,9 @@ private void updateMetrics(BeatmapMetrics metrics, bool failOnMissing = true) var hasRatings = metrics?.Ratings.Any() ?? false; var hasRetriesFails = (metrics?.Retries.Any() ?? false) && metrics.Fails.Any(); + if (failOnMissing) + loading.Hide(); + if (hasRatings) { var ratings = metrics.Ratings.ToList(); @@ -320,11 +324,13 @@ public BeatmapDetails() } }, }, - } + }, + loading = new LoadingAnimation() }; } private APIAccess api; + private readonly LoadingAnimation loading; [BackgroundDependencyLoader] private void load(OsuColour colour, APIAccess api) diff --git a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs index 7d97581a29..510ba68f2c 100644 --- a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs @@ -12,6 +12,7 @@ using osu.Framework.Allocation; using osu.Framework.Threading; using osu.Game.Database; +using osu.Game.Graphics.UserInterface; using osu.Game.Rulesets.Scoring; using osu.Game.Online.API; using osu.Game.Online.API.Requests; @@ -25,6 +26,8 @@ public class Leaderboard : Container public Action ScoreSelected; + private LoadingAnimation loading; + private IEnumerable scores; public IEnumerable Scores { @@ -86,6 +89,7 @@ public Leaderboard() }, }, }, + loading = new LoadingAnimation() }; } @@ -117,6 +121,7 @@ private void load(APIAccess api) } private GetScoresRequest getScoresRequest; + private void updateScores() { if (!IsLoaded) return; @@ -126,8 +131,14 @@ private void updateScores() if (api == null || Beatmap == null) return; + loading.Show(); + getScoresRequest = new GetScoresRequest(Beatmap); - getScoresRequest.Success += r => Scores = r.Scores; + getScoresRequest.Success += r => + { + Scores = r.Scores; + loading.Hide(); + }; api.Queue(getScoresRequest); }