1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 19:32:55 +08:00

Make beatmap download buttons inherit BeatmapDownloadTrackingComposite

- Move DownloadTrackingComposite into the online namespace
This commit is contained in:
naoey 2019-06-11 23:01:01 +05:30
parent 4a6074865e
commit ab27d82cd5
No known key found for this signature in database
GPG Key ID: 670DA9BE3DF7EE60
8 changed files with 55 additions and 32 deletions

View File

@ -29,7 +29,7 @@ namespace osu.Game.Database
/// </summary> /// </summary>
/// <typeparam name="TModel">The model type.</typeparam> /// <typeparam name="TModel">The model type.</typeparam>
/// <typeparam name="TFileModel">The associated file join type.</typeparam> /// <typeparam name="TFileModel">The associated file join type.</typeparam>
public abstract class ArchiveModelManager<TModel, TFileModel> : ICanAcceptFiles, IModelManager public abstract class ArchiveModelManager<TModel, TFileModel> : ICanAcceptFiles, IModelManager<TModel>
where TModel : class, IHasFiles<TFileModel>, IHasPrimaryKey, ISoftDelete where TModel : class, IHasFiles<TFileModel>, IHasPrimaryKey, ISoftDelete
where TFileModel : INamedFileInfo, new() where TFileModel : INamedFileInfo, new()
{ {
@ -44,7 +44,7 @@ namespace osu.Game.Database
/// Fired when a new <see cref="TModel"/> becomes available in the database. /// Fired when a new <see cref="TModel"/> becomes available in the database.
/// This is not guaranteed to run on the update thread. /// This is not guaranteed to run on the update thread.
/// </summary> /// </summary>
public event ItemAddedDelegate ItemAdded; public event Action<TModel, bool> ItemAdded;
/// <summary> /// <summary>
/// Fired when a <see cref="TModel"/> is removed from the database. /// Fired when a <see cref="TModel"/> is removed from the database.

View File

@ -1,7 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
namespace osu.Game.Overlays.Direct namespace osu.Game.Online
{ {
public enum DownloadState public enum DownloadState
{ {

View File

@ -7,18 +7,21 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Online.API; using osu.Game.Online.API;
namespace osu.Game.Overlays.Direct namespace osu.Game.Online
{ {
/// <summary> /// <summary>
/// A component which tracks a beatmap through potential download/import/deletion. /// A component which tracks a beatmap through potential download/import/deletion.
/// </summary> /// </summary>
public abstract class DownloadTrackingComposite : CompositeDrawable public abstract class DownloadTrackingComposite<TModel, TModelManager> : CompositeDrawable
where TModel : class
where TModelManager : class, IDownloadModelManager<TModel>
{ {
public readonly Bindable<BeatmapSetInfo> BeatmapSet = new Bindable<BeatmapSetInfo>(); public readonly Bindable<TModel> ModelInfo = new Bindable<TModel>();
private BeatmapManager beatmaps; private TModelManager manager;
/// <summary> /// <summary>
/// Holds the current download state of the beatmap, whether is has already been downloaded, is in progress, or is not downloaded. /// Holds the current download state of the beatmap, whether is has already been downloaded, is in progress, or is not downloaded.
@ -27,34 +30,34 @@ namespace osu.Game.Overlays.Direct
protected readonly Bindable<double> Progress = new Bindable<double>(); protected readonly Bindable<double> Progress = new Bindable<double>();
protected DownloadTrackingComposite(BeatmapSetInfo beatmapSet = null) protected DownloadTrackingComposite(TModel model = null)
{ {
BeatmapSet.Value = beatmapSet; ModelInfo.Value = model;
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(BeatmapManager beatmaps) private void load(TModelManager manager)
{ {
this.beatmaps = beatmaps; this.manager = manager;
BeatmapSet.BindValueChanged(setInfo => ModelInfo.BindValueChanged(modelInfo =>
{ {
if (setInfo.NewValue == null) if (modelInfo.NewValue == null)
attachDownload(null); attachDownload(null);
else if (beatmaps.GetAllUsableBeatmapSetsEnumerable().Any(s => s.OnlineBeatmapSetID == setInfo.NewValue.OnlineBeatmapSetID)) else if (manager.IsAvailableLocally(modelInfo.NewValue))
State.Value = DownloadState.LocallyAvailable; State.Value = DownloadState.LocallyAvailable;
else else
attachDownload(beatmaps.GetExistingDownload(setInfo.NewValue)); attachDownload(manager.GetExistingDownload(modelInfo.NewValue));
}, true); }, true);
beatmaps.DownloadBegan += download => manager.DownloadBegan += download =>
{ {
if (download.Info.OnlineBeatmapSetID == BeatmapSet.Value?.OnlineBeatmapSetID) if (download.Info.Equals(ModelInfo.Value))
attachDownload(download); attachDownload(download);
}; };
beatmaps.ItemAdded += setAdded; manager.ItemAdded += itemAdded;
beatmaps.ItemRemoved += setRemoved; manager.ItemRemoved += itemRemoved;
} }
#region Disposal #region Disposal
@ -63,10 +66,10 @@ namespace osu.Game.Overlays.Direct
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);
if (beatmaps != null) if (manager != null)
{ {
beatmaps.DownloadBegan -= attachDownload; manager.DownloadBegan -= attachDownload;
beatmaps.ItemAdded -= setAdded; manager.ItemAdded -= itemAdded;
} }
State.UnbindAll(); State.UnbindAll();
@ -76,9 +79,9 @@ namespace osu.Game.Overlays.Direct
#endregion #endregion
private ArchiveDownloadModelRequest<BeatmapSetInfo> attachedRequest; private ArchiveDownloadModelRequest<TModel> attachedRequest;
private void attachDownload(ArchiveDownloadModelRequest<BeatmapSetInfo> request) private void attachDownload(ArchiveDownloadModelRequest<TModel> request)
{ {
if (attachedRequest != null) if (attachedRequest != null)
{ {
@ -118,13 +121,13 @@ namespace osu.Game.Overlays.Direct
private void onRequestFailure(Exception e) => Schedule(() => attachDownload(null)); private void onRequestFailure(Exception e) => Schedule(() => attachDownload(null));
private void setAdded(BeatmapSetInfo s, bool existing) => setDownloadStateFromManager(s, DownloadState.LocallyAvailable); private void itemAdded(TModel s, bool existing) => setDownloadStateFromManager(s, DownloadState.LocallyAvailable);
private void setRemoved(BeatmapSetInfo s) => setDownloadStateFromManager(s, DownloadState.NotDownloaded); private void itemRemoved(TModel s) => setDownloadStateFromManager(s, DownloadState.NotDownloaded);
private void setDownloadStateFromManager(BeatmapSetInfo s, DownloadState state) => Schedule(() => private void setDownloadStateFromManager(TModel s, DownloadState state) => Schedule(() =>
{ {
if (s.OnlineBeatmapSetID != BeatmapSet.Value?.OnlineBeatmapSetID) if (s.Equals(ModelInfo.Value))
return; return;
State.Value = state; State.Value = state;

View File

@ -11,6 +11,7 @@ using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Online;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Overlays.Direct; using osu.Game.Overlays.Direct;
using osu.Game.Users; using osu.Game.Users;
@ -19,7 +20,7 @@ using osuTK.Graphics;
namespace osu.Game.Overlays.BeatmapSet.Buttons namespace osu.Game.Overlays.BeatmapSet.Buttons
{ {
public class DownloadButton : DownloadTrackingComposite, IHasTooltip public class DownloadButton : BeatmapDownloadTrackingComposite, IHasTooltip
{ {
private readonly bool noVideo; private readonly bool noVideo;

View File

@ -13,6 +13,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.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
using osu.Game.Overlays.BeatmapSet.Buttons; using osu.Game.Overlays.BeatmapSet.Buttons;
using osu.Game.Overlays.Direct; using osu.Game.Overlays.Direct;
using osuTK; using osuTK;
@ -21,7 +22,7 @@ using DownloadButton = osu.Game.Overlays.BeatmapSet.Buttons.DownloadButton;
namespace osu.Game.Overlays.BeatmapSet namespace osu.Game.Overlays.BeatmapSet
{ {
public class Header : DownloadTrackingComposite public class Header : BeatmapDownloadTrackingComposite
{ {
private const float transition_duration = 200; private const float transition_duration = 200;
private const float tabs_height = 50; private const float tabs_height = 50;

View File

@ -0,0 +1,16 @@
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Online;
namespace osu.Game.Overlays.Direct
{
public abstract class BeatmapDownloadTrackingComposite : DownloadTrackingComposite<BeatmapSetInfo, BeatmapManager>
{
public Bindable<BeatmapSetInfo> BeatmapSet => ModelInfo;
public BeatmapDownloadTrackingComposite(BeatmapSetInfo set = null)
: base(set)
{
}
}
}

View File

@ -9,11 +9,12 @@ using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
using osuTK; using osuTK;
namespace osu.Game.Overlays.Direct namespace osu.Game.Overlays.Direct
{ {
public class DownloadButton : DownloadTrackingComposite public class DownloadButton : BeatmapDownloadTrackingComposite
{ {
private readonly bool noVideo; private readonly bool noVideo;
private readonly SpriteIcon icon; private readonly SpriteIcon icon;

View File

@ -7,11 +7,12 @@ using osu.Framework.Graphics;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Overlays.Direct namespace osu.Game.Overlays.Direct
{ {
public class DownloadProgressBar : DownloadTrackingComposite public class DownloadProgressBar : BeatmapDownloadTrackingComposite
{ {
private readonly ProgressBar progressBar; private readonly ProgressBar progressBar;