From 4042b94e018379236cbad2282eddfd6843ca9328 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 28 Mar 2017 14:35:18 +0900 Subject: [PATCH] Use DelayedLoadContainer in more places. --- .../Beatmaps/Drawables/BeatmapSetHeader.cs | 27 +-- osu.Game/Overlays/MusicController.cs | 57 +++--- osu.Game/Screens/Select/BeatmapInfoWedge.cs | 163 +++++++++--------- .../Select/Leaderboards/LeaderboardScore.cs | 1 + osu.Game/Users/UpdateableAvatar.cs | 1 + 5 files changed, 124 insertions(+), 125 deletions(-) diff --git a/osu.Game/Beatmaps/Drawables/BeatmapSetHeader.cs b/osu.Game/Beatmaps/Drawables/BeatmapSetHeader.cs index 2d032f0ea4..f8986b2ecd 100644 --- a/osu.Game/Beatmaps/Drawables/BeatmapSetHeader.cs +++ b/osu.Game/Beatmaps/Drawables/BeatmapSetHeader.cs @@ -33,12 +33,25 @@ namespace osu.Game.Beatmaps.Drawables Children = new Drawable[] { + new DelayedLoadContainer + { + RelativeSizeAxes = Axes.Both, + TimeBeforeLoad = 100, + Children = new[] + { + new PanelBackground(beatmap) + { + RelativeSizeAxes = Axes.Both, + Depth = 1, + } + } + }, new FillFlowContainer { Direction = FillDirection.Vertical, Padding = new MarginPadding { Top = 5, Left = 18, Right = 10, Bottom = 10 }, AutoSizeAxes = Axes.Both, - Children = new[] + Children = new Drawable[] { title = new OsuSpriteText { @@ -71,23 +84,13 @@ namespace osu.Game.Beatmaps.Drawables } [BackgroundDependencyLoader] - private void load(OsuConfigManager config, OsuGameBase game) + private void load(OsuConfigManager config) { this.config = config; preferUnicode = config.GetBindable(OsuConfig.ShowUnicode); preferUnicode.ValueChanged += preferUnicode_changed; preferUnicode_changed(preferUnicode, null); - - new PanelBackground(beatmap) - { - RelativeSizeAxes = Axes.Both, - Depth = 1, - }.LoadAsync(game, b => - { - Add(b); - b.FadeInFromZero(200); - }); } private void preferUnicode_changed(object sender, EventArgs e) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index a45dcaacb8..ad115d32cc 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -29,7 +29,7 @@ namespace osu.Game.Overlays { public class MusicController : FocusedOverlayContainer { - private MusicControllerBackground backgroundSprite; + private Drawable currentBackground; private DragBar progress; private TextAwesome playButton; private SpriteText title, artist; @@ -44,7 +44,6 @@ namespace osu.Game.Overlays private Bindable preferUnicode; private WorkingBeatmap current; private BeatmapDatabase beatmaps; - private Framework.Game game; private Container dragContainer; @@ -78,10 +77,8 @@ namespace osu.Game.Overlays } [BackgroundDependencyLoader] - private void load(OsuGameBase osuGame, OsuConfigManager config, BeatmapDatabase beatmaps, OsuColour colours) + private void load(OsuGameBase game, OsuConfigManager config, BeatmapDatabase beatmaps, OsuColour colours) { - game = osuGame; - unicodeString = config.GetUnicodeString; Children = new Drawable[] @@ -212,15 +209,15 @@ namespace osu.Game.Overlays }; this.beatmaps = beatmaps; - trackManager = osuGame.Audio.Track; + trackManager = game.Audio.Track; preferUnicode = config.GetBindable(OsuConfig.ShowUnicode); preferUnicode.ValueChanged += preferUnicode_changed; - beatmapSource = osuGame.Beatmap ?? new Bindable(); + beatmapSource = game.Beatmap ?? new Bindable(); playList = beatmaps.GetAllWithChildren(); - backgroundSprite = new MusicControllerBackground(); - dragContainer.Add(backgroundSprite); + currentBackground = new MusicControllerBackground(); + dragContainer.Add(currentBackground); } protected override void LoadComplete() @@ -351,29 +348,29 @@ namespace osu.Game.Overlays } }); - MusicControllerBackground newBackground; - - (newBackground = new MusicControllerBackground(beatmap)).LoadAsync(game, delegate + dragContainer.Add(new AsyncLoadContainer { - - dragContainer.Add(newBackground); - - switch (direction) + RelativeSizeAxes = Axes.Both, + Depth = float.MaxValue, + Children = new[] { new MusicControllerBackground(beatmap) }, + FinishedLoading = d => { - case TransformDirection.Next: - newBackground.Position = new Vector2(400, 0); - newBackground.MoveToX(0, 500, EasingTypes.OutCubic); - backgroundSprite.MoveToX(-400, 500, EasingTypes.OutCubic); - break; - case TransformDirection.Prev: - newBackground.Position = new Vector2(-400, 0); - newBackground.MoveToX(0, 500, EasingTypes.OutCubic); - backgroundSprite.MoveToX(400, 500, EasingTypes.OutCubic); - break; + switch (direction) + { + case TransformDirection.Next: + d.Position = new Vector2(400, 0); + d.MoveToX(0, 500, EasingTypes.OutCubic); + currentBackground.MoveToX(-400, 500, EasingTypes.OutCubic); + break; + case TransformDirection.Prev: + d.Position = new Vector2(-400, 0); + d.MoveToX(0, 500, EasingTypes.OutCubic); + currentBackground.MoveToX(400, 500, EasingTypes.OutCubic); + break; + } + currentBackground.Expire(); + currentBackground = d; } - - backgroundSprite.Expire(); - backgroundSprite = newBackground; }); }; } @@ -422,8 +419,8 @@ namespace osu.Game.Overlays { this.beatmap = beatmap; CacheDrawnFrameBuffer = true; - RelativeSizeAxes = Axes.Both; Depth = float.MaxValue; + RelativeSizeAxes = Axes.Both; Children = new Drawable[] { diff --git a/osu.Game/Screens/Select/BeatmapInfoWedge.cs b/osu.Game/Screens/Select/BeatmapInfoWedge.cs index d0805c19bd..e932b6faf1 100644 --- a/osu.Game/Screens/Select/BeatmapInfoWedge.cs +++ b/osu.Game/Screens/Select/BeatmapInfoWedge.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq; using OpenTK; using OpenTK.Graphics; -using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; @@ -30,9 +29,7 @@ namespace osu.Game.Screens.Select { private static readonly Vector2 wedged_container_shear = new Vector2(0.15f, 0); - private BufferedContainer beatmapInfoContainer; - - private OsuGameBase game; + private Drawable beatmapInfoContainer; public BeatmapInfoWedge() { @@ -49,12 +46,6 @@ namespace osu.Game.Screens.Select }; } - [BackgroundDependencyLoader] - private void load(OsuGameBase game) - { - this.game = game; - } - protected override bool HideOnEscape => false; protected override void PopIn() @@ -113,105 +104,111 @@ namespace osu.Game.Screens.Select labels.AddRange(Ruleset.GetRuleset(beatmap.BeatmapInfo.Mode).GetBeatmapStatistics(beatmap).Select(s => new InfoLabel(s))); } - (beatmapInfoContainer = new BufferedContainer + Add(beatmapInfoContainer = new AsyncLoadContainer { - Depth = newDepth, - PixelSnapping = true, - CacheDrawnFrameBuffer = true, - Shear = -Shear, - RelativeSizeAxes = Axes.Both, - Children = new Drawable[] + FinishedLoading = d => { - // We will create the white-to-black gradient by modulating transparency and having - // a black backdrop. This results in an sRGB-space gradient and not linear space, - // transitioning from white to black more perceptually uniformly. - new Box + FadeIn(250); + + lastContainer?.FadeOut(250); + lastContainer?.Expire(); + }, + Depth = newDepth, + RelativeSizeAxes = Axes.Both, + Children = new[] + { + new BufferedContainer { + PixelSnapping = true, + CacheDrawnFrameBuffer = true, + Shear = -Shear, RelativeSizeAxes = Axes.Both, - Colour = Color4.Black, - }, - // We use a container, such that we can set the colour gradient to go across the - // vertices of the masked container instead of the vertices of the (larger) sprite. - new Container - { - RelativeSizeAxes = Axes.Both, - ColourInfo = ColourInfo.GradientVertical(Color4.White, Color4.White.Opacity(0.3f)), - Children = new [] - { - // Zoomed-in and cropped beatmap background - new BeatmapBackgroundSprite(beatmap) - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - FillMode = FillMode.Fill, - }, - }, - }, - // Text for beatmap info - new FillFlowContainer - { - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - Direction = FillDirection.Vertical, - Margin = new MarginPadding { Top = 10, Left = 25, Right = 10, Bottom = 20 }, - AutoSizeAxes = Axes.Both, Children = new Drawable[] { - new OsuSpriteText + // We will create the white-to-black gradient by modulating transparency and having + // a black backdrop. This results in an sRGB-space gradient and not linear space, + // transitioning from white to black more perceptually uniformly. + new Box { - Font = @"Exo2.0-MediumItalic", - Text = metadata.Artist + " -- " + metadata.Title, - TextSize = 28, - Shadow = true, + RelativeSizeAxes = Axes.Both, + Colour = Color4.Black, }, - new OsuSpriteText + // We use a container, such that we can set the colour gradient to go across the + // vertices of the masked container instead of the vertices of the (larger) sprite. + new Container { - Font = @"Exo2.0-MediumItalic", - Text = beatmapInfo.Version, - TextSize = 17, - Shadow = true, + RelativeSizeAxes = Axes.Both, + ColourInfo = ColourInfo.GradientVertical(Color4.White, Color4.White.Opacity(0.3f)), + Children = new[] + { + // Zoomed-in and cropped beatmap background + new BeatmapBackgroundSprite(beatmap) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + FillMode = FillMode.Fill, + }, + }, }, + // Text for beatmap info new FillFlowContainer { - Margin = new MarginPadding { Top = 10 }, - Direction = FillDirection.Horizontal, + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Direction = FillDirection.Vertical, + Margin = new MarginPadding { Top = 10, Left = 25, Right = 10, Bottom = 20 }, AutoSizeAxes = Axes.Both, - Children = new [] + Children = new Drawable[] { new OsuSpriteText { - Font = @"Exo2.0-Medium", - Text = "mapped by ", - TextSize = 15, + Font = @"Exo2.0-MediumItalic", + Text = metadata.Artist + " -- " + metadata.Title, + TextSize = 28, Shadow = true, }, new OsuSpriteText { - Font = @"Exo2.0-Bold", - Text = metadata.Author, - TextSize = 15, + Font = @"Exo2.0-MediumItalic", + Text = beatmapInfo.Version, + TextSize = 17, Shadow = true, }, + new FillFlowContainer + { + Margin = new MarginPadding { Top = 10 }, + Direction = FillDirection.Horizontal, + AutoSizeAxes = Axes.Both, + Children = new[] + { + new OsuSpriteText + { + Font = @"Exo2.0-Medium", + Text = "mapped by ", + TextSize = 15, + Shadow = true, + }, + new OsuSpriteText + { + Font = @"Exo2.0-Bold", + Text = metadata.Author, + TextSize = 15, + Shadow = true, + }, + } + }, + new FillFlowContainer + { + Margin = new MarginPadding { Top = 20 }, + Spacing = new Vector2(40, 0), + AutoSizeAxes = Axes.Both, + Children = labels + }, } }, - new FillFlowContainer - { - Margin = new MarginPadding { Top = 20 }, - Spacing = new Vector2(40, 0), - AutoSizeAxes = Axes.Both, - Children = labels - }, } - }, + } } - }).LoadAsync(game, delegate (Drawable d) - { - FadeIn(250); - - lastContainer?.FadeOut(250); - lastContainer?.Expire(); - - Add(d); }); } diff --git a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs index 4ea1be3674..d98744aa50 100644 --- a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs @@ -145,6 +145,7 @@ namespace osu.Game.Screens.Select.Leaderboards avatar = new DelayedLoadContainer { TimeBeforeLoad = 500, + FinishedLoading = d => d.FadeInFromZero(200), Size = new Vector2(HEIGHT - edge_margin * 2, HEIGHT - edge_margin * 2), Children = new Drawable[] { diff --git a/osu.Game/Users/UpdateableAvatar.cs b/osu.Game/Users/UpdateableAvatar.cs index 3ffb2a1dfd..4fc2298525 100644 --- a/osu.Game/Users/UpdateableAvatar.cs +++ b/osu.Game/Users/UpdateableAvatar.cs @@ -43,6 +43,7 @@ namespace osu.Game.Users Add(displayedAvatar = new AsyncLoadContainer { RelativeSizeAxes = Axes.Both, + FinishedLoading = d => d.FadeInFromZero(200), Children = new[] { new Avatar(user) { RelativeSizeAxes = Axes.Both }