mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Centralise download tracking logic so we can show it in multiple scenarios
This commit is contained in:
@ -11,6 +11,7 @@ using osu.Game.Beatmaps.Drawables;
|
|||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Overlays.Direct;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
@ -28,7 +29,9 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
|
|||||||
Width = 120;
|
Width = 120;
|
||||||
|
|
||||||
BeatmapSetDownloader downloader;
|
BeatmapSetDownloader downloader;
|
||||||
Add(new Container
|
AddRange(new Drawable[]
|
||||||
|
{
|
||||||
|
new Container
|
||||||
{
|
{
|
||||||
Depth = -1,
|
Depth = -1,
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
@ -67,6 +70,13 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
|
|||||||
Margin = new MarginPadding { Right = 5 },
|
Margin = new MarginPadding { Right = 5 },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
new DownloadProgressBar(set)
|
||||||
|
{
|
||||||
|
Depth = -2,
|
||||||
|
Anchor = Anchor.BottomLeft,
|
||||||
|
Origin = Anchor.BottomLeft,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Action = () =>
|
Action = () =>
|
||||||
|
@ -16,8 +16,6 @@ using osu.Game.Beatmaps;
|
|||||||
using osu.Game.Beatmaps.Drawables;
|
using osu.Game.Beatmaps.Drawables;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
using osu.Game.Online.API.Requests;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
@ -31,8 +29,6 @@ namespace osu.Game.Overlays.Direct
|
|||||||
|
|
||||||
private Container content;
|
private Container content;
|
||||||
|
|
||||||
private ProgressBar progressBar;
|
|
||||||
private BeatmapManager beatmaps;
|
|
||||||
private BeatmapSetOverlay beatmapSetOverlay;
|
private BeatmapSetOverlay beatmapSetOverlay;
|
||||||
|
|
||||||
public PreviewTrack Preview => PlayButton.Preview;
|
public PreviewTrack Preview => PlayButton.Preview;
|
||||||
@ -65,14 +61,10 @@ namespace osu.Game.Overlays.Direct
|
|||||||
Colour = Color4.Black.Opacity(0.3f),
|
Colour = Color4.Black.Opacity(0.3f),
|
||||||
};
|
};
|
||||||
|
|
||||||
private OsuColour colours;
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader(permitNulls: true)]
|
[BackgroundDependencyLoader(permitNulls: true)]
|
||||||
private void load(BeatmapManager beatmaps, OsuColour colours, BeatmapSetOverlay beatmapSetOverlay)
|
private void load(BeatmapManager beatmaps, OsuColour colours, BeatmapSetOverlay beatmapSetOverlay)
|
||||||
{
|
{
|
||||||
this.beatmaps = beatmaps;
|
|
||||||
this.beatmapSetOverlay = beatmapSetOverlay;
|
this.beatmapSetOverlay = beatmapSetOverlay;
|
||||||
this.colours = colours;
|
|
||||||
|
|
||||||
AddInternal(content = new Container
|
AddInternal(content = new Container
|
||||||
{
|
{
|
||||||
@ -82,33 +74,14 @@ namespace osu.Game.Overlays.Direct
|
|||||||
Children = new[]
|
Children = new[]
|
||||||
{
|
{
|
||||||
CreateBackground(),
|
CreateBackground(),
|
||||||
progressBar = new ProgressBar
|
new DownloadProgressBar(SetInfo)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.BottomLeft,
|
Anchor = Anchor.BottomLeft,
|
||||||
Origin = Anchor.BottomLeft,
|
Origin = Anchor.BottomLeft,
|
||||||
Height = 0,
|
|
||||||
Alpha = 0,
|
|
||||||
BackgroundColour = Color4.Black.Opacity(0.7f),
|
|
||||||
FillColour = colours.Blue,
|
|
||||||
Depth = -1,
|
Depth = -1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var downloadRequest = beatmaps.GetExistingDownload(SetInfo);
|
|
||||||
|
|
||||||
if (downloadRequest != null)
|
|
||||||
attachDownload(downloadRequest);
|
|
||||||
|
|
||||||
beatmaps.BeatmapDownloadBegan += attachDownload;
|
|
||||||
beatmaps.ItemAdded += setAdded;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
|
||||||
{
|
|
||||||
base.Dispose(isDisposing);
|
|
||||||
beatmaps.BeatmapDownloadBegan -= attachDownload;
|
|
||||||
beatmaps.ItemAdded -= setAdded;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
@ -149,37 +122,6 @@ namespace osu.Game.Overlays.Direct
|
|||||||
|
|
||||||
protected void ShowInformation() => beatmapSetOverlay?.ShowBeatmapSet(SetInfo);
|
protected void ShowInformation() => beatmapSetOverlay?.ShowBeatmapSet(SetInfo);
|
||||||
|
|
||||||
private void attachDownload(DownloadBeatmapSetRequest request)
|
|
||||||
{
|
|
||||||
if (request.BeatmapSet.OnlineBeatmapSetID != SetInfo.OnlineBeatmapSetID)
|
|
||||||
return;
|
|
||||||
|
|
||||||
progressBar.FadeIn(400, Easing.OutQuint);
|
|
||||||
progressBar.ResizeHeightTo(4, 400, Easing.OutQuint);
|
|
||||||
|
|
||||||
progressBar.Current.Value = 0;
|
|
||||||
|
|
||||||
request.Failure += e =>
|
|
||||||
{
|
|
||||||
progressBar.Current.Value = 0;
|
|
||||||
progressBar.FadeOut(500);
|
|
||||||
};
|
|
||||||
|
|
||||||
request.DownloadProgressed += progress => Schedule(() => progressBar.Current.Value = progress);
|
|
||||||
|
|
||||||
request.Success += data =>
|
|
||||||
{
|
|
||||||
progressBar.Current.Value = 1;
|
|
||||||
progressBar.FillColour = colours.Yellow;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setAdded(BeatmapSetInfo s, bool existing, bool silent) => Schedule(() =>
|
|
||||||
{
|
|
||||||
if (s.OnlineBeatmapSetID == SetInfo.OnlineBeatmapSetID)
|
|
||||||
progressBar.FadeOut(500);
|
|
||||||
});
|
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
70
osu.Game/Overlays/Direct/DownloadProgressBar.cs
Normal file
70
osu.Game/Overlays/Direct/DownloadProgressBar.cs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Direct
|
||||||
|
{
|
||||||
|
public class DownloadProgressBar : DownloadTrackingComponent
|
||||||
|
{
|
||||||
|
private readonly ProgressBar progressBar;
|
||||||
|
|
||||||
|
private OsuColour colours;
|
||||||
|
|
||||||
|
public DownloadProgressBar(BeatmapSetInfo setInfo)
|
||||||
|
: base(setInfo)
|
||||||
|
{
|
||||||
|
AddInternal(progressBar = new ProgressBar
|
||||||
|
{
|
||||||
|
Height = 0,
|
||||||
|
Alpha = 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
AutoSizeAxes = Axes.Y;
|
||||||
|
RelativeSizeAxes = Axes.X;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader(true)]
|
||||||
|
private void load(OsuColour colours)
|
||||||
|
{
|
||||||
|
this.colours = colours;
|
||||||
|
|
||||||
|
progressBar.FillColour = colours.Blue;
|
||||||
|
progressBar.BackgroundColour = Color4.Black.Opacity(0.7f);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DownloadFailed()
|
||||||
|
{
|
||||||
|
progressBar.Current.Value = 0;
|
||||||
|
progressBar.FadeOut(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DownloadComleted()
|
||||||
|
{
|
||||||
|
progressBar.Current.Value = 1;
|
||||||
|
progressBar.FillColour = colours.Yellow;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DownloadStarted()
|
||||||
|
{
|
||||||
|
progressBar.FadeIn(400, Easing.OutQuint);
|
||||||
|
progressBar.ResizeHeightTo(4, 400, Easing.OutQuint);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void BeatmapImported()
|
||||||
|
{
|
||||||
|
progressBar.FadeOut(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ProgressChanged(float progress)
|
||||||
|
{
|
||||||
|
progressBar.Current.Value = progress;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
77
osu.Game/Overlays/Direct/DownloadTrackingComponent.cs
Normal file
77
osu.Game/Overlays/Direct/DownloadTrackingComponent.cs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
// Copyright (c) 2007-2019 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Online.API.Requests;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Direct
|
||||||
|
{
|
||||||
|
public abstract class DownloadTrackingComponent : CompositeDrawable
|
||||||
|
{
|
||||||
|
private readonly BeatmapSetInfo setInfo;
|
||||||
|
private BeatmapManager beatmaps;
|
||||||
|
|
||||||
|
protected DownloadTrackingComponent(BeatmapSetInfo beatmapSetInfo)
|
||||||
|
{
|
||||||
|
setInfo = beatmapSetInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Disposal
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
beatmaps.BeatmapDownloadBegan -= attachDownload;
|
||||||
|
beatmaps.ItemAdded -= setAdded;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader(true)]
|
||||||
|
private void load(BeatmapManager beatmaps)
|
||||||
|
{
|
||||||
|
this.beatmaps = beatmaps;
|
||||||
|
|
||||||
|
var downloadRequest = beatmaps.GetExistingDownload(setInfo);
|
||||||
|
|
||||||
|
if (downloadRequest != null)
|
||||||
|
attachDownload(downloadRequest);
|
||||||
|
|
||||||
|
beatmaps.BeatmapDownloadBegan += attachDownload;
|
||||||
|
beatmaps.ItemAdded += setAdded;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void attachDownload(DownloadBeatmapSetRequest request)
|
||||||
|
{
|
||||||
|
if (request.BeatmapSet.OnlineBeatmapSetID != setInfo.OnlineBeatmapSetID)
|
||||||
|
return;
|
||||||
|
|
||||||
|
DownloadStarted();
|
||||||
|
|
||||||
|
request.Failure += e => { DownloadFailed(); };
|
||||||
|
|
||||||
|
request.DownloadProgressed += progress => Schedule(() => ProgressChanged(progress));
|
||||||
|
request.Success += data => { DownloadComleted(); };
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void ProgressChanged(float progress);
|
||||||
|
|
||||||
|
protected abstract void DownloadFailed();
|
||||||
|
|
||||||
|
protected abstract void DownloadComleted();
|
||||||
|
|
||||||
|
protected abstract void BeatmapImported();
|
||||||
|
|
||||||
|
protected abstract void DownloadStarted();
|
||||||
|
|
||||||
|
private void setAdded(BeatmapSetInfo s, bool existing, bool silent)
|
||||||
|
{
|
||||||
|
if (s.OnlineBeatmapSetID != setInfo.OnlineBeatmapSetID)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Schedule(BeatmapImported);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user